From patchwork Wed Dec 20 15:50:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 181705 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:24d3:b0:fb:cd0c:d3e with SMTP id r19csp2732845dyi; Wed, 20 Dec 2023 07:49:42 -0800 (PST) X-Google-Smtp-Source: AGHT+IEwakgwI8WNwo2eqPs9oIaKDjKV0Z5dEDCjINozk1YUTDLdMhFlJqI1ZNCCvkRASjNbhLlY X-Received: by 2002:a05:6a20:918b:b0:190:61a1:3c04 with SMTP id v11-20020a056a20918b00b0019061a13c04mr12261109pzd.0.1703087381969; Wed, 20 Dec 2023 07:49:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703087381; cv=none; d=google.com; s=arc-20160816; b=IG0CaXMYNyyEH08npDtWFxvSNJ8CjjkbxZmBGFElYNGBO3nhvLDQJC25i+KR+bZu4A y+yDSyOrV4UBb1VA1YpjpRZ4Y9cIui+mjUIf1sR6zDzFPr9Yo4KzIZDXOq/nkqHrhVWl p3DWRHscrlmON2XP3MzUVo4WsDQRJCBs4UhKDGp3V0w4dMgUwKwVEttRtw1kwxN6d9c2 RZsEeQw/3CofHgaDH5sjr0YPRiEwnCPmo9Rk18HOEoGN3mM5WmTPrxMPDMafh2d2HDbx dvRp9yLRSpNFr/xPYKNwi56rZL1Vk7Nlm2CAmwojhWzsNDckuxa87pAVvEO5b9YniHXw 7AdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:subject:cc:to:from :date; bh=/6FzHHpmraReAwhVj+aasqHqKGAsFnZqnyZmmTF0M8I=; fh=TPYfBUCvOHDfysRELIQISgfRl7g06qnHKEYuJ8Jxaek=; b=rfyZ4g7pHFkYABo1WrVtLHEFW4e6WbY707If7VSYfjwrDDmg2il/P9Pzs6nEtJ5lAQ YMfCzeCZUh8JoBzfvAOviXiv7cKOdU0+S9XkFH6ExTbKbsiHFfXuguleYhGoz508IW1w yU4Gr6b2Tb+pxLyiM+DYajw8S1eFk9Cf+cMMmf2YnbiGsP9BoRiT4eG/wI5hOGmQPCkn iRV3Wp27mZZocfcYdOWLY1RBtp9/JyjpNIZvqEhy4mU4gCWm041JtYb7Tjj+Ewgq19L4 zRaSMolwU5fR6zWPvvOpyaTtmhXKPJz9Y5DVb4VqvgMJOmk9AePjdVBQKOTwai3X+xPR DLaQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-7194-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-7194-ouuuleilei=gmail.com@vger.kernel.org" Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id e19-20020a17090a9a9300b0028b8bcd71a0si3191708pjp.49.2023.12.20.07.49.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 07:49:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-7194-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-7194-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-7194-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id A68D128474D for ; Wed, 20 Dec 2023 15:49:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4C8E541741; Wed, 20 Dec 2023 15:49:20 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C1D7540BF0; Wed, 20 Dec 2023 15:49:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 44827C433C8; Wed, 20 Dec 2023 15:49:17 +0000 (UTC) Date: Wed, 20 Dec 2023 10:50:17 -0500 From: Steven Rostedt To: LKML , Linux Trace Kernel Cc: Masami Hiramatsu , Mathieu Desnoyers , Dongliang Cui , Hongyu Jin , linux-fsdevel@vger.kernel.org Subject: [PATCH] eventfs: Have event files and directories default to parent uid and gid Message-ID: <20231220105017.1489d790@gandalf.local.home> X-Mailer: Claws Mail 3.19.1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785816554197919126 X-GMAIL-MSGID: 1785816554197919126 From: "Steven Rostedt (Google)" Dongliang reported: I found that in the latest version, the nodes of tracefs have been changed to dynamically created. This has caused me to encounter a problem where the gid I specified in the mounting parameters cannot apply to all files, as in the following situation: /data/tmp/events # mount | grep tracefs tracefs on /data/tmp type tracefs (rw,seclabel,relatime,gid=3012) gid 3012 = readtracefs /data/tmp # ls -lh total 0 -r--r----- 1 root readtracefs 0 1970-01-01 08:00 README -r--r----- 1 root readtracefs 0 1970-01-01 08:00 available_events ums9621_1h10:/data/tmp/events # ls -lh total 0 drwxr-xr-x 2 root root 0 2023-12-19 00:56 alarmtimer drwxr-xr-x 2 root root 0 2023-12-19 00:56 asoc It will prevent certain applications from accessing tracefs properly, I try to avoid this issue by making the following modifications. To fix this, have the files created default to taking the ownership of the parent dentry unless the ownership was previously set by the user. Link: https://lore.kernel.org/linux-trace-kernel/1703063706-30539-1-git-send-email-dongliang.cui@unisoc.com/ Reported-by: Dongliang Cui Signed-off-by: Steven Rostedt (Google) Acked-by: Masami Hiramatsu (Google) --- fs/tracefs/event_inode.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index 43e237864a42..2ccc849a5bda 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -148,7 +148,8 @@ static const struct file_operations eventfs_file_operations = { .release = eventfs_release, }; -static void update_inode_attr(struct inode *inode, struct eventfs_attr *attr, umode_t mode) +static void update_inode_attr(struct dentry *dentry, struct inode *inode, + struct eventfs_attr *attr, umode_t mode) { if (!attr) { inode->i_mode = mode; @@ -162,9 +163,13 @@ static void update_inode_attr(struct inode *inode, struct eventfs_attr *attr, um if (attr->mode & EVENTFS_SAVE_UID) inode->i_uid = attr->uid; + else + inode->i_uid = d_inode(dentry->d_parent)->i_uid; if (attr->mode & EVENTFS_SAVE_GID) inode->i_gid = attr->gid; + else + inode->i_gid = d_inode(dentry->d_parent)->i_gid; } /** @@ -206,7 +211,7 @@ static struct dentry *create_file(const char *name, umode_t mode, return eventfs_failed_creating(dentry); /* If the user updated the directory's attributes, use them */ - update_inode_attr(inode, attr, mode); + update_inode_attr(dentry, inode, attr, mode); inode->i_op = &eventfs_file_inode_operations; inode->i_fop = fop; @@ -242,7 +247,8 @@ static struct dentry *create_dir(struct eventfs_inode *ei, struct dentry *parent return eventfs_failed_creating(dentry); /* If the user updated the directory's attributes, use them */ - update_inode_attr(inode, &ei->attr, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO); + update_inode_attr(dentry, inode, &ei->attr, + S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO); inode->i_op = &eventfs_root_dir_inode_operations; inode->i_fop = &eventfs_file_operations;