seq_file: fix incomplete reset on read from zero offset

"Linux Kernel Mailing List" <[email protected]>
Newsgroups gmane.linux.kernel.commits.head
Message-ID <[email protected]>
Web:        https://git.kernel.org/torvalds/c/cf5eebae2cd28d37581507668605f4d23cd7218d
Commit:     cf5eebae2cd28d37581507668605f4d23cd7218d
Parent:     ba87977a49913129962af8ac35b0e13e0fa4382d
Refname:    refs/heads/master
Author:     Miklos Szeredi <[email protected]>
AuthorDate: Wed Nov 15 11:34:58 2017 +0100
Committer:  Al Viro <[email protected]>
CommitDate: Sat Jan 20 02:31:15 2018 -0500

    seq_file: fix incomplete reset on read from zero offset
    
    When resetting iterator on a zero offset we need to discard any data
    already in the buffer (count), and private state of the iterator (version).
    
    For example this bug results in first line being repeated in /proc/mounts
    if doing a zero size read before a non-zero size read.
    
    Reported-by: Rich Felker <[email protected]>
    Signed-off-by: Miklos Szeredi <[email protected]>
    Fixes: e522751d605d ("seq_file: reset iterator to first record for zero offset")
    Cc: <[email protected]> # v4.10
    Signed-off-by: Al Viro <[email protected]>
---
 fs/seq_file.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/fs/seq_file.c b/fs/seq_file.c
index 4be761c1a03d..eea09f6d8830 100644
--- a/fs/seq_file.c
+++ b/fs/seq_file.c
@@ -181,8 +181,11 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
 	 * if request is to read from zero offset, reset iterator to first
 	 * record as it might have been already advanced by previous requests
 	 */
-	if (*ppos == 0)
+	if (*ppos == 0) {
 		m->index = 0;
+		m->version = 0;
+		m->count = 0;
+	}
 
 	/* Don't assume *ppos is where we left it */
 	if (unlikely(*ppos != m->read_pos)) {
--
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.