Skip to contentSkip to conversation

selinux-testsuite: Add userfaultfd test

PATCH In review Lokesh Gidra 2 participants 4 messages Jan 8, 2021 – Jan 23, 2021 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 selinux-testsuite: Add userfaultfd test

Confirm SELinux policies are enforced on userfaultfd operations via secure anon-inode interface.

---
 policy/Makefile                 |   4 +-
 policy/test_userfaultfd.cil     |  52 ++++++++++
 policy/test_userfaultfd.te      |  52 ++++++++++
 tests/Makefile                  |   2 +-
 tests/userfaultfd/Makefile      |   5 +
 tests/userfaultfd/test          |  44 ++++++++
 tests/userfaultfd/userfaultfd.c | 177 ++++++++++++++++++++++++++++++++
 7 files changed, 333 insertions(+), 3 deletions(-)
 create mode 100644 policy/test_userfaultfd.cil
 create mode 100644 policy/test_userfaultfd.te
 create mode 100644 tests/userfaultfd/Makefile
 create mode 100755 tests/userfaultfd/test
 create mode 100644 tests/userfaultfd/userfaultfd.c
policy/Makefile +2 -2
index 6c49091..3e00875 100644
@@ -29,14 +29,14 @@ TARGETS = \
 	test_task_getsid.te test_task_setpgid.te test_task_setsched.te \
 	test_transition.te test_unix_socket.te \
 	test_mmap.te test_overlayfs.te test_mqueue.te \
-	test_ibpkey.te test_atsecure.te test_cgroupfs.te
+	test_ibpkey.te test_atsecure.te test_cgroupfs.te test_userfaultfd.te
 
 ifeq (x$(DISTRO),$(filter x$(DISTRO),xRHEL4 xRHEL5 xRHEL6))
 SUPPORTS_CIL = n
 endif
 
 ifeq ($(SUPPORTS_CIL),y)
-CIL_TARGETS = test_mlsconstrain.cil test_overlay_defaultrange.cil
+CIL_TARGETS = test_mlsconstrain.cil test_overlay_defaultrange.cil test_userfaultfd.cil
 ifeq ($(shell [ $(MAX_KERNEL_POLICY) -ge 32 ] && echo true),true)
 ifeq ($(shell [ $(POL_VERS) -ge 32 ] && echo true),true)
 # If other MLS tests get written this can be moved outside of the glblub test
policy/test_userfaultfd.cil new file +52 -0

52 lines not on this page · raw message

policy/test_userfaultfd.te new file +52 -0

52 lines not on this page · raw message

tests/Makefile +1 -1
index 4c00b5f..3871570 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 userfaultfd
 
 ifeq ($(shell grep -q cap_userns $(POLDEV)/include/support/all_perms.spt && echo true),true)
 ifneq ($(shell ./kvercmp $$(uname -r) 4.7),-1)
tests/userfaultfd/Makefile new file +5 -0
new file mode 100644
index 0000000..0daa759
@@ -0,0 +1,5 @@
+userfaultfd:
+	cc userfaultfd.c -o userfaultfd -pthread
+all: userfaultfd
+clean:
+	rm -f userfaultfd
tests/userfaultfd/test new file +44 -0

44 lines not on this page · raw message

tests/userfaultfd/userfaultfd.c new file +177 -0

177 lines not on this page · raw message

Signature · 1 line
2.28.0
#1 lore raw
Quoted 5 lines · Lokesh Gidra

Confirm SELinux policies are enforced on userfaultfd operations via secure anon-inode interface.

Quoted 14 lines
---
 policy/Makefile                 |   4 +-
 policy/test_userfaultfd.cil     |  52 ++++++++++
 policy/test_userfaultfd.te      |  52 ++++++++++
 tests/Makefile                  |   2 +-
 tests/userfaultfd/Makefile      |   5 +
 tests/userfaultfd/test          |  44 ++++++++
 tests/userfaultfd/userfaultfd.c | 177 ++++++++++++++++++++++++++++++++
 7 files changed, 333 insertions(+), 3 deletions(-)
 create mode 100644 policy/test_userfaultfd.cil
 create mode 100644 policy/test_userfaultfd.te
 create mode 100644 tests/userfaultfd/Makefile
 create mode 100755 tests/userfaultfd/test
 create mode 100644 tests/userfaultfd/userfaultfd.c

Sorry for the long delay... This version is already almost there, I just had to fix some style issues and added checks so that the test is skipped on old systems (when <linux/usefaultfd.h> doesn't exist or userfaultfd(2) returns -ENOSYS).

You can review the changes at
https://github.com/WOnder93/selinux-testsuite/commits/uffd3 and if you (or others) have no objections, I'll fold them into the patch and merge it with a note that it was edited by me.

If you prefer, you can also fetch the branch via the command-line:
git fetch https://github.com/WOnder93/selinux-testsuite uffd3:uffd3

Thank you for being patient with us :)

