From: Andrew Morton <akpm@linux-foundation.org>
To: andrey.konovalov@linux.dev
Cc: Marco Elver <elver@google.com>,
Andrey Konovalov <andreyknvl@gmail.com>,
Alexander Potapenko <glider@google.com>,
Dmitry Vyukov <dvyukov@google.com>,
Andrey Ryabinin <ryabinin.a.a@gmail.com>,
kasan-dev@googlegroups.com, linux-mm@kvack.org,
Kees Cook <keescook@chromium.org>,
linux-kernel@vger.kernel.org,
Andrey Konovalov <andreyknvl@google.com>,
kernel test robot <lkp@intel.com>
Subject: Re: [PATCH mm v2] kasan: fix array-bounds warnings in tests
Date: Sun, 25 Sep 2022 10:03:12 -0700 [thread overview]
Message-ID: <20220925100312.6bfecb122b314862ad7b2dd4@linux-foundation.org> (raw)
In-Reply-To: <9c0210393a8da6fb6887a111a986eb50dfc1b895.1664050880.git.andreyknvl@google.com>
On Sat, 24 Sep 2022 22:23:21 +0200 andrey.konovalov@linux.dev wrote:
> From: Andrey Konovalov <andreyknvl@google.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
next prev parent reply other threads:[~2022-09-25 17:03 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-24 20:23 andrey.konovalov
2022-09-25 17:03 ` Andrew Morton [this message]
2022-09-26 18:07 ` Andrey Konovalov
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=20220925100312.6bfecb122b314862ad7b2dd4@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=andrey.konovalov@linux.dev \
--cc=andreyknvl@gmail.com \
--cc=andreyknvl@google.com \
--cc=dvyukov@google.com \
--cc=elver@google.com \
--cc=glider@google.com \
--cc=kasan-dev@googlegroups.com \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lkp@intel.com \
--cc=ryabinin.a.a@gmail.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