Skip to content

Commit 6a2aeab

Browse files
NeilBrowntorvalds
authored andcommitted
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/[email protected]/ Fixes: 1f4aace ("fs/seq_file.c: simplify seq_file iteration code and interface") Signed-off-by: NeilBrown <[email protected]> Reported-by: Sergei Turchanov <[email protected]> Tested-by: Sergei Turchanov <[email protected]> Cc: Alexander Viro <[email protected]> Cc: Markus Elfring <[email protected]> Cc: <[email protected]> [4.19+] Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent ec9f023 commit 6a2aeab

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

fs/seq_file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,14 @@ static int traverse(struct seq_file *m, loff_t offset)
119119
}
120120
if (seq_has_overflowed(m))
121121
goto Eoverflow;
122+
p = m->op->next(m, p, &m->index);
122123
if (pos + m->count > offset) {
123124
m->from = offset - pos;
124125
m->count -= m->from;
125126
break;
126127
}
127128
pos += m->count;
128129
m->count = 0;
129-
p = m->op->next(m, p, &m->index);
130130
if (pos == offset)
131131
break;
132132
}

0 commit comments

Comments
 (0)