Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Miklos Szeredi and committed by
Al Viro
cf5eebae ba87977a

+4 -1
+4 -1
fs/seq_file.c
··· 181 181 * if request is to read from zero offset, reset iterator to first 182 182 * record as it might have been already advanced by previous requests 183 183 */ 184 - if (*ppos == 0) 184 + if (*ppos == 0) { 185 185 m->index = 0; 186 + m->version = 0; 187 + m->count = 0; 188 + } 186 189 187 190 /* Don't assume *ppos is where we left it */ 188 191 if (unlikely(*ppos != m->read_pos)) {