diff options
author | Yonghong Song <yonghong.song@linux.dev> | 2025-06-11 09:21:03 -0700 |
---|---|---|
committer | Alexei Starovoitov <ast@kernel.org> | 2025-06-11 12:32:50 -0700 |
commit | 517b088a846b3ce56b3ff07cdf24cd68c89b3a9e (patch) | |
tree | 0ce6bf82fa14bbde49098e04e16503d1be631196 | |
parent | c9b03a11005f6c1b8945a69f456653e8cdb70fdb (diff) |
selftests/bpf: Fix cgroup_mprog_ordering failure due to uninitialized variable
On arm64, the cgroup_mprog_ordering selftest failed with test_progs run
when building with clang compiler. The reason is due to socklen_t optlen
not initialized.
In kernel function do_ip_getsockopt(), we have
if (copy_from_sockptr(&len, optlen, sizeof(int)))
return -EFAULT;
if (len < 0)
return -EINVAL;
The above 'len' variable is a negative value and hence the test failed.
But the test is okay on x86_64. I checked the x86_64 asm code and I didn't
see explicit initialization of 'optlen' but its value is 0 so kernel
didn't return error. This should be a pure luck.
Fix the bug by initializing 'oplen' var properly.
Fixes: e422d5f118e4 ("selftests/bpf: Add two selftests for mprog API based cgroup progs")
Signed-off-by: Yonghong Song <yonghong.song@linux.dev>
Link: https://lore.kernel.org/r/20250611162103.1623692-1-yonghong.song@linux.dev
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
-rw-r--r-- | tools/testing/selftests/bpf/prog_tests/cgroup_mprog_ordering.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/tools/testing/selftests/bpf/prog_tests/cgroup_mprog_ordering.c b/tools/testing/selftests/bpf/prog_tests/cgroup_mprog_ordering.c index 4a4e9710b474..a36d2e968bc5 100644 --- a/tools/testing/selftests/bpf/prog_tests/cgroup_mprog_ordering.c +++ b/tools/testing/selftests/bpf/prog_tests/cgroup_mprog_ordering.c @@ -12,7 +12,7 @@ static int run_getsockopt_test(int cg_parent, int sock_fd, bool has_relative_fd) struct cgroup_preorder *skel = NULL; struct bpf_program *prog; __u8 *result, buf; - socklen_t optlen; + socklen_t optlen = 1; int err = 0; skel = cgroup_preorder__open_and_load(); |