]> git.baikalelectronics.ru Git - kernel.git/commit
selftests: bpf: Add a test when bpf_probe_read_kernel_str() returns EFAULT
authorAlban Crequy <albancrequy@linux.microsoft.com>
Thu, 10 Nov 2022 08:56:14 +0000 (09:56 +0100)
committerAndrii Nakryiko <andrii@kernel.org>
Fri, 11 Nov 2022 19:44:46 +0000 (11:44 -0800)
commit9a2eb0bc71d5ce691e2f06f1577ea585a635f6dc
tree09a8c1c050975d07822ecdf5fb8197be912d20c0
parentaacca799320b8b5cb6782b07e8e53b7ccda4e3ad
selftests: bpf: Add a test when bpf_probe_read_kernel_str() returns EFAULT

This commit tests previous fix of bpf_probe_read_kernel_str().

The BPF helper bpf_probe_read_kernel_str should return -EFAULT when
given a bad source pointer and the target buffer should only be modified
to make the string NULL terminated.

bpf_probe_read_kernel_str() was previously inserting a NULL before the
beginning of the dst buffer. This test should ensure that the
implementation stays correct for now on.

Without the fix, this test will fail as follows:
  $ cd tools/testing/selftests/bpf
  $ make
  $ sudo ./test_progs --name=varlen
  ...
  test_varlen:FAIL:check got 0 != exp 66

Signed-off-by: Alban Crequy <albancrequy@linux.microsoft.com>
Signed-off-by: Francis Laniel <flaniel@linux.microsoft.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Yonghong Song <yhs@fb.com>
Link: https://lore.kernel.org/bpf/20221110085614.111213-3-albancrequy@linux.microsoft.com
Changes v1 to v2:
- add ack tag
- fix my email
- rebase on bpf tree and tag for bpf tree
tools/testing/selftests/bpf/prog_tests/varlen.c
tools/testing/selftests/bpf/progs/test_varlen.c