diff options
author | Miklos Szeredi <mszeredi@redhat.com> | 2017-11-15 11:34:58 +0100 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2018-01-20 02:31:15 -0500 |
commit | cf5eebae2cd28d37581507668605f4d23cd7218d (patch) | |
tree | 4eb7d05f8d94adf671ba5f8aa736b9f502e37d21 /fs/seq_file.c | |
parent | ba87977a49913129962af8ac35b0e13e0fa4382d (diff) | |
download | op-kernel-dev-cf5eebae2cd28d37581507668605f4d23cd7218d.zip op-kernel-dev-cf5eebae2cd28d37581507668605f4d23cd7218d.tar.gz |
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 <dalias@libc.org>
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
Fixes: e522751d605d ("seq_file: reset iterator to first record for zero offset")
Cc: <stable@vger.kernel.org> # v4.10
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'fs/seq_file.c')
-rw-r--r-- | fs/seq_file.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/fs/seq_file.c b/fs/seq_file.c index 4be761c..eea09f6 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)) { |