Netdev List
 help / color / mirror / Atom feed
* [PATCH bpf] bpf: use array_index_nospec in find_prog_type
@ 2018-05-04  0:13 Daniel Borkmann
  2018-05-04  2:32 ` Alexei Starovoitov
  0 siblings, 1 reply; 2+ messages in thread
From: Daniel Borkmann @ 2018-05-04  0:13 UTC (permalink / raw)
  To: alexei.starovoitov; +Cc: netdev, Daniel Borkmann, Mark Rutland

Commit 9ef09e35e521 ("bpf: fix possible spectre-v1 in find_and_alloc_map()")
converted find_and_alloc_map() over to use array_index_nospec() to sanitize
map type that user space passes on map creation, and this patch does an
analogous conversion for progs in find_prog_type() as it's also passed from
user space when loading progs as attr->prog_type.

Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Cc: Mark Rutland <mark.rutland@arm.com>
---
 kernel/bpf/syscall.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index 8f43448..016ef90 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -874,11 +874,17 @@ static const struct bpf_prog_ops * const bpf_prog_types[] = {
 
 static int find_prog_type(enum bpf_prog_type type, struct bpf_prog *prog)
 {
-	if (type >= ARRAY_SIZE(bpf_prog_types) || !bpf_prog_types[type])
+	const struct bpf_prog_ops *ops;
+
+	if (type >= ARRAY_SIZE(bpf_prog_types))
+		return -EINVAL;
+	type = array_index_nospec(type, ARRAY_SIZE(bpf_prog_types));
+	ops = bpf_prog_types[type];
+	if (!ops)
 		return -EINVAL;
 
 	if (!bpf_prog_is_dev_bound(prog->aux))
-		prog->aux->ops = bpf_prog_types[type];
+		prog->aux->ops = ops;
 	else
 		prog->aux->ops = &bpf_offload_prog_ops;
 	prog->type = type;
-- 
2.9.5

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

* Re: [PATCH bpf] bpf: use array_index_nospec in find_prog_type
  2018-05-04  0:13 [PATCH bpf] bpf: use array_index_nospec in find_prog_type Daniel Borkmann
@ 2018-05-04  2:32 ` Alexei Starovoitov
  0 siblings, 0 replies; 2+ messages in thread
From: Alexei Starovoitov @ 2018-05-04  2:32 UTC (permalink / raw)
  To: Daniel Borkmann; +Cc: netdev, Mark Rutland

On Fri, May 04, 2018 at 02:13:57AM +0200, Daniel Borkmann wrote:
> Commit 9ef09e35e521 ("bpf: fix possible spectre-v1 in find_and_alloc_map()")
> converted find_and_alloc_map() over to use array_index_nospec() to sanitize
> map type that user space passes on map creation, and this patch does an
> analogous conversion for progs in find_prog_type() as it's also passed from
> user space when loading progs as attr->prog_type.
> 
> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
> Cc: Mark Rutland <mark.rutland@arm.com>

Applied to bpf tree, thanks Daniel.

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

end of thread, other threads:[~2018-05-04  2:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-05-04  0:13 [PATCH bpf] bpf: use array_index_nospec in find_prog_type Daniel Borkmann
2018-05-04  2:32 ` Alexei Starovoitov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox