[PATCH v2 net 2/2] selftests: vlan: add test for turn on hw offload with reorder_hdr off

Chen Zhen posted 2 patches 1 month ago
There is a newer version of this series
[PATCH v2 net 2/2] selftests: vlan: add test for turn on hw offload with reorder_hdr off
Posted by Chen Zhen 1 month ago
If vlan dev was created with reorder_hdr off and hw offload both
off but up with hw offload on, it will trigger a skb_panic bug in
vlan_dev_hard_header().

Add a test to automatically catch re-occurrence of the issue.

Suggested-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Chen Zhen <chenzhen126@huawei.com>
---
 tools/testing/selftests/net/Makefile          |  1 +
 .../testing/selftests/net/vlan_hw_offload.sh  | 30 +++++++++++++++++++
 2 files changed, 31 insertions(+)
 create mode 100755 tools/testing/selftests/net/vlan_hw_offload.sh

diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile
index b66ba04f19d9..8b50448a01cd 100644
--- a/tools/testing/selftests/net/Makefile
+++ b/tools/testing/selftests/net/Makefile
@@ -113,6 +113,7 @@ TEST_PROGS := \
 	veth.sh \
 	vlan_bridge_binding.sh \
 	vlan_hw_filter.sh \
+	vlan_hw_offload.sh \
 	vrf-xfrm-tests.sh \
 	vrf_route_leaking.sh \
 	vrf_strict_mode_test.sh \
diff --git a/tools/testing/selftests/net/vlan_hw_offload.sh b/tools/testing/selftests/net/vlan_hw_offload.sh
new file mode 100755
index 000000000000..5c49cc2525f2
--- /dev/null
+++ b/tools/testing/selftests/net/vlan_hw_offload.sh
@@ -0,0 +1,30 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+
+setup() {
+	ip link add veth0 type veth peer name veth1
+	ip link set veth0 up
+	ip link set veth1 up
+}
+
+cleanup() {
+	ip link delete veth0 2>/dev/null
+}
+
+#turn on hw offload and set up vlan dev with reorder_hdr off
+test_vlan_hw_offload_toggle_crash() {
+	ethtool -K veth0 tx-vlan-hw-insert off
+	ip link add link veth0 name veth0.10 type vlan id 10 reorder_hdr off
+	ethtool -K veth0 tx-vlan-hw-insert on
+
+	# set up vlan dev and it will trigger ndisc
+	ip link set veth0.10 up
+	ip -6 route show dev veth0.10
+}
+
+trap cleanup EXIT
+
+setup
+test_vlan_hw_offload_toggle_crash
+
+exit 0
-- 
2.33.0
Re: [PATCH v2 net 2/2] selftests: vlan: add test for turn on hw offload with reorder_hdr off
Posted by Simon Horman 1 month ago
On Wed, Jan 07, 2026 at 11:34:23AM +0800, Chen Zhen wrote:
> If vlan dev was created with reorder_hdr off and hw offload both
> off but up with hw offload on, it will trigger a skb_panic bug in
> vlan_dev_hard_header().
> 
> Add a test to automatically catch re-occurrence of the issue.
> 
> Suggested-by: Jakub Kicinski <kuba@kernel.org>
> Signed-off-by: Chen Zhen <chenzhen126@huawei.com>

Shellcheck warns that cleanup is never invoked.

  SC2329 (info): This function is never invoked. Check usage (or ignored if invoked indirectly).

But is only true if only direct invocations are taken into
account (which I assume is what shellcheck does).
cleanup is actually called on exit as it has been
registered to do so by trap.

In order to keep shellcheck quiet I'd recommend adding the following
to vlan_hw_offload.sh.

#shellcheck disable=SC2329

...