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 453691F4FA6 for ; Mon, 21 Oct 2024 18:02:56 +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=1729533777; cv=none; b=IZ4ZQKjyPrQlQTxbXDUDIB1X9Yyi6DjfGH8+JwPn41llwf1OEveIwl8mYJVO+CQTI5Jzn4xNPX1PtXCctwaN4fiUl307LLcwS04tM81YJeN+yO25UlC/voT6RFr0SzxdhymiKLm/ClQvhw4VbfpYSSjZUfDxIjlAy+gGPWzPP80= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729533777; c=relaxed/simple; bh=6EjM+hUzr7E/IAlBxntvi80kodGgRo3QwNE/uZjh6u8=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=dweUabNWU7nziaXwC6uxMTM2cumC0hD9R83gEgU1RV0kT/1HJTOj9ocSsQ9pZvC7641USPoR0RIkyxMlJ9XVVqXVd4yI22we46yHwBUghXX/jjXSFFFQvaMXMJDcL/haQFn8dmOdUOmwRZaHSBk1HbJFZyTXGdXIQOwpjqewLIg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=BcmyOFDF; 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="BcmyOFDF" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 69800C4CEE7; Mon, 21 Oct 2024 18:02:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1729533776; bh=6EjM+hUzr7E/IAlBxntvi80kodGgRo3QwNE/uZjh6u8=; h=From:To:Cc:Subject:Date:Reply-to:From; b=BcmyOFDFZsngHRNJfAZT3z1wVSPLqDSV6JP0lSZyauVjyxYsy2h1MxcRnpFiWliIi Fntn4gixlTupdnGwHGJBbzw54BjkI3prGAx2615tapnVMbghehRd3H5GxQvcKMmWi8 khfrR+3DmL05VvxDLd99QDlvzYxsX0wlP2UekNTk= From: Greg Kroah-Hartman To: linux-cve-announce@vger.kernel.org Cc: Greg Kroah-Hartman Subject: CVE-2024-49888: bpf: Fix a sdiv overflow issue Date: Mon, 21 Oct 2024 20:01:36 +0200 Message-ID: <2024102117-CVE-2024-49888-027c@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=3650; i=gregkh@linuxfoundation.org; h=from:subject:message-id; bh=6EjM+hUzr7E/IAlBxntvi80kodGgRo3QwNE/uZjh6u8=; b=owGbwMvMwCRo6H6F97bub03G02pJDOli0962il6sF/0ku6W5qEwy9pirT3JXT9T5tzqNO3Pr5 21OXJXSEcvCIMjEICumyPJlG8/R/RWHFL0MbU/DzGFlAhnCwMUpABNxS2eYZxJWKy97WPCxdJzy vZteF6bMeJk+m2EO56oJfR8n/Vyhqx/167X2iU/l384fBAA= 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: Fix a sdiv overflow issue Zac Ecob reported a problem where a bpf program may cause kernel crash due to the following error: Oops: divide error: 0000 [#1] PREEMPT SMP KASAN PTI The failure is due to the below signed divide: LLONG_MIN/-1 where LLONG_MIN equals to -9,223,372,036,854,775,808. LLONG_MIN/-1 is supposed to give a positive number 9,223,372,036,854,775,808, but it is impossible since for 64-bit system, the maximum positive number is 9,223,372,036,854,775,807. On x86_64, LLONG_MIN/-1 will cause a kernel exception. On arm64, the result for LLONG_MIN/-1 is LLONG_MIN. Further investigation found all the following sdiv/smod cases may trigger an exception when bpf program is running on x86_64 platform: - LLONG_MIN/-1 for 64bit operation - INT_MIN/-1 for 32bit operation - LLONG_MIN%-1 for 64bit operation - INT_MIN%-1 for 32bit operation where -1 can be an immediate or in a register. On arm64, there are no exceptions: - LLONG_MIN/-1 = LLONG_MIN - INT_MIN/-1 = INT_MIN - LLONG_MIN%-1 = 0 - INT_MIN%-1 = 0 where -1 can be an immediate or in a register. Insn patching is needed to handle the above cases and the patched codes produced results aligned with above arm64 result. The below are pseudo codes to handle sdiv/smod exceptions including both divisor -1 and divisor 0 and the divisor is stored in a register. sdiv: tmp = rX tmp += 1 /* [-1, 0] -> [0, 1] if tmp >(unsigned) 1 goto L2 if tmp == 0 goto L1 rY = 0 L1: rY = -rY; goto L3 L2: rY /= rX L3: smod: tmp = rX tmp += 1 /* [-1, 0] -> [0, 1] if tmp >(unsigned) 1 goto L1 if tmp == 1 (is64 ? goto L2 : goto L3) rY = 0; goto L2 L1: rY %= rX L2: goto L4 // only when !is64 L3: wY = wY // only when !is64 L4: [1] https://lore.kernel.org/bpf/tPJLTEh7S_DxFEqAI2Ji5MBSoZVg7_G-Py2iaZpAaWtM961fFTWtsnlzwvTbzBzaUzwQAoNATXKUlt0LZOFgnDcIyKCswAnAGdUF3LBrhGQ=@protonmail.com/ The Linux kernel CVE team has assigned CVE-2024-49888 to this issue. Affected and fixed versions =========================== Fixed in 6.10.14 with commit 4902a6a0dc59 Fixed in 6.11.3 with commit d22e45a369af Fixed in 6.12-rc1 with commit 7dd34d7b7dcf 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-2024-49888 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/4902a6a0dc593c82055fc8c9ada371bafe26c9cc https://git.kernel.org/stable/c/d22e45a369afc7c28f11acfa5b5e8e478227ca5d https://git.kernel.org/stable/c/7dd34d7b7dcf9309fc6224caf4dd5b35bedddcb7