• Steven Rostedt (Google)'s avatar
    tracing: Fix reading strings from synthetic events · 0934ae99
    Steven Rostedt (Google) authored
    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.
    
    Use the helper functions from trace_kprobe and trace_eprobe that can
    read strings safely (and actually succeed when the address is from user
    space and the memory is mapped in).
    
    Now the above can show:
    
         packagekitd-1721    [000] ...2.   104.597170: open: file=/usr/lib/rpm/fileattrs/cmake.attr
        in:imjournal-978     [006] ...2.   104.599642: open: file=/var/lib/rsyslog/imjournal.state.tmp
         packagekitd-1721    [000] ...2.   104.626308: open: file=/usr/lib/rpm/fileattrs/debuginfo.attr
    
    Link: https://lkml.kernel.org/r/20221012104534.826549315@goodmis.org
    
    Cc: stable@vger.kernel.org
    Cc: Andrew Morton <akpm@linux-foundation.org>
    Cc: Tom Zanussi <zanussi@kernel.org>
    Acked-by: default avatarMasami Hiramatsu (Google) <mhiramat@kernel.org>
    Reviewed-by: default avatarTom Zanussi <zanussi@kernel.org>
    Fixes: bd82631d ("tracing: Add support for dynamic strings to synthetic events")
    Signed-off-by: default avatarSteven Rostedt (Google) <rostedt@goodmis.org>
    0934ae99
trace_events_synth.c 53.7 KB