* [PATCH AUTOSEL 6.1 02/12] tracing/user_events: Prevent same name but different args event
[not found] <20230629190134.907949-1-sashal@kernel.org>
@ 2023-06-29 19:01 ` Sasha Levin
2023-06-29 19:01 ` [PATCH AUTOSEL 6.1 03/12] tracing/user_events: Handle matching arguments that is null from dyn_events Sasha Levin
2023-06-29 19:01 ` [PATCH AUTOSEL 6.1 04/12] tracing/user_events: Fix the incorrect trace record for empty arguments events Sasha Levin
2 siblings, 0 replies; 3+ messages in thread
From: Sasha Levin @ 2023-06-29 19:01 UTC (permalink / raw)
To: linux-kernel, stable
Cc: sunliming, Masami Hiramatsu, Beau Belgrave, Steven Rostedt,
Sasha Levin, shuah, quic_mojha, zwisler, linux-trace-kernel,
linux-kselftest
From: sunliming <sunliming@kylinos.cn>
[ Upstream commit ba470eebc2f6c2f704872955a715b9555328e7d0 ]
User processes register name_args for events. If the same name but different
args event are registered. The trace outputs of second event are printed
as the first event. This is incorrect.
Return EADDRINUSE back to the user process if the same name but different args
event has being registered.
Link: https://lore.kernel.org/linux-trace-kernel/20230529032100.286534-1-sunliming@kylinos.cn
Signed-off-by: sunliming <sunliming@kylinos.cn>
Reviewed-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Acked-by: Beau Belgrave <beaub@linux.microsoft.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
kernel/trace/trace_events_user.c | 36 +++++++++++++++----
.../selftests/user_events/ftrace_test.c | 6 ++++
2 files changed, 36 insertions(+), 6 deletions(-)
diff --git a/kernel/trace/trace_events_user.c b/kernel/trace/trace_events_user.c
index 625cab4b9d945..774d146c2c2ca 100644
--- a/kernel/trace/trace_events_user.c
+++ b/kernel/trace/trace_events_user.c
@@ -1274,6 +1274,8 @@ static int user_event_parse(struct user_event_group *group, char *name,
int index;
u32 key;
struct user_event *user;
+ int argc = 0;
+ char **argv;
/* Prevent dyn_event from racing */
mutex_lock(&event_mutex);
@@ -1281,13 +1283,35 @@ static int user_event_parse(struct user_event_group *group, char *name,
mutex_unlock(&event_mutex);
if (user) {
- *newuser = user;
- /*
- * Name is allocated by caller, free it since it already exists.
- * Caller only worries about failure cases for freeing.
- */
- kfree(name);
+ if (args) {
+ argv = argv_split(GFP_KERNEL, args, &argc);
+ if (!argv) {
+ ret = -ENOMEM;
+ goto error;
+ }
+
+ ret = user_fields_match(user, argc, (const char **)argv);
+ argv_free(argv);
+
+ } else
+ ret = list_empty(&user->fields);
+
+ if (ret) {
+ *newuser = user;
+ /*
+ * Name is allocated by caller, free it since it already exists.
+ * Caller only worries about failure cases for freeing.
+ */
+ kfree(name);
+ } else {
+ ret = -EADDRINUSE;
+ goto error;
+ }
+
return 0;
+error:
+ refcount_dec(&user->refcnt);
+ return ret;
}
index = find_first_zero_bit(group->page_bitmap, MAX_EVENTS);
diff --git a/tools/testing/selftests/user_events/ftrace_test.c b/tools/testing/selftests/user_events/ftrace_test.c
index 1bc26e6476fc3..df0e776c2cc1b 100644
--- a/tools/testing/selftests/user_events/ftrace_test.c
+++ b/tools/testing/selftests/user_events/ftrace_test.c
@@ -209,6 +209,12 @@ TEST_F(user, register_events) {
ASSERT_EQ(0, reg.write_index);
ASSERT_NE(0, reg.status_bit);
+ /* Multiple registers to same name but different args should fail */
+ reg.enable_bit = 29;
+ reg.name_args = (__u64)"__test_event u32 field1;";
+ ASSERT_EQ(-1, ioctl(self->data_fd, DIAG_IOCSREG, ®));
+ ASSERT_EQ(EADDRINUSE, errno);
+
/* Ensure disabled */
self->enable_fd = open(enable_file, O_RDWR);
ASSERT_NE(-1, self->enable_fd);
--
2.39.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH AUTOSEL 6.1 03/12] tracing/user_events: Handle matching arguments that is null from dyn_events
[not found] <20230629190134.907949-1-sashal@kernel.org>
2023-06-29 19:01 ` [PATCH AUTOSEL 6.1 02/12] tracing/user_events: Prevent same name but different args event Sasha Levin
@ 2023-06-29 19:01 ` Sasha Levin
2023-06-29 19:01 ` [PATCH AUTOSEL 6.1 04/12] tracing/user_events: Fix the incorrect trace record for empty arguments events Sasha Levin
2 siblings, 0 replies; 3+ messages in thread
From: Sasha Levin @ 2023-06-29 19:01 UTC (permalink / raw)
To: linux-kernel, stable
Cc: sunliming, Masami Hiramatsu, Steven Rostedt, Sasha Levin,
linux-trace-kernel
From: sunliming <sunliming@kylinos.cn>
[ Upstream commit cfac4ed7279d056df6167bd665e460787dc9e0c4 ]
When A registering user event from dyn_events has no argments, it will pass the
matching check, regardless of whether there is a user event with the same name
and arguments. Add the matching check when the arguments of registering user
event is null.
Link: https://lore.kernel.org/linux-trace-kernel/20230529065110.303440-1-sunliming@kylinos.cn
Signed-off-by: sunliming <sunliming@kylinos.cn>
Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
kernel/trace/trace_events_user.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/kernel/trace/trace_events_user.c b/kernel/trace/trace_events_user.c
index 774d146c2c2ca..ad64da21c34aa 100644
--- a/kernel/trace/trace_events_user.c
+++ b/kernel/trace/trace_events_user.c
@@ -1232,6 +1232,8 @@ static bool user_event_match(const char *system, const char *event,
if (match && argc > 0)
match = user_fields_match(user, argc, argv);
+ else if (match && argc == 0)
+ match = list_empty(&user->fields);
return match;
}
--
2.39.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH AUTOSEL 6.1 04/12] tracing/user_events: Fix the incorrect trace record for empty arguments events
[not found] <20230629190134.907949-1-sashal@kernel.org>
2023-06-29 19:01 ` [PATCH AUTOSEL 6.1 02/12] tracing/user_events: Prevent same name but different args event Sasha Levin
2023-06-29 19:01 ` [PATCH AUTOSEL 6.1 03/12] tracing/user_events: Handle matching arguments that is null from dyn_events Sasha Levin
@ 2023-06-29 19:01 ` Sasha Levin
2 siblings, 0 replies; 3+ messages in thread
From: Sasha Levin @ 2023-06-29 19:01 UTC (permalink / raw)
To: linux-kernel, stable
Cc: sunliming, Beau Belgrave, Masami Hiramatsu, Steven Rostedt,
Sasha Levin, linux-trace-kernel
From: sunliming <sunliming@kylinos.cn>
[ Upstream commit 6f05dcabe5c241d066ec472cf38ac8b84f8c9c6f ]
The user_events support events that has empty arguments. But the trace event
is discarded and not really committed when the arguments is empty. Fix this
by not attempting to copy in zero-length data.
Link: https://lkml.kernel.org/r/20230606062027.1008398-2-sunliming@kylinos.cn
Acked-by: Beau Belgrave <beaub@linux.microsoft.com>
Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Signed-off-by: sunliming <sunliming@kylinos.cn>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
kernel/trace/trace_events_user.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/kernel/trace/trace_events_user.c b/kernel/trace/trace_events_user.c
index ad64da21c34aa..49e114d250136 100644
--- a/kernel/trace/trace_events_user.c
+++ b/kernel/trace/trace_events_user.c
@@ -916,7 +916,7 @@ static void user_event_ftrace(struct user_event *user, struct iov_iter *i,
if (unlikely(!entry))
return;
- if (unlikely(!copy_nofault(entry + 1, i->count, i)))
+ if (unlikely(i->count != 0 && !copy_nofault(entry + 1, i->count, i)))
goto discard;
if (!list_empty(&user->validators) &&
@@ -957,7 +957,7 @@ static void user_event_perf(struct user_event *user, struct iov_iter *i,
perf_fetch_caller_regs(regs);
- if (unlikely(!copy_nofault(perf_entry + 1, i->count, i)))
+ if (unlikely(i->count != 0 && !copy_nofault(perf_entry + 1, i->count, i)))
goto discard;
if (!list_empty(&user->validators) &&
--
2.39.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-06-29 19:03 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20230629190134.907949-1-sashal@kernel.org>
2023-06-29 19:01 ` [PATCH AUTOSEL 6.1 02/12] tracing/user_events: Prevent same name but different args event Sasha Levin
2023-06-29 19:01 ` [PATCH AUTOSEL 6.1 03/12] tracing/user_events: Handle matching arguments that is null from dyn_events Sasha Levin
2023-06-29 19:01 ` [PATCH AUTOSEL 6.1 04/12] tracing/user_events: Fix the incorrect trace record for empty arguments events Sasha Levin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).