Skip to content

Commit ab86d0b

Browse files
tohojoAlexei Starovoitov
authored andcommitted
selftests/bpf: Update xdp_context_test_run test to check maximum metadata size
Update the selftest to check that the metadata size check takes the xdp_frame size into account in bpf_prog_test_run. The original check (for meta size 256) was broken because the data frame supplied was smaller than this, triggering a different EINVAL return. So supply a larger data frame for this test to make sure we actually exercise the check we think we are. Signed-off-by: Toke Høiland-Jørgensen <[email protected]> Reviewed-by: Amery Hung <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent e558cca commit ab86d0b

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

tools/testing/selftests/bpf/prog_tests/xdp_context_test_run.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ void test_xdp_context_test_run(void)
4747
struct test_xdp_context_test_run *skel = NULL;
4848
char data[sizeof(pkt_v4) + sizeof(__u32)];
4949
char bad_ctx[sizeof(struct xdp_md) + 1];
50+
char large_data[256];
5051
struct xdp_md ctx_in, ctx_out;
5152
DECLARE_LIBBPF_OPTS(bpf_test_run_opts, opts,
5253
.data_in = &data,
@@ -94,9 +95,6 @@ void test_xdp_context_test_run(void)
9495
test_xdp_context_error(prog_fd, opts, 4, sizeof(__u32), sizeof(data),
9596
0, 0, 0);
9697

97-
/* Meta data must be 255 bytes or smaller */
98-
test_xdp_context_error(prog_fd, opts, 0, 256, sizeof(data), 0, 0, 0);
99-
10098
/* Total size of data must be data_end - data_meta or larger */
10199
test_xdp_context_error(prog_fd, opts, 0, sizeof(__u32),
102100
sizeof(data) + 1, 0, 0, 0);
@@ -116,6 +114,16 @@ void test_xdp_context_test_run(void)
116114
test_xdp_context_error(prog_fd, opts, 0, sizeof(__u32), sizeof(data),
117115
0, 0, 1);
118116

117+
/* Meta data must be 216 bytes or smaller (256 - sizeof(struct
118+
* xdp_frame)). Test both nearest invalid size and nearest invalid
119+
* 4-byte-aligned size, and make sure data_in is large enough that we
120+
* actually hit the check on metadata length
121+
*/
122+
opts.data_in = large_data;
123+
opts.data_size_in = sizeof(large_data);
124+
test_xdp_context_error(prog_fd, opts, 0, 217, sizeof(large_data), 0, 0, 0);
125+
test_xdp_context_error(prog_fd, opts, 0, 220, sizeof(large_data), 0, 0, 0);
126+
119127
test_xdp_context_test_run__destroy(skel);
120128
}
121129

0 commit comments

Comments
 (0)