Skip to contentSkip to conversation

bpf: ensure all memory is initialized in bpf_get_current_comm

PATCH Applied Barret Rhoden 3 participants 4 messages Apr 5, 2023 – Apr 7, 2023

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

BPF helpers that take an ARG_PTR_TO_UNINIT_MEM must ensure that all of the memory is set, including beyond the end of the string.

---
 kernel/bpf/helpers.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/bpf/helpers.c +1 -1
index 5b278a38ae58..adffb2f87e44 100644
@@ -257,7 +257,7 @@ BPF_CALL_2(bpf_get_current_comm, char *, buf, u32, size)
 		goto err_clear;
 
 	/* Verifier guarantees that size > 0 */
-	strscpy(buf, task->comm, size);
+	strscpy_pad(buf, task->comm, size);
 	return 0;
 err_clear:
 	memset(buf, 0, size);
Signature · 1 line
2.40.0.348.gf938b09366-goog
#1 lore raw
Quoted 5 lines · Barret Rhoden

BPF helpers that take an ARG_PTR_TO_UNINIT_MEM must ensure that all of the memory is set, including beyond the end of the string.

The patch looks fine, but please rebase to bpf-next and resubmit with [PATCH bpf-next] subj, so it goes through BPF CI.

See Documentation/bpf/bpf_devel_QA.rst

#2 lore raw

PATCH 1/1 bpf: ensure all memory is initialized in bpf_get_current_comm

In reply to Barret Rhoden

BPF helpers that take an ARG_PTR_TO_UNINIT_MEM must ensure that all of the memory is set, including beyond the end of the string.

---
 kernel/bpf/helpers.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/bpf/helpers.c +1 -1
index 6be16db9f188..b6a5cda5bb59 100644
@@ -258,7 +258,7 @@ BPF_CALL_2(bpf_get_current_comm, char *, buf, u32, size)
 		goto err_clear;
 
 	/* Verifier guarantees that size > 0 */
-	strscpy(buf, task->comm, size);
+	strscpy_pad(buf, task->comm, size);
 	return 0;
 err_clear:
 	memset(buf, 0, size);
Signature · 1 line
2.40.0.577.gac1e443424-goog
#3 lore raw
This patch was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:

Hello:

This patch was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:

Quoted 7 lines · On Thu, 6 Apr 2023 20:18:08 -0400 you wrote:

BPF helpers that take an ARG_PTR_TO_UNINIT_MEM must ensure that all of the memory is set, including beyond the end of the string.

---
 kernel/bpf/helpers.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Here is the summary with links:
- [bpf-next] bpf: ensure all memory is initialized in bpf_get_current_comm

    https://git.kernel.org/bpf/bpf-next/c/f3f213497797

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html