Skip to contentSkip to conversation

Patch "arm64: kernel: Save and restore UAO and addr_limit on exception entry" has been added to the 4.4-stable tree

PATCH [email protected] 1 participant 1 message Aug 17, 2016

Subsystems (3)
lore
Share & tools
lore

[email protected]

author maintainer Applied
#0 lore raw

This is a note to let you know that I've just added the patch titled

arm64: kernel: Save and restore UAO and addr_limit on exception entry

to the 4.4-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
arm64-kernel-save-and-restore-uao-and-addr_limit-on-exception-entry.patch
and it can be found in the queue-4.4 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.

Quoted 1 line

From e19a6ee2460bdd0d0055a6029383422773f9999a Mon Sep 17 00:00:00 2001

From: James Morse <[email protected]>
Date: Mon, 20 Jun 2016 18:28:01 +0100
Subject: arm64: kernel: Save and restore UAO and addr_limit on exception entry

From: James Morse <[email protected]>

commit e19a6ee2460bdd0d0055a6029383422773f9999a upstream.

If we take an exception while at EL1, the exception handler inherits the original context's addr_limit and PSTATE.UAO values. To be consistent always reset addr_limit and PSTATE.UAO on (re-)entry to EL1. This prevents accidental re-use of the original context's addr_limit.

Based on a similar patch for arm from Russell King.

[ backport to stop perf misusing inherited addr_limit.
Removed code interacting with UAO and the irqstack ]

---
 arch/arm64/include/asm/ptrace.h |    2 ++
 arch/arm64/kernel/asm-offsets.c |    1 +
 arch/arm64/kernel/entry.S       |   15 ++++++++++++++-
 3 files changed, 17 insertions(+), 1 deletion(-)
arch/arm64/include/asm/ptrace.h +2 -0
@@ -117,6 +117,8 @@ struct pt_regs {
 	};
 	u64 orig_x0;
 	u64 syscallno;
+	u64 orig_addr_limit;
+	u64 unused;	// maintain 16 byte alignment
 };
 
 #define arch_has_single_step()	(1)
arch/arm64/kernel/asm-offsets.c +1 -0
@@ -58,6 +58,7 @@ int main(void)
   DEFINE(S_PC,			offsetof(struct pt_regs, pc));
   DEFINE(S_ORIG_X0,		offsetof(struct pt_regs, orig_x0));
   DEFINE(S_SYSCALLNO,		offsetof(struct pt_regs, syscallno));
+  DEFINE(S_ORIG_ADDR_LIMIT,	offsetof(struct pt_regs, orig_addr_limit));
   DEFINE(S_FRAME_SIZE,		sizeof(struct pt_regs));
   BLANK();
   DEFINE(MM_CONTEXT_ID,		offsetof(struct mm_struct, context.id.counter));
arch/arm64/kernel/entry.S +14 -1
@@ -27,6 +27,7 @@
 #include <asm/cpufeature.h>
 #include <asm/errno.h>
 #include <asm/esr.h>
+#include <asm/memory.h>
 #include <asm/thread_info.h>
 #include <asm/unistd.h>
 
@@ -93,7 +94,13 @@
 	disable_step_tsk x19, x20		// exceptions when scheduling.
 	.else
 	add	x21, sp, #S_FRAME_SIZE
-	.endif
+	get_thread_info tsk
+	/* Save the task's original addr_limit and set USER_DS (TASK_SIZE_64) */
+	ldr	x20, [tsk, #TI_ADDR_LIMIT]
+	str	x20, [sp, #S_ORIG_ADDR_LIMIT]
+	mov	x20, #TASK_SIZE_64
+	str	x20, [tsk, #TI_ADDR_LIMIT]
+	.endif /* \el == 0 */
 	mrs	x22, elr_el1
 	mrs	x23, spsr_el1
 	stp	lr, x21, [sp, #S_LR]
@@ -117,6 +124,12 @@
 	.endm
 
 	.macro	kernel_exit, el
+	.if	\el != 0
+	/* Restore the task's original addr_limit. */
+	ldr	x20, [sp, #S_ORIG_ADDR_LIMIT]
+	str	x20, [tsk, #TI_ADDR_LIMIT]
+	.endif
+
 	ldp	x21, x22, [sp, #S_PC]		// load ELR, SPSR
 	.if	\el == 0
 	ct_user_enter

Patches currently in stable-queue which might be from [email protected] are

queue-4.4/arm64-kernel-save-and-restore-uao-and-addr_limit-on-exception-entry.patch