linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dan Williams <dan.j.williams@intel.com>
To: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Alan Cox <alan.cox@intel.com>,
	Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>,
	Will Deacon <will.deacon@arm.com>,
	Solomon Peachy <pizza@shaftnet.org>,
	"H. Peter Anvin" <hpa@zytor.com>,
	Christian Lamparter <chunkeey@googlemail.com>,
	Elena Reshetova <elena.reshetova@intel.com>,
	linux-arch@vger.kernel.org, Andi Kleen <ak@linux.intel.com>,
	"James E.J. Bottomley" <jejb@linux.vnet.ibm.com>,
	linux-scsi <linux-scsi@vger.kernel.org>,
	Jonathan Corbet <corbet@lwn.net>, X86 ML <x86@kernel.org>,
	Ingo Molnar <mingo@redhat.com>,
	Alexey Kuznetsov <kuznet@ms2.inr.ac.ru>,
	Zhang Rui <rui.zhang@intel.com>,
	"Linux-media@vger.kernel.org" <linux-media@vger.kernel.org>,
	Arnd Bergmann <arnd@arndb.de>, Jan Kara <jack@suse.com>,
	Eduardo Valentin <edubezval@gmail.com>,
	Al Viro <viro@zeniv.linux.org.uk>,
	qla2xxx-upstream@qlogic.com, Thomas Gleixner <tglx@linutronix.de>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Arjan van de Ven <arjan@linux.intel.com>,
	Kalle Valo <kvalo@codeaurora.org>,
	Alan Cox <alan@linux.intel.com>,
	"Martin K. Petersen" <martin.petersen@oracle.com>,
	Hideaki YOSHIFUJI <yoshfuji@linux-ipv6.org>,
	Greg KH <gregkh@linuxfoundation.org>,
	linux-wireless@vger.kernel.org, Netdev <netdev@vger.kernel.org>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	"David S. Miller" <davem@davemloft.net>,
	Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Subject: Re: [PATCH 00/18] prevent bounds-check bypass via speculative execution
Date: Fri, 5 Jan 2018 22:30:16 -0800	[thread overview]
Message-ID: <CAPcyv4hVisGeXbTH985Hb6dkYKA9Sr8wwZHudNF-CtH0=ADFug@mail.gmail.com> (raw)
In-Reply-To: <87y3lbpvzp.fsf@xmission.com>

On Fri, Jan 5, 2018 at 6:22 PM, Eric W. Biederman <ebiederm@xmission.com> wrote:
> Dan Williams <dan.j.williams@intel.com> writes:
>
>> Quoting Mark's original RFC:
>>
>> "Recently, Google Project Zero discovered several classes of attack
>> against speculative execution. One of these, known as variant-1, allows
>> explicit bounds checks to be bypassed under speculation, providing an
>> arbitrary read gadget. Further details can be found on the GPZ blog [1]
>> and the Documentation patch in this series."
>>
>> This series incorporates Mark Rutland's latest api and adds the x86
>> specific implementation of nospec_barrier. The
>> nospec_{array_ptr,ptr,barrier} helpers are then combined with a kernel
>> wide analysis performed by Elena Reshetova to address static analysis
>> reports where speculative execution on a userspace controlled value
>> could bypass a bounds check. The patches address a precondition for the
>> attack discussed in the Spectre paper [2].
>
> Please expand this.
>
> It is not clear what the static analysis is looking for.  Have a clear
> description of what is being fixed is crucial for allowing any of these
> changes.
>
> For the details given in the change description what I read is magic
> changes because a magic process says this code is vunlerable.

Yes, that was my first reaction to the patches as well, I try below to
add some more background and guidance, but in the end these are static
analysis reports across a wide swath of sub-systems. It's going to
take some iteration with domain experts to improve the patch
descriptions, and that's the point of this series, to get the better
trained eyes from the actual sub-system owners to take a look at these
reports.

For example, I'm looking for feedback like what Srinivas gave where he
identified that the report is bogus, the branch condition can not be
seeded with bad values in that path. Be like Srinivas.

> Given the similarities in the code that is being patched to many other
> places in the kernel it is not at all clear that this small set of
> changes is sufficient for any purpose.

I find this assertion absurd, when in the past have we as kernel
developers ever been handed a static analysis report and then
questioned why the static analysis did not flag other call sites
before first reviewing the ones it did find?

