Skip to content

Commit b7c510d

Browse files
brooniewilldeacon
authored andcommitted
arm64/ptrace: Don't flush ZA/ZT storage when writing ZA via ptrace
When writing ZA we currently unconditionally flush the buffer used to store it as part of ensuring that it is allocated. Since this buffer is shared with ZT0 this means that a write to ZA when PSTATE.ZA is already set will corrupt the value of ZT0 on a SME2 system. Fix this by only flushing the backing storage if PSTATE.ZA was not previously set. This will mean that short or failed writes may leave stale data in the buffer, this seems as correct as our current behaviour and unlikely to be something that userspace will rely on. Fixes: f90b529 ("arm64/sme: Implement ZT0 ptrace support") Signed-off-by: Mark Brown <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent da59f1d commit b7c510d

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

arch/arm64/kernel/ptrace.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,12 +1107,13 @@ static int za_set(struct task_struct *target,
11071107
}
11081108
}
11091109

1110-
/* Allocate/reinit ZA storage */
1111-
sme_alloc(target, true);
1112-
if (!target->thread.sme_state) {
1113-
ret = -ENOMEM;
1114-
goto out;
1115-
}
1110+
/*
1111+
* Only flush the storage if PSTATE.ZA was not already set,
1112+
* otherwise preserve any existing data.
1113+
*/
1114+
sme_alloc(target, !thread_za_enabled(&target->thread));
1115+
if (!target->thread.sme_state)
1116+
return -ENOMEM;
11161117

11171118
/* If there is no data then disable ZA */
11181119
if (!count) {

0 commit comments

Comments
 (0)