From: "Luruo, Kuthonuzo" <kuthonuzo.luruo@hpe.com>
To: Alexander Potapenko <glider@google.com>
Cc: Andrey Ryabinin <aryabinin@virtuozzo.com>,
Dmitriy Vyukov <dvyukov@google.com>,
Christoph Lameter <cl@linux.com>,
"penberg@kernel.org" <penberg@kernel.org>,
David Rientjes <rientjes@google.com>,
Joonsoo Kim <iamjoonsoo.kim@lge.com>,
Andrew Morton <akpm@linux-foundation.org>,
kasan-dev <kasan-dev@googlegroups.com>,
LKML <linux-kernel@vger.kernel.org>,
"ynorov@caviumnetworks.com" <ynorov@caviumnetworks.com>
Subject: RE: [PATCH v5 1/2] mm, kasan: improve double-free detection
Date: Thu, 9 Jun 2016 16:54:57 +0000 [thread overview]
Message-ID: <DF4PR84MB0089ACE8F082A1293A7BACACF45F0@DF4PR84MB0089.NAMPRD84.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <CAG_fn=XAcDZt8dE57KRnHXWEWmLgx=SGG==qcBhWdULuVV86iA@mail.gmail.com>
> > Currently, KASAN may fail to detect concurrent deallocations of the same
> > object due to a race in kasan_slab_free(). This patch makes double-free
> > detection more reliable by serializing access to KASAN object metadata.
> > New functions kasan_meta_lock() and kasan_meta_unlock() are provided to
> > lock/unlock per-object metadata. Double-free errors are now reported via
> > kasan_report().
> >
> > Per-object lock concept from suggestion/observations by Dmitry Vyukov.
> Note I've sent out a patch that enables stackdepot support in SLUB.
> I'll probably need to wait till you patch lands and add locking to SLUB as well.
My patch can wait; It can be rebased and resent for consideration by
maintainers/reviewers after your patch has been reviewed.
> > +void kasan_init_object(struct kmem_cache *cache, void *object)
> > +{
> > + if (cache->flags & SLAB_KASAN) {
> > + struct kasan_alloc_meta *allocp = get_alloc_info(cache, object);
> > + union kasan_shadow_meta *shadow_meta =
> get_shadow_meta(allocp);
> > +
> > + __memset(allocp, 0, sizeof(*allocp));
> I think we need initialize the lock first, then lock it in order to
> touch *allocp.
> > + shadow_meta->data = KASAN_KMALLOC_META;
> Shouldn't this be a release store?
Object at this point is being initialized by SLAB off a newly allocated page/slab.
Concurrent access to the embryonic object is unlikely/not expected. I don't
think locking here is of any benefit...
> > default:
> > + pr_err("invalid allocation state!\n");
> I suggest you also print the object pointer here.
ok.
> > +
> > struct kasan_alloc_meta {
> > + u32 alloc_size : 24;
> Why reduce the alloc size?
Thought to save some bits while still accounting for max object size
instrumented by KASAN. But now, with the spectre of OOB writes,
header real estate suddenly seems a lot less valuable ;-). A reset to
u32 won’t be inappropriate.
> > if (!(cache->flags & SLAB_KASAN))
> > return;
> > - switch (alloc_info->state) {
> > + if (info->access_size)
> > + kasan_meta_lock(alloc_info);
> In which case can info->access_size be zero? Guess even in that case
> we need to lock the metadata.
For a double-free error, access size is zero and lock is already held.
Thank you very much for reviewing the patch!
Kuthonuzo
next prev parent reply other threads:[~2016-06-09 17:09 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-07 18:03 Kuthonuzo Luruo
2016-06-09 13:32 ` Alexander Potapenko
2016-06-09 16:54 ` Luruo, Kuthonuzo [this message]
2016-06-09 17:00 ` Andrey Ryabinin
2016-06-10 17:03 ` Andrey Ryabinin
2016-06-10 17:09 ` Dmitry Vyukov
2016-06-15 16:18 ` Andrey Ryabinin
2016-06-13 11:56 ` Alexander Potapenko
2016-06-14 6:46 ` Luruo, Kuthonuzo
2016-06-15 16:38 ` Andrey Ryabinin
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=DF4PR84MB0089ACE8F082A1293A7BACACF45F0@DF4PR84MB0089.NAMPRD84.PROD.OUTLOOK.COM \
--to=kuthonuzo.luruo@hpe.com \
--cc=akpm@linux-foundation.org \
--cc=aryabinin@virtuozzo.com \
--cc=cl@linux.com \
--cc=dvyukov@google.com \
--cc=glider@google.com \
--cc=iamjoonsoo.kim@lge.com \
--cc=kasan-dev@googlegroups.com \
--cc=linux-kernel@vger.kernel.org \
--cc=penberg@kernel.org \
--cc=rientjes@google.com \
--cc=ynorov@caviumnetworks.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
Powered by JetHome