[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CALCETrW7=WDxt_ZiXKBez9mTGz92qeVxWJp3BJauEtAs3r4cTg@mail.gmail.com>
Date: Fri, 24 Nov 2017 08:27:09 -0800
From: Andy Lutomirski <luto@...nel.org>
To: Andrey Ryabinin <aryabinin@...tuozzo.com>
Cc: Andy Lutomirski <luto@...nel.org>, X86 ML <x86@...nel.org>,
Borislav Petkov <bpetkov@...e.de>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
Brian Gerst <brgerst@...il.com>,
Dave Hansen <dave.hansen@...el.com>,
Linus Torvalds <torvalds@...ux-foundation.org>,
Josh Poimboeuf <jpoimboe@...hat.com>,
Alexander Potapenko <glider@...gle.com>,
Dmitry Vyukov <dvyukov@...gle.com>,
kasan-dev <kasan-dev@...glegroups.com>
Subject: Re: [PATCH v3 05/19] x86/kasan/64: Teach KASAN about the cpu_entry_area
On Fri, Nov 24, 2017 at 5:16 AM, Andrey Ryabinin
<aryabinin@...tuozzo.com> wrote:
>
>
> On 11/24/2017 07:32 AM, Andy Lutomirski wrote:
>> The cpu_entry_area will contain stacks. Make sure that KASAN has
>> appropriate shadow mappings for them.
>>
>> Cc: Andrey Ryabinin <aryabinin@...tuozzo.com>
>> Cc: Alexander Potapenko <glider@...gle.com>
>> Cc: Dmitry Vyukov <dvyukov@...gle.com>
>> Cc: kasan-dev@...glegroups.com
>> Signed-off-by: Andy Lutomirski <luto@...nel.org>
>> ---
>> arch/x86/mm/kasan_init_64.c | 13 ++++++++++++-
>> 1 file changed, 12 insertions(+), 1 deletion(-)
>>
>> diff --git a/arch/x86/mm/kasan_init_64.c b/arch/x86/mm/kasan_init_64.c
>> index 99dfed6dfef8..54561dce742e 100644
>> --- a/arch/x86/mm/kasan_init_64.c
>> +++ b/arch/x86/mm/kasan_init_64.c
>> @@ -277,6 +277,7 @@ void __init kasan_early_init(void)
>> void __init kasan_init(void)
>> {
>> int i;
>> + void *cpu_entry_area_begin, *cpu_entry_area_end;
>>
>> #ifdef CONFIG_KASAN_INLINE
>> register_die_notifier(&kasan_die_notifier);
>> @@ -329,8 +330,18 @@ void __init kasan_init(void)
>> (unsigned long)kasan_mem_to_shadow(_end),
>> early_pfn_to_nid(__pa(_stext)));
>>
>> + cpu_entry_area_begin = (void *)(__fix_to_virt(FIX_CPU_ENTRY_AREA_BOTTOM));
>> + cpu_entry_area_end = (void *)(__fix_to_virt(FIX_CPU_ENTRY_AREA_TOP) + PAGE_SIZE);
>> +
>> kasan_populate_zero_shadow(kasan_mem_to_shadow((void *)MODULES_END),
>> - (void *)KASAN_SHADOW_END);
>> + kasan_mem_to_shadow(cpu_entry_area_begin));
>> +
>> + kasan_populate_shadow((unsigned long)kasan_mem_to_shadow(cpu_entry_area_begin),
>> + (unsigned long)kasan_mem_to_shadow(cpu_entry_area_end),
>> + 0);
>> +
>> + kasan_populate_zero_shadow(kasan_mem_to_shadow(cpu_entry_area_end),
>
> Seems we need to round_up kasan_mem_to_shadow(cpu_entry_area_end) to the next page
> (or alternatively - round_up(cpu_entry_area_end, KASAN_SHADOW_SCALE_SIZE*PAGE_SIZE)).
> Otherwise, kasan_populate_zero_shadow() will overpopulate the last shadow page of cpu_entry area with kasan_zero_page.
>
> We don't necessarily need to round_down(kasan_mem_to_shadow(cpu_entry_area_begin), PAGE_SIZE) because
> kasan_populate_zero_shadow() will not populate the last 'incomplete' page and kasan_populate_shadow()
> does round_down() internally, which is exactly what we want here. But it might be better to round_down()
> explicitly anyway, to avoid relying on such subtle implementation details.
Any chance you could send a fixup patch or a replacement patch? You
obviously understand this code *way* better than I do.
Or you could do my table-based approach and fix it permanently... :)
>
>> + (void *)KASAN_SHADOW_END);
>>
>> load_cr3(init_top_pgt);
>> __flush_tlb_all();
>>
Powered by blists - more mailing lists