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 54079168DC for ; Sun, 19 May 2024 08:35:24 +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=1716107725; cv=none; b=KmnAiqMYUOF0DFVvkCWI0zzeu2iyNWgV6QrVbcuRbunqTyOx0hXnqIHzLFgoIh9sWifLazQytGRzwDItU0GnOF1gHhREdtftkfW9lehuV4I3+0qK5srv1QIxnhc167Foqy4xw6IjLGAwK4nPnse5eUHxjgtWJOnMSNLK+HWqhrU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716107725; c=relaxed/simple; bh=OEGon1x/iQ/xIf3xsaLN0YEGXa3nlcqz9WZ1cCDxxJU=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=sLTV4mpOqn19aSchrweHzKf0H4iuGQZVHdxTWX+udsLpP/GaBEXx22bhWSkR2Z7EDspBNSR++17nmkbPU3CHRoIbjGAE8X78faIAyH2rqXA8HqNlOKkvP4QHn8JTSHIvovxDhotAqE/jSFBIk8Zfkz3pxbD8Coew8JVMbSI6sBA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=QhbDB4ix; 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="QhbDB4ix" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 57A70C32781; Sun, 19 May 2024 08:35:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1716107724; bh=OEGon1x/iQ/xIf3xsaLN0YEGXa3nlcqz9WZ1cCDxxJU=; h=From:To:Cc:Subject:Date:Reply-to:From; b=QhbDB4ix3YkZd0hwr8M5NEd+RqjB5gCO0YLybqEkJmjBpV38TCkBrJRb3lckwQ2oQ uU21HKjPC/2WVgfK6ke0S6SGjVjeVqwngm/aOwM+8vIurhdlNXVkDqCYzomIBsX7i8 YJHzk50x0LpzWZkUVLyjzDu86L6P+nhfsGumpHfI= From: Greg Kroah-Hartman To: linux-cve-announce@vger.kernel.org Cc: Greg Kroah-Hartman Subject: CVE-2024-35873: riscv: Fix vector state restore in rt_sigreturn() Date: Sun, 19 May 2024 10:34:47 +0200 Message-ID: <2024051942-CVE-2024-35873-40f1@gregkh> X-Mailer: git-send-email 2.45.1 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=3727; i=gregkh@linuxfoundation.org; h=from:subject:message-id; bh=OEGon1x/iQ/xIf3xsaLN0YEGXa3nlcqz9WZ1cCDxxJU=; b=kA0DAAIRMUfUDdst+ykByyZiAGZJuaKgdt7gQXAhd4c8dhly+ax020lDaRfqCHR5TAimaWJSA IhdBAARAgAdFiEE9LYMxb94wiFKMT3LMUfUDdst+ykFAmZJuaIACgkQMUfUDdst+ykCoQCgpgQL Q7TIlTLeItuf6EIhcvOVoiEAoNhEyxt0VaXopLKW4MShTpvCOZVg 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: riscv: Fix vector state restore in rt_sigreturn() The RISC-V Vector specification states in "Appendix D: Calling Convention for Vector State" [1] that "Executing a system call causes all caller-saved vector registers (v0-v31, vl, vtype) and vstart to become unspecified.". In the RISC-V kernel this is called "discarding the vstate". Returning from a signal handler via the rt_sigreturn() syscall, vector discard is also performed. However, this is not an issue since the vector state should be restored from the sigcontext, and therefore not care about the vector discard. The "live state" is the actual vector register in the running context, and the "vstate" is the vector state of the task. A dirty live state, means that the vstate and live state are not in synch. When vectorized user_from_copy() was introduced, an bug sneaked in at the restoration code, related to the discard of the live state. An example when this go wrong: 1. A userland application is executing vector code 2. The application receives a signal, and the signal handler is entered. 3. The application returns from the signal handler, using the rt_sigreturn() syscall. 4. The live vector state is discarded upon entering the rt_sigreturn(), and the live state is marked as "dirty", indicating that the live state need to be synchronized with the current vstate. 5. rt_sigreturn() restores the vstate, except the Vector registers, from the sigcontext 6. rt_sigreturn() restores the Vector registers, from the sigcontext, and now the vectorized user_from_copy() is used. The dirty live state from the discard is saved to the vstate, making the vstate corrupt. 7. rt_sigreturn() returns to the application, which crashes due to corrupted vstate. Note that the vectorized user_from_copy() is invoked depending on the value of CONFIG_RISCV_ISA_V_UCOPY_THRESHOLD. Default is 768, which means that vlen has to be larger than 128b for this bug to trigger. The fix is simply to mark the live state as non-dirty/clean prior performing the vstate restore. The Linux kernel CVE team has assigned CVE-2024-35873 to this issue. Affected and fixed versions =========================== Issue introduced in 6.8 with commit c2a658d41924 and fixed in 6.8.5 with commit 5b16d904e910 Issue introduced in 6.8 with commit c2a658d41924 and fixed in 6.9 with commit c27fa53b858b 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-35873 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: arch/riscv/kernel/signal.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/5b16d904e910183181b9d90efa957c787a8ac91b https://git.kernel.org/stable/c/c27fa53b858b4ee6552a719aa599c250cf98a586