tracing/probes: fix error check in parse_btf_field()
authorCarlos López <clopez@suse.de>
Mon, 27 May 2024 09:43:52 +0000 (11:43 +0200)
committerMasami Hiramatsu (Google) <mhiramat@kernel.org>
Mon, 27 May 2024 12:32:35 +0000 (21:32 +0900)
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.

Link: https://lore.kernel.org/all/20240527094351.15687-1-clopez@suse.de/
Fixes: c440adfbe3025 ("tracing/probes: Support BTF based data structure field access")
Signed-off-by: Carlos López <clopez@suse.de>
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
kernel/trace/trace_probe.c

index 5e263c14157403cd9ad65be5bf543fe525fb09ba..39877c80d6cb9ace8163e2bfd16525629562ba82 100644 (file)
@@ -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;