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 C6E29280324 for ; Wed, 18 Jun 2025 11:02:38 +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=1750244558; cv=none; b=PXmx+iuhUu9+Bhz4gAQrL8TYoegPY1LyMCyaC/7XBjd/uKBGHVmrrsvcFQZnFaJgAISNaAxqdVqapadfN1UMAgBlaismn5jcwkW1jah1HngwMtexkekWdfJfdzCmhFcXc1jmPA83heMFuutPqd4TJVc61CwA5n+QZXiWKbsbPrE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750244558; c=relaxed/simple; bh=F1WoPFobZs5EUQia4YC1kz255QnHPbv2OaWimq6ZqsM=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=PmsnDUBpN10z0V60x6MIoWTIQLxLuo1bzcmmUj+XVk//RtlfFxwOd/I9bHYmjpiqm2m6Gu1JC4MOKawhT0T+adfnEvEViBd3HlwsUWEaJKR8CF98h6muK4OxPPETwZQO9EnZo7ldF5jQY4tBPlvKy/sFosP39oVNHfbGT2MNqRI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=EFZnsnot; 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="EFZnsnot" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0060BC4CEED; Wed, 18 Jun 2025 11:02:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1750244558; bh=F1WoPFobZs5EUQia4YC1kz255QnHPbv2OaWimq6ZqsM=; h=From:To:Cc:Subject:Date:Reply-to:From; b=EFZnsnotVg+vWHl8Fgd8e7gKwxmcwcwjDYfQGNoR5AhO1FDz6ielQv4hLkMNKxv+R N03tlhaZ1Is2mjIjOwqZ6pMeW4Xc00t2DG/oDH/QRGAlXotpIms8GQDod8sTTcWnTL JGC/o/8ehg3YNVyGt7FWH+qgPFfEHG0VXQ+YS6oc= From: Greg Kroah-Hartman To: linux-cve-announce@vger.kernel.org Cc: Greg Kroah-Hartman Subject: CVE-2022-49961: bpf: Do mark_chain_precision for ARG_CONST_ALLOC_SIZE_OR_ZERO Date: Wed, 18 Jun 2025 13:00:26 +0200 Message-ID: <2025061814-CVE-2022-49961-b7fa@gregkh> X-Mailer: git-send-email 2.49.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=4559; i=gregkh@linuxfoundation.org; h=from:subject:message-id; bh=vPye4c9RipeC3U+ydGvqfg17wXJdEu5P1nJrA9mPJzM=; b=owGbwMvMwCRo6H6F97bub03G02pJDBlBc+y0QmduV8yfcvjUrwP5x8+rVuWkHlsrJO5vvJr58 su1k0uKO2JZGASZGGTFFFm+bOM5ur/ikKKXoe1pmDmsTCBDGLg4BWAiG58wzM83WrJAsMr6tVdf b/VxFj+rlPCCDIb5vjvtsh2DmWJWJ20U/RfaxbWqMmIyAA== 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: Do mark_chain_precision for ARG_CONST_ALLOC_SIZE_OR_ZERO Precision markers need to be propagated whenever we have an ARG_CONST_* style argument, as the verifier cannot consider imprecise scalars to be equivalent for the purposes of states_equal check when such arguments refine the return value (in this case, set mem_size for PTR_TO_MEM). The resultant mem_size for the R0 is derived from the constant value, and if the verifier incorrectly prunes states considering them equivalent where such arguments exist (by seeing that both registers have reg->precise as false in regsafe), we can end up with invalid programs passing the verifier which can do access beyond what should have been the correct mem_size in that explored state. To show a concrete example of the problem: 0000000000000000 : 0: r2 = *(u32 *)(r1 + 80) 1: r1 = *(u32 *)(r1 + 76) 2: r3 = r1 3: r3 += 4 4: if r3 > r2 goto +18 5: w2 = 0 6: *(u32 *)(r1 + 0) = r2 7: r1 = *(u32 *)(r1 + 0) 8: r2 = 1 9: if w1 == 0 goto +1 10: r2 = -1 0000000000000058 : 11: r1 = 0 ll 13: r3 = 0 14: call bpf_ringbuf_reserve 15: if r0 == 0 goto +7 16: r1 = r0 17: r1 += 16777215 18: w2 = 0 19: *(u8 *)(r1 + 0) = r2 20: r1 = r0 21: r2 = 0 22: call bpf_ringbuf_submit 00000000000000b8 : 23: w0 = 0 24: exit For the first case, the single line execution's exploration will prune the search at insn 14 for the branch insn 9's second leg as it will be verified first using r2 = -1 (UINT_MAX), while as w1 at insn 9 will always be 0 so at runtime we don't get error for being greater than UINT_MAX/4 from bpf_ringbuf_reserve. The verifier during regsafe just sees reg->precise as false for both r2 registers in both states, hence considers them equal for purposes of states_equal. If we propagated precise markers using the backtracking support, we would use the precise marking to then ensure that old r2 (UINT_MAX) was within the new r2 (1) and this would never be true, so the verification would rightfully fail. The end result is that the out of bounds access at instruction 19 would be permitted without this fix. Note that reg->precise is always set to true when user does not have CAP_BPF (or when subprog count is greater than 1 (i.e. use of any static or global functions)), hence this is only a problem when precision marks need to be explicitly propagated (i.e. privileged users with CAP_BPF). A simplified test case has been included in the next patch to prevent future regressions. The Linux kernel CVE team has assigned CVE-2022-49961 to this issue. Affected and fixed versions =========================== Issue introduced in 5.8 with commit 457f44363a8894135c85b7a9afd2bd8196db24ab and fixed in 5.19.8 with commit 2459615a8d7f44ac81f0965bc094e55ccb254717 Issue introduced in 5.8 with commit 457f44363a8894135c85b7a9afd2bd8196db24ab and fixed in 6.0 with commit 2fc31465c5373b5ca4edf2e5238558cb62902311 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-2022-49961 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/verifier.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/2459615a8d7f44ac81f0965bc094e55ccb254717 https://git.kernel.org/stable/c/2fc31465c5373b5ca4edf2e5238558cb62902311