Skip to content

Commit 6c871b7

Browse files
vaverinkees
authored andcommitted
pstore: pstore_ftrace_seq_next should increase position index
In Aug 2018 NeilBrown noticed commit 1f4aace ("fs/seq_file.c: simplify seq_file iteration code and interface") "Some ->next functions do not increment *pos when they return NULL... Note that such ->next functions are buggy and should be fixed. A simple demonstration is dd if=/proc/swaps bs=1000 skip=1 Choose any block size larger than the size of /proc/swaps. This will always show the whole last line of /proc/swaps" /proc/swaps output was fixed recently, however there are lot of other affected files, and one of them is related to pstore subsystem. If .next function does not change position index, following .show function will repeat output related to current position index. There are at least 2 related problems: - read after lseek beyond end of file, described above by NeilBrown "dd if=<AFFECTED_FILE> bs=1000 skip=1" will generate whole last list - read after lseek on in middle of last line will output expected rest of last line but then repeat whole last line once again. If .show() function generates multy-line output (like pstore_ftrace_seq_show() does ?) following bash script cycles endlessly $ q=;while read -r r;do echo "$((++q)) $r";done < AFFECTED_FILE Unfortunately I'm not familiar enough to pstore subsystem and was unable to find affected pstore-related file on my test node. If .next function does not change position index, following .show function will repeat output related to current position index. Cc: [email protected] Fixes: 1f4aace ("fs/seq_file.c: simplify seq_file iteration code ...") Link: https://bugzilla.kernel.org/show_bug.cgi?id=206283 Signed-off-by: Vasily Averin <[email protected]> Link: https://lore.kernel.org/r/[email protected] [kees: with robustness tweak from Joel Fernandes <[email protected]>] Signed-off-by: Kees Cook <[email protected]>
1 parent e030b80 commit 6c871b7

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

fs/pstore/inode.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,11 @@ static void *pstore_ftrace_seq_next(struct seq_file *s, void *v, loff_t *pos)
8787
struct pstore_private *ps = s->private;
8888
struct pstore_ftrace_seq_data *data = v;
8989

90+
(*pos)++;
9091
data->off += REC_SIZE;
9192
if (data->off + REC_SIZE > ps->total_size)
9293
return NULL;
9394

94-
(*pos)++;
9595
return data;
9696
}
9797

@@ -101,6 +101,9 @@ static int pstore_ftrace_seq_show(struct seq_file *s, void *v)
101101
struct pstore_ftrace_seq_data *data = v;
102102
struct pstore_ftrace_record *rec;
103103

104+
if (!data)
105+
return 0;
106+
104107
rec = (struct pstore_ftrace_record *)(ps->record->buf + data->off);
105108

106109
seq_printf(s, "CPU:%d ts:%llu %08lx %08lx %ps <- %pS\n",

0 commit comments

Comments
 (0)