Skip to contentSkip to conversation

selftests/bpf: Fix OOB read in dmabuf_collector

PATCH Applied T.J. Mercier 2 participants 3 messages Feb 25 – Feb 26

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

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.

Fixes ae5d2c59ecd7 ("selftests/bpf: Add test for dmabuf_iter")
---
 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
index 13cdb11fdeb2..9cbb7442646e 100644
@@ -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
#1 lore raw
Quoted 10 lines · T.J. Mercier

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.

Fixes ae5d2c59ecd7 ("selftests/bpf: Add test for dmabuf_iter")

Sukadev just let me know that Jerome Lee <[email protected]> should actually be the reporter here.

Quoted 21 lines
---
 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
index 13cdb11fdeb2..9cbb7442646e 100644
@@ -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

#2 lore raw
In reply to T.J. Mercier
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_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.

[...]

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