~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/ftrace/test.d/00basic/mount_options.tc

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 #!/bin/sh
  2 # SPDX-License-Identifier: GPL-2.0
  3 # description: Test tracefs GID mount option
  4 # requires: "[gid=<gid>]":README
  5 
  6 fail() {
  7         local msg="$1"
  8 
  9         echo "FAILED: $msg"
 10         exit_fail
 11 }
 12 
 13 find_alternate_gid() {
 14         local original_gid="$1"
 15         tac /etc/group | grep -v ":$original_gid:" | head -1 | cut -d: -f3
 16 }
 17 
 18 mount_tracefs_with_options() {
 19         local mount_point="$1"
 20         local options="$2"
 21 
 22         mount -t tracefs -o "$options" nodev "$mount_point"
 23 
 24         setup
 25 }
 26 
 27 unmount_tracefs() {
 28         local mount_point="$1"
 29 
 30         # Need to make sure the mount isn't busy so that we can umount it
 31         (cd $mount_point; finish_ftrace;)
 32 
 33         cleanup
 34 }
 35 
 36 create_instance() {
 37         local mount_point="$1"
 38         local instance="$mount_point/instances/$(mktemp -u test-XXXXXX)"
 39 
 40         mkdir "$instance"
 41         echo "$instance"
 42 }
 43 
 44 remove_instance() {
 45         local instance="$1"
 46 
 47         rmdir "$instance"
 48 }
 49 
 50 check_gid() {
 51         local mount_point="$1"
 52         local expected_gid="$2"
 53 
 54         echo "Checking permission group ..."
 55 
 56         cd "$mount_point"
 57 
 58         for file in "." "events" "events/sched" "events/sched/sched_switch" "events/sched/sched_switch/enable"; do
 59                 local gid=`stat -c "%g" $file`
 60                 if [ "$gid" -ne "$expected_gid" ]; then
 61                         cd - # Return to the previous working directory (tracefs root)
 62                         fail "$(realpath $file): Expected group $expected_gid; Got group $gid"
 63                 fi
 64         done
 65 
 66         cd - # Return to the previous working directory (tracefs root)
 67 }
 68 
 69 test_gid_mount_option() {
 70         local mount_point=$(get_mount_point)
 71         local mount_options=$(get_mnt_options "$mount_point")
 72         local original_group=$(stat -c "%g" .)
 73         local other_group=$(find_alternate_gid "$original_group")
 74 
 75         # Set up mount options with new GID for testing
 76         local new_options=`echo "$mount_options" | sed -e "s/gid=[0-9]*/gid=$other_group/"`
 77         if [ "$new_options" = "$mount_options" ]; then
 78                 new_options="$mount_options,gid=$other_group"
 79                 mount_options="$mount_options,gid=$original_group"
 80         fi
 81 
 82         # Unmount existing tracefs instance and mount with new GID
 83         unmount_tracefs "$mount_point"
 84         mount_tracefs_with_options "$mount_point" "$new_options"
 85 
 86         check_gid "$mount_point" "$other_group"
 87 
 88         # Check that files created after the mount inherit the GID
 89         local instance=$(create_instance "$mount_point")
 90         check_gid "$instance" "$other_group"
 91         remove_instance "$instance"
 92 
 93         # Unmount and remount with the original GID
 94         unmount_tracefs "$mount_point"
 95         mount_tracefs_with_options "$mount_point" "$mount_options"
 96         check_gid "$mount_point" "$original_group"
 97 }
 98 
 99 test_gid_mount_option
100 
101 exit 0

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php