From: Greg Kroah-Hartman <gregkh@linuxfoundation•org>
To: linux-kernel@vger•kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation•org>,
stable@vger•kernel.org, Mark Rutland <mark.rutland@arm•com>,
Alexei Starovoitov <ast@kernel•org>,
Dan Carpenter <dan.carpenter@oracle•com>,
Daniel Borkmann <daniel@iogearbox•net>,
Peter Zijlstra <peterz@infradead•org>,
netdev@vger•kernel.org, "David S. Miller" <davem@davemloft•net>,
Sasha Levin <alexander.levin@microsoft•com>
Subject: [PATCH 4.16 179/279] bpf: fix possible spectre-v1 in find_and_alloc_map()
Date: Mon, 18 Jun 2018 10:12:44 +0200 [thread overview]
Message-ID: <20180618080616.349022432@linuxfoundation.org> (raw)
In-Reply-To: <20180618080608.851973560@linuxfoundation.org>
4.16-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mark Rutland <mark.rutland@arm•com>
[ Upstream commit 9ef09e35e521bf0df5325cc9cffa726a8f5f3c1b ]
It's possible for userspace to control attr->map_type. Sanitize it when
using it as an array index to prevent an out-of-bounds value being used
under speculation.
Found by smatch.
Signed-off-by: Mark Rutland <mark.rutland@arm•com>
Cc: Alexei Starovoitov <ast@kernel•org>
Cc: Dan Carpenter <dan.carpenter@oracle•com>
Cc: Daniel Borkmann <daniel@iogearbox•net>
Cc: Peter Zijlstra <peterz@infradead•org>
Cc: netdev@vger•kernel.org
Acked-by: David S. Miller <davem@davemloft•net>
Signed-off-by: Daniel Borkmann <daniel@iogearbox•net>
Signed-off-by: Sasha Levin <alexander.levin@microsoft•com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation•org>
---
kernel/bpf/syscall.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -26,6 +26,7 @@
#include <linux/cred.h>
#include <linux/timekeeping.h>
#include <linux/ctype.h>
+#include <linux/nospec.h>
#define IS_FD_ARRAY(map) ((map)->map_type == BPF_MAP_TYPE_PROG_ARRAY || \
(map)->map_type == BPF_MAP_TYPE_PERF_EVENT_ARRAY || \
@@ -102,12 +103,14 @@ const struct bpf_map_ops bpf_map_offload
static struct bpf_map *find_and_alloc_map(union bpf_attr *attr)
{
const struct bpf_map_ops *ops;
+ u32 type = attr->map_type;
struct bpf_map *map;
int err;
- if (attr->map_type >= ARRAY_SIZE(bpf_map_types))
+ if (type >= ARRAY_SIZE(bpf_map_types))
return ERR_PTR(-EINVAL);
- ops = bpf_map_types[attr->map_type];
+ type = array_index_nospec(type, ARRAY_SIZE(bpf_map_types));
+ ops = bpf_map_types[type];
if (!ops)
return ERR_PTR(-EINVAL);
@@ -122,7 +125,7 @@ static struct bpf_map *find_and_alloc_ma
if (IS_ERR(map))
return map;
map->ops = ops;
- map->map_type = attr->map_type;
+ map->map_type = type;
return map;
}
parent reply other threads:[~2018-06-18 8:12 UTC|newest]
Thread overview: expand[flat|nested] mbox.gz Atom feed
[parent not found: <20180618080608.851973560@linuxfoundation.org>]
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=20180618080616.349022432@linuxfoundation.org \
--to=gregkh@linuxfoundation$(echo .)org \
--cc=alexander.levin@microsoft$(echo .)com \
--cc=ast@kernel$(echo .)org \
--cc=dan.carpenter@oracle$(echo .)com \
--cc=daniel@iogearbox$(echo .)net \
--cc=davem@davemloft$(echo .)net \
--cc=linux-kernel@vger$(echo .)kernel.org \
--cc=mark.rutland@arm$(echo .)com \
--cc=netdev@vger$(echo .)kernel.org \
--cc=peterz@infradead$(echo .)org \
--cc=stable@vger$(echo .)kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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