[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240628090517.17994-4-laoar.shao@gmail.com>
Date: Fri, 28 Jun 2024 17:05:10 +0800
From: Yafang Shao <laoar.shao@...il.com>
To: torvalds@...ux-foundation.org,
laoar.shao@...il.com
Cc: akpm@...ux-foundation.org,
alexei.starovoitov@...il.com,
audit@...r.kernel.org,
bpf@...r.kernel.org,
catalin.marinas@....com,
dri-devel@...ts.freedesktop.org,
ebiederm@...ssion.com,
linux-fsdevel@...r.kernel.org,
linux-mm@...ck.org,
linux-security-module@...r.kernel.org,
linux-trace-kernel@...r.kernel.org,
netdev@...r.kernel.org,
penguin-kernel@...ove.sakura.ne.jp,
rostedt@...dmis.org,
selinux@...r.kernel.org,
Quentin Monnet <qmo@...nel.org>
Subject: [PATCH v4 04/11] bpftool: Ensure task comm is always NUL-terminated
Let's explicitly ensure the destination string is NUL-terminated. This way,
it won't be affected by changes to the source string.
Signed-off-by: Yafang Shao <laoar.shao@...il.com>
Reviewed-by: Quentin Monnet <qmo@...nel.org>
---
tools/bpf/bpftool/pids.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/tools/bpf/bpftool/pids.c b/tools/bpf/bpftool/pids.c
index 9b898571b49e..23f488cf1740 100644
--- a/tools/bpf/bpftool/pids.c
+++ b/tools/bpf/bpftool/pids.c
@@ -54,6 +54,7 @@ static void add_ref(struct hashmap *map, struct pid_iter_entry *e)
ref = &refs->refs[refs->ref_cnt];
ref->pid = e->pid;
memcpy(ref->comm, e->comm, sizeof(ref->comm));
+ ref->comm[sizeof(ref->comm) - 1] = '\0';
refs->ref_cnt++;
return;
@@ -77,6 +78,7 @@ static void add_ref(struct hashmap *map, struct pid_iter_entry *e)
ref = &refs->refs[0];
ref->pid = e->pid;
memcpy(ref->comm, e->comm, sizeof(ref->comm));
+ ref->comm[sizeof(ref->comm) - 1] = '\0';
refs->ref_cnt = 1;
refs->has_bpf_cookie = e->has_bpf_cookie;
refs->bpf_cookie = e->bpf_cookie;
--
2.43.5
Powered by blists - more mailing lists