From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
To: "Masami Hiramatsu (Google)" <mhiramat@kernel.org>
Cc: Steven Rostedt <rostedt@goodmis.org>,
Shuah Khan <shuah@kernel.org>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org,
linux-kselftest@vger.kernel.org
Subject: Re: [PATCH 1/2] tracing: Handle "(const) char __attribute() *" as string ptr type
Date: Tue, 8 Jul 2025 10:06:07 +0900 [thread overview]
Message-ID: <20250708100607.a09526bf6712a3b98f7a5464@kernel.org> (raw)
In-Reply-To: <175151679513.2149615.16646841903099858271.stgit@mhiramat.tok.corp.google.com>
On Thu, 3 Jul 2025 13:26:35 +0900
"Masami Hiramatsu (Google)" <mhiramat@kernel.org> wrote:
> From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
>
> With CONFIG_DEBUG_INFO_BTF=y and PAHOLE_HAS_BTF_TAG=y, `__user` is
> converted to `__attribute((btf_type_tag("user")))`. In this case,
> some syscall events have `const char __attribute(...) *` for __user
> string, like below;
>
> /sys/kernel/tracing # cat events/syscalls/sys_enter_openat/format
> name: sys_enter_openat
> ID: 720
> format:
> field:unsigned short common_type; offset:0; size:2; signed:0;
> field:unsigned char common_flags; offset:2; size:1; signed:0;
> field:unsigned char common_preempt_count; offset:3; size:1; signed:0;
> field:int common_pid; offset:4; size:4; signed:1;
>
> field:int __syscall_nr; offset:8; size:4; signed:1;
> field:int dfd; offset:16; size:8; signed:0;
> field:const char __attribute__((btf_type_tag("user"))) * filename; offset:24;
Ahh, sorry, it was "__attribute__()" not "__attribute()".
Anyway, I think we should sanitize the __attribute__ from
format.
Thank you,
size:8; signed:0;
> field:int flags; offset:32; size:8; signed:0;
> field:umode_t mode; offset:40; size:8; signed:0;
>
>
> Then the trace event filter failes to set string acceptable flag
> (FILTER_PTR_STRING) and rejects setting string filter;
>
> # echo 'filename.ustring ~ "*ftracetest-dir.wbx24v*"' >> events/syscalls/sys_enter_openat/filter
> sh: write error: Invalid argument
> # cat error_log
> [ 723.743637] event filter parse error: error: Expecting numeric field
> Command: filename.ustring ~ "*ftracetest-dir.wbx24v*"
>
> Handle "(const) char __attribute() *" also as string ptr type.
>
> Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
> ---
> kernel/trace/trace_events_filter.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events_filter.c
> index 3885aadc434d..5e27190a0377 100644
> --- a/kernel/trace/trace_events_filter.c
> +++ b/kernel/trace/trace_events_filter.c
> @@ -1488,6 +1488,11 @@ int filter_assign_type(const char *type)
> if (strcmp(type, "char *") == 0 || strcmp(type, "const char *") == 0)
> return FILTER_PTR_STRING;
>
> + /* Ignore attributes */
> + if (glob_match("char __attribute(*) \\*", type) ||
> + glob_match("const char __attribute(*) \\*", type))
> + return FILTER_PTR_STRING;
> +
> return FILTER_OTHER;
> }
>
>
--
Masami Hiramatsu (Google) <mhiramat@kernel.org>
next prev parent reply other threads:[~2025-07-08 1:06 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-03 4:26 [PATCH 0/2] tracing: Fixes for filter Masami Hiramatsu (Google)
2025-07-03 4:26 ` [PATCH 1/2] tracing: Handle "(const) char __attribute() *" as string ptr type Masami Hiramatsu (Google)
2025-07-08 1:06 ` Masami Hiramatsu [this message]
2025-07-03 4:26 ` [PATCH 2/2] selftests: tracing: Use mutex_unlock for testing glob filter Masami Hiramatsu (Google)
2025-07-03 14:30 ` Steven Rostedt
2025-07-04 6:04 ` Masami Hiramatsu
2025-07-07 21:36 ` Shuah Khan
2025-07-03 14:30 ` [PATCH 0/2] tracing: Fixes for filter Steven Rostedt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250708100607.a09526bf6712a3b98f7a5464@kernel.org \
--to=mhiramat@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=rostedt@goodmis.org \
--cc=shuah@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).