Skip to contentSkip to conversation

selftests/net: add txring_overwrite

PATCH In review Willem de Bruijn 2 participants 2 messages Nov 25, 2018

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

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
index 8cf22b3c2563..7f57b916e6b2 100644
@@ -14,4 +14,5 @@ udpgso_bench_rx
 udpgso_bench_tx
 tcp_inq
 tls
+txring_overwrite
 ip_defrag
tools/testing/selftests/net/Makefile +1 -1
index eec359895feb..7aebbcaa91bf 100644
@@ -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
index bea079edc278..2dc95fda7ef7 100755
@@ -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
maintainer
#1 lore raw

From: 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_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.

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_ubufs to create a private copy. The separate sends each arrive correctly.

Thanks for following up on this, applied.