From: William Tu <u9012063@gmail.com>
To: netdev@vger.kernel.org
Subject: [PATCH] bpf: fix size of copy_to_user in percpu map.
Date: Thu, 28 Jul 2016 17:42:21 -0700 [thread overview]
Message-ID: <1469752941-7140-1-git-send-email-u9012063@gmail.com> (raw)
The total size of value copy_to_user() writes to userspace should
be the (current number of cpu) * (value size), instead of
num_possible_cpus() * (value size). Found by samples/bpf/test_maps.c,
which always copies 512 byte to userspace, crashing the userspace
program stack.
Signed-off-by: William Tu <u9012063@gmail.com>
---
kernel/bpf/syscall.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index 228f962..47f738e 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -324,7 +324,8 @@ static int map_lookup_elem(union bpf_attr *attr)
goto free_value;
err = -EFAULT;
- if (copy_to_user(uvalue, value, value_size) != 0)
+ if (copy_to_user(uvalue, value,
+ map->value_size * num_online_cpus()) != 0)
goto free_value;
err = 0;
--
2.5.0
next reply other threads:[~2016-07-29 0:42 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-29 0:42 William Tu [this message]
2016-07-29 6:47 ` [PATCH] bpf: fix size of copy_to_user in percpu map Alexei Starovoitov
2016-07-29 7:54 ` Daniel Borkmann
2016-07-29 20:03 ` William Tu
2016-07-30 0:19 ` Daniel Borkmann
2016-07-30 5:23 ` William Tu
2016-07-30 5:34 ` Alexei Starovoitov
2016-07-31 15:25 ` William Tu
2016-08-01 16:07 ` Alexei Starovoitov
2016-08-01 16:30 ` William Tu
2016-08-12 16:58 ` William Tu
2016-08-12 23:08 ` Alexei Starovoitov
2016-08-19 1:38 ` William Tu
2016-08-24 23:46 ` William Tu
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=1469752941-7140-1-git-send-email-u9012063@gmail.com \
--to=u9012063@gmail.com \
--cc=netdev@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 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.