From: Steven Rostedt <rostedt@goodmis.org>
To: linux-kernel@vger.kernel.org
Cc: Masami Hiramatsu <mhiramat@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Andrew Morton <akpm@linux-foundation.org>,
Doug Cook <dcook@linux.microsoft.com>,
Beau Belgrave <beaub@linux.microsoft.com>
Subject: [for-next][PATCH 06/11] tracing/user_events: Ensure bit is cleared on unregister
Date: Wed, 26 Apr 2023 13:17:09 -0400 [thread overview]
Message-ID: <20230426171750.231148604@goodmis.org> (raw)
In-Reply-To: 20230426171703.202523909@goodmis.org
From: Beau Belgrave <beaub@linux.microsoft.com>
If an event is enabled and a user process unregisters user_events, the
bit is left set. Fix this by always clearing the bit in the user process
if unregister is successful.
Update abi self-test to ensure this occurs properly.
Link: https://lkml.kernel.org/r/20230425225107.8525-3-beaub@linux.microsoft.com
Suggested-by: Doug Cook <dcook@linux.microsoft.com>
Signed-off-by: Beau Belgrave <beaub@linux.microsoft.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
kernel/trace/trace_events_user.c | 34 +++++++++++++++++++
.../testing/selftests/user_events/abi_test.c | 9 +++--
2 files changed, 40 insertions(+), 3 deletions(-)
diff --git a/kernel/trace/trace_events_user.c b/kernel/trace/trace_events_user.c
index 546d47a57520..4f9ae63dfc5d 100644
--- a/kernel/trace/trace_events_user.c
+++ b/kernel/trace/trace_events_user.c
@@ -2149,6 +2149,35 @@ static long user_unreg_get(struct user_unreg __user *ureg,
return ret;
}
+static int user_event_mm_clear_bit(struct user_event_mm *user_mm,
+ unsigned long uaddr, unsigned char bit)
+{
+ struct user_event_enabler enabler;
+ int result;
+
+ memset(&enabler, 0, sizeof(enabler));
+ enabler.addr = uaddr;
+ enabler.values = bit;
+retry:
+ /* Prevents state changes from racing with new enablers */
+ mutex_lock(&event_mutex);
+
+ /* Force the bit to be cleared, since no event is attached */
+ mmap_read_lock(user_mm->mm);
+ result = user_event_enabler_write(user_mm, &enabler, false);
+ mmap_read_unlock(user_mm->mm);
+
+ mutex_unlock(&event_mutex);
+
+ if (result) {
+ /* Attempt to fault-in and retry if it worked */
+ if (!user_event_mm_fault_in(user_mm, uaddr))
+ goto retry;
+ }
+
+ return result;
+}
+
/*
* Unregisters an enablement address/bit within a task/user mm.
*/
@@ -2193,6 +2222,11 @@ static long user_events_ioctl_unreg(unsigned long uarg)
mutex_unlock(&event_mutex);
+ /* Ensure bit is now cleared for user, regardless of event status */
+ if (!ret)
+ ret = user_event_mm_clear_bit(mm, reg.disable_addr,
+ reg.disable_bit);
+
return ret;
}
diff --git a/tools/testing/selftests/user_events/abi_test.c b/tools/testing/selftests/user_events/abi_test.c
index e0323d3777a7..5125c42efe65 100644
--- a/tools/testing/selftests/user_events/abi_test.c
+++ b/tools/testing/selftests/user_events/abi_test.c
@@ -109,13 +109,16 @@ TEST_F(user, enablement) {
ASSERT_EQ(0, change_event(false));
ASSERT_EQ(0, self->check);
- /* Should not change after disable */
+ /* Ensure kernel clears bit after disable */
ASSERT_EQ(0, change_event(true));
ASSERT_EQ(1, self->check);
ASSERT_EQ(0, reg_disable(&self->check, 0));
+ ASSERT_EQ(0, self->check);
+
+ /* Ensure doesn't change after unreg */
+ ASSERT_EQ(0, change_event(true));
+ ASSERT_EQ(0, self->check);
ASSERT_EQ(0, change_event(false));
- ASSERT_EQ(1, self->check);
- self->check = 0;
}
TEST_F(user, bit_sizes) {
--
2.39.2
next prev parent reply other threads:[~2023-04-26 17:18 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-26 17:17 [for-next][PATCH 00/11] tracing: Final fixes and minor updates before sending pull request Steven Rostedt
2023-04-26 17:17 ` [for-next][PATCH 01/11] ring-buffer: Clearly check null ptr returned by rb_set_head_page() Steven Rostedt
2023-04-26 17:17 ` [for-next][PATCH 02/11] tracing/user_events: Set event filter_type from type Steven Rostedt
2023-04-26 17:17 ` [for-next][PATCH 03/11] tracing: Fix print_fields() for __dyn_loc/__rel_loc Steven Rostedt
2023-04-26 17:17 ` [for-next][PATCH 04/11] seq_buf: Add seq_buf_do_printk() helper Steven Rostedt
2023-04-26 17:17 ` [for-next][PATCH 05/11] tracing/user_events: Ensure write index cannot be negative Steven Rostedt
2023-04-26 17:17 ` Steven Rostedt [this message]
2023-04-26 17:17 ` [for-next][PATCH 07/11] tracing/user_events: Prevent same address and bit per process Steven Rostedt
2023-04-26 17:17 ` [for-next][PATCH 08/11] tracing/user_events: Limit max fault-in attempts Steven Rostedt
2023-04-26 17:17 ` [for-next][PATCH 09/11] recordmcount: Fix memory leaks in the uwrite function Steven Rostedt
2023-04-26 17:17 ` [for-next][PATCH 10/11] ring-buffer: Ensure proper resetting of atomic variables in ring_buffer_reset_online_cpus Steven Rostedt
2023-04-26 17:17 ` [for-next][PATCH 11/11] tracing: Add missing spaces in trace_print_hex_seq() 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=20230426171750.231148604@goodmis.org \
--to=rostedt@goodmis.org \
--cc=akpm@linux-foundation.org \
--cc=beaub@linux.microsoft.com \
--cc=dcook@linux.microsoft.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mhiramat@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.