linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Jann Horn <jannh@google.com>
To: Vlastimil Babka <vbabka@suse.cz>
Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com>,
	Alexander Potapenko <glider@google.com>,
	 Andrey Konovalov <andreyknvl@gmail.com>,
	Dmitry Vyukov <dvyukov@google.com>,
	 Vincenzo Frascino <vincenzo.frascino@arm.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	 kasan-dev@googlegroups.com, linux-mm@kvack.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] kasan: add test for SLAB_TYPESAFE_BY_RCU quarantine skipping
Date: Tue, 29 Jul 2025 18:35:03 +0200	[thread overview]
Message-ID: <CAG48ez2O4OvhKjdy=Y6fzuK0Qf79JQXCXV=uQV2ED08fS1RNpA@mail.gmail.com> (raw)
In-Reply-To: <6aeb9c5d-7c3f-4c0c-989f-df309267ffbe@suse.cz>

On Tue, Jul 29, 2025 at 6:14 PM Vlastimil Babka <vbabka@suse.cz> wrote:
> On 7/28/25 17:25, Jann Horn wrote:
> > Verify that KASAN does not quarantine objects in SLAB_TYPESAFE_BY_RCU slabs
> > if CONFIG_SLUB_RCU_DEBUG is off.
> >
> > Suggested-by: Andrey Konovalov <andreyknvl@gmail.com>
> > Signed-off-by: Jann Horn <jannh@google.com>
> > ---
> > Feel free to either take this as a separate commit or squash it into the
> > preceding "[PATCH] kasan: skip quarantine if object is still accessible
> > under RCU".
> >
> > I tested this by running KASAN kunit tests for x86-64 with KASAN
> > and tracing manually enabled; there are two failing tests but those
> > seem unrelated (kasan_memchr is unexpectedly not detecting some
> > accesses, and kasan_strings is also failing).
> > ---
> >  mm/kasan/kasan_test_c.c | 36 ++++++++++++++++++++++++++++++++++++
> >  1 file changed, 36 insertions(+)
> >
> > diff --git a/mm/kasan/kasan_test_c.c b/mm/kasan/kasan_test_c.c
> > index 5f922dd38ffa..15d3d82041bf 100644
> > --- a/mm/kasan/kasan_test_c.c
> > +++ b/mm/kasan/kasan_test_c.c
> > @@ -1073,6 +1073,41 @@ static void kmem_cache_rcu_uaf(struct kunit *test)
> >       kmem_cache_destroy(cache);
> >  }
> >
> > +/*
> > + * Check that SLAB_TYPESAFE_BY_RCU objects are immediately reused when
> > + * CONFIG_SLUB_RCU_DEBUG is off, and stay at the same address.
> > + */
> > +static void kmem_cache_rcu_reuse(struct kunit *test)
> > +{
> > +     char *p, *p2;
> > +     struct kmem_cache *cache;
> > +
> > +     KASAN_TEST_NEEDS_CONFIG_OFF(test, CONFIG_SLUB_RCU_DEBUG);
> > +
> > +     cache = kmem_cache_create("test_cache", 16, 0, SLAB_TYPESAFE_BY_RCU,
> > +                               NULL);
> > +     KUNIT_ASSERT_NOT_ERR_OR_NULL(test, cache);
>
> Hmm is there anything inherent in kunit that keeps the test pinned to the
> same cpu? Otherwise I think you'll need here
>
> migrate_disable();

Oops, right, good point.

> > +     p = kmem_cache_alloc(cache, GFP_KERNEL);
> > +     if (!p) {
> > +             kunit_err(test, "Allocation failed: %s\n", __func__);
> > +             kmem_cache_destroy(cache);
> > +             return;
> > +     }
> > +
> > +     kmem_cache_free(cache, p);
> > +     p2 = kmem_cache_alloc(cache, GFP_KERNEL);
>
> and here (or later)
>
> migrate_enable();
>
> > +     if (!p2) {
> > +             kunit_err(test, "Allocation failed: %s\n", __func__);
> > +             kmem_cache_destroy(cache);
> > +             return;
> > +     }
> > +     KUNIT_ASSERT_PTR_EQ(test, p, p2);
>
> Otherwise the cpu slab caching of SLUB and a migration could mean this won't
> hold as you'll get object from another slab.

Yeah...


      reply	other threads:[~2025-07-29 16:35 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-28 15:25 Jann Horn
2025-07-29 16:14 ` Vlastimil Babka
2025-07-29 16:35   ` Jann Horn [this message]

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='CAG48ez2O4OvhKjdy=Y6fzuK0Qf79JQXCXV=uQV2ED08fS1RNpA@mail.gmail.com' \
    --to=jannh@google.com \
    --cc=akpm@linux-foundation.org \
    --cc=andreyknvl@gmail.com \
    --cc=dvyukov@google.com \
    --cc=glider@google.com \
    --cc=kasan-dev@googlegroups.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ryabinin.a.a@gmail.com \
    --cc=vbabka@suse.cz \
    --cc=vincenzo.frascino@arm.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