Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp1971421rwn; Fri, 16 Sep 2022 03:53:53 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6qlEP6XZi4Te+D2Tr3eCZMv0oi5XxcvE8Bmffx3YweyqetK1xTRbWmhhHeC5l8ONbLVqN/ X-Received: by 2002:a05:6402:1e96:b0:451:129e:1a2c with SMTP id f22-20020a0564021e9600b00451129e1a2cmr3575792edf.60.1663325633451; Fri, 16 Sep 2022 03:53:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663325633; cv=none; d=google.com; s=arc-20160816; b=02qCRWxQcHppEWGunw30U2CiZcNlCZGJMvYWe32CxskqZv5s20iVYRJWqGzU+H1gh1 meGUObf2a2vNbad4typ6vHiX1wvye0CV7PQtd+e1VOXKetwwxeJ3Zv1F0v0oqfd79EwL 6o43u/efE78655+UcDmjQgBMQjwYqyjwrK1HFbfkKrnfqR0Iudcy3HrktiI2fbGGEXcL M7ryu9E8sjA9ZHwLb1+E2kr9djzoWjzJRDhJtlg0C3nVgyk1i0e40cNeVtYRLllYlEGE 6noF/ioxBP3X+1yGP6RBmR0G8HI+NeA8VrrOgG5OpMwO3FZivf5dqTifPniTKxr8mr8U HHvg== 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=0IfkqWpcAqo0uyKFcs4a8VpeVIImG1CcxjC81Pal+XM=; b=WzS7ljED2GXJ33SKFwaTTLbduc1tb5tYy0HZPPVBgF4/ETUvHoDUDSd5388PnlekmV PodP/RTc7KO0kQsHH9a9OGwPeHy1bmKeT8W3FKU0oeTyFv1Ib2CEuas/guNcNKNQ289Y XLb24fkdYJSETZ7Tnf9hmITU+ozpB/RNE4yjy4VuOIVb5KwK+lNeWDFHuDdNdGVZ6z+e nDwrYolfojpjo3TDsnSKcohSlLXEiGt9WRHWjoKaDJ35D8U+uJoa+t8KDSBR7Pl3iCWq G1sEa9p7AnIzyOtJxtWGUgHxiimPyHZ9fdxvR+vdEF6QT7gePMcFRPlfjrbC8ea9inuq qyyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=iQvnqgSK; 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 fj4-20020a1709069c8400b00741d9a1e2dbsi16744000ejc.1004.2022.09.16.03.53.28; Fri, 16 Sep 2022 03:53:53 -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=iQvnqgSK; 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 S231230AbiIPKJf (ORCPT + 99 others); Fri, 16 Sep 2022 06:09:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231264AbiIPKIo (ORCPT ); Fri, 16 Sep 2022 06:08:44 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E003ABD5F; Fri, 16 Sep 2022 03:08:17 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 6EA7E629EB; Fri, 16 Sep 2022 10:08:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5FFB4C433C1; Fri, 16 Sep 2022 10:08:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1663322895; bh=LzV4F/MDDvs2PsNWQ4DkbtFiMj0IuYqEthpNVbJpyNo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iQvnqgSKwWb+PzagDmoxwl1RV0qWUbrrJqwuNP4PTx5MejQ3VFxXOlHLpl3m46744 m95tyOsZCwzDo4GQDq604dwk8zHnChL02AgB60L0Tf5NWxKU9U1QMiNth9/FF+DYt3 04f33pSeJVX9ivUnrzNpacFyC0s7Y3ruZlYRKvPM= 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 4.14 7/7] tracefs: Only clobber mode/uid/gid on remount if asked Date: Fri, 16 Sep 2022 12:07:59 +0200 Message-Id: <20220916100441.914631914@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220916100441.528608977@linuxfoundation.org> References: <20220916100441.528608977@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 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.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: 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 @@ -142,6 +142,8 @@ struct tracefs_mount_opts { kuid_t uid; kgid_t gid; umode_t mode; + /* Opt_* bitfield. */ + unsigned int opts; }; enum { @@ -242,6 +244,7 @@ static int tracefs_parse_options(char *d kgid_t gid; char *p; + opts->opts = 0; opts->mode = TRACEFS_DEFAULT_MODE; while ((p = strsep(&data, ",")) != NULL) { @@ -276,24 +279,36 @@ static int tracefs_parse_options(char *d * 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; } @@ -308,7 +323,7 @@ static int tracefs_remount(struct super_ if (err) goto fail; - tracefs_apply_options(sb); + tracefs_apply_options(sb, true); fail: return err; @@ -360,7 +375,7 @@ static int trace_fill_super(struct super sb->s_op = &tracefs_super_operations; - tracefs_apply_options(sb); + tracefs_apply_options(sb, false); return 0;