selftests/bpf: Fix cgroup_mprog_ordering failure due to uninitialized variable
Subsystems (3)
Yonghong Song
reviewerPATCH 1/1 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.
--- tools/testing/selftests/bpf/prog_tests/cgroup_mprog_ordering.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/bpf/prog_tests/cgroup_mprog_ordering.c +1 -1
@@ -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 ();
Signature · 1 line
2.47.1
This patch was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:
Hello:
This patch was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:
Quoted 4 lines · On Wed, 11 Jun 2025 09:21:03 -0700 you wrote:
On arm64, the
cgroup_mprog_orderingselftest failed withtest_progsrun when building with clang compiler. The reason is due tosocklen_toptlen not initialized.
Quoted 8 lines
In kernel function
do_ip_getsockopt(), we haveif (copy_from_sockptr(&len, optlen, sizeof(int))) return -EFAULT; if (len < 0) return -EINVAL;[...]
Here is the summary with links:
- [bpf-next] selftests/bpf: Fix cgroup_mprog_ordering failure due to uninitialized variable
https://git.kernel.org/bpf/bpf-next/c/517b088a846b
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html