Skip to content

Commit 3b55a9e

Browse files
Tao ChenAlexei Starovoitov
authored andcommitted
bpf: Clear user buf when bpf_d_path failed
The bpf_d_path() function may fail. If it does, clear the user buf, like bpf_probe_read etc. Signed-off-by: Tao Chen <[email protected]> Acked-by: Song Liu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 517b088 commit 3b55a9e

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

kernel/trace/bpf_trace.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -916,11 +916,14 @@ BPF_CALL_3(bpf_d_path, struct path *, path, char *, buf, u32, sz)
916916
* potentially broken verifier.
917917
*/
918918
len = copy_from_kernel_nofault(&copy, path, sizeof(*path));
919-
if (len < 0)
919+
if (len < 0) {
920+
memset(buf, 0, sz);
920921
return len;
922+
}
921923

922924
p = d_path(&copy, buf, sz);
923925
if (IS_ERR(p)) {
926+
memset(buf, 0, sz);
924927
len = PTR_ERR(p);
925928
} else {
926929
len = buf + sz - p;

0 commit comments

Comments
 (0)