On 4/3/26 17:44, Feng Yang wrote:
> From: Feng Yang <[email protected]>
> 
> Calling bpf_lwt_xmit_push_encap will not cause a crash when dst is missing.
> 
> Signed-off-by: Feng Yang <[email protected]>
> ---
>  .../selftests/bpf/prog_tests/lwt_misc.c       |  9 ++++++++
>  tools/testing/selftests/bpf/progs/lwt_misc.c  | 22 +++++++++++++++++++
>  2 files changed, 31 insertions(+)
>  create mode 100644 tools/testing/selftests/bpf/prog_tests/lwt_misc.c
>  create mode 100644 tools/testing/selftests/bpf/progs/lwt_misc.c
> 

Unnecessary to create new files.

Move the adding test to verifier_lwt.c. prog_tests/verifier.c will run
the test.

Thanks,
Leon

> diff --git a/tools/testing/selftests/bpf/prog_tests/lwt_misc.c 
> b/tools/testing/selftests/bpf/prog_tests/lwt_misc.c
> new file mode 100644
> index 000000000000..6940fca38512
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/prog_tests/lwt_misc.c
> @@ -0,0 +1,9 @@
> +// SPDX-License-Identifier: GPL-2.0
> +
> +#include <test_progs.h>
> +#include "lwt_misc.skel.h"
> +
> +void test_lwt_misc(void)
> +{
> +     RUN_TESTS(lwt_misc);
> +}
> diff --git a/tools/testing/selftests/bpf/progs/lwt_misc.c 
> b/tools/testing/selftests/bpf/progs/lwt_misc.c
> new file mode 100644
> index 000000000000..aa638a4f2922
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/progs/lwt_misc.c
> @@ -0,0 +1,22 @@
> +// SPDX-License-Identifier: GPL-2.0
> +
> +#include "vmlinux.h"
> +#include <bpf/bpf_helpers.h>
> +#include "bpf_misc.h"
> +
> +SEC("lwt_xmit")
> +__success __retval(0)
> +int test_missing_dst_call_bpf_lwt_xmit_push_encap(struct __sk_buff *skb)
> +{
> +     struct iphdr iph;
> +
> +     __builtin_memset(&iph, 0, sizeof(struct iphdr));
> +     iph.ihl = 5;
> +     iph.version = 4;
> +
> +     bpf_lwt_push_encap(skb, BPF_LWT_ENCAP_IP, &iph, sizeof(struct iphdr));
> +
> +     return 0;
> +}
> +
> +char _license[] SEC("license") = "GPL";


Reply via email to