Skip to contentSkip to conversation

bpf_prog_offload_info_fill: replace bitwise AND by logical AND

PATCH Applied Johannes Krude 3 participants 3 messages Feb 12, 2020 – Feb 17, 2020

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

PATCH 1/1 bpf_prog_offload_info_fill: replace bitwise AND by logical AND

This if guards whether user-space wants a copy of the offload-jited bytecode and whether this bytecode exists. By erroneously doing a bitwise AND instead of a logical AND on user- and kernel-space buffer-size can lead to no data being copied to user-space especially when user-space size is a power of two and bigger then the kernel-space buffer.

---
 kernel/bpf/offload.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/bpf/offload.c +1 -1
index 2c5dc6541..bd09290e3 100644
@@ -321,7 +321,7 @@ int bpf_prog_offload_info_fill(struct bpf_prog_info *info,
 
 	ulen = info->jited_prog_len;
 	info->jited_prog_len = aux->offload->jited_len;
-	if (info->jited_prog_len & ulen) {
+	if (info->jited_prog_len && ulen) {
 		uinsns = u64_to_user_ptr(info->jited_prog_insns);
 		ulen = min_t(u32, info->jited_prog_len, ulen);
 		if (copy_to_user(uinsns, aux->offload->jited_image, ulen)) {
Signature · 1 line
2.24.0
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 7 lines · Johannes Krude

This if guards whether user-space wants a copy of the offload-jited bytecode and whether this bytecode exists. By erroneously doing a bitwise AND instead of a logical AND on user- and kernel-space buffer-size can lead to no data being copied to user-space especially when user-space size is a power of two and bigger then the kernel-space buffer.

Thank you for the fix, in the future please provide a Fixes tag and include the tree name in the PATCH tag, e.g. [PATCH bpf], or [PATCH net] etc.

Fixes fcfb126defda ("bpf: add new jited info fields in bpf_dev_offload and bpf_prog_info")
maintainer Applied
#2 lore raw
In reply to Johannes Krude
Quoted 7 lines · Johannes Krude

This if guards whether user-space wants a copy of the offload-jited bytecode and whether this bytecode exists. By erroneously doing a bitwise AND instead of a logical AND on user- and kernel-space buffer-size can lead to no data being copied to user-space especially when user-space size is a power of two and bigger then the kernel-space buffer.

Applied, thanks!