Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp2002374rwn; Fri, 16 Sep 2022 04:22:45 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7lRd+5Q7+L52iPhdmMftSGxa1x8UNHcCCx5ZhXTn0LpXBPf5sMM+EXDMpzimeh43gzS/9D X-Received: by 2002:a05:6402:f0f:b0:451:1ecd:a61f with SMTP id i15-20020a0564020f0f00b004511ecda61fmr3503172eda.125.1663327364829; Fri, 16 Sep 2022 04:22:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663327364; cv=none; d=google.com; s=arc-20160816; b=OjGUD7eXWGih66+A895ymCThPXFsMQLXU4E6S/Tgv1LKuaMMmwOri0LauwQpcb2ccM QdzG4iF+At4mCe7r/Vrk0m+w+lKfJ8ThXtHg8UF9Qz6OWnGytjg8JX4satQ1QLCQ3hNe FpZcvr9fPvpd9Oy5d02fQggXwEO/y86u1ENDjoopk3NWThEvT3K0SI99EdC13qhTJTzS 361bk0HT4z+TOH16nXQxLuqcNUq0IWvrDSXuFDbKvdEKpXxSOwSznhLhvEIGWzgIuyjL +jbXzbFMU3iwnOb+pL7dA5h+b5jN+y5GQDe4sjd0Mi2L07z8RJ6dFDRSDGlEJ/flRsnc o0mw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=BhGG9JGnk5X+1E04gjHkhK6Ep2GbYGHNWzORQP30nVU=; b=dBpoMeWeEsdBbxbEwB/RCN7K11BPPlKOruSb99nMatrBbCeHi6B/Anmhjwquc7gJjO JkmASuaFTe1oKLbpyqRpAnjDMyitDD60ljs9NNYMlMVP5Xa1pWJpFHwLg2lbGtcENyY7 dNqyAohGQnlwNkBrJqA4ldOTrOffsaYVgisRr0BNGxC445ujgTKuqQY5sgA/mZsDAy7t cAe9Qd+jWgEikvqt/Xp4teU7Rvk4M0TKfmo1EmWzu3pMvL6LDVLQHVcieEL67eQouM6x PDggthGcHJwWAuo4v5uTTY+tW+jDqWNcyMkdVHh59xYBDktYIUO6qqkttp57Wqqn78qO E6JQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="DUo/H5DY"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id he11-20020a1709073d8b00b00780488c11bbsi5356077ejc.388.2022.09.16.04.22.19; Fri, 16 Sep 2022 04:22:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="DUo/H5DY"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231656AbiIPKRM (ORCPT + 99 others); Fri, 16 Sep 2022 06:17:12 -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-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.Iab6e5ea57963d6deca5311b27fb7226790d44406@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; }; enum { @@ -239,6 +241,7 @@ static int tracefs_parse_options(char *data, struct tracefs_mount_opts *opts) kgid_t gid; char *p; + opts->opts = 0; opts->mode = TRACEFS_DEFAULT_MODE; while ((p = strsep(&data, ",")) != NULL) { @@ -273,24 +276,36 @@ static int tracefs_parse_options(char *data, struct tracefs_mount_opts *opts) * but traditionally tracefs has ignored all mount options */ } + + opts->opts |= BIT(token); } return 0; } -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 = sb->s_fs_info; struct inode *inode = sb->s_root->d_inode; struct tracefs_mount_opts *opts = &fsi->mount_opts; - inode->i_mode &= ~S_IALLUGO; - inode->i_mode |= 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 &= ~S_IALLUGO; + inode->i_mode |= opts->mode; + } - inode->i_uid = opts->uid; + if (!remount || opts->opts & BIT(Opt_uid)) + inode->i_uid = opts->uid; - /* 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); + } return 0; } @@ -305,7 +320,7 @@ static int tracefs_remount(struct super_block *sb, int *flags, char *data) if (err) goto fail; - tracefs_apply_options(sb); + tracefs_apply_options(sb, true); fail: return err; @@ -357,7 +372,7 @@ static int trace_fill_super(struct super_block *sb, void *data, int silent) sb->s_op = &tracefs_super_operations; - tracefs_apply_options(sb); + tracefs_apply_options(sb, false); return 0; -- 2.35.1