From nobody Wed Feb 11 13:00:55 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 0202613AD3E; Thu, 23 May 2024 05:14:55 +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=1716441296; cv=none; b=VJJHVZFrtBp02mHbdG5214pNCrK5DNhCG8etBv7+VqG741ucXscWmgxTT/r+iUtXsXAEIQdDYtvuuLGZBrbTVToIfhefIPxZdM96nxjcmXG26h8U821Tzd+FcnmM5mNNfmF+DKDCXZhFQwfp07M69zgJfbX9pFJVSa7M4K8tu7g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716441296; c=relaxed/simple; bh=XqsroI8Co4hl2Eg1PmlEh9f9N1L0jJ02yHQWdWwApwQ=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=oHvRQP7GQ2M2OFrcLPRKzwQj2l3hOn45J6Kv2Sb9udiM3lRQRgcZG6kgWwrM2WbzV6fGfUm5iIZIV1JfZsplyNkAl4hq/HJxmDGIC5lutRBgB2Ff0GOdTuR2WYvBGb5fr9GU11dtmvIBXBRwMskPjeM935rNMg/j1Icwp7UaHHM= 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 86EF9C4AF0D; Thu, 23 May 2024 05:14:55 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1sA0nj-00000006W6f-3ijh; Thu, 23 May 2024 01:15:39 -0400 Message-ID: <20240523051539.754424703@goodmis.org> User-Agent: quilt/0.68 Date: Thu, 23 May 2024 01:14:28 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Masahiro Yamada , stable@vger.kernel.org Subject: [PATCH v2 3/4] eventfs: Update all the eventfs_inodes from the events descriptor References: <20240523051425.335105631@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 change to update the permissions of the eventfs_inode had the misconception that using the tracefs_inode would find all the eventfs_inodes that have been updated and reset them on remount. The problem with this approach is that the eventfs_inodes are freed when they are no longer used (basically the reason the eventfs system exists). When they are freed, the updated eventfs_inodes are not reset on a remount because their tracefs_inodes have been freed. Instead, since the events directory eventfs_inode always has a tracefs_inode pointing to it (it is not freed when finished), and the events directory has a link to all its children, have the eventfs_remount() function only operate on the events eventfs_inode and have it descend into its children updating their uid and gids. Link: https://lore.kernel.org/all/CAK7LNARXgaWw3kH9JgrnH4vK6fr8LDkNKf3wq8Nh= MWJrVwJyVQ@mail.gmail.com/ Cc: stable@vger.kernel.org Fixes: baa23a8d4360d ("tracefs: Reset permissions on remount if permissions= are options") Reported-by: Masahiro Yamada Signed-off-by: Steven Rostedt (Google) --- fs/tracefs/event_inode.c | 44 ++++++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index 5dfb1ccd56ea..129d0f54ba62 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -305,27 +305,27 @@ static const struct file_operations eventfs_file_oper= ations =3D { .llseek =3D generic_file_llseek, }; =20 -/* - * On a remount of tracefs, if UID or GID options are set, then - * the mount point inode permissions should be used. - * Reset the saved permission flags appropriately. - */ -void eventfs_remount(struct tracefs_inode *ti, bool update_uid, bool updat= e_gid) +static void eventfs_set_attrs(struct eventfs_inode *ei, bool update_uid, k= uid_t uid, + bool update_gid, kgid_t gid, int level) { - struct eventfs_inode *ei =3D ti->private; + struct eventfs_inode *ei_child; =20 - if (!ei) + /* Update events// */ + if (WARN_ON_ONCE(level > 3)) return; =20 if (update_uid) { ei->attr.mode &=3D ~EVENTFS_SAVE_UID; - ei->attr.uid =3D ti->vfs_inode.i_uid; + ei->attr.uid =3D uid; } =20 - if (update_gid) { ei->attr.mode &=3D ~EVENTFS_SAVE_GID; - ei->attr.gid =3D ti->vfs_inode.i_gid; + ei->attr.gid =3D gid; + } + + list_for_each_entry(ei_child, &ei->children, list) { + eventfs_set_attrs(ei_child, update_uid, uid, update_gid, gid, level + 1); } =20 if (!ei->entry_attrs) @@ -334,13 +334,31 @@ void eventfs_remount(struct tracefs_inode *ti, bool u= pdate_uid, bool update_gid) for (int i =3D 0; i < ei->nr_entries; i++) { if (update_uid) { ei->entry_attrs[i].mode &=3D ~EVENTFS_SAVE_UID; - ei->entry_attrs[i].uid =3D ti->vfs_inode.i_uid; + ei->entry_attrs[i].uid =3D uid; } if (update_gid) { ei->entry_attrs[i].mode &=3D ~EVENTFS_SAVE_GID; - ei->entry_attrs[i].gid =3D ti->vfs_inode.i_gid; + ei->entry_attrs[i].gid =3D gid; } } + +} + +/* + * On a remount of tracefs, if UID or GID options are set, then + * the mount point inode permissions should be used. + * Reset the saved permission flags appropriately. + */ +void eventfs_remount(struct tracefs_inode *ti, bool update_uid, bool updat= e_gid) +{ + struct eventfs_inode *ei =3D ti->private; + + /* Only the events directory does the updates */ + if (!ei || !ei->is_events || ei->is_freed) + return; + + eventfs_set_attrs(ei, update_uid, ti->vfs_inode.i_uid, + update_gid, ti->vfs_inode.i_gid, 0); } =20 /* Return the evenfs_inode of the "events" directory */ --=20 2.43.0