Skip to content

Commit 3ed61b8

Browse files
IurmanJPaolo Abeni
authored andcommitted
selftests: net: test for lwtunnel dst ref loops
As recently specified by commit 0ea09cb ("docs: netdev: add a note on selftest posting") in net-next, the selftest is therefore shipped in this series. However, this selftest does not really test this series. It needs this series to avoid crashing the kernel. What it really tests, thanks to kmemleak, is what was fixed by the following commits: - commit c71a192 ("net: ipv6: fix dst refleaks in rpl, seg6 and ioam6 lwtunnels") - commit 92191dd ("net: ipv6: fix dst ref loops in rpl, seg6 and ioam6 lwtunnels") - commit c64a072 ("net: ipv6: fix dst ref loop on input in seg6 lwt") - commit 13e55fb ("net: ipv6: fix dst ref loop on input in rpl lwt") - commit 0e7633d ("net: ipv6: fix dst ref loop in ila lwtunnel") - commit 5da15a9 ("net: ipv6: fix missing dst ref drop in ila lwtunnel") Signed-off-by: Justin Iurman <justin.iurman@uliege.be> Link: https://patch.msgid.link/20250314120048.12569-4-justin.iurman@uliege.be Signed-off-by: Paolo Abeni <pabeni@redhat.com>
1 parent 3e7a60b commit 3ed61b8

File tree

3 files changed

+249
-0
lines changed

3 files changed

+249
-0
lines changed

tools/testing/selftests/net/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ TEST_PROGS += vlan_bridge_binding.sh
101101
TEST_PROGS += bpf_offload.py
102102
TEST_PROGS += ipv6_route_update_soft_lockup.sh
103103
TEST_PROGS += busy_poll_test.sh
104+
TEST_PROGS += lwt_dst_cache_ref_loop.sh
104105

105106
# YNL files, must be before "include ..lib.mk"
106107
YNL_GEN_FILES := busy_poller netlink-dumps

