Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp1974211rwn; Fri, 16 Sep 2022 03:57:25 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6XQuqrC8Pdz2J3wamzhkJm9Ic19Cgg2vnrTuLMHkc9bVyKxeSqHxDeWJExzl1eo3kWm/sP X-Received: by 2002:aa7:cdc8:0:b0:451:e570:882c with SMTP id h8-20020aa7cdc8000000b00451e570882cmr3493024edw.334.1663325845671; Fri, 16 Sep 2022 03:57:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663325845; cv=none; d=google.com; s=arc-20160816; b=ImY4Cp1+S64hYeBuPX3u7BOVtMPfv8juJ/goSpSmdqgs+de89UXfELxh7gIFo73DmN NdAB4uLkWsqKLhFbhq5QUmYlgbT+tjg3eFuCSq/mnBKOuYQp+ZNBcP6/DknI6mR+bvE9 zu19p1hlZUFO1qExYPdxZAZVziKeT+hctxMAbiWoGnLgtCTS/ml2QiaJ9OX89bO9ngEq 5iCrhq9F9lqL6A4pkf7Gw5NMvel/xpRvVGSnSNvPHFZHwkM+tG+ok8ifPqJ0Nt9LeQpp hvRwDMjqd9AIyCHcM2Fm5+yEWWd59oLZ/gA/qkYqGsw5eTynitdVxFaB/42ex9hXyFHl h71Q== 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=tLfIF+ogZzKWzyhJUY+5EdaPBwd84ytNa+3UjeUzmmo=; b=tq5Vbyjxyz/hj9+9++owd3u5tCTvgUcYsanvROZFEXAHDLTycAnuIcLWzb+C7ggpu6 ycLcBra2qoz/bwUSEi2ZopZ4qI9Pz/rWQxNpR93EbK+4gGkh/AgQkpeeLWSSV3aMu1Vy jlTap7hJil4dKfyKcChjtJ7f7T8u2mT8zi4P2ldyAxRkhbkWx2hQmcK46PLttBK5+P0G fNBm44cXj164ix5Zs//31yB9Omu+g1RPuBqM/hthrOK1OA46BjEymiokmIvQnfugp+p2 NYWHWWAI+gY7tgT3If3JMQ8dCBcv5bkKc0+elp4AvpoLWT5xnKVXZzXFdezjMaQd/t6h D6qA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=eyQ2bQjl; 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 u19-20020a50c053000000b0043dc410c5ddsi1812064edd.484.2022.09.16.03.56.59; Fri, 16 Sep 2022 03:57:25 -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=eyQ2bQjl; 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 S231394AbiIPKNf (ORCPT + 99 others); Fri, 16 Sep 2022 06:13:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60360 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230483AbiIPKMa (ORCPT ); Fri, 16 Sep 2022 06:12:30 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8EBEDA3D7D; Fri, 16 Sep 2022 03:10:06 -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 102F6629E7; Fri, 16 Sep 2022 10:10:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 268C2C433C1; Fri, 16 Sep 2022 10:09:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1663323000; bh=01W0zjQVqA35OWNap4lZMa7U31CITdvi1cGX39Kpkbw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eyQ2bQjl5w/SEN2takO+dywmdhTiO1Tjatf/g23kLUAJBe5gcCaHWegf90Ug7enHk kzDxFfC6KX4kBhs+zPRYlIS43ZR4StePjo2VfeVwHXdJddOyKq4uMDgxALR/tYcDG4 vtEtRw9AvbClK8YSy+/8Q7w2CeaPOnM3OeAKGnZo= 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.4 14/14] tracefs: Only clobber mode/uid/gid on remount if asked Date: Fri, 16 Sep 2022 12:08:21 +0200 Message-Id: <20220916100443.814559871@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220916100443.123226979@linuxfoundation.org> References: <20220916100443.123226979@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 @@ -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 *d 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 *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; } @@ -305,7 +320,7 @@ static int tracefs_remount(struct super_ 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 sb->s_op = &tracefs_super_operations; - tracefs_apply_options(sb); + tracefs_apply_options(sb, false); return 0;