Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions kernel/bpf/btf.c
Original file line number Diff line number Diff line change
Expand Up @@ -6762,7 +6762,7 @@ bool btf_ctx_access(int off, int size, enum bpf_access_type type,
/* skip modifiers */
while (btf_type_is_modifier(t))
t = btf_type_by_id(btf, t->type);
if (btf_type_is_small_int(t) || btf_is_any_enum(t) || __btf_type_is_struct(t))
if (btf_type_is_small_int(t) || btf_is_any_enum(t) || btf_type_is_struct(t))
/* accessing a scalar */
return true;
if (!btf_type_is_ptr(t)) {
Expand Down Expand Up @@ -7334,7 +7334,7 @@ static int __get_type_size(struct btf *btf, u32 btf_id,
if (btf_type_is_ptr(t))
/* kernel size of pointer. Not BPF's size of pointer*/
return sizeof(void *);
if (btf_type_is_int(t) || btf_is_any_enum(t) || __btf_type_is_struct(t))
if (btf_type_is_int(t) || btf_is_any_enum(t) || btf_type_is_struct(t))
return t->size;
return -EINVAL;
}
Expand Down
14 changes: 13 additions & 1 deletion net/bpf/test_run.c
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,16 @@ noinline int bpf_fentry_test10(const void *a)
return (long)a;
}

typedef union {
void *arg0;
int *arg1;
} union_test_t;

noinline int bpf_fentry_test11(union_test_t t)
{
return (int)(long)t.arg0;
}

noinline void bpf_fentry_test_sinfo(struct skb_shared_info *sinfo)
{
}
Expand Down Expand Up @@ -688,6 +698,7 @@ int bpf_prog_test_run_tracing(struct bpf_prog *prog,
struct bpf_fentry_test_t arg = {};
u16 side_effect = 0, ret = 0;
int b = 2, err = -EFAULT;
union_test_t utt = {};
u32 retval = 0;

if (kattr->test.flags || kattr->test.cpu || kattr->test.batch_size)
Expand All @@ -705,7 +716,8 @@ int bpf_prog_test_run_tracing(struct bpf_prog *prog,
bpf_fentry_test7((struct bpf_fentry_test_t *)0) != 0 ||
bpf_fentry_test8(&arg) != 0 ||
bpf_fentry_test9(&retval) != 0 ||
bpf_fentry_test10((void *)0) != 0)
bpf_fentry_test10((void *)0) != 0 ||
bpf_fentry_test11(utt) != 0)
goto out;
break;
case BPF_MODIFY_RETURN:
Expand Down
12 changes: 12 additions & 0 deletions tools/testing/selftests/bpf/progs/verifier_btf_ctx_access.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,16 @@ __naked void ctx_access_const_void_pointer_accept(void)
" ::: __clobber_all);
}

SEC("fentry/bpf_fentry_test11")
__description("btf_ctx_access union arg accept")
__success __retval(0)
__naked void ctx_access_union_arg_accept(void)
{
asm volatile (" \
r2 = *(u64 *)(r1 + 0); /* load 1st argument value (union) */\
r0 = 0; \
exit; \
" ::: __clobber_all);
}

char _license[] SEC("license") = "GPL";
Loading