Commit 29b4af70 authored by Miklos Szeredi's avatar Miklos Szeredi Committed by Greg Kroah-Hartman

seq_file: fix incomplete reset on read from zero offset

commit cf5eebae upstream.

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: default avatarRich Felker <dalias@libc.org>
Signed-off-by: default avatarMiklos Szeredi <mszeredi@redhat.com>
Fixes: e522751d ("seq_file: reset iterator to first record for zero offset")
Cc: <stable@vger.kernel.org> # v4.10
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 0f0fd007
......@@ -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)) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment