public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v10 bpf-next 0/2] Fix the null pointer dereference issue in bpf_lwt_xmit_push_encap
@ 2026-03-04  9:44 Feng Yang
  2026-03-04  9:44 ` [PATCH v10 bpf-next 1/2] bpf: test_run: " Feng Yang
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Feng Yang @ 2026-03-04  9:44 UTC (permalink / raw)
  To: davem, edumazet, kuba, pabeni, horms, posk, ast, daniel, andrii,
	martin.lau, eddyz87
  Cc: bpf, netdev, linux-kernel, linux-kselftest, yangfeng59949

From: Feng Yang <yangfeng@kylinos.cn>

Fix the null pointer dereference issue in bpf_lwt_xmit_push_encap

Changes in v10:
- Optimization patch. Thanks, Martin KaFai Lau.
- Link to v9: https://lore.kernel.org/all/20260303074423.172680-1-yangfeng59949@163.com/
Changes in v9:
- Use dst_hold() and skb_dst_set().
  !skb_dst skip.
  Move all changes into the IS_ENABLED(CONFIG_IPV6).
  Use #if IS_ENABLED(CONFIG_IPV6); otherwise, a compilation error will occur when ipv6 is not enabled.
  Thanks, Martin KaFai Lau.
- Link to v8: https://lore.kernel.org/all/20260227082133.96951-1-yangfeng59949@163.com/
Changes in v8:
- set ret to an error code before goto out.
- Link to v7: https://lore.kernel.org/all/20260226095156.117996-1-yangfeng59949@163.com/
Changes in v7:
- Use ip6_null_entry to avoid. Thanks, Martin KaFai Lau.
Changes in v6:
- Modify the bpf_lwt_xmit_push_encap function and add selftests for it.
  Thanks, Martin KaFai Lau.
- Link to v5: https://lore.kernel.org/all/20260210090657.86977-1-yangfeng59949@163.com/
Changes in v5:
- Refer to the bpf_lwt_xmit_reroute function to configure the dst parameter.
- Link to v4: https://lore.kernel.org/all/20260209015111.28144-1-yangfeng59949@163.com/
Changes in v4:
- add rcu lock
- Link to v3: https://lore.kernel.org/all/20260206055113.63476-1-yangfeng59949@163.com/
Changes in v3:
- use dst_init
- Link to v2: https://lore.kernel.org/all/20260205092227.126665-1-yangfeng59949@163.com/
Changes in v2:
- Link to v1: https://lore.kernel.org/all/20260127084520.13890-1-luyun_611@163.com/

Feng Yang (2):
  bpf: test_run: Fix the null pointer dereference issue in
    bpf_lwt_xmit_push_encap
  selftests/bpf: Add selftests for the invocation of
    bpf_lwt_xmit_push_encap

 net/bpf/test_run.c                            | 14 ++++++++++++
 .../selftests/bpf/prog_tests/lwt_misc.c       |  9 ++++++++
 tools/testing/selftests/bpf/progs/lwt_misc.c  | 22 +++++++++++++++++++
 3 files changed, 45 insertions(+)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/lwt_misc.c
 create mode 100644 tools/testing/selftests/bpf/progs/lwt_misc.c

-- 
2.43.0


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v10 bpf-next 1/2] bpf: test_run: Fix the null pointer dereference issue in bpf_lwt_xmit_push_encap
  2026-03-04  9:44 [PATCH v10 bpf-next 0/2] Fix the null pointer dereference issue in bpf_lwt_xmit_push_encap Feng Yang
@ 2026-03-04  9:44 ` Feng Yang
  2026-03-04 10:30   ` bot+bpf-ci
  2026-03-04 10:33   ` Leon Hwang
  2026-03-04  9:44 ` [PATCH v10 bpf-next 2/2] selftests/bpf: Add selftests for the invocation of bpf_lwt_xmit_push_encap Feng Yang
  2026-03-05  1:10 ` [PATCH v10 bpf-next 0/2] Fix the null pointer dereference issue in bpf_lwt_xmit_push_encap patchwork-bot+netdevbpf
  2 siblings, 2 replies; 10+ messages in thread
From: Feng Yang @ 2026-03-04  9:44 UTC (permalink / raw)
  To: davem, edumazet, kuba, pabeni, horms, posk, ast, daniel, andrii,
	martin.lau, eddyz87
  Cc: bpf, netdev, linux-kernel, linux-kselftest, yangfeng59949

From: Feng Yang <yangfeng@kylinos.cn>

The bpf_lwt_xmit_push_encap helper needs to access skb_dst(skb)->dev to
calculate the needed headroom:

	err = skb_cow_head(skb,
			   len + LL_RESERVED_SPACE(skb_dst(skb)->dev));

But skb->_skb_refdst may not be initialized when the skb is set up by
bpf_prog_test_run_skb function. Executing bpf_lwt_push_ip_encap function
in this scenario will trigger null pointer dereference, causing a kernel
crash as Yinhao reported:

[  105.186365] BUG: kernel NULL pointer dereference, address: 0000000000000000
[  105.186382] #PF: supervisor read access in kernel mode
[  105.186388] #PF: error_code(0x0000) - not-present page
[  105.186393] PGD 121d3d067 P4D 121d3d067 PUD 106c83067 PMD 0
[  105.186404] Oops: 0000 [#1] PREEMPT SMP NOPTI
[  105.186412] CPU: 3 PID: 3250 Comm: poc Kdump: loaded Not tainted 6.19.0-rc5 #1
[  105.186423] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
[  105.186427] RIP: 0010:bpf_lwt_push_ip_encap+0x1eb/0x520
[  105.186443] Code: 0f 84 de 01 00 00 0f b7 4a 04 66 85 c9 0f 85 47 01 00 00 31 c0 5b 5d 41 5c 41 5d 41 5e c3 cc cc cc cc 48 8b 73 58 48 83 e6 fe <48> 8b 36 0f b7 be ec 00 00 00 0f b7 b6 e6 00 00 00 01 fe 83 e6 f0
[  105.186449] RSP: 0018:ffffbb0e0387bc50 EFLAGS: 00010246
[  105.186455] RAX: 000000000000004e RBX: ffff94c74e036500 RCX: ffff94c74874da00
[  105.186460] RDX: 0000000000000000 RSI: 0000000000000000 RDI: ffff94c74e036500
[  105.186463] RBP: 0000000000000001 R08: 0000000000000002 R09: 0000000000000000
[  105.186467] R10: ffffbb0e0387bd50 R11: 0000000000000000 R12: ffffbb0e0387bc98
[  105.186471] R13: 0000000000000014 R14: 0000000000000000 R15: 0000000000000002
[  105.186484] FS:  00007f166aa4d680(0000) GS:ffff94c8b7780000(0000) knlGS:0000000000000000
[  105.186490] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[  105.186494] CR2: 0000000000000000 CR3: 000000015eade001 CR4: 0000000000770ee0
[  105.186499] PKRU: 55555554
[  105.186502] Call Trace:
[  105.186507]  <TASK>
[  105.186513]  bpf_lwt_xmit_push_encap+0x2b/0x40
[  105.186522]  bpf_prog_a75eaad51e517912+0x41/0x49
[  105.186536]  ? kvm_clock_get_cycles+0x18/0x30
[  105.186547]  ? ktime_get+0x3c/0xa0
[  105.186554]  bpf_test_run+0x195/0x320
[  105.186563]  ? bpf_test_run+0x10f/0x320
[  105.186579]  bpf_prog_test_run_skb+0x2f5/0x4f0
[  105.186590]  __sys_bpf+0x69c/0xa40
[  105.186603]  __x64_sys_bpf+0x1e/0x30
[  105.186611]  do_syscall_64+0x59/0x110
[  105.186620]  entry_SYSCALL_64_after_hwframe+0x76/0xe0
[  105.186649] RIP: 0033:0x7f166a97455d

Temporarily add the setting of skb->_skb_refdst before bpf_test_run to resolve the issue.

Fixes: 52f278774e79 ("bpf: implement BPF_LWT_ENCAP_IP mode in bpf_lwt_push_encap")
Reported-by: Yinhao Hu <dddddd@hust.edu.cn>
Reported-by: Kaiyan Mei <M202472210@hust.edu.cn>
Closes: https://groups.google.com/g/hust-os-kernel-patches/c/8-a0kPpBW2s
Signed-off-by: Yun Lu <luyun@kylinos.cn>
Signed-off-by: Feng Yang <yangfeng@kylinos.cn>
Tested-by: syzbot@syzkaller.appspotmail.com
---
 net/bpf/test_run.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

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;
+		}
+	}
+
 	ret = bpf_test_run(prog, skb, repeat, &retval, &duration, false);
 	if (ret)
 		goto out;
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v10 bpf-next 2/2] selftests/bpf: Add selftests for the invocation of bpf_lwt_xmit_push_encap
  2026-03-04  9:44 [PATCH v10 bpf-next 0/2] Fix the null pointer dereference issue in bpf_lwt_xmit_push_encap Feng Yang
  2026-03-04  9:44 ` [PATCH v10 bpf-next 1/2] bpf: test_run: " Feng Yang
@ 2026-03-04  9:44 ` Feng Yang
  2026-03-04 10:33   ` Leon Hwang
  2026-03-05  1:10 ` [PATCH v10 bpf-next 0/2] Fix the null pointer dereference issue in bpf_lwt_xmit_push_encap patchwork-bot+netdevbpf
  2 siblings, 1 reply; 10+ messages in thread
From: Feng Yang @ 2026-03-04  9:44 UTC (permalink / raw)
  To: davem, edumazet, kuba, pabeni, horms, posk, ast, daniel, andrii,
	martin.lau, eddyz87
  Cc: bpf, netdev, linux-kernel, linux-kselftest, yangfeng59949

From: Feng Yang <yangfeng@kylinos.cn>

Calling bpf_lwt_xmit_push_encap will not cause a crash when dst is missing.

Signed-off-by: Feng Yang <yangfeng@kylinos.cn>
---
 .../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

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";
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH v10 bpf-next 1/2] bpf: test_run: Fix the null pointer dereference issue in bpf_lwt_xmit_push_encap
  2026-03-04  9:44 ` [PATCH v10 bpf-next 1/2] bpf: test_run: " Feng Yang
@ 2026-03-04 10:30   ` bot+bpf-ci
  2026-03-04 10:33   ` Leon Hwang
  1 sibling, 0 replies; 10+ messages in thread
From: bot+bpf-ci @ 2026-03-04 10:30 UTC (permalink / raw)
  To: yangfeng59949, davem, edumazet, kuba, pabeni, horms, posk, ast,
	daniel, andrii, martin.lau, eddyz87
  Cc: bpf, netdev, linux-kernel, linux-kselftest, yangfeng59949, ast,
	andrii, daniel, martin.lau, eddyz87, yonghong.song, clm,
	ihor.solodrai

[-- Attachment #1: Type: text/plain, Size: 968 bytes --]

> 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,

[ ... ]

> +		} else {
> +			/* For CONFIG_IPV6=n, ipv6_bpf_stub is NULL */
> +			pr_warn_once("Please test this program with the IPv6 module enabled\n");

Martin KaFai Lau's v9 review suggested pr_err_once here instead of
pr_warn_once.  Since the function also returns -EOPNOTSUPP, should this
use pr_err_once to match the error severity?

https://lore.kernel.org/bpf/0e88a3ea-9424-40eb-96ea-2d3d1cccac7d@linux.dev/

> +			ret = -EOPNOTSUPP;
> +			goto out;
> +		}
> +	}


---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/22664502452

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v10 bpf-next 1/2] bpf: test_run: Fix the null pointer dereference issue in bpf_lwt_xmit_push_encap
  2026-03-04  9:44 ` [PATCH v10 bpf-next 1/2] bpf: test_run: " Feng Yang
  2026-03-04 10:30   ` bot+bpf-ci
@ 2026-03-04 10:33   ` Leon Hwang
  2026-03-05  1:12     ` Martin KaFai Lau
  1 sibling, 1 reply; 10+ messages in thread
From: Leon Hwang @ 2026-03-04 10:33 UTC (permalink / raw)
  To: Feng Yang, davem, edumazet, kuba, pabeni, horms, posk, ast,
	daniel, andrii, martin.lau, eddyz87
  Cc: bpf, netdev, linux-kernel, linux-kselftest

On 4/3/26 17:44, Feng Yang wrote:
> From: Feng Yang <yangfeng@kylinos.cn>
> 
> The bpf_lwt_xmit_push_encap helper needs to access skb_dst(skb)->dev to
> calculate the needed headroom:
> 
> 	err = skb_cow_head(skb,
> 			   len + LL_RESERVED_SPACE(skb_dst(skb)->dev));
> 
> But skb->_skb_refdst may not be initialized when the skb is set up by
> bpf_prog_test_run_skb function. Executing bpf_lwt_push_ip_encap function
> in this scenario will trigger null pointer dereference, causing a kernel
> crash as Yinhao reported:
> 
> [  105.186365] BUG: kernel NULL pointer dereference, address: 0000000000000000
> [  105.186382] #PF: supervisor read access in kernel mode
> [  105.186388] #PF: error_code(0x0000) - not-present page
> [  105.186393] PGD 121d3d067 P4D 121d3d067 PUD 106c83067 PMD 0
> [  105.186404] Oops: 0000 [#1] PREEMPT SMP NOPTI
> [  105.186412] CPU: 3 PID: 3250 Comm: poc Kdump: loaded Not tainted 6.19.0-rc5 #1
> [  105.186423] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
> [  105.186427] RIP: 0010:bpf_lwt_push_ip_encap+0x1eb/0x520
> [  105.186443] Code: 0f 84 de 01 00 00 0f b7 4a 04 66 85 c9 0f 85 47 01 00 00 31 c0 5b 5d 41 5c 41 5d 41 5e c3 cc cc cc cc 48 8b 73 58 48 83 e6 fe <48> 8b 36 0f b7 be ec 00 00 00 0f b7 b6 e6 00 00 00 01 fe 83 e6 f0
> [  105.186449] RSP: 0018:ffffbb0e0387bc50 EFLAGS: 00010246
> [  105.186455] RAX: 000000000000004e RBX: ffff94c74e036500 RCX: ffff94c74874da00
> [  105.186460] RDX: 0000000000000000 RSI: 0000000000000000 RDI: ffff94c74e036500
> [  105.186463] RBP: 0000000000000001 R08: 0000000000000002 R09: 0000000000000000
> [  105.186467] R10: ffffbb0e0387bd50 R11: 0000000000000000 R12: ffffbb0e0387bc98
> [  105.186471] R13: 0000000000000014 R14: 0000000000000000 R15: 0000000000000002
> [  105.186484] FS:  00007f166aa4d680(0000) GS:ffff94c8b7780000(0000) knlGS:0000000000000000
> [  105.186490] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
> [  105.186494] CR2: 0000000000000000 CR3: 000000015eade001 CR4: 0000000000770ee0
> [  105.186499] PKRU: 55555554
> [  105.186502] Call Trace:
> [  105.186507]  <TASK>
> [  105.186513]  bpf_lwt_xmit_push_encap+0x2b/0x40
> [  105.186522]  bpf_prog_a75eaad51e517912+0x41/0x49
> [  105.186536]  ? kvm_clock_get_cycles+0x18/0x30
> [  105.186547]  ? ktime_get+0x3c/0xa0
> [  105.186554]  bpf_test_run+0x195/0x320
> [  105.186563]  ? bpf_test_run+0x10f/0x320
> [  105.186579]  bpf_prog_test_run_skb+0x2f5/0x4f0
> [  105.186590]  __sys_bpf+0x69c/0xa40
> [  105.186603]  __x64_sys_bpf+0x1e/0x30
> [  105.186611]  do_syscall_64+0x59/0x110
> [  105.186620]  entry_SYSCALL_64_after_hwframe+0x76/0xe0
> [  105.186649] RIP: 0033:0x7f166a97455d
> 
> Temporarily add the setting of skb->_skb_refdst before bpf_test_run to resolve the issue.
> 
> Fixes: 52f278774e79 ("bpf: implement BPF_LWT_ENCAP_IP mode in bpf_lwt_push_encap")
> Reported-by: Yinhao Hu <dddddd@hust.edu.cn>
> Reported-by: Kaiyan Mei <M202472210@hust.edu.cn>
> Closes: https://groups.google.com/g/hust-os-kernel-patches/c/8-a0kPpBW2s
> Signed-off-by: Yun Lu <luyun@kylinos.cn>
> Signed-off-by: Feng Yang <yangfeng@kylinos.cn>
> Tested-by: syzbot@syzkaller.appspotmail.com
> ---
>  net/bpf/test_run.c | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)
> 
> 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
}

Thanks,
Leon

>  	ret = bpf_test_run(prog, skb, repeat, &retval, &duration, false);
>  	if (ret)
>  		goto out;


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v10 bpf-next 2/2] selftests/bpf: Add selftests for the invocation of bpf_lwt_xmit_push_encap
  2026-03-04  9:44 ` [PATCH v10 bpf-next 2/2] selftests/bpf: Add selftests for the invocation of bpf_lwt_xmit_push_encap Feng Yang
@ 2026-03-04 10:33   ` Leon Hwang
  2026-03-05  1:11     ` Martin KaFai Lau
  0 siblings, 1 reply; 10+ messages in thread
From: Leon Hwang @ 2026-03-04 10:33 UTC (permalink / raw)
  To: Feng Yang, davem, edumazet, kuba, pabeni, horms, posk, ast,
	daniel, andrii, martin.lau, eddyz87
  Cc: bpf, netdev, linux-kernel, linux-kselftest

On 4/3/26 17:44, Feng Yang wrote:
> From: Feng Yang <yangfeng@kylinos.cn>
> 
> Calling bpf_lwt_xmit_push_encap will not cause a crash when dst is missing.
> 
> Signed-off-by: Feng Yang <yangfeng@kylinos.cn>
> ---
>  .../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";


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v10 bpf-next 0/2] Fix the null pointer dereference issue in bpf_lwt_xmit_push_encap
  2026-03-04  9:44 [PATCH v10 bpf-next 0/2] Fix the null pointer dereference issue in bpf_lwt_xmit_push_encap Feng Yang
  2026-03-04  9:44 ` [PATCH v10 bpf-next 1/2] bpf: test_run: " Feng Yang
  2026-03-04  9:44 ` [PATCH v10 bpf-next 2/2] selftests/bpf: Add selftests for the invocation of bpf_lwt_xmit_push_encap Feng Yang
