Skip to content

Commit 62c15d0

Browse files
mikeygregkh
authored andcommitted
powerpc/tm: Avoid possible userspace r1 corruption on reclaim
[ Upstream commit 96dc89d ] Current we store the userspace r1 to PACATMSCRATCH before finally saving it to the thread struct. In theory an exception could be taken here (like a machine check or SLB miss) that could write PACATMSCRATCH and hence corrupt the userspace r1. The SLB fault currently doesn't touch PACATMSCRATCH, but others do. We've never actually seen this happen but it's theoretically possible. Either way, the code is fragile as it is. This patch saves r1 to the kernel stack (which can't fault) before we turn MSR[RI] back on. PACATMSCRATCH is still used but only with MSR[RI] off. We then copy r1 from the kernel stack to the thread struct once we have MSR[RI] back on. Suggested-by: Breno Leitao <leitao@debian.org> Signed-off-by: Michael Neuling <mikey@neuling.org> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> Signed-off-by: Sasha Levin <alexander.levin@microsoft.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 256707d commit 62c15d0

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

  • arch/powerpc/kernel

arch/powerpc/kernel/tm.S

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,13 @@ _GLOBAL(tm_reclaim)
169169

170170
std r11, GPR11(r1) /* Temporary stash */
171171

172+
/*
173+
* Move the saved user r1 to the kernel stack in case PACATMSCRATCH is
174+
* clobbered by an exception once we turn on MSR_RI below.
175+
*/
176+
ld r11, PACATMSCRATCH(r13)
177+
std r11, GPR1(r1)
178+
172179
/*
173180
* Store r13 away so we can free up the scratch SPR for the SLB fault
174181
* handler (needed once we start accessing the thread_struct).
@@ -205,7 +212,7 @@ _GLOBAL(tm_reclaim)
205212
SAVE_GPR(8, r7) /* user r8 */
206213
SAVE_GPR(9, r7) /* user r9 */
207214
SAVE_GPR(10, r7) /* user r10 */
208-
ld r3, PACATMSCRATCH(r13) /* user r1 */
215+
ld r3, GPR1(r1) /* user r1 */
209216
ld r4, GPR7(r1) /* user r7 */
210217
ld r5, GPR11(r1) /* user r11 */
211218
ld r6, GPR12(r1) /* user r12 */

0 commit comments

Comments
 (0)