blob: 1a0ecf15808faa9923a3866198e2c014e1eea9bc [file] [log] [blame]
From 5327d82d1fe46038bed1e425cfa700decdcea448 Mon Sep 17 00:00:00 2001
From: Johannes Krude <>
Date: Wed, 12 Feb 2020 20:32:27 +0100
Subject: [PATCH] bpf, offload: Replace bitwise AND by logical AND in
commit e20d3a055a457a10a4c748ce5b7c2ed3173a1324 upstream.
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.
Fixes: fcfb126defda ("bpf: add new jited info fields in bpf_dev_offload and bpf_prog_info")
Signed-off-by: Johannes Krude <>
Signed-off-by: Daniel Borkmann <>
Acked-by: Jakub Kicinski <>
Signed-off-by: Paul Gortmaker <>
diff --git a/kernel/bpf/offload.c b/kernel/bpf/offload.c
index ba635209ae9a..1853aa420f2f 100644
--- a/kernel/bpf/offload.c
+++ b/kernel/bpf/offload.c
@@ -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)) {