Re: [PATCH v3] kprobes: unpoison stack in jprobe_return() for KASAN

From: Dmitry Vyukov
Date: Fri Oct 14 2016 - 07:56:00 EST


On Fri, Oct 14, 2016 at 1:25 PM, Will Deacon <will.deacon@xxxxxxx> wrote:
> On Fri, Oct 14, 2016 at 12:53:56PM +0200, Dmitry Vyukov wrote:
>> KASAN stack instrumentation poisons stack redzones on function entry
>> and unpoisons them on function exit. If a function exits abnormally
>> (e.g. with a longjmp like jprobe_return()), stack redzones are left
>> poisoned. Later this leads to random KASAN false reports.
>>
>> Unpoison stack redzones in the frames we are going to jump over
>> before doing actual longjmp in jprobe_return().
>>
>> Signed-off-by: Dmitry Vyukov <dvyukov@xxxxxxxxxx>
>> Cc: Mark Rutland <mark.rutland@xxxxxxx>
>> Cc: Catalin Marinas <catalin.marinas@xxxxxxx>
>> Cc: Andrey Ryabinin <ryabinin.a.a@xxxxxxxxx>
>> Cc: Lorenzo Pieralisi <lorenzo.pieralisi@xxxxxxx>
>> Cc: Alexander Potapenko <glider@xxxxxxxxxx>
>> Cc: Will Deacon <will.deacon@xxxxxxx>
>> Cc: Ingo Molnar <mingo@xxxxxxxxxx>
>> Cc: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
>> Cc: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
>> Cc: "H. Peter Anvin" <hpa@xxxxxxxxx>
>> Cc: Ananth N Mavinakayanahalli <ananth@xxxxxxxxxxxxxxxxxx>
>> Cc: Anil S Keshavamurthy <anil.s.keshavamurthy@xxxxxxxxx>
>> Cc: "David S. Miller" <davem@xxxxxxxxxxxxx>
>> Cc: Masami Hiramatsu <mhiramat@xxxxxxxxxx>
>> Cc: x86@xxxxxxxxxx
>> Cc: kasan-dev@xxxxxxxxxxxxxxxx
>>
>> --
>>
>> Changes since v1:
>> - leave kasan_unpoison_remaining_stack() intact
>> - instead add kasan_unpoison_stack_above_sp_to()
>> - rename kasan_unpoison_remaining_stack() to kasan_unpoison_task_stack_below()
>>
>> Changes since v2:
>> - fix build by adding return type to kasan_unpoison_stack_above_sp_to
>> (tested v2 with it, but forgot to git add)
>
> I get build warnings with this patch applied and KASAN enabled:
>
> mm/kasan/kasan.c: In function âkasan_unpoison_task_stack_belowâ:
> mm/kasan/kasan.c:82:34: warning: passing argument 2 of â__kasan_unpoison_stackâ discards âconstâ qualifier from pointer target type [-Wdiscarded-qualifiers]
> __kasan_unpoison_stack(current, watermark);
> ^~~~~~~~~
> mm/kasan/kasan.c:65:13: note: expected âvoid *â but argument is of type âconst void *â
> static void __kasan_unpoison_stack(struct task_struct *task, void *sp)
> ^~~~~~~~~~~~~~~~~~~~~~
> mm/kasan/kasan.c: In function âkasan_unpoison_stack_above_sp_toâ:
> mm/kasan/kasan.c:92:27: error: called object âcurrent_stack_pointerâ is not a function or function pointer
> const void *sp = (void *)current_stack_pointer();
> ^~~~~~~~~~~~~~~~~~~~~


Mailed v4.

Thanks