All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/18] prevent bounds-check bypass via speculative execution
@ 2018-01-06  1:09 ` Dan Williams
  0 siblings, 0 replies; 197+ messages in thread
From: Dan Williams @ 2018-01-06  1:09 UTC (permalink / raw)
  To: linux-kernel
  Cc: Mark Rutland, peterz, Alan Cox, Srinivas Pandruvada, Will Deacon,
	Solomon Peachy, H. Peter Anvin, Christian Lamparter,
	Elena Reshetova, linux-arch, Andi Kleen, James E.J. Bottomley,
	linux-scsi, Jonathan Corbet, x86, Ingo Molnar, Alexey Kuznetsov,
	Zhang Rui, linux-media, Arnd Bergmann, Jan Kara,
	Eduardo Valentin, Al Viro, qla2xxx-upstream, tglx,
	Mauro Carvalho Chehab, Arjan van de Ven, Kalle Valo, alan,
	Martin K. Petersen, Hideaki YOSHIFUJI, gregkh, linux-wireless,
	Eric W. Biederman, netdev, torvalds, David S. Miller,
	Laurent Pinchart

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].

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.

These patches also will also be available via the 'nospec' git branch
here:

    git://git.kernel.org/pub/scm/linux/kernel/git/djbw/linux nospec

[1]: https://googleprojectzero.blogspot.co.uk/2018/01/reading-privileged-memory-with-side.html
[2]: https://spectreattack.com/spectre.pdf
[3]: https://marc.info/?l=linux-kernel&m=151510446027625&w=2

---

Andi Kleen (1):
      x86, barrier: stop speculation for failed access_ok

Dan Williams (13):
      x86: implement nospec_barrier()
      [media] uvcvideo: prevent bounds-check bypass via speculative execution
      carl9170: prevent bounds-check bypass via speculative execution
      p54: prevent bounds-check bypass via speculative execution
      qla2xxx: prevent bounds-check bypass via speculative execution
      cw1200: prevent bounds-check bypass via speculative execution
      Thermal/int340x: prevent bounds-check bypass via speculative execution
      ipv6: prevent bounds-check bypass via speculative execution
      ipv4: prevent bounds-check bypass via speculative execution
      vfs, fdtable: prevent bounds-check bypass via speculative execution
      net: mpls: prevent bounds-check bypass via speculative execution
      udf: prevent bounds-check bypass via speculative execution
      userns: prevent bounds-check bypass via speculative execution

Mark Rutland (4):
      asm-generic/barrier: add generic nospec helpers
      Documentation: document nospec helpers
      arm64: implement nospec_ptr()
      arm: implement nospec_ptr()

 Documentation/speculation.txt                      |  166 ++++++++++++++++++++
 arch/arm/include/asm/barrier.h                     |   75 +++++++++
 arch/arm64/include/asm/barrier.h                   |   55 +++++++
 arch/x86/include/asm/barrier.h                     |    6 +
 arch/x86/include/asm/uaccess.h                     |   17 ++
 drivers/media/usb/uvc/uvc_v4l2.c                   |    7 +
 drivers/net/wireless/ath/carl9170/main.c           |    6 -
 drivers/net/wireless/intersil/p54/main.c           |    8 +
 drivers/net/wireless/st/cw1200/sta.c               |   10 +
 drivers/net/wireless/st/cw1200/wsm.h               |    4 
 drivers/scsi/qla2xxx/qla_mr.c                      |   15 +-
 .../thermal/int340x_thermal/int340x_thermal_zone.c |   14 +-
 fs/udf/misc.c                                      |   39 +++--
 include/asm-generic/barrier.h                      |   68 ++++++++
 include/linux/fdtable.h                            |    5 -
 kernel/user_namespace.c                            |   10 -
 net/ipv4/raw.c                                     |    9 +
 net/ipv6/raw.c                                     |    9 +
 net/mpls/af_mpls.c                                 |   12 +
 19 files changed, 466 insertions(+), 69 deletions(-)
 create mode 100644 Documentation/speculation.txt

^ permalink raw reply	[flat|nested] 197+ messages in thread
* Re: [PATCH 06/18] x86, barrier: stop speculation for failed access_ok
@ 2018-01-09  0:12 Linus Torvalds
  0 siblings, 0 replies; 197+ messages in thread
From: Linus Torvalds @ 2018-01-09  0:12 UTC (permalink / raw)
  To: Dan Williams
  Cc: Linux Kernel Mailing List, linux-arch, Andi Kleen, Arnd Bergmann,
	Greg Kroah-Hartman, Peter Zijlstra, Network Development,
	the arch/x86 maintainers, Ingo Molnar, H. Peter Anvin,
	Thomas Gleixner, Alan Cox

On Mon, Jan 8, 2018 at 3:53 PM, Dan Williams <dan.j.williams@intel.com> wrote:
>
> I've been thinking the "and" is only suitable for the array bounds
> check, for get_user() we're trying to block speculation past
> access_ok() at which point we can only do the lfence?

Well, we *could* do the "and", at least for the simple cases (ie the
true "get_user()" that integrates the access_ok with the access).

IOW, mainly the code in arch/x86/lib/getuser.S.

But it probably is a lot simpler to just add the "lfence" to ASM_STAC,
because by definition those cases don't tend to be the truly critical
ones - people who use those functions tend to do one or two accesses,
and the real cost is likely the I$ misses and the D$ miss to get
current->addr_limit. Not to mention the "stac" itself, which is much
more expensive than the access on current microarchitectures.

But something like this *might* work:

   index c97d935a29e8..7fa3d293beaf 100644
   --- a/arch/x86/lib/getuser.S
   +++ b/arch/x86/lib/getuser.S
   @@ -38,8 +38,11 @@
           .text
    ENTRY(__get_user_1)
           mov PER_CPU_VAR(current_task), %_ASM_DX
   -       cmp TASK_addr_limit(%_ASM_DX),%_ASM_AX
   +       mov TASK_addr_limit(%_ASM_DX),%_ASM_DX
   +       cmp %_ASM_DX,%_ASM_AX
           jae bad_get_user
   +       or $0xfff,%_ASM_DX
   +       and %_ASM_DX,%_ASM_AX
           ASM_STAC
    1:     movzbl (%_ASM_AX),%edx
           xor %eax,%eax

(this only does the one-byte case - the 2/4/8 byte cases are exactly the same).

The above is completely untested and might have some stupid
thinko/typo, so take it purely as a "example patch" to show the
concept, rather than actually do it.

But just adding "lfence" to the existing ASM_STAC is a hell of a lot
easier, and the performance difference between that trivial patch and
the above "let's be clever with 'and'" might not be measurable.

I really have no idea how expensive lfence might actually end up being
in practice. It's possible that lfence is actually fairly cheap in
kernel code, since we tend to not have very high IPC anyway.

                 Linus

^ permalink raw reply	[flat|nested] 197+ messages in thread

end of thread, other threads:[~2018-01-13 11:33 UTC | newest]

Thread overview: 197+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-06  1:09 [PATCH 00/18] prevent bounds-check bypass via speculative execution Dan Williams
2018-01-06  1:09 ` Dan Williams
2018-01-06  1:09 ` 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  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  2:23                                     ` David Miller
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  2:22   ` Eric W. Biederman
2018-01-06  2:22   ` Eric W. Biederman
2018-01-06  6:30   ` Dan Williams
2018-01-06  6:30     ` Dan Williams
2018-01-08 10:08     ` Peter Zijlstra
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:43         ` Alan Cox
2018-01-08 11:43         ` Alan Cox
2018-01-08 11:55         ` Peter Zijlstra
2018-01-08 11:55           ` Peter Zijlstra
2018-01-08 11:55           ` Peter Zijlstra
2018-01-08 18:33         ` Ingo Molnar
2018-01-08 18:33           ` Ingo Molnar
2018-01-08 18:33           ` Ingo Molnar
2018-01-08 16:20     ` Bart Van Assche
2018-01-08 16:20       ` Bart Van Assche
2018-01-06 18:56 ` Florian Fainelli
2018-01-06 18:56   ` Florian Fainelli
2018-01-06 18:56   ` Florian Fainelli
2018-01-06 18:59   ` Arjan van de Ven
2018-01-06 18:59     ` Arjan van de Ven
2018-01-06 18:59     ` Arjan van de Ven
2018-01-06 19:37 ` Dan Williams
2018-01-06 19:37   ` Dan Williams
2018-01-06 19:37   ` Dan Williams
2018-01-06 20:07   ` Dan Williams
2018-01-06 20:07     ` 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:34   ` Jiri Kosina
2018-01-09 19:34   ` Jiri Kosina
2018-01-09 19:44   ` Dan Williams
2018-01-09 19:44     ` Dan Williams
2018-01-09 20:55     ` Josh Poimboeuf
2018-01-09 20:55       ` Josh Poimboeuf
2018-01-09 20:55       ` Josh Poimboeuf
2018-01-11  9:54       ` Jiri Kosina
2018-01-11  9:54         ` Jiri Kosina
2018-01-11  9:54         ` Jiri Kosina
2018-01-11 15:58         ` Dan Williams
2018-01-11 15:58           ` Dan Williams
2018-01-11 15:58           ` Dan Williams
2018-01-11 16:34           ` Daniel Borkmann
2018-01-11 16:34             ` Daniel Borkmann
2018-01-11 16:34             ` Daniel Borkmann
2018-01-13 11:33 ` QingFeng Hao
2018-01-09  0:12 [PATCH 06/18] x86, barrier: stop speculation for failed access_ok Linus Torvalds

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.