tracefs: Fix regression of setting group permissions at boot
Steven Rostedt
maintainerKalesh Singh <[email protected]>
Linus,
Fix tracefs mount options:
The commit 78ff64081949 ("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 recognizes 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.
Please pull the latest tracefs-v6.12-rc6 tree, which can be found at:
git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace.git
tracefs-v6.12-rc6
Tag SHA1: ba611308a30ae768483f77653d25ac6c98c618a7 Head SHA1: 8b55572e51805184353ee7d587c720a51818fb82
Kalesh Singh (3):
tracing: Fix tracefs mount options
tracing: Document tracefs gid mount option tracing/selftests: Add tracefs mount options test
----
fs/tracefs/inode.c | 12 ++- kernel/trace/trace.c | 4 + .../ftrace/test.d/00basic/mount_options.tc | 101 +++++++++++++++++++++ .../ftrace/test.d/00basic/test_ownership.tc | 16 +--- tools/testing/selftests/ftrace/test.d/functions | 25 +++++ 5 files changed, 142 insertions(+), 16 deletions(-) create mode 100644 tools/testing/selftests/ftrace/test.d/00basic/mount_options.tc
---------------------------
fs/tracefs/inode.c +9 -3
@@ -392,6 +392,9 @@ static int tracefs_reconfigure(struct fs_context *fc)struct tracefs_fs_info *sb_opts = sb->s_fs_info;struct tracefs_fs_info *new_opts = fc->s_fs_info; +if (!new_opts) +return 0 ; +sync_filesystem (sb);/* structure copy of new mount options to sb */ *sb_opts = *new_opts;
@@ -478,14 +481,17 @@ static int tracefs_fill_super(struct super_block *sb, struct fs_context *fc) sb->s_op = &tracefs_super_operations; sb->s_d_op = &tracefs_dentry_operations; -tracefs_apply_options (sb, false); -return 0 ; }static int tracefs_get_tree (struct fs_context *fc) { -return get_tree_single (fc, tracefs_fill_super); +int err =get_tree_single (fc, tracefs_fill_super); + +if (err) +return err; + +return tracefs_reconfigure (fc); }static void tracefs_free_fc (struct fs_context *fc)
kernel/trace/trace.c +4 -0
@@ -5501,6 +5501,10 @@ static const struct file_operations tracing_iter_fops = {static const char readme_msg[] ="tracing mini-HOWTO:\n\n" +"By default tracefs removes all OTH file permission bits.\n" +"When mounting tracefs an optional group id can be specified\n" +"which adds the group to every directory and file in tracefs:\n\n" +"\t e.g. mount -t tracefs [-o [gid=<gid>]] nodev /sys/kernel/tracing\n\n" "# echo 0 > tracing_on : quick way to disable tracing\n" "# echo 1 > tracing_on : quick way to re-enable tracing\n\n" " Important files:\n"
tools/testing/selftests/ftrace/test.d/00basic/mount_options.tc new file +101 -0
101 lines not on this page · raw message
tools/testing/selftests/ftrace/test.d/00basic/test_ownership.tc +3 -13
@@ -1,24 +1,14 @@ #!/bin/sh # SPDX-License-Identifier: GPL-2.0 # description: Test file and directory ownership changes for eventfs +# requires: "[gid=<gid>]":README original_group=`stat -c "%g" .` original_owner=`stat -c "%u" .` -mount_point=`stat -c '%m' .` +local mount_point=$(get_mount_point) -# If stat -c '%m' does not work (e.g. busybox) or failed, try to use the -# current working directory (which should be a tracefs) as the mount point. -if [ ! -d "$mount_point" ]; then - if mount | grep -qw $PWD ; then - mount_point=$PWD - else - # If PWD doesn't work, that is an environmental problem. - exit_unresolved - fi -fi - -mount_options=`mount | grep "$mount_point" | sed -e 's/.*(\(.*\)).*/\1/'` +mount_options=$(get_mnt_options "$mount_point") # find another owner and group that is not the original other_group=`tac /etc/group | grep -v ":$original_group:" | head -1 | cut -d: -f3`
tools/testing/selftests/ftrace/test.d/functions +25 -0
@@ -193,3 +193,28 @@ ftrace_errlog_check() { # err-prefix command-with-error-pos-by-^ command-file # " Command: " and "^\n" => 13 test $(expr 13 + $pos) -eq $N } + +# Helper to get the tracefs mount point +get_mount_point() { + local mount_point=`stat -c '%m' .` + + # If stat -c '%m' does not work (e.g. busybox) or failed, try to use the + # current working directory (which should be a tracefs) as the mount point. + if [ ! -d "$mount_point" ]; then + if mount | grep -qw "$PWD"; then + mount_point=$PWD + else + # If PWD doesn't work, that is an environmental problem. + exit_unresolved + fi + fi + echo "$mount_point" +} + +# Helper function to retrieve mount options for a given mount point +get_mnt_options() { + local mnt_point="$1" + local opts=$(mount | grep -m1 "$mnt_point" | sed -e 's/.*(\(.*\)).*/\1/') + + echo "$opts" +}
The pull request you sent on Wed, 6 Nov 2024 12:22:50 -0500:
The pull request you sent on Wed, 6 Nov 2024 12:22:50 -0500:
Quoted 1 line
git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace.gittracefs-v6.12-rc6
has been merged into torvalds/linux.git:
https://git.kernel.org/torvalds/c/7758b206117dab9894f0bcb8333f8e4731c5065a
Thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/prtracker.html