* [PATCH bpf-next] selftests/bpf: Fix cgroup_mprog_ordering failure due to uninitialized variable
@ 2025-06-11 16:21 Yonghong Song
2025-06-11 19:40 ` patchwork-bot+netdevbpf
0 siblings, 1 reply; 2+ messages in thread
From: Yonghong Song @ 2025-06-11 16:21 UTC (permalink / raw)
To: bpf
Cc: Alexei Starovoitov, Andrii Nakryiko, Daniel Borkmann, kernel-team,
Martin KaFai Lau
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>
---
tools/testing/selftests/bpf/prog_tests/cgroup_mprog_ordering.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
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();
--
2.47.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH bpf-next] selftests/bpf: Fix cgroup_mprog_ordering failure due to uninitialized variable
2025-06-11 16:21 [PATCH bpf-next] selftests/bpf: Fix cgroup_mprog_ordering failure due to uninitialized variable Yonghong Song
@ 2025-06-11 19:40 ` patchwork-bot+netdevbpf
0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-06-11 19:40 UTC (permalink / raw)
To: Yonghong Song; +Cc: bpf, ast, andrii, daniel, kernel-team, martin.lau
Hello:
This patch was applied to bpf/bpf-next.git (master)
by Alexei Starovoitov <ast@kernel.org>:
On Wed, 11 Jun 2025 09:21:03 -0700 you wrote:
> 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;
>
> [...]
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!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-06-11 19:40 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-11 16:21 [PATCH bpf-next] selftests/bpf: Fix cgroup_mprog_ordering failure due to uninitialized variable Yonghong Song
2025-06-11 19:40 ` patchwork-bot+netdevbpf
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.