lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Sun, 25 Sep 2022 10:03:12 -0700
From:   Andrew Morton <akpm@...ux-foundation.org>
To:     andrey.konovalov@...ux.dev
Cc:     Marco Elver <elver@...gle.com>,
        Andrey Konovalov <andreyknvl@...il.com>,
        Alexander Potapenko <glider@...gle.com>,
        Dmitry Vyukov <dvyukov@...gle.com>,
        Andrey Ryabinin <ryabinin.a.a@...il.com>,
        kasan-dev@...glegroups.com, linux-mm@...ck.org,
        Kees Cook <keescook@...omium.org>,
        linux-kernel@...r.kernel.org,
        Andrey Konovalov <andreyknvl@...gle.com>,
        kernel test robot <lkp@...el.com>
Subject: Re: [PATCH mm v2] kasan: fix array-bounds warnings in tests

On Sat, 24 Sep 2022 22:23:21 +0200 andrey.konovalov@...ux.dev wrote:

> From: Andrey Konovalov <andreyknvl@...gle.com>
> 
> GCC's -Warray-bounds option detects out-of-bounds accesses to
> statically-sized allocations in krealloc out-of-bounds tests.
> 
> Use OPTIMIZER_HIDE_VAR to suppress the warning.
> 
> Also change kmalloc_memmove_invalid_size to use OPTIMIZER_HIDE_VAR
> instead of a volatile variable.
> 
> ...
>
> --- a/mm/kasan/kasan_test.c
> +++ b/mm/kasan/kasan_test.c
> @@ -333,6 +333,8 @@ static void krealloc_more_oob_helper(struct kunit *test,
>  	ptr2 = krealloc(ptr1, size2, GFP_KERNEL);
>  	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr2);
>  
> +	OPTIMIZER_HIDE_VAR(ptr2);
> +
>  	/* All offsets up to size2 must be accessible. */
>  	ptr2[size1 - 1] = 'x';
>  	ptr2[size1] = 'x';
> @@ -365,6 +367,8 @@ static void krealloc_less_oob_helper(struct kunit *test,
>  	ptr2 = krealloc(ptr1, size2, GFP_KERNEL);
>  	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr2);
>  
> +	OPTIMIZER_HIDE_VAR(ptr2);

What chance does a reader have of working out why this is here?  If
"little" then a code comment would be a nice way of saving that poor
person for having to dive into the git history.


>  	/* Must be accessible for all modes. */
>  	ptr2[size2 - 1] = 'x';
>  
> @@ -578,13 +582,14 @@ static void kmalloc_memmove_invalid_size(struct kunit *test)
>  {
>  	char *ptr;
>  	size_t size = 64;
> -	volatile size_t invalid_size = size;
> +	size_t invalid_size = size;
>  
>  	ptr = kmalloc(size, GFP_KERNEL);
>  	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr);
>  
>  	memset((char *)ptr, 0, 64);
>  	OPTIMIZER_HIDE_VAR(ptr);
> +	OPTIMIZER_HIDE_VAR(invalid_size);
>  	KUNIT_EXPECT_KASAN_FAIL(test,
>  		memmove((char *)ptr, (char *)ptr + 4, invalid_size));
>  	kfree(ptr);
> -- 
> 2.25.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