bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] bpf: Specify access type of bpf_sysctl_get_name args
@ 2025-05-27 16:54 Jerome Marchand
  2025-05-27 19:56 ` Yonghong Song
                   ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: Jerome Marchand @ 2025-05-27 16:54 UTC (permalink / raw)
  To: bpf
  Cc: Martin KaFai Lau, Alexei Starovoitov, Daniel Borkmann,
	Andrii Nakryiko, linux-kernel, Jerome Marchand

The second argument of bpf_sysctl_get_name() helper is a pointer to a
buffer that is being written to. However that isn't specify in the
prototype.

Until commit 37cce22dbd51a ("bpf: verifier: Refactor helper access
type tracking"), all helper accesses were considered as a possible
write access by the verifier, so no big harm was done. However, since
then, the verifier might make wrong asssumption about the content of
that address which might lead it to make faulty optimizations (such as
removing code that was wrongly labeled dead). This is what happens in
test_sysctl selftest to the tests related to sysctl_get_name.

Correctly mark the second argument of bpf_sysctl_get_name() as
ARG_PTR_TO_UNINIT_MEM.

Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
---
 kernel/bpf/cgroup.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/bpf/cgroup.c b/kernel/bpf/cgroup.c
index 84f58f3d028a3..09c02a592d24a 100644
--- a/kernel/bpf/cgroup.c
+++ b/kernel/bpf/cgroup.c
@@ -2104,7 +2104,7 @@ static const struct bpf_func_proto bpf_sysctl_get_name_proto = {
 	.gpl_only	= false,
 	.ret_type	= RET_INTEGER,
 	.arg1_type	= ARG_PTR_TO_CTX,
-	.arg2_type	= ARG_PTR_TO_MEM,
+	.arg2_type	= ARG_PTR_TO_UNINIT_MEM,
 	.arg3_type	= ARG_CONST_SIZE,
 	.arg4_type	= ARG_ANYTHING,
 };
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2025-06-10 17:17 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-27 16:54 [PATCH] bpf: Specify access type of bpf_sysctl_get_name args Jerome Marchand
2025-05-27 19:56 ` Yonghong Song
2025-05-28  9:09   ` Jerome Marchand
2025-05-28 17:41     ` Yonghong Song
2025-05-27 21:39 ` Eduard Zingerman
2025-05-28 12:47   ` Jerome Marchand
2025-05-28 16:41     ` Eduard Zingerman
2025-05-29 11:35       ` Jerome Marchand
2025-06-10  9:19 ` [PATCH v2 0/2] " Jerome Marchand
2025-06-10  9:19   ` [PATCH v2 1/2] " Jerome Marchand
2025-06-10 16:41     ` Yonghong Song
2025-06-10  9:19   ` [PATCH v2 2/2] selftests/bpf: Convert test_sysctl to prog_tests Jerome Marchand
2025-06-10 17:16     ` Yonghong Song

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).