From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1AE7C2FFDEA; Sat, 12 Sep 2026 14:22:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789222931; cv=none; b=ozEL49LH35/VXxENF1PgjuUXihIBbCqgT1bfkdKQmr5igdxUCnpr2QpRyiRzSBtqc8geYOL0fFa0ol0bYjOUmpWLhiRy1XVfXv3I5knzmITZUQl/66ulSO6+m7+HMJE/fNbkQbsyPO3KrIVLHV1o6wfe7QapMscJ493lZdqYwhU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789222931; c=relaxed/simple; bh=lfnN/+Pb0zwhM0B/rnnfRDtn6vw0fyagh2xd3usgNaM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rP/mBlPWpXL5zCS2wj1dLDgDAFfCy6dOhcBKmOK85DUSGqhns3IGvjijLHyFILBSludB7F0LV3R7wG7GO719fzq/nZqv2CdyVE2hQGFJ5Oc/XVFSNd7MjBgNyBP+Pn1Q3vVpY9LeEJzskOd1qL4RnLrKuYFtbWsRw367xkGP50s= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=c4IdLgzl; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="c4IdLgzl" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1BC651F000FF; Sat, 12 Sep 2026 14:22:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1789222930; bh=FeZ7D2dffXG2Avy1qGuN6ALa+Oz/LwpHA5ViCr1w50M=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=c4IdLgzl0hBTZWsqQTx9fzvKonc6Hwwtr4dShsj7NgZXSa/cwdVYiP9qQMfEj80NV eqrE7Rp7W6REObqoIJixmh3MKNqYrDojr2gXA0aA8tqiqs4l42uIcJ2B4zxp4z3gFH feN5TH27newFWLKeVN2Jd/LgR/yh/NsXz3mXemUQ= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Daniel Borkmann , Kumar Kartikeya Dwivedi , Sasha Levin Subject: [PATCH 6.6 0687/1424] bpf: Fix vmlinux BTF prep race in bpf_get_btf_vmlinux Date: Sat, 12 Sep 2026 08:51:59 +0200 Message-ID: <20260912065622.686127732@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260912065607.279695368@linuxfoundation.org> References: <20260912065607.279695368@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Daniel Borkmann [ Upstream commit 92863e678070f57c17c868e4bfa2441a5c61ad2b ] bpf_get_btf_vmlinux() lazily parses the vmlinux BTF under the bpf_verifier_lock, but publishes the result through a plain store and re-checks it through a plain lockless load. Nothing orders the stores initializing the struct btf inside btf_parse_vmlinux() against the store publishing the pointer: On a weakly ordered arch, a concurrent first-time caller taking the lockless fast path could in principle observe the pointer before the parsed contents are visible. The mutex_unlock() does not help such a reader given it only synchronizes with a later acquisition of the same lock. Thus, publish the pointer with smp_store_release() and read it on the fast path with smp_load_acquire(). Acquire semantics are needed rather than a dependency-ordered READ_ONCE(): btf_parse_vmlinux() also populates globals outside the returned object (e.g. bpf_ctx_convert.t). An address dependency would only order accesses performed through the pointer and not cover other globals. Fixes: 8580ac9404f6 ("bpf: Process in-kernel BTF") Signed-off-by: Daniel Borkmann Link: https://lore.kernel.org/bpf/20260708211537.371874-2-daniel@iogearbox.net Signed-off-by: Kumar Kartikeya Dwivedi Signed-off-by: Sasha Levin --- kernel/bpf/verifier.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 0a67f285f4b08..f7f5f54dc4485 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -20511,13 +20511,25 @@ static int check_attach_btf_id(struct bpf_verifier_env *env) struct btf *bpf_get_btf_vmlinux(void) { - if (!btf_vmlinux && IS_ENABLED(CONFIG_DEBUG_INFO_BTF)) { + /* Pairs with the smp_store_release() on the parse path below. */ + struct btf *btf = smp_load_acquire(&btf_vmlinux); + + if (!btf && IS_ENABLED(CONFIG_DEBUG_INFO_BTF)) { mutex_lock(&bpf_verifier_lock); - if (!btf_vmlinux) - btf_vmlinux = btf_parse_vmlinux(); + btf = btf_vmlinux; + if (!btf) { + btf = btf_parse_vmlinux(); + /* + * Order the parsed BTF contents and the globals the + * parse populated (e.g. bpf_ctx_convert.t) before + * the pointer publication. Pairs with the acquire + * on the lockless fast path above. + */ + smp_store_release(&btf_vmlinux, btf); + } mutex_unlock(&bpf_verifier_lock); } - return btf_vmlinux; + return btf; } int bpf_check(struct bpf_prog **prog, union bpf_attr *attr, bpfptr_t uattr, __u32 uattr_size) -- 2.53.0