bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* bpf: ensure all memory is initialized in bpf_get_current_comm
@ 2023-04-05 22:52 Barret Rhoden
  2023-04-06 23:00 ` Alexei Starovoitov
  2023-04-07  0:18 ` [PATCH bpf-next] " Barret Rhoden
  0 siblings, 2 replies; 4+ messages in thread
From: Barret Rhoden @ 2023-04-05 22:52 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko
  Cc: Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend,
	KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa, bpf,
	linux-kernel

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.

Signed-off-by: Barret Rhoden <brho@google.com>
---
 kernel/bpf/helpers.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c
index 5b278a38ae58..adffb2f87e44 100644
--- a/kernel/bpf/helpers.c
+++ b/kernel/bpf/helpers.c
@@ -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);
-- 
2.40.0.348.gf938b09366-goog


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: bpf: ensure all memory is initialized in bpf_get_current_comm
  2023-04-05 22:52 bpf: ensure all memory is initialized in bpf_get_current_comm Barret Rhoden
@ 2023-04-06 23:00 ` Alexei Starovoitov
  2023-04-07  0:18 ` [PATCH bpf-next] " Barret Rhoden
  1 sibling, 0 replies; 4+ messages in thread
From: Alexei Starovoitov @ 2023-04-06 23:00 UTC (permalink / raw)
  To: Barret Rhoden
  Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend,
	KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa, bpf, LKML

On Wed, Apr 5, 2023 at 3:53 PM Barret Rhoden <brho@google.com> 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.
>
> Signed-off-by: Barret Rhoden <brho@google.com>

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH bpf-next] bpf: ensure all memory is initialized in bpf_get_current_comm
  2023-04-05 22:52 bpf: ensure all memory is initialized in bpf_get_current_comm Barret Rhoden
  2023-04-06 23:00 ` Alexei Starovoitov
@ 2023-04-07  0:18 ` Barret Rhoden
  2023-04-07  2:00   ` patchwork-bot+netdevbpf
  1 sibling, 1 reply; 4+ messages in thread
From: Barret Rhoden @ 2023-04-07  0:18 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko
  Cc: Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend,
	KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa, netdev, bpf,
	linux-kernel

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.

Signed-off-by: Barret Rhoden <brho@google.com>
---
 kernel/bpf/helpers.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c
index 6be16db9f188..b6a5cda5bb59 100644
--- a/kernel/bpf/helpers.c
+++ b/kernel/bpf/helpers.c
@@ -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);
-- 
2.40.0.577.gac1e443424-goog


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH bpf-next] bpf: ensure all memory is initialized in bpf_get_current_comm
  2023-04-07  0:18 ` [PATCH bpf-next] " Barret Rhoden
@ 2023-04-07  2:00   ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-04-07  2:00 UTC (permalink / raw)
  To: Barret Rhoden
  Cc: ast, daniel, andrii, martin.lau, song, yhs, john.fastabend,
	kpsingh, sdf, haoluo, jolsa, netdev, bpf, linux-kernel

Hello:

This patch was applied to bpf/bpf-next.git (master)
by Alexei Starovoitov <ast@kernel.org>:

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.
> 
> Signed-off-by: Barret Rhoden <brho@google.com>
> ---
>  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!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-04-07  2:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-05 22:52 bpf: ensure all memory is initialized in bpf_get_current_comm Barret Rhoden
2023-04-06 23:00 ` Alexei Starovoitov
2023-04-07  0:18 ` [PATCH bpf-next] " Barret Rhoden
2023-04-07  2:00   ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).