From: Mark Rutland <mark.rutland@arm.com>
To: Kees Cook <keescook@chromium.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Andrey Ryabinin <ryabinin.a.a@gmail.com>,
Alexander Potapenko <glider@google.com>,
Andrey Konovalov <andreyknvl@gmail.com>,
Dmitry Vyukov <dvyukov@google.com>,
kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org,
linux-hardening@vger.kernel.org
Subject: Re: [PATCH] kasan: test: Bypass __alloc_size checks
Date: Wed, 6 Oct 2021 12:38:36 +0100 [thread overview]
Message-ID: <20211006113732.GA14159@C02TD0UTHF1T.local> (raw)
In-Reply-To: <20211006035522.539346-1-keescook@chromium.org>
Hi Kees,
On Tue, Oct 05, 2021 at 08:55:22PM -0700, Kees Cook wrote:
> Intentional overflows, as performed by the KASAN tests, are detected
> at compile time[1] (instead of only at run-time) with the addition of
> __alloc_size. Fix this by forcing the compiler into not being able to
> trust the size used following the kmalloc()s.
It might be better to use OPTIMIZER_HIDE_VAR(), since that's intended to
make the value opaque to the compiler, and volatile might not always do
that depending on how the compiler tracks the variable.
Thanks,
Mark.
>
> [1] https://lore.kernel.org/lkml/20211005184717.65c6d8eb39350395e387b71f@linux-foundation.org
>
> Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com>
> Cc: Alexander Potapenko <glider@google.com>
> Cc: Andrey Konovalov <andreyknvl@gmail.com>
> Cc: Dmitry Vyukov <dvyukov@google.com>
> Cc: kasan-dev@googlegroups.com
> Signed-off-by: Kees Cook <keescook@chromium.org>
> ---
> lib/test_kasan.c | 10 +++++-----
> lib/test_kasan_module.c | 2 +-
> 2 files changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/lib/test_kasan.c b/lib/test_kasan.c
> index 8835e0784578..0e1f8d5281b4 100644
> --- a/lib/test_kasan.c
> +++ b/lib/test_kasan.c
> @@ -435,7 +435,7 @@ static void kmalloc_uaf_16(struct kunit *test)
> static void kmalloc_oob_memset_2(struct kunit *test)
> {
> char *ptr;
> - size_t size = 128 - KASAN_GRANULE_SIZE;
> + volatile size_t size = 128 - KASAN_GRANULE_SIZE;
>
> ptr = kmalloc(size, GFP_KERNEL);
> KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr);
> @@ -447,7 +447,7 @@ static void kmalloc_oob_memset_2(struct kunit *test)
> static void kmalloc_oob_memset_4(struct kunit *test)
> {
> char *ptr;
> - size_t size = 128 - KASAN_GRANULE_SIZE;
> + volatile size_t size = 128 - KASAN_GRANULE_SIZE;
>
> ptr = kmalloc(size, GFP_KERNEL);
> KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr);
> @@ -459,7 +459,7 @@ static void kmalloc_oob_memset_4(struct kunit *test)
> static void kmalloc_oob_memset_8(struct kunit *test)
> {
> char *ptr;
> - size_t size = 128 - KASAN_GRANULE_SIZE;
> + volatile size_t size = 128 - KASAN_GRANULE_SIZE;
>
> ptr = kmalloc(size, GFP_KERNEL);
> KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr);
> @@ -471,7 +471,7 @@ static void kmalloc_oob_memset_8(struct kunit *test)
> static void kmalloc_oob_memset_16(struct kunit *test)
> {
> char *ptr;
> - size_t size = 128 - KASAN_GRANULE_SIZE;
> + volatile size_t size = 128 - KASAN_GRANULE_SIZE;
>
> ptr = kmalloc(size, GFP_KERNEL);
> KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr);
> @@ -483,7 +483,7 @@ static void kmalloc_oob_memset_16(struct kunit *test)
> static void kmalloc_oob_in_memset(struct kunit *test)
> {
> char *ptr;
> - size_t size = 128 - KASAN_GRANULE_SIZE;
> + volatile size_t size = 128 - KASAN_GRANULE_SIZE;
>
> ptr = kmalloc(size, GFP_KERNEL);
> KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr);
> diff --git a/lib/test_kasan_module.c b/lib/test_kasan_module.c
> index 7ebf433edef3..c8cc77b1dcf3 100644
> --- a/lib/test_kasan_module.c
> +++ b/lib/test_kasan_module.c
> @@ -19,7 +19,7 @@ static noinline void __init copy_user_test(void)
> {
> char *kmem;
> char __user *usermem;
> - size_t size = 128 - KASAN_GRANULE_SIZE;
> + volatile size_t size = 128 - KASAN_GRANULE_SIZE;
> int __maybe_unused unused;
>
> kmem = kmalloc(size, GFP_KERNEL);
> --
> 2.30.2
>
next prev parent reply other threads:[~2021-10-06 11:38 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-06 3:55 [PATCH] kasan: test: Bypass __alloc_size checks Kees Cook
2021-10-06 11:38 ` Mark Rutland [this message]
2021-10-06 16:33 ` Kees Cook
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=20211006113732.GA14159@C02TD0UTHF1T.local \
--to=mark.rutland@arm.com \
--cc=akpm@linux-foundation.org \
--cc=andreyknvl@gmail.com \
--cc=dvyukov@google.com \
--cc=glider@google.com \
--cc=kasan-dev@googlegroups.com \
--cc=keescook@chromium.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--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