tracing/user_events: Prevent same name event per process
PATCH RESEND 1/1 tracing/user_events: Prevent same name event per process
User processes register name_args for events. If the same name are registered multiple times in the same process, it can cause undefined behavior. Because the same name may be used for a diffrent event. If this event has the same format as the original event, it is impossible to distinguish the trace output of these two events. If the event has a different format from the original event, the trace output of the new event is incorrect.
Return EADDRINUSE back to the user process if the same event has being registered in the same process.
--- kernel/trace/trace_events_user.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/trace_events_user.c +1 -1
@@ -1996,7 +1996,7 @@ static int user_events_ref_add(struct user_event_file_info *info,for (i =0 ; i < count; ++i)if (refs->events[i] == user) -return i; +return -EADDRINUSE ; } size =struct_size (refs, events, count +1 );
Signature · 1 line
2.25.1
Quoted 7 lines
User processes register
name_argsfor events. If the same name are registered multiple times in the same process, it can cause undefined behavior. Because the same name may be used for a diffrent event. If this event has the same format as the original event, it is impossible to distinguish the trace output of these two events. If the event has a different format from the original event, the trace output of the new event is incorrect.
Quoted 5 lines
Return EADDRINUSE back to the user process if the same event has being registered in the same process.
Signed-off-by sunliming <[email protected]>---
Thank you for the patch, a few comments.
kernel/trace/trace_events_user.c static int user_events_ref_add(struct user_event_file_info *info, · line 1999
Quoted 13 lines
kernel/trace/trace_events_user.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)kernel/trace/trace_events_user.c +1
-1@@ -1996,7 +1996,7 @@ static int user_events_ref_add(struct user_event_file_info *info,for (i =0 ; i < count; ++i)if (refs->events[i] == user) -return i; +return -EADDRINUSE ;
The ABI currently allows this to allow for shared libraries to share a common write FD. Do you feel strongly that this should not be allowed?
If you and others feel this should not be allowed, I'd kindly ask you to also update the self-tests at tools/testing/selftests/user_events/ in the tree and ensure they pass fully.
For example, see ftrace_test.c at the above tree location:
...
TEST_F(user, register_events) {
...
/* Multiple registers to the same addr + bit should fail */ ASSERT_EQ(-1, ioctl(self->data_fd, DIAG_IOCSREG, ®)); ASSERT_EQ(EADDRINUSE, errno); /* Multiple registers to same name should result in same index */ reg.enable_bit = 30; ASSERT_EQ(0, ioctl(self->data_fd, DIAG_IOCSREG, ®)); ASSERT_EQ(0, reg.write_index);
...
Thanks,
-Beau
Quoted 5 lines
kernel/trace/trace_events_user.c +0
-0} size =struct_size (refs, events, count +1 );Signature · 1 line
2.25.1