From nobody Tue Dec 16 11:05:26 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D7062C6FA8B for ; Fri, 16 Sep 2022 10:17:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231437AbiIPKRN (ORCPT ); Fri, 16 Sep 2022 06:17:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229892AbiIPKP5 (ORCPT ); Fri, 16 Sep 2022 06:15:57 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 350F9AED97; Fri, 16 Sep 2022 03:12:01 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 4D781B8253A; Fri, 16 Sep 2022 10:11:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CAF8FC433D6; Fri, 16 Sep 2022 10:11:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1663323062; bh=uew7UfIz61kBeo+FHcmBBaDsIPADVsObCmyCkHbFitc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DUo/H5DY5k5Of/gqcjjDm2U6/pCWY4s1F0ovIVUMWVmYrYB0Y3zl+3qK1c4xgB7uS fXykAMV9YQC3p3i+dof6hDhau74xTOH5xpEtgnGk0Zko+QLfOvq3gEiH2lgTuEFlLf G8WnvNKK5RNA0qtx9JGsSvM4UERhAyCz+XqTD4aA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Brian Norris , "Steven Rostedt (Google)" , Sasha Levin Subject: [PATCH 5.10 04/24] tracefs: Only clobber mode/uid/gid on remount if asked Date: Fri, 16 Sep 2022 12:08:29 +0200 Message-Id: <20220916100445.555302211@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220916100445.354452396@linuxfoundation.org> References: <20220916100445.354452396@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Brian Norris [ Upstream commit 47311db8e8f33011d90dee76b39c8886120cdda4 ] Users may have explicitly configured their tracefs permissions; we shouldn't overwrite those just because a second mount appeared. Only clobber if the options were provided at mount time. Note: the previous behavior was especially surprising in the presence of automounted /sys/kernel/debug/tracing/. Existing behavior: ## Pre-existing status: tracefs is 0755. # stat -c '%A' /sys/kernel/tracing/ drwxr-xr-x ## (Re)trigger the automount. # umount /sys/kernel/debug/tracing # stat -c '%A' /sys/kernel/debug/tracing/. drwx------ ## Unexpected: the automount changed mode for other mount instances. # stat -c '%A' /sys/kernel/tracing/ drwx------ New behavior (after this change): ## Pre-existing status: tracefs is 0755. # stat -c '%A' /sys/kernel/tracing/ drwxr-xr-x ## (Re)trigger the automount. # umount /sys/kernel/debug/tracing # stat -c '%A' /sys/kernel/debug/tracing/. drwxr-xr-x ## Expected: the automount does not change other mount instances. # stat -c '%A' /sys/kernel/tracing/ drwxr-xr-x Link: https://lkml.kernel.org/r/20220826174353.2.Iab6e5ea57963d6deca5311b27= fb7226790d44406@changeid Cc: stable@vger.kernel.org Fixes: 4282d60689d4f ("tracefs: Add new tracefs file system") Signed-off-by: Brian Norris Signed-off-by: Steven Rostedt (Google) Signed-off-by: Sasha Levin --- fs/tracefs/inode.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/fs/tracefs/inode.c b/fs/tracefs/inode.c index 8b7315c22f0d1..4b70571368526 100644 --- a/fs/tracefs/inode.c +++ b/fs/tracefs/inode.c @@ -139,6 +139,8 @@ struct tracefs_mount_opts { kuid_t uid; kgid_t gid; umode_t mode; + /* Opt_* bitfield. */ + unsigned int opts; }; =20 enum { @@ -239,6 +241,7 @@ static int tracefs_parse_options(char *data, struct tra= cefs_mount_opts *opts) kgid_t gid; char *p; =20 + opts->opts =3D 0; opts->mode =3D TRACEFS_DEFAULT_MODE; =20 while ((p =3D strsep(&data, ",")) !=3D NULL) { @@ -273,24 +276,36 @@ static int tracefs_parse_options(char *data, struct t= racefs_mount_opts *opts) * but traditionally tracefs has ignored all mount options */ } + + opts->opts |=3D BIT(token); } =20 return 0; } =20 -static int tracefs_apply_options(struct super_block *sb) +static int tracefs_apply_options(struct super_block *sb, bool remount) { struct tracefs_fs_info *fsi =3D sb->s_fs_info; struct inode *inode =3D sb->s_root->d_inode; struct tracefs_mount_opts *opts =3D &fsi->mount_opts; =20 - inode->i_mode &=3D ~S_IALLUGO; - inode->i_mode |=3D opts->mode; + /* + * On remount, only reset mode/uid/gid if they were provided as mount + * options. + */ + + if (!remount || opts->opts & BIT(Opt_mode)) { + inode->i_mode &=3D ~S_IALLUGO; + inode->i_mode |=3D opts->mode; + } =20 - inode->i_uid =3D opts->uid; + if (!remount || opts->opts & BIT(Opt_uid)) + inode->i_uid =3D opts->uid; =20 - /* Set all the group ids to the mount option */ - set_gid(sb->s_root, opts->gid); + if (!remount || opts->opts & BIT(Opt_gid)) { + /* Set all the group ids to the mount option */ + set_gid(sb->s_root, opts->gid); + } =20 return 0; } @@ -305,7 +320,7 @@ static int tracefs_remount(struct super_block *sb, int = *flags, char *data) if (err) goto fail; =20 - tracefs_apply_options(sb); + tracefs_apply_options(sb, true); =20 fail: return err; @@ -357,7 +372,7 @@ static int trace_fill_super(struct super_block *sb, voi= d *data, int silent) =20 sb->s_op =3D &tracefs_super_operations; =20 - tracefs_apply_options(sb); + tracefs_apply_options(sb, false); =20 return 0; =20 --=20 2.35.1