Re: [PATCH RESEND v3 2/3] kasan: migrate copy_user_test to kunit

2024-10-15 Thread Andrey Konovalov
On Tue, Oct 15, 2024 at 12:52 PM Sabyrzhan Tasbolatov wrote: > > > Too bad. I guess we have to duplicate both kasan_check_write and > > check_object_size before both do_strncpy_from_user calls in > > strncpy_from_user. > > Shall we do it once in strncpy_from_user() as I did in v1? > Please let me

Re: [PATCH RESEND v3 2/3] kasan: migrate copy_user_test to kunit

2024-10-14 Thread Andrey Konovalov
On Tue, Oct 15, 2024 at 1:10 AM Andrew Morton wrote: > > On Mon, 14 Oct 2024 07:57:00 +0500 Sabyrzhan Tasbolatov > wrote: > > > Migrate the copy_user_test to the KUnit framework to verify out-of-bound > > detection via KASAN reports in copy_from_user(), copy_to_user() and > > their static functi

Re: [PATCH v3 3/3] kasan: delete CONFIG_KASAN_MODULE_TEST

2024-10-13 Thread Andrey Konovalov
id) { } > > #endif /* CONFIG_KASAN_KUNIT_TEST */ > > -#if IS_ENABLED(CONFIG_KASAN_KUNIT_TEST) || > IS_ENABLED(CONFIG_KASAN_MODULE_TEST) > +#if IS_ENABLED(CONFIG_KASAN_KUNIT_TEST) > > bool kasan_save_enable_multi_shot(void); > void kasan_restore_multi_shot(bool enabled); > diff --git a/mm/kasan/report.c b/mm/kasan/report.c > index b48c768acc8..3e48668c3e4 100644 > --- a/mm/kasan/report.c > +++ b/mm/kasan/report.c > @@ -132,7 +132,7 @@ static bool report_enabled(void) > return !test_and_set_bit(KASAN_BIT_REPORTED, &kasan_flags); > } > > -#if IS_ENABLED(CONFIG_KASAN_KUNIT_TEST) || > IS_ENABLED(CONFIG_KASAN_MODULE_TEST) > +#if IS_ENABLED(CONFIG_KASAN_KUNIT_TEST) > > bool kasan_save_enable_multi_shot(void) > { > -- > 2.34.1 > Reviewed-by: Andrey Konovalov

Re: [PATCH v3 2/3] kasan: migrate copy_user_test to kunit

2024-10-13 Thread Andrey Konovalov
= __copy_to_user_inatomic(usermem, kmem, size + 1); > - > - pr_info("out-of-bounds in strncpy_from_user()\n"); > - unused = strncpy_from_user(kmem, usermem, size + 1); > - > - vm_munmap((unsigned long)usermem, PAGE_SIZE); > - kfree(kmem); > -} > - > -static int __ini

Re: [PATCH v2 1/3] kasan: move checks to do_strncpy_from_user

