FAILED: patch "[PATCH] arm64/fpsimd: signal: Fix restoration of SVE context" failed to apply to 6.12-stable tree
Subsystems (2)
[email protected]
maintainerThe patch below does not apply to the 6.12-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 <[email protected]>.
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.12.y
git checkout FETCH_HEAD
git cherry-pick -x d2907cbe9ea0a54cbe078076f9d089240ee1e2d9
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026012701-tile-landowner-8d31@gregkh' --subject-prefix 'PATCH 6.12.y' HEAD^..
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From d2907cbe9ea0a54cbe078076f9d089240ee1e2d9 Mon Sep 17 00:00:00 2001
From: Mark Rutland <[email protected]>
Date: Tue, 20 Jan 2026 14:51:07 +0000
Subject: [PATCH] arm64/fpsimd: signal: Fix restoration of SVE context
When SME is supported, Restoring SVE signal context can go wrong in a few ways, including placing the task into an invalid state where the kernel may read from out-of-bounds memory (and may potentially take a fatal fault) and/or may kill the task with a SIGKILL.
(1) Restoring a context with SVE_SIG_FLAG_SM set can place the task into an invalid state where SVCR.SM is set (and sve_state is non-NULL) but TIF_SME is clear, consequently resuting in out-of-bounds memory reads and/or killing the task with SIGKILL.
This can only occur in unusual (but legitimate) cases where the SVE signal context has either been modified by userspace or was saved in the context of another task (e.g. as with CRIU), as otherwise the presence of an SVE signal context with SVE_SIG_FLAG_SM implies that TIF_SME is already set.
While in this state, task_fpsimd_load() will NOT configure SMCR_ELx (leaving some arbitrary value configured in hardware) before restoring SVCR and attempting to restore the streaming mode SVE registers from memory via sve_load_state(). As the value of SMCR_ELx.LEN may be larger than the task's streaming SVE vector length, this may read memory outside of the task's allocated sve_state, reading unrelated data and/or triggering a fault.
While this can result in secrets being loaded into streaming SVE registers, these values are never exposed. As TIF_SME is clear, fpsimd_bind_task_to_cpu() will configure CPACR_ELx.SMEN to trap EL0 accesses to streaming mode SVE registers, so these cannot be accessed directly at EL0. As fpsimd_save_user_state() verifies the live vector length before saving (S)SVE state to memory, no secret values can be saved back to memory (and hence cannot be observed via ptrace, signals, etc).
When the live vector length doesn't match the expected vector length for the task, fpsimd_save_user_state() will send a fatal SIGKILL signal to the task. Hence the task may be killed after executing userspace for some period of time.
(2) Restoring a context with SVE_SIG_FLAG_SM clear does not clear the task's SVCR.SM. If SVCR.SM was set prior to restoring the context, then the task will be left in streaming mode unexpectedly, and some register state will be combined inconsistently, though the task will be left in legitimate state from the kernel's PoV.
This can only occur in unusual (but legitimate) cases where ptrace has been used to set SVCR.SM after entry to the sigreturn syscall, as syscall entry clears SVCR.SM.
In these cases, the the provided SVE register data will be loaded into the task's sve_state using the non-streaming SVE vector length and the FPSIMD registers will be merged into this using the streaming SVE vector length.
Fix (1) by setting TIF_SME when setting SVCR.SM. This also requires ensuring that the task's sme_state has been allocated, but as this could contain live ZA state, it should not be zeroed. Fix (2) by clearing SVCR.SM when restoring a SVE signal context with SVE_SIG_FLAG_SM clear.
For consistency, I've pulled the manipulation of SVCR, TIF_SVE, TIF_SME, and fp_type earlier, immediately after the allocation of sve_state/sme_state, before the restore of the actual register state. This makes it easier to ensure that these are always modified consistently, even if a fault is taken while reading the register data from the signal context. I do not expect any software to depend on the exact state restored when a fault is taken while reading the context.
arch/arm64/kernel/signal.c +16 -6
@@ -449,12 +449,28 @@ static int restore_sve_fpsimd_context(struct user_ctxs *user)if (user->sve_size <SVE_SIG_CONTEXT_SIZE (vq))return -EINVAL ; +if (sm) { +sme_alloc (current, false); +if (!current->thread.sme_state) +return -ENOMEM ; + } +sve_alloc (current, true);if (!current->thread.sve_state) {clear_thread_flag (TIF_SVE );return -ENOMEM ; } +if (sm) { + current->thread.svcr |=SVCR_SM_MASK ; +set_thread_flag (TIF_SME ); + }else { + current->thread.svcr &= ~SVCR_SM_MASK ; +set_thread_flag (TIF_SVE ); + } + + current->thread.fp_type =FP_STATE_SVE ; + err = __copy_from_user(current->thread.sve_state, (char __user const *)user->sve + SVE_SIG_REGS_OFFSET,
@@ -462,12 +478,6 @@ static int restore_sve_fpsimd_context(struct user_ctxs *user)if (err)return -EFAULT ; -if (flags &SVE_SIG_FLAG_SM ) - current->thread.svcr |=SVCR_SM_MASK ; -else -set_thread_flag (TIF_SVE ); - current->thread.fp_type =FP_STATE_SVE ; - err =read_fpsimd_context (&fpsimd, user);if (err)return err;
Mark Rutland
reviewerQuoted 5 lines · On Tue, Jan 27, 2026 at 02:16:01PM +0100, [email protected] wrote:
The patch below does not apply to the 6.12-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 <[email protected]>.
As a heads-up for the others on Cc, I've seen this and will chase this up shortly.
At present this patch doesn't strictly matter since we haven't re-enabled SME support in the upstream stable trees, and at this point I reckon we shouldn't.
Mark.
Quoted 145 lines
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.12.y
git checkoutFETCH_HEAD
git cherry-pick -xd2907cbe9ea0a54cbe078076f9d089240ee1e2d9
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026012701-tile-landowner-8d31@gregkh' --subject-prefix 'PATCH 6.12.y' HEAD^..Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From
d2907cbe9ea0a54cbe078076f9d089240ee1e2d9Mon Sep 17 00:00:00 2001
From: Mark Rutland <[email protected]>
Date: Tue, 20 Jan 2026 14:51:07 +0000
Subject: [PATCH] arm64/fpsimd: signal: Fix restoration of SVE contextWhen SME is supported, Restoring SVE signal context can go wrong in a few ways, including placing the task into an invalid state where the kernel may read from out-of-bounds memory (and may potentially take a fatal fault) and/or may kill the task with a SIGKILL.
(1) Restoring a context with
SVE_SIG_FLAG_SMset can place the task into an invalid state where SVCR.SM is set (andsve_stateis non-NULL) butTIF_SMEis clear, consequently resuting in out-of-bounds memory reads and/or killing the task with SIGKILL.This can only occur in unusual (but legitimate) cases where the SVE signal context has either been modified by userspace or was saved in the context of another task (e.g. as with CRIU), as otherwise the presence of an SVE signal context with
SVE_SIG_FLAG_SMimplies thatTIF_SMEis already set.While in this state,
task_fpsimd_load()will NOT configureSMCR_ELx(leaving some arbitrary value configured in hardware) before restoring SVCR and attempting to restore the streaming mode SVE registers from memory viasve_load_state(). As the value of SMCR_ELx.LEN may be larger than the task's streaming SVE vector length, this may read memory outside of the task's allocatedsve_state, reading unrelated data and/or triggering a fault.While this can result in secrets being loaded into streaming SVE registers, these values are never exposed. As
TIF_SMEis clear,fpsimd_bind_task_to_cpu()will configure CPACR_ELx.SMEN to trap EL0 accesses to streaming mode SVE registers, so these cannot be accessed directly at EL0. Asfpsimd_save_user_state()verifies the live vector length before saving (S)SVE state to memory, no secret values can be saved back to memory (and hence cannot be observed via ptrace, signals, etc).When the live vector length doesn't match the expected vector length for the task,
fpsimd_save_user_state()will send a fatal SIGKILL signal to the task. Hence the task may be killed after executing userspace for some period of time.(2) Restoring a context with
SVE_SIG_FLAG_SMclear does not clear the task's SVCR.SM. If SVCR.SM was set prior to restoring the context, then the task will be left in streaming mode unexpectedly, and some register state will be combined inconsistently, though the task will be left in legitimate state from the kernel's PoV.This can only occur in unusual (but legitimate) cases where ptrace has been used to set SVCR.SM after entry to the sigreturn syscall, as syscall entry clears SVCR.SM.
In these cases, the the provided SVE register data will be loaded into the task's
sve_stateusing the non-streaming SVE vector length and the FPSIMD registers will be merged into this using the streaming SVE vector length.Fix (1) by setting
TIF_SMEwhen setting SVCR.SM. This also requires ensuring that the task'ssme_statehas been allocated, but as this could contain live ZA state, it should not be zeroed. Fix (2) by clearing SVCR.SM when restoring a SVE signal context withSVE_SIG_FLAG_SMclear.For consistency, I've pulled the manipulation of SVCR,
TIF_SVE,TIF_SME, andfp_typeearlier, immediately after the allocation of sve_state/sme_state, before the restore of the actual register state. This makes it easier to ensure that these are always modified consistently, even if a fault is taken while reading the register data from the signal context. I do not expect any software to depend on the exact state restored when a fault is taken while reading the context.Fixes 85ed24dad290 ("arm64/sme: Implement streaming SVE signal handling")Signed-off-by Mark Rutland <[email protected]>Cc <[email protected]>Cc Mark Brown <[email protected]>Cc Will Deacon <[email protected]>Reviewed-by Mark Brown <[email protected]>Signed-off-by Catalin Marinas <[email protected]>arch/arm64/kernel/signal.c +16
-6@@ -449,12 +449,28 @@ static int restore_sve_fpsimd_context(struct user_ctxs *user)if (user->sve_size <SVE_SIG_CONTEXT_SIZE (vq))return -EINVAL ; +if (sm) { +sme_alloc (current, false); +if (!current->thread.sme_state) +return -ENOMEM ; + } +sve_alloc (current, true);if (!current->thread.sve_state) {clear_thread_flag (TIF_SVE );return -ENOMEM ; } +if (sm) { + current->thread.svcr |=SVCR_SM_MASK ; +set_thread_flag (TIF_SME ); + }else { + current->thread.svcr &= ~SVCR_SM_MASK ; +set_thread_flag (TIF_SVE ); + } + + current->thread.fp_type =FP_STATE_SVE ; + err = __copy_from_user(current->thread.sve_state, (char __user const *)user->sve + SVE_SIG_REGS_OFFSET,@@ -462,12 +478,6 @@ static int restore_sve_fpsimd_context(struct user_ctxs *user)if (err)return -EFAULT ; -if (flags &SVE_SIG_FLAG_SM ) - current->thread.svcr |=SVCR_SM_MASK ; -else -set_thread_flag (TIF_SVE ); - current->thread.fp_type =FP_STATE_SVE ; - err =read_fpsimd_context (&fpsimd, user);if (err)return err;