bpf: Fix too large copy from user in bpf_test_init
authorJesper Dangaard Brouer <brouer@redhat.com>
Mon, 18 May 2020 13:05:27 +0000 (15:05 +0200)
committerDaniel Borkmann <daniel@iogearbox.net>
Tue, 19 May 2020 15:56:34 +0000 (17:56 +0200)
commitd800bad67d4c21aaf11722f04e0f7547fb915ab5
treee7dbca49e7a5c1b6a8c5bd42acec8624903914df
parent59929cd1fec508a48ea2a04d8f2e4fdef907a2cd
bpf: Fix too large copy from user in bpf_test_init

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>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Andrii Nakryiko <andriin@fb.com>
Link: https://lore.kernel.org/bpf/158980712729.256597.6115007718472928659.stgit@firesoul
net/bpf/test_run.c