Re: [PATCH v8 2/5] arm64: Tighten the PR_{SET,GET}_TAGGED_ADDR_CTRL prctl() unused arguments

2019-08-19 Thread Andrey Konovalov
On Thu, Aug 15, 2019 at 5:44 PM Catalin Marinas wrote: > > Require that arg{3,4,5} of the PR_{SET,GET}_TAGGED_ADDR_CTRL prctl and > arg2 of the PR_GET_TAGGED_ADDR_CTRL prctl() are zero rather than ignored > for future extensions. > > Signed-off-by: Catalin Marinas Acked-by

Re: [PATCH v8 1/5] mm: untag user pointers in mmap/munmap/mremap/brk

2019-08-19 Thread Andrey Konovalov
g the user addresses on entry to these functions. > > Signed-off-by: Catalin Marinas Acked-by: Andrey Konovalov > --- > mm/mmap.c | 5 + > mm/mremap.c | 6 +- > 2 files changed, 6 insertions(+), 5 deletions(-) > > diff --git a/mm/mmap.c b/mm/mmap.c > ind

Re: [PATCH v8 3/5] arm64: Change the tagged_addr sysctl control semantics to only prevent the opt-in

2019-08-19 Thread Andrey Konovalov
GED_ADDR_ENABLE). > Getting the status of the ABI or disabling it is still allowed. > > Signed-off-by: Catalin Marinas Acked-by: Andrey Konovalov > --- > arch/arm64/kernel/process.c | 17 ++--- > 1 file changed, 10 insertions(+), 7 deletions(-) > > diff --git a/a

Re: [PATCH v8 5/5] arm64: Relax Documentation/arm64/tagged-pointers.rst

2019-08-19 Thread Andrey Konovalov
ged Address ABI. > > Cc: Will Deacon > Cc: Andrey Konovalov > Cc: Szabolcs Nagy > Cc: Kevin Brodsky > Signed-off-by: Vincenzo Frascino > Co-developed-by: Catalin Marinas > Signed-off-by: Catalin Marinas Acked-by: Andrey Konovalov > --- > Documentation/arm64/tagg

Re: [PATCH v8 4/5] arm64: Define Documentation/arm64/tagged-address-abi.rst

2019-08-19 Thread Andrey Konovalov
the relaxation of the > syscall ABI that allows userspace to pass certain tagged pointers to > kernel syscalls. > > Cc: Will Deacon > Cc: Andrey Konovalov > Cc: Szabolcs Nagy > Cc: Kevin Brodsky > Signed-off-by: Vincenzo Frascino > Co-developed-by: Catalin Marinas

Re: [PATCH v9 2/3] arm64: Define Documentation/arm64/tagged-address-abi.rst

2019-08-21 Thread Andrey Konovalov
the relaxation of the > syscall ABI that allows userspace to pass certain tagged pointers to > kernel syscalls. > > Cc: Will Deacon > Cc: Andrey Konovalov > Cc: Szabolcs Nagy > Cc: Kevin Brodsky > Signed-off-by: Vincenzo Frascino > Co-developed-by: Catalin Marinas

Re: [PATCH 1/8] kcsan: Add Kernel Concurrency Sanitizer infrastructure

2019-10-16 Thread Andrey Konovalov
On Wed, Oct 16, 2019 at 10:41 AM Marco Elver wrote: > > Kernel Concurrency Sanitizer (KCSAN) is a dynamic data-race detector for > kernel space. KCSAN is a sampling watchpoint-based data-race detector. > See the included Documentation/dev-tools/kcsan.rst for more details. > > This patch adds basic

Re: [PATCH v10 07/12] fs, arm64: untag user pointers in fs/userfaultfd.c

2019-03-05 Thread Andrey Konovalov
On Fri, Mar 1, 2019 at 7:37 PM Dave Hansen wrote: > > On 3/1/19 8:59 AM, Catalin Marinas wrote: > >>> So, we have to patch all these sites before the tagged values get to the > >>> point of hitting the vma lookup functions. Dumb question: Why don't we > >>> just patch the vma lookup functions the

[RFC PATCH v2 5/6] lib, arm64: untag addrs passed to strncpy_from_user and strnlen_user

2018-03-27 Thread Andrey Konovalov
strncpy_from_user and strnlen_user accept user addresses as arguments, and do not go through the same path as copy_from_user and others, so here we need to separately handle the case of tagged user addresses as well. Untag user pointers passed to these functions. Signed-off-by: Andrey Konovalov

[RFC PATCH v2 2/6] uaccess: add untagged_addr definition for other arches

2018-03-27 Thread Andrey Konovalov
architectures besides arm64. Signed-off-by: Andrey Konovalov --- include/linux/uaccess.h | 4 1 file changed, 4 insertions(+) diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h index efe79c1cdd47..c045b4eff95e 100644 --- a/include/linux/uaccess.h +++ b/include/linux/uaccess.h

[RFC PATCH v2 6/6] arm64: update Documentation/arm64/tagged-pointers.txt

2018-03-27 Thread Andrey Konovalov
Add a note that work on passing tagged user pointers to the kernel via syscalls has started, but might not be complete yet. Signed-off-by: Andrey Konovalov --- Documentation/arm64/tagged-pointers.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Documentation/arm64

[RFC PATCH v2 1/6] arm64: add type casts to untagged_addr macro

2018-03-27 Thread Andrey Konovalov
This patch makes the untagged_addr macro accept all kinds of address types (void *, unsigned long, etc.) and allows not to specify type casts in each place where it is used. This is done by using __typeof__. Signed-off-by: Andrey Konovalov --- arch/arm64/include/asm/uaccess.h | 3 ++- 1 file

[RFC PATCH v2 3/6] arm64: untag user addresses in copy_from_user and others

