Skip to content

Commit bddeb44

Browse files
ecree-solarflaregregkh
authored andcommitted
bpf: fix off-by-one error in adjust_subprog_starts
commit afd5942 upstream. When patching in a new sequence for the first insn of a subprog, the start of that subprog does not change (it's the first insn of the sequence), so adjust_subprog_starts should check start <= off (rather than < off). Also added a test to test_verifier.c (it's essentially the syz reproducer). Fixes: cc8b0b9 ("bpf: introduce function calls (function boundaries)") Reported-by: syzbot+4fc427c7af994b0948be@syzkaller.appspotmail.com Signed-off-by: Edward Cree <ecree@solarflare.com> Acked-by: Yonghong Song <yhs@fb.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 1fd99ac commit bddeb44

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

‎kernel/bpf/verifier.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5283,7 +5283,7 @@ static void adjust_subprog_starts(struct bpf_verifier_env *env, u32 off, u32 len
52835283
return;
52845284
/* NOTE: fake 'exit' subprog should be updated as well. */
52855285
for (i = 0; i <= env->subprog_cnt; i++) {
5286-
if (env->subprog_info[i].start < off)
5286+
if (env->subprog_info[i].start <= off)
52875287
continue;
52885288
env->subprog_info[i].start += len - 1;
52895289
}

‎tools/testing/selftests/bpf/test_verifier.c‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12511,6 +12511,25 @@ static struct bpf_test tests[] = {
1251112511
.prog_type = BPF_PROG_TYPE_SCHED_CLS,
1251212512
.result = ACCEPT,
1251312513
},
12514+
{
12515+
"calls: ctx read at start of subprog",
12516+
.insns = {
12517+
BPF_MOV64_REG(BPF_REG_6, BPF_REG_1),
12518+
BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 1, 0, 5),
12519+
BPF_JMP_REG(BPF_JSGT, BPF_REG_0, BPF_REG_0, 0),
12520+
BPF_MOV64_REG(BPF_REG_1, BPF_REG_6),
12521+
BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 1, 0, 2),
12522+
BPF_MOV64_REG(BPF_REG_1, BPF_REG_0),
12523+
BPF_EXIT_INSN(),
12524+
BPF_LDX_MEM(BPF_B, BPF_REG_9, BPF_REG_1, 0),
12525+
BPF_MOV64_IMM(BPF_REG_0, 0),
12526+
BPF_EXIT_INSN(),
12527+
},
12528+
.prog_type = BPF_PROG_TYPE_SOCKET_FILTER,
12529+
.errstr_unpriv = "function calls to other bpf functions are allowed for root only",
12530+
.result_unpriv = REJECT,
12531+
.result = ACCEPT,
12532+
},
1251412533
};
1251512534

1251612535
static int probe_filter_length(const struct bpf_insn *fp)

0 commit comments

Comments
 (0)