Skip to contentSkip to conversation

tests/overlay: add tests for mmap(2) and mprotect(2)

PATCH Superseded Ondrej Mosnacek 1 participant 1 message Apr 9 SELinux security module

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tests/overlay: add tests for mmap(2) and mprotect(2)

Add asserts that verify the expected behavior of mmap(2) and mprotect(2) on overlayfs files.

---
 policy/test_overlayfs.te    |  45 ++++++++++--
 tests/overlay/.gitignore    |   1 +
 tests/overlay/map_access.c  |  55 ++++++++++++++
 tests/overlay/setup-overlay |  10 ++-
 tests/overlay/test          | 138 +++++++++++++++++++++++++++++++++---
 5 files changed, 232 insertions(+), 17 deletions(-)
 create mode 100644 tests/overlay/map_access.c
policy/test_overlayfs.te +38 -7
index c09b577..787685c 100644
@@ -21,6 +21,12 @@ files_type(test_overlay_files_ro_t)
 type test_overlay_files_rwx_t;
 files_type(test_overlay_files_rwx_t)
 
+type test_overlay_files_map_ro_t;
+files_type(test_overlay_files_map_ro_t)
+
+type test_overlay_files_map_rwx_t;
+files_type(test_overlay_files_map_rwx_t)
+
 type test_overlay_mounter_files_t;
 files_type(test_overlay_mounter_files_t)
 
@@ -60,7 +66,11 @@ allow test_overlay_mounter_t test_overlay_files_ro_t:file mounton;
 allow test_overlay_mounter_t test_overlay_files_ro_t:filesystem { mount relabelfrom relabelto };
 allow test_overlay_mounter_t test_overlay_files_rwx_t:{dir file} mounton;
 allow test_overlay_mounter_t test_overlay_files_rwx_t:filesystem { mount relabelfrom relabelto };
-can_exec(test_overlay_mounter_t, test_overlay_files_ro_t)
+allow test_overlay_mounter_t test_overlay_files_map_ro_t:file mounton;
+allow test_overlay_mounter_t test_overlay_files_map_ro_t:filesystem { mount relabelfrom relabelto };
+allow test_overlay_mounter_t test_overlay_files_map_rwx_t:{dir file} mounton;
+allow test_overlay_mounter_t test_overlay_files_map_rwx_t:filesystem { mount relabelfrom relabelto };
+can_exec(test_overlay_mounter_t, test_overlay_files_map_ro_t)
 
 #
 # Mounter should be allowed to search/read r/o directories and files
