Skip to content

Commit

Permalink
selftests/bpf: Test for null-pointer-deref bugfix in resolve_prog_type()
Browse files Browse the repository at this point in the history
This test verifies that resolve_prog_type() works as expected when
`attach_prog_fd` is not passed in.

`prog->aux->dst_prog` in resolve_prog_type() is assigned by
`attach_prog_fd`, and would be NULL if `attach_prog_fd` is not provided.

Loading EXT prog with bpf_dynptr_from_skb() kfunc call in this way will
lead to null-pointer-deref.

Verify that the null-pointer-deref bug in resolve_prog_type() is fixed.

Signed-off-by: Tengda Wu <wutengda@huaweicloud.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20240711145819.254178-3-wutengda@huaweicloud.com
  • Loading branch information
Tengda Wu authored and borkmann committed Jul 12, 2024
1 parent f7866c3 commit e435b04
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tools/testing/selftests/bpf/verifier/calls.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,19 @@
.result_unpriv = REJECT,
.result = ACCEPT,
},
{
"calls: invalid kfunc call: must provide (attach_prog_fd, btf_id) pair when freplace",
.insns = {
BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, BPF_PSEUDO_KFUNC_CALL, 0, 0),
BPF_EXIT_INSN(),
},
.prog_type = BPF_PROG_TYPE_EXT,
.result = REJECT,
.errstr = "Tracing programs must provide btf_id",
.fixup_kfunc_btf_id = {
{ "bpf_dynptr_from_skb", 0 },
},
},
{
"calls: basic sanity",
.insns = {
Expand Down

0 comments on commit e435b04

Please sign in to comment.