Skip to content

Commit ee9793b

Browse files
rostedtshuahkh
authored andcommitted
tracing/selftests: Add ownership modification tests for eventfs
As there were bugs found with the ownership of eventfs dynamic file creation. Add a test to test it. It will remount tracefs with a different gid and check the ownership of the eventfs directory, as well as the system and event directories. It will also check the event file directories. It then does a chgrp on each of these as well to see if they all get updated as expected. Then it remounts the tracefs file system back to the original group and makes sure that all the updated files and directories were reset back to the original ownership. It does the same for instances that change the ownership of he instance directory. Note, because the uid is not reset by a remount, it is tested for every file by switching it to a new owner and then back again. Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org> Tested-by: Masami Hiramatsu (Google) <mhiramat@kernel.org> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
1 parent 130a838 commit ee9793b

1 file changed

Lines changed: 114 additions & 0 deletions

File tree

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
#!/bin/sh
2+
# SPDX-License-Identifier: GPL-2.0
3+
# description: Test file and directory owership changes for eventfs
4+
5+
original_group=`stat -c "%g" .`
6+
original_owner=`stat -c "%u" .`
7+
8+
mount_point=`stat -c '%m' .`
9+
mount_options=`mount | grep "$mount_point" | sed -e 's/.*(\(.*\)).*/\1/'`
10+
11+
# find another owner and group that is not the original
12+
other_group=`tac /etc/group | grep -v ":$original_group:" | head -1 | cut -d: -f3`
13+
other_owner=`tac /etc/passwd | grep -v ":$original_owner:" | head -1 | cut -d: -f3`
14+
15+
# Remove any group ownership already
16+
new_options=`echo "$mount_options" | sed -e "s/gid=[0-9]*/gid=$other_group/"`
17+
18+
if [ "$new_options" = "$mount_options" ]; then
19+
new_options="$mount_options,gid=$other_group"
20+
mount_options="$mount_options,gid=$original_group"
21+
fi
22+
23+
canary="events/timer events/timer/timer_cancel events/timer/timer_cancel/format"
24+
25+
test() {
26+
file=$1
27+
test_group=$2
28+
29+
owner=`stat -c "%u" $file`
30+
group=`stat -c "%g" $file`
31+
32+
echo "testing $file $owner=$original_owner and $group=$test_group"
33+
if [ $owner -ne $original_owner ]; then
34+
exit_fail
35+
fi
36+
if [ $group -ne $test_group ]; then
37+
exit_fail
38+
fi
39+
40+
# Note, the remount does not update ownership so test going to and from owner
41+
echo "test owner $file to $other_owner"
42+
chown $other_owner $file
43+
owner=`stat -c "%u" $file`
44+
if [ $owner -ne $other_owner ]; then
45+
exit_fail
46+
fi
47+
48+
chown $original_owner $file
49+
owner=`stat -c "%u" $file`
50+
if [ $owner -ne $original_owner ]; then
51+
exit_fail
52+
fi
53+
54+
}
55+
56+
run_tests() {
57+
for d in "." "events" "events/sched" "events/sched/sched_switch" "events/sched/sched_switch/enable" $canary; do
58+
test "$d" $other_group
59+
done
60+
61+
chgrp $original_group events
62+
test "events" $original_group
63+
for d in "." "events/sched" "events/sched/sched_switch" "events/sched/sched_switch/enable" $canary; do
64+
test "$d" $other_group
65+
done
66+
67+
chgrp $original_group events/sched
68+
test "events/sched" $original_group
69+
for d in "." "events/sched/sched_switch" "events/sched/sched_switch/enable" $canary; do
70+
test "$d" $other_group
71+
done
72+
73+
chgrp $original_group events/sched/sched_switch
74+
test "events/sched/sched_switch" $original_group
75+
for d in "." "events/sched/sched_switch/enable" $canary; do
76+
test "$d" $other_group
77+
done
78+
79+
chgrp $original_group events/sched/sched_switch/enable
80+
test "events/sched/sched_switch/enable" $original_group
81+
for d in "." $canary; do
82+
test "$d" $other_group
83+
done
84+
}
85+
86+
mount -o remount,"$new_options" .
87+
88+
run_tests
89+
90+
mount -o remount,"$mount_options" .
91+
92+
for d in "." "events" "events/sched" "events/sched/sched_switch" "events/sched/sched_switch/enable" $canary; do
93+
test "$d" $original_group
94+
done
95+
96+
# check instances as well
97+
98+
chgrp $other_group instances
99+
100+
instance="$(mktemp -u test-XXXXXX)"
101+
102+
mkdir instances/$instance
103+
104+
cd instances/$instance
105+
106+
run_tests
107+
108+
cd ../..
109+
110+
rmdir instances/$instance
111+
112+
chgrp $original_group instances
113+
114+
exit 0

0 commit comments

Comments
 (0)