@ 2026-03-05  1:10 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 10+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-03-05  1:10 UTC (permalink / raw)
  To: Feng Yang
  Cc: davem, edumazet, kuba, pabeni, horms, posk, ast, daniel, andrii,
	martin.lau, eddyz87, bpf, netdev, linux-kernel, linux-kselftest

Hello:

This series was applied to bpf/bpf-next.git (master)
by Martin KaFai Lau <martin.lau@kernel.org>:

On Wed,  4 Mar 2026 17:44:27 +0800 you wrote:
> From: Feng Yang <yangfeng@kylinos.cn>
> 
> Fix the null pointer dereference issue in bpf_lwt_xmit_push_encap
> 
> Changes in v10:
> - Optimization patch. Thanks, Martin KaFai Lau.
> - Link to v9: https://lore.kernel.org/all/20260303074423.172680-1-yangfeng59949@163.com/
> Changes in v9:
> - Use dst_hold() and skb_dst_set().
>   !skb_dst skip.
>   Move all changes into the IS_ENABLED(CONFIG_IPV6).
>   Use #if IS_ENABLED(CONFIG_IPV6); otherwise, a compilation error will occur when ipv6 is not enabled.
>   Thanks, Martin KaFai Lau.
> - Link to v8: https://lore.kernel.org/all/20260227082133.96951-1-yangfeng59949@163.com/
> Changes in v8:
> - set ret to an error code before goto out.
> - Link to v7: https://lore.kernel.org/all/20260226095156.117996-1-yangfeng59949@163.com/
> Changes in v7:
> - Use ip6_null_entry to avoid. Thanks, Martin KaFai Lau.
> Changes in v6:
> - Modify the bpf_lwt_xmit_push_encap function and add selftests for it.
>   Thanks, Martin KaFai Lau.
> - Link to v5: https://lore.kernel.org/all/20260210090657.86977-1-yangfeng59949@163.com/
> Changes in v5:
> - Refer to the bpf_lwt_xmit_reroute function to configure the dst parameter.
> - Link to v4: https://lore.kernel.org/all/20260209015111.28144-1-yangfeng59949@163.com/
> Changes in v4:
> - add rcu lock
> - Link to v3: https://lore.kernel.org/all/20260206055113.63476-1-yangfeng59949@163.com/
> Changes in v3:
> - use dst_init
> - Link to v2: https://lore.kernel.org/all/20260205092227.126665-1-yangfeng59949@163.com/
> Changes in v2:
> - Link to v1: https://lore.kernel.org/all/20260127084520.13890-1-luyun_611@163.com/
> 
> [...]

