Skip to contentSkip to conversation

Patch "bpf: avoid copying junk bytes in bpf_get_current_comm()" has been added to the 4.4-stable tree

PATCH [email protected] 1 participant 1 message Apr 16, 2016

Subsystems (2)
lore
Share & tools
lore

[email protected]

author maintainer Applied
#0 lore raw

This is a note to let you know that I've just added the patch titled

bpf: avoid copying junk bytes in bpf_get_current_comm()

to the 4.4-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
bpf-avoid-copying-junk-bytes-in-bpf_get_current_comm.patch
and it can be found in the queue-4.4 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.

Quoted 1 line

From foo@baz Sat Apr 16 10:02:53 PDT 2016

From: Alexei Starovoitov <[email protected]>
Date: Wed, 9 Mar 2016 20:02:33 -0800
Subject: bpf: avoid copying junk bytes in bpf_get_current_comm()

From: Alexei Starovoitov <[email protected]>

[ Upstream commit cdc4e47da8f4c32eeb6b2061a8a834f4362a12b7 ]

Lots of places in the kernel use memcpy(buf, comm, TASK_COMM_LEN); but the result is typically passed to print("%s", buf) and extra bytes after zero don't cause any harm.
In bpf the result of bpf_get_current_comm() is used as the part of map key and was causing spurious hash map mismatches.
Use strlcpy() to guarantee zero-terminated string.
bpf verifier checks that output buffer is zero-initialized, so even for short task names the output buffer don't have junk bytes. Note it's not a security concern, since kprobe+bpf is root only.

Fixes ffeedafbf023 ("bpf: introduce current->pid, tgid, uid, gid, comm accessors")
---
 kernel/bpf/helpers.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/bpf/helpers.c +1 -1
@@ -166,7 +166,7 @@ static u64 bpf_get_current_comm(u64 r1,
 	if (!task)
 		return -EINVAL;
 
-	memcpy(buf, task->comm, min_t(size_t, size, sizeof(task->comm)));
+	strlcpy(buf, task->comm, min_t(size_t, size, sizeof(task->comm)));
 	return 0;
 }
 

Patches currently in stable-queue which might be from [email protected] are

queue-4.4/bpf-avoid-copying-junk-bytes-in-bpf_get_current_comm.patch