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=1796382564; b=0ufu4j/umwAr8F/S384xX8dtIa/gMFQ4uTqLb4DW4PqWhJ2ot8kR85xUVFKX9pIh1PCw v+YYajlg6NccF3mh16PaqzJjpQiTfPL1AAoyCG3gX01lx04eNfXwwqpScFyaPyWOi97r5 tZlpivEDli+0WqjDkTRkJkucoambbu2SytPuJytThWc0PfY81kWjNWIxZR8N2Al0+U3Ob EWdp3jMdqBcEX5wXJbvGHw/Yr4gsrKDVjtcnpY0SHAP2GD028Qebej9pr1hkPArOLLk+l 7rZvzarWSuOt42FJukPlKYM22ERCKwn3/YwJGAASJ5zhSB3LZejtqD00hgvAujPODGA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796382564; 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=KT0D+siEEIBbunbpxRuqxL2MZNAcUdJIWr5m3sVF5wQ=; b=csmL3mjRDTdh4i7wHKJWN8h4wBdTmf3GtrGYmLfaT6QnKNmFKHRzUh2IMc5B/PxdCRbT PZonMiYLWBz3TPsbNGHQC12/q30JwLNqEIR1qgd/ysxJnU+gcggLCe23K+taB/C+DNiZC Ji2Y0Gj6LvQKD32WmEEWm0Zs52P+ljEM0HvomEx9PqJeAwNOH2teV97oQxfA8fIjcbuSZ 7vNgJJGxLLMz7aIiXvaZHBIDgtVAdIDm8a/eX28qhxIDJNmCCbKOpHXuG1PK5h3iHVEHa o6mIbRuzAAgN66W3HGL5UXpLnqYfKBQ4FDPEm4PFPWLwkRPN2P/7GnIX4WKd0v3R+2Q== 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=AzjZ4X+f; 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 DE719606A330; Fri, 4 Dec 2026 11:09:24 +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=AzjZ4X+f Received: by smtp.kernel.org (Postfix) with ESMTPSA id 281F11F000C2; Fri, 4 Dec 2026 11:09:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796382564; bh=KT0D+siEEIBbunbpxRuqxL2MZNAcUdJIWr5m3sVF5wQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=AzjZ4X+f4WxIoCqgWb8I1e9pO/QZJUIdH+u1TWFjJiu+P80nY3TT28HZE/cQIKYEg nL8wZkOl//kE55ymhLNlP9N9oyicaqz99+ZnVExP9Lx8/XvDLNwzwKlA5Dg7dSnj2h +MpNPHw10HOJSO4Yyl9QzqQ8D5lflnZ1MHk+zGdg= 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.18 509/703] riscv: Fix SR_SUM leakage across context switches Date: Fri, 4 Dec 2026 19:06:48 +0900 Message-ID: <20261204100641.337717244@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100627.522266145@linuxfoundation.org> References: <20261204100627.522266145@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-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 @@ -408,15 +408,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)