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

From: Pavel Machek
Date: Fri Dec 02 2016 - 07:54:39 EST


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@xxxxxxxxx>
> Suggested-by: Dmitry Vyukov <dvyukov@xxxxxxxxxx>
> Signed-off-by: Josh Poimboeuf <jpoimboe@xxxxxxxxxx>

Acked-by: Pavel Machek <pavel@xxxxxx>

> ---
> 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: signature.asc
Description: Digital signature