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 E155C18F2F7 for ; Tue, 5 Nov 2024 10:09:44 +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=1730801385; cv=none; b=I7gVGQZvDY0t8LN+SYL8Ih5hZVOTrG363Akn0Bz1EkCDBGE3vu/tbdYUTkdCtJoF3weXGFXPUZIk/hzDkeqvTUrq2m4MHGa7+WHhT4t73Z+8iM2p4CdT4wtthXwXjqdJVO3me8rohg47Fh4MuXQ/lf/7V0vd57oqtRHJiuaiDYE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730801385; c=relaxed/simple; bh=FXgCdICcLhz0QWSoY8Sjpi/Or/70gCIEWHzbj8Pyonw=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=t0Smws+3Dc+CLSS1K7Z9kP+qBNPvf4QffxJZwIZOa7kvpJr+lh/e4psy2IoKxNBXsVpNEsT3otE0cAfMTwKzy402nNGZBdyHTCKeQi8azg/MPza8+93TTTtvOhn+V/xmLSVlke8sGBlx4dLLRm23tA6xAk04ZghIbGueGdal6lg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=Xz4YesGF; 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="Xz4YesGF" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 172A2C4CECF; Tue, 5 Nov 2024 10:09:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1730801384; bh=FXgCdICcLhz0QWSoY8Sjpi/Or/70gCIEWHzbj8Pyonw=; h=From:To:Cc:Subject:Date:Reply-to:From; b=Xz4YesGFjdi0rWei0HQCb//YQm5wBqFPL+8nJKrueO6qUBTO2M9zCQ9EhpAhuqL0j 1C1ERxKRpYWlAK/se19k8mwBLSXiGMCvVdVXv21Rn9/IwBSdyDGcDLdStW0GBaWYu8 tUH/nmn++TXn/BU275PVz9DPSjYQzeq8e3zQx6LM= From: Greg Kroah-Hartman To: linux-cve-announce@vger.kernel.org Cc: Greg Kroah-Hartman Subject: CVE-2023-52920: bpf: support non-r10 register spill/fill to/from stack in precision tracking Date: Tue, 5 Nov 2024 11:09:19 +0100 Message-ID: <2024110518-CVE-2023-52920-17f6@gregkh> X-Mailer: git-send-email 2.47.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=4133; i=gregkh@linuxfoundation.org; h=from:subject:message-id; bh=FXgCdICcLhz0QWSoY8Sjpi/Or/70gCIEWHzbj8Pyonw=; b=owGbwMvMwCRo6H6F97bub03G02pJDOma786FdO6MEluotPhhodJG/VPnkgye3b8lds2hmrf5c Fpa7vWnHbEsDIJMDLJiiixftvEc3V9xSNHL0PY0zBxWJpAhDFycAjCRrZEMC9ZGHdjJY7LkldGa pW1LHDfe97v9dB3Dgv4LTgp1R1luTldcInjBVv3ebeVl5wA= X-Developer-Key: i=gregkh@linuxfoundation.org; a=openpgp; fpr=F4B60CC5BF78C2214A313DCB3147D40DDB2DFB29 Content-Transfer-Encoding: 8bit Description =========== In the Linux kernel, the following vulnerability has been resolved: bpf: support non-r10 register spill/fill to/from stack in precision tracking Use instruction (jump) history to record instructions that performed register spill/fill to/from stack, regardless if this was done through read-only r10 register, or any other register after copying r10 into it *and* potentially adjusting offset. To make this work reliably, we push extra per-instruction flags into instruction history, encoding stack slot index (spi) and stack frame number in extra 10 bit flags we take away from prev_idx in instruction history. We don't touch idx field for maximum performance, as it's checked most frequently during backtracking. This change removes basically the last remaining practical limitation of precision backtracking logic in BPF verifier. It fixes known deficiencies, but also opens up new opportunities to reduce number of verified states, explored in the subsequent patches. There are only three differences in selftests' BPF object files according to veristat, all in the positive direction (less states). File Program Insns (A) Insns (B) Insns (DIFF) States (A) States (B) States (DIFF) -------------------------------------- ------------- --------- --------- ------------- ---------- ---------- ------------- test_cls_redirect_dynptr.bpf.linked3.o cls_redirect 2987 2864 -123 (-4.12%) 240 231 -9 (-3.75%) xdp_synproxy_kern.bpf.linked3.o syncookie_tc 82848 82661 -187 (-0.23%) 5107 5073 -34 (-0.67%) xdp_synproxy_kern.bpf.linked3.o syncookie_xdp 85116 84964 -152 (-0.18%) 5162 5130 -32 (-0.62%) Note, I avoided renaming jmp_history to more generic insn_hist to minimize number of lines changed and potential merge conflicts between bpf and bpf-next trees. Notice also cur_hist_entry pointer reset to NULL at the beginning of instruction verification loop. This pointer avoids the problem of relying on last jump history entry's insn_idx to determine whether we already have entry for current instruction or not. It can happen that we added jump history entry because current instruction is_jmp_point(), but also we need to add instruction flags for stack access. In this case, we don't want to entries, so we need to reuse last added entry, if it is present. Relying on insn_idx comparison has the same ambiguity problem as the one that was fixed recently in [0], so we avoid that. [0] https://patchwork.kernel.org/project/netdevbpf/patch/20231110002638.4168352-3-andrii@kernel.org/ The Linux kernel CVE team has assigned CVE-2023-52920 to this issue. Affected and fixed versions =========================== Fixed in 6.8 with commit 41f6f64e6999 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-52920 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: include/linux/bpf_verifier.h kernel/bpf/verifier.c tools/testing/selftests/bpf/progs/verifier_subprog_precision.c tools/testing/selftests/bpf/verifier/precise.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/41f6f64e6999a837048b1bd13a2f8742964eca6b