Skip to content

Commit 7758b20

Browse files
committed
Merge tag 'tracefs-v6.12-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace
Pull tracefs fixes from Steven Rostedt: "Fix tracefs mount options. Commit 78ff640 ("vfs: Convert tracefs to use the new mount API") broke the gid setting when set by fstab or other mount utility. It is ignored when it is set. Fix the code so that it recognises the option again and will honor the settings on mount at boot up. Update the internal documentation and create a selftest to make sure it doesn't break again in the future" * tag 'tracefs-v6.12-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace: tracing/selftests: Add tracefs mount options test tracing: Document tracefs gid mount option tracing: Fix tracefs mount options
2 parents b226d01 + 8b55572 commit 7758b20

File tree

5 files changed

+142
-16
lines changed

5 files changed

+142
-16
lines changed

fs/tracefs/inode.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,9 @@ static int tracefs_reconfigure(struct fs_context *fc)
392392
struct tracefs_fs_info *sb_opts = sb->s_fs_info;
393393
struct tracefs_fs_info *new_opts = fc->s_fs_info;
394394

395+
if (!new_opts)
396+
return 0;
397+
395398
sync_filesystem(sb);
396399
/* structure copy of new mount options to sb */
397400
*sb_opts = *new_opts;
@@ -478,14 +481,17 @@ static int tracefs_fill_super(struct super_block *sb, struct fs_context *fc)
478481
sb->s_op = &tracefs_super_operations;
479482
sb->s_d_op = &tracefs_dentry_operations;
480483

481-
tracefs_apply_options(sb, false);
482-
483484
return 0;
484485
}
485486

486487
static int tracefs_get_tree(struct fs_context *fc)
487488
{
488-
return get_tree_single(fc, tracefs_fill_super);
489+
int err = get_tree_single(fc, tracefs_fill_super);
490+
491+
if (err)
492+
return err;
493+
494+
return tracefs_reconfigure(fc);
489495
}
490496

491497
static void tracefs_free_fc(struct fs_context *fc)

kernel/trace/trace.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5501,6 +5501,10 @@ static const struct file_operations tracing_iter_fops = {
55015501

55025502
static const char readme_msg[] =
55035503
"tracing mini-HOWTO:\n\n"
5504+
"By default tracefs removes all OTH file permission bits.\n"
5505+
"When mounting tracefs an optional group id can be specified\n"
5506+
"which adds the group to every directory and file in tracefs:\n\n"
5507+
"\t e.g. mount -t tracefs [-o [gid=<gid>]] nodev /sys/kernel/tracing\n\n"
55045508
"# echo 0 > tracing_on : quick way to disable tracing\n"
55055509
"# echo 1 > tracing_on : quick way to re-enable tracing\n\n"
55065510
" Important files:\n"
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
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

tools/testing/selftests/ftrace/test.d/00basic/test_ownership.tc

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,14 @@
11
#!/bin/sh
22
# SPDX-License-Identifier: GPL-2.0
33
# description: Test file and directory ownership changes for eventfs
4+
# requires: "[gid=<gid>]":README
45

56
original_group=`stat -c "%g" .`
67
original_owner=`stat -c "%u" .`
78

8-
mount_point=`stat -c '%m' .`
9+
local mount_point=$(get_mount_point)
910

10-
# If stat -c '%m' does not work (e.g. busybox) or failed, try to use the
11-
# current working directory (which should be a tracefs) as the mount point.
12-
if [ ! -d "$mount_point" ]; then
13-
if mount | grep -qw $PWD ; then
14-
mount_point=$PWD
15-
else
16-
# If PWD doesn't work, that is an environmental problem.
17-
exit_unresolved
18-
fi
19-
fi
20-
21-
mount_options=`mount | grep "$mount_point" | sed -e 's/.*(\(.*\)).*/\1/'`
11+
mount_options=$(get_mnt_options "$mount_point")
2212

2313
# find another owner and group that is not the original
2414
other_group=`tac /etc/group | grep -v ":$original_group:" | head -1 | cut -d: -f3`

tools/testing/selftests/ftrace/test.d/functions

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,3 +193,28 @@ ftrace_errlog_check() { # err-prefix command-with-error-pos-by-^ command-file
193193
# " Command: " and "^\n" => 13
194194
test $(expr 13 + $pos) -eq $N
195195
}
196+
197+
# Helper to get the tracefs mount point
198+
get_mount_point() {
199+
local mount_point=`stat -c '%m' .`
200+
201+
# If stat -c '%m' does not work (e.g. busybox) or failed, try to use the
202+
# current working directory (which should be a tracefs) as the mount point.
203+
if [ ! -d "$mount_point" ]; then
204+
if mount | grep -qw "$PWD"; then
205+
mount_point=$PWD
206+
else
207+
# If PWD doesn't work, that is an environmental problem.
208+
exit_unresolved
209+
fi
210+
fi
211+
echo "$mount_point"
212+
}
213+
214+
# Helper function to retrieve mount options for a given mount point
215+
get_mnt_options() {
216+
local mnt_point="$1"
217+
local opts=$(mount | grep -m1 "$mnt_point" | sed -e 's/.*(\(.*\)).*/\1/')
218+
219+
echo "$opts"
220+
}

0 commit comments

Comments
 (0)