Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 BB55D2E425E for ; Tue, 7 Oct 2025 15:21:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759850512; cv=none; b=kVcgAQWhhSnH1NCD5KILtALYWOUyh8/oG6BnicKCYhRlmhbNyg977ksxp21Xq7BueeDzdXwaBINL9iLRex+yGLcoMryyorzBUFS142ZrufKmYoAI7mnZSRXxewteAye/tDimeUIwBfAFQiB05jefgZWTGCH96NVa7ucbSzeTp1M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759850512; c=relaxed/simple; bh=H29ymFugj1+CzQMfMuXoK+LCyKVxDg06IHCWSUwvHSw=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=bZc6jaf42oD5RnorWym93MKCzAdzMvscsv+n5NA2YDUV8QHDIhuiokyN3xvFfcTUa1qBTcmEvS2LYj8XFbOqdNImGtKIzocO4e09nnCTw758G+OZVZwghF9xdzWGcR4PLpihXNlTeuZUhg3N+TZkxwK8Pv18wRYRUwtSVbvVetM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=xk+T6fZU; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="xk+T6fZU" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 40ED0C4CEF1; Tue, 7 Oct 2025 15:21:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1759850512; bh=H29ymFugj1+CzQMfMuXoK+LCyKVxDg06IHCWSUwvHSw=; h=From:To:Cc:Subject:Date:Reply-to:From; b=xk+T6fZUuKzW1JV97rrBrmPtUEUaYD9+vD21Rwa60rtlLvjMuNDdr4MYrPnJZnaYi laIo4j5aOsbgE76Lnqymeav8UgALeicgFP+1m9xYo+ONo98KcnTE5tn9W1aQsJNPLP 6NXWXtBOun1NsZToht/usc/9Jp5X/mzWhbhWhAt0= From: Greg Kroah-Hartman To: linux-cve-announce@vger.kernel.org Cc: Greg Kroah-Hartman Subject: CVE-2023-53645: bpf: Make bpf_refcount_acquire fallible for non-owning refs Date: Tue, 7 Oct 2025 17:19:50 +0200 Message-ID: <2025100717-CVE-2023-53645-6c08@gregkh> X-Mailer: git-send-email 2.51.0 Precedence: bulk X-Mailing-List: linux-cve-announce@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Reply-to: , X-Developer-Signature: v=1; a=openpgp-sha256; l=5550; i=gregkh@linuxfoundation.org; h=from:subject:message-id; bh=zBT2SNn187zo+k55VMl0bk7fN7JKYG49vabl/0r5DIk=; b=owGbwMvMwCRo6H6F97bub03G02pJDBlP9Usv2Tpcz+uInd7bM39V8f6ppWLWB3f02jPIn1+yI Oh3m4p1RywLgyATg6yYIsuXbTxH91ccUvQytD0NM4eVCWQIAxenAEyERY5hwfXls5SuLp28RftM +CONKSHSzAeTmRjmWfYwnyqsSEopWFpxd1VEWeSUPn1zAA== X-Developer-Key: i=gregkh@linuxfoundation.org; a=openpgp; fpr=F4B60CC5BF78C2214A313DCB3147D40DDB2DFB29 Content-Transfer-Encoding: 8bit From: Greg Kroah-Hartman Description =========== In the Linux kernel, the following vulnerability has been resolved: bpf: Make bpf_refcount_acquire fallible for non-owning refs This patch fixes an incorrect assumption made in the original bpf_refcount series [0], specifically that the BPF program calling bpf_refcount_acquire on some node can always guarantee that the node is alive. In that series, the patch adding failure behavior to rbtree_add and list_push_{front, back} breaks this assumption for non-owning references. Consider the following program: n = bpf_kptr_xchg(&mapval, NULL); /* skip error checking */ bpf_spin_lock(&l); if(bpf_rbtree_add(&t, &n->rb, less)) { bpf_refcount_acquire(n); /* Failed to add, do something else with the node */ } bpf_spin_unlock(&l); It's incorrect to assume that bpf_refcount_acquire will always succeed in this scenario. bpf_refcount_acquire is being called in a critical section here, but the lock being held is associated with rbtree t, which isn't necessarily the lock associated with the tree that the node is already in. So after bpf_rbtree_add fails to add the node and calls bpf_obj_drop in it, the program has no ownership of the node's lifetime. Therefore the node's refcount can be decr'd to 0 at any time after the failing rbtree_add. If this happens before the refcount_acquire above, the node might be free'd, and regardless refcount_acquire will be incrementing a 0 refcount. Later patches in the series exercise this scenario, resulting in the expected complaint from the kernel (without this patch's changes): refcount_t: addition on 0; use-after-free. WARNING: CPU: 1 PID: 207 at lib/refcount.c:25 refcount_warn_saturate+0xbc/0x110 Modules linked in: bpf_testmod(O) CPU: 1 PID: 207 Comm: test_progs Tainted: G O 6.3.0-rc7-02231-g723de1a718a2-dirty #371 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.15.0-0-g2dd4b9b3f840-prebuilt.qemu.org 04/01/2014 RIP: 0010:refcount_warn_saturate+0xbc/0x110 Code: 6f 64 f6 02 01 e8 84 a3 5c ff 0f 0b eb 9d 80 3d 5e 64 f6 02 00 75 94 48 c7 c7 e0 13 d2 82 c6 05 4e 64 f6 02 01 e8 64 a3 5c ff <0f> 0b e9 7a ff ff ff 80 3d 38 64 f6 02 00 0f 85 6d ff ff ff 48 c7 RSP: 0018:ffff88810b9179b0 EFLAGS: 00010082 RAX: 0000000000000000 RBX: 0000000000000002 RCX: 0000000000000000 RDX: 0000000000000202 RSI: 0000000000000008 RDI: ffffffff857c3680 RBP: ffff88810027d3c0 R08: ffffffff8125f2a4 R09: ffff88810b9176e7 R10: ffffed1021722edc R11: 746e756f63666572 R12: ffff88810027d388 R13: ffff88810027d3c0 R14: ffffc900005fe030 R15: ffffc900005fe048 FS: 00007fee0584a700(0000) GS:ffff88811b280000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00005634a96f6c58 CR3: 0000000108ce9002 CR4: 0000000000770ee0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 PKRU: 55555554 Call Trace: bpf_refcount_acquire_impl+0xb5/0xc0 (rest of output snipped) The patch addresses this by changing bpf_refcount_acquire_impl to use refcount_inc_not_zero instead of refcount_inc and marking bpf_refcount_acquire KF_RET_NULL. For owning references, though, we know the above scenario is not possible and thus that bpf_refcount_acquire will always succeed. Some verifier bookkeeping is added to track "is input owning ref?" for bpf_refcount_acquire calls and return false from is_kfunc_ret_null for bpf_refcount_acquire on owning refs despite it being marked KF_RET_NULL. Existing selftests using bpf_refcount_acquire are modified where necessary to NULL-check its return value. [0]: https://lore.kernel.org/bpf/20230415201811.343116-1-davemarchevsky@fb.com/ The Linux kernel CVE team has assigned CVE-2023-53645 to this issue. Affected and fixed versions =========================== Issue introduced in 6.4 with commit d2dcc67df910dd85253a701b6a5b747f955d28f5 and fixed in 6.4.4 with commit d906d1b940b9dbf0a3e821d6b32a51c369273d91 Issue introduced in 6.4 with commit d2dcc67df910dd85253a701b6a5b747f955d28f5 and fixed in 6.5 with commit 7793fc3babe9fea908e57f7c187ea819f9fd7e95 Please see https://www.kernel.org for a full list of currently supported kernel versions by the kernel community. Unaffected versions might change over time as fixes are backported to older supported kernel versions. The official CVE entry at https://cve.org/CVERecord/?id=CVE-2023-53645 will be updated if fixes are backported, please check that for the most up to date information about this issue. Affected files ============== The file(s) affected by this issue are: kernel/bpf/helpers.c kernel/bpf/verifier.c tools/testing/selftests/bpf/progs/refcounted_kptr.c tools/testing/selftests/bpf/progs/refcounted_kptr_fail.c Mitigation ========== The Linux kernel CVE team recommends that you update to the latest stable kernel version for this, and many other bugfixes. Individual changes are never tested alone, but rather are part of a larger kernel release. Cherry-picking individual commits is not recommended or supported by the Linux kernel community at all. If however, updating to the latest release is impossible, the individual changes to resolve this issue can be found at these commits: https://git.kernel.org/stable/c/d906d1b940b9dbf0a3e821d6b32a51c369273d91 https://git.kernel.org/stable/c/7793fc3babe9fea908e57f7c187ea819f9fd7e95