linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Paul Gortmaker <paul.gortmaker@windriver.com>
To: andreyknvl@google.com
Cc: aryabinin@virtuozzo.com, glider@google.com, dvyukov@google.com,
	catalin.marinas@arm.com, will.deacon@arm.com, cl@linux.com,
	Andrew Morton <akpm@linux-foundation.org>,
	mark.rutland@arm.com, ndesaulniers@google.com,
	marc.zyngier@arm.com, dave.martin@arm.com,
	ard.biesheuvel@linaro.org, ebiederm@xmission.com,
	mingo@kernel.org, paullawrence@google.com,
	Geert Uytterhoeven <geert@linux-m68k.org>,
	Arnd Bergmann <arnd@arndb.de>,
	kirill.shutemov@linux.intel.com, gregkh@linuxfoundation.org,
	kstewart@linuxfoundation.org, rppt@linux.vnet.ibm.com,
	kasan-dev@googlegroups.com, LKML doc <linux-doc@vger.kernel.org>,
	LKML <linux-kernel@vger.kernel.org>,
	linux-arm-kernel@lists.infradead.org,
	linux-sparse@vger.kernel.org, linux-mm@kvack.org,
	linux-kbuild <linux-kbuild@vger.kernel.org>,
	kcc@google.com, eugenis@google.com, Lee.Smith@arm.com,
	Ramana.Radhakrishnan@arm.com, Jacob.Bramley@arm.com,
	Ruben.Ayrapetyan@arm.com, jannh@google.com, markbrand@google.com,
	cpandya@codeaurora.org, vishwath@google.com,
	linux-next@vger.kernel.org
Subject: Re: [PATCH v13 08/25] kasan: initialize shadow to 0xff for tag-based mode
Date: Sun, 9 Dec 2018 20:35:13 -0500	[thread overview]
Message-ID: <CAP=VYLo-o8vpGrpM_+0jdvxLC9uxw+F7_OtsSfRyq24HR1dDwA@mail.gmail.com> (raw)
In-Reply-To: <5cc1b789aad7c99cf4f3ec5b328b147ad53edb40.1544099024.git.andreyknvl@google.com>

