History

tracing/probes: Fix to add NULL check for BTF APIs

Since find_btf_func_param() abd btf_type_by_id() can return NULL, the caller must check the return value correctly. Link: https://lore.kernel.org/all/169024903951.395371.11361556840733470934.stgit@devnote2/

Masami Hiramatsu (Google) committed 3 years ago

Commit 1f9f4f41 parent 6eaae191 file · +4 −4Browse files

Showing the changes to kernel/trace (1 of 1 file). Show all

Unified · Split

kernel/trace/trace_probe.c+4−4
@@ -386,12 +386,12 @@ static const struct btf_type *find_btf_func_proto(const char *funcname) · 385 unmodified lines
386386
387387 /* Get BTF_KIND_FUNC type */
388388 t = btf_type_by_id(btf, id);
389− if (!btf_type_is_func(t))
389+ if (!t || !btf_type_is_func(t))
390390 return ERR_PTR(-ENOENT);
391391
392392 /* The type of BTF_KIND_FUNC is BTF_KIND_FUNC_PROTO */
393393 t = btf_type_by_id(btf, t->type);
394− if (!btf_type_is_func_proto(t))
394+ if (!t || !btf_type_is_func_proto(t))
395395 return ERR_PTR(-ENOENT);
396396
397397 return t;
@@ -443,7 +443,7 @@ static int parse_btf_arg(const char *varname, struct fetch_insn *code, · 45 unmodified lines
443443 if (!ctx->params) {
444444 params = find_btf_func_param(ctx->funcname, &ctx->nr_params,
445445 ctx->flags & TPARG_FL_TPOINT);
446− if (IS_ERR(params)) {
446+ if (IS_ERR_OR_NULL(params)) {
447447 trace_probe_log_err(ctx->offset, NO_BTF_ENTRY);
448448 return PTR_ERR(params);
449449 }
@@ -1273,7 +1273,7 @@ const char **traceprobe_expand_meta_args(int argc, const char *argv[], · 823 unmodified lines
12731273
12741274 params = find_btf_func_param(ctx->funcname, &nr_params,
12751275 ctx->flags & TPARG_FL_TPOINT);
1276− if (IS_ERR(params)) {
1276+ if (IS_ERR_OR_NULL(params)) {
12771277 if (args_idx != -1) {
12781278 /* $arg* requires BTF info */
12791279 trace_probe_log_err(0, NOSUP_BTFARG);