History

Merge tag 'probes-fixes-v7.2-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace

Pull probes fixes from Masami Hiramatsu: "fprobe fixes and spelling typos: - Fix NULL pointer dereference in fprobe_fgraph_entry(). Prevent general protection faults by checking shadow-stack reservation bounds. Skip mid-flight registered fprobes that were not counted during sizing. eprobe: fix string pointer extraction - Correct the casting of string pointers read from the ringbuffer to prevent truncation of base event pointer variables when dereferencing FILTER_PTR_STRING fields. tracing/probes: clean up argument parsing and BTF helper logic - Make the $ prefix mandatory for comm access: Require the $ prefix for special fetcharg variables like $comm and $COMM, preventing naming conflicts with regular BTF-based event fields. - Fix double addition of offset for @+FOFFSET: Clear the temporary offset variable after setting the FETCH_OP_FOFFS instruction to avoid applying the offset multiple times. - Remove WARN_ON_ONCE from parse_btf_arg: Prevent triggering a kernel warning via user-space input when creating a kprobe event on a raw address. - Fix typo in a log message: Correct a spelling error ("$-valiable") in trace probe log messages. samples/trace_events: improve error checking - Validate the thread pointer returned from kthread_run() in the trace events sample code to properly handle thread creation failures" * tag 'probes-fixes-v7.2-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace: tracing/probes: Make the $ prefix mandatory for comm access tracing/fprobe: Fix NULL pointer dereference in fprobe_fgraph_entry() tracing/probes: Fix double addition of offset for @+FOFFSET tracing: eprobe: read the complete FILTER_PTR_STRING pointer tracing/events: Fix to check the simple_tsk_fn creation tracing/probes: Remove WARN_ON_ONCE from parse_btf_arg tracing: probes: fix typo in a log message

Linus Torvalds committed 4 months ago

Commit 665159e2 parents dc59e4f a3692995 files · +25 −8Browse files

Unified · Split

5 files
  1. kernel/trace/fprobe.c +10 −0
  2. kernel/trace/trace_eprobe.c +1 −1
  3. kernel/trace/trace_probe.c +9 −6
  4. kernel/trace/trace_probe.h +1 −1
  5. samples/trace_events/trace-events-sample.c +4 −0
kernel/trace/fprobe.c+10−0
@@ -613,6 +613,16 @@ static int fprobe_fgraph_entry(struct ftrace_graph_ent *trace, struct fgraph_ops · 612 unmodified lines
613613 continue;
614614
615615 data_size = fp->entry_data_size;
616+ /*
617+ * The list may have grown since it was sized, so this node
618+ * may not fit. Skip it as missed rather than overrun the
619+ * reservation.
620+ */
621+ if (fp->exit_handler &&
622+ used + FPROBE_HEADER_SIZE_IN_LONG + SIZE_IN_LONG(data_size) > reserved_words) {
623+ fp->nmissed++;
624+ continue;
625+ }
616626 if (data_size && fp->exit_handler)
617627 data = fgraph_data + used + FPROBE_HEADER_SIZE_IN_LONG;
618628 else
kernel/trace/trace_eprobe.c+1−1
@@ -315,7 +315,7 @@ get_event_field(struct fetch_insn *code, void *rec) · 314 unmodified lines
315315 val = (unsigned long)addr;
316316 break;
317317 case FILTER_PTR_STRING:
318− val = (unsigned long)(*(char *)addr);
318+ val = *(unsigned long *)addr;
319319 break;
320320 default:
321321 WARN_ON_ONCE(1);
kernel/trace/trace_probe.c+9−6
@@ -342,10 +342,6 @@ static int parse_trace_event(char *arg, struct fetch_insn *code, · 341 unmodified lines
342342 ret = parse_trace_event_arg(arg, code, ctx);
343343 if (!ret)
344344 return 0;
345− if (strcmp(arg, "comm") == 0 || strcmp(arg, "COMM") == 0) {
346− code->op = FETCH_OP_COMM;
347− return 0;
348− }
349345 return -EINVAL;
350346 }
351347
@@ -678,7 +674,7 @@ static int parse_btf_arg(char *varname, · 326 unmodified lines
678674 int i, is_ptr, ret;
679675 u32 tid;
680676
681− if (WARN_ON_ONCE(!ctx->funcname && !(ctx->flags & TPARG_FL_TEVENT)))
677+ if (!ctx->funcname && !(ctx->flags & TPARG_FL_TEVENT))
682678 return -EINVAL;
683679
684680 is_ptr = split_next_field(varname, &field, ctx);
@@ -1068,8 +1064,14 @@ static int parse_probe_vars(char *orig_arg, const struct fetch_type *t, · 383 unmodified lines
10681064 int len;
10691065
10701066 if (ctx->flags & TPARG_FL_TEVENT) {
1071− if (parse_trace_event(arg, code, ctx) < 0)
1067+ if (parse_trace_event(arg, code, ctx) < 0) {
1068+ /* 'comm' should be checked after field parsing. */
1069+ if (strcmp(arg, "comm") == 0 || strcmp(arg, "COMM") == 0) {
1070+ code->op = FETCH_OP_COMM;
1071+ return 0;
1072+ }
10721073 goto inval;
1074+ }
10731075 return 0;
10741076 }
10751077
@@ -1241,6 +1243,7 @@ parse_probe_arg(char *arg, const struct fetch_type *type, · 165 unmodified lines
12411243
12421244 code->op = FETCH_OP_FOFFS;
12431245 code->immediate = (unsigned long)offset; // imm64?
1246+ offset = 0;
12441247 } else {
12451248 /* uprobes don't support symbols */
12461249 if (!(ctx->flags & TPARG_FL_KERNEL)) {
kernel/trace/trace_probe.h+1−1
@@ -511,7 +511,7 @@ extern int traceprobe_define_arg_fields(struct trace_event_call *event_call, · 510 unmodified lines
511511 C(NO_RETVAL, "This function returns 'void' type"), \
512512 C(BAD_STACK_NUM, "Invalid stack number"), \
513513 C(BAD_ARG_NUM, "Invalid argument number"), \
514− C(BAD_VAR, "Invalid $-valiable specified"), \
514+ C(BAD_VAR, "Invalid $-variable specified"), \
515515 C(BAD_REG_NAME, "Invalid register name"), \
516516 C(BAD_MEM_ADDR, "Invalid memory address"), \
517517 C(BAD_IMM, "Invalid immediate value"), \
samples/trace_events/trace-events-sample.c+4−0
@@ -107,6 +107,10 @@ int foo_bar_reg(void) · 106 unmodified lines
107107 * for consistency sake, we still take the thread_mutex.
108108 */
109109 simple_tsk_fn = kthread_run(simple_thread_fn, NULL, "event-sample-fn");
110+ if (IS_ERR_OR_NULL(simple_tsk_fn)) {
111+ pr_err("Failed to create simple_thread_fn\n");
112+ simple_tsk_fn = NULL;
113+ }
110114 out:
111115 mutex_unlock(&thread_mutex);
112116 return 0;