Re: [PATCH 3/3] x86/kasan: Populate shadow for shared chunk of the CPU entry area

From: Andrey Ryabinin
Date: Tue Nov 08 2022 - 15:32:24 EST




On 11/8/22 23:03, Sean Christopherson wrote:
> On Tue, Nov 08, 2022, Andrey Ryabinin wrote:
>>
>> On 11/4/22 21:32, Sean Christopherson wrote:
>>> @@ -409,6 +410,15 @@ void __init kasan_init(void)
>>> kasan_mem_to_shadow((void *)VMALLOC_END + 1),
>>> (void *)shadow_cea_begin);
>>>
>>> + /*
>>> + * Populate the shadow for the shared portion of the CPU entry area.
>>> + * Shadows for the per-CPU areas are mapped on-demand, as each CPU's
>>> + * area is randomly placed somewhere in the 512GiB range and mapping
>>> + * the entire 512GiB range is prohibitively expensive.
>>> + */
>>> + kasan_populate_shadow(shadow_cea_begin,
>>> + shadow_cea_per_cpu_begin, 0);
>>> +
>>
>> I think we can extend the kasan_populate_early_shadow() call above up to
>> shadow_cea_per_cpu_begin point, instead of this.
>> populate_early_shadow() maps single RO zeroed page. No one should write to the shadow for IDT.
>> KASAN only needs writable shadow for linear mapping/stacks/vmalloc/global variables.
>
> Is that the only difference between the "early" and "normal" variants?

It is. kasan_populate_shadow() allocates new memory and maps it, while the "early" one maps
'kasan_early_shadow_page'

> If so, renaming them to kasan_populate_ro_shadow() vs. kasan_populate_rw_shadow() would
> make this code much more intuitive for non-KASAN folks.
>

Agreed.