Signature · 3 lines
Ondrej Mosnacek
Software Engineer, Platform Security - SELinux kernel
Red Hat, Inc.
#2 lore raw
Quoted 22 lines · Ondrej Mosnacek
Quoted 5 lines · Lokesh Gidra

Confirm SELinux policies are enforced on userfaultfd operations via secure anon-inode interface.

Quoted 14 lines
---
 policy/Makefile                 |   4 +-
 policy/test_userfaultfd.cil     |  52 ++++++++++
 policy/test_userfaultfd.te      |  52 ++++++++++
 tests/Makefile                  |   2 +-
 tests/userfaultfd/Makefile      |   5 +
 tests/userfaultfd/test          |  44 ++++++++
 tests/userfaultfd/userfaultfd.c | 177 ++++++++++++++++++++++++++++++++
 7 files changed, 333 insertions(+), 3 deletions(-)
 create mode 100644 policy/test_userfaultfd.cil
 create mode 100644 policy/test_userfaultfd.te
 create mode 100644 tests/userfaultfd/Makefile
 create mode 100755 tests/userfaultfd/test
 create mode 100644 tests/userfaultfd/userfaultfd.c
Quoted 5 lines

Sorry for the long delay... This version is already almost there, I just had to fix some style issues and added checks so that the test is skipped on old systems (when <linux/usefaultfd.h> doesn't exist or userfaultfd(2) returns -ENOSYS).

Thanks so much for fixing these issues. And I apologize for missing them.

Quoted 4 lines

You can review the changes at
https://github.com/WOnder93/selinux-testsuite/commits/uffd3 and if you (or others) have no objections, I'll fold them into the patch and merge it with a note that it was edited by me.

LGTM

Quoted 5 lines

If you prefer, you can also fetch the branch via the command-line:
git fetch https://github.com/WOnder93/selinux-testsuite uffd3:uffd3

Thank you for being patient with us :)

Thank you for the reviews. It was a very learning experience for me :)

Quoted 6 lines

--
Ondrej Mosnacek
Software Engineer, Platform Security - SELinux kernel Red Hat, Inc.

#3 lore raw
Quoted 29 lines · Lokesh Gidra
Quoted 22 lines · Ondrej Mosnacek
Quoted 5 lines · Lokesh Gidra

Confirm SELinux policies are enforced on userfaultfd operations via secure anon-inode interface.

Quoted 14 lines
---
 policy/Makefile                 |   4 +-
 policy/test_userfaultfd.cil     |  52 ++++++++++
 policy/test_userfaultfd.te      |  52 ++++++++++
 tests/Makefile                  |   2 +-
 tests/userfaultfd/Makefile      |   5 +
 tests/userfaultfd/test          |  44 ++++++++
 tests/userfaultfd/userfaultfd.c | 177 ++++++++++++++++++++++++++++++++
 7 files changed, 333 insertions(+), 3 deletions(-)
 create mode 100644 policy/test_userfaultfd.cil
 create mode 100644 policy/test_userfaultfd.te
 create mode 100644 tests/userfaultfd/Makefile
 create mode 100755 tests/userfaultfd/test
 create mode 100644 tests/userfaultfd/userfaultfd.c
Quoted 5 lines

Sorry for the long delay... This version is already almost there, I just had to fix some style issues and added checks so that the test is skipped on old systems (when <linux/usefaultfd.h> doesn't exist or userfaultfd(2) returns -ENOSYS).

Quoted 8 lines

Thanks so much for fixing these issues. And I apologize for missing them.

Quoted 4 lines

You can review the changes at
https://github.com/WOnder93/selinux-testsuite/commits/uffd3 and if you (or others) have no objections, I'll fold them into the patch and merge it with a note that it was edited by me.

LGTM

Thanks, I have now merged the final patch:
https://github.com/SELinuxProject/selinux-testsuite/commit/2ea0079243635d7e4232deab7af8b90106474cec

Quoted 14 lines
Quoted 5 lines

If you prefer, you can also fetch the branch via the command-line:
git fetch https://github.com/WOnder93/selinux-testsuite uffd3:uffd3

Thank you for being patient with us :)

Thank you for the reviews. It was a very learning experience for me :)

Quoted 6 lines

--
Ondrej Mosnacek
Software Engineer, Platform Security - SELinux kernel Red Hat, Inc.

--
Ondrej Mosnacek
Software Engineer, Platform Security - SELinux kernel Red Hat, Inc.