linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Marco Elver <elver@google.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>,
	"the arch/x86 maintainers" <x86@kernel.org>,
	"Paul E. McKenney" <paulmck@kernel.org>,
	kasan-dev <kasan-dev@googlegroups.com>,
	LKML <linux-kernel@vger.kernel.org>,
	Will Deacon <will@kernel.org>, Dmitry Vyukov <dvyukov@google.com>,
	Alexander Potapenko <glider@google.com>,
	Andrey Konovalov <andreyknvl@google.com>
Subject: Re: [PATCH 0/9] x86/entry fixes
Date: Wed, 3 Jun 2020 19:26:25 +0200	[thread overview]
Message-ID: <CANpmjNMCAv4JS1Go0KUoCgc5y17ROTbaEGFy=tAYosE9sOAnAg@mail.gmail.com> (raw)
In-Reply-To: <20200603160722.GD2570@hirez.programming.kicks-ass.net>

On Wed, 3 Jun 2020 at 18:07, Peter Zijlstra <peterz@infradead.org> wrote:
>
> On Wed, Jun 03, 2020 at 04:47:54PM +0200, Marco Elver wrote:
>
> > This is fun: __always_inline functions inlined into
> > __no_sanitize_undefined *do* get instrumented because apparently UBSan
> > passes must run before the optimizer (before inlining), contrary to
> > what [ATM]SAN instrumentation does. Both GCC and Clang do this.
>
> That's just broken :-( You can keep it marked and then strip it out at
> the end if it turns out it wasn't needed after all (of course I do
> realize this might not be entirely as trivial as it sounds).

Eventually we may get the compilers to do this. But adding even more
ifdefs and Kconfig variables to check which combinations of things
work is getting out of hand. :-/ So if we can make the below work
would be great.

> > Some options to fix:
> >
> > 1. Add __no_sanitize_undefined to the problematic __always_inline
> > functions. I don't know if a macro like '#define
> > __always_inline_noinstr __always_inline __no_sanitize_undefined' is
> > useful, but it's not an automatic fix either. This option isn't great,
> > because it doesn't really scale.
>
> Agreed, that's quite horrible and fragile.
>
> > 2. If you look at the generated code for functions with
> > __ubsan_handle_*, all the calls are actually guarded by a branch. So
> > if we know that there is no UBSan violation in the function, AFAIK
> > we're fine.
>
> > What are the exact requirements for 'noinstr'?
>
> > Is it only "do not call anything I didn't tell you to call?" If that's
> > the case, and there is no bug in the function ;-), then for UBSan
> > we're fine.
>
> This; any excursion out of noinstr for an unknown reason can have
> unknown side effects which we might not be able to deal with at that
> point.
>
> For instance, if we cause a #PF before the current #PF has read CR2,
> we're hosed. If we hit a hardware breakpoint before we're ready for it,
> we're hosed (and we explicitly disallow setting breakpoints on noinstr,
> but not stuff outside it).
>
> So IFF UBSAN only calls out when things have gone wrong, as opposed to
> checking if things go wrong (say, an out-of-line bounds check), then,
> indeed, assuming no bug, no harm in having them.
>
> And in that regard they're no different from all the WARN_ON() crud we
> have all over the place, those are deemed safe under the assumption they
> don't happen either.
>
> > With that in mind, you could whitelist "__ubsan_handle"-prefixed
> > functions in objtool. Given the __always_inline+noinstr+__ubsan_handle
> > case is quite rare, it might be reasonable.
>
> Yes, I think so. Let me go have dinner and then I'll try and do a patch
> to that effect.

Very good. Yes, UBSan inlines the check and the __ubsan_handle
functions are just to generate the report.