@@ -70,10 +80,14 @@ read_files_pattern(test_overlay_mounter_t, test_overlay_files_ro_t, test_overlay
 read_chr_files_pattern(test_overlay_mounter_t, test_overlay_files_ro_t, test_overlay_files_ro_t)
 read_blk_files_pattern(test_overlay_mounter_t, test_overlay_files_ro_t, test_overlay_files_ro_t)
 read_lnk_files_pattern(test_overlay_mounter_t, test_overlay_files_ro_t, test_overlay_files_ro_t)
+list_dirs_pattern(test_overlay_mounter_t, test_overlay_files_map_ro_t, test_overlay_files_map_ro_t)
+read_files_pattern(test_overlay_mounter_t, test_overlay_files_map_ro_t, test_overlay_files_map_ro_t)
+allow_map(test_overlay_mounter_t, test_overlay_files_map_ro_t, file)
 allow test_overlay_mounter_t test_overlay_files_ro_t:dir mounton;
 allow test_overlay_mounter_t test_overlay_mounter_files_t:dir mounton;
-allow test_overlay_mounter_t test_overlay_files_rwx_t:filesystem unmount;
+allow test_overlay_mounter_t test_overlay_files_map_rwx_t:filesystem unmount;
 manage_files_pattern(test_overlay_mounter_t, test_overlay_mounter_files_t, test_overlay_mounter_files_t)
+allow_map(test_overlay_mounter_t, test_overlay_mounter_files_t, file)
 # Needed for transition
 manage_dirs_pattern(test_overlay_mounter_t, test_overlay_mounter_files_t, test_overlay_mounter_files_t)
 #
@@ -90,6 +104,10 @@ manage_dirs_pattern(test_overlay_mounter_t, test_overlay_files_rwx_t, test_overl
 manage_lnk_files_pattern(test_overlay_mounter_t, test_overlay_files_rwx_t, test_overlay_files_rwx_t)
 manage_sock_files_pattern(test_overlay_mounter_t, test_overlay_files_rwx_t, test_overlay_files_rwx_t)
 
+manage_files_pattern(test_overlay_mounter_t, test_overlay_files_map_rwx_t, test_overlay_files_map_rwx_t)
+manage_dirs_pattern(test_overlay_mounter_t, test_overlay_files_map_rwx_t, test_overlay_files_map_rwx_t)
+allow_map(test_overlay_mounter_t, test_overlay_files_map_rwx_t, file)
+
 manage_files_pattern(test_overlay_mounter_t, test_overlay_transition_files_t, test_overlay_transition_files_t)
 
 #
@@ -121,7 +139,11 @@ list_dirs_pattern(test_overlay_client_t, test_overlay_files_ro_t, test_overlay_f
 read_lnk_files_pattern(test_overlay_client_t, test_overlay_files_ro_t, test_overlay_files_ro_t)
 read_chr_files_pattern(test_overlay_client_t, test_overlay_files_ro_t, test_overlay_files_ro_t)
 read_sock_files_pattern(test_overlay_client_t, test_overlay_files_ro_t, test_overlay_files_ro_t)
-can_exec(test_overlay_client_t, test_overlay_files_ro_t)
+
+read_files_pattern(test_overlay_client_t, test_overlay_files_map_ro_t, test_overlay_files_map_ro_t)
+allow_map(test_overlay_client_t, test_overlay_files_map_ro_t, file)
+can_exec(test_overlay_client_t, test_overlay_files_map_ro_t)
+allow test_overlay_client_t test_overlay_files_map_ro_t:file entrypoint;
 
 #
 # Client should be allowed to execute/write/search/read r/w/x directories and files
@@ -131,15 +153,22 @@ manage_dirs_pattern(test_overlay_client_t, test_overlay_files_rwx_t, test_overla
 manage_lnk_files_pattern(test_overlay_client_t, test_overlay_files_rwx_t, test_overlay_files_rwx_t)
 rw_chr_files_pattern(test_overlay_client_t, test_overlay_files_rwx_t, test_overlay_files_rwx_t)
 manage_sock_files_pattern(test_overlay_client_t, test_overlay_files_rwx_t, test_overlay_files_rwx_t)
-can_exec(test_overlay_client_t, test_overlay_files_rwx_t)
-allow test_overlay_client_t test_overlay_files_rwx_t:file entrypoint;
+
+manage_files_pattern(test_overlay_client_t, test_overlay_files_map_rwx_t, test_overlay_files_map_rwx_t)
+manage_dirs_pattern(test_overlay_client_t, test_overlay_files_map_rwx_t, test_overlay_files_map_rwx_t)
+manage_lnk_files_pattern(test_overlay_client_t, test_overlay_files_map_rwx_t, test_overlay_files_map_rwx_t)
+rw_chr_files_pattern(test_overlay_client_t, test_overlay_files_map_rwx_t, test_overlay_files_map_rwx_t)
+manage_sock_files_pattern(test_overlay_client_t, test_overlay_files_map_rwx_t, test_overlay_files_map_rwx_t)
+allow_map(test_overlay_client_t, test_overlay_files_map_rwx_t, file)
+can_exec(test_overlay_client_t, test_overlay_files_map_rwx_t)
+allow test_overlay_client_t test_overlay_files_map_rwx_t:file entrypoint;
 
 #
 # Client needs to manage test_overlay_transition_files_t and transition on file named "transition"
 #
 manage_files_pattern(test_overlay_client_t, test_overlay_transition_files_t, test_overlay_transition_files_t)
 manage_dirs_pattern(test_overlay_client_t, test_overlay_transition_files_t, test_overlay_transition_files_t)
-filetrans_pattern(test_overlay_client_t, test_overlay_files_rwx_t, test_overlay_transition_files_t, file, "transition")
+filetrans_pattern(test_overlay_client_t, test_overlay_files_map_rwx_t, test_overlay_transition_files_t, file, "transition")
 
 #
 # Client needs to search test_file_t directory and execute tests
@@ -153,7 +182,9 @@ can_exec(test_overlay_client_t,test_file_t)
 #
 allow test_overlay_client_t test_overlay_files_rwx_t:file { relabelto relabelfrom };
 allow test_overlay_mounter_t test_overlay_files_rwx_t:file { relabelto relabelfrom };
-can_exec(test_overlay_mounter_t, test_overlay_files_rwx_t)
+allow test_overlay_client_t test_overlay_files_map_rwx_t:file { relabelto relabelfrom };
+allow test_overlay_mounter_t test_overlay_files_map_rwx_t:file { relabelto relabelfrom };
+can_exec(test_overlay_mounter_t, test_overlay_files_map_rwx_t)
 
 #
 # Server needs to manage socket files
tests/overlay/.gitignore +1 -0
index 73bc322..dc61362 100644
@@ -1 +1,2 @@
 access
+map_access
tests/overlay/map_access.c new file +55 -0

55 lines not on this page · raw message

tests/overlay/setup-overlay +8 -2
index 3f33499..ae817a1 100755
@@ -12,6 +12,8 @@ setup () {
     mkdir -p $BASEDIR/lower/readdir $BASEDIR/lower/writedir $BASEDIR/lower/noaccessdir $BASEDIR/lower/mounterdir
     echo read > $BASEDIR/lower/readfile
     echo write > $BASEDIR/lower/writefile
+    echo mapread > $BASEDIR/lower/mapreadfile
+    echo mapwrite > $BASEDIR/lower/mapwritefile
     echo noaccess > $BASEDIR/lower/noaccessfile
     echo client_nounlink > $BASEDIR/lower/client_nounlinkfile
     echo mounter > $BASEDIR/lower/mounterfile
@@ -35,7 +37,11 @@ setup () {
     chcon -t test_overlay_mounter_files_t $BASEDIR/lower/mounterfile $BASEDIR/lower/mounterdir $BASEDIR/lower/null_mounter
     # Label writefile on lower with a type that is writable by the client which
     # should allow copy up and write.
-    chcon -t test_overlay_files_rwx_t $BASEDIR/lower/writefile $BASEDIR/lower/writedir $BASEDIR/lower/null_write $BASEDIR/lower/transition $BASEDIR/lower/goodentrypoint
+    chcon -t test_overlay_files_rwx_t $BASEDIR/lower/writefile $BASEDIR/lower/writedir $BASEDIR/lower/null_write $BASEDIR/lower/transition
+    # Label mapreadfile and mapwritefile with the appropriate types that
+    # allow map access
+    chcon -t test_overlay_files_map_ro_t $BASEDIR/lower/mapreadfile $BASEDIR/lower/goodentrypoint
+    chcon -t test_overlay_files_map_rwx_t $BASEDIR/lower/mapwritefile
     # Create a directory per container.
     mkdir -p $BASEDIR/container1
 
@@ -48,7 +54,7 @@ setup () {
     # creation and to prevent permission problems when overlayfs
     # internally creates files on behalf of the current process.
     chcon -R -t test_overlay_mounter_files_t $BASEDIR/container1/work $BASEDIR/container1/merged
-    chcon -R -t test_overlay_files_rwx_t  $BASEDIR/container1/upper
+    chcon -R -t test_overlay_files_map_rwx_t  $BASEDIR/container1/upper
 }
 
 # Mount the overlays.
tests/overlay/test +130 -8

210 lines not on this page · raw message

Signature · 1 line
2.53.0