2018-03-27 Thread Andrey Konovalov
in access_ok and in __uaccess_mask_ptr. Signed-off-by: Andrey Konovalov --- arch/arm64/include/asm/uaccess.h | 6 +- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h index 2d6451cbaa86..24a221678fe3 100644 --- a

[RFC PATCH v2 4/6] mm, arm64: untag user addresses in mm/gup.c

2018-03-27 Thread Andrey Konovalov
mm/gup.c provides a kernel interface that accepts user addresses and manipulates user pages directly (for example get_user_pages, that is used by the futex syscall). Here we also need to handle the case of tagged user pointers. Untag addresses passed to this interface. Signed-off-by: Andrey

[RFC PATCH v2 0/6] arm64: untag user pointers passed to the kernel

2018-03-27 Thread Andrey Konovalov
on/arm64/tagged-pointers.txt. - Dropped “mm, arm64: untag user addresses in memory syscalls”. - Rebased onto 3eb2ce82 (4.16-rc7). Andrey Konovalov (6): arm64: add type casts to untagged_addr macro uaccess: add untagged_addr definition for other arches arm64: untag user addresses in copy_from_

Re: [PATCH v10 06/22] kasan, arm64: adjust shadow size for tag-based mode

2018-11-12 Thread Andrey Konovalov
On Wed, Nov 7, 2018 at 5:54 PM, Mark Rutland wrote: [...] >> --- a/arch/arm64/Makefile >> +++ b/arch/arm64/Makefile >> @@ -94,7 +94,7 @@ endif >> # KASAN_SHADOW_OFFSET = VA_START + (1 << (VA_BITS - >> KASAN_SHADOW_SCALE_SHIFT)) >> # - (1 << (64 - KASAN_SHADOW_SCALE

Re: [PATCH v10 05/22] kasan: add CONFIG_KASAN_GENERIC and CONFIG_KASAN_SW_TAGS

