Skip to content

Commit 47a5fb1

Browse files
electronlsrKernel Patches Daemon
authored andcommitted
bpf: mark bpf_d_path() buffer as writeable
Commit 37cce22 ("bpf: verifier: Refactor helper access type tracking") started distinguishing read vs write accesses performed by helpers. The second argument of bpf_d_path() is a pointer to a buffer that the helper fills with the resulting path. However, its prototype currently uses ARG_PTR_TO_MEM without MEM_WRITE. Before 37cce22, helper accesses were conservatively treated as potential writes, so this mismatch did not cause issues. Since that commit, the verifier may incorrectly assume that the buffer contents are unchanged across the helper call and base its optimizations on this wrong assumption. This can lead to misbehaviour in BPF programs that read back the buffer, such as prefix comparisons on the returned path. Fix this by marking the second argument of bpf_d_path() as ARG_PTR_TO_MEM | MEM_WRITE so that the verifier correctly models the write to the caller-provided buffer. Fixes: 37cce22 ("bpf: verifier: Refactor helper access type tracking") Co-developed-by: Zesen Liu <[email protected]> Signed-off-by: Zesen Liu <[email protected]> Co-developed-by: Peili Gao <[email protected]> Signed-off-by: Peili Gao <[email protected]> Co-developed-by: Haoran Ni <[email protected]> Signed-off-by: Haoran Ni <[email protected]> Signed-off-by: Shuran Liu <[email protected]>
1 parent ad17a83 commit 47a5fb1

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

kernel/trace/bpf_trace.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,7 @@ static const struct bpf_func_proto bpf_d_path_proto = {
965965
.ret_type = RET_INTEGER,
966966
.arg1_type = ARG_PTR_TO_BTF_ID,
967967
.arg1_btf_id = &bpf_d_path_btf_ids[0],
968-
.arg2_type = ARG_PTR_TO_MEM,
968+
.arg2_type = ARG_PTR_TO_MEM | MEM_WRITE,
969969
.arg3_type = ARG_CONST_SIZE_OR_ZERO,
970970
.allowed = bpf_d_path_allowed,
971971
};

0 commit comments

Comments
 (0)