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=1796381233; b=lsmE2wZs8Qdo2YPxziYPo+NylZWIJpVAj4wFDJqT3uJSUAwYQL97Vpus74cS88UUSW+Y zCqM25K9BNzNbfmJMm+eT8v8UlZJ/nOIVDBaR6WT2DsfrDa9/2MZAvjvMSX5Bazzq+gsO 0tcyuqaat0PhY5v9HJb18q9fOJQCYuNA8DZIPi5UH2NSwNvFVLcV2vAVOsWbhpcx2htqB hOscIjImo1KFj5UL4QBNwsnFViUnOXNtqkS1/MWC52ejHSKvtbAAJQeF/GXSyIfZLnRkM vupIZao/kKevaIKsKReS22MTiRfFYMvjtA8AEbLifM92Nf8jYDkc7b1O8KORGdRiNWA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796381233; 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=cV3Nn/YV6negKzoaYvU/rA5kWEhrjjdHQ1xGX4hJftQ=; b=cRH1m+wMHGOfs6UvCY3KYUcoeWvu0dHgZRflW6kbAb5kNd4k8JpOkov+9u6zGXvTzHE/ A7rZd81LIzcJQ2+nv7PXHeKWfjp87CU1BljUyDlCl7jzTUTSZUWXf7zgdnN9ag6gFJ+R9 AllKXyTzXo4miYmPpls3HGCmIpm2Aq/ok9iiu7KN22uOr2EKdaQ0T30iiZih6H33YazV9 9F8a6wiS+ZnyXiY5jZXxt4aJiIOqpcVyDe2Srx0kUx2aPAEoVUX9xRZHgwiq2C0tkiqED BpxUrnigo4yPEbD0/f+j56zRtf6zjPU4MjhScwJ1HSiFHzFS+Cy7qQBl0ndr95Xup8w== 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=M6rLkH21; 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 F367C606A683; Fri, 4 Dec 2026 10:47:12 +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=M6rLkH21 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6F7251F000CE; Fri, 4 Dec 2026 10:47:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796381232; bh=cV3Nn/YV6negKzoaYvU/rA5kWEhrjjdHQ1xGX4hJftQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=M6rLkH21cQuKZaH6je31+4W9uV7nQdb+piuocl7ONPNZmjMgQohZx/SDJB2rAV8Wr jV9UgxVFwW6nlJZgoJc7vojkFVHHWcLBLPaEGrNw8EawYjQfU+k1nw0ezLOesyf7tX SzJp8kW3prmCuKtV2UAAkGUI5xQDvfV4Ez/c3uEQ= 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 7.3 576/742] riscv: Fix SR_SUM leakage across context switches Date: Fri, 4 Dec 2026 19:07:20 +0900 Message-ID: <20261204100650.437543363@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@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 7.3-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 @@ -443,15 +443,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)