selftests/net: add txring_overwrite
Subsystems (3)
PATCH 1/1 selftests/net: add txring_overwrite
From: Willem de Bruijn <[email protected]>
Packet sockets with PACKET_TX_RING send skbs with user data in frags.
Before commit 5cd8d46ea156 ("packet: copy user buffers before orphan or clone") ring slots could be released prematurely, possibly allowing a process to overwrite data still in flight.
This test opens two packet sockets, one to send and one to read. The sender has a tx ring of one slot. It sends two packets with different payload, then reads both and verifies their payload.
Before the above commit, both receive calls return the same data as the send calls use the same buffer. From the commit, the clone needed for looping onto a packet socket triggers an skb_copy_ubufs to create a private copy. The separate sends each arrive correctly.
--- tools/testing/selftests/net/.gitignore | 1 + tools/testing/selftests/net/Makefile | 2 +- tools/testing/selftests/net/run_afpackettests | 10 + .../testing/selftests/net/txring_overwrite.c | 180 ++++++++++++++++++ 4 files changed, 192 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/net/txring_overwrite.c
tools/testing/selftests/net/.gitignore +1 -0
@@ -14,4 +14,5 @@ udpgso_bench_rx udpgso_bench_tx tcp_inq tls +txring_overwrite ip_defrag
tools/testing/selftests/net/Makefile +1 -1
@@ -11,7 +11,7 @@ TEST_PROGS += udpgro_bench.sh udpgro.sh TEST_PROGS_EXTENDED := in_netns.sh TEST_GEN_FILES = socket TEST_GEN_FILES += psock_fanout psock_tpacket msg_zerocopy -TEST_GEN_FILES += tcp_mmap tcp_inq psock_snd +TEST_GEN_FILES += tcp_mmap tcp_inq psock_snd txring_overwrite TEST_GEN_FILES += udpgso udpgso_bench_tx udpgso_bench_rx ip_defrag TEST_GEN_PROGS = reuseport_bpf reuseport_bpf_cpu reuseport_bpf_numa TEST_GEN_PROGS += reuseport_dualstack reuseaddr_conflict tls
tools/testing/selftests/net/run_afpackettests +10 -0
@@ -25,3 +25,13 @@ if [ $? -ne 0 ]; then else echo "[PASS]" fi + +echo "--------------------" +echo "running txring_overwrite test" +echo "--------------------" +./in_netns.sh ./txring_overwrite +if [ $? -ne 0 ]; then + echo "[FAIL]" +else + echo "[PASS]" +fi
tools/testing/selftests/net/txring_overwrite.c new file +180 -0
180 lines not on this page · raw message
Signature · 1 line
2.20.0.rc0.387.gc7a69e6b6c-goog
David Miller
maintainerFrom: Willem de Bruijn <[email protected]>
Date: Sat, 24 Nov 2018 21:09:26 -0500
Quoted 12 lines
From: Willem de Bruijn <[email protected]>
Packet sockets with
PACKET_TX_RINGsend skbs with user data in frags.Before commit
5cd8d46ea156("packet: copy user buffers before orphan or clone") ring slots could be released prematurely, possibly allowing a process to overwrite data still in flight.This test opens two packet sockets, one to send and one to read. The sender has a tx ring of one slot. It sends two packets with different payload, then reads both and verifies their payload.
Quoted 6 lines
Before the above commit, both receive calls return the same data as the send calls use the same buffer. From the commit, the clone needed for looping onto a packet socket triggers an
skb_copy_ubufsto create a private copy. The separate sends each arrive correctly.Signed-off-by Willem de Bruijn <[email protected]>
Thanks for following up on this, applied.