2
0
mirror of git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git synced 2025-09-04 20:19:47 +08:00
linux/tools/testing/vsock
Michal Luczaj 440c9d4887 vsock/test: Add test for SO_LINGER null ptr deref
Explicitly close() a TCP_ESTABLISHED (connectible) socket with SO_LINGER
enabled.

As for now, test does not verify if close() actually lingers.
On an unpatched machine, may trigger a null pointer dereference.

Tested-by: Luigi Leonardi <leonardi@redhat.com>
Reviewed-by: Luigi Leonardi <leonardi@redhat.com>
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
Signed-off-by: Michal Luczaj <mhal@rbox.co>
Link: https://patch.msgid.link/20250210-vsock-linger-nullderef-v3-2-ef6244d02b54@rbox.co
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2025-02-12 20:01:29 -08:00
..
.gitignore test/vsock: io_uring rx/tx tests 2023-10-15 13:19:43 +01:00
control.c vsock/test: verify socket options after setting them 2024-12-05 11:39:34 +01:00
control.h test/vsock: rework message bounds test 2023-01-12 12:53:54 +01:00
Makefile test/vsock: add install target 2024-07-13 15:17:35 -07:00
msg_zerocopy_common.c vsock/test: verify socket options after setting them 2024-12-05 11:39:34 +01:00
msg_zerocopy_common.h vsock/test: verify socket options after setting them 2024-12-05 11:39:34 +01:00
README vsock/test: Add README blurb about kmemleak usage 2024-12-23 10:28:00 -08:00
timeout.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 441 2019-06-05 17:37:17 +02:00
timeout.h VSOCK: add SPDX identifiers to vsock tests 2019-12-20 21:09:21 -08:00
util.c vsock/test: Introduce vsock_connect_fd() 2025-01-29 18:50:37 -08:00
util.h vsock/test: Introduce vsock_connect_fd() 2025-01-29 18:50:37 -08:00
vsock_diag_test.c vsock/test: print type for SOCK_SEQPACKET 2024-01-25 16:39:21 -08:00
vsock_perf.c vsock/test: verify socket options after setting them 2024-12-05 11:39:34 +01:00
vsock_test_zerocopy.c vsock/test: verify socket options after setting them 2024-12-05 11:39:34 +01:00
vsock_test_zerocopy.h test/vsock: MSG_ZEROCOPY flag tests 2023-10-15 13:19:42 +01:00
vsock_test.c vsock/test: Add test for SO_LINGER null ptr deref 2025-02-12 20:01:29 -08:00
vsock_uring_test.c vsock/test: verify socket options after setting them 2024-12-05 11:39:34 +01:00

AF_VSOCK test suite
-------------------
These tests exercise net/vmw_vsock/ host<->guest sockets for VMware, KVM, and
Hyper-V.

The following tests are available:

  * vsock_test - core AF_VSOCK socket functionality
  * vsock_diag_test - vsock_diag.ko module for listing open sockets

The following prerequisite steps are not automated and must be performed prior
to running tests:

1. Build the kernel, make headers_install, and build these tests.
2. Install the kernel and tests on the host.
3. Install the kernel and tests inside the guest.
4. Boot the guest and ensure that the AF_VSOCK transport is enabled.

Invoke test binaries in both directions as follows:

  # host=server, guest=client
  (host)# $TEST_BINARY --mode=server \
                       --control-port=1234 \
                       --peer-cid=3
  (guest)# $TEST_BINARY --mode=client \
                        --control-host=$HOST_IP \
                        --control-port=1234 \
                        --peer-cid=2

  # host=client, guest=server
  (guest)# $TEST_BINARY --mode=server \
                        --control-port=1234 \
                        --peer-cid=2
  (host)# $TEST_BINARY --mode=client \
                       --control-port=$GUEST_IP \
                       --control-port=1234 \
                       --peer-cid=3

Some tests are designed to produce kernel memory leaks. Leaks detection,
however, is deferred to Kernel Memory Leak Detector. It is recommended to enable
kmemleak (CONFIG_DEBUG_KMEMLEAK=y) and explicitly trigger a scan after each test
suite run, e.g.

  # echo clear > /sys/kernel/debug/kmemleak
  # $TEST_BINARY ...
  # echo "wait for any grace periods" && sleep 2
  # echo scan > /sys/kernel/debug/kmemleak
  # echo "wait for kmemleak" && sleep 5
  # echo scan > /sys/kernel/debug/kmemleak
  # cat /sys/kernel/debug/kmemleak

For more information see Documentation/dev-tools/kmemleak.rst.

vsock_perf utility
-------------------
'vsock_perf' is a simple tool to measure vsock performance. It works in
sender/receiver modes: sender connect to peer at the specified port and
starts data transmission to the receiver. After data processing is done,
it prints several metrics(see below).

Usage:
# run as sender
# connect to CID 2, port 1234, send 1G of data, tx buf size is 1M
./vsock_perf --sender 2 --port 1234 --bytes 1G --buf-size 1M

Output:
tx performance: A Gbits/s

Output explanation:
A is calculated as "number of bits to send" / "time in tx loop"

# run as receiver
# listen port 1234, rx buf size is 1M, socket buf size is 1G, SO_RCVLOWAT is 64K
./vsock_perf --port 1234 --buf-size 1M --vsk-size 1G --rcvlowat 64K

Output:
rx performance: A Gbits/s
total in 'read()': B sec
POLLIN wakeups: C
average in 'read()': D ns

Output explanation:
A is calculated as "number of received bits" / "time in rx loop".
B is time, spent in 'read()' system call(excluding 'poll()')
C is number of 'poll()' wake ups with POLLIN bit set.
D is B / C, e.g. average amount of time, spent in single 'read()'.