Skip to content

Commit

Permalink
kasan, vmalloc, arm64: mark vmalloc mappings as pgprot_tagged
Browse files Browse the repository at this point in the history
HW_TAGS KASAN relies on ARM Memory Tagging Extension (MTE).  With MTE, a
memory region must be mapped as MT_NORMAL_TAGGED to allow setting memory
tags via MTE-specific instructions.

Add proper protection bits to vmalloc() allocations.  These allocations
are always backed by page_alloc pages, so the tags will actually be
getting set on the corresponding physical memory.

Link: https://lkml.kernel.org/r/983fc33542db2f6b1e77b34ca23448d4640bbb9e.1643047180.git.andreyknvl@google.com
Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
Co-developed-by: Vincenzo Frascino <vincenzo.frascino@arm.com>
Signed-off-by: Vincenzo Frascino <vincenzo.frascino@arm.com>
Acked-by: Marco Elver <elver@google.com>
Cc: Alexander Potapenko <glider@google.com>
Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Evgenii Stepanov <eugenis@google.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Peter Collingbourne <pcc@google.com>
Cc: Will Deacon <will@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au>
  • Loading branch information
Andrey Konovalov authored and Stephen Rothwell committed Jan 30, 2022
1 parent 6c6db55 commit 5ae3b91
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
6 changes: 6 additions & 0 deletions arch/arm64/include/asm/vmalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,10 @@ static inline bool arch_vmap_pmd_supported(pgprot_t prot)

#endif

#define arch_vmap_pgprot_tagged arch_vmap_pgprot_tagged
static inline pgprot_t arch_vmap_pgprot_tagged(pgprot_t prot)
{
return pgprot_tagged(prot);
}

#endif /* _ASM_ARM64_VMALLOC_H */
7 changes: 7 additions & 0 deletions include/linux/vmalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,13 @@ static inline int arch_vmap_pte_supported_shift(unsigned long size)
}
#endif

#ifndef arch_vmap_pgprot_tagged
static inline pgprot_t arch_vmap_pgprot_tagged(pgprot_t prot)
{
return prot;
}
#endif

/*
* Highlevel APIs for driver use
*/
Expand Down
9 changes: 9 additions & 0 deletions mm/vmalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -3108,6 +3108,15 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
goto fail;
}

/*
* Modify protection bits to allow tagging.
* This must be done before mapping by __vmalloc_area_node().
*/
if (kasan_hw_tags_enabled() &&
pgprot_val(prot) == pgprot_val(PAGE_KERNEL))
prot = arch_vmap_pgprot_tagged(prot);

/* Allocate physical pages and map them into vmalloc space. */
addr = __vmalloc_area_node(area, gfp_mask, prot, shift, node);
if (!addr)
goto fail;
Expand Down

0 comments on commit 5ae3b91

Please sign in to comment.