Skip to content

Commit

Permalink
selftests: netfilter: nft_queue.sh: add test for disappearing listener
Browse files Browse the repository at this point in the history
If userspace program exits while the queue its subscribed to has packets
those need to be discarded.

commit dc21c6c ("netfilter: nfnetlink_queue: acquire rcu_read_lock()
in instance_destroy_rcu()") fixed a (harmless) rcu splat that could be
triggered in this case.

Add a test case to cover this.

Signed-off-by: Florian Westphal <[email protected]>
Signed-off-by: Pablo Neira Ayuso <[email protected]>
  • Loading branch information
Florian Westphal authored and ummakynes committed Jun 28, 2024
1 parent e296302 commit 742ad97
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions tools/testing/selftests/net/netfilter/nft_queue.sh
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,42 @@ EOF
wait 2>/dev/null
}

test_queue_removal()
{
read tainted_then < /proc/sys/kernel/tainted

ip netns exec "$ns1" nft -f - <<EOF
flush ruleset
table ip filter {
chain output {
type filter hook output priority 0; policy accept;
ip protocol icmp queue num 0
}
}
EOF
ip netns exec "$ns1" ./nf_queue -q 0 -d 30000 -t "$timeout" &
local nfqpid=$!

busywait "$BUSYWAIT_TIMEOUT" nf_queue_wait "$ns1" 0

ip netns exec "$ns1" ping -w 2 -f -c 10 127.0.0.1 -q >/dev/null
kill $nfqpid

ip netns exec "$ns1" nft flush ruleset

if [ "$tainted_then" -ne 0 ];then
return
fi

read tainted_now < /proc/sys/kernel/tainted
if [ "$tainted_now" -eq 0 ];then
echo "PASS: queue program exiting while packets queued"
else
echo "TAINT: queue program exiting while packets queued"
ret=1
fi
}

ip netns exec "$nsrouter" sysctl net.ipv6.conf.all.forwarding=1 > /dev/null
ip netns exec "$nsrouter" sysctl net.ipv4.conf.veth0.forwarding=1 > /dev/null
ip netns exec "$nsrouter" sysctl net.ipv4.conf.veth1.forwarding=1 > /dev/null
Expand Down Expand Up @@ -413,5 +449,6 @@ test_tcp_localhost
test_tcp_localhost_connectclose
test_tcp_localhost_requeue
test_icmp_vrf
test_queue_removal

exit $ret

0 comments on commit 742ad97

Please sign in to comment.