Skip to content

Commit 15d4cf2

Browse files
Yonghong Songintel-lab-lkp
authored andcommitted
selftests/bpf: Fix dynptr/test_probe_read_user_str_dynptr test failure
When running bpf selftests with llvm18 compiler, I hit the following test failure: verify_success:PASS:dynptr_success__open 0 nsec verify_success:PASS:bpf_object__find_program_by_name 0 nsec verify_success:PASS:dynptr_success__load 0 nsec verify_success:PASS:test_run 0 nsec verify_success:FAIL:err unexpected err: actual 1 != expected 0 torvalds#91/19 dynptr/test_probe_read_user_str_dynptr:FAIL torvalds#91 dynptr:FAIL I did some analysis and found that the test failure is related to lib/strncpy_from_user.c function do_strncpy_from_user(): ... byte_at_a_time: while (max) { char c; unsafe_get_user(c,src+res, efault); dst[res] = c; if (!c) return res; res++; max--; } ... Depending on whether the character 'c' is '\0' or not, the return value 'res' could be different. In prog_tests/dynptr.c, we have char user_data[384] = {[0 ... 382] = 'a', '\0'}; the user_data[383] is '\0'. This will cause the following error in progs/dynptr_success.c: test_dynptr_probe_str_xdp: ... bpf_for(i, 0, ARRAY_SIZE(test_len)) { __u32 len = test_len[i]; cnt = bpf_read_dynptr_fn(&ptr_xdp, off, len, ptr); if (cnt != len) err = 1; <=== error happens here ... In the above particular case, len is 384 and cnt is 383. If user_data[384] is changed to char user_data[384] = {[0 ... 383] = 'a'}; The above error will not happen and the test will run successfully. Cc: Mykyta Yatsenko <[email protected]> Signed-off-by: Yonghong Song <[email protected]>
1 parent 9325d53 commit 15d4cf2

File tree

1 file changed

+1
-1
lines changed
  • tools/testing/selftests/bpf/prog_tests

1 file changed

+1
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ static struct {
4545

4646
static void verify_success(const char *prog_name, enum test_setup_type setup_type)
4747
{
48-
char user_data[384] = {[0 ... 382] = 'a', '\0'};
48+
char user_data[384] = {[0 ... 383] = 'a'};
4949
struct dynptr_success *skel;
5050
struct bpf_program *prog;
5151
struct bpf_link *link;

0 commit comments

Comments
 (0)