selftest/bpf: Check invalid length in test_xdp_update_frags
Update test_xdp_update_frags adding a test for a buffer size set to (MAX_SKB_FRAGS + 2) * PAGE_SIZE. The kernel is supposed to return -ENOMEM. Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Acked-by: Yonghong Song <yhs@fb.com> Link: https://lore.kernel.org/bpf/3e4afa0ee4976854b2f0296998fe6754a80b62e5.1644366736.git.lorenzo@kernel.org
This commit is contained in:
parent
85fbd23303
commit
a5a358abbc
|
@ -5,11 +5,12 @@
|
|||
static void test_xdp_update_frags(void)
|
||||
{
|
||||
const char *file = "./test_xdp_update_frags.o";
|
||||
int err, prog_fd, max_skb_frags, buf_size, num;
|
||||
struct bpf_program *prog;
|
||||
struct bpf_object *obj;
|
||||
int err, prog_fd;
|
||||
__u32 *offset;
|
||||
__u8 *buf;
|
||||
FILE *f;
|
||||
LIBBPF_OPTS(bpf_test_run_opts, topts);
|
||||
|
||||
obj = bpf_object__open(file);
|
||||
|
@ -99,6 +100,41 @@ static void test_xdp_update_frags(void)
|
|||
ASSERT_EQ(buf[7621], 0xbb, "xdp_update_frag buf[7621]");
|
||||
|
||||
free(buf);
|
||||
|
||||
/* test_xdp_update_frags: unsupported buffer size */
|
||||
f = fopen("/proc/sys/net/core/max_skb_frags", "r");
|
||||
if (!ASSERT_OK_PTR(f, "max_skb_frag file pointer"))
|
||||
goto out;
|
||||
|
||||
num = fscanf(f, "%d", &max_skb_frags);
|
||||
fclose(f);
|
||||
|
||||
if (!ASSERT_EQ(num, 1, "max_skb_frags read failed"))
|
||||
goto out;
|
||||
|
||||
/* xdp_buff linear area size is always set to 4096 in the
|
||||
* bpf_prog_test_run_xdp routine.
|
||||
*/
|
||||
buf_size = 4096 + (max_skb_frags + 1) * sysconf(_SC_PAGE_SIZE);
|
||||
buf = malloc(buf_size);
|
||||
if (!ASSERT_OK_PTR(buf, "alloc buf"))
|
||||
goto out;
|
||||
|
||||
memset(buf, 0, buf_size);
|
||||
offset = (__u32 *)buf;
|
||||
*offset = 16;
|
||||
buf[*offset] = 0xaa;
|
||||
buf[*offset + 15] = 0xaa;
|
||||
|
||||
topts.data_in = buf;
|
||||
topts.data_out = buf;
|
||||
topts.data_size_in = buf_size;
|
||||
topts.data_size_out = buf_size;
|
||||
|
||||
err = bpf_prog_test_run_opts(prog_fd, &topts);
|
||||
ASSERT_EQ(err, -ENOMEM,
|
||||
"unsupported buf size, possible non-default /proc/sys/net/core/max_skb_flags?");
|
||||
free(buf);
|
||||
out:
|
||||
bpf_object__close(obj);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue