From nobody Wed Dec 17 21:00:33 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A366329D0B for ; Fri, 3 May 2024 22:50:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714776634; cv=none; b=LcyZM4DrGezc8oeMD8eu4LWKHQRDSWV23hX8aKF3MHhA5//jlkr4RcK7Xqhsr24+YYhN8E1qzKlGqPF/i544XTWFkhdevne/X5icUmjdapbLa6McCtkeUd7a7JVApoRqNw9eyNiHzHc44PD4Oyz55wHmaG/l38kRXJR6Ba+fCQY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714776634; c=relaxed/simple; bh=iJERzLjJkxTqAUWnDXq2duAyH62ba6gQeg5N6A7qs8g=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=bph5r4OXbdAyGclU90xmseuRYOX4KXpv+WC3YUPYAzwEix8EjvP1fs4SOEdlc9h0JES2704E1qOoLUdt4egoefenht93DoBYRWA4zJjN8U4gwEPux3gRliqeNn9ULlGSRYMy/JEqny8kOXMzy5Dv0OBDtLTxLwBB5kt5gHDZ1Jw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 60E4BC4AF14; Fri, 3 May 2024 22:50:34 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1s31jd-00000000NK8-35uG; Fri, 03 May 2024 18:50:33 -0400 Message-ID: <20240503225033.597936455@goodmis.org> User-Agent: quilt/0.68 Date: Fri, 03 May 2024 18:50:14 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Beau Belgrave Subject: [for-linus][PATCH 1/9] tracing/user_events: Fix non-spaced field matching References: <20240503225013.519028385@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Beau Belgrave When the ABI was updated to prevent same name w/different args, it missed an important corner case when fields don't end with a space. Typically, space is used for fields to help separate them, like "u8 field1; u8 field2". If no spaces are used, like "u8 field1;u8 field2", then the parsing works for the first time. However, the match check fails on a subsequent register, leading to confusion. This is because the match check uses argv_split() and assumes that all fields will be split upon the space. When spaces are used, we get back { "u8", "field1;" }, without spaces we get back { "u8", "field1;u8" }. This causes a mismatch, and the user program gets back -EADDRINUSE. Add a method to detect this case before calling argv_split(). If found force a space after the field separator character ';'. This ensures all cases work properly for matching. With this fix, the following are all treated as matching: u8 field1;u8 field2 u8 field1; u8 field2 u8 field1;\tu8 field2 u8 field1;\nu8 field2 Link: https://lore.kernel.org/linux-trace-kernel/20240423162338.292-2-beaub= @linux.microsoft.com Fixes: ba470eebc2f6 ("tracing/user_events: Prevent same name but different = args event") Signed-off-by: Beau Belgrave Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace_events_user.c | 76 +++++++++++++++++++++++++++++++- 1 file changed, 75 insertions(+), 1 deletion(-) diff --git a/kernel/trace/trace_events_user.c b/kernel/trace/trace_events_u= ser.c index 70d428c394b6..82b191f33a28 100644 --- a/kernel/trace/trace_events_user.c +++ b/kernel/trace/trace_events_user.c @@ -1989,6 +1989,80 @@ static int user_event_set_tp_name(struct user_event = *user) return 0; } =20 +/* + * Counts how many ';' without a trailing space are in the args. + */ +static int count_semis_no_space(char *args) +{ + int count =3D 0; + + while ((args =3D strchr(args, ';'))) { + args++; + + if (!isspace(*args)) + count++; + } + + return count; +} + +/* + * Copies the arguments while ensuring all ';' have a trailing space. + */ +static char *insert_space_after_semis(char *args, int count) +{ + char *fixed, *pos; + int len; + + len =3D strlen(args) + count; + fixed =3D kmalloc(len + 1, GFP_KERNEL); + + if (!fixed) + return NULL; + + pos =3D fixed; + + /* Insert a space after ';' if there is no trailing space. */ + while (*args) { + *pos =3D *args++; + + if (*pos++ =3D=3D ';' && !isspace(*args)) + *pos++ =3D ' '; + } + + *pos =3D '\0'; + + return fixed; +} + +static char **user_event_argv_split(char *args, int *argc) +{ + char **split; + char *fixed; + int count; + + /* Count how many ';' without a trailing space */ + count =3D count_semis_no_space(args); + + /* No fixup is required */ + if (!count) + return argv_split(GFP_KERNEL, args, argc); + + /* We must fixup 'field;field' to 'field; field' */ + fixed =3D insert_space_after_semis(args, count); + + if (!fixed) + return NULL; + + /* We do a normal split afterwards */ + split =3D argv_split(GFP_KERNEL, fixed, argc); + + /* We can free since argv_split makes a copy */ + kfree(fixed); + + return split; +} + /* * Parses the event name, arguments and flags then registers if successful. * The name buffer lifetime is owned by this method for success cases only. @@ -2012,7 +2086,7 @@ static int user_event_parse(struct user_event_group *= group, char *name, return -EPERM; =20 if (args) { - argv =3D argv_split(GFP_KERNEL, args, &argc); + argv =3D user_event_argv_split(args, &argc); =20 if (!argv) return -ENOMEM; --=20 2.43.0