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=1796221352; b=0Ejda3xVwdbzz53aYaKS8+Mm0vgV9ww2swj4M4zG0NXLPevbgIkJrymlGdwhCfQ1SIfO JAuAPIdxP/8GOHcnqlS9EJ1RhcsZPsAXNNAoXNtjMeCDg/akoxoCxCvCFrN+Twn4TIz20 fzdZwUtdJ7ZdnZSf0mfWi3BJK9cw93JB5K0l2UI/AtO7PKLU0bnM4eCwtirTd/cG61ugr BDm8kFZOIaw+ImwpxwxF5YgyxaBnGMEMrFFx+zovDEKEYK5JSkajiCJOWtpL0/pBobzSh ZzpVPvK4hsBWuhzVra7Co40qIS2A20PDeypRLlfYjIVzGcN7s6ffzCkH5AFQv2rpR5Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796221352; h=Received:DKIM-Signature:Subject:To:Cc:From:Date:Message-ID: MIME-Version:Content-Type:Content-Transfer-Encoding; bh=h8AcrFovKPfSMs4uk+siyNIkTqiaqYvXisKH1gWSzQI=; b=lclkitVxfw5u39ux31G1ajI9r5qmwU6kMNuanxNItq4U8h9A0bY4+8CFwODLZPdLJem+ u9OieoYObjFyzOYjfB/+YJFCZMEzPTWKLVT4nzuGY/P3YRI9CYSXZ/9AYpeMSNxBPT2CB H5KC2tZZwH12CsnNQpbZzRcTtA399luhsChycqbCx6kGicknD8Y9P8V4MoIShw4c+CRj1 uVl9hXSd0m/K066FWKwSy/b6oAyB1YqlS69Q/tL/+kSYYv1q9Zp23v66KuBDNlc8Bxif1 kmA3F9QuypO+VB2N1+FS/FxfM7eSgAByhhxJ7gHJsNmHFKNvQdmb5t/cuBYKyhnFvZg== 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=TOoQVDb8; 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 5D0B5606A323 for ; Wed, 2 Dec 2026 14:22:32 +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=TOoQVDb8 Received: by smtp.kernel.org (Postfix) with ESMTPSA id EFC3E1F00897; Wed, 2 Dec 2026 14:22:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796221351; bh=h8AcrFovKPfSMs4uk+siyNIkTqiaqYvXisKH1gWSzQI=; h=Subject:To:Cc:From:Date; b=TOoQVDb8grzxjimPyd0vCqau1ap/0Oi3AMHi/MhpG/mJujP66l4mmBklDJsciCh9p b+zAzrUq5S7zKdRgzoMTna1CLSMbktsB2uM/YXdVjR6T3zPH47wrtFLAd1NpaF72C1 IGD5oCYwdRshf2YrtK46pvwDrfupvPGarq66YIII= Subject: FAILED: patch "[PATCH] riscv: Fix SR_SUM leakage across context switches" failed to apply to 6.6-stable tree To: cuiyunhui@bytedance.com,jszhang@kernel.org,pjw@kernel.org,tchiu@tenstorrent.com,yang.yicong@picoheart.com Cc: From: Date: Wed, 02 Dec 2026 14:41:13 +0100 Message-ID: <2026120213-mortuary-lying-96d8@gregkh> 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-Type: text/plain; charset=ANSI_X3.4-1968 Content-Transfer-Encoding: 8bit The patch below does not apply to the 6.6-stable tree. If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to . To reproduce the conflict and resubmit, you may use the following commands: git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.6.y git checkout FETCH_HEAD git cherry-pick -x 807b09be9c8f234ce758bcf43101f34e0a036b83 # git commit -s git send-email --to '' --in-reply-to '2026120213-mortuary-lying-96d8@gregkh' --subject-prefix 'PATCH 6.6.y' 'HEAD^..' Possible dependencies: thanks, greg k-h ------------------ original commit in Linus's tree ------------------ >From 807b09be9c8f234ce758bcf43101f34e0a036b83 Mon Sep 17 00:00:00 2001 From: Yunhui Cui Date: Thu, 22 Oct 2026 16:32:12 +0800 Subject: [PATCH] riscv: Fix SR_SUM leakage across context switches __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 diff --git a/arch/riscv/kernel/entry.S b/arch/riscv/kernel/entry.S index 61b7a7716697..628b85e3915a 100644 --- 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)