tools/testing/selftests/net/config

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,5 @@ CONFIG_XFRM_INTERFACE=m
107107
CONFIG_XFRM_USER=m
108108
CONFIG_IP_NF_MATCH_RPFILTER=m
109109
CONFIG_IP6_NF_MATCH_RPFILTER=m
110+
CONFIG_IPV6_ILA=m
111+
CONFIG_IPV6_RPL_LWTUNNEL=y
Lines changed: 246 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,246 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: GPL-2.0+
3+
#
4+
# Author: Justin Iurman <justin.iurman@uliege.be>
5+
#
6+
# WARNING
7+
# -------
8+
# This is just a dummy script that triggers encap cases with possible dst cache
9+
# reference loops in affected lwt users (see list below). Some cases are
10+
# pathological configurations for simplicity, others are valid. Overall, we
11+
# don't want this issue to happen, no matter what. In order to catch any
12+
# reference loops, kmemleak MUST be used. The results alone are always blindly
13+
# successful, don't rely on them. Note that the following tests may crash the
14+
# kernel if the fix to prevent lwtunnel_{input|output|xmit}() reentry loops is
15+
# not present.
16+
#
17+
# Affected lwt users so far (please update accordingly if needed):
18+
# - ila_lwt (output only)
19+
# - ioam6_iptunnel (output only)
20+
# - rpl_iptunnel (both input and output)
21+
# - seg6_iptunnel (both input and output)
22+
23+
source lib.sh
24+
25+
check_compatibility()
26+
{
27+
setup_ns tmp_node &>/dev/null
28+
if [ $? != 0 ]; then
29+
echo "SKIP: Cannot create netns."
30+
exit $ksft_skip
31+
fi
32+
33+
ip link add name veth0 netns $tmp_node type veth \
34+
peer name veth1 netns $tmp_node &>/dev/null
35+
local ret=$?
36+
37+
ip -netns $tmp_node link set veth0 up &>/dev/null
38+
ret=$((ret + $?))
39+
40+
ip -netns $tmp_node link set veth1 up &>/dev/null
41+
ret=$((ret + $?))
42+
43+
if [ $ret != 0 ]; then
44+
echo "SKIP: Cannot configure links."
45+
cleanup_ns $tmp_node
46+
exit $ksft_skip
47+
fi
48+
49+
lsmod 2>/dev/null | grep -q "ila"
50+
ila_lsmod=$?
51+
[ $ila_lsmod != 0 ] && modprobe ila &>/dev/null
52+
53+
ip -netns $tmp_node route add 2001:db8:1::/64 \
54+
encap ila 1:2:3:4 csum-mode no-action ident-type luid \
55+
hook-type output \
56+
dev veth0 &>/dev/null
57+
58+
ip -netns $tmp_node route add 2001:db8:2::/64 \
59+
encap ioam6 trace prealloc type 0x800000 ns 0 size 4 \
60+
dev veth0 &>/dev/null
61+
62+
ip -netns $tmp_node route add 2001:db8:3::/64 \
63+
encap rpl segs 2001:db8:3::1 dev veth0 &>/dev/null
64+
65+
ip -netns $tmp_node route add 2001:db8:4::/64 \
66+
encap seg6 mode inline segs 2001:db8:4::1 dev veth0 &>/dev/null
67+
68+
ip -netns $tmp_node -6 route 2>/dev/null | grep -q "encap ila"
69+
skip_ila=$?
70+
71+
ip -netns $tmp_node -6 route 2>/dev/null | grep -q "encap ioam6"
72+
skip_ioam6=$?
73+
74+
ip -netns $tmp_node -6 route 2>/dev/null | grep -q "encap rpl"
75+
skip_rpl=$?
76+
77+
ip -netns $tmp_node -6 route 2>/dev/null | grep -q "encap seg6"
78+
skip_seg6=$?
79+
80+
cleanup_ns $tmp_node
81+
}
82+
83+
setup()
84+
{
85+
setup_ns alpha beta gamma &>/dev/null
86+
87+
ip link add name veth-alpha netns $alpha type veth \
88+
peer name veth-betaL netns $beta &>/dev/null
89+
90+
ip link add name veth-betaR netns $beta type veth \
91+
peer name veth-gamma netns $gamma &>/dev/null
92+
93+
ip -netns $alpha link set veth-alpha name veth0 &>/dev/null
94+
ip -netns $beta link set veth-betaL name veth0 &>/dev/null
95+
ip -netns $beta link set veth-betaR name veth1 &>/dev/null
96+
ip -netns $gamma link set veth-gamma name veth0 &>/dev/null
97+
98+
ip -netns $alpha addr add 2001:db8:1::2/64 dev veth0 &>/dev/null
99+
ip -netns $alpha link set veth0 up &>/dev/null
100+
ip -netns $alpha link set lo up &>/dev/null
101+
ip -netns $alpha route add 2001:db8:2::/64 \
102+
via 2001:db8:1::1 dev veth0 &>/dev/null
103+
104+
ip -netns $beta addr add 2001:db8:1::1/64 dev veth0 &>/dev/null
105+
ip -netns $beta addr add 2001:db8:2::1/64 dev veth1 &>/dev/null
106+
ip -netns $beta link set veth0 up &>/dev/null
107+
ip -netns $beta link set veth1 up &>/dev/null
108+
ip -netns $beta link set lo up &>/dev/null
109+
ip -netns $beta route del 2001:db8:2::/64
110+
ip -netns $beta route add 2001:db8:2::/64 dev veth1
111+
ip netns exec $beta \
112+
sysctl -wq net.ipv6.conf.all.forwarding=1 &>/dev/null
113+
114+
ip -netns $gamma addr add 2001:db8:2::2/64 dev veth0 &>/dev/null
115+
ip -netns $gamma link set veth0 up &>/dev/null
116+
ip -netns $gamma link set lo up &>/dev/null
117+
ip -netns $gamma route add 2001:db8:1::/64 \
118+
via 2001:db8:2::1 dev veth0 &>/dev/null
119+
120+
sleep 1
121+
122+
ip netns exec $alpha ping6 -c 5 -W 1 2001:db8:2::2 &>/dev/null
123+
if [ $? != 0 ]; then
124+
echo "SKIP: Setup failed."
125+
exit $ksft_skip
126+
fi
127+
128+
sleep 1
129+
}
130+
131+
cleanup()
132+
{
133+
cleanup_ns $alpha $beta $gamma
134+
[ $ila_lsmod != 0 ] && modprobe -r ila &>/dev/null
135+
}
136+
137+
run_ila()
138+
{
139+
if [ $skip_ila != 0 ]; then
140+
echo "SKIP: ila (output)"
141+
return
142+
fi
143+
144+
ip -netns $beta route del 2001:db8:2::/64
145+
ip -netns $beta route add 2001:db8:2:0:0:0:0:2/128 \
146+
encap ila 2001:db8:2:0 csum-mode no-action ident-type luid \
147+
hook-type output \
148+
dev veth1 &>/dev/null
149+
sleep 1
150+
151+
echo "TEST: ila (output)"
152+
ip netns exec $beta ping6 -c 2 -W 1 2001:db8:2::2 &>/dev/null
153+
sleep 1
154+
155+
ip -netns $beta route del 2001:db8:2:0:0:0:0:2/128
156+
ip -netns $beta route add 2001:db8:2::/64 dev veth1
157+
sleep 1
158+
}
159+
160+
run_ioam6()
161+
{
162+
if [ $skip_ioam6 != 0 ]; then
163+
echo "SKIP: ioam6 (output)"
164+
return
165+
fi
166+
167+
ip -netns $beta route change 2001:db8:2::/64 \
168+
encap ioam6 trace prealloc type 0x800000 ns 1 size 4 \
169+
dev veth1 &>/dev/null
170+
sleep 1
171+
172+
echo "TEST: ioam6 (output)"
173+
ip netns exec $beta ping6 -c 2 -W 1 2001:db8:2::2 &>/dev/null
174+
sleep 1
175+
}
176+
177+
run_rpl()
178+
{
179+
if [ $skip_rpl != 0 ]; then
180+
echo "SKIP: rpl (input)"
181+
echo "SKIP: rpl (output)"
182+
return
183+
fi
184+
185+
ip -netns $beta route change 2001:db8:2::/64 \
186+
encap rpl segs 2001:db8:2::2 \
187+
dev veth1 &>/dev/null
188+
sleep 1
189+
190+
echo "TEST: rpl (input)"
191+
ip netns exec $alpha ping6 -c 2 -W 1 2001:db8:2::2 &>/dev/null
192+
sleep 1
193+
194+
echo "TEST: rpl (output)"
195+
ip netns exec $beta ping6 -c 2 -W 1 2001:db8:2::2 &>/dev/null
196+
sleep 1
197+
}
198+
199+
run_seg6()
200+
{
201+
if [ $skip_seg6 != 0 ]; then
202+
echo "SKIP: seg6 (input)"
203+
echo "SKIP: seg6 (output)"
204+
return
205+
fi
206+
207+
ip -netns $beta route change 2001:db8:2::/64 \
208+
encap seg6 mode inline segs 2001:db8:2::2 \
209+
dev veth1 &>/dev/null
210+
sleep 1
211+
212+
echo "TEST: seg6 (input)"
213+
ip netns exec $alpha ping6 -c 2 -W 1 2001:db8:2::2 &>/dev/null
214+
sleep 1
215+
216+
echo "TEST: seg6 (output)"
217+
ip netns exec $beta ping6 -c 2 -W 1 2001:db8:2::2 &>/dev/null
218+
sleep 1
219+
}
220+
221+
run()
222+
{
223+
run_ila
224+
run_ioam6
225+
run_rpl
226+
run_seg6
227+
}
228+
229+
if [ "$(id -u)" -ne 0 ]; then
230+
echo "SKIP: Need root privileges."
231+
exit $ksft_skip
232+
fi
233+
234+
if [ ! -x "$(command -v ip)" ]; then
235+
echo "SKIP: Could not run test without ip tool."
236+
exit $ksft_skip
237+
fi
238+
239+
check_compatibility
240+
241+
trap cleanup EXIT
242+
243+
setup
244+
run
245+
246+
exit $ksft_pass

0 commit comments

Comments
 (0)