[PATCH v2 0/3] tracing: Fix synthetic event bug

Steven Rostedt posted 3 patches 3 years, 6 months ago
kernel/trace/trace_eprobe.c       |  60 ++------------------
kernel/trace/trace_events_synth.c |  23 ++++++--
kernel/trace/trace_kprobe.c       |  60 ++------------------
kernel/trace/trace_probe_kernel.h | 115 ++++++++++++++++++++++++++++++++++++++
4 files changed, 142 insertions(+), 116 deletions(-)
create mode 100644 kernel/trace/trace_probe_kernel.h
[PATCH v2 0/3] tracing: Fix synthetic event bug
Posted by Steven Rostedt 3 years, 6 months ago
The follow commands caused a crash:

  # cd /sys/kernel/tracing
  # echo 's:open char file[]' > dynamic_events
  # echo 'hist:keys=common_pid:file=filename:onchange($file).trace(open,$file)' > events/syscalls/sys_enter_openat/trigger'
  # echo 1 > events/synthetic/open/enable

BOOM!

The problem is that the synthetic event field "char file[]" will read
the value given to it as a string without any memory checks to make sure
the address is valid. The above example will pass in the user space
address and the sythetic event code will happily call strlen() on it
and then strscpy() where either one will cause an oops when accessing
user space addresses.

Changes since v1: https://lore.kernel.org/all/20221011212501.773319898@goodmis.org/

 - Handle "(fault)" printing when there's a fault

Steven Rostedt (Google) (3):
      tracing: Move duplicate code of trace_kprobe/eprobe.c into header
      tracing: Add "(fault)" name injection to kernel probes
      tracing: Fix reading strings from synthetic events

----
 kernel/trace/trace_eprobe.c       |  60 ++------------------
 kernel/trace/trace_events_synth.c |  23 ++++++--
 kernel/trace/trace_kprobe.c       |  60 ++------------------
 kernel/trace/trace_probe_kernel.h | 115 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 142 insertions(+), 116 deletions(-)
 create mode 100644 kernel/trace/trace_probe_kernel.h
Re: [PATCH v2 0/3] tracing: Fix synthetic event bug
Posted by Tom Zanussi 3 years, 6 months ago
Hi Steve,

On Wed, 2022-10-12 at 06:40 -0400, Steven Rostedt wrote:
> 
> The follow commands caused a crash:
> 
>   # cd /sys/kernel/tracing
>   # echo 's:open char file[]' > dynamic_events
>   # echo
> 'hist:keys=common_pid:file=filename:onchange($file).trace(open,$file)
> ' > events/syscalls/sys_enter_openat/trigger'
>   # echo 1 > events/synthetic/open/enable
> 
> BOOM!
> 
> The problem is that the synthetic event field "char file[]" will read
> the value given to it as a string without any memory checks to make
> sure
> the address is valid. The above example will pass in the user space
> address and the sythetic event code will happily call strlen() on it
> and then strscpy() where either one will cause an oops when accessing
> user space addresses.
> 
> Changes since v1:
> https://lore.kernel.org/all/20221011212501.773319898@goodmis.org/
> 
>  - Handle "(fault)" printing when there's a fault


Thanks for fixing the synthetic event string tracing bug, along with
the other nice cleanup.

Reviewed-by: Tom Zanussi <zanussi@kernel.org>



> 
> Steven Rostedt (Google) (3):
>       tracing: Move duplicate code of trace_kprobe/eprobe.c into
> header
>       tracing: Add "(fault)" name injection to kernel probes
>       tracing: Fix reading strings from synthetic events
> 
> ----
>  kernel/trace/trace_eprobe.c       |  60 ++------------------
>  kernel/trace/trace_events_synth.c |  23 ++++++--
>  kernel/trace/trace_kprobe.c       |  60 ++------------------
>  kernel/trace/trace_probe_kernel.h | 115
> ++++++++++++++++++++++++++++++++++++++
>  4 files changed, 142 insertions(+), 116 deletions(-)
>  create mode 100644 kernel/trace/trace_probe_kernel.h
Re: [PATCH v2 0/3] tracing: Fix synthetic event bug
Posted by Masami Hiramatsu 3 years, 6 months ago
Hi,

2022年10月12日(水) 11:45 Steven Rostedt <rostedt@goodmis.org>:
>
>
> The follow commands caused a crash:
>
>   # cd /sys/kernel/tracing
>   # echo 's:open char file[]' > dynamic_events
>   # echo 'hist:keys=common_pid:file=filename:onchange($file).trace(open,$file)' > events/syscalls/sys_enter_openat/trigger'
>   # echo 1 > events/synthetic/open/enable
>
> BOOM!
>
> The problem is that the synthetic event field "char file[]" will read
> the value given to it as a string without any memory checks to make sure
> the address is valid. The above example will pass in the user space
> address and the sythetic event code will happily call strlen() on it
> and then strscpy() where either one will cause an oops when accessing
> user space addresses.
>
> Changes since v1: https://lore.kernel.org/all/20221011212501.773319898@goodmis.org/

Thanks, this series of patches looks good to me.

Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>

Thank you!

>
>  - Handle "(fault)" printing when there's a fault
>
> Steven Rostedt (Google) (3):
>       tracing: Move duplicate code of trace_kprobe/eprobe.c into header
>       tracing: Add "(fault)" name injection to kernel probes
>       tracing: Fix reading strings from synthetic events
>
> ----
>  kernel/trace/trace_eprobe.c       |  60 ++------------------
>  kernel/trace/trace_events_synth.c |  23 ++++++--
>  kernel/trace/trace_kprobe.c       |  60 ++------------------
>  kernel/trace/trace_probe_kernel.h | 115 ++++++++++++++++++++++++++++++++++++++
>  4 files changed, 142 insertions(+), 116 deletions(-)
>  create mode 100644 kernel/trace/trace_probe_kernel.h



-- 
Masami Hiramatsu
mailto:masami.hiramatsu@gmail.com