• Jin Yao's avatar
    perf/core: Drop kernel samples even though :u is specified · d6f90404
    Jin Yao authored
    [ Upstream commit cc1582c2 ]
    
    When doing sampling, for example:
    
      perf record -e cycles:u ...
    
    On workloads that do a lot of kernel entry/exits we see kernel
    samples, even though :u is specified. This is due to skid existing.
    
    This might be a security issue because it can leak kernel addresses even
    though kernel sampling support is disabled.
    
    The patch drops the kernel samples if exclude_kernel is specified.
    
    For example, test on Haswell desktop:
    
      perf record -e cycles:u <mgen>
      perf report --stdio
    
    Before patch applied:
    
        99.77%  mgen     mgen              [.] buf_read
         0.20%  mgen     mgen              [.] rand_buf_init
         0.01%  mgen     [kernel.vmlinux]  [k] apic_timer_interrupt
         0.00%  mgen     mgen              [.] last_free_elem
         0.00%  mgen     libc-2.23.so      [.] __random_r
         0.00%  mgen     libc-2.23.so      [.] _int_malloc
         0.00%  mgen     mgen              [.] rand_array_init
         0.00%  mgen     [kernel.vmlinux]  [k] page_fault
         0.00%  mgen     libc-2.23.so      [.] __random
         0.00%  mgen     libc-2.23.so      [.] __strcasestr
         0.00%  mgen     ld-2.23.so        [.] strcmp
         0.00%  mgen     ld-2.23.so        [.] _dl_start
         0.00%  mgen     libc-2.23.so      [.] sched_setaffinity@@GLIBC_2.3.4
         0.00%  mgen     ld-2.23.so        [.] _start
    
    We can see kernel symbols apic_timer_interrupt and page_fault.
    
    After patch applied:
    
        99.79%  mgen     mgen           [.] buf_read
         0.19%  mgen     mgen           [.] rand_buf_init
         0.00%  mgen     libc-2.23.so   [.] __random_r
         0.00%  mgen     mgen           [.] rand_array_init
         0.00%  mgen     mgen           [.] last_free_elem
         0.00%  mgen     libc-2.23.so   [.] vfprintf
         0.00%  mgen     libc-2.23.so   [.] rand
         0.00%  mgen     libc-2.23.so   [.] __random
         0.00%  mgen     libc-2.23.so   [.] _int_malloc
         0.00%  mgen     libc-2.23.so   [.] _IO_doallocbuf
         0.00%  mgen     ld-2.23.so     [.] do_lookup_x
         0.00%  mgen     ld-2.23.so     [.] open_verify.constprop.7
         0.00%  mgen     ld-2.23.so     [.] _dl_important_hwcaps
         0.00%  mgen     libc-2.23.so   [.] sched_setaffinity@@GLIBC_2.3.4
         0.00%  mgen     ld-2.23.so     [.] _start
    
    There are only userspace symbols.
    Signed-off-by: default avatarJin Yao <yao.jin@linux.intel.com>
    Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
    Cc: <stable@vger.kernel.org>
    Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
    Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
    Cc: Jiri Olsa <jolsa@redhat.com>
    Cc: Linus Torvalds <torvalds@linux-foundation.org>
    Cc: Namhyung Kim <namhyung@kernel.org>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Stephane Eranian <eranian@google.com>
    Cc: Thomas Gleixner <tglx@linutronix.de>
    Cc: Vince Weaver <vincent.weaver@maine.edu>
    Cc: acme@kernel.org
    Cc: jolsa@kernel.org
    Cc: kan.liang@intel.com
    Cc: mark.rutland@arm.com
    Cc: will.deacon@arm.com
    Cc: yao.jin@intel.com
    Link: http://lkml.kernel.org/r/1495706947-3744-1-git-send-email-yao.jin@linux.intel.comSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
    Signed-off-by: default avatarSasha Levin <alexander.levin@verizon.com>
    d6f90404
core.c 212 KB