Re: [PATCH v2 1/1] x86_64: fix KASan shadow region page tables

From: Andrey Ryabinin
Date: Fri May 29 2015 - 10:51:26 EST


On 05/29/2015 04:46 PM, Alexander Popov wrote:
> KASan shadow region page tables can't be filled statically because
> physical addresses in these page tables depend on phys_base.
> Initialize KASan shadow region page tables in kasan_early_init().
>
> Signed-off-by: Alexander Popov <alpopov@xxxxxxxxxxxxxx>
> ---

Thanks. Couple comments bellow, otherwise looks good.

>
> -extern unsigned char kasan_zero_page[PAGE_SIZE];
> +static pud_t kasan_zero_pud[PTRS_PER_PUD] __page_aligned_data;
> +static pmd_t kasan_zero_pmd[PTRS_PER_PMD] __page_aligned_data;
> +static pte_t kasan_zero_pte[PTRS_PER_PTE] __page_aligned_data;

It's better to keep these in bss.


> +/*
> + * This page used as early shadow. We don't use empty_zero_page
> + * at early stages, stack instrumentation could write some garbage
> + * to this page.
> + * Latter we reuse it as zero shadow for large ranges of memory
> + * that allowed to access, but not instrumented by kasan
> + * (vmalloc/vmemmap ...).
> + */
> +static unsigned char kasan_zero_page[PAGE_SIZE] __page_aligned_bss;
>
> static int __init map_range(struct range *range)
> {
> @@ -166,6 +178,23 @@ static struct notifier_block kasan_die_notifier = {
> };
> #endif
>
> +void __init kasan_early_init(void)
> +{
> + int i;
> + pteval_t pte_val = __pa_nodebug(kasan_zero_page) | _KERNPG_TABLE;


Should be __PAGE_KERNEL.
Yes, currently kasan's ptes have _KERNPG_TABLE flags, but that is wrong.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/