From nobody Tue Feb 10 23:54:12 2026 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 2E56D17F36C for ; Tue, 14 May 2024 16:17:07 +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=1715703427; cv=none; b=DsMNAk3jnQPbDaXmNSJsMdOqYrH0ylAytbiyDEAuNjm3WzXB2ixTXJLBgsWFbq6mz2P8K5nuHV5tAsOKwJOKGB7uUpv1xAQph7d8bcwdV/FzDhuSdzKljoYHeDyiTDGzsV8xgg0dMBSmKEVTiTtBpVseulM+OowlyobiPrRg7fg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715703427; c=relaxed/simple; bh=iJERzLjJkxTqAUWnDXq2duAyH62ba6gQeg5N6A7qs8g=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=CjhX0Ypgn1GCZzIAvAd4DOPqgdRt6twNiLge6WeVZRMlUT12/6JbNAAIXNiU1C3sfekfGa7gjZyrdQh9xiXAVuhk3MLMyi12cZ/FH9eFT7F3zDuJ6VQ/o9Xz5f932Fg0hT085bciBdXOv2LZyY9fmb5h0rdwzFgOAE/FFv7puI8= 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 1148AC4AF08; Tue, 14 May 2024 16:17:07 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1s6uqJ-00000003tJe-3FPU; Tue, 14 May 2024 12:17:31 -0400 Message-ID: <20240514161731.642735808@goodmis.org> User-Agent: quilt/0.68 Date: Tue, 14 May 2024 12:17:11 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Beau Belgrave Subject: [for-next][PATCH 1/2] tracing/user_events: Fix non-spaced field matching References: <20240514161710.977621701@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 From nobody Tue Feb 10 23:54:12 2026 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 A428717F38B for ; Tue, 14 May 2024 16:17:07 +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=1715703427; cv=none; b=igyKOvmrN0NFn5dvKAuoHcRWCWvTWtEcdJN2oB6GRTlzhpoC9LrhDv0csoRKkxEK9MIDlhbp8p/hXCoadtdIYGsLmDze5c5JMabR5pWA26ff2S65ZkgyHrobrQMTWH8u7Ava9hk5Lirc4IL3gLQK5FylSX26pSkO9q3pwuqwu9M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715703427; c=relaxed/simple; bh=VuXalIPTL9sTa7bnw/R/Fo8g3BmGZ0SIUARYlC9WdwQ=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=Fxm0Vbo5TbllSZuUfOPKzokc4acUhhhcDVc+8iLDXaMViOFFLEDHAP4cxDXLWBFGklPp4Q7p4dwqCIOPXSLwMuWjnyg1Q+yPDVODx9JTFk57ER62Et/V08w6gcPrbjCj/tkEUdctT12IlWLYq13Tjvs5m2R1wTcGaNwkihR9UKQ= 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 3C7CCC32786; Tue, 14 May 2024 16:17:07 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1s6uqJ-00000003tK8-3wp5; Tue, 14 May 2024 12:17:31 -0400 Message-ID: <20240514161731.798160831@goodmis.org> User-Agent: quilt/0.68 Date: Tue, 14 May 2024 12:17:12 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Beau Belgrave Subject: [for-next][PATCH 2/2] selftests/user_events: Add non-spacing separator check References: <20240514161710.977621701@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 The ABI documentation indicates that field separators do not need a space between them, only a ';'. When no spacing is used, the register must work. Any subsequent register, with or without spaces, must match and not return -EADDRINUSE. Add a non-spacing separator case to our self-test register case to ensure it works going forward. Link: https://lore.kernel.org/linux-trace-kernel/20240423162338.292-3-beaub= @linux.microsoft.com Signed-off-by: Beau Belgrave Signed-off-by: Steven Rostedt (Google) --- tools/testing/selftests/user_events/ftrace_test.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tools/testing/selftests/user_events/ftrace_test.c b/tools/test= ing/selftests/user_events/ftrace_test.c index dcd7509fe2e0..0bb46793dcd4 100644 --- a/tools/testing/selftests/user_events/ftrace_test.c +++ b/tools/testing/selftests/user_events/ftrace_test.c @@ -261,6 +261,12 @@ TEST_F(user, register_events) { ASSERT_EQ(0, ioctl(self->data_fd, DIAG_IOCSREG, ®)); ASSERT_EQ(0, reg.write_index); =20 + /* Register without separator spacing should still match */ + reg.enable_bit =3D 29; + reg.name_args =3D (__u64)"__test_event u32 field1;u32 field2"; + ASSERT_EQ(0, ioctl(self->data_fd, DIAG_IOCSREG, ®)); + ASSERT_EQ(0, reg.write_index); + /* Multiple registers to same name but different args should fail */ reg.enable_bit =3D 29; reg.name_args =3D (__u64)"__test_event u32 field1;"; @@ -288,6 +294,8 @@ TEST_F(user, register_events) { ASSERT_EQ(0, ioctl(self->data_fd, DIAG_IOCSUNREG, &unreg)); unreg.disable_bit =3D 30; ASSERT_EQ(0, ioctl(self->data_fd, DIAG_IOCSUNREG, &unreg)); + unreg.disable_bit =3D 29; + ASSERT_EQ(0, ioctl(self->data_fd, DIAG_IOCSUNREG, &unreg)); =20 /* Delete should have been auto-done after close and unregister */ close(self->data_fd); --=20 2.43.0