>> A consideration worth noting for reviewing these patches is to weigh the
>> dramatic cost of being wrong about whether a given report is exploitable
>> vs the overhead nospec_{array_ptr,ptr} may introduce. In other words,
>> lets make the bar for applying these patches be "can you prove that the
>> bounds check bypass is *not* exploitable". Consider that the Spectre
>> paper reports one example of a speculation window being ~180 cycles.
>
>
>> Note that there is also a proposal from Linus, array_access [3], that
>> attempts to quash speculative execution past a bounds check without
>> introducing an lfence instruction. That may be a future optimization
>> possibility that is compatible with this api, but it would appear to
>> need guarantees from the compiler that it is not clear the kernel can
>> rely on at this point. It is also not clear that it would be a
>> significant performance win vs lfence.
>
> It is also not clear that these changes fix anything, or are in any
> sense correct for the problem they are trying to fix as the problem
> is not clearly described.

I'll try my best. I don't have first hand knowledge of how the static
analyzer is doing this job, and I don't think it matters for
evaluating these reports. I'll give you my thoughts on how I would
handle one of these reports if it flagged one of the sub-systems I
maintain.

Start with the example from the Spectre paper:

    if (x < array1_size)
        y = array2[array1[x] * 256];

In all the patches 'x' and 'array1' are called out explicitly. For example:

    net: mpls: prevent bounds-check bypass via speculative execution

    Static analysis reports that 'index' may be a user controlled value that
    is used as a data dependency reading 'rt' from the 'platform_label'
    array...

So the first thing to review is whether the analyzer got it wrong and
'x' is not arbitrarily controllable by userspace to cause speculation
outside of the checked bounds. Be like Srinivas. The next step is to
ask whether the code can be refactored so that 'x' is sanitized
earlier in the call stack, especially if the nospec_array_ptr() lands
in a hot path. The next aspect that I expect most would be tempted to
go check is whether 'array2[array1[x]]' occurs later in the code
stream, but with speculation windows being architecture dependent and
potentially large (~180 cycles in one case says the paper) I submit
that we should err on the side of caution and not guess if that second
dependent read has been emitted somewhere in the instruction stream.

> In at least one place (mpls) you are patching a fast path.  Compile out
> or don't load mpls by all means.  But it is not acceptable to change the
> fast path without even considering performance.

Performance matters greatly, but I need help to identify a workload
that is representative for this fast path to see what, if any, impact
is incurred. Even better is a review that says "nope, 'index' is not
subject to arbitrary userspace control at this point, drop the patch."

  reply	other threads:[~2018-01-06  6:30 UTC|newest]

