From: Peter Zijlstra <peterz@infradead.org>
To: Kees Cook <keescook@chromium.org>
Cc: linux-kernel@vger.kernel.org, Eric Biggers <ebiggers3@gmail.com>,
Christoph Hellwig <hch@infradead.org>,
"axboe@kernel.dk" <axboe@kernel.dk>,
James Bottomley <James.Bottomley@hansenpartnership.com>,
Elena Reshetova <elena.reshetova@intel.com>,
Hans Liljestrand <ishkamiel@gmail.com>,
David Windsor <dwindsor@gmail.com>,
x86@kernel.org, Ingo Molnar <mingo@kernel.org>,
Arnd Bergmann <arnd@arndb.de>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Jann Horn <jann@thejh.net>,
davem@davemloft.net, linux-arch@vger.kernel.org,
kernel-hardening@lists.openwall.com,
PaX Team <pageexec@freemail.hu>
Subject: Re: [PATCH] x86/refcount: Implement fast refcount_t handling
Date: Tue, 25 Apr 2017 12:23:37 +0200 [thread overview]
Message-ID: <20170425102337.ocdi2v7ivue7x7cc@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <20170421220939.GA65363@beast>
On Fri, Apr 21, 2017 at 03:09:39PM -0700, Kees Cook wrote:
> +static __always_inline void refcount_inc(refcount_t *r)
> +{
> + asm volatile(LOCK_PREFIX "incl %0\n\t"
> + REFCOUNT_CHECK_OVERFLOW(4)
> + : [counter] "+m" (r->refs.counter)
> + : : "cc", "cx");
> +}
> +
> +static __always_inline void refcount_dec(refcount_t *r)
> +{
> + asm volatile(LOCK_PREFIX "decl %0\n\t"
> + REFCOUNT_CHECK_UNDERFLOW(4)
> + : [counter] "+m" (r->refs.counter)
> + : : "cc", "cx");
> +}
> +dotraplinkage void do_refcount_error(struct pt_regs *regs, long error_code)
> +{
> + const char *str = NULL;
> +
> + BUG_ON(!(regs->flags & X86_EFLAGS_OF));
> +
> +#define range_check(size, direction, type, value) \
> + if ((unsigned long)__##size##_##direction##_start <= regs->ip && \
> + regs->ip < (unsigned long)__##size##_##direction##_end) { \
> + *(type *)regs->cx = value; \
> + str = #size " " #direction; \
> + }
> +
> + range_check(refcount, overflow, int, INT_MAX)
> + range_check(refcount, underflow, int, INT_MIN)
> +
> +#undef range_check
> +
> + BUG_ON(!str);
> + do_error_trap(regs, error_code, (char *)str, X86_REFCOUNT_VECTOR,
> + SIGILL);
> +}
> +#endif
So what avoids this:
CPU0 CPU1
lock inc %[val]; # 0x7fffffff
jo 2f
1: ...
lock dec %[val]; # 0x80000000
jo 2f
1: ...
2: mov $0x7fffffff, %[val]
jmp 1b
2: mov $0x80000000, %[val]
jmp 1b
~~~~//~~~~
lock inc %val; #0x80000000
....
lock inc %val; 0xffffffff
lock inc %val; 0x00000000
next prev parent reply other threads:[~2017-04-25 10:24 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-21 22:09 Kees Cook
2017-04-24 8:32 ` Peter Zijlstra
2017-04-24 8:53 ` [kernel-hardening] " Jann Horn
2017-04-24 9:20 ` Peter Zijlstra
2017-04-24 11:00 ` PaX Team
2017-04-24 11:15 ` Peter Zijlstra
2017-04-24 13:08 ` PaX Team
2017-04-24 13:33 ` Peter Zijlstra
2017-04-24 15:15 ` PaX Team
2017-04-24 20:40 ` Kees Cook
2017-04-24 22:01 ` Peter Zijlstra
2017-04-24 22:37 ` Kees Cook
2017-04-25 1:11 ` [kernel-hardening] " Rik van Riel
2017-04-25 9:05 ` Peter Zijlstra
2017-04-25 11:26 ` PaX Team
2017-04-25 16:36 ` Kees Cook
2017-04-24 20:33 ` Kees Cook
2017-04-25 11:26 ` PaX Team
2017-04-25 16:39 ` Kees Cook
2017-04-26 2:14 ` PaX Team
2017-04-26 4:42 ` Kees Cook
2017-04-24 20:16 ` Kees Cook
2017-04-24 10:45 ` Peter Zijlstra
2017-04-24 20:19 ` Kees Cook
2017-04-24 10:48 ` Peter Zijlstra
2017-04-24 20:21 ` Kees Cook
2017-04-25 10:23 ` Peter Zijlstra [this message]
2017-04-25 11:26 ` PaX Team
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=20170425102337.ocdi2v7ivue7x7cc@hirez.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=James.Bottomley@hansenpartnership.com \
--cc=arnd@arndb.de \
--cc=axboe@kernel.dk \
--cc=davem@davemloft.net \
--cc=dwindsor@gmail.com \
--cc=ebiggers3@gmail.com \
--cc=elena.reshetova@intel.com \
--cc=gregkh@linuxfoundation.org \
--cc=hch@infradead.org \
--cc=ishkamiel@gmail.com \
--cc=jann@thejh.net \
--cc=keescook@chromium.org \
--cc=kernel-hardening@lists.openwall.com \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=pageexec@freemail.hu \
--cc=x86@kernel.org \
/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
all inboxes | Powered by JetHome®