selinux-testsuite: Add watch_sb and watch_mount checks
cover selinux-testsuite: Add watch_sb and watch_mount checks
To test fanotify fs watch perms on 5.4+ (will also include tests/notify):
1) Extract the base module (base.cil):
semodule -c -E base
2) Edit the following definitions in base.cil to add watch permissions:
(common file (ioctl read write ....))
Add:
watch watch_mount watch_sb watch_with_perm watch_reads
(class filesystem (mount remount ....))
Add:
watch
3) Insert modified base module (inserts with default priority 400):
semodule -i base.cil
4) Backup, then edit the following definitions in:
/usr/share/selinux/devel/include/support/all_perms.spt
define(all_file_perms',{ ioctl read write ....
Add:
watch watch_mount watch_sb watch_with_perm watch_reads
define(all_dir_perms',{ ioctl read write ....
Add:
watch watch_mount watch_sb watch_with_perm watch_reads
define(all_filesystem_perms',{ mount remount ....
Add:
watch
5) 'make test' can now be run. tests/filesystem should run 81 tests, and tests/fs_filesystem should run 79 tests. However one test will fail on current kernels (fix in 5.7) with fs_filesystem because:
'Failed as kernel 5.x without "selinux: fix regression introduced by move_mount(2) syscall" patch'
NOTE: Do NOT leave the new base.cil active after tests, as the system may not reboot if in enforcing mode, as various watch permissions will be denied. Revert to the original (priority 100) as follows:
semodule -r base
make clean
make -C policy unload
Finally restore the original:/usr/share/selinux/devel/include/support/all_perms.spt
Richard Haines (1):
selinux-testsuite: Add watch_sb and watch_mount checks
policy/Makefile | 3 ++ policy/test_filesystem.te | 15 ------- policy/test_filesystem_notify.te | 60 ++++++++++++++++++++++++++ tests/filesystem/Filesystem.pm | 6 +-- tests/filesystem/fanotify_fs.c | 18 ++++++-- tests/filesystem/test | 74 ++++++++++++++++++++++++++++++-- tests/fs_filesystem/test | 74 ++++++++++++++++++++++++++++++-- 7 files changed, 221 insertions(+), 29 deletions(-) create mode 100644 policy/test_filesystem_notify.te
Signature · 1 line
2.24.1
PATCH 1/1 selinux-testsuite: Add watch_sb and watch_mount checks
Test watch_sb and watch_mount permissions.
The policy is contained in test_filesystem_notify.te as it can then be built if the policy supports the permissions.
--- policy/Makefile | 3 ++ policy/test_filesystem.te | 15 ------- policy/test_filesystem_notify.te | 60 ++++++++++++++++++++++++++ tests/filesystem/Filesystem.pm | 6 +-- tests/filesystem/fanotify_fs.c | 18 ++++++-- tests/filesystem/test | 74 ++++++++++++++++++++++++++++++-- tests/fs_filesystem/test | 74 ++++++++++++++++++++++++++++++-- 7 files changed, 221 insertions(+), 29 deletions(-) create mode 100644 policy/test_filesystem_notify.te
policy/Makefile +3 -0
@@ -118,6 +118,9 @@ ifeq ($(shell grep -q filesystem $(POLDEV)/include/support/all_perms.spt && echo TARGETS += test_filesystem.te ifeq ($(shell [ $(MOD_POL_VERS) -ge 11 -a $(POL_VERS) -ge 25 ] && echo true),true) TARGETS += test_filesystem_name_trans.te +ifeq ($(shell grep -q all_file_perms.*watch $(POLDEV)/include/support/all_perms.spt && echo true),true) +TARGETS+= test_filesystem_notify.te +endif endif endif
policy/test_filesystem.te +0 -15
@@ -292,21 +292,6 @@ dontaudit unconfined_t test_filesystem_filecon_t:file { getattr read }; allow test_filesystem_inode_setxattr_no_associate_t unconfined_t:dir { add_name write }; allow test_filesystem_inode_setxattr_no_associate_t unconfined_t:file { create relabelfrom relabelto }; -#################### Deny filesystem { watch } ###################### -# hooks.c selinux_path_notify() FILESYSTEM__WATCH -type test_filesystem_no_watch_t; -domain_type(test_filesystem_no_watch_t) -unconfined_runs_test(test_filesystem_no_watch_t) -typeattribute test_filesystem_no_watch_t testdomain; -typeattribute test_filesystem_no_watch_t filesystemdomain; - -allow test_filesystem_no_watch_t self:capability { sys_admin }; -allow test_filesystem_no_watch_t self:filesystem { associate relabelto mount unmount relabelfrom }; -allow test_filesystem_no_watch_t test_file_t:dir { mounton write remove_name rmdir }; -fs_mount_all_fs(test_filesystem_no_watch_t) -fs_relabelfrom_all_fs(test_filesystem_no_watch_t) -fs_associate(test_filesystem_no_watch_t) - ################# Test process { setfscreate } ############# type test_setfscreatecon_t; domain_type(test_setfscreatecon_t)
policy/test_filesystem_notify.te new file +60 -0
60 lines not on this page · raw message
tests/filesystem/Filesystem.pm +3 -3
@@ -8,16 +8,16 @@ sub check_config { $tst_count = 0; - # From kernel 5.5 support for fanotify(7) with filesystem { watch } + # From kernel 5.4 support for fanotify(7) LSM hooks $kvercur = `uname -r`; chomp($kvercur); - $kverminstream = "5.5"; + $kverminstream = "5.4"; $watch = 0; $result = `$base/../kvercmp $kvercur $kverminstream`; if ( $result > 0 && -e $fanotify_fs ) { $watch = 1; - $tst_count += 4; + $tst_count += 11; } $name_trans = 0;
tests/filesystem/fanotify_fs.c +15 -3
@@ -11,29 +11,38 @@#ifndef FAN_MARK_FILESYSTEM #define FAN_MARK_FILESYSTEM 0x00000100#endif +#ifndef FAN_MARK_MOUNT +#define FAN_MARK_MOUNT 0x00000010 +#endif static void print_usage (char *progname) {fprintf (stderr, -"usage: %s -t path [-v]\n" +"usage: %s -t path [-m] [-v]\n" "Where:\n\t" "-t Target mount point to mark\n\t" +"-m Set flag to FAN_MARK_MOUNT, default is FAN_MARK_FILESYSTEM\n\t" "-v Print information.\n" , progname);exit (-1 ); }int main (int argc,char *argv[]) { -int mask =FAN_OPEN , flags =FAN_MARK_ADD |FAN_MARK_FILESYSTEM ; +int mask =FAN_OPEN , flags;int fd, result, opt, save_err;char *context, *tgt =NULL ;bool verbose = false; -while ((opt =getopt (argc, argv,"t:v" )) !=-1 ) { + flags =0 ; + +while ((opt =getopt (argc, argv,"t:mv" )) !=-1 ) {switch (opt) {case 't' : tgt = optarg;break ; +case 'm' : + flags =FAN_MARK_ADD |FAN_MARK_MOUNT ; +break ;case 'v' : verbose = true;break ;
@@ -42,6 +51,9 @@ int main(int argc, char *argv[]) } } +if (!flags) + flags =FAN_MARK_ADD |FAN_MARK_FILESYSTEM ; +if (!tgt)print_usage (argv[0 ]);
tests/filesystem/test +70 -4
103 lines not on this page · raw message
tests/fs_filesystem/test +70 -4
103 lines not on this page · raw message
Signature · 1 line
2.24.1
Quoted 5 lines · Richard Haines
Test
watch_sbandwatch_mountpermissions.
The policy is contained in test_filesystem_notify.te as it can then be built if the policy supports the permissions.Signed-off-by Richard Haines <[email protected]>
Tested with and without the watch permissions defined in base.cil and all_perms.spt; everything worked as expected.
Quoted 10 lines
--- policy/Makefile | 3 ++ policy/test_filesystem.te | 15 ------- policy/test_filesystem_notify.te | 60 ++++++++++++++++++++++++++ tests/filesystem/Filesystem.pm | 6 +-- tests/filesystem/fanotify_fs.c | 18 ++++++-- tests/filesystem/test | 74 ++++++++++++++++++++++++++++++-- tests/fs_filesystem/test | 74 ++++++++++++++++++++++++++++++-- 7 files changed, 221 insertions(+), 29 deletions(-)create mode 100644 policy/test_filesystem_notify.te
[...]
Stephen Smalley
AppliedQuoted 5 lines · Stephen Smalley
Quoted 4 lines · Richard Haines
Test
watch_sbandwatch_mountpermissions.
The policy is contained in test_filesystem_notify.te as it can then be built if the policy supports the permissions.
Quoted 7 lines
Quoted 1 line
Signed-off-by Richard Haines <[email protected]>Tested with and without the watch permissions defined in base.cil and all_perms.spt; everything worked as expected.
Acked-by Stephen Smalley <[email protected]>Quoted 1 line
---
Applied.