Skip to content

Commit 044215d

Browse files
Gustavo Romerompe
authored andcommitted
powerpc/tm: Fix illegal TM state in signal handler
Currently it's possible that on returning from the signal handler through the restore_tm_sigcontexts() code path (e.g. from a signal caught due to a `trap` instruction executed in the middle of an HTM block, or a deliberately constructed sigframe) an illegal TM state (like TS=10 TM=0, i.e. "T0") is set in SRR1 and when `rfid` sets implicitly the MSR register from SRR1 register on return to userspace it causes a TM Bad Thing exception. That illegal state can be set (a) by a malicious user that disables the TM bit by tweaking the bits in uc_mcontext before returning from the signal handler or (b) by a sufficient number of context switches occurring such that the load_tm counter overflows and TM is disabled whilst in the signal handler. This commit fixes the illegal TM state by ensuring that TM bit is always enabled before we return from restore_tm_sigcontexts(). A small comment correction is made as well. Fixes: 5d176f7 ("powerpc: tm: Enable transactional memory (TM) lazily for userspace") Cc: stable@vger.kernel.org # v4.9+ Signed-off-by: Gustavo Romero <gromero@linux.vnet.ibm.com> Signed-off-by: Breno Leitao <leitao@debian.org> Signed-off-by: Cyril Bur <cyrilbur@gmail.com> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
1 parent 265e60a commit 044215d

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

‎arch/powerpc/kernel/signal_64.c‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,9 +452,20 @@ static long restore_tm_sigcontexts(struct task_struct *tsk,
452452
if (MSR_TM_RESV(msr))
453453
return -EINVAL;
454454

455-
/* pull in MSR TM from user context */
455+
/* pull in MSR TS bits from user context */
456456
regs->msr = (regs->msr & ~MSR_TS_MASK) | (msr & MSR_TS_MASK);
457457

458+
/*
459+
* Ensure that TM is enabled in regs->msr before we leave the signal
460+
* handler. It could be the case that (a) user disabled the TM bit
461+
* through the manipulation of the MSR bits in uc_mcontext or (b) the
462+
* TM bit was disabled because a sufficient number of context switches
463+
* happened whilst in the signal handler and load_tm overflowed,
464+
* disabling the TM bit. In either case we can end up with an illegal
465+
* TM state leading to a TM Bad Thing when we return to userspace.
466+
*/
467+
regs->msr |= MSR_TM;
468+
458469
/* pull in MSR LE from user context */
459470
regs->msr = (regs->msr & ~MSR_LE) | (msr & MSR_LE);
460471

0 commit comments

Comments
 (0)