kcov: prefault the kcov_area
authorMark Rutland <[email protected]>
Thu, 14 Jun 2018 22:27:37 +0000 (15:27 -0700)
committerLinus Torvalds <[email protected]>
Thu, 14 Jun 2018 22:55:24 +0000 (07:55 +0900)
commitdc55daff9040a90adce97208e776ee0bf515ab12
tree28b562c0d2a06c901e481d217b85cdf1a24723a6
parentc9484b986ef03492357fddd50afbdd02929cfa72
kcov: prefault the kcov_area

On many architectures the vmalloc area is lazily faulted in upon first
access.  This is problematic for KCOV, as __sanitizer_cov_trace_pc
accesses the (vmalloc'd) kcov_area, and fault handling code may be
instrumented.  If an access to kcov_area faults, this will result in
mutual recursion through the fault handling code and
__sanitizer_cov_trace_pc(), eventually leading to stack corruption
and/or overflow.

We can avoid this by faulting in the kcov_area before
__sanitizer_cov_trace_pc() is permitted to access it.  Once it has been
faulted in, it will remain present in the process page tables, and will
not fault again.

[[email protected]: code cleanup]
[[email protected]: add comment explaining kcov_fault_in_area()]
[[email protected]: fancier code comment from Mark]
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Mark Rutland <[email protected]>
Acked-by: Andrey Ryabinin <[email protected]>
Cc: Dmitry Vyukov <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
kernel/kcov.c