Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 91CE7C433EF for ; Tue, 7 Dec 2021 19:48:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238744AbhLGTwH (ORCPT ); Tue, 7 Dec 2021 14:52:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37078 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231562AbhLGTwG (ORCPT ); Tue, 7 Dec 2021 14:52:06 -0500 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84906C061574; Tue, 7 Dec 2021 11:48:35 -0800 (PST) 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 sin.source.kernel.org (Postfix) with ESMTPS id D6CF8CE1DEF; Tue, 7 Dec 2021 19:48:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D9939C341C1; Tue, 7 Dec 2021 19:48:29 +0000 (UTC) Date: Tue, 7 Dec 2021 14:48:28 -0500 From: Steven Rostedt To: LKML Cc: Kalesh Singh , Kees Cook , Ingo Molnar , Andrew Morton , Linus Torvalds , linux-fsdevel@vger.kernel.org, Al Viro , Greg Kroah-Hartman , Yabin Cui Subject: [PATCH] tracefs: Have new files inherit the ownership of their parent Message-ID: <20211207144828.3d356e26@gandalf.local.home> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Steven Rostedt (VMware)" If the tracefs system is set to a specific owner and group, then the files and directories that are created under them should inherit the owner and group of the parent. Cc: stable@vger.kernel.org Fixes: 4282d60689d4f ("tracefs: Add new tracefs file system") Reported-by: Kalesh Singh Reported: https://lore.kernel.org/all/CAC_TJve8MMAv+H_NdLSJXZUSoxOEq2zB_pVaJ9p=7H6Bu3X76g@mail.gmail.com/ Signed-off-by: Steven Rostedt (VMware) --- fs/tracefs/inode.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fs/tracefs/inode.c b/fs/tracefs/inode.c index f20f575cdaef..6b16d89cf187 100644 --- a/fs/tracefs/inode.c +++ b/fs/tracefs/inode.c @@ -488,6 +488,8 @@ struct dentry *tracefs_create_file(const char *name, umode_t mode, inode->i_mode = mode; inode->i_fop = fops ? fops : &tracefs_file_operations; inode->i_private = data; + inode->i_uid = dentry->d_parent->d_inode->i_uid; + inode->i_gid = dentry->d_parent->d_inode->i_gid; d_instantiate(dentry, inode); fsnotify_create(dentry->d_parent->d_inode, dentry); return end_creating(dentry); @@ -510,6 +512,8 @@ static struct dentry *__create_dir(const char *name, struct dentry *parent, inode->i_mode = S_IFDIR | S_IRWXU | S_IRUSR| S_IRGRP | S_IXUSR | S_IXGRP; inode->i_op = ops; inode->i_fop = &simple_dir_operations; + inode->i_uid = dentry->d_parent->d_inode->i_uid; + inode->i_gid = dentry->d_parent->d_inode->i_gid; /* directory inodes start off with i_nlink == 2 (for "." entry) */ inc_nlink(inode); -- 2.31.1