linux-trace-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf-next] bpf: clear user buf when bpf_d_path failed
@ 2025-06-11 15:48 Tao Chen
  2025-06-11 17:20 ` Song Liu
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Tao Chen @ 2025-06-11 15:48 UTC (permalink / raw)
  To: kpsingh, mattbobrowski, ast, daniel, andrii, martin.lau, eddyz87,
	song, yonghong.song, john.fastabend, sdf, haoluo, jolsa, rostedt,
	mhiramat, mathieu.desnoyers
  Cc: bpf, linux-kernel, linux-trace-kernel, Tao Chen

The bpf_d_path() function may fail. If it does,
clear the user buf, like bpf_probe_read etc.

Signed-off-by: Tao Chen <chen.dylane@linux.dev>
---
 kernel/trace/bpf_trace.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index 0998cbbb963..bb1003cb271 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -916,11 +916,14 @@ BPF_CALL_3(bpf_d_path, struct path *, path, char *, buf, u32, sz)
 	 * potentially broken verifier.
 	 */
 	len = copy_from_kernel_nofault(&copy, path, sizeof(*path));
-	if (len < 0)
+	if (len < 0) {
+		memset(buf, 0, sz);
 		return len;
+	}
 
 	p = d_path(&copy, buf, sz);
 	if (IS_ERR(p)) {
+		memset(buf, 0, sz);
 		len = PTR_ERR(p);
 	} else {
 		len = buf + sz - p;
-- 
2.48.1


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

end of thread, other threads:[~2025-06-13  2:37 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-11 15:48 [PATCH bpf-next] bpf: clear user buf when bpf_d_path failed Tao Chen
2025-06-11 17:20 ` Song Liu
2025-06-11 19:40 ` patchwork-bot+netdevbpf
2025-06-12 21:29 ` Andrii Nakryiko
2025-06-12 21:39   ` Alexei Starovoitov
2025-06-12 23:27     ` Andrii Nakryiko
2025-06-12 23:56       ` Alexei Starovoitov
2025-06-13  0:06         ` Andrii Nakryiko
2025-06-13  2:37           ` Tao Chen

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).