Skip to contentSkip to conversation

racing/user_events: Prevent same address and bit per process

PATCH In review sunliming 2 participants 2 messages May 19, 2023 – May 22, 2023 Tracing

lore
Share & tools
lore

sunliming

author
#0 lore raw

PATCH 1/1 racing/user_events: Prevent same address and bit 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
index b1ecd7677642..4ef6bdb5c07c 100644
@@ -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
maintainer
#1 lore raw

Is the subject a Freudian slip?

Added Beau. I need to add him to the maintainers file for user events ;-)

Quoted 9 lines · On Fri, 19 May 2023 16:10:35 +0800 sunliming <[email protected]> wrote:

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.

I'll let Beau ack this or not.

-- Steve

Quoted 19 lines
---
 kernel/trace/trace_events_user.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/trace_events_user.c +1 -1
index b1ecd7677642..4ef6bdb5c07c 100644
@@ -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);