Commit 6a2aeab5 authored by NeilBrown's avatar NeilBrown Committed by Linus Torvalds

seq_file: fix problem when seeking mid-record

If you use lseek or similar (e.g.  pread) to access a location in a
seq_file file that is within a record, rather than at a record boundary,
then the first read will return the remainder of the record, and the
second read will return the whole of that same record (instead of the
next record).  When seeking to a record boundary, the next record is
correctly returned.

This bug was introduced by a recent patch (identified below).  Before
that patch, seq_read() would increment m->index when the last of the
buffer was returned (m->count == 0).  After that patch, we rely on
->next to increment m->index after filling the buffer - but there was
one place where that didn't happen.

Link: https://lkml.kernel.org/lkml/877e7xl029.fsf@notabene.neil.brown.name/
Fixes: 1f4aace6 ("fs/seq_file.c: simplify seq_file iteration code and interface")
Signed-off-by: default avatarNeilBrown <neilb@suse.com>
Reported-by: default avatarSergei Turchanov <turchanov@farpost.com>
Tested-by: default avatarSergei Turchanov <turchanov@farpost.com>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Markus Elfring <Markus.Elfring@web.de>
Cc: <stable@vger.kernel.org>	[4.19+]
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent ec9f0238
...@@ -119,6 +119,7 @@ static int traverse(struct seq_file *m, loff_t offset) ...@@ -119,6 +119,7 @@ static int traverse(struct seq_file *m, loff_t offset)
} }
if (seq_has_overflowed(m)) if (seq_has_overflowed(m))
goto Eoverflow; goto Eoverflow;
p = m->op->next(m, p, &m->index);
if (pos + m->count > offset) { if (pos + m->count > offset) {
m->from = offset - pos; m->from = offset - pos;
m->count -= m->from; m->count -= m->from;
...@@ -126,7 +127,6 @@ static int traverse(struct seq_file *m, loff_t offset) ...@@ -126,7 +127,6 @@ static int traverse(struct seq_file *m, loff_t offset)
} }
pos += m->count; pos += m->count;
m->count = 0; m->count = 0;
p = m->op->next(m, p, &m->index);
if (pos == offset) if (pos == offset)
break; break;
} }
......
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