2018-11-12 Thread Andrey Konovalov
On Wed, Nov 7, 2018 at 6:04 PM, Mark Rutland wrote: > On Tue, Nov 06, 2018 at 06:30:20PM +0100, Andrey Konovalov wrote: >> This commit splits the current CONFIG_KASAN config option into two: >> 1. CONFIG_KASAN_GENERIC, that enables the generic KASAN mode (the one >>t

Re: [PATCH v10 07/22] kasan: initialize shadow to 0xff for tag-based mode

2018-11-13 Thread Andrey Konovalov
On Wed, Nov 7, 2018 at 6:08 PM, Mark Rutland wrote: > On Tue, Nov 06, 2018 at 06:30:22PM +0100, Andrey Konovalov 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

Re: [PATCH v10 12/22] kasan, arm64: fix up fault handling logic

2018-11-13 Thread Andrey Konovalov
On Thu, Nov 8, 2018 at 1:22 PM, Mark Rutland wrote: > On Tue, Nov 06, 2018 at 06:30:27PM +0100, Andrey Konovalov wrote: >> show_pte in arm64 fault handling relies on the fact that the top byte of >> a kernel pointer is 0xff, which isn't always the case with tag-based >>

Re: [PATCH v10 09/22] kasan: add tag related helper functions

2018-11-14 Thread Andrey Konovalov
On Wed, Nov 7, 2018 at 6:23 PM, Mark Rutland wrote: > On Tue, Nov 06, 2018 at 06:30:24PM +0100, Andrey Konovalov wrote: >> This commit adds a few helper functions, that are meant to be used to >> work with tags embedded in the top byte of kernel pointers: to set, to >> ge

Re: [PATCH v10 08/22] kasan, arm64: untag address in __kimg_to_phys and _virt_addr_is_linear

2018-11-14 Thread Andrey Konovalov
On Wed, Nov 7, 2018 at 5:52 PM, Mark Rutland wrote: > Hi Andrey, > > On Tue, Nov 06, 2018 at 06:30:23PM +0100, Andrey Konovalov wrote: >> __kimg_to_phys (which is used by virt_to_phys) and _virt_addr_is_linear >> (which is used by virt_addr_valid) assume that the top byte

Re: [PATCH v10 08/22] kasan, arm64: untag address in __kimg_to_phys and _virt_addr_is_linear

2018-11-14 Thread Andrey Konovalov
On Wed, Nov 7, 2018 at 7:10 PM, Catalin Marinas wrote: > On Tue, Nov 06, 2018 at 06:30:23PM +0100, Andrey Konovalov wrote: >> --- a/arch/arm64/include/asm/memory.h >> +++ b/arch/arm64/include/asm/memory.h >> @@ -92,6 +92,15 @@ >> #define KASAN_THREAD_SHIFT

Re: [PATCH v10 12/22] kasan, arm64: fix up fault handling logic

2018-11-14 Thread Andrey Konovalov
On Tue, Nov 13, 2018 at 11:07 PM, Mark Rutland wrote: > On Tue, Nov 13, 2018 at 04:01:27PM +0100, Andrey Konovalov wrote: >> On Thu, Nov 8, 2018 at 1:22 PM, Mark Rutland wrote: >> > On Tue, Nov 06, 2018 at 06:30:27PM +0100, Andrey Konovalov wrote: >> >> show_pte in

Re: [PATCH v10 12/22] kasan, arm64: fix up fault handling logic

2018-11-15 Thread Andrey Konovalov
On Wed, Nov 14, 2018 at 9:17 PM, Mark Rutland wrote: > On Wed, Nov 14, 2018 at 09:06:23PM +0100, Andrey Konovalov wrote: >> On Tue, Nov 13, 2018 at 11:07 PM, Mark Rutland wrote: >> > On Tue, Nov 13, 2018 at 04:01:27PM +0100, Andrey Konovalov wrote: >> >> On Thu

Re: [PATCH v10 08/22] kasan, arm64: untag address in __kimg_to_phys and _virt_addr_is_linear

2018-11-15 Thread Andrey Konovalov
On Wed, Nov 14, 2018 at 8:23 PM, Andrey Konovalov wrote: > On Wed, Nov 7, 2018 at 5:52 PM, Mark Rutland wrote: >>> /* >>> @@ -232,7 +241,7 @@ static inline unsigned long kaslr_offset(void) >>> #define __is_lm_address(addr)(!!((addr) & BIT(VA_BITS -

[PATCH v11 07/24] kasan: rename kasan_zero_page to kasan_early_shadow_page

2018-11-19 Thread Andrey Konovalov
With tag based KASAN mode the early shadow value is 0xff and not 0x00, so this patch renames kasan_zero_(page|pte|pmd|pud|p4d) to kasan_early_shadow_(page|pte|pmd|pud|p4d) to avoid confusion. Suggested-by: Mark Rutland Signed-off-by: Andrey Konovalov --- arch/arm64/mm/kasan_init.c | 43

[PATCH v11 08/24] kasan: initialize shadow to 0xff for tag-based mode

2018-11-19 Thread Andrey Konovalov
Ryabinin Reviewed-by: Dmitry Vyukov Signed-off-by: Andrey Konovalov --- arch/arm64/mm/kasan_init.c | 15 +-- include/linux/kasan.h | 8 mm/kasan/common.c | 3 ++- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/arch/arm64/mm/kasan_init.c b/arch

[PATCH v11 06/24] kasan, arm64: adjust shadow size for tag-based mode

2018-11-19 Thread Andrey Konovalov
Signed-off-by: Andrey Konovalov --- arch/arm64/Makefile | 11 ++- arch/arm64/include/asm/memory.h | 7 +++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile index 6cb9fc7e9382..99e7d08c6083 100644 --- a/arch/arm64

[PATCH v11 10/24] kasan: add tag related helper functions

2018-11-19 Thread Andrey Konovalov
This commit adds a few helper functions, that are meant to be used to work with tags embedded in the top byte of kernel pointers: to set, to get or to reset the top byte. Signed-off-by: Andrey Konovalov --- arch/arm64/include/asm/kasan.h | 8 +-- arch/arm64/include/asm/memory.h | 12

[PATCH v11 18/24] mm: move obj_to_index to include/linux/slab_def.h

2018-11-19 Thread Andrey Konovalov
which index this object corresponds to. This patch moves obj_to_index from slab.c to include/linux/slab_def.h to be reused by KASAN. Acked-by: Christoph Lameter Reviewed-by: Andrey Ryabinin Reviewed-by: Dmitry Vyukov Signed-off-by: Andrey Konovalov --- include/linux/slab_def.h

[PATCH v11 14/24] kasan, arm64: enable top byte ignore for the kernel

2018-11-19 Thread Andrey Konovalov
-off-by: Andrey Konovalov --- arch/arm64/include/asm/pgtable-hwdef.h | 1 + arch/arm64/mm/proc.S | 8 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/arch/arm64/include/asm/pgtable-hwdef.h b/arch/arm64/include/asm/pgtable-hwdef.h index 1d7d8da2ef9b

[PATCH v11 19/24] kasan: add hooks implementation for tag-based mode

2018-11-19 Thread Andrey Konovalov
the logic of the hook implementation is very much similar to the one provided by generic KASAN. Tag-based KASAN saves allocation and free stack metadata to the slab object the same way generic KASAN does. Reviewed-by: Andrey Ryabinin Reviewed-by: Dmitry Vyukov Signed-off-by: Andrey Konovalov

[PATCH v11 21/24] kasan, mm, arm64: tag non slab memory allocated via pagealloc

2018-11-19 Thread Andrey Konovalov
-by: Dmitry Vyukov Signed-off-by: Andrey Konovalov --- arch/arm64/include/asm/memory.h | 8 +++- include/linux/mm.h| 29 + include/linux/page-flags-layout.h | 10 ++ mm/cma.c | 11 +++ mm/kasan/common.c

[PATCH v11 23/24] kasan: update documentation

2018-11-19 Thread Andrey Konovalov
This patch updates KASAN documentation to reflect the addition of the new tag-based mode. Reviewed-by: Andrey Ryabinin Reviewed-by: Dmitry Vyukov Signed-off-by: Andrey Konovalov --- Documentation/dev-tools/kasan.rst | 232 ++ 1 file changed, 138 insertions(+), 94

[PATCH v11 24/24] kasan: add SPDX-License-Identifier mark to source files

2018-11-19 Thread Andrey Konovalov
This patch adds a "SPDX-License-Identifier: GPL-2.0" mark to all source files under mm/kasan. Reviewed-by: Andrey Ryabinin Reviewed-by: Dmitry Vyukov Signed-off-by: Andrey Konovalov --- mm/kasan/common.c | 1 + mm/kasan/generic.c| 1 + mm/kasan/generic_report.c | 1 +

[PATCH v11 15/24] kasan, mm: perform untagged pointers comparison in krealloc

2018-11-19 Thread Andrey Konovalov
on on untagged (with tags reset) pointers to check whether it's the same memory region or not. Reviewed-by: Andrey Ryabinin Reviewed-by: Dmitry Vyukov Signed-off-by: Andrey Konovalov --- mm/slab_common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/slab_com

[PATCH v11 16/24] kasan: split out generic_report.c from report.c

2018-11-19 Thread Andrey Konovalov
This patch moves generic KASAN specific error reporting routines to generic_report.c without any functional changes, leaving common error reporting code in report.c to be later reused by tag-based KASAN. Reviewed-by: Andrey Ryabinin Reviewed-by: Dmitry Vyukov Signed-off-by: Andrey Konovalov

[PATCH v11 22/24] kasan: add __must_check annotations to kasan hooks

2018-11-19 Thread Andrey Konovalov
This patch adds __must_check annotations to kasan hooks that return a pointer to make sure that a tagged pointer always gets propagated. Suggested-by: Andrey Ryabinin Signed-off-by: Andrey Konovalov --- include/linux/kasan.h | 16 ++-- mm/kasan/common.c | 14 -- 2

[PATCH v11 17/24] kasan: add bug reporting routines for tag-based mode

2018-11-19 Thread Andrey Konovalov
tag. 2. Tag-based KASAN reports all bugs with the "KASAN: invalid-access" header. Also simplify generic KASAN find_first_bad_addr. Reviewed-by: Andrey Ryabinin Reviewed-by: Dmitry Vyukov Signed-off-by: Andrey Konovalov --- mm/kasan/generic_report.c | 16 --- mm/kas

[PATCH v11 20/24] kasan, arm64: add brk handler for inline instrumentation

2018-11-19 Thread Andrey Konovalov
to the brk instructions (to extract information about the memory access that triggered the mismatch), reads the register values (x0 contains the guilty address) and reports the bug. Reviewed-by: Andrey Ryabinin Reviewed-by: Dmitry Vyukov Signed-off-by: Andrey Konovalov --- arch/arm64/include

[PATCH v11 12/24] kasan: preassign tags to objects with ctors or SLAB_TYPESAFE_BY_RCU

2018-11-19 Thread Andrey Konovalov
ed-by: Andrey Ryabinin Reviewed-by: Dmitry Vyukov Signed-off-by: Andrey Konovalov --- mm/slab.c | 2 +- mm/slub.c | 24 ++-- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/mm/slab.c b/mm/slab.c index 26f60a22e5e0..27859fb39889 100644 --- a/mm/slab.c +++

Re: [PATCH v11 00/24] kasan: add software tag-based mode for arm64

2018-11-19 Thread Andrey Konovalov
On Mon, Nov 19, 2018 at 6:26 PM, Andrey Konovalov wrote: > This patchset adds a new software tag-based mode to KASAN [1]. > (Initially this mode was called KHWASAN, but it got renamed, > see the naming rationale at the end of this section). > > The plan is to implement HWASan [2]

[PATCH v11 13/24] kasan, arm64: fix up fault handling logic

2018-11-19 Thread Andrey Konovalov
fact that TTBR1 pointers might be tagged when tag-based KASAN is in use, and uses these helper functions to perform pointer checks in arch/arm64/mm/fault.c. Suggested-by: Mark Rutland Signed-off-by: Andrey Konovalov --- arch/arm64/mm/fault.c | 31 ++- 1 file change

[PATCH v11 09/24] arm64: move untagged_addr macro from uaccess.h to memory.h

2018-11-19 Thread Andrey Konovalov
macro is used. This is done by using __typeof__. Signed-off-by: Andrey Konovalov --- arch/arm64/include/asm/memory.h | 8 arch/arm64/include/asm/uaccess.h | 7 --- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm

[PATCH v11 11/24] kasan, arm64: untag address in _virt_addr_is_linear

2018-11-19 Thread Andrey Konovalov
virt_addr_is_linear (which is used by virt_addr_valid) assumes that the top byte of the address is 0xff, which isn't always the case with tag-based KASAN. This patch resets the tag in this macro. Reviewed-by: Andrey Ryabinin Reviewed-by: Dmitry Vyukov Signed-off-by: Andrey Konovalov ---

[PATCH v11 05/24] kasan: add CONFIG_KASAN_GENERIC and CONFIG_KASAN_SW_TAGS

2018-11-19 Thread Andrey Konovalov
correctly with each of the config options. Reviewed-by: Andrey Ryabinin Reviewed-by: Dmitry Vyukov Signed-off-by: Andrey Konovalov --- arch/arm64/Kconfig | 1 + include/linux/compiler-clang.h | 5 +- include/linux/compiler-gcc.h| 6 ++ include/linux

[PATCH v11 04/24] kasan: rename source files to reflect the new naming scheme

2018-11-19 Thread Andrey Konovalov
We now have two KASAN modes: generic KASAN and tag-based KASAN. Rename kasan.c to generic.c to reflect that. Also rename kasan_init.c to init.c as it contains initialization code for both KASAN modes. Reviewed-by: Andrey Ryabinin Reviewed-by: Dmitry Vyukov Signed-off-by: Andrey Konovalov

[PATCH v11 03/24] kasan: move common generic and tag-based code to common.c

2018-11-19 Thread Andrey Konovalov
Tag-based KASAN reuses a significant part of the generic KASAN code, so move the common parts to common.c without any functional changes. Reviewed-by: Andrey Ryabinin Reviewed-by: Dmitry Vyukov Signed-off-by: Andrey Konovalov --- mm/kasan/Makefile | 5 +- mm/kasan/common.c | 603

[PATCH v11 00/24] kasan: add software tag-based mode for arm64

2018-11-19 Thread Andrey Konovalov
dress + kmap usage). - Used the reserved tag 0xFE to mark redzones and freed objects. - Added mnemonics for esr manipulation in KHWASAN brk handler. - Added a comment about the -recover flag. - Some minor cleanups and fixes. - Rebased onto 3215b9d5 (4.16-rc6+). - Tested on real hardware (Odroid C2 board)

[PATCH v11 01/24] kasan, mm: change hooks signatures

2018-11-19 Thread Andrey Konovalov
: Andrey Konovalov --- include/linux/kasan.h | 43 +-- include/linux/slab.h | 4 ++-- mm/kasan/kasan.c | 30 ++ mm/slab.c | 12 ++-- mm/slab.h | 2 +- mm/slab_common.c | 4 ++-- mm

[PATCH v11 02/24] kasan, slub: handle pointer tags in early_kmem_cache_node_alloc

2018-11-19 Thread Andrey Konovalov
is assigned by kasan_kmalloc. Signed-off-by: Andrey Konovalov --- mm/slub.c | 10 +- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mm/slub.c b/mm/slub.c index fdd4a86aa882..8561a32910dd 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -3364,16 +3364,16 @@ static void

Re: [PATCH v11 09/24] arm64: move untagged_addr macro from uaccess.h to memory.h

2018-11-27 Thread Andrey Konovalov
On Fri, Nov 23, 2018 at 6:37 PM, Mark Rutland wrote: > On Mon, Nov 19, 2018 at 06:26:25PM +0100, Andrey Konovalov wrote: >> Move the untagged_addr() macro from arch/arm64/include/asm/uaccess.h >> to arch/arm64/include/asm/memory.h to be later reused by KASAN. >> >>

Re: [PATCH v11 05/24] kasan: add CONFIG_KASAN_GENERIC and CONFIG_KASAN_SW_TAGS

2018-11-27 Thread Andrey Konovalov
On Fri, Nov 23, 2018 at 6:43 PM, Mark Rutland wrote: > On Mon, Nov 19, 2018 at 06:26:21PM +0100, Andrey Konovalov wrote: >> This commit splits the current CONFIG_KASAN config option into two: >> 1. CONFIG_KASAN_GENERIC, that enables the generic KASAN mode (the one >>t

[PATCH v12 03/25] kasan: move common generic and tag-based code to common.c

2018-11-27 Thread Andrey Konovalov
Tag-based KASAN reuses a significant part of the generic KASAN code, so move the common parts to common.c without any functional changes. Reviewed-by: Andrey Ryabinin Reviewed-by: Dmitry Vyukov Signed-off-by: Andrey Konovalov --- mm/kasan/Makefile | 5 +- mm/kasan/common.c | 603

[PATCH v12 01/25] kasan, mm: change hooks signatures

2018-11-27 Thread Andrey Konovalov
: Andrey Konovalov --- include/linux/kasan.h | 43 +-- include/linux/slab.h | 4 ++-- mm/kasan/kasan.c | 30 ++ mm/slab.c | 12 ++-- mm/slab.h | 2 +- mm/slab_common.c | 4 ++-- mm

[PATCH v12 00/25] kasan: add software tag-based mode for arm64

2018-11-27 Thread Andrey Konovalov
on in KHWASAN brk handler. - Added a comment about the -recover flag. - Some minor cleanups and fixes. - Rebased onto 3215b9d5 (4.16-rc6+). - Tested on real hardware (Odroid C2 board). - Added better benchmarks. [1] https://lkml.org/lkml/2018/7/18/765 [2] https://lkml.org/lkml/2018/4/19/775

[PATCH v12 24/25] kasan: update documentation

2018-11-27 Thread Andrey Konovalov
This patch updates KASAN documentation to reflect the addition of the new tag-based mode. Reviewed-by: Andrey Ryabinin Reviewed-by: Dmitry Vyukov Signed-off-by: Andrey Konovalov --- Documentation/dev-tools/kasan.rst | 232 ++ 1 file changed, 138 insertions(+), 94

[PATCH v12 23/25] kasan, arm64: select HAVE_ARCH_KASAN_SW_TAGS

2018-11-27 Thread Andrey Konovalov
Now, that all the necessary infrastructure code has been introduced, select HAVE_ARCH_KASAN_SW_TAGS for arm64 to enable software tag-based KASAN mode. Signed-off-by: Andrey Konovalov --- arch/arm64/Kconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/arm64/Kconfig b/arch/arm64

[PATCH v12 21/25] kasan, mm, arm64: tag non slab memory allocated via pagealloc

2018-11-27 Thread Andrey Konovalov
-by: Dmitry Vyukov Signed-off-by: Andrey Konovalov --- arch/arm64/include/asm/memory.h | 8 +++- include/linux/mm.h| 29 + include/linux/page-flags-layout.h | 10 ++ mm/cma.c | 11 +++ mm/kasan/common.c

[PATCH v12 18/25] mm: move obj_to_index to include/linux/slab_def.h

2018-11-27 Thread Andrey Konovalov
which index this object corresponds to. This patch moves obj_to_index from slab.c to include/linux/slab_def.h to be reused by KASAN. Acked-by: Christoph Lameter Reviewed-by: Andrey Ryabinin Reviewed-by: Dmitry Vyukov Signed-off-by: Andrey Konovalov --- include/linux/slab_def.h

[PATCH v12 12/25] kasan: preassign tags to objects with ctors or SLAB_TYPESAFE_BY_RCU

2018-11-27 Thread Andrey Konovalov
ed-by: Andrey Ryabinin Reviewed-by: Dmitry Vyukov Signed-off-by: Andrey Konovalov --- mm/slab.c | 2 +- mm/slub.c | 24 ++-- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/mm/slab.c b/mm/slab.c index 26f60a22e5e0..27859fb39889 100644 --- a/mm/slab.c +++

[PATCH v12 11/25] kasan, arm64: untag address in _virt_addr_is_linear

2018-11-27 Thread Andrey Konovalov
virt_addr_is_linear (which is used by virt_addr_valid) assumes that the top byte of the address is 0xff, which isn't always the case with tag-based KASAN. This patch resets the tag in this macro. Reviewed-by: Andrey Ryabinin Reviewed-by: Dmitry Vyukov Signed-off-by: Andrey Konovalov ---

[PATCH v12 15/25] kasan, mm: perform untagged pointers comparison in krealloc

2018-11-27 Thread Andrey Konovalov
on on untagged (with tags reset) pointers to check whether it's the same memory region or not. Reviewed-by: Andrey Ryabinin Reviewed-by: Dmitry Vyukov Signed-off-by: Andrey Konovalov --- mm/slab_common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/slab_com

[PATCH v12 14/25] kasan, arm64: enable top byte ignore for the kernel

2018-11-27 Thread Andrey Konovalov
-off-by: Andrey Konovalov --- arch/arm64/include/asm/pgtable-hwdef.h | 1 + arch/arm64/mm/proc.S | 8 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/arch/arm64/include/asm/pgtable-hwdef.h b/arch/arm64/include/asm/pgtable-hwdef.h index 1d7d8da2ef9b

[PATCH v12 07/25] kasan: rename kasan_zero_page to kasan_early_shadow_page

2018-11-27 Thread Andrey Konovalov
With tag based KASAN mode the early shadow value is 0xff and not 0x00, so this patch renames kasan_zero_(page|pte|pmd|pud|p4d) to kasan_early_shadow_(page|pte|pmd|pud|p4d) to avoid confusion. Suggested-by: Mark Rutland Signed-off-by: Andrey Konovalov --- arch/arm64/mm/kasan_init.c | 43

[PATCH v12 17/25] kasan: add bug reporting routines for tag-based mode

2018-11-27 Thread Andrey Konovalov
tag. 2. Tag-based KASAN reports all bugs with the "KASAN: invalid-access" header. Also simplify generic KASAN find_first_bad_addr. Reviewed-by: Andrey Ryabinin Reviewed-by: Dmitry Vyukov Signed-off-by: Andrey Konovalov --- mm/kasan/generic_report.c | 16 --- mm/kas

[PATCH v12 25/25] kasan: add SPDX-License-Identifier mark to source files

2018-11-27 Thread Andrey Konovalov
This patch adds a "SPDX-License-Identifier: GPL-2.0" mark to all source files under mm/kasan. Reviewed-by: Andrey Ryabinin Reviewed-by: Dmitry Vyukov Signed-off-by: Andrey Konovalov --- mm/kasan/common.c | 1 + mm/kasan/generic.c| 1 + mm/kasan/generic_report.c | 1 +

[PATCH v12 16/25] kasan: split out generic_report.c from report.c

2018-11-27 Thread Andrey Konovalov
This patch moves generic KASAN specific error reporting routines to generic_report.c without any functional changes, leaving common error reporting code in report.c to be later reused by tag-based KASAN. Reviewed-by: Andrey Ryabinin Reviewed-by: Dmitry Vyukov Signed-off-by: Andrey Konovalov

[PATCH v12 22/25] kasan: add __must_check annotations to kasan hooks

2018-11-27 Thread Andrey Konovalov
This patch adds __must_check annotations to kasan hooks that return a pointer to make sure that a tagged pointer always gets propagated. Suggested-by: Andrey Ryabinin Signed-off-by: Andrey Konovalov --- include/linux/kasan.h | 16 ++-- mm/kasan/common.c | 15 +-- 2

[PATCH v12 19/25] kasan: add hooks implementation for tag-based mode

2018-11-27 Thread Andrey Konovalov
the logic of the hook implementation is very much similar to the one provided by generic KASAN. Tag-based KASAN saves allocation and free stack metadata to the slab object the same way generic KASAN does. Reviewed-by: Andrey Ryabinin Reviewed-by: Dmitry Vyukov Signed-off-by: Andrey Konovalov

[PATCH v12 20/25] kasan, arm64: add brk handler for inline instrumentation

2018-11-27 Thread Andrey Konovalov
to the brk instructions (to extract information about the memory access that triggered the mismatch), reads the register values (x0 contains the guilty address) and reports the bug. Reviewed-by: Andrey Ryabinin Reviewed-by: Dmitry Vyukov Signed-off-by: Andrey Konovalov --- arch/arm64/include

[PATCH v12 13/25] kasan, arm64: fix up fault handling logic

2018-11-27 Thread Andrey Konovalov
fact that TTBR1 pointers might be tagged when tag-based KASAN is in use, and uses these helper functions to perform pointer checks in arch/arm64/mm/fault.c. Suggested-by: Mark Rutland Signed-off-by: Andrey Konovalov --- arch/arm64/mm/fault.c | 31 ++- 1 file change

[PATCH v12 08/25] kasan: initialize shadow to 0xff for tag-based mode

2018-11-27 Thread Andrey Konovalov
Ryabinin Reviewed-by: Dmitry Vyukov Signed-off-by: Andrey Konovalov --- arch/arm64/mm/kasan_init.c | 15 +-- include/linux/kasan.h | 8 mm/kasan/common.c | 3 ++- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/arch/arm64/mm/kasan_init.c b/arch

[PATCH v12 02/25] kasan, slub: handle pointer tags in early_kmem_cache_node_alloc

2018-11-27 Thread Andrey Konovalov
is assigned by kasan_kmalloc. Signed-off-by: Andrey Konovalov --- mm/slub.c | 10 +- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mm/slub.c b/mm/slub.c index fdd4a86aa882..8561a32910dd 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -3364,16 +3364,16 @@ static void

[PATCH v12 04/25] kasan: rename source files to reflect the new naming scheme

2018-11-27 Thread Andrey Konovalov
We now have two KASAN modes: generic KASAN and tag-based KASAN. Rename kasan.c to generic.c to reflect that. Also rename kasan_init.c to init.c as it contains initialization code for both KASAN modes. Reviewed-by: Andrey Ryabinin Reviewed-by: Dmitry Vyukov Signed-off-by: Andrey Konovalov

[PATCH v12 06/25] kasan, arm64: adjust shadow size for tag-based mode

2018-11-27 Thread Andrey Konovalov
Signed-off-by: Andrey Konovalov --- arch/arm64/Makefile | 11 ++- arch/arm64/include/asm/memory.h | 7 +++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile index 6cb9fc7e9382..99e7d08c6083 100644 --- a/arch/arm64

[PATCH v12 05/25] kasan: add CONFIG_KASAN_GENERIC and CONFIG_KASAN_SW_TAGS

2018-11-27 Thread Andrey Konovalov
commit adds the CONFIG_KASAN_SW_TAGS config option, this option is not selectable, as it depends on HAVE_ARCH_KASAN_SW_TAGS, which we will enable once all the infrastracture code has been added. Reviewed-by: Andrey Ryabinin Reviewed-by: Dmitry Vyukov Signed-off-by: Andrey Konovalov --- include/linux

[PATCH v12 09/25] arm64: move untagged_addr macro from uaccess.h to memory.h

2018-11-27 Thread Andrey Konovalov
macro is used. This is done by using __typeof__. Acked-by: Mark Rutland Signed-off-by: Andrey Konovalov --- arch/arm64/include/asm/memory.h | 8 arch/arm64/include/asm/uaccess.h | 7 --- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/arch/arm64/include/asm/memory.h b

[PATCH v12 10/25] kasan: add tag related helper functions

2018-11-27 Thread Andrey Konovalov
This commit adds a few helper functions, that are meant to be used to work with tags embedded in the top byte of kernel pointers: to set, to get or to reset the top byte. Signed-off-by: Andrey Konovalov --- arch/arm64/include/asm/kasan.h | 8 +-- arch/arm64/include/asm/memory.h | 12

Re: [PATCH v12 05/25] kasan: add CONFIG_KASAN_GENERIC and CONFIG_KASAN_SW_TAGS

2018-12-06 Thread Andrey Konovalov
On Tue, Dec 4, 2018 at 11:24 PM Max Filippov wrote: > > Hello, > > On Tue, Nov 27, 2018 at 9:00 AM Andrey Konovalov > wrote: > > > > This commit splits the current CONFIG_KASAN config option into two: > > 1. CONFIG_KASAN_GENERIC, that enables the generic KASAN

Re: [PATCH v12 23/25] kasan, arm64: select HAVE_ARCH_KASAN_SW_TAGS

2018-12-06 Thread Andrey Konovalov
On Thu, Nov 29, 2018 at 7:01 PM Will Deacon wrote: > > On Tue, Nov 27, 2018 at 05:55:41PM +0100, Andrey Konovalov wrote: > > Now, that all the necessary infrastructure code has been introduced, > > select HAVE_ARCH_KASAN_SW_TAGS for arm64 to enable software tag-ba

Re: [PATCH v12 20/25] kasan, arm64: add brk handler for inline instrumentation

2018-12-06 Thread Andrey Konovalov
On Thu, Nov 29, 2018 at 7:01 PM Will Deacon wrote: > > On Tue, Nov 27, 2018 at 05:55:38PM +0100, Andrey Konovalov wrote: > > Tag-based KASAN inline instrumentation mode (which embeds checks of shadow > > memory into the generated code, instead of inserting a callback) g

[PATCH v13 01/25] kasan, mm: change hooks signatures

2018-12-06 Thread Andrey Konovalov
: Andrey Konovalov --- include/linux/kasan.h | 43 +-- include/linux/slab.h | 4 ++-- mm/kasan/kasan.c | 30 ++ mm/slab.c | 12 ++-- mm/slab.h | 2 +- mm/slab_common.c | 4 ++-- mm

[PATCH v13 02/25] kasan, slub: handle pointer tags in early_kmem_cache_node_alloc

2018-12-06 Thread Andrey Konovalov
is assigned by kasan_kmalloc. Signed-off-by: Andrey Konovalov --- mm/slub.c | 10 +- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mm/slub.c b/mm/slub.c index fdd4a86aa882..8561a32910dd 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -3364,16 +3364,16 @@ static void

[PATCH v13 04/25] kasan: rename source files to reflect the new naming scheme

2018-12-06 Thread Andrey Konovalov
We now have two KASAN modes: generic KASAN and tag-based KASAN. Rename kasan.c to generic.c to reflect that. Also rename kasan_init.c to init.c as it contains initialization code for both KASAN modes. Reviewed-by: Andrey Ryabinin Reviewed-by: Dmitry Vyukov Signed-off-by: Andrey Konovalov

[PATCH v13 22/25] kasan: add __must_check annotations to kasan hooks

2018-12-06 Thread Andrey Konovalov
This patch adds __must_check annotations to kasan hooks that return a pointer to make sure that a tagged pointer always gets propagated. Suggested-by: Andrey Ryabinin Signed-off-by: Andrey Konovalov --- include/linux/kasan.h | 16 ++-- mm/kasan/common.c | 15 +-- 2

[PATCH v13 21/25] kasan, mm, arm64: tag non slab memory allocated via pagealloc

2018-12-06 Thread Andrey Konovalov
-by: Dmitry Vyukov Signed-off-by: Andrey Konovalov --- arch/arm64/include/asm/memory.h | 8 +++- include/linux/mm.h| 29 + include/linux/page-flags-layout.h | 10 ++ mm/cma.c | 11 +++ mm/kasan/common.c

[PATCH v13 07/25] kasan: rename kasan_zero_page to kasan_early_shadow_page

2018-12-06 Thread Andrey Konovalov
With tag based KASAN mode the early shadow value is 0xff and not 0x00, so this patch renames kasan_zero_(page|pte|pmd|pud|p4d) to kasan_early_shadow_(page|pte|pmd|pud|p4d) to avoid confusion. Suggested-by: Mark Rutland Signed-off-by: Andrey Konovalov --- arch/arm64/mm/kasan_init.c | 43

[PATCH v13 16/25] kasan: split out generic_report.c from report.c

2018-12-06 Thread Andrey Konovalov
This patch moves generic KASAN specific error reporting routines to generic_report.c without any functional changes, leaving common error reporting code in report.c to be later reused by tag-based KASAN. Reviewed-by: Andrey Ryabinin Reviewed-by: Dmitry Vyukov Signed-off-by: Andrey Konovalov

[PATCH v13 14/25] kasan, arm64: enable top byte ignore for the kernel

2018-12-06 Thread Andrey Konovalov
-off-by: Andrey Konovalov --- arch/arm64/include/asm/pgtable-hwdef.h | 1 + arch/arm64/mm/proc.S | 8 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/arch/arm64/include/asm/pgtable-hwdef.h b/arch/arm64/include/asm/pgtable-hwdef.h index 1d7d8da2ef9b

[PATCH v13 25/25] kasan: add SPDX-License-Identifier mark to source files

2018-12-06 Thread Andrey Konovalov
This patch adds a "SPDX-License-Identifier: GPL-2.0" mark to all source files under mm/kasan. Reviewed-by: Andrey Ryabinin Reviewed-by: Dmitry Vyukov Signed-off-by: Andrey Konovalov --- mm/kasan/common.c | 1 + mm/kasan/generic.c| 1 + mm/kasan/generic_report.c | 1 +

Re: [PATCH v12 20/25] kasan, arm64: add brk handler for inline instrumentation

2018-12-06 Thread Andrey Konovalov
On Thu, Dec 6, 2018 at 12:10 PM Will Deacon wrote: > > On Thu, Dec 06, 2018 at 11:31:43AM +0100, Andrey Konovalov wrote: > > On Thu, Nov 29, 2018 at 7:01 PM Will Deacon wrote: > > > > > > On Tue, Nov 27, 2018 at 05:55:38PM +0100, Andrey Konovalov wrote:

[PATCH v13 24/25] kasan: update documentation

2018-12-06 Thread Andrey Konovalov
This patch updates KASAN documentation to reflect the addition of the new tag-based mode. Reviewed-by: Andrey Ryabinin Reviewed-by: Dmitry Vyukov Signed-off-by: Andrey Konovalov --- Documentation/dev-tools/kasan.rst | 232 ++ 1 file changed, 138 insertions(+), 94

[PATCH v13 20/25] kasan, arm64: add brk handler for inline instrumentation

2018-12-06 Thread Andrey Konovalov
to the brk instructions (to extract information about the memory access that triggered the mismatch), reads the register values (x0 contains the guilty address) and reports the bug. Reviewed-by: Andrey Ryabinin Reviewed-by: Dmitry Vyukov Signed-off-by: Andrey Konovalov --- arch/arm64/include

[PATCH v13 23/25] kasan, arm64: select HAVE_ARCH_KASAN_SW_TAGS

2018-12-06 Thread Andrey Konovalov
Now, that all the necessary infrastructure code has been introduced, select HAVE_ARCH_KASAN_SW_TAGS for arm64 to enable software tag-based KASAN mode. Signed-off-by: Andrey Konovalov --- arch/arm64/Kconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/arm64/Kconfig b/arch/arm64

[PATCH v13 19/25] kasan: add hooks implementation for tag-based mode

2018-12-06 Thread Andrey Konovalov
the logic of the hook implementation is very much similar to the one provided by generic KASAN. Tag-based KASAN saves allocation and free stack metadata to the slab object the same way generic KASAN does. Reviewed-by: Andrey Ryabinin Reviewed-by: Dmitry Vyukov Signed-off-by: Andrey Konovalov

[PATCH v13 12/25] kasan: preassign tags to objects with ctors or SLAB_TYPESAFE_BY_RCU

2018-12-06 Thread Andrey Konovalov
ed-by: Andrey Ryabinin Reviewed-by: Dmitry Vyukov Signed-off-by: Andrey Konovalov --- mm/slab.c | 2 +- mm/slub.c | 24 ++-- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/mm/slab.c b/mm/slab.c index 26f60a22e5e0..27859fb39889 100644 --- a/mm/slab.c +++

[PATCH v13 17/25] kasan: add bug reporting routines for tag-based mode

2018-12-06 Thread Andrey Konovalov
tag. 2. Tag-based KASAN reports all bugs with the "KASAN: invalid-access" header. Also simplify generic KASAN find_first_bad_addr. Reviewed-by: Andrey Ryabinin Reviewed-by: Dmitry Vyukov Signed-off-by: Andrey Konovalov --- mm/kasan/generic_report.c | 16 --- mm/kas

[PATCH v13 15/25] kasan, mm: perform untagged pointers comparison in krealloc

2018-12-06 Thread Andrey Konovalov
on on untagged (with tags reset) pointers to check whether it's the same memory region or not. Reviewed-by: Andrey Ryabinin Reviewed-by: Dmitry Vyukov Signed-off-by: Andrey Konovalov --- mm/slab_common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/slab_com

[PATCH v13 18/25] mm: move obj_to_index to include/linux/slab_def.h

2018-12-06 Thread Andrey Konovalov
which index this object corresponds to. This patch moves obj_to_index from slab.c to include/linux/slab_def.h to be reused by KASAN. Acked-by: Christoph Lameter Reviewed-by: Andrey Ryabinin Reviewed-by: Dmitry Vyukov Signed-off-by: Andrey Konovalov --- include/linux/slab_def.h

  1   2   3   >