From patchwork Thu Dec 21 15:09:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 182290 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp476505dyi; Thu, 21 Dec 2023 07:12:17 -0800 (PST) X-Google-Smtp-Source: AGHT+IHQDUbq+0NDT5zQi3vsKnec/R/NF2Xm8ofOlNiLJGMI+YKYGanYAullL9ep7siUUygOQ5RC X-Received: by 2002:a05:6808:1910:b0:3b9:ee8a:b440 with SMTP id bf16-20020a056808191000b003b9ee8ab440mr27302514oib.47.1703171537776; Thu, 21 Dec 2023 07:12:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703171537; cv=none; d=google.com; s=arc-20160816; b=Uwi67q5W+HQi+TSZ6xhw8SYytGcN6IaVMgNLV0xrbKIrscYhKYDI2EVsan9WVlHeic 2/DZfF2LeRsdleOcNA+XgyLHbKCiwI+fomN23J3KBX2H1tNQDhwftFRZRwtjcDbgd/23 O620drWdr/TnnV0RHCmeuuGDuEGV8K5ftTJu+xYsYVR/pVSRSZxpHTxbJbzF26aya2rs gP7SD7j4oIchdSm/F8R7kIzkCr6zKs5KWZzuFxd3VHApDwgk9sWYFoaUJvaRnyQHZss9 5kc9FoVnGd+/rWoS5qgJWGEKXebr5mIThCvs57CM4lre94gh5xrnmliCq+qx7wSHOVBV B3gQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:subject:cc:to:from:date:user-agent:message-id; bh=MwPBwKrgtMFvGyAEOwAoOLY4/itsxR9ny86e4yfuQsQ=; fh=/fZ4Zlp6PXqhpzsIp1iHWR4kXEStFSwRrPTs9PRKbMk=; b=VwV6EBIIWqprOxYZcN0QYNr6dEkby2fzsKOBbszcjq2etnIMbQ56bAqWtKSAO42yvX quZ1snSJnr1qJ3G8Y9IDPOoa2Kv48WxUO4GoTDJUbxnGnSfu3uJr9vrlOoNEMlVDi86c aKLffnCR3TZiFaVmC+71dvbkkRRlTOKMfbmr0sax2qR/1CeQieE8MEoHjlT3tRTvH5SE yGXJliS0fLIbSjTeZOEEwmlmkXz5canqdoWWIAi7JBkM/RvLdRzLShRl8uDO8zXz/inS Bn/q6K8W1rpDUKGLYIxcvACNqNFP+TbAwdbFb/lhjVs6uxTx5xS293OKvfZd2MPP/v8r DYJA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-8624-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-8624-ouuuleilei=gmail.com@vger.kernel.org" Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id e7-20020a67eb87000000b004667be4e1a1si315257vso.44.2023.12.21.07.12.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 07:12:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-8624-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-8624-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-8624-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 852DF1C23D96 for ; Thu, 21 Dec 2023 15:12:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D96D755E5A; Thu, 21 Dec 2023 15:11:31 +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 5A47F539EC; Thu, 21 Dec 2023 15:11:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EEF66C433CD; Thu, 21 Dec 2023 15:11:29 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rGKiv-000000040Vo-3Vx0; Thu, 21 Dec 2023 10:12:33 -0500 Message-ID: <20231221151233.624191677@goodmis.org> User-Agent: quilt/0.67 Date: Thu, 21 Dec 2023 10:09:24 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , stable@vger.kernel.org, Hongyu Jin , Dongliang Cui Subject: [for-linus][PATCH 2/3] eventfs: Have event files and directories default to parent uid and gid References: <20231221150922.017965539@goodmis.org> 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: 1785904798064419678 X-GMAIL-MSGID: 1785904798064419678 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/ Link: https://lore.kernel.org/linux-trace-kernel/20231220105017.1489d790@gandalf.local.home Cc: stable@vger.kernel.org Cc: Mathieu Desnoyers Cc: Hongyu Jin Fixes: 28e12c09f5aa0 ("eventfs: Save ownership and mode") Acked-by: Masami Hiramatsu (Google) Reported-by: Dongliang Cui Signed-off-by: Steven Rostedt (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;