Skip to content

Commit 1e7e356

Browse files
committed
bpf: Fix sock_addr_is_valid_access() for 32-bit
Support 32-bit pointers and fix errors like: root@qemu-armhf:/usr/libexec/kselftests-bpf# ./test_progs -w 0 -a socket_cookie libbpf: prog 'set_cookie': BPF program load failed: -EACCES libbpf: prog 'set_cookie': -- BEGIN PROG LOAD LOG -- 0: R1=ctx() R10=fp0 ; if (ctx->family != AF_INET6 || ctx->user_family != AF_INET6) @ socket_cookie_prog.c:37 0: (61) r2 = *(u32 *)(r1 +28) ; R1=ctx() R2_w=scalar(smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff)) 1: (56) if w2 != 0xa goto pc+16 ; R2_w=10 2: (61) r2 = *(u32 *)(r1 +0) ; R1=ctx() R2_w=scalar(smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff)) 3: (56) if w2 != 0xa goto pc+14 ; R2_w=10 ; p = bpf_sk_storage_get(&socket_cookies, ctx->sk, 0, @ socket_cookie_prog.c:40 4: (61) r2 = *(u32 *)(r1 +64) invalid bpf_context access off=64 size=4 insn_idx=4 is_valid_access=c096ceec processed 5 insns (limit 1000000) max_states_per_insn 0 total_states 0 peak_states 0 mark_read 0 -- END PROG LOAD LOG -- libbpf: prog 'set_cookie': failed to load: -EACCES libbpf: failed to load object 'socket_cookie_prog' libbpf: failed to load BPF skeleton 'socket_cookie_prog': -EACCES test_socket_cookie:FAIL:skel_open unexpected error: -13 torvalds#366 socket_cookie:FAIL Fixes: fb85c4a ("bpf: export bpf_sock for BPF_PROG_TYPE_CGROUP_SOCK_ADDR prog type") Signed-off-by: Tony Ambardar <tony.ambardar@gmail.com>
1 parent 3263881 commit 1e7e356

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

net/core/filter.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9268,10 +9268,10 @@ static bool sock_addr_is_valid_access(int off, int size,
92689268
return false;
92699269
}
92709270
break;
9271-
case offsetof(struct bpf_sock_addr, sk):
9271+
case bpf_ctx_range_ptr(struct bpf_sock_addr, sk):
92729272
if (type != BPF_READ)
92739273
return false;
9274-
if (size != sizeof(__u64))
9274+
if (size != sizeof(void *))
92759275
return false;
92769276
info->reg_type = PTR_TO_SOCKET;
92779277
break;

0 commit comments

Comments
 (0)