lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAG_fn=U3uSm3-dDoDJ6RG2-p4SmcG0sB0z3yjX4Xypf7U67qVg@mail.gmail.com>
Date:   Wed, 18 Nov 2020 16:36:10 +0100
From:   Alexander Potapenko <glider@...gle.com>
To:     Andrey Konovalov <andreyknvl@...gle.com>
Cc:     Andrew Morton <akpm@...ux-foundation.org>,
        Catalin Marinas <catalin.marinas@....com>,
        Will Deacon <will.deacon@....com>,
        Vincenzo Frascino <vincenzo.frascino@....com>,
        Dmitry Vyukov <dvyukov@...gle.com>,
        Andrey Ryabinin <aryabinin@...tuozzo.com>,
        Marco Elver <elver@...gle.com>,
        Evgenii Stepanov <eugenis@...gle.com>,
        Branislav Rankov <Branislav.Rankov@....com>,
        Kevin Brodsky <kevin.brodsky@....com>,
        kasan-dev <kasan-dev@...glegroups.com>,
        Linux ARM <linux-arm-kernel@...ts.infradead.org>,
        Linux Memory Management List <linux-mm@...ck.org>,
        LKML <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH mm v10 09/42] kasan: define KASAN_MEMORY_PER_SHADOW_PAGE

On Fri, Nov 13, 2020 at 11:16 PM Andrey Konovalov <andreyknvl@...gle.com> wrote:
>
> Define KASAN_MEMORY_PER_SHADOW_PAGE as (KASAN_GRANULE_SIZE << PAGE_SHIFT),
> which is the same as (KASAN_GRANULE_SIZE * PAGE_SIZE) for software modes
> that use shadow memory, and use it across KASAN code to simplify it.
>
> Signed-off-by: Andrey Konovalov <andreyknvl@...gle.com>
> Signed-off-by: Vincenzo Frascino <vincenzo.frascino@....com>
> Reviewed-by: Marco Elver <elver@...gle.com>
Reviewed-by: Alexander Potapenko <glider@...gle.com>

