Netdev List
 help / color / mirror / Atom feed
From: Josh Poimboeuf <jpoimboe@redhat.com>
To: Jeremy Cline <jcline@redhat.com>
Cc: "David S . Miller" <davem@davemloft.net>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: Re: [PATCH 2/2] net: socket: Fix potential spectre v1 gadget in sock_is_registered
Date: Sun, 29 Jul 2018 08:59:06 -0500	[thread overview]
Message-ID: <20180729135906.lgqo5ue6it3hl2da@treble> (raw)
In-Reply-To: <20180727224302.5503-3-jcline@redhat.com>

On Fri, Jul 27, 2018 at 10:43:02PM +0000, Jeremy Cline wrote:
> 'family' can be a user-controlled value, so sanitize it after the bounds
> check to avoid speculative out-of-bounds access.
> 
> Cc: Josh Poimboeuf <jpoimboe@redhat.com>
> Cc: stable@vger.kernel.org
> Signed-off-by: Jeremy Cline <jcline@redhat.com>
> ---
>  net/socket.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/net/socket.c b/net/socket.c
> index f15d5cbb3ba4..608e29ae6baf 100644
> --- a/net/socket.c
> +++ b/net/socket.c
> @@ -2672,7 +2672,8 @@ EXPORT_SYMBOL(sock_unregister);
>  
>  bool sock_is_registered(int family)
>  {
> -	return family < NPROTO && rcu_access_pointer(net_families[family]);
> +	return family < NPROTO &&
> +		rcu_access_pointer(net_families[array_index_nospec(family, NPROTO)]);
>  }
>  
>  static int __init sock_init(void)

This is another one where I think it would be better to do the nospec
clamp higher up the call chain.  The untrusted 'family' value comes from
__sock_diag_cmd():

__sock_diag_cmd
  sock_load_diag_module
    sock_is_registered

That function has a bounds check, and also uses the value in some other
array accesses:

	if (req->sdiag_family >= AF_MAX)
		return -EINVAL;

	if (sock_diag_handlers[req->sdiag_family] == NULL)
		sock_load_diag_module(req->sdiag_family, 0);

	mutex_lock(&sock_diag_table_mutex);
	hndl = sock_diag_handlers[req->sdiag_family];
	...

So I think clamping 'req->sdiag_family' right after the bounds check
would be the way to go.

-- 
Josh

  reply	other threads:[~2018-07-29 13:59 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-27 22:43 [PATCH 0/2] net: socket: Fix potential spectre v1 gadgets Jeremy Cline
2018-07-27 22:43 ` [PATCH 1/2] net: socket: fix potential spectre v1 gadget in socketcall Jeremy Cline
2018-07-29 13:59   ` Josh Poimboeuf
2018-07-27 22:43 ` [PATCH 2/2] net: socket: Fix potential spectre v1 gadget in sock_is_registered Jeremy Cline
2018-07-29 13:59   ` Josh Poimboeuf [this message]
2018-07-29 15:59     ` Jeremy Cline
2018-08-13 17:16       ` Josh Poimboeuf
2018-08-13 19:03         ` Jeremy Cline
2018-07-29  5:45 ` [PATCH 0/2] net: socket: Fix potential spectre v1 gadgets David Miller

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=20180729135906.lgqo5ue6it3hl2da@treble \
    --to=jpoimboe@redhat.com \
    --cc=davem@davemloft.net \
    --cc=jcline@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=stable@vger.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