]> git.baikalelectronics.ru Git - kernel.git/commit
bpf: Add selftests to cover packet access corner cases
authorMaxim Mikityanskiy <maximmi@nvidia.com>
Tue, 7 Dec 2021 08:15:21 +0000 (10:15 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 14 Dec 2021 09:57:23 +0000 (10:57 +0100)
commit3b3d7ed8cb0872d076b0dbec70c22a98ecf0d2cd
tree8b066a3344fd4a5b55a29da54375f3e44f6e7464
parent671fe261db42453394e93091ddc63524d8e4c2f7
bpf: Add selftests to cover packet access corner cases

commit 16c1aee54279611331eaded588d8cdd8772b7c66 upstream.

This commit adds BPF verifier selftests that cover all corner cases by
packet boundary checks. Specifically, 8-byte packet reads are tested at
the beginning of data and at the beginning of data_meta, using all kinds
of boundary checks (all comparison operators: <, >, <=, >=; both
permutations of operands: data + length compared to end, end compared to
data + length). For each case there are three tests:

1. Length is just enough for an 8-byte read. Length is either 7 or 8,
   depending on the comparison.

2. Length is increased by 1 - should still pass the verifier. These
   cases are useful, because they failed before commit 31853f3d9196
   ("bpf: Fix the off-by-two error in range markings").

3. Length is decreased by 1 - should be rejected by the verifier.

Some existing tests are just renamed to avoid duplication.

Signed-off-by: Maxim Mikityanskiy <maximmi@nvidia.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20211207081521.41923-1-maximmi@nvidia.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
tools/testing/selftests/bpf/verifier/xdp_direct_packet_access.c