tracing/probes: fix error check in parse_btf_field()
PATCH v2 1/1 tracing/probes: fix error check in parse_btf_field()
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 <[email protected]>
---
v2: added call to trace_probe_log_err()
kernel/trace/trace_probe.c | 4 ++++ 1 file changed, 4 insertions(+)
kernel/trace/trace_probe.c +4 -0
@@ -554,6 +554,10 @@ 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)) { +trace_probe_log_err (ctx->offset,BAD_BTF_TID ); +return PTR_ERR (field); + }if (!field) {trace_probe_log_err (ctx->offset,NO_BTF_FIELD );return -ENOENT ;
Signature · 1 line
2.35.3
Masami Hiramatsu (Google)
maintainerQuoted 5 lines · On Mon, 27 May 2024 11:43:52 +0200 Carlos López <[email protected]> wrote:
btf_find_struct_member()might return NULL or an error via theERR_PTR()macro. However, its caller inparse_btf_field()only checks for the NULL condition. Fix this by usingIS_ERR()and returning the error up the stack.
Thanks for updating! This version looks good to me. Let me pick this to probes/fixes.
Thank you,
Quoted 26 lines
Fixes c440adfbe3025 ("tracing/probes: Support BTF based data structure field access")Signed-off-by Carlos López <[email protected]>---
v2: added call totrace_probe_log_err()kernel/trace/trace_probe.c | 4 ++++ 1 file changed, 4 insertions(+)kernel/trace/trace_probe.c +4
-0@@ -554,6 +554,10 @@ 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)) { +trace_probe_log_err (ctx->offset,BAD_BTF_TID ); +return PTR_ERR (field); + }if (!field) {trace_probe_log_err (ctx->offset,NO_BTF_FIELD );return -ENOENT ;Signature · 1 line
2.35.3
Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>