Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1620418 > unrolled thread

Re: [PATCH v7 4/4] arm64/syscalls: Architecture specific pre-usermode check

Started byCatalin Marinas <catalin.marinas@arm.com>
First post2017-04-10 19:20 +0200
Last post2017-04-10 22:10 +0200
Articles 4 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: [PATCH v7 4/4] arm64/syscalls: Architecture specific  pre-usermode check Catalin Marinas <catalin.marinas@arm.com> - 2017-04-10 19:20 +0200
    [PATCH v7 4/4] arm64/syscalls: Architecture specific pre-usermode check Thomas Garnier <thgarnie@google.com> - 2017-04-10 22:10 +0200
    [PATCH v7 4/4] arm64/syscalls: Architecture specific pre-usermode check Thomas Garnier <thgarnie@google.com> - 2017-04-10 22:10 +0200
      Re: [PATCH v7 4/4] arm64/syscalls: Architecture specific pre-usermode check Thomas Garnier <thgarnie@google.com> - 2017-04-10 22:10 +0200

#1620418 — Re: [PATCH v7 4/4] arm64/syscalls: Architecture specific pre-usermode check

FromCatalin Marinas <catalin.marinas@arm.com>
Date2017-04-10 19:20 +0200
SubjectRe: [PATCH v7 4/4] arm64/syscalls: Architecture specific pre-usermode check
Message-ID<tuL8T-3IQ-33@gated-at.bofh.it>
On Mon, Apr 10, 2017 at 09:44:20AM -0700, Thomas Garnier wrote:
> Disable the generic pre-usermode check in favor of an optimized
> implementation. This patch adds specific checks on user-mode return path
> to make it faster and smaller.
> 
> The address limit is checked on each syscall return path to user-mode.
> If it was changed, a generic handler is called to stop the kernel on an
> explicit check.
> 
> Signed-off-by: Thomas Garnier <thgarnie@google.com>
> ---
> Based on next-20170410
> ---
>  arch/arm64/Kconfig        |  1 +
>  arch/arm64/kernel/entry.S | 13 +++++++++++++
>  2 files changed, 14 insertions(+)
> 
> diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
> index 9b8fcab7da56..3f9e8e7d9376 100644
> --- a/arch/arm64/Kconfig
> +++ b/arch/arm64/Kconfig
> @@ -24,6 +24,7 @@ config ARM64
>  	select ARCH_WANT_COMPAT_IPC_PARSE_VERSION
>  	select ARCH_WANT_FRAME_POINTERS
>  	select ARCH_HAS_UBSAN_SANITIZE_ALL
> +	select ARCH_NO_SYSCALL_VERIFY_PRE_USERMODE_STATE
>  	select ARM_AMBA
>  	select ARM_ARCH_TIMER
>  	select ARM_GIC
> diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S
> index 43512d4d7df2..bdd094c7837a 100644
> --- a/arch/arm64/kernel/entry.S
> +++ b/arch/arm64/kernel/entry.S
> @@ -744,6 +744,8 @@ ENDPROC(cpu_switch_to)
>  ret_fast_syscall:
>  	disable_irq				// disable interrupts
>  	str	x0, [sp, #S_X0]			// returned x0
> +	ldr	x2, [tsk, #TSK_TI_ADDR_LIMIT]	// check addr limit change
> +	tbnz	x2, #63, addr_limit_fail
>  	ldr	x1, [tsk, #TSK_TI_FLAGS]	// re-check for syscall tracing
>  	and	x2, x1, #_TIF_SYSCALL_WORK
>  	cbnz	x2, ret_fast_syscall_trace
> @@ -771,6 +773,9 @@ work_pending:
>   */
>  ret_to_user:
>  	disable_irq				// disable interrupts
> +	ldr	x2, [tsk, #TSK_TI_ADDR_LIMIT]	// check addr limit change
> +	tbnz	x2, #63, addr_limit_fail
> +

Nitpick: unnecessary empty line added.

>  	ldr	x1, [tsk, #TSK_TI_FLAGS]
>  	and	x2, x1, #_TIF_WORK_MASK
>  	cbnz	x2, work_pending
> @@ -780,6 +785,14 @@ finish_ret_to_user:
>  ENDPROC(ret_to_user)
>  
>  /*
> + * Address limit was incorrect before returning in user-mode which could be
> + * used to elevate privileges. Call the generic handler to stop the kernel on
> + * the appropriate check. This function does not return.
> + */
> +addr_limit_fail:
> +	bl address_limit_check_failed

You could do a "b address_limit_check_failed" rather than "bl" since we
don't care about returning here (and a nitpick: insert tab between "b"
and "address_limit_check_failed").

With the above:

Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>

[toc] | [next] | [standalone]


#1620692 — [PATCH v7 4/4] arm64/syscalls: Architecture specific pre-usermode check

FromThomas Garnier <thgarnie@google.com>
Date2017-04-10 22:10 +0200
Subject[PATCH v7 4/4] arm64/syscalls: Architecture specific pre-usermode check
Message-ID<tuNNn-5x7-7@gated-at.bofh.it>
In reply to#1620418
Disable the generic pre-usermode check in favor of an optimized
implementation. This patch adds specific checks on user-mode return path
to make it faster and smaller.

The address limit is checked on each syscall return path to user-mode.
If it was changed, a generic handler is called to stop the kernel on an
explicit check.

Signed-off-by: Thomas Garnier <thgarnie@google.com>
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
---
Based on next-20170410
Fix comments from Catalin and add review-by in the message.
---
 arch/arm64/Kconfig        |  1 +
 arch/arm64/kernel/entry.S | 12 ++++++++++++
 2 files changed, 13 insertions(+)

diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index 9b8fcab7da56..3f9e8e7d9376 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -24,6 +24,7 @@ config ARM64
 	select ARCH_WANT_COMPAT_IPC_PARSE_VERSION
 	select ARCH_WANT_FRAME_POINTERS
 	select ARCH_HAS_UBSAN_SANITIZE_ALL
+	select ARCH_NO_SYSCALL_VERIFY_PRE_USERMODE_STATE
 	select ARM_AMBA
 	select ARM_ARCH_TIMER
 	select ARM_GIC
diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S
index 43512d4d7df2..04c44c6f41b1 100644
--- a/arch/arm64/kernel/entry.S
+++ b/arch/arm64/kernel/entry.S
@@ -744,6 +744,8 @@ ENDPROC(cpu_switch_to)
 ret_fast_syscall:
 	disable_irq				// disable interrupts
 	str	x0, [sp, #S_X0]			// returned x0
+	ldr	x2, [tsk, #TSK_TI_ADDR_LIMIT]	// check addr limit change
+	tbnz	x2, #63, addr_limit_fail
 	ldr	x1, [tsk, #TSK_TI_FLAGS]	// re-check for syscall tracing
 	and	x2, x1, #_TIF_SYSCALL_WORK
 	cbnz	x2, ret_fast_syscall_trace
@@ -771,6 +773,8 @@ work_pending:
  */
 ret_to_user:
 	disable_irq				// disable interrupts
+	ldr	x2, [tsk, #TSK_TI_ADDR_LIMIT]	// check addr limit change
+	tbnz	x2, #63, addr_limit_fail
 	ldr	x1, [tsk, #TSK_TI_FLAGS]
 	and	x2, x1, #_TIF_WORK_MASK
 	cbnz	x2, work_pending
@@ -780,6 +784,14 @@ finish_ret_to_user:
 ENDPROC(ret_to_user)
 
 /*
+ * Address limit was incorrect before returning in user-mode which could be
+ * used to elevate privileges. Call the generic handler to stop the kernel on
+ * the appropriate check. This function does not return.
+ */
+addr_limit_fail:
+	b	address_limit_check_failed
+
+/*
  * This is how we return from a fork.
  */
 ENTRY(ret_from_fork)
-- 
2.12.2.715.g7642488e1d-goog

[toc] | [prev] | [next] | [standalone]


#1620695 — [PATCH v7 4/4] arm64/syscalls: Architecture specific pre-usermode check

FromThomas Garnier <thgarnie@google.com>
Date2017-04-10 22:10 +0200
Subject[PATCH v7 4/4] arm64/syscalls: Architecture specific pre-usermode check
Message-ID<tuNNn-5x7-17@gated-at.bofh.it>
In reply to#1620418
Disable the generic pre-usermode check in favor of an optimized
implementation. This patch adds specific checks on user-mode return path
to make it faster and smaller.

The address limit is checked on each syscall return path to user-mode.
If it was changed, a generic handler is called to stop the kernel on an
explicit check.

Signed-off-by: Thomas Garnier <thgarnie@google.com>
---
Based on next-20170410
---
 arch/arm64/Kconfig        |  1 +
 arch/arm64/kernel/entry.S | 13 +++++++++++++
 2 files changed, 14 insertions(+)

diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index 9b8fcab7da56..3f9e8e7d9376 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -24,6 +24,7 @@ config ARM64
 	select ARCH_WANT_COMPAT_IPC_PARSE_VERSION
 	select ARCH_WANT_FRAME_POINTERS
 	select ARCH_HAS_UBSAN_SANITIZE_ALL
+	select ARCH_NO_SYSCALL_VERIFY_PRE_USERMODE_STATE
 	select ARM_AMBA
 	select ARM_ARCH_TIMER
 	select ARM_GIC
diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S
index 43512d4d7df2..bdd094c7837a 100644
--- a/arch/arm64/kernel/entry.S
+++ b/arch/arm64/kernel/entry.S
@@ -744,6 +744,8 @@ ENDPROC(cpu_switch_to)
 ret_fast_syscall:
 	disable_irq				// disable interrupts
 	str	x0, [sp, #S_X0]			// returned x0
+	ldr	x2, [tsk, #TSK_TI_ADDR_LIMIT]	// check addr limit change
+	tbnz	x2, #63, addr_limit_fail
 	ldr	x1, [tsk, #TSK_TI_FLAGS]	// re-check for syscall tracing
 	and	x2, x1, #_TIF_SYSCALL_WORK
 	cbnz	x2, ret_fast_syscall_trace
@@ -771,6 +773,9 @@ work_pending:
  */
 ret_to_user:
 	disable_irq				// disable interrupts
+	ldr	x2, [tsk, #TSK_TI_ADDR_LIMIT]	// check addr limit change
+	tbnz	x2, #63, addr_limit_fail
+
 	ldr	x1, [tsk, #TSK_TI_FLAGS]
 	and	x2, x1, #_TIF_WORK_MASK
 	cbnz	x2, work_pending
@@ -780,6 +785,14 @@ finish_ret_to_user:
 ENDPROC(ret_to_user)
 
 /*
+ * Address limit was incorrect before returning in user-mode which could be
+ * used to elevate privileges. Call the generic handler to stop the kernel on
+ * the appropriate check. This function does not return.
+ */
+addr_limit_fail:
+	bl address_limit_check_failed
+
+/*
  * This is how we return from a fork.
  */
 ENTRY(ret_from_fork)
-- 
2.12.2.715.g7642488e1d-goog

[toc] | [prev] | [next] | [standalone]


#1620696 — Re: [PATCH v7 4/4] arm64/syscalls: Architecture specific pre-usermode check

FromThomas Garnier <thgarnie@google.com>
Date2017-04-10 22:10 +0200
SubjectRe: [PATCH v7 4/4] arm64/syscalls: Architecture specific pre-usermode check
Message-ID<tuNNo-5x7-19@gated-at.bofh.it>
In reply to#1620695
On Mon, Apr 10, 2017 at 1:06 PM, Thomas Garnier <thgarnie@google.com> wrote:
> Disable the generic pre-usermode check in favor of an optimized
> implementation. This patch adds specific checks on user-mode return path
> to make it faster and smaller.
>
> The address limit is checked on each syscall return path to user-mode.
> If it was changed, a generic handler is called to stop the kernel on an
> explicit check.
>
> Signed-off-by: Thomas Garnier <thgarnie@google.com>
> ---
> Based on next-20170410
> ---
>  arch/arm64/Kconfig        |  1 +
>  arch/arm64/kernel/entry.S | 13 +++++++++++++
>  2 files changed, 14 insertions(+)
>
> diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
> index 9b8fcab7da56..3f9e8e7d9376 100644
> --- a/arch/arm64/Kconfig
> +++ b/arch/arm64/Kconfig
> @@ -24,6 +24,7 @@ config ARM64
>         select ARCH_WANT_COMPAT_IPC_PARSE_VERSION
>         select ARCH_WANT_FRAME_POINTERS
>         select ARCH_HAS_UBSAN_SANITIZE_ALL
> +       select ARCH_NO_SYSCALL_VERIFY_PRE_USERMODE_STATE
>         select ARM_AMBA
>         select ARM_ARCH_TIMER
>         select ARM_GIC
> diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S
> index 43512d4d7df2..bdd094c7837a 100644
> --- a/arch/arm64/kernel/entry.S
> +++ b/arch/arm64/kernel/entry.S
> @@ -744,6 +744,8 @@ ENDPROC(cpu_switch_to)
>  ret_fast_syscall:
>         disable_irq                             // disable interrupts
>         str     x0, [sp, #S_X0]                 // returned x0
> +       ldr     x2, [tsk, #TSK_TI_ADDR_LIMIT]   // check addr limit change
> +       tbnz    x2, #63, addr_limit_fail
>         ldr     x1, [tsk, #TSK_TI_FLAGS]        // re-check for syscall tracing
>         and     x2, x1, #_TIF_SYSCALL_WORK
>         cbnz    x2, ret_fast_syscall_trace
> @@ -771,6 +773,9 @@ work_pending:
>   */
>  ret_to_user:
>         disable_irq                             // disable interrupts
> +       ldr     x2, [tsk, #TSK_TI_ADDR_LIMIT]   // check addr limit change
> +       tbnz    x2, #63, addr_limit_fail
> +
>         ldr     x1, [tsk, #TSK_TI_FLAGS]
>         and     x2, x1, #_TIF_WORK_MASK
>         cbnz    x2, work_pending
> @@ -780,6 +785,14 @@ finish_ret_to_user:
>  ENDPROC(ret_to_user)
>
>  /*
> + * Address limit was incorrect before returning in user-mode which could be
> + * used to elevate privileges. Call the generic handler to stop the kernel on
> + * the appropriate check. This function does not return.
> + */
> +addr_limit_fail:
> +       bl address_limit_check_failed
> +
> +/*
>   * This is how we return from a fork.
>   */
>  ENTRY(ret_from_fork)
> --
> 2.12.2.715.g7642488e1d-goog
>

Ignore this revision, I sent the previous patch by mistake. The next
email is the changed patch.
Sorry about that.


-- 
Thomas

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web