]>
Commit | Line | Data |
---|---|---|
b0dcea26 GKH |
1 | From d0a3022f30629a208e5944022caeca3568add9e7 Mon Sep 17 00:00:00 2001 |
2 | From: Beau Belgrave <beaub@linux.microsoft.com> | |
3 | Date: Thu, 29 Jun 2023 23:50:48 +0000 | |
4 | Subject: tracing/user_events: Fix struct arg size match check | |
5 | ||
6 | From: Beau Belgrave <beaub@linux.microsoft.com> | |
7 | ||
8 | commit d0a3022f30629a208e5944022caeca3568add9e7 upstream. | |
9 | ||
10 | When users register an event the name of the event and it's argument are | |
11 | checked to ensure they match if the event already exists. Normally all | |
12 | arguments are in the form of "type name", except for when the type | |
13 | starts with "struct ". In those cases, the size of the struct is passed | |
14 | in addition to the name, IE: "struct my_struct a 20" for an argument | |
15 | that is of type "struct my_struct" with a field name of "a" and has the | |
16 | size of 20 bytes. | |
17 | ||
18 | The current code does not honor the above case properly when comparing | |
19 | a match. This causes the event register to fail even when the same | |
20 | string was used for events that contain a struct argument within them. | |
21 | The example above "struct my_struct a 20" generates a match string of | |
22 | "struct my_struct a" omitting the size field. | |
23 | ||
24 | Add the struct size of the existing field when generating a comparison | |
25 | string for a struct field to ensure proper match checking. | |
26 | ||
27 | Link: https://lkml.kernel.org/r/20230629235049.581-2-beaub@linux.microsoft.com | |
28 | ||
29 | Cc: stable@vger.kernel.org | |
30 | Fixes: e6f89a149872 ("tracing/user_events: Ensure user provided strings are safely formatted") | |
31 | Signed-off-by: Beau Belgrave <beaub@linux.microsoft.com> | |
32 | Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org> | |
33 | Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> | |
34 | --- | |
35 | kernel/trace/trace_events_user.c | 3 +++ | |
36 | 1 file changed, 3 insertions(+) | |
37 | ||
38 | --- a/kernel/trace/trace_events_user.c | |
39 | +++ b/kernel/trace/trace_events_user.c | |
40 | @@ -707,6 +707,9 @@ static int user_field_set_string(struct | |
41 | pos += snprintf(buf + pos, LEN_OR_ZERO, " "); | |
42 | pos += snprintf(buf + pos, LEN_OR_ZERO, "%s", field->name); | |
43 | ||
44 | + if (str_has_prefix(field->type, "struct ")) | |
45 | + pos += snprintf(buf + pos, LEN_OR_ZERO, " %d", field->size); | |
46 | + | |
47 | if (colon) | |
48 | pos += snprintf(buf + pos, LEN_OR_ZERO, ";"); | |
49 |