linux-trace-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] tracing/probes: fix error check in parse_btf_field()
@ 2024-05-25 18:21 Carlos López
  2024-05-26 10:17 ` Masami Hiramatsu
  0 siblings, 1 reply; 4+ messages in thread
From: Carlos López @ 2024-05-25 18:21 UTC (permalink / raw)
  To: linux-trace-kernel
  Cc: Carlos López, Steven Rostedt, Masami Hiramatsu,
	Mathieu Desnoyers, Alan Maguire, open list:TRACING

btf_find_struct_member() might return NULL or an error via the
ERR_PTR() macro. However, its caller in parse_btf_field() only checks
for the NULL condition. Fix this by using IS_ERR() and returning the
error up the stack.

Fixes: c440adfbe3025 ("tracing/probes: Support BTF based data structure field access")
Signed-off-by: Carlos López <clopez@suse.de>
---
 kernel/trace/trace_probe.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c
index 5e263c141574..5417e9712157 100644
--- a/kernel/trace/trace_probe.c
+++ b/kernel/trace/trace_probe.c
@@ -554,6 +554,8 @@ static int parse_btf_field(char *fieldname, const struct btf_type *type,
 			anon_offs = 0;
 			field = btf_find_struct_member(ctx->btf, type, fieldname,
 						       &anon_offs);
+			if (IS_ERR(field))
+				return PTR_ERR(field);
 			if (!field) {
 				trace_probe_log_err(ctx->offset, NO_BTF_FIELD);
 				return -ENOENT;
-- 
2.35.3


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] tracing/probes: fix error check in parse_btf_field()
  2024-05-25 18:21 [PATCH] tracing/probes: fix error check in parse_btf_field() Carlos López
@ 2024-05-26 10:17 ` Masami Hiramatsu
  2024-05-26 12:27   ` Carlos López
  0 siblings, 1 reply; 4+ messages in thread
From: Masami Hiramatsu @ 2024-05-26 10:17 UTC (permalink / raw)
  To: Carlos López
  Cc: linux-trace-kernel, Steven Rostedt, Masami Hiramatsu,
	Mathieu Desnoyers, Alan Maguire, open list:TRACING

On Sat, 25 May 2024 20:21:32 +0200
Carlos López <clopez@suse.de> wrote:

> btf_find_struct_member() might return NULL or an error via the
> ERR_PTR() macro. However, its caller in parse_btf_field() only checks
> for the NULL condition. Fix this by using IS_ERR() and returning the
> error up the stack.
> 

Thanks for finding it!
I think this requires new error message for error_log file.
Can you add the log as

trace_probe_log_err(ctx->offset, BTF_ERROR);

And define BTF_ERROR in ERRORS@kernel/trace/trace_probe.h ?

Thank you,

> Fixes: c440adfbe3025 ("tracing/probes: Support BTF based data structure field access")
> Signed-off-by: Carlos López <clopez@suse.de>
> ---
>  kernel/trace/trace_probe.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c
> index 5e263c141574..5417e9712157 100644
> --- a/kernel/trace/trace_probe.c
> +++ b/kernel/trace/trace_probe.c
> @@ -554,6 +554,8 @@ static int parse_btf_field(char *fieldname, const struct btf_type *type,
>  			anon_offs = 0;
>  			field = btf_find_struct_member(ctx->btf, type, fieldname,
>  						       &anon_offs);
> +			if (IS_ERR(field))
> +				return PTR_ERR(field);
>  			if (!field) {
>  				trace_probe_log_err(ctx->offset, NO_BTF_FIELD);
>  				return -ENOENT;
> -- 
> 2.35.3
> 


-- 
Masami Hiramatsu (Google) <mhiramat@kernel.org>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] tracing/probes: fix error check in parse_btf_field()
  2024-05-26 10:17 ` Masami Hiramatsu
@ 2024-05-26 12:27   ` Carlos López
  2024-05-26 23:13     ` Masami Hiramatsu
  0 siblings, 1 reply; 4+ messages in thread
From: Carlos López @ 2024-05-26 12:27 UTC (permalink / raw)
  To: Masami Hiramatsu (Google)
  Cc: linux-trace-kernel, Steven Rostedt, Mathieu Desnoyers,
	Alan Maguire, open list:TRACING


Hi,

On 26/5/24 12:17, Masami Hiramatsu (Google) wrote:
> On Sat, 25 May 2024 20:21:32 +0200
> Carlos López <clopez@suse.de> wrote:
> 
>> btf_find_struct_member() might return NULL or an error via the
>> ERR_PTR() macro. However, its caller in parse_btf_field() only checks
>> for the NULL condition. Fix this by using IS_ERR() and returning the
>> error up the stack.
>>
> 
> Thanks for finding it!
> I think this requires new error message for error_log file.
> Can you add the log as
> 
> trace_probe_log_err(ctx->offset, BTF_ERROR);
> 
> And define BTF_ERROR in ERRORS@kernel/trace/trace_probe.h ?

Sounds good, but should we perhaps reuse BAD_BTF_TID?

```
C(BAD_BTF_TID,		"Failed to get BTF type info."),\
```

`btf_find_struct_member()` fails if `type` is not a struct or if it runs
OOM while allocating the anon stack, so it seems appropriate.

Best,
Carlos

> Thank you,
> 
>> Fixes: c440adfbe3025 ("tracing/probes: Support BTF based data structure field access")
>> Signed-off-by: Carlos López <clopez@suse.de>
>> ---
>>   kernel/trace/trace_probe.c | 2 ++
>>   1 file changed, 2 insertions(+)
>>
>> diff --git a/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c
>> index 5e263c141574..5417e9712157 100644
>> --- a/kernel/trace/trace_probe.c
>> +++ b/kernel/trace/trace_probe.c
>> @@ -554,6 +554,8 @@ static int parse_btf_field(char *fieldname, const struct btf_type *type,
>>   			anon_offs = 0;
>>   			field = btf_find_struct_member(ctx->btf, type, fieldname,
>>   						       &anon_offs);
>> +			if (IS_ERR(field))
>> +				return PTR_ERR(field);
>>   			if (!field) {
>>   				trace_probe_log_err(ctx->offset, NO_BTF_FIELD);
>>   				return -ENOENT;
>> -- 
>> 2.35.3
>>
> 
> 

-- 
Carlos López
Security Engineer
SUSE Software Solutions

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] tracing/probes: fix error check in parse_btf_field()
  2024-05-26 12:27   ` Carlos López
@ 2024-05-26 23:13     ` Masami Hiramatsu
  0 siblings, 0 replies; 4+ messages in thread
From: Masami Hiramatsu @ 2024-05-26 23:13 UTC (permalink / raw)
  To: Carlos López
  Cc: linux-trace-kernel, Steven Rostedt, Mathieu Desnoyers,
	Alan Maguire, open list:TRACING

On Sun, 26 May 2024 14:27:56 +0200
Carlos López <clopez@suse.de> wrote:

> 
> Hi,
> 
> On 26/5/24 12:17, Masami Hiramatsu (Google) wrote:
> > On Sat, 25 May 2024 20:21:32 +0200
> > Carlos López <clopez@suse.de> wrote:
> > 
> >> btf_find_struct_member() might return NULL or an error via the
> >> ERR_PTR() macro. However, its caller in parse_btf_field() only checks
> >> for the NULL condition. Fix this by using IS_ERR() and returning the
> >> error up the stack.
> >>
> > 
> > Thanks for finding it!
> > I think this requires new error message for error_log file.
> > Can you add the log as
> > 
> > trace_probe_log_err(ctx->offset, BTF_ERROR);
> > 
> > And define BTF_ERROR in ERRORS@kernel/trace/trace_probe.h ?
> 
> Sounds good, but should we perhaps reuse BAD_BTF_TID?
> 
> ```
> C(BAD_BTF_TID,		"Failed to get BTF type info."),\
> ```
> 
> `btf_find_struct_member()` fails if `type` is not a struct or if it runs
> OOM while allocating the anon stack, so it seems appropriate.

Good point, it sounds reasonable.

Thanks!

> 
> Best,
> Carlos
> 
> > Thank you,
> > 
> >> Fixes: c440adfbe3025 ("tracing/probes: Support BTF based data structure field access")
> >> Signed-off-by: Carlos López <clopez@suse.de>
> >> ---
> >>   kernel/trace/trace_probe.c | 2 ++
> >>   1 file changed, 2 insertions(+)
> >>
> >> diff --git a/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c
> >> index 5e263c141574..5417e9712157 100644
> >> --- a/kernel/trace/trace_probe.c
> >> +++ b/kernel/trace/trace_probe.c
> >> @@ -554,6 +554,8 @@ static int parse_btf_field(char *fieldname, const struct btf_type *type,
> >>   			anon_offs = 0;
> >>   			field = btf_find_struct_member(ctx->btf, type, fieldname,
> >>   						       &anon_offs);
> >> +			if (IS_ERR(field))
> >> +				return PTR_ERR(field);
> >>   			if (!field) {
> >>   				trace_probe_log_err(ctx->offset, NO_BTF_FIELD);
> >>   				return -ENOENT;
> >> -- 
> >> 2.35.3
> >>
> > 
> > 
> 
> -- 
> Carlos López
> Security Engineer
> SUSE Software Solutions


-- 
Masami Hiramatsu (Google) <mhiramat@kernel.org>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-05-26 23:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-25 18:21 [PATCH] tracing/probes: fix error check in parse_btf_field() Carlos López
2024-05-26 10:17 ` Masami Hiramatsu
2024-05-26 12:27   ` Carlos López
2024-05-26 23:13     ` Masami Hiramatsu

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).