selftests/bpf: Fix OOB read in dmabuf_collector
Subsystems (3)
PATCH 1/1 selftests/bpf: Fix OOB read in dmabuf_collector
Dmabuf name allocations can be less than DMA_BUF_NAME_LEN characters, but bpf_probe_read_kernel always tries to read exactly that many bytes. If a name is less than DMA_BUF_NAME_LEN characters, bpf_probe_read_kernel will read past the end. bpf_probe_read_kernel_str stops at the first NUL terminator so use it instead, like iter_dmabuf_for_each already does.
--- tools/testing/selftests/bpf/progs/dmabuf_iter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/bpf/progs/dmabuf_iter.c +1 -1
@@ -48,7 +48,7 @@ int dmabuf_collector(struct bpf_iter__dmabuf *ctx)/* Buffers are not required to be named */ if (pname) { -if (bpf_probe_read_kernel (name,sizeof (name), pname)) +if (bpf_probe_read_kernel_str (name,sizeof (name), pname) <0 )return 1 ;/* Name strings can be provided by userspace */
Signature · 1 line
2.53.0.414.gf7e9f6c205-goog
Quoted 10 lines · T.J. Mercier
Dmabuf name allocations can be less than
DMA_BUF_NAME_LENcharacters, butbpf_probe_read_kernelalways tries to read exactly that many bytes. If a name is less thanDMA_BUF_NAME_LENcharacters,bpf_probe_read_kernelwill read past the end.bpf_probe_read_kernel_strstops at the first NUL terminator so use it instead, likeiter_dmabuf_for_eachalready does.Fixes ae5d2c59ecd7 ("selftests/bpf: Add test for dmabuf_iter")Reported-by Sukadev Bhattiprolu <[email protected]>
Sukadev just let me know that Jerome Lee <[email protected]> should actually be the reporter here.
Quoted 21 lines
Signed-off-by T.J. Mercier <[email protected]>--- tools/testing/selftests/bpf/progs/dmabuf_iter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/testing/selftests/bpf/progs/dmabuf_iter.c +1
-2@@ -48,7 +48,7 @@ int dmabuf_collector(struct bpf_iter__dmabuf *ctx)/* Buffers are not required to be named */ if (pname) { -if (bpf_probe_read_kernel (name,sizeof (name), pname)) +if (bpf_probe_read_kernel_str (name,sizeof (name), pname) <0 )return 1 ;/* Name strings can be provided by userspace */ --2.53.0.414.gf7e9f6c205-goog
This patch was applied to bpf/bpf.git (master) by Alexei Starovoitov <[email protected]>:
Hello:
This patch was applied to bpf/bpf.git (master)
by Alexei Starovoitov <[email protected]>:
Quoted 8 lines · On Tue, 24 Feb 2026 16:33:48 -0800 you wrote:
Dmabuf name allocations can be less than
DMA_BUF_NAME_LENcharacters, butbpf_probe_read_kernelalways tries to read exactly that many bytes. If a name is less thanDMA_BUF_NAME_LENcharacters,bpf_probe_read_kernelwill read past the end.bpf_probe_read_kernel_strstops at the first NUL terminator so use it instead, likeiter_dmabuf_for_eachalready does.[...]
Here is the summary with links:
- [bpf] selftests/bpf: Fix OOB read in dmabuf_collector
https://git.kernel.org/bpf/bpf/c/6881af27f9ea
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html