linux-arch.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: ebiederm@xmission.com (Eric W. Biederman)
To: Dan Williams <dan.j.williams@intel.com>
Cc: linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org,
	peterz@infradead.org, netdev@vger.kernel.org,
	gregkh@linuxfoundation.org, tglx@linutronix.de,
	torvalds@linux-foundation.org,
	"David S. Miller" <davem@davemloft.net>,
	Elena Reshetova <elena.reshetova@intel.com>,
	alan@linux.intel.com
Subject: Re: [PATCH 16/18] net: mpls: prevent bounds-check bypass via speculative execution
Date: Mon, 08 Jan 2018 21:11:56 -0600	[thread overview]
Message-ID: <87lgh7n2tf.fsf@xmission.com> (raw)
In-Reply-To: <151520108080.32271.16420298348259030860.stgit@dwillia2-desk3.amr.corp.intel.com> (Dan Williams's message of "Fri, 05 Jan 2018 17:11:20 -0800")

Dan Williams <dan.j.williams@intel.com> writes:

> 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.  In order to avoid potential leaks of kernel memory values, block
> speculative execution of the instruction stream that could issue further
> reads based on an invalid 'rt' value.


In detail.
a) This code is fast path packet forwarding code.  Introducing an
   unconditional pipeline stall is not ok.

   AKA either there is no speculation and so this is invulnerable
   or there is speculation and you are creating an unconditional
   pipeline stall here.

   My back of the napkin caluculations say that a pipeline stall
   is about 20 cycles.  Which is about the same length of time
   as a modern cache miss.

   On a good day this code will perform with 0 cache misses. On a less
   good day 1 cache miss.  Which means you are quite possibly doubling
   the runtime of mpls_forward.

b) The array is dynamically allocated which should provide some
   protection, as it will be more difficult to predict the address
   of the array which is needed to craft an malicious userspace value.

c) The code can be trivially modified to say:

static struct mpls_route *mpls_route_input_rcu(struct net *net, unsigned index)
{
	struct mpls_route *rt = NULL;

	if (index < net->mpls.platform_labels) {
		struct mpls_route __rcu **platform_label =
			rcu_dereference(net->mpls.platform_label);
		rt = rcu_dereference(platform_label[index & ((1 << 20) - 1)]);
	}
	return rt;
}

AKA a static mask will ensure that there is not a primitive that can be
used to access all of memory.  That is max a 1 cycle slowdown in the
code, which is a much better trade off.

d) If we care more it is straight forward to modify
   resize_platform_label_table() to ensure that the size of the array
   is always a power of 2.

e) The fact that a pointer is returned from the array and it is treated
   like a pointer would seem to provide a defense against the
   exfiltration technique of using the value read as an index into
   a small array, that user space code can probe aliased cached
   lines of, to see which value was dereferenced.


So to this patch in particular.
Nacked-by: "Eric W. Biederman" <ebiederm@xmission.com>

This code path will be difficult to exploit.  This change messes with
performance.  There are ways to make this code path useless while
preserving the performance of the code.

Eric

