@@ -151,20 +151,20 @@ def test_ro_cgroup():
151151 add_all_namespaces (conf , cgroupns = cgroupns , netns = netns )
152152 mounts = [
153153 {
154- "destination" : "/sys" ,
155- "type" : "sysfs" ,
156- "source" : "sysfs" ,
157- "options" : [
158- "nosuid" ,
159- "noexec" ,
160- "nodev" ,
161- "ro"
162- ]
163- },
154+ "destination" : "/sys" ,
155+ "type" : "sysfs" ,
156+ "source" : "sysfs" ,
157+ "options" : [
158+ "nosuid" ,
159+ "noexec" ,
160+ "nodev" ,
161+ "ro"
162+ ]
163+ },
164164 {
165- "destination" : "/proc" ,
166- "type" : "proc"
167- }
165+ "destination" : "/proc" ,
166+ "type" : "proc"
167+ }
168168 ]
169169
170170 if has_cgroup_mount :
@@ -583,28 +583,28 @@ def test_cgroup_mount_without_netns():
583583 add_all_namespaces (conf , cgroupns = cgroupns , netns = False )
584584 mounts = [
585585 {
586- "destination" : "/proc" ,
587- "type" : "proc"
588- },
586+ "destination" : "/proc" ,
587+ "type" : "proc"
588+ },
589589 {
590- "destination" : "/sys" ,
591- "type" : "bind" ,
592- "source" : "/sys" ,
593- "options" : [
590+ "destination" : "/sys" ,
591+ "type" : "bind" ,
592+ "source" : "/sys" ,
593+ "options" : [
594594 "rprivate" ,
595595 "nosuid" ,
596596 "noexec" ,
597597 "nodev" ,
598598 "ro" ,
599599 "rbind"
600- ]
601- },
600+ ]
601+ },
602602 {
603603 "destination" : "/sys/fs/cgroup" ,
604604 "type" : "cgroup" ,
605605 "source" : "cgroup" ,
606606 "options" : [
607- "rprivate" ,
607+ "rprivate" ,
608608 "nosuid" ,
609609 "noexec" ,
610610 "nodev" ,
@@ -703,6 +703,81 @@ def test_mount_help():
703703
704704 return 0
705705
706+ def test_bind_mount_symlink_nofollow ():
707+ root = get_tests_root ()
708+ file_target = os .path .join (root , "a-file" )
709+ symlink = os .path .join (root , "a-symlink" )
710+ target_content = file_target
711+ file_target_content = "inside-the-file"
712+
713+ with open (file_target , "w+" ) as f :
714+ f .write (file_target_content )
715+
716+ os .symlink (target_content , symlink )
717+
718+ def prepare_rootfs (rootfs ):
719+ path = os .path .join (rootfs , "target" )
720+ os .symlink ("point-to-nowhere" , path )
721+
722+ for src_nofollow in [True , False ]:
723+ conf = base_config ()
724+ add_all_namespaces (conf )
725+ if src_nofollow :
726+ options = ["bind" , "dest-nofollow" , "src-nofollow" ]
727+ conf ['process' ]['args' ] = ['/init' , 'readlink' , '/target' ]
728+ expected = target_content
729+ else :
730+ options = ["bind" , "dest-nofollow" ]
731+ conf ['process' ]['args' ] = ['/init' , 'cat' , '/target' ]
732+ expected = file_target_content
733+
734+ mount_opt = {"destination" : "/target" , "type" : "bind" , "source" : symlink , "options" : options }
735+ conf ['mounts' ].append (mount_opt )
736+
737+ try :
738+ out , _ = run_and_get_output (conf , hide_stderr = True ,callback_prepare_rootfs = prepare_rootfs )
739+ sys .stderr .write ("got output %s\n " % out )
740+ if expected not in out :
741+ return - 1
742+ except Exception as e :
743+ sys .stderr .write ("error %s\n " % e )
744+ return - 1
745+
746+ return 0
747+
748+ def test_bind_mount_file_nofollow ():
749+ root = get_tests_root ()
750+ target = os .path .join (root , "a-file" )
751+ target_content = "content-of-file"
752+
753+ with open (target , "w+" ) as f :
754+ f .write (target_content )
755+
756+ def prepare_rootfs (rootfs ):
757+ path = os .path .join (rootfs , "symlink" )
758+ os .symlink ("point-to-nowhere" , path )
759+
760+ for src_nofollow in [True , False ]:
761+ conf = base_config ()
762+ conf ['process' ]['args' ] = ['/init' , 'cat' , '/symlink' ]
763+ add_all_namespaces (conf )
764+ if src_nofollow :
765+ options = ["bind" , "dest-nofollow" , "src-nofollow" ]
766+ else :
767+ options = ["bind" , "dest-nofollow" ]
768+ mount_opt = {"destination" : "/symlink" , "type" : "bind" , "source" : target , "options" : options }
769+ conf ['mounts' ].append (mount_opt )
770+
771+ try :
772+ out , _ = run_and_get_output (conf , hide_stderr = True ,callback_prepare_rootfs = prepare_rootfs )
773+ sys .stderr .write ("got output %s\n " % out )
774+ if target_content in out :
775+ return 0
776+ except Exception as e :
777+ sys .stderr .write ("error %s\n " % e )
778+ pass
779+ return - 1
780+
706781all_tests = {
707782 "mount-ro" : test_mount_ro ,
708783 "mount-rro" : test_mount_rro ,
@@ -732,6 +807,8 @@ def test_mount_help():
732807 "mount-ro-cgroup" : test_ro_cgroup ,
733808 "mount-cgroup-without-netns" : test_cgroup_mount_without_netns ,
734809 "mount-copy-symlink" : test_copy_symlink ,
810+ "mount-bind-mount-symlink-nofollow" : test_bind_mount_symlink_nofollow ,
811+ "mount-bind-mount-file-nofollow" : test_bind_mount_file_nofollow ,
735812 "mount-tmpfs-permissions" : test_mount_tmpfs_permissions ,
736813 "mount-add-remove-mounts" : test_add_remove_mounts ,
737814 "mount-help" : test_mount_help ,
0 commit comments