> ---
> Change-Id: I0b627b24187d06c8b9bb2f1d04d94b3d06945e73
> ---
>  mm/kasan/init.c   | 10 ++++------
>  mm/kasan/kasan.h  |  2 ++
>  mm/kasan/shadow.c | 16 +++++++---------
>  3 files changed, 13 insertions(+), 15 deletions(-)
>
> diff --git a/mm/kasan/init.c b/mm/kasan/init.c
> index 1a71eaa8c5f9..bc0ad208b3a7 100644
> --- a/mm/kasan/init.c
> +++ b/mm/kasan/init.c
> @@ -441,9 +441,8 @@ void kasan_remove_zero_shadow(void *start, unsigned long size)
>         addr = (unsigned long)kasan_mem_to_shadow(start);
>         end = addr + (size >> KASAN_SHADOW_SCALE_SHIFT);
>
> -       if (WARN_ON((unsigned long)start %
> -                       (KASAN_GRANULE_SIZE * PAGE_SIZE)) ||
> -           WARN_ON(size % (KASAN_GRANULE_SIZE * PAGE_SIZE)))
> +       if (WARN_ON((unsigned long)start % KASAN_MEMORY_PER_SHADOW_PAGE) ||
> +           WARN_ON(size % KASAN_MEMORY_PER_SHADOW_PAGE))
>                 return;
>
>         for (; addr < end; addr = next) {
> @@ -476,9 +475,8 @@ int kasan_add_zero_shadow(void *start, unsigned long size)
>         shadow_start = kasan_mem_to_shadow(start);
>         shadow_end = shadow_start + (size >> KASAN_SHADOW_SCALE_SHIFT);
>
> -       if (WARN_ON((unsigned long)start %
> -                       (KASAN_GRANULE_SIZE * PAGE_SIZE)) ||
> -           WARN_ON(size % (KASAN_GRANULE_SIZE * PAGE_SIZE)))
> +       if (WARN_ON((unsigned long)start % KASAN_MEMORY_PER_SHADOW_PAGE) ||
> +           WARN_ON(size % KASAN_MEMORY_PER_SHADOW_PAGE))
>                 return -EINVAL;
>
>         ret = kasan_populate_early_shadow(shadow_start, shadow_end);
> diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h
> index 53b095f56f28..eec88bf28c64 100644
> --- a/mm/kasan/kasan.h
> +++ b/mm/kasan/kasan.h
> @@ -8,6 +8,8 @@
>  #define KASAN_GRANULE_SIZE     (1UL << KASAN_SHADOW_SCALE_SHIFT)
>  #define KASAN_GRANULE_MASK     (KASAN_GRANULE_SIZE - 1)
>
> +#define KASAN_MEMORY_PER_SHADOW_PAGE   (KASAN_GRANULE_SIZE << PAGE_SHIFT)
> +
>  #define KASAN_TAG_KERNEL       0xFF /* native kernel pointers tag */
>  #define KASAN_TAG_INVALID      0xFE /* inaccessible memory tag */
>  #define KASAN_TAG_MAX          0xFD /* maximum value for random tags */
> diff --git a/mm/kasan/shadow.c b/mm/kasan/shadow.c
> index 4264bfbdca1a..80522d2c447b 100644
> --- a/mm/kasan/shadow.c
> +++ b/mm/kasan/shadow.c
> @@ -174,7 +174,7 @@ static int __meminit kasan_mem_notifier(struct notifier_block *nb,
>         shadow_end = shadow_start + shadow_size;
>
>         if (WARN_ON(mem_data->nr_pages % KASAN_GRANULE_SIZE) ||
> -               WARN_ON(start_kaddr % (KASAN_GRANULE_SIZE << PAGE_SHIFT)))
> +               WARN_ON(start_kaddr % KASAN_MEMORY_PER_SHADOW_PAGE))
>                 return NOTIFY_BAD;
>
>         switch (action) {
> @@ -445,22 +445,20 @@ void kasan_release_vmalloc(unsigned long start, unsigned long end,
>         unsigned long region_start, region_end;
>         unsigned long size;
>
> -       region_start = ALIGN(start, PAGE_SIZE * KASAN_GRANULE_SIZE);
> -       region_end = ALIGN_DOWN(end, PAGE_SIZE * KASAN_GRANULE_SIZE);
> +       region_start = ALIGN(start, KASAN_MEMORY_PER_SHADOW_PAGE);
> +       region_end = ALIGN_DOWN(end, KASAN_MEMORY_PER_SHADOW_PAGE);
>
> -       free_region_start = ALIGN(free_region_start,
> -                                 PAGE_SIZE * KASAN_GRANULE_SIZE);
> +       free_region_start = ALIGN(free_region_start, KASAN_MEMORY_PER_SHADOW_PAGE);
>
>         if (start != region_start &&
>             free_region_start < region_start)
> -               region_start -= PAGE_SIZE * KASAN_GRANULE_SIZE;
> +               region_start -= KASAN_MEMORY_PER_SHADOW_PAGE;
>
> -       free_region_end = ALIGN_DOWN(free_region_end,
> -                                    PAGE_SIZE * KASAN_GRANULE_SIZE);
> +       free_region_end = ALIGN_DOWN(free_region_end, KASAN_MEMORY_PER_SHADOW_PAGE);
>
>         if (end != region_end &&
>             free_region_end > region_end)
> -               region_end += PAGE_SIZE * KASAN_GRANULE_SIZE;
> +               region_end += KASAN_MEMORY_PER_SHADOW_PAGE;
>
>         shadow_start = kasan_mem_to_shadow((void *)region_start);
>         shadow_end = kasan_mem_to_shadow((void *)region_end);
> --
> 2.29.2.299.gdc1121823c-goog
>


-- 
Alexander Potapenko
Software Engineer

Google Germany GmbH
Erika-Mann-Straße, 33
80636 München

Geschäftsführer: Paul Manicle, Halimah DeLaine Prado
Registergericht und -nummer: Hamburg, HRB 86891
Sitz der Gesellschaft: Hamburg

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