selftest/bpf: Test bpf_probe_read_user_str() strips trailing bytes after NUL
authorDaniel Xu <dxu@dxuuu.xyz>
Tue, 17 Nov 2020 20:05:46 +0000 (12:05 -0800)
committerAlexei Starovoitov <ast@kernel.org>
Thu, 19 Nov 2020 19:58:15 +0000 (11:58 -0800)
commitc8a36aedf3e24768e94d87fdcdd37684bd241c44
tree5eadde2770ff55b99a77d39e56e9b3dc322ce628
parent6fa6d28051e9fcaa1570e69648ea13a353a5d218
selftest/bpf: Test bpf_probe_read_user_str() strips trailing bytes after NUL

Previously, bpf_probe_read_user_str() could potentially overcopy the
trailing bytes after the NUL due to how do_strncpy_from_user() does the
copy in long-sized strides. The issue has been fixed in the previous
commit.

This commit adds a selftest that ensures we don't regress
bpf_probe_read_user_str() again.

Signed-off-by: Daniel Xu <dxu@dxuuu.xyz>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Song Liu <songliubraving@fb.com>
Acked-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/4d977508fab4ec5b7b574b85bdf8b398868b6ee9.1605642949.git.dxu@dxuuu.xyz
tools/testing/selftests/bpf/prog_tests/probe_read_user_str.c [new file with mode: 0644]
tools/testing/selftests/bpf/progs/test_probe_read_user_str.c [new file with mode: 0644]