Skip to contentSkip to conversation

FAILED: patch "[PATCH] s390: always save and restore all registers on context switch" failed to apply to 4.4-stable tree

PATCH [email protected] 2 participants 3 messages Dec 11, 2017 – Dec 14, 2017

Subsystems (2)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

The patch below does not apply to the 4.4-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]>.

thanks,

greg k-h

------------------ original commit in Linus's tree ------------------

Quoted 1 line

From fbbd7f1a51965b50dd12924841da0d478f3da71b Mon Sep 17 00:00:00 2001

From: Heiko Carstens <[email protected]>
Date: Mon, 20 Nov 2017 12:38:44 +0100
Subject: [PATCH] s390: always save and restore all registers on context switch

The switch_to() macro has an optimization to avoid saving and restoring register contents that aren't needed for kernel threads.

There is however the possibility that a kernel thread execve's a user space program. In such a case the execve'd process can partially see the contents of the previous process, which shouldn't be allowed.

To avoid this, simply always save and restore register contents on context switch.

Cc <[email protected]> # v2.6.37+
Fixes fdb6d070effba ("switch_to: dont restore/save access & fpu regs for kernel threads")
arch/s390/include/asm/switch_to.h +13 -14
index ec7b476c1ac5..c61b2cc1a8a8 100644
@@ -30,21 +30,20 @@ static inline void restore_access_regs(unsigned int *acrs)
 	asm volatile("lam 0,15,%0" : : "Q" (*(acrstype *)acrs));
 }
 
-#define switch_to(prev,next,last) do {					\
-	if (prev->mm) {							\
-		save_fpu_regs();					\
-		save_access_regs(&prev->thread.acrs[0]);		\
-		save_ri_cb(prev->thread.ri_cb);				\
-		save_gs_cb(prev->thread.gs_cb);				\
-	}								\
+#define switch_to(prev, next, last) do {				\
+	/* save_fpu_regs() sets the CIF_FPU flag, which enforces	\
+	 * a restore of the floating point / vector registers as	\
+	 * soon as the next task returns to user space			\
+	 */								\
+	save_fpu_regs();						\
+	save_access_regs(&prev->thread.acrs[0]);			\
+	save_ri_cb(prev->thread.ri_cb);					\
+	save_gs_cb(prev->thread.gs_cb);					\
 	update_cr_regs(next);						\
-	if (next->mm) {							\
-		set_cpu_flag(CIF_FPU);					\
-		restore_access_regs(&next->thread.acrs[0]);		\
-		restore_ri_cb(next->thread.ri_cb, prev->thread.ri_cb);	\
-		restore_gs_cb(next->thread.gs_cb);			\
-	}								\
-	prev = __switch_to(prev,next);					\
+	restore_access_regs(&next->thread.acrs[0]);			\
+	restore_ri_cb(next->thread.ri_cb, prev->thread.ri_cb);		\
+	restore_gs_cb(next->thread.gs_cb);				\
+	prev = __switch_to(prev, next);					\
 } while (0)
 
 #endif /* __ASM_SWITCH_TO_H */
#1 lore raw
Quoted 5 lines · On Mon, Dec 11, 2017 at 10:30:32PM +0100, [email protected] wrote:

The patch below does not apply to the 4.4-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]>.

Please find below the patch applies against 4.4-stable.

Quoted 1 line

From 7ad104f73a7eece168875e2bc19d7c3f8944a938 Mon Sep 17 00:00:00 2001

From: Heiko Carstens <[email protected]>
Date: Mon, 20 Nov 2017 12:38:44 +0100
Subject: [PATCH] s390: always save and restore all registers on context switch

commit fbbd7f1a51965b50dd12924841da0d478f3da71b upstream.

The switch_to() macro has an optimization to avoid saving and restoring register contents that aren't needed for kernel threads.

There is however the possibility that a kernel thread execve's a user space program. In such a case the execve'd process can partially see the contents of the previous process, which shouldn't be allowed.

To avoid this, simply always save and restore register contents on context switch.

Fixes fdb6d070effba ("switch_to: dont restore/save access & fpu regs for kernel threads")
---
 arch/s390/include/asm/switch_to.h | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)
arch/s390/include/asm/switch_to.h +9 -10
index dde6b52359c5..ff2fbdafe689 100644
@@ -29,17 +29,16 @@ static inline void restore_access_regs(unsigned int *acrs)
 }
 
 #define switch_to(prev,next,last) do {					\
-	if (prev->mm) {							\
-		save_fpu_regs();					\
-		save_access_regs(&prev->thread.acrs[0]);		\
-		save_ri_cb(prev->thread.ri_cb);				\
-	}								\
+	/* save_fpu_regs() sets the CIF_FPU flag, which enforces	\
+	 * a restore of the floating point / vector registers as	\
+	 * soon as the next task returns to user space			\
+	 */								\
+	save_fpu_regs();						\
+	save_access_regs(&prev->thread.acrs[0]);			\
+	save_ri_cb(prev->thread.ri_cb);					\
 	update_cr_regs(next);						\
-	if (next->mm) {							\
-		set_cpu_flag(CIF_FPU);					\
-		restore_access_regs(&next->thread.acrs[0]);		\
-		restore_ri_cb(next->thread.ri_cb, prev->thread.ri_cb);	\
-	}								\
+	restore_access_regs(&next->thread.acrs[0]);			\
+	restore_ri_cb(next->thread.ri_cb, prev->thread.ri_cb);		\
 	prev = __switch_to(prev,next);					\
 } while (0)
 
Signature · 1 line
2.13.5
author maintainer Applied
#2 lore raw
Quoted 8 lines · Heiko Carstens
Quoted 5 lines · On Mon, Dec 11, 2017 at 10:30:32PM +0100, [email protected] wrote:

The patch below does not apply to the 4.4-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]>.

Please find below the patch applies against 4.4-stable.

Applied, thanks.

greg k-h