From nobody Fri Dec 19 07:49:56 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 10563C54EE9 for ; Tue, 13 Sep 2022 14:18:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232990AbiIMOSa (ORCPT ); Tue, 13 Sep 2022 10:18:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44414 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232939AbiIMOR5 (ORCPT ); Tue, 13 Sep 2022 10:17:57 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E141275E1; Tue, 13 Sep 2022 07:12:45 -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 sin.source.kernel.org (Postfix) with ESMTPS id 0288DCE126A; Tue, 13 Sep 2022 14:11:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 02534C433C1; Tue, 13 Sep 2022 14:11:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1663078278; bh=s1/ZCp8gVewybkMOSq1CpY6XS87wnG57FxBySIRht4E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ueBf82Mw7aIxb7j6vXxStcXhgosgzhuDEZrq443+dAAVWdON7hmqtkX5ZbnBYnBq3 KqhwHNQctmkaQrSnVOfb0Howhn4EzHLGe+IHnOGEa4OS4cKFrzCnlcIHVFGojTfmkJ XqZv+JJfT7d0AmVLnQ4iEtYoqF13/lBp5GbLY/DA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Brian Norris , "Steven Rostedt (Google)" Subject: [PATCH 5.19 042/192] tracefs: Only clobber mode/uid/gid on remount if asked Date: Tue, 13 Sep 2022 16:02:28 +0200 Message-Id: <20220913140412.017270415@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913140410.043243217@linuxfoundation.org> References: <20220913140410.043243217@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 commit 47311db8e8f33011d90dee76b39c8886120cdda4 upstream. 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: Greg Kroah-Hartman --- fs/tracefs/inode.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) --- a/fs/tracefs/inode.c +++ b/fs/tracefs/inode.c @@ -141,6 +141,8 @@ struct tracefs_mount_opts { kuid_t uid; kgid_t gid; umode_t mode; + /* Opt_* bitfield. */ + unsigned int opts; }; =20 enum { @@ -241,6 +243,7 @@ static int tracefs_parse_options(char *d kgid_t gid; char *p; =20 + opts->opts =3D 0; opts->mode =3D TRACEFS_DEFAULT_MODE; =20 while ((p =3D strsep(&data, ",")) !=3D NULL) { @@ -275,24 +278,36 @@ static int tracefs_parse_options(char *d * 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 d_inode(sb->s_root); 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; } @@ -307,7 +322,7 @@ static int tracefs_remount(struct super_ if (err) goto fail; =20 - tracefs_apply_options(sb); + tracefs_apply_options(sb, true); =20 fail: return err; @@ -359,7 +374,7 @@ static int trace_fill_super(struct super =20 sb->s_op =3D &tracefs_super_operations; =20 - tracefs_apply_options(sb); + tracefs_apply_options(sb, false); =20 return 0;