Skip to content

Commit

Permalink
bpf: map_seq_next should always increase position index
Browse files Browse the repository at this point in the history
If seq_file .next fuction does not change position index,
read after some lseek can generate an unexpected output.

See also: https://bugzilla.kernel.org/show_bug.cgi?id=206283

v1 -> v2: removed missed increment in end of function

Signed-off-by: Vasily Averin <[email protected]>
Signed-off-by: Daniel Borkmann <[email protected]>
Link: https://lore.kernel.org/bpf/[email protected]
  • Loading branch information
vaverin authored and borkmann committed Jan 27, 2020
1 parent 07fdbee commit 90435a7
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions kernel/bpf/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ static void *map_seq_next(struct seq_file *m, void *v, loff_t *pos)
void *key = map_iter(m)->key;
void *prev_key;

(*pos)++;
if (map_iter(m)->done)
return NULL;

Expand All @@ -208,8 +209,6 @@ static void *map_seq_next(struct seq_file *m, void *v, loff_t *pos)
map_iter(m)->done = true;
return NULL;
}

++(*pos);
return key;
}

Expand Down

0 comments on commit 90435a7

Please sign in to comment.