mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jeff Barnes <jeffbarnes@linux.microsoft.com>
To: rostedt@goodmis.org, mhiramat@kernel.org, shuah@kernel.org
Cc: mathieu.desnoyers@efficios.com, reddybalavignesh9979@gmail.com,
	richard.weiyang@gmail.com, michael.bommarito@gmail.com,
	linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org,
	linux-kselftest@vger.kernel.org
Subject: [PATCH v2 1/3] tracing/user_events: Serialize duplicate enabler lookup with event removal
Date: Tue,  6 Oct 2026 12:47:18 -0400	[thread overview]
Message-ID: <20261006164720.3940272-2-jeffbarnes@linux.microsoft.com> (raw)
In-Reply-To: <20261006164720.3940272-1-jeffbarnes@linux.microsoft.com>

user_event_enabler_exists() performs a plain traversal of the per-mm
enabler list. Registration invokes it while holding the event group's
reg_mutex, which serializes registration and unregister operations from
that group.

However, deferred fault cleanup can remove an enabler asynchronously
while holding event_mutex without holding the group reg_mutex. The plain
list traversal can therefore race with list_del_rcu() despite the
registration mutex being held.

Take event_mutex around user_event_enabler_exists() so the traversal is
serialized with all enabler removal paths. Pass the group into
current_user_event_enabler_exists() and assert that its reg_mutex is
already held.

This preserves the established lock order of group->reg_mutex followed
by event_mutex.

Signed-off-by: Jeff Barnes <jeffbarnes@linux.microsoft.com>
---
 kernel/trace/trace_events_user.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/kernel/trace/trace_events_user.c b/kernel/trace/trace_events_user.c
index f658c3a77aa7..24983f68d075 100644
--- a/kernel/trace/trace_events_user.c
+++ b/kernel/trace/trace_events_user.c
@@ -890,16 +890,21 @@ void user_event_mm_dup(struct task_struct *t, struct user_event_mm *old_mm)
 	user_event_mm_destroy(mm);
 }
 
-static bool current_user_event_enabler_exists(unsigned long uaddr,
-					      unsigned char bit)
+static bool
+current_user_event_enabler_exists(struct user_event_group *group,
+				  unsigned long uaddr, unsigned char bit)
 {
 	struct user_event_mm *user_mm = current_user_event_mm();
 	bool exists;
 
+	lockdep_assert_held(&group->reg_mutex);
+
 	if (!user_mm)
 		return false;
 
+	mutex_lock(&event_mutex);
 	exists = user_event_enabler_exists(user_mm, uaddr, bit);
+	mutex_unlock(&event_mutex);
 
 	user_event_mm_put(user_mm);
 
@@ -2510,7 +2515,8 @@ static long user_events_ioctl_reg(struct user_event_file_info *info,
 	 * for user processes that is far easier to debug if this is explicitly
 	 * an error upon registering.
 	 */
-	if (current_user_event_enabler_exists((unsigned long)reg.enable_addr,
+	if (current_user_event_enabler_exists(info->group,
+					      (unsigned long)reg.enable_addr,
 					      reg.enable_bit))
 		return -EADDRINUSE;
 
-- 
2.43.0


  reply	other threads:[~2026-10-06 16:47 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-02 15:39 [PATCH 0/2] tracing/user_events: Share state between existing threads Jeff Barnes
2026-10-02 15:39 ` [PATCH 1/2] selftests/user_events: Test registration from " Jeff Barnes
2026-10-02 15:39 ` [PATCH 2/2] tracing/user_events: Share tracing state between " Jeff Barnes
2026-10-06 16:47 ` [PATCH v2 0/3] tracing/user_events: Share state with " Jeff Barnes
2026-10-06 16:47   ` Jeff Barnes [this message]
2026-10-06 16:47   ` [PATCH v2 2/3] tracing/user_events: Share event " Jeff Barnes
2026-10-06 16:47   ` [PATCH v2 3/3] selftests/user_events: Test registration from " Jeff Barnes

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=20261006164720.3940272-2-jeffbarnes@linux.microsoft.com \
    --to=jeffbarnes@linux.microsoft.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mhiramat@kernel.org \
    --cc=michael.bommarito@gmail.com \
    --cc=reddybalavignesh9979@gmail.com \
    --cc=richard.weiyang@gmail.com \
    --cc=rostedt@goodmis.org \
    --cc=shuah@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

all inboxes | Powered by JetHome®