From: Steven Rostedt <rostedt@kernel.org>
To: linux-kernel@vger.kernel.org
Cc: Masami Hiramatsu <mhiramat@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
Andrew Morton <akpm@linux-foundation.org>,
stable@vger.kernel.org,
Jeff Barnes <jeffbarnes@linux.microsoft.com>,
Beau Belgrave <beaub@linux.microsoft.com>
Subject: [for-linus][PATCH 1/5] tracing/user_events: Fail fork when event state duplication fails
Date: Fri, 27 Nov 2026 13:42:04 -0500 [thread overview]
Message-ID: <20261127184241.554209298@kernel.org> (raw)
In-Reply-To: 20261127184203.439481361@kernel.org
From: Jeff Barnes <jeffbarnes@linux.microsoft.com>
Registered user events are retained across fork, but duplicating their
state for a child with a separate mm can fail. Both user_event_mm_dup() and
user_events_fork() currently return void, so allocation failure silently
creates a child without the inherited registration state.
The child can consequently retain a stale copy-on-write enable word and
miss later event enable and disable updates.
Return an error from user_event_mm_dup() and user_events_fork(), and
perform the duplication in copy_process() while failure can still be
unwound. Return -ENOMEM when the child user_event_mm or any of its enablers
cannot be duplicated.
Add a cleanup path so successfully acquired user-events state is removed if
a later fork operation fails. Preserve the existing CLONE_VM behavior and
its task reference accounting.
A deterministic allocation-failure test on upstream master previously
allowed fork() to succeed while the child missed an enablement update. With
this change, the same fork fails with ENOMEM. The complete user_events ABI
suite passes.
Cc: stable@vger.kernel.org
Fixes: 7235759084a4 ("tracing/user_events: Use remote writes for event enablement")
Link: https://patch.msgid.link/20261002222639.1964370-1-jeffbarnes@linux.microsoft.com
Signed-off-by: Jeff Barnes <jeffbarnes@linux.microsoft.com>
Reviewed-by: Beau Belgrave <beaub@linux.microsoft.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
include/linux/user_events.h | 16 +++++++---------
kernel/fork.c | 8 ++++++--
kernel/trace/trace_events_user.c | 8 +++++---
3 files changed, 18 insertions(+), 14 deletions(-)
diff --git a/include/linux/user_events.h b/include/linux/user_events.h
index 57d1ff006090..75f184126727 100644
--- a/include/linux/user_events.h
+++ b/include/linux/user_events.h
@@ -27,28 +27,26 @@ struct user_event_mm {
struct rcu_work put_rwork;
};
-extern void user_event_mm_dup(struct task_struct *t,
- struct user_event_mm *old_mm);
+int user_event_mm_dup(struct task_struct *t, struct user_event_mm *old_mm);
extern void user_event_mm_remove(struct task_struct *t);
-static inline void user_events_fork(struct task_struct *t,
- u64 clone_flags)
+static inline int user_events_fork(struct task_struct *t, u64 clone_flags)
{
struct user_event_mm *old_mm;
if (!t || !current->user_event_mm)
- return;
+ return 0;
old_mm = current->user_event_mm;
if (clone_flags & CLONE_VM) {
t->user_event_mm = old_mm;
refcount_inc(&old_mm->tasks);
- return;
+ return 0;
}
- user_event_mm_dup(t, old_mm);
+ return user_event_mm_dup(t, old_mm);
}
static inline void user_events_execve(struct task_struct *t)
@@ -67,9 +65,9 @@ static inline void user_events_exit(struct task_struct *t)
user_event_mm_remove(t);
}
#else
-static inline void user_events_fork(struct task_struct *t,
- u64 clone_flags)
+static inline int user_events_fork(struct task_struct *t, u64 clone_flags)
{
+ return 0;
}
static inline void user_events_execve(struct task_struct *t)
diff --git a/kernel/fork.c b/kernel/fork.c
index 5efceb8d58a7..cdba6ba6335d 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -2328,9 +2328,12 @@ __latent_entropy struct task_struct *copy_process(
retval = copy_mm(clone_flags, p);
if (retval)
goto bad_fork_cleanup_signal;
- retval = copy_namespaces(clone_flags, p);
+ retval = user_events_fork(p, clone_flags);
if (retval)
goto bad_fork_cleanup_mm;
+ retval = copy_namespaces(clone_flags, p);
+ if (retval)
+ goto bad_fork_cleanup_user_events;
retval = copy_io(clone_flags, p);
if (retval)
goto bad_fork_cleanup_namespaces;
@@ -2598,7 +2601,6 @@ __latent_entropy struct task_struct *copy_process(
trace_task_newtask(p, clone_flags);
uprobe_copy_process(p, clone_flags);
- user_events_fork(p, clone_flags);
copy_oom_score_adj(clone_flags, p);
@@ -2625,6 +2627,8 @@ __latent_entropy struct task_struct *copy_process(
exit_io_context(p);
bad_fork_cleanup_namespaces:
exit_nsproxy_namespaces(p);
+bad_fork_cleanup_user_events:
+ user_events_exit(p);
bad_fork_cleanup_mm:
sched_cache_fork_cleanup(p);
if (p->mm) {
diff --git a/kernel/trace/trace_events_user.c b/kernel/trace/trace_events_user.c
index e29e1c772aa7..c561443f7947 100644
--- a/kernel/trace/trace_events_user.c
+++ b/kernel/trace/trace_events_user.c
@@ -868,7 +868,7 @@ void user_event_mm_remove(struct task_struct *t)
queue_rcu_work(system_percpu_wq, &mm->put_rwork);
}
-void user_event_mm_dup(struct task_struct *t, struct user_event_mm *old_mm)
+int user_event_mm_dup(struct task_struct *t, struct user_event_mm *old_mm)
{
struct user_event_mm *mm = user_event_mm_alloc(t);
struct user_event_enabler *enabler;
@@ -877,7 +877,7 @@ void user_event_mm_dup(struct task_struct *t, struct user_event_mm *old_mm)
t->user_event_mm = NULL;
if (!mm)
- return;
+ return -ENOMEM;
rcu_read_lock();
@@ -889,10 +889,12 @@ void user_event_mm_dup(struct task_struct *t, struct user_event_mm *old_mm)
rcu_read_unlock();
user_event_mm_attach(mm, t);
- return;
+ return 0;
error:
rcu_read_unlock();
user_event_mm_destroy(mm);
+
+ return -ENOMEM;
}
static bool current_user_event_enabler_exists(unsigned long uaddr,
--
2.53.0
next parent reply other threads:[~2026-11-27 18:42 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20261127184203.439481361@kernel.org>
2026-11-27 18:42 ` Steven Rostedt [this message]
2026-11-27 18:42 ` [for-linus][PATCH 2/5] tracing/remotes: Align field offset in remote_event_format_show() Steven Rostedt
2026-11-27 18:42 ` [for-linus][PATCH 4/5] ftrace: Reject "!!" in front of a set_ftrace_filter command Steven Rostedt
2026-11-27 18:42 ` [for-linus][PATCH 5/5] tracing/filters: Use atomic bitops and READ_ONCE() for trace_event_file::flags Steven Rostedt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261127184241.554209298@kernel.org \
--to=rostedt@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=beaub@linux.microsoft.com \
--cc=jeffbarnes@linux.microsoft.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mathieu.desnoyers@efficios.com \
--cc=mhiramat@kernel.org \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox