Skip to content

Commit b0b9850

Browse files
committed
Merge tag 'probes-fixes-v6.5-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace
Pull probe fixes from Masami Hiramatsu: - probe-events: add NULL check for some BTF API calls which can return error code and NULL. - ftrace selftests: check fprobe and kprobe event correctly. This fixes a miss condition of the test command. - kprobes: do not allow probing functions that start with "__cfi_" or "__pfx_" since those are auto generated for kernel CFI and not executed. * tag 'probes-fixes-v6.5-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace: kprobes: Prohibit probing on CFI preamble symbol selftests/ftrace: Fix to check fprobe event eneblement tracing/probes: Fix to add NULL check for BTF APIs
2 parents 98a05fe + de02f2a commit b0b9850

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

kernel/kprobes.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1545,6 +1545,17 @@ static int check_ftrace_location(struct kprobe *p)
15451545
return 0;
15461546
}
15471547

1548+
static bool is_cfi_preamble_symbol(unsigned long addr)
1549+
{
1550+
char symbuf[KSYM_NAME_LEN];
1551+
1552+
if (lookup_symbol_name(addr, symbuf))
1553+
return false;
1554+
1555+
return str_has_prefix("__cfi_", symbuf) ||
1556+
str_has_prefix("__pfx_", symbuf);
1557+
}
1558+
15481559
static int check_kprobe_address_safe(struct kprobe *p,
15491560
struct module **probed_mod)
15501561
{
@@ -1563,7 +1574,8 @@ static int check_kprobe_address_safe(struct kprobe *p,
15631574
within_kprobe_blacklist((unsigned long) p->addr) ||
15641575
jump_label_text_reserved(p->addr, p->addr) ||
15651576
static_call_text_reserved(p->addr, p->addr) ||
1566-
find_bug((unsigned long)p->addr)) {
1577+
find_bug((unsigned long)p->addr) ||
1578+
is_cfi_preamble_symbol((unsigned long)p->addr)) {
15671579
ret = -EINVAL;
15681580
goto out;
15691581
}

kernel/trace/trace_probe.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -386,12 +386,12 @@ static const struct btf_type *find_btf_func_proto(const char *funcname)
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,
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[],
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);

tools/testing/selftests/ftrace/test.d/dynevent/add_remove_btfarg.tc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ if grep -qF "f[:[<group>/][<event>]] <func-name>[%return] [<args>]" README ; the
1313
FPROBES=yes
1414
fi
1515

16-
if [ -z "$KPROBES" -a "$FPROBES" ] ; then
16+
if [ -z "$KPROBES" -a -z "$FPROBES" ] ; then
1717
exit_unsupported
1818
fi
1919

0 commit comments

Comments
 (0)