]> git.proxmox.com Git - mirror_ubuntu-focal-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)
committerStefan Bader <stefan.bader@canonical.com>
Thu, 3 Feb 2022 17:58:12 +0000 (18:58 +0100)
commitd9b446ec323e80566cc80e53d3844961267a1a8d
treebe6ccbce8b0d5c3941a53adc4dc184b32cdbf80a
parent8fdae2ef18b49376847cff1be663c407cd86a06a
bpf: Add selftests to cover packet access corner cases

BugLink: https://bugs.launchpad.net/bugs/1957007
commit b560b21f71eb4ef9dfc7c8ec1d0e4d7f9aa54b51 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 2fa7d94afc1a
   ("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>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
tools/testing/selftests/bpf/verifier/xdp_direct_packet_access.c