From: Peter Zijlstra <peterz@infradead.org>
To: Dmitry Vyukov <dvyukov@google.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Andrey Ryabinin <aryabinin@virtuozzo.com>,
Ingo Molnar <mingo@redhat.com>,
kasan-dev <kasan-dev@googlegroups.com>,
"linux-mm@kvack.org" <linux-mm@kvack.org>,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] x86, kasan: add KASAN checks to atomic operations
Date: Mon, 6 Mar 2017 13:58:51 +0100 [thread overview]
Message-ID: <20170306125851.GL6500@twins.programming.kicks-ass.net> (raw)
In-Reply-To: <CACT4Y+YmpTMdJca-rE2nXR-qa=wn_bCqQXaRghtg1uC65-pKyA@mail.gmail.com>
On Mon, Mar 06, 2017 at 01:50:47PM +0100, Dmitry Vyukov wrote:
> On Mon, Mar 6, 2017 at 1:42 PM, Dmitry Vyukov <dvyukov@google.com> wrote:
> > KASAN uses compiler instrumentation to intercept all memory accesses.
> > But it does not see memory accesses done in assembly code.
> > One notable user of assembly code is atomic operations. Frequently,
> > for example, an atomic reference decrement is the last access to an
> > object and a good candidate for a racy use-after-free.
> >
> > Add manual KASAN checks to atomic operations.
> > Note: we need checks only before asm blocks and don't need them
> > in atomic functions composed of other atomic functions
> > (e.g. load-cmpxchg loops).
>
> Peter, also pointed me at arch/x86/include/asm/bitops.h. Will add them in v2.
>
> > static __always_inline void atomic_add(int i, atomic_t *v)
> > {
> > + kasan_check_write(v, sizeof(*v));
> > asm volatile(LOCK_PREFIX "addl %1,%0"
> > : "+m" (v->counter)
> > : "ir" (i));
So the problem is doing load/stores from asm bits, and GCC
(traditionally) doesn't try and interpret APP asm bits.
However, could we not write a GCC plugin that does exactly that?
Something that interprets the APP asm bits and generates these KASAN
bits that go with it?
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
WARNING: multiple messages have this Message-ID (diff)
From: Peter Zijlstra <peterz@infradead.org>
To: Dmitry Vyukov <dvyukov@google.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Andrey Ryabinin <aryabinin@virtuozzo.com>,
Ingo Molnar <mingo@redhat.com>,
kasan-dev <kasan-dev@googlegroups.com>,
"linux-mm@kvack.org" <linux-mm@kvack.org>,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] x86, kasan: add KASAN checks to atomic operations
Date: Mon, 6 Mar 2017 13:58:51 +0100 [thread overview]
Message-ID: <20170306125851.GL6500@twins.programming.kicks-ass.net> (raw)
In-Reply-To: <CACT4Y+YmpTMdJca-rE2nXR-qa=wn_bCqQXaRghtg1uC65-pKyA@mail.gmail.com>
On Mon, Mar 06, 2017 at 01:50:47PM +0100, Dmitry Vyukov wrote:
> On Mon, Mar 6, 2017 at 1:42 PM, Dmitry Vyukov <dvyukov@google.com> wrote:
> > KASAN uses compiler instrumentation to intercept all memory accesses.
> > But it does not see memory accesses done in assembly code.
> > One notable user of assembly code is atomic operations. Frequently,
> > for example, an atomic reference decrement is the last access to an
> > object and a good candidate for a racy use-after-free.
> >
> > Add manual KASAN checks to atomic operations.
> > Note: we need checks only before asm blocks and don't need them
> > in atomic functions composed of other atomic functions
> > (e.g. load-cmpxchg loops).
>
> Peter, also pointed me at arch/x86/include/asm/bitops.h. Will add them in v2.
>
> > static __always_inline void atomic_add(int i, atomic_t *v)
> > {
> > + kasan_check_write(v, sizeof(*v));
> > asm volatile(LOCK_PREFIX "addl %1,%0"
> > : "+m" (v->counter)
> > : "ir" (i));
So the problem is doing load/stores from asm bits, and GCC
(traditionally) doesn't try and interpret APP asm bits.
However, could we not write a GCC plugin that does exactly that?
Something that interprets the APP asm bits and generates these KASAN
bits that go with it?
next prev parent reply other threads:[~2017-03-06 12:58 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-06 12:42 [PATCH] x86, kasan: add KASAN checks to atomic operations Dmitry Vyukov
2017-03-06 12:42 ` Dmitry Vyukov
2017-03-06 12:50 ` Dmitry Vyukov
2017-03-06 12:50 ` Dmitry Vyukov
2017-03-06 12:58 ` Peter Zijlstra [this message]
2017-03-06 12:58 ` Peter Zijlstra
2017-03-06 13:01 ` Peter Zijlstra
2017-03-06 13:01 ` Peter Zijlstra
2017-03-06 14:24 ` Dmitry Vyukov
2017-03-06 14:24 ` Dmitry Vyukov
2017-03-06 15:20 ` Peter Zijlstra
2017-03-06 15:20 ` Peter Zijlstra
2017-03-06 16:04 ` Mark Rutland
2017-03-06 16:04 ` Mark Rutland
2017-03-06 15:33 ` Peter Zijlstra
2017-03-06 15:33 ` Peter Zijlstra
2017-03-06 16:20 ` Mark Rutland
2017-03-06 16:20 ` Mark Rutland
2017-03-06 16:27 ` Dmitry Vyukov
2017-03-06 16:27 ` Dmitry Vyukov
2017-03-06 17:25 ` Mark Rutland
2017-03-06 17:25 ` Mark Rutland
2017-03-06 20:35 ` Peter Zijlstra
2017-03-06 20:35 ` Peter Zijlstra
2017-03-08 13:42 ` Dmitry Vyukov
2017-03-08 15:20 ` Mark Rutland
2017-03-08 15:20 ` Mark Rutland
2017-03-08 15:27 ` Dmitry Vyukov
2017-03-08 15:27 ` Dmitry Vyukov
2017-03-08 15:43 ` Mark Rutland
2017-03-08 15:43 ` Mark Rutland
2017-03-08 15:45 ` Dmitry Vyukov
2017-03-08 15:45 ` Dmitry Vyukov
2017-03-08 15:48 ` Mark Rutland
2017-03-08 15:48 ` Mark Rutland
2017-03-08 17:43 ` Will Deacon
2017-03-08 17:43 ` Will Deacon
2017-03-14 15:22 ` Dmitry Vyukov
2017-03-14 15:31 ` Peter Zijlstra
2017-03-14 15:31 ` Peter Zijlstra
2017-03-14 15:32 ` Peter Zijlstra
2017-03-14 15:32 ` Peter Zijlstra
2017-03-14 15:44 ` Mark Rutland
2017-03-14 15:44 ` Mark Rutland
2017-03-14 19:25 ` Dmitry Vyukov
2017-03-14 19:25 ` Dmitry Vyukov
2017-03-06 16:48 ` Andrey Ryabinin
2017-03-06 16:48 ` 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=20170306125851.GL6500@twins.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=akpm@linux-foundation.org \
--cc=aryabinin@virtuozzo.com \
--cc=dvyukov@google.com \
--cc=kasan-dev@googlegroups.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mingo@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.