]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - releases/6.1.40/tracing-user_events-fix-struct-arg-size-match-check.patch
6.1-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 6.1.40 / tracing-user_events-fix-struct-arg-size-match-check.patch
CommitLineData
b0dcea26
GKH
1From d0a3022f30629a208e5944022caeca3568add9e7 Mon Sep 17 00:00:00 2001
2From: Beau Belgrave <beaub@linux.microsoft.com>
3Date: Thu, 29 Jun 2023 23:50:48 +0000
4Subject: tracing/user_events: Fix struct arg size match check
5
6From: Beau Belgrave <beaub@linux.microsoft.com>
7
8commit d0a3022f30629a208e5944022caeca3568add9e7 upstream.
9
10When users register an event the name of the event and it's argument are
11checked to ensure they match if the event already exists. Normally all
12arguments are in the form of "type name", except for when the type
13starts with "struct ". In those cases, the size of the struct is passed
14in addition to the name, IE: "struct my_struct a 20" for an argument
15that is of type "struct my_struct" with a field name of "a" and has the
16size of 20 bytes.
17
18The current code does not honor the above case properly when comparing
19a match. This causes the event register to fail even when the same
20string was used for events that contain a struct argument within them.
21The example above "struct my_struct a 20" generates a match string of
22"struct my_struct a" omitting the size field.
23
24Add the struct size of the existing field when generating a comparison
25string for a struct field to ensure proper match checking.
26
27Link: https://lkml.kernel.org/r/20230629235049.581-2-beaub@linux.microsoft.com
28
29Cc: stable@vger.kernel.org
30Fixes: e6f89a149872 ("tracing/user_events: Ensure user provided strings are safely formatted")
31Signed-off-by: Beau Belgrave <beaub@linux.microsoft.com>
32Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
33Signed-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