Skip to contentSkip to conversation

Add AF_VSOCK SOCK_STREAM client/server tests

PATCH In review David Brazdil 2 participants 4 messages Mar 29, 2021 – May 10, 2021 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add AF_VSOCK SOCK_STREAM client/server tests

If AF_VSOCK and vsock_loopback are supported by the system, run tests that exchange a byte of data between a client and a server listening on VMADDR_CID_LOCAL and a random port.

Various permissions are removed from the client/server between runs and it is checked that the corresponding syscalls returned error.

A newly created vsock_socket inherits the SID of the current process and it is tested that the vsock_socket returned by accept() inherits the same SID from its parent.

SOCK_DGRAM is not tested as it is only supported in the VMCI transport.

These tests depend on an upstream commit 1f935e8e72ec ("selinux: vsock:
Set SID for socket returned by accept()"). It was first released in v5.12 and backported to all the stable branches.

---
This is also posted on GitHub as pull request #75:
https://github.com/SELinuxProject/selinux-testsuite/pull/75

The patch that fixes the vsock_socket bug has been merged to 5.12 and backported to 5.10-stable and 5.11-stable. Backport all the way back to 4.4-stable is awaiting merging here:
https://lkml.kernel.org/stable/[email protected]
Since the expectation is that all stable kernels will soon have the patch, I skipped a kernel version check in this test.

 policy/Makefile                  |   2 +-
 policy/test_vsock_socket.te      |  52 ++++++++++++
 tests/Makefile                   |   2 +-
 tests/vsock_socket/.gitignore    |   3 +
 tests/vsock_socket/Makefile      |   7 ++
 tests/vsock_socket/check_vsock.c |  47 +++++++++++
 tests/vsock_socket/client.c      | 129 ++++++++++++++++++++++++++++
 tests/vsock_socket/server.c      | 140 +++++++++++++++++++++++++++++++
 tests/vsock_socket/test          | 118 ++++++++++++++++++++++++++
 9 files changed, 498 insertions(+), 2 deletions(-)
 create mode 100644 policy/test_vsock_socket.te
 create mode 100644 tests/vsock_socket/.gitignore
 create mode 100644 tests/vsock_socket/Makefile
 create mode 100644 tests/vsock_socket/check_vsock.c
 create mode 100644 tests/vsock_socket/client.c
 create mode 100644 tests/vsock_socket/server.c
 create mode 100755 tests/vsock_socket/test
policy/Makefile +1 -1
index b092bb3..0b30a46 100644
@@ -27,7 +27,7 @@ TARGETS = \
 	test_setnice.te test_sigkill.te test_stat.te test_sysctl.te \
 	test_task_create.te test_task_getpgid.te test_task_getsched.te \
 	test_task_getsid.te test_task_setpgid.te test_task_setsched.te \
-	test_transition.te test_unix_socket.te \
+	test_transition.te test_unix_socket.te test_vsock_socket.te \
 	test_mmap.te test_overlayfs.te test_mqueue.te \
 	test_ibpkey.te test_atsecure.te test_cgroupfs.te test_userfaultfd.te
 
policy/test_vsock_socket.te new file +52 -0

52 lines not on this page · raw message

tests/Makefile +1 -1
index c19fcd7..fb95a97 100644
@@ -27,7 +27,7 @@ SUBDIRS:= domain_trans entrypoint execshare exectrace execute_no_trans \
 	task_setnice task_setscheduler task_getscheduler task_getsid \
 	task_getpgid task_setpgid file ioctl capable_file capable_net \
 	capable_sys dyntrans dyntrace bounds nnp_nosuid mmap unix_socket \
-	inet_socket overlay checkreqprot mqueue mac_admin atsecure
+	inet_socket overlay checkreqprot mqueue mac_admin atsecure vsock_socket
 
 ifeq ($(shell grep -q cap_userns $(POLDEV)/include/support/all_perms.spt && echo true),true)
 ifneq ($(shell ./kvercmp $$(uname -r) 4.7),-1)
tests/vsock_socket/.gitignore new file +3 -0
new file mode 100644
index 0000000..13eeb1b
@@ -0,0 +1,3 @@
+client
+server
+check_vsock
tests/vsock_socket/Makefile new file +7 -0
new file mode 100644
index 0000000..bf6ec7b
@@ -0,0 +1,7 @@
+TARGETS=client server check_vsock
+
+LDLIBS+= -lselinux
+
+all: $(TARGETS)
+clean:
+	rm -f $(TARGETS)
tests/vsock_socket/check_vsock.c new file +47 -0

47 lines not on this page · raw message

tests/vsock_socket/client.c new file +129 -0

129 lines not on this page · raw message

tests/vsock_socket/server.c new file +140 -0

140 lines not on this page · raw message

tests/vsock_socket/test new file +118 -0

118 lines not on this page · raw message

Signature · 1 line
2.30.2
#1 lore raw
Quoted 38 lines · David Brazdil

If AF_VSOCK and vsock_loopback are supported by the system, run tests that exchange a byte of data between a client and a server listening on VMADDR_CID_LOCAL and a random port.

Various permissions are removed from the client/server between runs and it is checked that the corresponding syscalls returned error.

A newly created vsock_socket inherits the SID of the current process and it is tested that the vsock_socket returned by accept() inherits the same SID from its parent.

SOCK_DGRAM is not tested as it is only supported in the VMCI transport.

These tests depend on an upstream commit 1f935e8e72ec ("selinux: vsock:
Set SID for socket returned by accept()"). It was first released in v5.12 and backported to all the stable branches.

---
This is also posted on GitHub as pull request #75:
https://github.com/SELinuxProject/selinux-testsuite/pull/75

The patch that fixes the vsock_socket bug has been merged to 5.12 and backported to 5.10-stable and 5.11-stable. Backport all the way back to 4.4-stable is awaiting merging here:
https://lkml.kernel.org/stable/[email protected]
Since the expectation is that all stable kernels will soon have the patch, I skipped a kernel version check in this test.

 policy/Makefile                  |   2 +-
 policy/test_vsock_socket.te      |  52 ++++++++++++
 tests/Makefile                   |   2 +-
 tests/vsock_socket/.gitignore    |   3 +
 tests/vsock_socket/Makefile      |   7 ++
 tests/vsock_socket/check_vsock.c |  47 +++++++++++
 tests/vsock_socket/client.c      | 129 ++++++++++++++++++++++++++++
 tests/vsock_socket/server.c      | 140 +++++++++++++++++++++++++++++++
 tests/vsock_socket/test          | 118 ++++++++++++++++++++++++++
Quoted 8 lines
 9 files changed, 498 insertions(+), 2 deletions(-)
 create mode 100644 policy/test_vsock_socket.te
 create mode 100644 tests/vsock_socket/.gitignore
 create mode 100644 tests/vsock_socket/Makefile
 create mode 100644 tests/vsock_socket/check_vsock.c
 create mode 100644 tests/vsock_socket/client.c
 create mode 100644 tests/vsock_socket/server.c
 create mode 100755 tests/vsock_socket/test

Sorry for the late review... I finally looked at the patch and all looks good, so I applied it (I used the version from the pull request):
https://github.com/SELinuxProject/selinux-testsuite/commit/0a3f86ab841efa0f2bbd048243a801915d6808ba

Since the bare F33 cloud image has quite an old kernel that doesn't have the fix, I had to tweak the CI scripts a little so that the CI passes:
https://github.com/SELinuxProject/selinux-testsuite/commit/aa799e6f1719d52b570a96229e3b207b9b3515d9

Thank you for the contribution!

Signature · 3 lines
Ondrej Mosnacek
Software Engineer, Linux Security - SELinux kernel
Red Hat, Inc.
#2 lore raw
Quoted 48 lines · Ondrej Mosnacek
Quoted 38 lines · David Brazdil

If AF_VSOCK and vsock_loopback are supported by the system, run tests that exchange a byte of data between a client and a server listening on VMADDR_CID_LOCAL and a random port.

Various permissions are removed from the client/server between runs and it is checked that the corresponding syscalls returned error.

A newly created vsock_socket inherits the SID of the current process and it is tested that the vsock_socket returned by accept() inherits the same SID from its parent.

SOCK_DGRAM is not tested as it is only supported in the VMCI transport.

These tests depend on an upstream commit 1f935e8e72ec ("selinux: vsock:
Set SID for socket returned by accept()"). It was first released in v5.12 and backported to all the stable branches.

---
This is also posted on GitHub as pull request #75:
https://github.com/SELinuxProject/selinux-testsuite/pull/75

The patch that fixes the vsock_socket bug has been merged to 5.12 and backported to 5.10-stable and 5.11-stable. Backport all the way back to 4.4-stable is awaiting merging here:
https://lkml.kernel.org/stable/[email protected]
Since the expectation is that all stable kernels will soon have the patch, I skipped a kernel version check in this test.

 policy/Makefile                  |   2 +-
 policy/test_vsock_socket.te      |  52 ++++++++++++
 tests/Makefile                   |   2 +-
 tests/vsock_socket/.gitignore    |   3 +
 tests/vsock_socket/Makefile      |   7 ++
 tests/vsock_socket/check_vsock.c |  47 +++++++++++
 tests/vsock_socket/client.c      | 129 ++++++++++++++++++++++++++++
 tests/vsock_socket/server.c      | 140 +++++++++++++++++++++++++++++++
 tests/vsock_socket/test          | 118 ++++++++++++++++++++++++++
Quoted 8 lines
 9 files changed, 498 insertions(+), 2 deletions(-)
 create mode 100644 policy/test_vsock_socket.te
 create mode 100644 tests/vsock_socket/.gitignore
 create mode 100644 tests/vsock_socket/Makefile
 create mode 100644 tests/vsock_socket/check_vsock.c
 create mode 100644 tests/vsock_socket/client.c
 create mode 100644 tests/vsock_socket/server.c
 create mode 100755 tests/vsock_socket/test
Quoted 4 lines

Sorry for the late review... I finally looked at the patch and all looks good, so I applied it (I used the version from the pull request):
https://github.com/SELinuxProject/selinux-testsuite/commit/0a3f86ab841efa0f2bbd048243a801915d6808ba

Actually, I missed that there were two compiler warnings when compiling the C code. They were trivial, so I pushed a fix:
https://github.com/SELinuxProject/selinux-testsuite/commit/db6c1cc4c9631e1b44ee5a0c40ec7ede68ab43f9

I also enabled -Werror in CI, so that they are more visible in the future:
https://github.com/SELinuxProject/selinux-testsuite/commit/0b78a9d433e8c4f956d18dc0db901f0a1a58c003

Signature · 3 lines
Ondrej Mosnacek
Software Engineer, Linux Security - SELinux kernel
Red Hat, Inc.
#3 lore raw
Quoted 49 lines · Ondrej Mosnacek
Quoted 48 lines · Ondrej Mosnacek
Quoted 46 lines · David Brazdil

If AF_VSOCK and vsock_loopback are supported by the system, run tests that exchange a byte of data between a client and a server listening on VMADDR_CID_LOCAL and a random port.

Various permissions are removed from the client/server between runs and it is checked that the corresponding syscalls returned error.

A newly created vsock_socket inherits the SID of the current process and it is tested that the vsock_socket returned by accept() inherits the same SID from its parent.

SOCK_DGRAM is not tested as it is only supported in the VMCI transport.

These tests depend on an upstream commit 1f935e8e72ec ("selinux: vsock:
Set SID for socket returned by accept()"). It was first released in v5.12 and backported to all the stable branches.

---
This is also posted on GitHub as pull request #75:
https://github.com/SELinuxProject/selinux-testsuite/pull/75

The patch that fixes the vsock_socket bug has been merged to 5.12 and backported to 5.10-stable and 5.11-stable. Backport all the way back to 4.4-stable is awaiting merging here:
https://lkml.kernel.org/stable/[email protected]
Since the expectation is that all stable kernels will soon have the patch, I skipped a kernel version check in this test.

 policy/Makefile                  |   2 +-
 policy/test_vsock_socket.te      |  52 ++++++++++++
 tests/Makefile                   |   2 +-
 tests/vsock_socket/.gitignore    |   3 +
 tests/vsock_socket/Makefile      |   7 ++
 tests/vsock_socket/check_vsock.c |  47 +++++++++++
 tests/vsock_socket/client.c      | 129 ++++++++++++++++++++++++++++
 tests/vsock_socket/server.c      | 140 +++++++++++++++++++++++++++++++
 tests/vsock_socket/test          | 118 ++++++++++++++++++++++++++
 9 files changed, 498 insertions(+), 2 deletions(-)
 create mode 100644 policy/test_vsock_socket.te
 create mode 100644 tests/vsock_socket/.gitignore
 create mode 100644 tests/vsock_socket/Makefile
 create mode 100644 tests/vsock_socket/check_vsock.c
 create mode 100644 tests/vsock_socket/client.c
 create mode 100644 tests/vsock_socket/server.c
 create mode 100755 tests/vsock_socket/test
Quoted 4 lines
Quoted 4 lines

Sorry for the late review... I finally looked at the patch and all looks good, so I applied it (I used the version from the pull request):
https://github.com/SELinuxProject/selinux-testsuite/commit/0a3f86ab841efa0f2bbd048243a801915d6808ba

Brilliant, thanks!

Quoted 4 lines

Actually, I missed that there were two compiler warnings when compiling the C code. They were trivial, so I pushed a fix:
https://github.com/SELinuxProject/selinux-testsuite/commit/db6c1cc4c9631e1b44ee5a0c40ec7ede68ab43f9

Oops, thanks for fixing those.

Quoted 9 lines

I also enabled -Werror in CI, so that they are more visible in the future:
https://github.com/SELinuxProject/selinux-testsuite/commit/0b78a9d433e8c4f956d18dc0db901f0a1a58c003

Signature · 3 lines
Ondrej Mosnacek
Software Engineer, Linux Security - SELinux kernel
Red Hat, Inc.