android_kernel_google_msm/arch/x86
Thomas Gleixner 12bdf05727 x86/process: Add proper bound checks in 64bit get_wchan()
commit eddd3826a1a0190e5235703d1e666affa4d13b96 upstream.

Dmitry Vyukov reported the following using trinity and the memory
error detector AddressSanitizer
(https://code.google.com/p/address-sanitizer/wiki/AddressSanitizerForKernel).

[ 124.575597] ERROR: AddressSanitizer: heap-buffer-overflow on
address ffff88002e280000
[ 124.576801] ffff88002e280000 is located 131938492886538 bytes to
the left of 28857600-byte region [ffffffff81282e0a, ffffffff82e0830a)
[ 124.578633] Accessed by thread T10915:
[ 124.579295] inlined in describe_heap_address
./arch/x86/mm/asan/report.c:164
[ 124.579295] #0 ffffffff810dd277 in asan_report_error
./arch/x86/mm/asan/report.c:278
[ 124.580137] #1 ffffffff810dc6a0 in asan_check_region
./arch/x86/mm/asan/asan.c:37
[ 124.581050] #2 ffffffff810dd423 in __tsan_read8 ??:0
[ 124.581893] #3 ffffffff8107c093 in get_wchan
./arch/x86/kernel/process_64.c:444

The address checks in the 64bit implementation of get_wchan() are
wrong in several ways:

 - The lower bound of the stack is not the start of the stack
   page. It's the start of the stack page plus sizeof (struct
   thread_info)

 - The upper bound must be:

       top_of_stack - TOP_OF_KERNEL_STACK_PADDING - 2 * sizeof(unsigned long).

   The 2 * sizeof(unsigned long) is required because the stack pointer
   points at the frame pointer. The layout on the stack is: ... IP FP
   ... IP FP. So we need to make sure that both IP and FP are in the
   bounds.

Fix the bound checks and get rid of the mix of numeric constants, u64
and unsigned long. Making all unsigned long allows us to use the same
function for 32bit as well.

Use READ_ONCE() when accessing the stack. This does not prevent a
concurrent wakeup of the task and the stack changing, but at least it
avoids TOCTOU.

Also check task state at the end of the loop. Again that does not
prevent concurrent changes, but it avoids walking for nothing.

Add proper comments while at it.

Reported-by: Dmitry Vyukov <dvyukov@google.com>
Reported-by: Sasha Levin <sasha.levin@oracle.com>
Based-on-patch-from: Wolfram Gloger <wmglo@dent.med.uni-muenchen.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Borislav Petkov <bp@alien8.de>
Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Andrey Konovalov <andreyknvl@google.com>
Cc: Kostya Serebryany <kcc@google.com>
Cc: Alexander Potapenko <glider@google.com>
Cc: kasan-dev <kasan-dev@googlegroups.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Wolfram Gloger <wmglo@dent.med.uni-muenchen.de>
Link: http://lkml.kernel.org/r/20150930083302.694788319@linutronix.de
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
[lizf: Backported to 3.4:
 - s/READ_ONCE/ACCESS_ONCE
 - remove TOP_OF_KERNEL_STACK_PADDING]
Signed-off-by: Zefan Li <lizefan@huawei.com>
2016-04-27 18:55:25 +08:00
..
boot x86, build: Pass in additional -mno-mmx, -mno-sse options 2014-06-07 16:02:08 -07:00
configs
crypto crypto: ghash-clmulni: specify context size for ghash async algorithm 2016-04-27 18:55:17 +08:00
ia32
include/asm KVM: x86: trap AMD MSRs for the TSeg base and mask 2016-04-27 18:55:23 +08:00
kernel x86/process: Add proper bound checks in 64bit get_wchan() 2016-04-27 18:55:25 +08:00
kvm KVM: x86: trap AMD MSRs for the TSeg base and mask 2016-04-27 18:55:23 +08:00
lguest x86, mm: Patch out arch_flush_lazy_mmu_mode() when running on bare metal 2013-04-16 21:27:27 -07:00
lib x86-64: Fix the failure case in copy_user_handle_tail() 2013-03-28 12:12:26 -07:00
math-emu x86/ldt: Correct FPU emulation access to LDT 2016-03-21 09:17:51 +08:00
mm x86, mm/ASLR: Fix stack randomization on 64-bit systems 2015-04-14 17:33:58 +08:00
net x86: bpf_jit: fix compilation of large bpf programs 2015-09-18 09:20:42 +08:00
oprofile
pci x86/PCI: Use host bridge _CRS info on Foxconn K8M890-8237A 2015-10-22 09:20:03 +08:00
platform x86/efi: Fix dummy variable buffer allocation 2014-06-07 16:02:10 -07:00
power x86/ldt: Make modify_ldt synchronous 2016-03-21 09:17:50 +08:00
syscalls x86, x32: Use compat shims for io_{setup,submit} 2014-06-30 20:01:33 -07:00
tools
um x86, um: actually mark system call tables readonly 2015-04-14 17:33:49 +08:00
vdso x86/vdso: Fix the build on GCC5 2015-06-19 11:40:25 +08:00
video
xen x86/xen: Do not clip xen_e820_map to xen_e820_map_entries when sanitizing map 2016-04-27 18:55:24 +08:00
.gitignore
Kbuild
Kconfig config: Enable NEED_DMA_MAP_STATE by default when SWIOTLB is selected 2015-06-19 11:40:34 +08:00
Kconfig.cpu
Kconfig.debug
Makefile
Makefile.um
Makefile_32.cpu