From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796382109; b=1T4mwB+QIr/fE5v8Uz599pO6fUJLN+MbGB19zrjIB/yZH1DVyXHBKpnCdsQMMMUX9EJl SqD6hWgPUeBa+FY53e8Y1sXC9szNdbcIgprc3vedh2eL/ZUZ1n1eBcNK/3AFKA1Rouw/p l9Jdsf1WuYyhnJzsvKjRPUCmn2mlFvvHkOHLMurmnIdIeoQs7kKxZM5waTf/KgwczAInY cQAE0qvVZo6s7XUlb03wjT8HD8pfzcMiYXcPtlsdhJuRZvglNZ0uoEPweB1uqj5duYYK2 9bmh9aUIOrWabISRkJ7QYbuRGHSiu8tfdeL+lA/m7Ptq6XRa1KY7JWjerKRfCVuV9nA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796382109; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=zUhL3KhIB2J8ZH1T828cI0DG/8opHIXry8Wnz8kGwjI=; b=z58AGiDKIwKUwZretckU25X896A8w6A4ugAugHTJb2nWYEfRfHX6c+7cHXnKB0Fo8wpj a+wi9kb+9mlxJ2Fxzp4uv7s2tAMCJ0VWS4XYUkBYkniYK5nxNQj/g5UGYnXU5B6C9ghat ycR2jQmlf/bol0nfT6Zv1CwVUdCY2MiNmDo77kkL3ELh6XLPIghaKV6lnWXVEOP7mfCrS 8bNQNS4xWbxEl7MATiE3Qj9EhzlvmZFZkjoBQar7/Sf2pDWyuIr1n3MXErpPm4oeIin0q DiHVhjuiyuab0LyF4LdzgoqMMdRde5Nv2yxwP+AjTL/fqOLyLF7hmkRLkUOqccFMZ4w== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=n1jxI8OJ; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EBB6D606A32C; Fri, 4 Dec 2026 11:01:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=n1jxI8OJ Received: by smtp.kernel.org (Postfix) with ESMTPSA id 639E91F000C2; Fri, 4 Dec 2026 11:01:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796382108; bh=zUhL3KhIB2J8ZH1T828cI0DG/8opHIXry8Wnz8kGwjI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=n1jxI8OJ1r25GtjE22rRhT5edSygHxCHxm4lezWx+2iWfcz0O0yxo2d9zjXBw30Zb CcPvqe60y1LYjQX1X+/hcb+rR8abUvdhBiTMtlFBH9mixHpsz6RyRmTCoFF53u/iZY KQMP/FdRDCgUXVvXpXt4c9hrG+e5O2NUldkQ3YP4= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Alexei Starovoitov , Sasha Levin Subject: [PATCH 6.18 311/703] bpf: Limit reads of variables of the kernel Date: Fri, 4 Dec 2026 19:03:30 +0900 Message-ID: <20261204100636.055857556@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100627.522266145@linuxfoundation.org> References: <20261204100627.522266145@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Alexei Starovoitov [ Upstream commit 419c69483a62c9b91654e9fa32e3782efea5dc7c ] ld_imm64 of a variable that is not a struct gives readable memory, so do bpf_per_cpu_ptr() and bpf_this_cpu_ptr(). Many variables hold addresses, and CAP_BPF is enough to read them. The size comes from BTF, and that can be BTF of the program. Loads from such memory are not probed. Ask for CAP_PERFMON, as for the access to a struct. Addresses of functions and of per-cpu variables can be loaded as before. Take BTF of the kernel and of modules only, libbpf passes no other. Fixes: eaa6bcb71ef6 ("bpf: Introduce bpf_per_cpu_ptr()") Fixes: 541c3bad8dc5 ("bpf: Support BPF ksym variables in kernel modules") Signed-off-by: Alexei Starovoitov Link: https://patch.msgid.link/20261125032938.670542-29-alexei.starovoitov@gmail.com Signed-off-by: Sasha Levin --- kernel/bpf/helpers.c | 8 ++++---- kernel/bpf/verifier.c | 11 +++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c index 9057efcf73d01..d1cd4f301f05b 100644 --- a/kernel/bpf/helpers.c +++ b/kernel/bpf/helpers.c @@ -2007,10 +2007,6 @@ bpf_base_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog) return &bpf_spin_unlock_proto; case BPF_FUNC_jiffies64: return &bpf_jiffies64_proto; - case BPF_FUNC_per_cpu_ptr: - return &bpf_per_cpu_ptr_proto; - case BPF_FUNC_this_cpu_ptr: - return &bpf_this_cpu_ptr_proto; case BPF_FUNC_timer_init: return &bpf_timer_init_proto; case BPF_FUNC_timer_set_callback: @@ -2118,6 +2114,10 @@ bpf_base_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog) return &bpf_get_branch_snapshot_proto; case BPF_FUNC_find_vma: return &bpf_find_vma_proto; + case BPF_FUNC_per_cpu_ptr: + return &bpf_per_cpu_ptr_proto; + case BPF_FUNC_this_cpu_ptr: + return &bpf_this_cpu_ptr_proto; default: return NULL; } diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 4d76394cbac1a..c21799fbaf341 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -20986,6 +20986,12 @@ static int __check_pseudo_btf_id(struct bpf_verifier_env *env, } } + if (!percpu && !env->allow_ptr_leaks) { + verbose(env, "access to '%s' is allowed only to CAP_PERFMON and CAP_SYS_ADMIN\n", + sym_name); + return -EPERM; + } + type = t->type; t = btf_type_skip_modifiers(btf, type, NULL); if (percpu) { @@ -21031,6 +21037,11 @@ static int check_pseudo_btf_id(struct bpf_verifier_env *env, verbose(env, "invalid module BTF object FD specified.\n"); return -EINVAL; } + if (!btf_is_kernel(btf)) { + verbose(env, "BTF fd for ksym is not a kernel BTF\n"); + btf_put(btf); + return -EINVAL; + } } else { if (!btf_vmlinux) { verbose(env, "kernel is missing BTF, make sure CONFIG_DEBUG_INFO_BTF=y is specified in Kconfig.\n"); -- 2.53.0