Thanks,
-- Marco

  reply	other threads:[~2020-06-03 17:26 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-03 11:40 [PATCH 0/9] x86/entry fixes Peter Zijlstra
2020-06-03 11:40 ` [PATCH 1/9] x86/entry: Fix irq_exit() Peter Zijlstra
2020-06-03 11:40 ` [PATCH 2/9] rcu: Fixup noinstr warnings Peter Zijlstra
2020-06-03 16:46   ` Paul E. McKenney
2020-06-03 17:13     ` Peter Zijlstra
2020-06-04  3:34       ` Paul E. McKenney
2020-06-04  6:02         ` Marco Elver
2020-06-04 14:14           ` Paul E. McKenney
2020-06-04  8:05         ` Peter Zijlstra
2020-06-04 14:17           ` Paul E. McKenney
2020-06-15 15:30     ` Peter Zijlstra
2020-06-15 15:52       ` Paul E. McKenney
2020-06-15 16:06         ` Peter Zijlstra
2020-06-15 15:49   ` Peter Zijlstra
2020-06-15 15:55     ` Peter Zijlstra
2020-06-15 16:24       ` Peter Zijlstra
2020-06-15 17:14         ` Paul E. McKenney
2020-06-15 18:33           ` Peter Zijlstra
2020-06-15 18:59             ` Paul E. McKenney
2020-06-15 20:00           ` Paul E. McKenney
2020-06-19 22:15           ` Paul E. McKenney
2020-06-23 20:46             ` Peter Zijlstra
2020-06-23 21:44               ` Paul E. McKenney
2020-06-24  7:52                 ` Peter Zijlstra
2020-06-24 13:03                   ` Paul E. McKenney
2020-06-03 11:40 ` [PATCH 3/9] x86/entry: __always_inline debugreg for noinstr Peter Zijlstra
2020-06-03 17:50   ` [tip: x86/entry] " tip-bot2 for Peter Zijlstra
2020-06-03 11:40 ` [PATCH 4/9] x86/entry: __always_inline irqflags " Peter Zijlstra
2020-06-03 17:50   ` [tip: x86/entry] " tip-bot2 for Peter Zijlstra
2020-06-03 11:40 ` [PATCH 5/9] x86/entry: __always_inline arch_atomic_* " Peter Zijlstra
2020-06-03 17:50   ` [tip: x86/entry] " tip-bot2 for Peter Zijlstra
2020-06-03 11:40 ` [PATCH 6/9] x86/entry: Re-order #DB handler to avoid *SAN instrumentation Peter Zijlstra
2020-06-03 17:50   ` [tip: x86/entry] " tip-bot2 for Peter Zijlstra
2020-06-03 11:40 ` [PATCH 7/9] lockdep: __always_inline more for noinstr Peter Zijlstra
2020-06-03 17:50   ` [tip: x86/entry] " tip-bot2 for Peter Zijlstra
2020-06-03 11:40 ` [PATCH 8/9] x86/entry: __always_inline CR2 " Peter Zijlstra
2020-06-03 17:50   ` [tip: x86/entry] " tip-bot2 for Peter Zijlstra
2020-06-03 11:40 ` [PATCH 9/9] x86/entry, cpumask: Provide non-instrumented variant of cpu_is_offline() Peter Zijlstra
2020-06-03 17:50   ` [tip: x86/entry] " tip-bot2 for Peter Zijlstra
2020-06-03 12:00 ` [PATCH 0/9] x86/entry fixes Peter Zijlstra
2020-06-03 12:08   ` Peter Zijlstra
2020-06-03 12:08     ` Marco Elver
2020-06-03 12:18       ` Peter Zijlstra
2020-06-03 13:32         ` Marco Elver
2020-06-03 14:47           ` Marco Elver
2020-06-03 16:07             ` Peter Zijlstra
2020-06-03 17:26               ` Marco Elver [this message]
2020-06-03 18:16               ` Peter Zijlstra
2020-06-03 19:10                 ` Marco Elver
2020-06-04  6:00                   ` Marco Elver
2020-06-04  9:52                     ` Marco Elver

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='CANpmjNMCAv4JS1Go0KUoCgc5y17ROTbaEGFy=tAYosE9sOAnAg@mail.gmail.com' \
    --to=elver@google.com \
    --cc=andreyknvl@google.com \
    --cc=dvyukov@google.com \
    --cc=glider@google.com \
    --cc=kasan-dev@googlegroups.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=paulmck@kernel.org \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=will@kernel.org \
    --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;
as well as URLs for NNTP newsgroup(s).