android_kernel_asus_sm8350/arch
He Ying 348831a9e8 powerpc/kasan: Silence KASAN warnings in __get_wchan()
[ Upstream commit a1b29ba2f2c171b9bea73be993bfdf0a62d37d15 ]

The following KASAN warning was reported in our kernel.

  BUG: KASAN: stack-out-of-bounds in get_wchan+0x188/0x250
  Read of size 4 at addr d216f958 by task ps/14437

  CPU: 3 PID: 14437 Comm: ps Tainted: G           O      5.10.0 #1
  Call Trace:
  [daa63858] [c0654348] dump_stack+0x9c/0xe4 (unreliable)
  [daa63888] [c035cf0c] print_address_description.constprop.3+0x8c/0x570
  [daa63908] [c035d6bc] kasan_report+0x1ac/0x218
  [daa63948] [c00496e8] get_wchan+0x188/0x250
  [daa63978] [c0461ec8] do_task_stat+0xce8/0xe60
  [daa63b98] [c0455ac8] proc_single_show+0x98/0x170
  [daa63bc8] [c03cab8c] seq_read_iter+0x1ec/0x900
  [daa63c38] [c03cb47c] seq_read+0x1dc/0x290
  [daa63d68] [c037fc94] vfs_read+0x164/0x510
  [daa63ea8] [c03808e4] ksys_read+0x144/0x1d0
  [daa63f38] [c005b1dc] ret_from_syscall+0x0/0x38
  --- interrupt: c00 at 0x8fa8f4
      LR = 0x8fa8cc

  The buggy address belongs to the page:
  page:98ebcdd2 refcount:0 mapcount:0 mapping:00000000 index:0x2 pfn:0x1216f
  flags: 0x0()
  raw: 00000000 00000000 01010122 00000000 00000002 00000000 ffffffff 00000000
  raw: 00000000
  page dumped because: kasan: bad access detected

  Memory state around the buggy address:
   d216f800: 00 00 00 00 00 f1 f1 f1 f1 00 00 00 00 00 00 00
   d216f880: f2 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  >d216f900: 00 00 00 00 00 00 00 00 00 00 00 f1 f1 f1 f1 00
                                            ^
   d216f980: f2 f2 f2 f2 f2 f2 f2 00 00 00 00 00 00 00 00 00
   d216fa00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

After looking into this issue, I find the buggy address belongs
to the task stack region. It seems KASAN has something wrong.
I look into the code of __get_wchan in x86 architecture and
find the same issue has been resolved by the commit
f7d27c35dd ("x86/mm, kasan: Silence KASAN warnings in get_wchan()").
The solution could be applied to powerpc architecture too.

As Andrey Ryabinin said, get_wchan() is racy by design, it may
access volatile stack of running task, thus it may access
redzone in a stack frame and cause KASAN to warn about this.

Use READ_ONCE_NOCHECK() to silence these warnings.

Reported-by: Wanming Hu <huwanming@huaweil.com>
Signed-off-by: He Ying <heying24@huawei.com>
Signed-off-by: Chen Jingwen <chenjingwen6@huawei.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20220121014418.155675-1-heying24@huawei.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
2022-06-22 14:11:19 +02:00
..
alpha alpha: define get_cycles macro for arch-override 2022-06-22 14:11:14 +02:00
arc ARC: entry: fix syscall_trace_exit argument 2022-04-27 13:50:49 +02:00
arm arm: use fallback for random_get_entropy() instead of zero 2022-06-22 14:11:15 +02:00
arm64 bpf, arm64: Clear prog->jited_len along prog->jited 2022-06-14 18:11:57 +02:00
c6x mm: consolidate pgtable_cache_init() and pgd_cache_init() 2019-09-24 15:54:09 -07:00
csky perf: Protect perf_guest_cbs with RCU 2022-01-20 09:19:18 +01:00
h8300 h8300: fix PREEMPTION build, TI_PRE_COUNT undefined 2021-02-17 10:35:18 +01:00
hexagon hexagon: export raw I/O routines for modules 2021-11-26 10:47:21 +01:00
ia64 ia64: define get_cycles macro for arch-override 2022-06-22 14:11:14 +02:00
m68k m68k: use fallback for random_get_entropy() instead of zero 2022-06-22 14:11:15 +02:00
microblaze uaccess: fix nios2 and microblaze get_user_8() 2022-04-15 14:18:08 +02:00
mips mips: use fallback for random_get_entropy() instead of just c0 random 2022-06-22 14:11:15 +02:00
nds32 nds32: fix access_ok() checks in get/put_user 2022-03-28 08:46:48 +02:00
nios2 nios2: use fallback for random_get_entropy() instead of zero 2022-06-22 14:11:15 +02:00
openrisc openrisc: start CPU timer early in boot 2022-06-14 18:11:28 +02:00
parisc parisc: define get_cycles macro for arch-override 2022-06-22 14:11:14 +02:00
powerpc powerpc/kasan: Silence KASAN warnings in __get_wchan() 2022-06-22 14:11:19 +02:00
riscv riscv module: remove (NOLOAD) 2022-04-15 14:18:31 +02:00
s390 s390: define get_cycles macro for arch-override 2022-06-22 14:11:14 +02:00
sh sh: define __BIG_ENDIAN for math-emu 2021-11-26 10:47:17 +01:00
sparc sparc: use fallback for random_get_entropy() instead of zero 2022-06-22 14:11:15 +02:00
um um: use fallback for random_get_entropy() instead of zero 2022-06-22 14:11:15 +02:00
unicore32 mm: treewide: clarify pgtable_page_{ctor,dtor}() naming 2019-09-26 10:10:44 -07:00
x86 x86/tsc: Use fallback for random_get_entropy() instead of zero 2022-06-22 14:11:15 +02:00
xtensa xtensa: use fallback for random_get_entropy() instead of zero 2022-06-22 14:11:15 +02:00
.gitignore
Kconfig Revert: "ring-buffer: Remove HAVE_64BIT_ALIGNED_ACCESS" 2020-12-30 11:51:47 +01:00