mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-25 22:25:37 +07:00
b53f40db59
Resuming from a suspend operation is showing a KASAN false positive warning: BUG: KASAN: stack-out-of-bounds in unwind_get_return_address+0x11d/0x130 at addr ffff8803867d7878 Read of size 8 by task pm-suspend/7774 page:ffffea000e19f5c0 count:0 mapcount:0 mapping: (null) index:0x0 flags: 0x2ffff0000000000() page dumped because: kasan: bad access detected CPU: 0 PID: 7774 Comm: pm-suspend Tainted: G B 4.9.0-rc7+ #8 Hardware name: Gigabyte Technology Co., Ltd. Z170X-UD5/Z170X-UD5-CF, BIOS F5 03/07/2016 Call Trace: dump_stack+0x63/0x82 kasan_report_error+0x4b4/0x4e0 ? acpi_hw_read_port+0xd0/0x1ea ? kfree_const+0x22/0x30 ? acpi_hw_validate_io_request+0x1a6/0x1a6 __asan_report_load8_noabort+0x61/0x70 ? unwind_get_return_address+0x11d/0x130 unwind_get_return_address+0x11d/0x130 ? unwind_next_frame+0x97/0xf0 __save_stack_trace+0x92/0x100 save_stack_trace+0x1b/0x20 save_stack+0x46/0xd0 ? save_stack_trace+0x1b/0x20 ? save_stack+0x46/0xd0 ? kasan_kmalloc+0xad/0xe0 ? kasan_slab_alloc+0x12/0x20 ? acpi_hw_read+0x2b6/0x3aa ? acpi_hw_validate_register+0x20b/0x20b ? acpi_hw_write_port+0x72/0xc7 ? acpi_hw_write+0x11f/0x15f ? acpi_hw_read_multiple+0x19f/0x19f ? memcpy+0x45/0x50 ? acpi_hw_write_port+0x72/0xc7 ? acpi_hw_write+0x11f/0x15f ? acpi_hw_read_multiple+0x19f/0x19f ? kasan_unpoison_shadow+0x36/0x50 kasan_kmalloc+0xad/0xe0 kasan_slab_alloc+0x12/0x20 kmem_cache_alloc_trace+0xbc/0x1e0 ? acpi_get_sleep_type_data+0x9a/0x578 acpi_get_sleep_type_data+0x9a/0x578 acpi_hw_legacy_wake_prep+0x88/0x22c ? acpi_hw_legacy_sleep+0x3c7/0x3c7 ? acpi_write_bit_register+0x28d/0x2d3 ? acpi_read_bit_register+0x19b/0x19b acpi_hw_sleep_dispatch+0xb5/0xba acpi_leave_sleep_state_prep+0x17/0x19 acpi_suspend_enter+0x154/0x1e0 ? trace_suspend_resume+0xe8/0xe8 suspend_devices_and_enter+0xb09/0xdb0 ? printk+0xa8/0xd8 ? arch_suspend_enable_irqs+0x20/0x20 ? try_to_freeze_tasks+0x295/0x600 pm_suspend+0x6c9/0x780 ? finish_wait+0x1f0/0x1f0 ? suspend_devices_and_enter+0xdb0/0xdb0 state_store+0xa2/0x120 ? kobj_attr_show+0x60/0x60 kobj_attr_store+0x36/0x70 sysfs_kf_write+0x131/0x200 kernfs_fop_write+0x295/0x3f0 __vfs_write+0xef/0x760 ? handle_mm_fault+0x1346/0x35e0 ? do_iter_readv_writev+0x660/0x660 ? __pmd_alloc+0x310/0x310 ? do_lock_file_wait+0x1e0/0x1e0 ? apparmor_file_permission+0x18/0x20 ? security_file_permission+0x73/0x1c0 ? rw_verify_area+0xbd/0x2b0 vfs_write+0x149/0x4a0 SyS_write+0xd9/0x1c0 ? SyS_read+0x1c0/0x1c0 entry_SYSCALL_64_fastpath+0x1e/0xad Memory state around the buggy address: ffff8803867d7700: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ffff8803867d7780: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >ffff8803867d7800: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 f4 ^ ffff8803867d7880: f3 f3 f3 f3 00 00 00 00 00 00 00 00 00 00 00 00 ffff8803867d7900: 00 00 00 f1 f1 f1 f1 04 f4 f4 f4 f3 f3 f3 f3 00 KASAN instrumentation poisons the stack when entering a function and unpoisons it when exiting the function. However, in the suspend path, some functions never return, so their stack never gets unpoisoned, resulting in stale KASAN shadow data which can cause later false positive warnings like the one above. Reported-by: Scott Bauer <scott.bauer@intel.com> Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com> Acked-by: Andrey Ryabinin <aryabinin@virtuozzo.com> Acked-by: Pavel Machek <pavel@ucw.cz> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
137 lines
2.9 KiB
ArmAsm
137 lines
2.9 KiB
ArmAsm
.text
|
|
#include <linux/linkage.h>
|
|
#include <asm/segment.h>
|
|
#include <asm/pgtable_types.h>
|
|
#include <asm/page_types.h>
|
|
#include <asm/msr.h>
|
|
#include <asm/asm-offsets.h>
|
|
#include <asm/frame.h>
|
|
|
|
# Copyright 2003 Pavel Machek <pavel@suse.cz>, distribute under GPLv2
|
|
|
|
.code64
|
|
/*
|
|
* Hooray, we are in Long 64-bit mode (but still running in low memory)
|
|
*/
|
|
ENTRY(wakeup_long64)
|
|
movq saved_magic, %rax
|
|
movq $0x123456789abcdef0, %rdx
|
|
cmpq %rdx, %rax
|
|
jne bogus_64_magic
|
|
|
|
movw $__KERNEL_DS, %ax
|
|
movw %ax, %ss
|
|
movw %ax, %ds
|
|
movw %ax, %es
|
|
movw %ax, %fs
|
|
movw %ax, %gs
|
|
movq saved_rsp, %rsp
|
|
|
|
movq saved_rbx, %rbx
|
|
movq saved_rdi, %rdi
|
|
movq saved_rsi, %rsi
|
|
movq saved_rbp, %rbp
|
|
|
|
movq saved_rip, %rax
|
|
jmp *%rax
|
|
ENDPROC(wakeup_long64)
|
|
|
|
bogus_64_magic:
|
|
jmp bogus_64_magic
|
|
|
|
ENTRY(do_suspend_lowlevel)
|
|
FRAME_BEGIN
|
|
subq $8, %rsp
|
|
xorl %eax, %eax
|
|
call save_processor_state
|
|
|
|
movq $saved_context, %rax
|
|
movq %rsp, pt_regs_sp(%rax)
|
|
movq %rbp, pt_regs_bp(%rax)
|
|
movq %rsi, pt_regs_si(%rax)
|
|
movq %rdi, pt_regs_di(%rax)
|
|
movq %rbx, pt_regs_bx(%rax)
|
|
movq %rcx, pt_regs_cx(%rax)
|
|
movq %rdx, pt_regs_dx(%rax)
|
|
movq %r8, pt_regs_r8(%rax)
|
|
movq %r9, pt_regs_r9(%rax)
|
|
movq %r10, pt_regs_r10(%rax)
|
|
movq %r11, pt_regs_r11(%rax)
|
|
movq %r12, pt_regs_r12(%rax)
|
|
movq %r13, pt_regs_r13(%rax)
|
|
movq %r14, pt_regs_r14(%rax)
|
|
movq %r15, pt_regs_r15(%rax)
|
|
pushfq
|
|
popq pt_regs_flags(%rax)
|
|
|
|
movq $.Lresume_point, saved_rip(%rip)
|
|
|
|
movq %rsp, saved_rsp
|
|
movq %rbp, saved_rbp
|
|
movq %rbx, saved_rbx
|
|
movq %rdi, saved_rdi
|
|
movq %rsi, saved_rsi
|
|
|
|
addq $8, %rsp
|
|
movl $3, %edi
|
|
xorl %eax, %eax
|
|
call x86_acpi_enter_sleep_state
|
|
/* in case something went wrong, restore the machine status and go on */
|
|
jmp .Lresume_point
|
|
|
|
.align 4
|
|
.Lresume_point:
|
|
/* We don't restore %rax, it must be 0 anyway */
|
|
movq $saved_context, %rax
|
|
movq saved_context_cr4(%rax), %rbx
|
|
movq %rbx, %cr4
|
|
movq saved_context_cr3(%rax), %rbx
|
|
movq %rbx, %cr3
|
|
movq saved_context_cr2(%rax), %rbx
|
|
movq %rbx, %cr2
|
|
movq saved_context_cr0(%rax), %rbx
|
|
movq %rbx, %cr0
|
|
pushq pt_regs_flags(%rax)
|
|
popfq
|
|
movq pt_regs_sp(%rax), %rsp
|
|
movq pt_regs_bp(%rax), %rbp
|
|
movq pt_regs_si(%rax), %rsi
|
|
movq pt_regs_di(%rax), %rdi
|
|
movq pt_regs_bx(%rax), %rbx
|
|
movq pt_regs_cx(%rax), %rcx
|
|
movq pt_regs_dx(%rax), %rdx
|
|
movq pt_regs_r8(%rax), %r8
|
|
movq pt_regs_r9(%rax), %r9
|
|
movq pt_regs_r10(%rax), %r10
|
|
movq pt_regs_r11(%rax), %r11
|
|
movq pt_regs_r12(%rax), %r12
|
|
movq pt_regs_r13(%rax), %r13
|
|
movq pt_regs_r14(%rax), %r14
|
|
movq pt_regs_r15(%rax), %r15
|
|
|
|
#ifdef CONFIG_KASAN
|
|
/*
|
|
* The suspend path may have poisoned some areas deeper in the stack,
|
|
* which we now need to unpoison.
|
|
*/
|
|
movq %rsp, %rdi
|
|
call kasan_unpoison_task_stack_below
|
|
#endif
|
|
|
|
xorl %eax, %eax
|
|
addq $8, %rsp
|
|
FRAME_END
|
|
jmp restore_processor_state
|
|
ENDPROC(do_suspend_lowlevel)
|
|
|
|
.data
|
|
ENTRY(saved_rbp) .quad 0
|
|
ENTRY(saved_rsi) .quad 0
|
|
ENTRY(saved_rdi) .quad 0
|
|
ENTRY(saved_rbx) .quad 0
|
|
|
|
ENTRY(saved_rip) .quad 0
|
|
ENTRY(saved_rsp) .quad 0
|
|
|
|
ENTRY(saved_magic) .quad 0
|