>
> Based on an original patch by Elena Reshetova.
>
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Eric W. Biederman <ebiederm@xmission.com>
> Cc: netdev@vger.kernel.org
> Signed-off-by: Elena Reshetova <elena.reshetova@intel.com>
> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
> ---
>  net/mpls/af_mpls.c |   12 +++++++-----
>  1 file changed, 7 insertions(+), 5 deletions(-)
>
> diff --git a/net/mpls/af_mpls.c b/net/mpls/af_mpls.c
> index 8ca9915befc8..ebcf0e246cfe 100644
> --- a/net/mpls/af_mpls.c
> +++ b/net/mpls/af_mpls.c
> @@ -8,6 +8,7 @@
>  #include <linux/ipv6.h>
>  #include <linux/mpls.h>
>  #include <linux/netconf.h>
> +#include <linux/compiler.h>
>  #include <linux/vmalloc.h>
>  #include <linux/percpu.h>
>  #include <net/ip.h>
> @@ -77,12 +78,13 @@ static void rtmsg_lfib(int event, u32 label, struct mpls_route *rt,
>  static struct mpls_route *mpls_route_input_rcu(struct net *net, unsigned index)
>  {
>  	struct mpls_route *rt = NULL;
> +	struct mpls_route __rcu **platform_label =
> +		rcu_dereference(net->mpls.platform_label);
> +	struct mpls_route __rcu **rtp;
>  
> -	if (index < net->mpls.platform_labels) {
> -		struct mpls_route __rcu **platform_label =
> -			rcu_dereference(net->mpls.platform_label);
> -		rt = rcu_dereference(platform_label[index]);
> -	}
> +	if ((rtp = nospec_array_ptr(platform_label, index,
> +					net->mpls.platform_labels)))
> +		rt = rcu_dereference(*rtp);
>  	return rt;
>  }
>  

  parent reply	other threads:[~2018-01-09  3:12 UTC|newest]

Thread overview: 256+ 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 ` Dan Williams
2018-01-06  1:09 ` [PATCH 01/18] asm-generic/barrier: add generic nospec helpers Dan Williams
2018-01-06  1:09   ` Dan Williams
2018-01-06  2:55   ` Linus Torvalds
2018-01-06  5:23     ` Dan Williams
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-06  1:10   ` Dan Williams
2018-01-08 16:29   ` Jonathan Corbet
2018-01-08 16:29     ` Jonathan Corbet
2018-01-08 17:09     ` Mark Rutland
2018-01-08 17:09       ` Mark Rutland
2018-01-08 21:19       ` Jonathan Corbet
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   ` Dan Williams
2018-01-06  1:10 ` [PATCH 04/18] arm: " Dan Williams
2018-01-06  1:10   ` 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  1:10   ` Dan Williams
2018-01-06  2:52   ` Linus Torvalds
2018-01-06  3:09     ` Linus Torvalds
2018-01-06  3:09       ` Linus Torvalds
2018-01-06 23:31       ` Dan Williams
2018-01-06 23:31         ` Dan Williams
2018-01-07  1:20         ` Linus Torvalds
2018-01-07  1:20           ` Linus Torvalds
2018-01-08 21:09           ` Dan Williams
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 17:56         ` Linus Torvalds
2018-01-06 18:13       ` Alexei Starovoitov
2018-01-06 18:29         ` Dan Williams
2018-01-06 18:29           ` Dan Williams
2018-01-06 18:39           ` Alexei Starovoitov
2018-01-06 18:39             ` Alexei Starovoitov
2018-01-06 18:54             ` Dan Williams
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:36                   ` Dan Williams
2018-01-06 19:41                 ` Thomas Gleixner
2018-01-06 19:41                   ` Thomas Gleixner
2018-01-08 10:02                   ` Andrea Arcangeli
2018-01-08 10:02                     ` Andrea Arcangeli
2018-01-06 18:38         ` Alan Cox
2018-01-06 18:51           ` Alexei Starovoitov
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:09                 ` Alexei Starovoitov
2018-01-06 20:22                 ` Alan Cox
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-06 23:05                       ` Alan Cox
2018-01-07  3:38                       ` Alexei Starovoitov
2018-01-07  6:33                         ` Willy Tarreau
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: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  7:38                                     ` Greg KH
2018-01-08  7:38                                       ` Greg KH
2018-01-07 22:15                                 ` Willy Tarreau
2018-01-07 22:15                                   ` Willy Tarreau
2018-01-07 20:15                             ` Dan Williams
2018-01-08  2:24                               ` Alexei Starovoitov
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  2:57                             ` Alexei Starovoitov
2018-01-08  9:57                             ` Peter Zijlstra
2018-01-08  9:57                               ` Peter Zijlstra
2018-01-06 20:42           ` Willy Tarreau
2018-01-07  1:36             ` David Miller
2018-01-07  1:36               ` David Miller
2018-01-07 17:19               ` James Bottomley
2018-01-07 17:19                 ` James Bottomley
2018-01-07 18:31                 ` Thomas Gleixner
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:41       ` Josh Poimboeuf
2018-01-09 21:47       ` Dan Williams
2018-01-09 21:47         ` Dan Williams
2018-01-09 21:49         ` Josh Poimboeuf
2018-01-09 21:49           ` Josh Poimboeuf
2018-01-09 21:59           ` Dan Williams
2018-01-09 21:59             ` Dan Williams
2018-01-09 22:23             ` Josh Poimboeuf
2018-01-09 22:35               ` Dan Williams
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  1:10   ` Dan Williams
2018-01-06  9:09   ` Greg KH
2018-01-06  9:09     ` Greg KH
2018-01-06  9:40     ` Greg KH
2018-01-06 17:41       ` Dan Williams
2018-01-06 17:41         ` Dan Williams
2018-01-07  9:09         ` Greg KH
2018-01-07  9:09           ` Greg KH
2018-01-07 19:37           ` Dan Williams
2018-01-07 19:37             ` Dan Williams
2018-01-09  8:40       ` Laurent Pinchart
2018-01-09 10:04         ` Greg KH
2018-01-09 10:04           ` Greg KH
2018-01-09 14:26           ` Laurent Pinchart
2018-01-09 14:26             ` Laurent Pinchart
2018-01-09 14:47             ` Greg KH
2018-01-09 14:47               ` Greg KH
2018-01-08 11:23   ` Laurent Pinchart
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  1:10   ` 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 15:06       ` Alan Cox
2018-01-06 16:38       ` Christian Lamparter
2018-01-06 16:34     ` Dan Williams
2018-01-06 16:34       ` Dan Williams
2018-01-06  1:10 ` [PATCH 09/18] p54: " Dan Williams
2018-01-06  1:10   ` Dan Williams
2018-01-06 10:01   ` Sergei Shtylyov
2018-01-06 10:01     ` Sergei Shtylyov
2018-01-06  1:10 ` [PATCH 10/18] qla2xxx: " Dan Williams
2018-01-06  1:10   ` Dan Williams
2018-01-06  9:03   ` Greg KH
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   ` Dan Williams
2018-01-06  1:10 ` [PATCH 12/18] Thermal/int340x: " Dan Williams
2018-01-06  1:10   ` 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 17:24         ` Srinivas Pandruvada
2018-01-06 10:03   ` Sergei Shtylyov
2018-01-06 10:03     ` Sergei Shtylyov
2018-01-06  1:11 ` [PATCH 13/18] ipv6: " Dan Williams
2018-01-06  1:11   ` Dan Williams
2018-01-06 10:04   ` Sergei Shtylyov
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  9:01     ` Greg KH
2018-01-06 12:23     ` Alan Cox
2018-01-06 15:14       ` Greg KH
2018-01-06 15:14         ` Greg KH
2018-01-06 16:29         ` Dan Williams
2018-01-06 16:29           ` Dan Williams
2018-01-06 18:10           ` 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  1:11   ` Dan Williams
2018-01-06 10:05   ` Sergei Shtylyov
2018-01-06  1:11 ` [PATCH 16/18] net: mpls: " Dan Williams
2018-01-06  1:11   ` Dan Williams
2018-01-06 10:06   ` Sergei Shtylyov
2018-01-06 10:06     ` Sergei Shtylyov
2018-01-09  3:11   ` Eric W. Biederman [this message]
2018-01-09  3:42     ` Dan Williams
2018-01-09  3:42       ` Dan Williams
2018-01-09  4:13       ` Linus Torvalds
2018-01-09  4:13         ` Linus Torvalds
2018-01-09  4:21         ` Linus Torvalds
2018-01-10  0:48         ` Dan Williams
2018-01-10  0:48           ` Dan Williams
2018-01-10  1:33           ` Dan Williams
2018-01-10  1:33             ` Dan Williams
2018-01-10  1:57           ` Alexei Starovoitov
2018-01-10  1:57             ` Alexei Starovoitov
2018-01-10  2:22             ` Dan Williams
2018-01-10  2:22               ` Dan Williams
2018-01-10  3:07               ` Alexei Starovoitov
2018-01-10  3:27           ` Linus Torvalds
2018-01-10  3:27             ` Linus Torvalds
2018-01-09 16:17       ` Eric W. Biederman
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  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-06  1:11   ` Dan Williams
2018-01-08 10:20   ` Jan Kara
2018-01-06  1:11 ` [PATCH 18/18] userns: " Dan Williams
2018-01-06  1:11   ` Dan Williams
2018-01-06  2:22 ` [PATCH 00/18] " Eric W. Biederman
2018-01-06  2:22   ` Eric W. Biederman
     [not found]   ` <87y3lbpvzp.fsf-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
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: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 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: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 20:07   ` Dan Williams
2018-01-06 20:07     ` Dan Williams
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-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 16:34           ` Daniel Borkmann
2018-01-11 16:34             ` Daniel Borkmann

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=87lgh7n2tf.fsf@xmission.com \
    --to=ebiederm@xmission.com \
    --cc=alan@linux.intel.com \
    --cc=dan.j.williams@intel.com \
    --cc=davem@davemloft.net \
    --cc=elena.reshetova@intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.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).