Re: [PATCH v10 bpf-next 1/2] bpf: test_run: Fix the null pointer dereference issue in bpf_lwt_xmit_push_encap

From: Martin KaFai Lau

Date: Wed Mar 04 2026 - 20:13:25 EST


On 3/4/26 2:33 AM, Leon Hwang wrote:
diff --git a/net/bpf/test_run.c b/net/bpf/test_run.c
index 178c4738e63b..565fe8cbcdc9 100644
--- a/net/bpf/test_run.c
+++ b/net/bpf/test_run.c
@@ -1156,6 +1156,20 @@ int bpf_prog_test_run_skb(struct bpf_prog *prog, const union bpf_attr *kattr,
skb->ip_summed = CHECKSUM_COMPLETE;
}
+ if (prog->type == BPF_PROG_TYPE_LWT_XMIT) {
+ if (ipv6_bpf_stub) {
+#if IS_ENABLED(CONFIG_IPV6)
+ dst_hold(&net->ipv6.ip6_null_entry->dst);
+ skb_dst_set(skb, &net->ipv6.ip6_null_entry->dst);
+#endif
+ } else {
+ /* For CONFIG_IPV6=n, ipv6_bpf_stub is NULL */
+ pr_warn_once("Please test this program with the IPv6 module enabled\n");
+ ret = -EOPNOTSUPP;
+ goto out;
+ }
+ }
+
NIT: it would be more readable to handle the error path first.

if (prog->type == BPF_PROG_TYPE_LWT_XMIT) {
if (!ipv6_bpf_stub) {
pr_warn_once("...");
ret = -EOPNOTSUPP;
goto out;
}
#if IS_ENABLED(CONFIG_IPV6)
dst_hold();
skb_dst_set();
#endif

I have adapted this change and applied. Thanks.