From nobody Fri Feb 13 18:35:06 2026 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 64EB912836E for ; Thu, 23 May 2024 21:23:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716499401; cv=none; b=aRQu8WE64kNUyYbX5gzS7OOvefXSlXYZMnJzaKQmLkwPbMrqW/HcMOoreILZDVGn6npAndndF+QnJATANr53QB+E1qjJ7lGYy1zOvb61SkfMsHPqjACTfWEVLaY+gvhve/doGjgcMEnkVJeZ/5ZlMbmE+PdC2tMLHWPuUVYBFUk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716499401; c=relaxed/simple; bh=b2rFVhUNdELSgple//yRUVKiuIFpt3ZKpCvrhw8yifE=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=tKqqqBcj5HIRxK3dwxnYciAYDpOhMu3WKeAdhdpiopfvDpVP3w6h5cUKBrM3wKbBqDq4chXRDhCFNYp5Txe7gIopMfRVm2l1WEfPqN9tCKKmMX5KJFOIyeCPxs83c77Q3MH/vWiQntH6BagdHwYxrju7WzIp3Zwn6rH8axFcr4E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 47848C4AF1D; Thu, 23 May 2024 21:23:21 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1sAFux-00000006lB9-0nme; Thu, 23 May 2024 17:24:07 -0400 Message-ID: <20240523212407.052080067@goodmis.org> User-Agent: quilt/0.68 Date: Thu, 23 May 2024 17:23:05 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Masahiro Yamada , Linus Torvalds Subject: [for-linus][PATCH 7/8] eventfs: Cleanup permissions in creation of inodes References: <20240523212258.883756004@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Steven Rostedt (Google)" The permissions being set during the creation of the inodes was updating eventfs_inode attributes as well. Those attributes should only be touched by the setattr or remount operations, not during the creation of inodes. The eventfs_inode attributes should only be used to set the inodes and should not be modified during the inode creation. Simplify the code and fix the situation by: 1) Removing the eventfs_find_events() and doing a simple lookup for the events descriptor in eventfs_get_inode() 2) Remove update_events_attr() as the attributes should only be used to update the inode and should not be modified here. 3) Add update_inode_attr() that uses the attributes to determine what the inode permissions should be. 4) As the parent_inode of the eventfs_root_inode structure is no longer needed, remove it. Now on creation, the inode gets the proper permissions without causing side effects to the ei->attr field. Link: https://lore.kernel.org/lkml/20240522165031.944088388@goodmis.org Cc: Linus Torvalds Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Andrew Morton Signed-off-by: Steven Rostedt (Google) --- fs/tracefs/event_inode.c | 90 ++++++++++------------------------------ 1 file changed, 23 insertions(+), 67 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index f32c6f7eb29f..320e49056d3a 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -37,7 +37,6 @@ static DEFINE_MUTEX(eventfs_mutex); =20 struct eventfs_root_inode { struct eventfs_inode ei; - struct inode *parent_inode; struct dentry *events_dir; }; =20 @@ -229,27 +228,6 @@ static int eventfs_set_attr(struct mnt_idmap *idmap, s= truct dentry *dentry, return ret; } =20 -static void update_events_attr(struct eventfs_inode *ei, struct super_bloc= k *sb) -{ - struct eventfs_root_inode *rei; - struct inode *parent; - - rei =3D get_root_inode(ei); - - /* Use the parent inode permissions unless root set its permissions */ - parent =3D rei->parent_inode; - - if (rei->ei.attr.mode & EVENTFS_SAVE_UID) - ei->attr.uid =3D rei->ei.attr.uid; - else - ei->attr.uid =3D parent->i_uid; - - if (rei->ei.attr.mode & EVENTFS_SAVE_GID) - ei->attr.gid =3D rei->ei.attr.gid; - else - ei->attr.gid =3D parent->i_gid; -} - static const struct inode_operations eventfs_dir_inode_operations =3D { .lookup =3D eventfs_root_lookup, .setattr =3D eventfs_set_attr, @@ -321,60 +299,30 @@ void eventfs_remount(struct tracefs_inode *ti, bool u= pdate_uid, bool update_gid) update_gid, ti->vfs_inode.i_gid, 0); } =20 -/* Return the evenfs_inode of the "events" directory */ -static struct eventfs_inode *eventfs_find_events(struct dentry *dentry) +static void update_inode_attr(struct inode *inode, umode_t mode, + struct eventfs_attr *attr, struct eventfs_root_inode *rei) { - struct eventfs_inode *ei; - - do { - // The parent is stable because we do not do renames - dentry =3D dentry->d_parent; - // ... and directories always have d_fsdata - ei =3D dentry->d_fsdata; - - /* - * If the ei is being freed, the ownership of the children - * doesn't matter. - */ - if (ei->is_freed) - return NULL; - - // Walk upwards until you find the events inode - } while (!ei->is_events); - - update_events_attr(ei, dentry->d_sb); - - return ei; -} - -static void update_inode_attr(struct dentry *dentry, struct inode *inode, - struct eventfs_attr *attr, umode_t mode) -{ - struct eventfs_inode *events_ei =3D eventfs_find_events(dentry); - - if (!events_ei) - return; - - inode->i_mode =3D mode; - inode->i_uid =3D events_ei->attr.uid; - inode->i_gid =3D events_ei->attr.gid; - - if (!attr) - return; - - if (attr->mode & EVENTFS_SAVE_MODE) + if (attr && attr->mode & EVENTFS_SAVE_MODE) inode->i_mode =3D attr->mode & EVENTFS_MODE_MASK; + else + inode->i_mode =3D mode; =20 - if (attr->mode & EVENTFS_SAVE_UID) + if (attr && attr->mode & EVENTFS_SAVE_UID) inode->i_uid =3D attr->uid; + else + inode->i_uid =3D rei->ei.attr.uid; =20 - if (attr->mode & EVENTFS_SAVE_GID) + if (attr && attr->mode & EVENTFS_SAVE_GID) inode->i_gid =3D attr->gid; + else + inode->i_gid =3D rei->ei.attr.gid; } =20 static struct inode *eventfs_get_inode(struct dentry *dentry, struct event= fs_attr *attr, umode_t mode, struct eventfs_inode *ei) { + struct eventfs_root_inode *rei; + struct eventfs_inode *pei; struct tracefs_inode *ti; struct inode *inode; =20 @@ -386,7 +334,16 @@ static struct inode *eventfs_get_inode(struct dentry *= dentry, struct eventfs_att ti->private =3D ei; ti->flags |=3D TRACEFS_EVENT_INODE; =20 - update_inode_attr(dentry, inode, attr, mode); + /* Find the top dentry that holds the "events" directory */ + do { + dentry =3D dentry->d_parent; + /* Directories always have d_fsdata */ + pei =3D dentry->d_fsdata; + } while (!pei->is_events); + + rei =3D get_root_inode(pei); + + update_inode_attr(inode, mode, attr, rei); =20 return inode; } @@ -823,7 +780,6 @@ struct eventfs_inode *eventfs_create_events_dir(const c= har *name, struct dentry // Note: we have a ref to the dentry from tracefs_start_creating() rei =3D get_root_inode(ei); rei->events_dir =3D dentry; - rei->parent_inode =3D d_inode(dentry->d_sb->s_root); =20 ei->entries =3D entries; ei->nr_entries =3D size; --=20 2.43.0