From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796383958; b=bTuQwL5WtvP8HCt6C5XEEXQQzWHJ2r0FnIt/0QoVtsRiFdYnJfRNF8gkKbvIXzSKtY9r c1DyqguU4sC8sMkWp3B70IuivR1IZimTtZzocyAgWDYFuDNgdgSmwgwXyVB2So/8vljXF M21dwGhTs5W8p+x9pWpJfWP29995Y/ECCI3O+SgT8/qlH3s7CtxPMXHu4ZC806ZPdA1c5 sZ00N4OLtTxmCdRViwNIK6EV/zgZQJ+Oulbw5pPyfDCR9Qmzn8A3HGsLICNqwrndRxm+i PuYKU2fDwyWhP5bebjb0HyS+9BpuJOM7LM31CgpSjB+oQlYsYhZAlsFoFYXxFOZSL4g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796383958; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=FO8R0E0MR8Y37leK9+HbvNwJ60gi6oFnNMkDp3jNklw=; b=Zunx3OX6n5o89Jt893hu0pqePM6ItJJ/Z0iNfB3bAGwDbXsFfn1Y+TMtKe34lFL7/W4d MqDacZkcQyGeL04wSl5QGQx3la3PhSGlMkGJtwccy1Dw6VuQvMX50QgBqzxSxXmmcrJA/ ta/P4tgKyI5pVYlJP/2dVX3AYwAZJ84JlbCcgUXAzNyaMmUmI9WckmXUnf/vX2LPALWie IVVQkAPsQfYKgLA5iq5Lc9Gn1KPlTJzPU3pGXXqcQsxypp4+i6szhBLqHgRsiUy19VP44 39Qt+N1yx8PsDUGiH6G41QcUDglqjgD4sVSg8A7fPIV/y9sCFr5vQvxwX3ka5NUFOpA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=PqIdmZHv; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BF5DA606A332; Fri, 4 Dec 2026 11:32:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=PqIdmZHv Received: by smtp.kernel.org (Postfix) with ESMTPSA id D907F1F00897; Fri, 4 Dec 2026 11:32:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796383958; bh=FO8R0E0MR8Y37leK9+HbvNwJ60gi6oFnNMkDp3jNklw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=PqIdmZHvBQ2O5q307vEYwbIvPCjr3z6ctqfjJYM198fvCmM9YmrTD9rTPUKTuFB9x IOaXrd4bufVQMJU4OTtUEjr+h22dlH6I2Vxju/pqN6aoP5x115u4Is+a7mew8gmcRX vPrlJaLJtS7s6AfQNLibDHiKYIf3ntg4tPPgqqiw= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Yunhui Cui , Jisheng Zhang , Andy Chiu , Yicong Yang , Paul Walmsley Subject: [PATCH 6.12 437/555] riscv: Fix SR_SUM leakage across context switches Date: Fri, 4 Dec 2026 19:08:00 +0900 Message-ID: <20261204100626.219751761@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100603.988357525@linuxfoundation.org> References: <20261204100603.988357525@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Yunhui Cui commit 807b09be9c8f234ce758bcf43101f34e0a036b83 upstream. __switch_to() saves the sstatus value of prev and restores the SR_SUM bit of next with csrs. However, csrs only sets bits. If prev has SR_SUM set and next has SR_SUM clear in its saved state, the old SR_SUM bit remains set in sstatus. This lets next run with user memory access enabled even though its saved SR_SUM state is clear. Use csrrc to save the sstatus value of prev and clear SR_SUM from the live CSR before restoring the saved SR_SUM state of next. This keeps prev's SR_SUM state intact, while preventing it from leaking to next. Fixes: 788aa64c01f1 ("riscv: save the SR_SUM status over switches") Cc: stable@vger.kernel.org Signed-off-by: Yunhui Cui Reviewed-by: Jisheng Zhang Reviewed-by: Andy Chiu Reviewed-by: Yicong Yang Link: https://patch.msgid.link/20261022083212.84721-1-cuiyunhui@bytedance.com Signed-off-by: Paul Walmsley Signed-off-by: Greg Kroah-Hartman --- arch/riscv/kernel/entry.S | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) --- a/arch/riscv/kernel/entry.S +++ b/arch/riscv/kernel/entry.S @@ -403,15 +403,15 @@ SYM_FUNC_START(__switch_to) REG_S s10, TASK_THREAD_S10_RA(a3) REG_S s11, TASK_THREAD_S11_RA(a3) - /* save the user space access flag */ - csrr s0, CSR_STATUS + /* Save and clear the user space access flag. */ + li s1, SR_SUM + csrrc s0, CSR_STATUS, s1 REG_S s0, TASK_THREAD_SUM_RA(a3) /* Save the kernel shadow call stack pointer */ scs_save_current /* Restore context from next->thread */ REG_L s0, TASK_THREAD_SUM_RA(a4) - li s1, SR_SUM and s0, s0, s1 csrs CSR_STATUS, s0 REG_L ra, TASK_THREAD_RA_RA(a4)