linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Axtens <dja@axtens.net>
To: Dmitry Vyukov <dvyukov@google.com>
Cc: LKML <linux-kernel@vger.kernel.org>,
	Linux-MM <linux-mm@kvack.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	kasan-dev <kasan-dev@googlegroups.com>,
	Christophe Leroy <christophe.leroy@c-s.fr>,
	Andrey Ryabinin <aryabinin@virtuozzo.com>,
	Alexander Potapenko <glider@google.com>
Subject: Re: [PATCH v3 3/3] kasan: initialise array in kasan_memcmp test
Date: Sat, 25 Apr 2020 00:37:04 +1000	[thread overview]
Message-ID: <877dy5t0fj.fsf@dja-thinkpad.axtens.net> (raw)
In-Reply-To: <CACT4Y+b7omyQ0bBBApOs5O_m0MDZWjoBi3QV6MxG4h_14gUa2g@mail.gmail.com>

Dmitry Vyukov <dvyukov@google.com> writes:

> On Thu, Apr 23, 2020 at 5:45 PM Daniel Axtens <dja@axtens.net> wrote:
>>
>> memcmp may bail out before accessing all the memory if the buffers
>> contain differing bytes. kasan_memcmp calls memcmp with a stack array.
>> Stack variables are not necessarily initialised (in the absence of a
>> compiler plugin, at least). Sometimes this causes the memcpy to bail
>> early thus fail to trigger kasan.
>>
>> Make sure the array initialised to zero in the code.
>>
>> No other test is dependent on the contents of an array on the stack.
>>
>> Cc: Andrey Ryabinin <aryabinin@virtuozzo.com>
>> Cc: Alexander Potapenko <glider@google.com>
>> Cc: Dmitry Vyukov <dvyukov@google.com>
>> Signed-off-by: Daniel Axtens <dja@axtens.net>
>> Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
>> ---
>>  lib/test_kasan.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/lib/test_kasan.c b/lib/test_kasan.c
>> index 939f395a5392..7700097842c8 100644
>> --- a/lib/test_kasan.c
>> +++ b/lib/test_kasan.c
>> @@ -638,7 +638,7 @@ static noinline void __init kasan_memcmp(void)
>>  {
>>         char *ptr;
>>         size_t size = 24;
>> -       int arr[9];
>> +       int arr[9] = {};
>>
>>         pr_info("out-of-bounds in memcmp\n");
>>         ptr = kmalloc(size, GFP_KERNEL | __GFP_ZERO);
>
> My version of this function contains the following below:
>
> memset(arr, 0, sizeof(arr));
>
> What am I missing?

Ah! It turns out I accidentally removed the memset in patch 1. No idea
why I did that. I'll fix up patch 1 to not remove the memset and drop
this patch.

Daniel


  reply	other threads:[~2020-04-24 14:37 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-23 15:45 [PATCH v3 0/3] Fix some incompatibilites between KASAN and FORTIFY_SOURCE Daniel Axtens
2020-04-23 15:45 ` [PATCH v3 1/3] kasan: stop tests being eliminated as dead code with FORTIFY_SOURCE Daniel Axtens
2020-04-23 15:45 ` [PATCH v3 2/3] string.h: fix incompatibility between FORTIFY_SOURCE and KASAN Daniel Axtens
2020-04-23 15:45 ` [PATCH v3 3/3] kasan: initialise array in kasan_memcmp test Daniel Axtens
2020-04-23 17:25   ` Dmitry Vyukov
2020-04-24 14:37     ` Daniel Axtens [this message]
2020-04-24  6:54 ` [PATCH v3 0/3] Fix some incompatibilites between KASAN and FORTIFY_SOURCE David Gow

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=877dy5t0fj.fsf@dja-thinkpad.axtens.net \
    --to=dja@axtens.net \
    --cc=akpm@linux-foundation.org \
    --cc=aryabinin@virtuozzo.com \
    --cc=christophe.leroy@c-s.fr \
    --cc=dvyukov@google.com \
    --cc=glider@google.com \
    --cc=kasan-dev@googlegroups.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --subject='Re: [PATCH v3 3/3] kasan: initialise array in kasan_memcmp test' \
    /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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).