2024-10-13 Thread Andrey Konovalov
check_object_size(dst, count, false); > if (user_read_access_begin(src, max)) { > retval = do_strncpy_from_user(dst, src, count, max); > user_read_access_end(); > -- > 2.34.1 > Reviewed-by: Andrey Konovalov

Re: [PATCH v2 3/3] kasan: delete CONFIG_KASAN_MODULE_TEST

2024-10-13 Thread Andrey Konovalov
On Sun, Oct 13, 2024 at 3:02 PM Sabyrzhan Tasbolatov wrote: > > diff --git a/Documentation/dev-tools/kasan.rst > b/Documentation/dev-tools/kasan.rst > index d7de44f5339..52fdd6b5ef6 100644 > --- a/Documentation/dev-tools/kasan.rst > +++ b/Documentation/dev-tools/kasan.rst > @@ -511,17 +511,12 @@

Re: [PATCH v2 2/3] kasan: migrate copy_user_test to kunit

2024-10-13 Thread Andrey Konovalov
On Sun, Oct 13, 2024 at 3:02 PM Sabyrzhan Tasbolatov wrote: > > Migrate the copy_user_test to the KUnit framework to verify out-of-bound > detection via KASAN reports in copy_from_user(), copy_to_user() and > their static functions. > > This is the last migrated test in kasan_test_module.c, theref

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 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 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 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 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 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 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 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

Re: [PATCH v10 00/12] arm64: untag user pointers passed to the kernel

2019-02-26 Thread Andrey Konovalov
On Fri, Feb 22, 2019 at 11:55 PM Dave Hansen wrote: > > On 2/22/19 4:53 AM, Andrey Konovalov wrote: > > The following testing approaches has been taken to find potential issues > > with user pointer untagging: > > > > 1. Static testing (with sparse [3] and s

Re: [PATCH v10 00/12] arm64: untag user pointers passed to the kernel

2019-02-26 Thread Andrey Konovalov
On Fri, Feb 22, 2019 at 5:10 PM Szabolcs Nagy wrote: > > On 22/02/2019 15:40, Andrey Konovalov wrote: > > On Fri, Feb 22, 2019 at 4:35 PM Szabolcs Nagy wrote: > >> > >> On 22/02/2019 12:53, Andrey Konovalov wrote: > >>> This patchset is meant to be m

Re: [PATCH v10 04/12] mm, arm64: untag user pointers passed to memory syscalls

2019-02-26 Thread Andrey Konovalov
On Sat, Feb 23, 2019 at 12:07 AM Dave Hansen wrote: > > On 2/22/19 4:53 AM, Andrey Konovalov wrote: > > --- a/mm/mprotect.c > > +++ b/mm/mprotect.c > > @@ -578,6 +578,7 @@ static int do_mprotect_pkey(unsigned long start, size_t > > len, > > SYSCALL_DEFINE3(mp

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

2019-02-26 Thread Andrey Konovalov
On Sat, Feb 23, 2019 at 12:06 AM Dave Hansen wrote: > > On 2/22/19 4:53 AM, Andrey Konovalov wrote: > > userfaultfd_register() and userfaultfd_unregister() use provided user > > pointers for vma lookups, which can only by done with untagged pointers. > > So, we have

Re: [PATCH v10 06/12] fs, arm64: untag user pointers in copy_mount_options

2019-02-26 Thread Andrey Konovalov
On Sat, Feb 23, 2019 at 12:03 AM Dave Hansen wrote: > > On 2/22/19 4:53 AM, Andrey Konovalov wrote: > > --- a/fs/namespace.c > > +++ b/fs/namespace.c > > @@ -2730,7 +2730,7 @@ void *copy_mount_options(const void __user * data) > >

Re: [PATCH v10 00/12] arm64: untag user pointers passed to the kernel

2019-02-22 Thread Andrey Konovalov
On Fri, Feb 22, 2019 at 4:35 PM Szabolcs Nagy wrote: > > On 22/02/2019 12:53, Andrey Konovalov wrote: > > This patchset is meant to be merged together with "arm64 relaxed ABI" [1]. > > > > arm64 has a feature called Top Byte Ignore, which allows to embed pointer

[PATCH v10 03/12] lib, arm64: untag user pointers in strn*_user

2019-02-22 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 handle the case of tagged user addresses separately. Untag user pointers passed to these functions. Signed-off-by: Andrey Konovalov

[PATCH v10 02/12] arm64: untag user pointers in access_ok and __uaccess_mask_ptr

2019-02-22 Thread Andrey Konovalov
in access_ok and in __uaccess_mask_ptr, before performing access validity checks. Note, that this patch only temporarily untags the pointers to perform the checks, but then passes them as is into the kernel internals. Reviewed-by: Catalin Marinas Signed-off-by: Andrey Konovalov --- arch/arm64

[PATCH v10 00/12] arm64: untag user pointers passed to the kernel

2019-02-22 Thread Andrey Konovalov
moved untagging pointers returned from __uaccess_mask_ptr. Changes in v1: - Rebased onto 4.17-rc1. Changes in RFC v2: - Added "#ifndef untagged_addr..." fallback in linux/uaccess.h instead of defining it for each arch individually. - Updated Documentation/arm64/tagged-pointers.txt. - Dro

[PATCH v10 04/12] mm, arm64: untag user pointers passed to memory syscalls

2019-02-22 Thread Andrey Konovalov
This commit allows tagged pointers to be passed to the following memory syscalls: madvise, mbind, get_mempolicy, mincore, mlock, mlock2, brk, mmap_pgoff, old_mmap, munmap, remap_file_pages, mprotect, pkey_mprotect, mremap, msync and shmdt. Signed-off-by: Andrey Konovalov --- ipc/shm.c | 2

[PATCH v10 09/12] kernel, arm64: untag user pointers in prctl_set_mm*

2019-02-22 Thread Andrey Konovalov
prctl_set_mm() and prctl_set_mm_map() use provided user pointers for vma lookups, which can only by done with untagged pointers. Untag user pointers in these functions. Signed-off-by: Andrey Konovalov --- kernel/sys.c | 14 ++ 1 file changed, 14 insertions(+) diff --git a/kernel

[PATCH v10 06/12] fs, arm64: untag user pointers in copy_mount_options

2019-02-22 Thread Andrey Konovalov
the address before subtracting. Signed-off-by: Andrey Konovalov --- fs/namespace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/namespace.c b/fs/namespace.c index a677b59efd74..d4b7adef9204 100644 --- a/fs/namespace.c +++ b/fs/namespace.c @@ -2730,7 +2730,7 @@ void

[PATCH v10 11/12] arm64: update Documentation/arm64/tagged-pointers.txt

2019-02-22 Thread Andrey Konovalov
Document the changes in Documentation/arm64/tagged-pointers.txt. Signed-off-by: Andrey Konovalov --- Documentation/arm64/tagged-pointers.txt | 25 +++-- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/Documentation/arm64/tagged-pointers.txt b/Documentation

[PATCH v10 08/12] net, arm64: untag user pointers in tcp_zerocopy_receive

2019-02-22 Thread Andrey Konovalov
tcp_zerocopy_receive() uses provided user pointers for vma lookups, which can only by done with untagged pointers. Untag user pointers in this function. Signed-off-by: Andrey Konovalov --- net/ipv4/tcp.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c

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

2019-02-22 Thread Andrey Konovalov
userfaultfd_register() and userfaultfd_unregister() use provided user pointers for vma lookups, which can only by done with untagged pointers. Untag user pointers in these functions. Signed-off-by: Andrey Konovalov --- fs/userfaultfd.c | 5 + 1 file changed, 5 insertions(+) diff --git a

[PATCH v10 05/12] mm, arm64: untag user pointers in mm/gup.c

2019-02-22 Thread Andrey Konovalov
for vma lookup. Signed-off-by: Andrey Konovalov --- mm/gup.c | 4 1 file changed, 4 insertions(+) diff --git a/mm/gup.c b/mm/gup.c index 75029649baca..b6eda1608bea 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -683,6 +683,8 @@ static long __get_user_pages(struct task_struct *tsk, struct mm_struct

[PATCH v10 12/12] selftests, arm64: add a selftest for passing tagged pointers to kernel

2019-02-22 Thread Andrey Konovalov
This patch adds a simple test, that calls the uname syscall with a tagged user pointer as an argument. Without the kernel accepting tagged user pointers the test fails with EFAULT. Signed-off-by: Andrey Konovalov --- tools/testing/selftests/arm64/.gitignore | 1 + tools/testing/selftests

[PATCH v10 10/12] tracing, arm64: untag user pointers in seq_print_user_ip

2019-02-22 Thread Andrey Konovalov
seq_print_user_ip() uses provided user pointers for vma lookups, which can only by done with untagged pointers. Untag user pointers in this function. Signed-off-by: Andrey Konovalov --- kernel/trace/trace_output.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/trace

[PATCH v10 01/12] uaccess: add untagged_addr definition for other arches

2019-02-22 Thread Andrey Konovalov
arm64. Acked-by: Catalin Marinas Signed-off-by: Andrey Konovalov --- include/linux/memory.h | 4 1 file changed, 4 insertions(+) diff --git a/include/linux/memory.h b/include/linux/memory.h index a6ddefc60517..fc383bc39ab8 100644 --- a/include/linux/memory.h +++ b/include/linux/memory.h

Re: [PATCH v3 1/3] kasan, arm64: use ARCH_SLAB_MINALIGN instead of manual aligning

2019-01-11 Thread Andrey Konovalov
On Wed, Jan 9, 2019 at 11:10 AM Vincenzo Frascino wrote: > > On 03/01/2019 18:45, Andrey Konovalov wrote: > > Instead of changing cache->align to be aligned to KASAN_SHADOW_SCALE_SIZE > > in kasan_cache_create() we can reuse the ARCH_SLAB_MINALIGN macro. > > > >

[PATCH] kasan, arm64: remove redundant ARCH_SLAB_MINALIGN define

2019-01-11 Thread Andrey Konovalov
Defining ARCH_SLAB_MINALIGN in arch/arm64/include/asm/cache.h when KASAN is off is not needed, as it is defined in defined in include/linux/slab.h as ifndef. Signed-off-by: Andrey Konovalov --- arch/arm64/include/asm/cache.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/arch/arm64

Re: [PATCH v2 1/3] kasan, arm64: use ARCH_SLAB_MINALIGN instead of manual aligning

2019-01-03 Thread Andrey Konovalov
On Wed, Jan 2, 2019 at 9:14 PM Andrew Morton wrote: > > On Wed, 2 Jan 2019 18:36:06 +0100 Andrey Konovalov > wrote: > > > Instead of changing cache->align to be aligned to KASAN_SHADOW_SCALE_SIZE > > in kasan_cache_create() we can reuse the ARCH_SLAB_MINALIGN macro

[PATCH v3 3/3] kasan: fix krealloc handling for tag-based mode

2019-01-03 Thread Andrey Konovalov
eping the same tag if the memory don't actually gets reallocated during krealloc. Signed-off-by: Andrey Konovalov --- mm/kasan/common.c | 63 --- 1 file changed, 43 insertions(+), 20 deletions(-) diff --git a/mm/kasan/common.c b/mm/kasan/comm

[PATCH v3 2/3] kasan: make tag based mode work with CONFIG_HARDENED_USERCOPY

2019-01-03 Thread Andrey Konovalov
operations. Signed-off-by: Andrey Konovalov --- mm/slub.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mm/slub.c b/mm/slub.c index 36c0befeebd8..1e3d0ec4e200 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -3846,6 +3846,8 @@ void __check_heap_object(const void *ptr, unsigned long n, struct page

[PATCH v3 0/3] kasan: tag-based mode fixes

2019-01-03 Thread Andrey Konovalov
with CONFIG_HARDENED_USERCOPY" patch. - Added "kasan: fix krealloc handling for tag-based mode" patch. Andrey Konovalov (3): kasan, arm64: use ARCH_SLAB_MINALIGN instead of manual aligning kasan: make tag based mode work with CONFIG_HARDENED_USERCOPY kasan: fix krealloc handling for tag-bas

[PATCH v3 1/3] kasan, arm64: use ARCH_SLAB_MINALIGN instead of manual aligning

2019-01-03 Thread Andrey Konovalov
Instead of changing cache->align to be aligned to KASAN_SHADOW_SCALE_SIZE in kasan_cache_create() we can reuse the ARCH_SLAB_MINALIGN macro. Suggested-by: Vincenzo Frascino Signed-off-by: Andrey Konovalov --- arch/arm64/include/asm/cache.h | 6 ++ mm/kasan/common.c | 2 --

[PATCH v2 2/3] kasan: make tag based mode work with CONFIG_HARDENED_USERCOPY

2019-01-02 Thread Andrey Konovalov
operations. Signed-off-by: Andrey Konovalov --- mm/slub.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mm/slub.c b/mm/slub.c index 36c0befeebd8..1e3d0ec4e200 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -3846,6 +3846,8 @@ void __check_heap_object(const void *ptr, unsigned long n, struct page

[PATCH v2 0/3] kasan: tag-based mode fixes

2019-01-02 Thread Andrey Konovalov
Hi Andrew, This patchset includes an updated "kasan, arm64: use ARCH_SLAB_MINALIGN instead of manual aligning" patch and fixes for two more issues that were uncovered while testing with a variety of different config options enabled. Thanks! Andrey Konovalov (3): kasan,

[PATCH v2 3/3] kasan: fix krealloc handling for tag-based mode

2019-01-02 Thread Andrey Konovalov
eping the same tag if the memory don't actually gets reallocated during krealloc. Signed-off-by: Andrey Konovalov --- include/linux/kasan.h | 14 +- include/linux/slab.h | 4 ++-- mm/kasan/common.c | 20 mm/slab.c | 8 mm/sla

[PATCH v2 1/3] kasan, arm64: use ARCH_SLAB_MINALIGN instead of manual aligning

2019-01-02 Thread Andrey Konovalov
Instead of changing cache->align to be aligned to KASAN_SHADOW_SCALE_SIZE in kasan_cache_create() we can reuse the ARCH_SLAB_MINALIGN macro. Suggested-by: Vincenzo Frascino Signed-off-by: Andrey Konovalov --- arch/arm64/include/asm/kasan.h | 4 include/linux/slab.h | 1 +

Re: [PATCH mm] kasan, arm64: use ARCH_SLAB_MINALIGN instead of manual aligning

2018-12-20 Thread Andrey Konovalov
On Tue, Dec 18, 2018 at 9:55 PM Andrew Morton wrote: > > On Tue, 18 Dec 2018 14:30:33 +0100 Andrey Konovalov > wrote: > > > Instead of changing cache->align to be aligned to KASAN_SHADOW_SCALE_SIZE > > in kasan_cache_create() we can reuse the ARCH_SLAB_MINALIGN macro

Re: [PATCH v9 0/8] arm64: untag user pointers passed to the kernel

2018-12-18 Thread Andrey Konovalov
On Wed, Dec 12, 2018 at 6:01 PM Dave Martin wrote: > > On Mon, Dec 10, 2018 at 01:50:57PM +0100, Andrey Konovalov wrote: > > arm64 has a feature called Top Byte Ignore, which allows to embed pointer > > tags into the top byte of each pointer. Userspace programs (such as &g

Re: [RFC][PATCH 0/3] arm64 relaxed ABI

2018-12-18 Thread Andrey Konovalov
On Wed, Dec 12, 2018 at 4:02 PM Catalin Marinas wrote: > > Hi Andrey, > > On Wed, Dec 12, 2018 at 03:23:25PM +0100, Andrey Konovalov wrote: > > On Mon, Dec 10, 2018 at 3:31 PM Vincenzo Frascino > > wrote: > > > On arm64 the TCR_EL1.TBI0 bit has been set since Li

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

2018-12-18 Thread Andrey Konovalov
On Mon, Dec 17, 2018 at 9:38 PM Andrew Morton wrote: > > On Mon, 17 Dec 2018 20:33:42 +0100 Andrey Konovalov > wrote: > > > > Curiosity, did you try your patches with SLUB red zoning enabled? > > > Since the area used for the Redzone is just after th

[PATCH mm] kasan, arm64: use ARCH_SLAB_MINALIGN instead of manual aligning

2018-12-18 Thread Andrey Konovalov
Instead of changing cache->align to be aligned to KASAN_SHADOW_SCALE_SIZE in kasan_cache_create() we can reuse the ARCH_SLAB_MINALIGN macro. Suggested-by: Vincenzo Frascino Signed-off-by: Andrey Konovalov --- arch/arm64/include/asm/kasan.h | 4 mm/kasan/common.c | 2 --

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

2018-12-17 Thread Andrey Konovalov
On Fri, Dec 14, 2018 at 1:34 PM Vincenzo Frascino wrote: > > On 12/12/18 3:04 PM, Andrey Konovalov wrote: > > On Tue, Dec 11, 2018 at 5:22 PM Vincenzo Frascino > > wrote: > >> > >> Hi Andrey, > >> > >> On 06/12/2018 12:24, Andrey Konovalov

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

2018-12-12 Thread Andrey Konovalov
On Tue, Dec 11, 2018 at 5:22 PM Vincenzo Frascino wrote: > > Hi Andrey, > > On 06/12/2018 12:24, Andrey Konovalov wrote: > > This commit adds tag-based KASAN specific hooks implementation and > > adjusts common generic and tag-based KASAN ones. > > > > 1. W

Re: [RFC][PATCH 0/3] arm64 relaxed ABI

2018-12-12 Thread Andrey Konovalov
m.doc.ihi0044f/IHI0044F_aaelf.pdf > SPARC ABI: http://math-atlas.sourceforge.net/devel/assembly/abi_sysV_sparc.pdf > > Cc: Catalin Marinas > Cc: Will Deacon > Cc: Mark Rutland > Cc: Robin Murphy > Cc: Kees Cook > Cc: Kate Stewart > Cc: Greg Kroah-Hartman > Cc:

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

2018-12-11 Thread Andrey Konovalov
On Tue, Dec 11, 2018 at 4:28 PM Luc Van Oostenryck wrote: > > On Thu, Dec 06, 2018 at 01:24:23PM +0100, Andrey Konovalov wrote: > > diff --git a/include/linux/compiler-clang.h b/include/linux/compiler-clang.h > > index 3e7dafb3ea80..39f668d5066b 100644 > > --- a/includ

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

2018-12-11 Thread Andrey Konovalov
On Tue, Dec 11, 2018 at 4:18 PM Will Deacon wrote: > > Hi Andrey, > > On Thu, Dec 06, 2018 at 01:24:18PM +0100, 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, >

[PATCH v9 4/8] mm, arm64: untag user addresses in mm/gup.c

2018-12-10 Thread Andrey Konovalov
for vma lookup. Signed-off-by: Andrey Konovalov --- mm/gup.c | 4 1 file changed, 4 insertions(+) diff --git a/mm/gup.c b/mm/gup.c index 8cb68a50dbdf..409aedb1e2d5 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -683,6 +683,8 @@ static long __get_user_pages(struct task_struct *tsk, struct mm_struct

[PATCH v9 3/8] arm64: untag user addresses in access_ok and __uaccess_mask_ptr

2018-12-10 Thread Andrey Konovalov
in access_ok and in __uaccess_mask_ptr, before performing access validity checks. Reviewed-by: Catalin Marinas Signed-off-by: Andrey Konovalov --- arch/arm64/include/asm/uaccess.h | 11 +++ 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/arch/arm64/include/asm/uaccess.h b

[PATCH v9 0/8] arm64: untag user pointers passed to the kernel

2018-12-10 Thread Andrey Konovalov
mm, arm64: untag user addresses in memory syscalls". - Rebased onto 3eb2ce82 (4.16-rc7). Reviewed-by: Luc Van Oostenryck Signed-off-by: Andrey Konovalov Andrey Konovalov (8): arm64: add type casts to untagged_addr macro uaccess: add untagged_addr definition for other arches arm64:

[PATCH v9 1/8] arm64: add type casts to untagged_addr macro

2018-12-10 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__. Acked-by: Catalin Marinas Signed-off-by: Andrey Konovalov --- arch/arm64/include/asm

[PATCH v9 6/8] fs, arm64: untag user address in copy_mount_options

2018-12-10 Thread Andrey Konovalov
the address before subtracting. Signed-off-by: Andrey Konovalov --- fs/namespace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/namespace.c b/fs/namespace.c index a7f91265ea67..694dcedb7e7d 100644 --- a/fs/namespace.c +++ b/fs/namespace.c @@ -2686,7 +2686,7 @@ void

[PATCH v9 7/8] arm64: update Documentation/arm64/tagged-pointers.txt

2018-12-10 Thread Andrey Konovalov
Document the changes in Documentation/arm64/tagged-pointers.txt. Signed-off-by: Andrey Konovalov --- Documentation/arm64/tagged-pointers.txt | 25 +++-- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/Documentation/arm64/tagged-pointers.txt b/Documentation

[PATCH v9 5/8] lib, arm64: untag addrs passed to strncpy_from_user and strnlen_user

2018-12-10 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 handle the case of tagged user addresses separately. Untag user pointers passed to these functions. Signed-off-by: Andrey Konovalov

[PATCH v9 2/8] uaccess: add untagged_addr definition for other arches

2018-12-10 Thread Andrey Konovalov
arm64. Acked-by: Catalin Marinas 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..42b7a4ac65e2 100644 --- a/include/linux/uaccess.h +++ b/include/linux/uaccess.h

[PATCH v9 8/8] selftests, arm64: add a selftest for passing tagged pointers to kernel

2018-12-10 Thread Andrey Konovalov
This patch adds a simple test, that calls the uname syscall with a tagged user pointer as an argument. Without the kernel accepting tagged user pointers the test fails with EFAULT. Signed-off-by: Andrey Konovalov --- tools/testing/selftests/arm64/.gitignore | 1 + tools/testing/selftests

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

2018-12-10 Thread Andrey Konovalov
On Mon, Dec 10, 2018 at 2:35 AM Paul Gortmaker wrote: > > On Thu, Dec 6, 2018 at 7:25 AM 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 >&g

Re: [PATCH v8 0/8] arm64: untag user pointers passed to the kernel

2018-12-06 Thread Andrey Konovalov
On Thu, Nov 29, 2018 at 7:16 PM Catalin Marinas wrote: > > Hi Andrey, > > On Thu, Nov 08, 2018 at 03:48:10PM +0100, Andrey Konovalov wrote: > > On Thu, Nov 8, 2018 at 3:36 PM, Andrey Konovalov > > wrote: > > > Changes in v8: > > > - Rebased onto 651022

Re: [PATCH v8 2/8] uaccess: add untagged_addr definition for other arches

2018-12-06 Thread Andrey Konovalov
On Thu, Nov 29, 2018 at 7:23 PM Catalin Marinas wrote: > > On Thu, Nov 08, 2018 at 03:36:09PM +0100, Andrey Konovalov wrote: > > diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h > > index efe79c1cdd47..c045b4eff95e 100644 > > --- a/include/linux/uaccess.h

Re: [PATCH v8 1/8] arm64: add type casts to untagged_addr macro

2018-12-06 Thread Andrey Konovalov
On Thu, Nov 29, 2018 at 7:22 PM Catalin Marinas wrote: > > On Thu, Nov 08, 2018 at 03:36:08PM +0100, Andrey Konovalov wrote: > > This patch makes the untagged_addr macro accept all kinds of address types > > (void *, unsigned long, etc.) and allows not to specify type casts

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

2018-12-06 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 v13 06/25] kasan, arm64: adjust shadow size for tag-based mode

2018-12-06 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 v13 00/25] kasan: add software tag-based mode for arm64

2018-12-06 Thread Andrey Konovalov
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 Reviewed-by: Andrey Ryabini

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

2018-12-06 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 v13 08/25] kasan: initialize shadow to 0xff for tag-based mode

2018-12-06 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 v13 09/25] arm64: move untagged_addr macro from uaccess.h to memory.h

2018-12-06 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 v13 10/25] kasan: add tag related helper functions

2018-12-06 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 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

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

2018-12-06 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 v13 11/25] kasan, arm64: untag address in _virt_addr_is_linear

2018-12-06 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 ---

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 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 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 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 +

[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

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

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 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

[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

  1   2   3   >