Re: [PATCH v2] x86/suspend: fix false positive KASAN warning on suspend/resume

Pavel Machek
2016-12-02T12:54:36Z

[-- Attachment #1: Type: text/plain, Size: 1963 bytes --]

Hi!

> Resuming from a suspend operation is showing a KASAN false positive
> warning:

> 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>
> Suggested-by: Dmitry Vyukov <dvyukov@google.com>
> Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>

Acked-by: Pavel Machek <pavel@ucw.cz>

> ---
> arch/x86/kernel/acpi/wakeup_64.S | 16 ++++++++++++++++
> 1 file changed, 16 insertions(+)
>
> diff --git a/arch/x86/kernel/acpi/wakeup_64.S b/arch/x86/kernel/acpi/wakeup_64.S
> index 169963f..1df9b75 100644
> --- a/arch/x86/kernel/acpi/wakeup_64.S
> +++ b/arch/x86/kernel/acpi/wakeup_64.S
> @@ -109,6 +109,22 @@ ENTRY(do_suspend_lowlevel)
> 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.
> + *
> + * We can't call kasan_unpoison_task_stack_below() because it uses %gs
> + * for 'current', which hasn't been set up yet. Instead, calculate the
> + * stack range manually and call kasan_unpoison_shadow().
> + */
> + movq %rsp, %rdi
> + andq $CURRENT_MASK, %rdi
> + movq %rsp, %rsi
> + xorq %rdi, %rsi
> + call kasan_unpoison_shadow
> +#endif

Well... you may want to add note to kasan_unpoison_shadow()

/*
* This is called by early resume code, with cpu not yer properly
* resumed. In particular, %gs may not be set up, and thus current
* is not available.
*/

Thanks,
Pavel
--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]