Check that the verifier accepts a "tx_extra_headroom:" tag of NETDEV_TX_EXTRA_HEADROOM_MAX (512 bytes), and rejects a tag above it, a tag with a plus sign and two tags on the same program. Signed-off-by: Tianyi Gao --- v2: - New patch. --- .../selftests/bpf/prog_tests/verifier.c | 2 + .../bpf/progs/verifier_tx_extra_headroom.c | 40 +++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 tools/testing/selftests/bpf/progs/verifier_tx_extra_headroom.c diff --git a/tools/testing/selftests/bpf/prog_tests/verifier.c b/tools/testing/selftests/bpf/prog_tests/verifier.c index 6a494c381266..e3ef97ed092a 100644 --- a/tools/testing/selftests/bpf/prog_tests/verifier.c +++ b/tools/testing/selftests/bpf/prog_tests/verifier.c @@ -126,6 +126,7 @@ #include "verifier_subreg.skel.h" #include "verifier_tailcall.skel.h" #include "verifier_tailcall_jit.skel.h" +#include "verifier_tx_extra_headroom.skel.h" #include "verifier_typedef.skel.h" #include "verifier_uninit.skel.h" #include "verifier_unpriv.skel.h" @@ -316,6 +317,7 @@ void test_verifier_subprog_topo(void) { RUN(verifier_subprog_topo); } void test_verifier_subreg(void) { RUN(verifier_subreg); } void test_verifier_tailcall(void) { RUN(verifier_tailcall); } void test_verifier_tailcall_jit(void) { RUN(verifier_tailcall_jit); } +void test_verifier_tx_extra_headroom(void) { RUN(verifier_tx_extra_headroom); } void test_verifier_typedef(void) { RUN(verifier_typedef); } void test_verifier_uninit(void) { RUN(verifier_uninit); } void test_verifier_unpriv(void) { RUN(verifier_unpriv); } diff --git a/tools/testing/selftests/bpf/progs/verifier_tx_extra_headroom.c b/tools/testing/selftests/bpf/progs/verifier_tx_extra_headroom.c new file mode 100644 index 000000000000..f15963e34434 --- /dev/null +++ b/tools/testing/selftests/bpf/progs/verifier_tx_extra_headroom.c @@ -0,0 +1,40 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include +#include "bpf_misc.h" + +SEC("tc") +__attribute__((btf_decl_tag("tx_extra_headroom:512"))) +__success +int tag_max(struct __sk_buff *skb) +{ + return 0; +} + +SEC("tc") +__attribute__((btf_decl_tag("tx_extra_headroom:513"))) +__failure __msg("invalid tx_extra_headroom tag '513'") +int tag_above_max(struct __sk_buff *skb) +{ + return 0; +} + +SEC("tc") +__attribute__((btf_decl_tag("tx_extra_headroom:+20"))) +__failure __msg("invalid tx_extra_headroom tag '+20'") +int tag_plus_sign(struct __sk_buff *skb) +{ + return 0; +} + +SEC("tc") +__attribute__((btf_decl_tag("tx_extra_headroom:20"))) +__attribute__((btf_decl_tag("tx_extra_headroom:30"))) +__failure __msg("multiple tx_extra_headroom tags for main subprog") +int tag_twice(struct __sk_buff *skb) +{ + return 0; +} + +char _license[] SEC("license") = "GPL"; -- 2.56.0