All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf-next] bpf: fix too large copy from user in bpf_test_init
@ 2020-05-18 13:05 Jesper Dangaard Brouer
  2020-05-19  0:15 ` Andrii Nakryiko
  2020-05-19 17:22 ` Daniel Borkmann
  0 siblings, 2 replies; 3+ messages in thread
From: Jesper Dangaard Brouer @ 2020-05-18 13:05 UTC (permalink / raw)
  Cc: Jesper Dangaard Brouer, netdev, bpf, Daniel Borkmann,
	Alexei Starovoitov, David S. Miller

Commit bc56c919fce7 ("bpf: Add xdp.frame_sz in bpf_prog_test_run_xdp().")
recently changed bpf_prog_test_run_xdp() to use larger frames for XDP in
order to test tail growing frames (via bpf_xdp_adjust_tail) and to have
memory backing frame better resemble drivers.

The commit contains a bug, as it tries to copy the max data size from
userspace, instead of the size provided by userspace.  This cause XDP
unit tests to fail sporadically with EFAULT, an unfortunate behavior.
The fix is to only copy the size specified by userspace.

Fixes: bc56c919fce7 ("bpf: Add xdp.frame_sz in bpf_prog_test_run_xdp().")
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
---
 net/bpf/test_run.c |    8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/net/bpf/test_run.c b/net/bpf/test_run.c
index 30ba7d38941d..bfd4ccd80847 100644
--- a/net/bpf/test_run.c
+++ b/net/bpf/test_run.c
@@ -160,16 +160,20 @@ static void *bpf_test_init(const union bpf_attr *kattr, u32 size,
 			   u32 headroom, u32 tailroom)
 {
 	void __user *data_in = u64_to_user_ptr(kattr->test.data_in);
+	u32 user_size = kattr->test.data_size_in;
 	void *data;
 
 	if (size < ETH_HLEN || size > PAGE_SIZE - headroom - tailroom)
 		return ERR_PTR(-EINVAL);
 
+	if (user_size > size)
+		return ERR_PTR(-EMSGSIZE);
+
 	data = kzalloc(size + headroom + tailroom, GFP_USER);
 	if (!data)
 		return ERR_PTR(-ENOMEM);
 
-	if (copy_from_user(data + headroom, data_in, size)) {
+	if (copy_from_user(data + headroom, data_in, user_size)) {
 		kfree(data);
 		return ERR_PTR(-EFAULT);
 	}
@@ -486,8 +490,6 @@ int bpf_prog_test_run_xdp(struct bpf_prog *prog, const union bpf_attr *kattr,
 
 	/* XDP have extra tailroom as (most) drivers use full page */
 	max_data_sz = 4096 - headroom - tailroom;
-	if (size > max_data_sz)
-		return -EINVAL;
 
 	data = bpf_test_init(kattr, max_data_sz, headroom, tailroom);
 	if (IS_ERR(data))



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

* Re: [PATCH bpf-next] bpf: fix too large copy from user in bpf_test_init
  2020-05-18 13:05 [PATCH bpf-next] bpf: fix too large copy from user in bpf_test_init Jesper Dangaard Brouer
@ 2020-05-19  0:15 ` Andrii Nakryiko
  2020-05-19 17:22 ` Daniel Borkmann
  1 sibling, 0 replies; 3+ messages in thread
From: Andrii Nakryiko @ 2020-05-19  0:15 UTC (permalink / raw)
  To: Jesper Dangaard Brouer
  Cc: Networking, bpf, Daniel Borkmann, Alexei Starovoitov, David S. Miller

On Mon, May 18, 2020 at 6:08 AM Jesper Dangaard Brouer
<brouer@redhat.com> wrote:
>
> Commit bc56c919fce7 ("bpf: Add xdp.frame_sz in bpf_prog_test_run_xdp().")
> recently changed bpf_prog_test_run_xdp() to use larger frames for XDP in
> order to test tail growing frames (via bpf_xdp_adjust_tail) and to have
> memory backing frame better resemble drivers.
>
> The commit contains a bug, as it tries to copy the max data size from
> userspace, instead of the size provided by userspace.  This cause XDP
> unit tests to fail sporadically with EFAULT, an unfortunate behavior.
> The fix is to only copy the size specified by userspace.
>
> Fixes: bc56c919fce7 ("bpf: Add xdp.frame_sz in bpf_prog_test_run_xdp().")
> Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
> ---

LGTM.

Acked-by: Andrii Nakryiko <andriin@fb.com>

>  net/bpf/test_run.c |    8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
>

[...]

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

* Re: [PATCH bpf-next] bpf: fix too large copy from user in bpf_test_init
  2020-05-18 13:05 [PATCH bpf-next] bpf: fix too large copy from user in bpf_test_init Jesper Dangaard Brouer
  2020-05-19  0:15 ` Andrii Nakryiko
@ 2020-05-19 17:22 ` Daniel Borkmann
  1 sibling, 0 replies; 3+ messages in thread
From: Daniel Borkmann @ 2020-05-19 17:22 UTC (permalink / raw)
  To: Jesper Dangaard Brouer
  Cc: netdev, bpf, Daniel Borkmann, Alexei Starovoitov, David S. Miller

On 5/18/20 3:05 PM, Jesper Dangaard Brouer wrote:
> Commit bc56c919fce7 ("bpf: Add xdp.frame_sz in bpf_prog_test_run_xdp().")
> recently changed bpf_prog_test_run_xdp() to use larger frames for XDP in
> order to test tail growing frames (via bpf_xdp_adjust_tail) and to have
> memory backing frame better resemble drivers.
> 
> The commit contains a bug, as it tries to copy the max data size from
> userspace, instead of the size provided by userspace.  This cause XDP
> unit tests to fail sporadically with EFAULT, an unfortunate behavior.
> The fix is to only copy the size specified by userspace.
> 
> Fixes: bc56c919fce7 ("bpf: Add xdp.frame_sz in bpf_prog_test_run_xdp().")
> Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>

Applied, thanks!

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

end of thread, other threads:[~2020-05-19 17:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-18 13:05 [PATCH bpf-next] bpf: fix too large copy from user in bpf_test_init Jesper Dangaard Brouer
2020-05-19  0:15 ` Andrii Nakryiko
2020-05-19 17:22 ` Daniel Borkmann

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.