From: Feng Tang <feng.tang@intel.com>
To: Vlastimil Babka <vbabka@suse.cz>
Cc: Marco Elver <elver@google.com>,
Andrew Morton <akpm@linux-foundation.org>,
Oliver Glitta <glittao@gmail.com>,
Christoph Lameter <cl@linux.com>,
"Pekka Enberg" <penberg@kernel.org>,
David Rientjes <rientjes@google.com>,
"Joonsoo Kim" <iamjoonsoo.kim@lge.com>,
Roman Gushchin <roman.gushchin@linux.dev>,
Hyeonggon Yoo <42.hyeyoo@gmail.com>, <linux-mm@kvack.org>,
<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v3 2/2] mm/slub, kunit: Add a test case for kmalloc redzone check
Date: Thu, 1 Dec 2022 14:02:40 +0800 [thread overview]
Message-ID: <Y4hDgEh2PP/SJDKu@feng-clx> (raw)
In-Reply-To: <b98a61ae-da11-00c0-60a9-30a3c043f761@suse.cz>
On Thu, Dec 01, 2022 at 12:05:41AM +0100, Vlastimil Babka wrote:
[...]
> > diff --git a/lib/slub_kunit.c b/lib/slub_kunit.c
> > index 5b0c8e7eb6dc..ff24879e3afe 100644
> > --- a/lib/slub_kunit.c
> > +++ b/lib/slub_kunit.c
> > @@ -135,6 +135,27 @@ static void test_clobber_redzone_free(struct kunit *test)
> > kmem_cache_destroy(s);
> > }
> >
> > +static void test_kmalloc_redzone_access(struct kunit *test)
> > +{
> > + struct kmem_cache *s = test_kmem_cache_create("TestSlub_RZ_kmalloc", 32,
> > + SLAB_KMALLOC|SLAB_STORE_USER|SLAB_RED_ZONE);
> > + u8 *p = kmalloc_trace(s, GFP_KERNEL, 18);
> > +
> > + kasan_disable_current();
> > +
> > + /* Suppress the -Warray-bounds warning */
> > + OPTIMIZER_HIDE_VAR(p);
> > + p[18] = 0xab;
> > + p[19] = 0xab;
> > +
> > + kmem_cache_free(s, p);
> > + validate_slab_cache(s);
> > + KUNIT_EXPECT_EQ(test, 2, slab_errors);
>
> With this ordering the expectation was failing as slab_Errors was 0, had to
> fix it up to look more like TestSlub_RZ_alloc:
Thanks for the catch and fix!
I checked why it worked in my test, and it should be related with
kasan. My test environment has both kasan and kfence enabled, and
kasan could delay the object freeing, and with the original code,
when validate_slab_cache() is called, the object is not freed yet
and gets redzone-checked.
> > + kasan_enable_current();
> > + kmem_cache_destroy(s);
> > +}
> > +
>
> --- a/lib/slub_kunit.c
> +++ b/lib/slub_kunit.c
> @@ -148,11 +148,11 @@ static void test_kmalloc_redzone_access(struct kunit *test)
> p[18] = 0xab;
> p[19] = 0xab;
>
> - kmem_cache_free(s, p);
> validate_slab_cache(s);
> KUNIT_EXPECT_EQ(test, 2, slab_errors);
>
> kasan_enable_current();
> + kmem_cache_free(s, p);
> kmem_cache_destroy(s);
> }
>
> With that, added both to slab.git branch slab/for-6.2/kmalloc_redzone
> Thanks!
Thanks!
- Feng
next prev parent reply other threads:[~2022-12-01 6:05 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-30 8:54 [PATCH v3 1/2] mm/slub, kunit: add SLAB_SKIP_KFENCE flag for cache creation Feng Tang
2022-11-30 8:54 ` [PATCH v3 2/2] mm/slub, kunit: Add a test case for kmalloc redzone check Feng Tang
2022-11-30 9:50 ` Hyeonggon Yoo
2022-11-30 23:05 ` Vlastimil Babka
2022-12-01 6:02 ` Feng Tang [this message]
2022-11-30 9:06 ` [PATCH v3 1/2] mm/slub, kunit: add SLAB_SKIP_KFENCE flag for cache creation Marco Elver
2022-11-30 9:25 ` Hyeonggon Yoo
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=Y4hDgEh2PP/SJDKu@feng-clx \
--to=feng.tang@intel.com \
--cc=42.hyeyoo@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=cl@linux.com \
--cc=elver@google.com \
--cc=glittao@gmail.com \
--cc=iamjoonsoo.kim@lge.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=penberg@kernel.org \
--cc=rientjes@google.com \
--cc=roman.gushchin@linux.dev \
--cc=vbabka@suse.cz \
/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