[-- Attachment #1: Type: text/plain, Size: 5497 bytes --]

On Thu, Dec 6, 2018 at 7:25 AM Andrey Konovalov <andreyknvl@google.com>
wrote:

> A tag-based KASAN shadow memory cell contains a memory tag, that
> corresponds to the tag in the top byte of the pointer, that points to that
> memory. The native top byte value of kernel pointers is 0xff, so with
> tag-based KASAN we need to initialize shadow memory to 0xff.
>
> Reviewed-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
> Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
> Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
> ---
>  arch/arm64/mm/kasan_init.c | 15 +++++++++++++--
>  include/linux/kasan.h      |  8 ++++++++
>

The version of this in  linux-next breaks arm64 allmodconfig for me:

mm/kasan/common.c: In function ‘kasan_module_alloc’:
mm/kasan/common.c:481:17: error: ‘KASAN_SHADOW_INIT’ undeclared (first use
in this function)
   __memset(ret, KASAN_SHADOW_INIT, shadow_size);
                 ^
mm/kasan/common.c:481:17: note: each undeclared identifier is reported only
once for each function it appears in
make[3]: *** [mm/kasan/common.o] Error 1
make[3]: *** Waiting for unfinished jobs....
make[2]: *** [mm/kasan] Error 2
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [mm/] Error 2
make: *** [sub-make] Error 2

An automated git bisect-run points at this:

5c36287813721999e79ac76f637f1ba7e5054402 is the first bad commit
commit 5c36287813721999e79ac76f637f1ba7e5054402
Author: Andrey Konovalov <andreyknvl@google.com>
Date:   Wed Dec 5 11:13:21 2018 +1100

    kasan: initialize shadow to 0xff for tag-based mode

A quick look at the commit makes me think that the case where the
"# CONFIG_KASAN_GENERIC is not set" has not been handled.

I'm using an older gcc 4.8.3 - only used for build testing.

Paul.
--

 mm/kasan/common.c          |  3 ++-
>  3 files changed, 23 insertions(+), 3 deletions(-)
>
> diff --git a/arch/arm64/mm/kasan_init.c b/arch/arm64/mm/kasan_init.c
> index 4ebc19422931..7a4a0904cac8 100644
> --- a/arch/arm64/mm/kasan_init.c
> +++ b/arch/arm64/mm/kasan_init.c
> @@ -43,6 +43,15 @@ static phys_addr_t __init kasan_alloc_zeroed_page(int
> node)
>         return __pa(p);
>  }
>
> +static phys_addr_t __init kasan_alloc_raw_page(int node)
> +{
> +       void *p = memblock_alloc_try_nid_raw(PAGE_SIZE, PAGE_SIZE,
> +                                               __pa(MAX_DMA_ADDRESS),
> +                                               MEMBLOCK_ALLOC_ACCESSIBLE,
> +                                               node);
> +       return __pa(p);
> +}
> +
>  static pte_t *__init kasan_pte_offset(pmd_t *pmdp, unsigned long addr,
> int node,
>                                       bool early)
>  {
> @@ -92,7 +101,9 @@ static void __init kasan_pte_populate(pmd_t *pmdp,
> unsigned long addr,
>         do {
>                 phys_addr_t page_phys = early ?
>                                 __pa_symbol(kasan_early_shadow_page)
> -                                       : kasan_alloc_zeroed_page(node);
> +                                       : kasan_alloc_raw_page(node);
> +               if (!early)
> +                       memset(__va(page_phys), KASAN_SHADOW_INIT,
> PAGE_SIZE);
>                 next = addr + PAGE_SIZE;
>                 set_pte(ptep, pfn_pte(__phys_to_pfn(page_phys),
> PAGE_KERNEL));
>         } while (ptep++, addr = next, addr != end &&
> pte_none(READ_ONCE(*ptep)));
> @@ -239,7 +250,7 @@ void __init kasan_init(void)
>                         pfn_pte(sym_to_pfn(kasan_early_shadow_page),
>                                 PAGE_KERNEL_RO));
>
> -       memset(kasan_early_shadow_page, 0, PAGE_SIZE);
> +       memset(kasan_early_shadow_page, KASAN_SHADOW_INIT, PAGE_SIZE);
>         cpu_replace_ttbr1(lm_alias(swapper_pg_dir));
>
>         /* At this point kasan is fully initialized. Enable error messages
> */
> diff --git a/include/linux/kasan.h b/include/linux/kasan.h
> index ec22d548d0d7..c56af24bd3e7 100644
> --- a/include/linux/kasan.h
> +++ b/include/linux/kasan.h
> @@ -153,6 +153,8 @@ static inline size_t kasan_metadata_size(struct
> kmem_cache *cache) { return 0; }
>
>  #ifdef CONFIG_KASAN_GENERIC
>
> +#define KASAN_SHADOW_INIT 0
> +
>  void kasan_cache_shrink(struct kmem_cache *cache);
>  void kasan_cache_shutdown(struct kmem_cache *cache);
>
> @@ -163,4 +165,10 @@ static inline void kasan_cache_shutdown(struct
> kmem_cache *cache) {}
>
>  #endif /* CONFIG_KASAN_GENERIC */
>
> +#ifdef CONFIG_KASAN_SW_TAGS
> +
> +#define KASAN_SHADOW_INIT 0xFF
> +
> +#endif /* CONFIG_KASAN_SW_TAGS */
> +
>  #endif /* LINUX_KASAN_H */
> diff --git a/mm/kasan/common.c b/mm/kasan/common.c
> index 5f68c93734ba..7134e75447ff 100644
> --- a/mm/kasan/common.c
> +++ b/mm/kasan/common.c
> @@ -473,11 +473,12 @@ int kasan_module_alloc(void *addr, size_t size)
>
>         ret = __vmalloc_node_range(shadow_size, 1, shadow_start,
>                         shadow_start + shadow_size,
> -                       GFP_KERNEL | __GFP_ZERO,
> +                       GFP_KERNEL,
>                         PAGE_KERNEL, VM_NO_GUARD, NUMA_NO_NODE,
>                         __builtin_return_address(0));
>
>         if (ret) {
> +               __memset(ret, KASAN_SHADOW_INIT, shadow_size);
>                 find_vm_area(addr)->flags |= VM_KASAN;
>                 kmemleak_ignore(ret);
>                 return 0;
> --
> 2.20.0.rc1.387.gf8505762e3-goog
>
>

[-- Attachment #2: Type: text/html, Size: 7016 bytes --]

  reply	other threads:[~2018-12-10  1:35 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-06 12:24 [PATCH v13 00/25] kasan: add software tag-based mode for arm64 Andrey Konovalov
2018-12-06 12:24 ` [PATCH v13 01/25] kasan, mm: change hooks signatures Andrey Konovalov
2018-12-06 12:24 ` [PATCH v13 02/25] kasan, slub: handle pointer tags in early_kmem_cache_node_alloc Andrey Konovalov
2018-12-06 12:24 ` [PATCH v13 03/25] kasan: move common generic and tag-based code to common.c Andrey Konovalov
2018-12-06 12:24 ` [PATCH v13 04/25] kasan: rename source files to reflect the new naming scheme Andrey Konovalov
2018-12-06 12:24 ` [PATCH v13 05/25] kasan: add CONFIG_KASAN_GENERIC and CONFIG_KASAN_SW_TAGS Andrey Konovalov
2018-12-11 15:28   ` Luc Van Oostenryck
2018-12-11 16:02     ` Andrey Konovalov
2018-12-06 12:24 ` [PATCH v13 06/25] kasan, arm64: adjust shadow size for tag-based mode Andrey Konovalov
2018-12-06 12:24 ` [PATCH v13 07/25] kasan: rename kasan_zero_page to kasan_early_shadow_page Andrey Konovalov
2018-12-06 12:24 ` [PATCH v13 08/25] kasan: initialize shadow to 0xff for tag-based mode Andrey Konovalov
2018-12-10  1:35   ` Paul Gortmaker [this message]
2018-12-10 12:12     ` Andrey Konovalov
2018-12-06 12:24 ` [PATCH v13 09/25] arm64: move untagged_addr macro from uaccess.h to memory.h Andrey Konovalov
2018-12-06 12:24 ` [PATCH v13 10/25] kasan: add tag related helper functions Andrey Konovalov
2018-12-06 12:24 ` [PATCH v13 11/25] kasan, arm64: untag address in _virt_addr_is_linear Andrey Konovalov
2018-12-06 12:24 ` [PATCH v13 12/25] kasan: preassign tags to objects with ctors or SLAB_TYPESAFE_BY_RCU Andrey Konovalov
2018-12-06 12:24 ` [PATCH v13 13/25] kasan, arm64: fix up fault handling logic Andrey Konovalov
2018-12-06 12:24 ` [PATCH v13 14/25] kasan, arm64: enable top byte ignore for the kernel Andrey Konovalov
2018-12-06 12:24 ` [PATCH v13 15/25] kasan, mm: perform untagged pointers comparison in krealloc Andrey Konovalov
2018-12-06 12:24 ` [PATCH v13 16/25] kasan: split out generic_report.c from report.c Andrey Konovalov
2018-12-06 12:24 ` [PATCH v13 17/25] kasan: add bug reporting routines for tag-based mode Andrey Konovalov
2018-12-06 12:24 ` [PATCH v13 18/25] mm: move obj_to_index to include/linux/slab_def.h Andrey Konovalov
2018-12-06 12:24 ` [PATCH v13 19/25] kasan: add hooks implementation for tag-based mode Andrey Konovalov
2018-12-11 16:22   ` Vincenzo Frascino
2018-12-12 15:04     ` Andrey Konovalov
2018-12-14 12:35       ` Vincenzo Frascino
2018-12-17 19:33         ` Andrey Konovalov
2018-12-17 20:38           ` Andrew Morton
2018-12-18 13:31             ` Andrey Konovalov
2018-12-06 12:24 ` [PATCH v13 20/25] kasan, arm64: add brk handler for inline instrumentation Andrey Konovalov
2018-12-06 12:24 ` [PATCH v13 21/25] kasan, mm, arm64: tag non slab memory allocated via pagealloc Andrey Konovalov
2018-12-06 12:24 ` [PATCH v13 22/25] kasan: add __must_check annotations to kasan hooks Andrey Konovalov
2018-12-06 12:24 ` [PATCH v13 23/25] kasan, arm64: select HAVE_ARCH_KASAN_SW_TAGS Andrey Konovalov
2018-12-06 12:24 ` [PATCH v13 24/25] kasan: update documentation Andrey Konovalov
2018-12-06 12:24 ` [PATCH v13 25/25] kasan: add SPDX-License-Identifier mark to source files Andrey Konovalov
2018-12-11 15:18 ` [PATCH v13 00/25] kasan: add software tag-based mode for arm64 Will Deacon
2018-12-11 15:57   ` Andrey Konovalov
2018-12-11 16:00     ` Will Deacon
2018-12-11 21:44       ` Andrew Morton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAP=VYLo-o8vpGrpM_+0jdvxLC9uxw+F7_OtsSfRyq24HR1dDwA@mail.gmail.com' \
    --to=paul.gortmaker@windriver.com \
    --cc=Jacob.Bramley@arm.com \
    --cc=Lee.Smith@arm.com \
    --cc=Ramana.Radhakrishnan@arm.com \
    --cc=Ruben.Ayrapetyan@arm.com \
    --cc=akpm@linux-foundation.org \
    --cc=andreyknvl@google.com \
    --cc=ard.biesheuvel@linaro.org \
    --cc=arnd@arndb.de \
    --cc=aryabinin@virtuozzo.com \
    --cc=catalin.marinas@arm.com \
    --cc=cl@linux.com \
    --cc=cpandya@codeaurora.org \
    --cc=dave.martin@arm.com \
    --cc=dvyukov@google.com \
    --cc=ebiederm@xmission.com \
    --cc=eugenis@google.com \
    --cc=geert@linux-m68k.org \
    --cc=glider@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jannh@google.com \
    --cc=kasan-dev@googlegroups.com \
    --cc=kcc@google.com \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=kstewart@linuxfoundation.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-next@vger.kernel.org \
    --cc=linux-sparse@vger.kernel.org \
    --cc=marc.zyngier@arm.com \
    --cc=mark.rutland@arm.com \
    --cc=markbrand@google.com \
    --cc=mingo@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=paullawrence@google.com \
    --cc=rppt@linux.vnet.ibm.com \
    --cc=vishwath@google.com \
    --cc=will.deacon@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox