Skip to content

Commit 116c8f4

Browse files
kkdwivediAlexei Starovoitov
authored andcommitted
bpf: Fix bounds for bpf_prog_get_file_line linfo loop
We may overrun the bounds because linfo and jited_linfo are already advanced to prog->aux->linfo_idx, hence we must only iterate the remaining elements until we reach prog->aux->nr_linfo. Adjust the nr_linfo calculation to fix this. Reported in [0]. [0]: https://lore.kernel.org/bpf/[email protected] Reported-by: Eduard Zingerman <[email protected]> Fixes: 0e521ef ("bpf: Add function to extract program source info") Signed-off-by: Kumar Kartikeya Dwivedi <[email protected]> Acked-by: Eduard Zingerman <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 6e5cae9 commit 116c8f4

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

kernel/bpf/core.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3244,6 +3244,7 @@ int bpf_prog_get_file_line(struct bpf_prog *prog, unsigned long ip, const char *
32443244
struct bpf_line_info *linfo;
32453245
void **jited_linfo;
32463246
struct btf *btf;
3247+
int nr_linfo;
32473248

32483249
btf = prog->aux->btf;
32493250
linfo = prog->aux->linfo;
@@ -3258,8 +3259,9 @@ int bpf_prog_get_file_line(struct bpf_prog *prog, unsigned long ip, const char *
32583259

32593260
insn_start = linfo[0].insn_off;
32603261
insn_end = insn_start + len;
3262+
nr_linfo = prog->aux->nr_linfo - prog->aux->linfo_idx;
32613263

3262-
for (int i = 0; i < prog->aux->nr_linfo &&
3264+
for (int i = 0; i < nr_linfo &&
32633265
linfo[i].insn_off >= insn_start && linfo[i].insn_off < insn_end; i++) {
32643266
if (jited_linfo[i] >= (void *)ip)
32653267
break;

0 commit comments

Comments
 (0)