Skip to content

Commit aef9d4a

Browse files
fomichevborkmann
authored andcommitted
bpf: Check attach_func_proto more carefully in check_helper_call
Syzkaller found a problem similar to d1a6ede ("bpf: Check attach_func_proto more carefully in check_return_code") where attach_func_proto might be NULL: RIP: 0010:check_helper_call+0x3dcb/0x8d50 kernel/bpf/verifier.c:7330 do_check kernel/bpf/verifier.c:12302 [inline] do_check_common+0x6e1e/0xb980 kernel/bpf/verifier.c:14610 do_check_main kernel/bpf/verifier.c:14673 [inline] bpf_check+0x661e/0xc520 kernel/bpf/verifier.c:15243 bpf_prog_load+0x11ae/0x1f80 kernel/bpf/syscall.c:2620 With the following reproducer: bpf$BPF_PROG_RAW_TRACEPOINT_LOAD(0x5, &(0x7f0000000780)={0xf, 0x4, &(0x7f0000000040)=@framed={{}, [@call={0x85, 0x0, 0x0, 0xbb}]}, &(0x7f0000000000)='GPL\x00', 0x0, 0x0, 0x0, 0x0, 0x0, '\x00', 0x0, 0x2b, 0xffffffffffffffff, 0x8, 0x0, 0x0, 0x10, 0x0}, 0x80) Let's do the same here, only check attach_func_proto for the prog types where we are certain that attach_func_proto is defined. Fixes: 69fd337 ("bpf: per-cgroup lsm flavor") Reported-by: [email protected] Signed-off-by: Stanislav Fomichev <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Acked-by: Martin KaFai Lau <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 14229b8 commit aef9d4a

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

kernel/bpf/verifier.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7170,6 +7170,7 @@ static void update_loop_inline_state(struct bpf_verifier_env *env, u32 subprogno
71707170
static int check_helper_call(struct bpf_verifier_env *env, struct bpf_insn *insn,
71717171
int *insn_idx_p)
71727172
{
7173+
enum bpf_prog_type prog_type = resolve_prog_type(env->prog);
71737174
const struct bpf_func_proto *fn = NULL;
71747175
enum bpf_return_type ret_type;
71757176
enum bpf_type_flag ret_flag;
@@ -7331,7 +7332,8 @@ static int check_helper_call(struct bpf_verifier_env *env, struct bpf_insn *insn
73317332
}
73327333
break;
73337334
case BPF_FUNC_set_retval:
7334-
if (env->prog->expected_attach_type == BPF_LSM_CGROUP) {
7335+
if (prog_type == BPF_PROG_TYPE_LSM &&
7336+
env->prog->expected_attach_type == BPF_LSM_CGROUP) {
73357337
if (!env->prog->aux->attach_func_proto->type) {
73367338
/* Make sure programs that attach to void
73377339
* hooks don't try to modify return value.

0 commit comments

Comments
 (0)