Here is the summary with links:
  - [v10,bpf-next,1/2] bpf: test_run: Fix the null pointer dereference issue in bpf_lwt_xmit_push_encap
    https://git.kernel.org/bpf/bpf-next/c/972787479ee7
  - [v10,bpf-next,2/2] selftests/bpf: Add selftests for the invocation of bpf_lwt_xmit_push_encap
    https://git.kernel.org/bpf/bpf-next/c/e8ae16d65ac6

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v10 bpf-next 2/2] selftests/bpf: Add selftests for the invocation of bpf_lwt_xmit_push_encap
  2026-03-04 10:33   ` Leon Hwang
@ 2026-03-05  1:11     ` Martin KaFai Lau
  2026-03-05  1:34       ` Leon Hwang
  0 siblings, 1 reply; 10+ messages in thread
From: Martin KaFai Lau @ 2026-03-05  1:11 UTC (permalink / raw)
  To: Leon Hwang, Feng Yang
  Cc: davem, edumazet, kuba, pabeni, horms, posk, ast, daniel, andrii,
	eddyz87, bpf, netdev, linux-kernel, linux-kselftest

On 3/4/26 2:33 AM, Leon Hwang wrote:
> On 4/3/26 17:44, Feng Yang wrote:
>> From: Feng Yang <yangfeng@kylinos.cn>
>>
>> Calling bpf_lwt_xmit_push_encap will not cause a crash when dst is missing.
>>
>> Signed-off-by: Feng Yang <yangfeng@kylinos.cn>
>> ---
>>   .../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.

It is actually the change from v9 to v10. I think leaving it separate is 
better. It is not testing the verifier, so logically it does not fit in 
verifier_lwt.c. It probably won't be the last fix for test_run+lwt, so 
separating it should be useful going forward.




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v10 bpf-next 1/2] bpf: test_run: Fix the null pointer dereference issue in bpf_lwt_xmit_push_encap
  2026-03-04 10:33   ` Leon Hwang
@ 2026-03-05  1:12     ` Martin KaFai Lau
  0 siblings, 0 replies; 10+ messages in thread
From: Martin KaFai Lau @ 2026-03-05  1:12 UTC (permalink / raw)
  To: Leon Hwang, Feng Yang
  Cc: davem, edumazet, kuba, pabeni, horms, posk, ast, daniel, andrii,
	eddyz87, bpf, netdev, linux-kernel, linux-kselftest

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.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v10 bpf-next 2/2] selftests/bpf: Add selftests for the invocation of bpf_lwt_xmit_push_encap
  2026-03-05  1:11     ` Martin KaFai Lau
@ 2026-03-05  1:34       ` Leon Hwang
  0 siblings, 0 replies; 10+ messages in thread
From: Leon Hwang @ 2026-03-05  1:34 UTC (permalink / raw)
  To: Martin KaFai Lau, Leon Hwang, Feng Yang
  Cc: davem, edumazet, kuba, pabeni, horms, posk, ast, daniel, andrii,
	eddyz87, bpf, netdev, linux-kernel, linux-kselftest

On 5/3/26 09:11, Martin KaFai Lau wrote:
> On 3/4/26 2:33 AM, Leon Hwang wrote:
>> On 4/3/26 17:44, Feng Yang wrote:
>>> From: Feng Yang <yangfeng@kylinos.cn>
>>>
>>> Calling bpf_lwt_xmit_push_encap will not cause a crash when dst is
>>> missing.
>>>
>>> Signed-off-by: Feng Yang <yangfeng@kylinos.cn>
>>> ---
>>>   .../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.
> 
> It is actually the change from v9 to v10. I think leaving it separate is

Got it.

> better. It is not testing the verifier, so logically it does not fit in
> verifier_lwt.c. It probably won't be the last fix for test_run+lwt, so
> separating it should be useful going forward.
> 

I realized it after sending the reply. Thanks for the explanation.

Thanks,
Leon


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2026-03-05  1:34 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-04  9:44 [PATCH v10 bpf-next 0/2] Fix the null pointer dereference issue in bpf_lwt_xmit_push_encap Feng Yang
2026-03-04  9:44 ` [PATCH v10 bpf-next 1/2] bpf: test_run: " Feng Yang
2026-03-04 10:30   ` bot+bpf-ci
2026-03-04 10:33   ` Leon Hwang
2026-03-05  1:12     ` Martin KaFai Lau
2026-03-04  9:44 ` [PATCH v10 bpf-next 2/2] selftests/bpf: Add selftests for the invocation of bpf_lwt_xmit_push_encap Feng Yang
2026-03-04 10:33   ` Leon Hwang
2026-03-05  1:11     ` Martin KaFai Lau
2026-03-05  1:34       ` Leon Hwang
2026-03-05  1:10 ` [PATCH v10 bpf-next 0/2] Fix the null pointer dereference issue in bpf_lwt_xmit_push_encap patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox