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=1796380472; b=Le4yXwM4+icUN+C9JzgshzvXvvKH7Z9X78WbKNonvfNTPlt8sfqSct8wyvLOlFn68p8t phv/h4r2GPAAEDS6sFouyQOA1R+3A/WT0k2GFfxmkjYXYHlfBjB2GGUMGVDVqdmVQALrH RUfLX2jVFFFxGHQ4njiouYgDLL8HwC09uwc5iMH2Y3LKJrdNPpcsWKxiYrCxpE4FkyFFw HyS9tL1THvfE/uyHjY1ApYVOg0BGtObptBefIiSvLL8nDjR1c3BxauTG+86TzsAY/N4f0 UUhU8k4YdBZkk5FlRvRvV15cYNYuM+FBYxSAdsG3cL8FtgK50bWRl20ge7hmsWgx/VQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796380472; 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=P2O8QB9MPDwzjNscGo1fbRUojMUh8LM3dKv46esmB5E=; b=E0RJGXnLDlHLNhSuyO1uPKnrnwIjYUulBNrXJVRMnqJx4pZ+3Mw8W7GdGENRmo7FAkWC rl/CcLGTA8NKMVjnkfGLvxrjRlJyCjtKLj1IHdUlCuDZzlNERrrL1Kp200NUgBFARw48Z XsWbzWL44P3N0+apapMJBeOrn+ztjXzI8c6JCEPzePE05LwW22SUVXyatTfmBLsf/ugPj /BEWC53wZjhZnzJNEclKBxMO0NSNtzAhxW23JM1w6WZ1OMK1VhvNtyavPmsjs3x9u9+IN VHlK/vOaDYsecrwqTh9TjsKCC/GSmPYNICVClH8jdjTsKEFfaFqGVtBmQE+qK7/8KSg== 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=an3Fk1Mg; 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 D1737606A33B; Fri, 4 Dec 2026 10:34:32 +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=an3Fk1Mg Received: by smtp.kernel.org (Postfix) with ESMTPSA id E72DF1F000C2; Fri, 4 Dec 2026 10:34:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796380472; bh=P2O8QB9MPDwzjNscGo1fbRUojMUh8LM3dKv46esmB5E=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=an3Fk1Mgs7SGZ/9yjkO1+VjnHC8L9kU2YCHQw3pGg/fjx74AfLxR8Gi83H2lvRdzc HpE94T/Nkv1tEDZo3HUhdos8zGZD/I0BN9R0nbu6FiWjIrtB9uoTceF11aEl3L91jH SMCUs2udumKtspeIr/SVineKBTZXSWQS9NCaNwGA= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Alexei Starovoitov , Sasha Levin Subject: [PATCH 7.3 288/742] bpf: Limit reads of variables of the kernel Date: Fri, 4 Dec 2026 19:02:32 +0900 Message-ID: <20261204100642.692938069@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@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 7.3-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 aaa646b5be736..daef14d343aad 100644 --- a/kernel/bpf/helpers.c +++ b/kernel/bpf/helpers.c @@ -2137,10 +2137,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: @@ -2244,6 +2240,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 7667982d4e38e..d7de38f8e9203 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -18992,6 +18992,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) { @@ -19037,6 +19043,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