Skip to content

Commit d93f9e2

Browse files
chleroympe
authored andcommitted
powerpc/32s: Fix kuap_kernel_restore()
At interrupt exit, kuap_kernel_restore() calls kuap_unlock() with the value contained in regs->kuap. However, when regs->kuap contains 0xffffffff it means that KUAP was not unlocked so calling kuap_unlock() is unrelevant and results in jeopardising the contents of kernel space segment registers. So check that regs->kuap doesn't contain KUAP_NONE before calling kuap_unlock(). In the meantime it also means that if KUAP has not been correcly locked back at interrupt exit, it must be locked before continuing. This is done by checking the content of current->thread.kuap which was returned by kuap_get_and_assert_locked() Fixes: 1613252 ("powerpc/32s: Rework Kernel Userspace Access Protection") Reported-by: Stan Johnson <[email protected]> Signed-off-by: Christophe Leroy <[email protected]> Signed-off-by: Michael Ellerman <[email protected]> Link: https://lore.kernel.org/r/0d0c4d0f050a637052287c09ba521bad960a2790.1631715131.git.christophe.leroy@csgroup.eu
1 parent 5a4b032 commit d93f9e2

File tree

1 file changed

+8
-0
lines changed
  • arch/powerpc/include/asm/book3s/32

1 file changed

+8
-0
lines changed

arch/powerpc/include/asm/book3s/32/kup.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,14 @@ static inline void kuap_kernel_restore(struct pt_regs *regs, unsigned long kuap)
136136
if (kuap_is_disabled())
137137
return;
138138

139+
if (unlikely(kuap != KUAP_NONE)) {
140+
current->thread.kuap = KUAP_NONE;
141+
kuap_lock(kuap, false);
142+
}
143+
144+
if (likely(regs->kuap == KUAP_NONE))
145+
return;
146+
139147
current->thread.kuap = regs->kuap;
140148

141149
kuap_unlock(regs->kuap, false);

0 commit comments

Comments
 (0)