Thread overview: 161+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-06  1:09 [PATCH 00/18] prevent bounds-check bypass via speculative execution Dan Williams
2018-01-06  1:09 ` [PATCH 01/18] asm-generic/barrier: add generic nospec helpers Dan Williams
2018-01-06  2:55   ` Linus Torvalds
2018-01-06  5:23     ` Dan Williams
2018-01-06 17:08       ` Mark Rutland
2018-01-06  1:10 ` [PATCH 02/18] Documentation: document " Dan Williams
2018-01-08 16:29   ` Jonathan Corbet
2018-01-08 17:09     ` Mark Rutland
2018-01-08 21:19       ` Jonathan Corbet
2018-01-06  1:10 ` [PATCH 03/18] arm64: implement nospec_ptr() Dan Williams
2018-01-06  1:10 ` [PATCH 04/18] arm: " Dan Williams
2018-01-10  2:04   ` Laura Abbott
2018-01-10  7:40     ` Hanjun Guo
2018-01-10 17:24       ` Laura Abbott
2018-01-06  1:10 ` [PATCH 05/18] x86: implement nospec_barrier() Dan Williams
2018-01-06  1:10 ` [PATCH 06/18] x86, barrier: stop speculation for failed access_ok Dan Williams
2018-01-06  2:52   ` Linus Torvalds
2018-01-06  3:09     ` Linus Torvalds
2018-01-06 23:31       ` Dan Williams
2018-01-07  1:20         ` Linus Torvalds
2018-01-08 21:09           ` Dan Williams
2018-01-08 23:44             ` Linus Torvalds
2018-01-08 23:53               ` Dan Williams
2018-01-06  5:47     ` Dan Williams
2018-01-06 12:32     ` Alan Cox
2018-01-06 17:56       ` Linus Torvalds
2018-01-06 18:13       ` Alexei Starovoitov
2018-01-06 18:29         ` Dan Williams
2018-01-06 18:39           ` Alexei Starovoitov
2018-01-06 18:54             ` Dan Williams
2018-01-06 19:25               ` Alexei Starovoitov
2018-01-06 19:36                 ` Dan Williams
2018-01-06 19:41                 ` Thomas Gleixner
2018-01-08 10:02                   ` Andrea Arcangeli
2018-01-06 18:38         ` Alan Cox
2018-01-06 18:51           ` Alexei Starovoitov
2018-01-06 19:55             ` Alan Cox
2018-01-06 20:09               ` Alexei Starovoitov
2018-01-06 20:22                 ` Alan Cox
2018-01-06 21:17                   ` Alexei Starovoitov
2018-01-06 21:21                     ` Thomas Gleixner
2018-01-06 23:05                     ` Alan Cox
2018-01-07  3:38                       ` Alexei Starovoitov
2018-01-07  6:33                         ` Willy Tarreau
2018-01-07 19:47                           ` Linus Torvalds
2018-01-07 20:12                             ` Willy Tarreau
2018-01-07 20:17                               ` Linus Torvalds
2018-01-07 20:56                                 ` Thomas Gleixner
2018-01-08  2:23                                   ` David Miller
2018-01-08  7:38                                     ` Greg KH
2018-01-07 22:15                                 ` Willy Tarreau
2018-01-07 20:15                             ` Dan Williams
2018-01-08  2:24                               ` Alexei Starovoitov
2018-01-08  9:51                                 ` Peter Zijlstra
2018-01-08 18:21                                   ` Ingo Molnar
2018-01-08 12:00                             ` David Laight
2018-01-08 12:12                               ` Alan Cox
2018-01-08 12:33                                 ` David Laight
2018-01-07 10:08                         ` Thomas Gleixner
2018-01-08  2:09                           ` Alexei Starovoitov
2018-01-07 13:59                         ` Alan Cox
2018-01-08  2:57                           ` Alexei Starovoitov
2018-01-08  9:57                             ` Peter Zijlstra
2018-01-06 20:42           ` Willy Tarreau
2018-01-07  1:36             ` David Miller
2018-01-07 17:19               ` James Bottomley
2018-01-07 18:31                 ` Thomas Gleixner
2018-01-08  2:04                   ` David Miller
2018-01-07 19:24                 ` Alan Cox
2018-01-09 21:41     ` Josh Poimboeuf
2018-01-09 21:47       ` Dan Williams
2018-01-09 21:49         ` Josh Poimboeuf
2018-01-09 21:59           ` Dan Williams
2018-01-09 22:23             ` Josh Poimboeuf
2018-01-09 22:35               ` Dan Williams
2018-01-06  1:10 ` [PATCH 07/18] [media] uvcvideo: prevent bounds-check bypass via speculative execution Dan Williams
2018-01-06  9:09   ` Greg KH
2018-01-06  9:40     ` Greg KH
2018-01-06 17:41       ` Dan Williams
2018-01-07  9:09         ` Greg KH
2018-01-07 19:37           ` Dan Williams
2018-01-09  8:40       ` Laurent Pinchart
2018-01-09 10:04         ` Greg KH
2018-01-09 14:26           ` Laurent Pinchart
2018-01-09 14:47             ` Greg KH
2018-01-08 11:23   ` Laurent Pinchart
2018-01-09  2:11     ` Dan Williams
2018-01-06  1:10 ` [PATCH 08/18] carl9170: " Dan Williams
2018-01-06 10:01   ` Sergei Shtylyov
2018-01-06 14:23   ` Christian Lamparter
2018-01-06 15:06     ` Alan Cox
2018-01-06 16:38       ` Christian Lamparter
2018-01-06 16:34     ` Dan Williams
2018-01-06  1:10 ` [PATCH 09/18] p54: " Dan Williams
2018-01-06 10:01   ` Sergei Shtylyov
2018-01-06  1:10 ` [PATCH 10/18] qla2xxx: " Dan Williams
2018-01-06  9:03   ` Greg KH
2018-01-06  9:42     ` Greg KH
2018-01-11 22:15     ` Dan Williams
2018-01-12  7:27       ` Greg KH
2018-01-12 15:25         ` James Bottomley
2018-01-06  1:10 ` [PATCH 11/18] cw1200: " Dan Williams
2018-01-06  1:10 ` [PATCH 12/18] Thermal/int340x: " Dan Williams
2018-01-06  1:53   ` Srinivas Pandruvada
2018-01-06  1:57     ` Dan Williams
2018-01-06 17:24       ` Srinivas Pandruvada
2018-01-06 10:03   ` Sergei Shtylyov
2018-01-06  1:11 ` [PATCH 13/18] ipv6: " Dan Williams
2018-01-06 10:04   ` Sergei Shtylyov
2018-01-06 14:48   ` Stephen Hemminger
2018-01-06 18:05     ` Dan Williams
2018-01-06  1:11 ` [PATCH 14/18] ipv4: " Dan Williams
2018-01-06  9:00   ` Greg KH
2018-01-06  9:01   ` Greg KH
2018-01-06 12:23     ` Alan Cox
2018-01-06 15:14       ` Greg KH
2018-01-06 16:29         ` Dan Williams
2018-01-06 18:10           ` Dan Williams
2018-01-06 10:04   ` Sergei Shtylyov
2018-01-06  1:11 ` [PATCH 15/18] vfs, fdtable: " Dan Williams
2018-01-06 10:05   ` Sergei Shtylyov
2018-01-06  1:11 ` [PATCH 16/18] net: mpls: " Dan Williams
2018-01-06 10:06   ` Sergei Shtylyov
2018-01-09  3:11   ` Eric W. Biederman
2018-01-09  3:42     ` Dan Williams
2018-01-09  4:13       ` Linus Torvalds
2018-01-09  4:21         ` Linus Torvalds
2018-01-10  0:48         ` Dan Williams
2018-01-10  1:33           ` Dan Williams
2018-01-10  1:57           ` Alexei Starovoitov
2018-01-10  2:22             ` Dan Williams
2018-01-10  3:07               ` Alexei Starovoitov
2018-01-10  3:27           ` Linus Torvalds
2018-01-09 16:17       ` Eric W. Biederman
2018-01-09 18:01         ` Dan Williams
2018-01-10  0:54           ` Eric W. Biederman
2018-01-10  1:31             ` Dan Williams
2018-01-06  1:11 ` [PATCH 17/18] udf: " Dan Williams
2018-01-08 10:20   ` Jan Kara
2018-01-06  1:11 ` [PATCH 18/18] userns: " Dan Williams
2018-01-06  2:22 ` [PATCH 00/18] " Eric W. Biederman
2018-01-06  6:30   ` Dan Williams [this message]
2018-01-08 10:08     ` Peter Zijlstra
2018-01-08 11:14       ` Laurent Pinchart
2018-01-08 11:43       ` Alan Cox
2018-01-08 11:55         ` Peter Zijlstra
2018-01-08 18:33         ` Ingo Molnar
2018-01-08 16:20     ` Bart Van Assche
2018-01-06 18:56 ` Florian Fainelli
2018-01-06 18:59   ` Arjan van de Ven
2018-01-06 19:37 ` Dan Williams
2018-01-06 20:07   ` Dan Williams
2018-01-08  4:49 ` Bart Van Assche
2018-01-08 13:33   ` Arjan van de Ven
2018-01-09 19:34 ` Jiri Kosina
2018-01-09 19:44   ` Dan Williams
2018-01-09 20:55     ` Josh Poimboeuf
2018-01-11  9:54       ` Jiri Kosina
2018-01-11 15:58         ` Dan Williams
2018-01-11 16:34           ` Daniel Borkmann
2018-01-13 11:33 ` QingFeng Hao

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='CAPcyv4hVisGeXbTH985Hb6dkYKA9Sr8wwZHudNF-CtH0=ADFug@mail.gmail.com' \
    --to=dan.j.williams@intel.com \
    --cc=ak@linux.intel.com \
    --cc=alan.cox@intel.com \
    --cc=alan@linux.intel.com \
    --cc=arjan@linux.intel.com \
    --cc=arnd@arndb.de \
    --cc=chunkeey@googlemail.com \
    --cc=corbet@lwn.net \
    --cc=davem@davemloft.net \
    --cc=ebiederm@xmission.com \
    --cc=edubezval@gmail.com \
    --cc=elena.reshetova@intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hpa@zytor.com \
    --cc=jack@suse.com \
    --cc=jejb@linux.vnet.ibm.com \
    --cc=kuznet@ms2.inr.ac.ru \
    --cc=kvalo@codeaurora.org \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=martin.petersen@oracle.com \
    --cc=mchehab@kernel.org \
    --cc=mingo@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=peterz@infradead.org \
    --cc=pizza@shaftnet.org \
    --cc=qla2xxx-upstream@qlogic.com \
    --cc=rui.zhang@intel.com \
    --cc=srinivas.pandruvada@linux.intel.com \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    --cc=viro@zeniv.linux.org.uk \
    --cc=will.deacon@arm.com \
    --cc=x86@kernel.org \
    --cc=yoshfuji@linux-ipv6.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).