Skip to content

Commit 3297b35

Browse files
vdasuekyooo
authored andcommitted
tools/gethostlatency,slabratetop: read strings with bpf_probe_read_*_str
The BCC versions have the same defect as the libbpf-tools versions: the host argument and the slab cache name are read with the fixed-size bpf_probe_read_user()/bpf_probe_read_kernel() helpers, which copy past the source string's NUL terminator and leak adjacent memory into the map value and perf output. Use the NUL-stopping *_str variants so only the string is copied into the zero-initialized destination.
1 parent 12afbb3 commit 3297b35

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

tools/gethostlatency.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
u32 tid = (u32)pid_tgid;
6767
6868
if (bpf_get_current_comm(&val.comm, sizeof(val.comm)) == 0) {
69-
bpf_probe_read_user(&val.host, sizeof(val.host),
69+
bpf_probe_read_user_str(&val.host, sizeof(val.host),
7070
(void *)PT_REGS_PARM1(ctx));
7171
val.pid = pid;
7272
val.ts = bpf_ktime_get_ns();

tools/slabratetop.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
{
187187
struct info_t info = {};
188188
const char *name = cachep->name;
189-
bpf_probe_read_kernel(&info.name, sizeof(info.name), name);
189+
bpf_probe_read_kernel_str(&info.name, sizeof(info.name), name);
190190
191191
struct val_t *valp, zero = {};
192192
valp = counts.lookup_or_try_init(&info, &zero);

0 commit comments

Comments
 (0)