Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932140AbdCVUjG (ORCPT ); Wed, 22 Mar 2017 16:39:06 -0400 Received: from mail-pg0-f44.google.com ([74.125.83.44]:36599 "EHLO mail-pg0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932075AbdCVUit (ORCPT ); Wed, 22 Mar 2017 16:38:49 -0400 From: Thomas Garnier To: Martin Schwidefsky , Heiko Carstens , Dave Hansen , David Howells , Al Viro , Arnd Bergmann , Thomas Garnier , =?UTF-8?q?Ren=C3=A9=20Nyffenegger?= , Andrew Morton , "Paul E . McKenney" , Ingo Molnar , Thomas Gleixner , Oleg Nesterov , Pavel Tikhomirov , Stephen Smalley , Ingo Molnar , "H . Peter Anvin" , Andy Lutomirski , Paolo Bonzini , Rik van Riel , Kees Cook , Josh Poimboeuf , Borislav Petkov , Brian Gerst , "Kirill A . Shutemov" , Christian Borntraeger , Russell King , Vladimir Murzin , Will Deacon , Catalin Marinas , Mark Rutland , James Morse Cc: linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, x86@kernel.org, linux-arm-kernel@lists.infradead.org, kernel-hardening@lists.openwall.com Subject: [PATCH v4 4/4] arm64/syscalls: Specific usage of verify_pre_usermode_state Date: Wed, 22 Mar 2017 13:38:34 -0700 Message-Id: <20170322203834.67556-4-thgarnie@google.com> X-Mailer: git-send-email 2.12.1.500.gab5fba24ee-goog In-Reply-To: <20170322203834.67556-1-thgarnie@google.com> References: <20170322203834.67556-1-thgarnie@google.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2062 Lines: 73 Implement specific usage of verify_pre_usermode_state for user-mode returns for arm64. --- Based on next-20170322 --- arch/arm64/Kconfig | 1 + arch/arm64/kernel/entry.S | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index f2b0b528037d..0e86d87259f4 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..685b43771ac9 100644 --- a/arch/arm64/kernel/entry.S +++ b/arch/arm64/kernel/entry.S @@ -744,6 +744,10 @@ 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 + mov x1, #TASK_SIZE_64 + cmp x2, x1 + b.ne 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 +775,11 @@ work_pending: */ ret_to_user: disable_irq // disable interrupts + ldr x2, [tsk, #TSK_TI_ADDR_LIMIT] // check addr limit change + mov x1, #TASK_SIZE_64 + cmp x2, x1 + b.ne addr_limit_fail + ldr x1, [tsk, #TSK_TI_FLAGS] and x2, x1, #_TIF_WORK_MASK cbnz x2, work_pending @@ -779,6 +788,22 @@ finish_ret_to_user: kernel_exit 0 ENDPROC(ret_to_user) +addr_limit_fail: +#ifdef CONFIG_BUG_ON_DATA_CORRUPTION + stp x0, lr, [sp,#-16]! + bl verify_pre_usermode_state + ldp x0, lr, [sp],#16 +#else + /* + * Similar to set_fs(USER_DS) in verify_pre_usermode_state without a + * warning. + */ + mov x2, #TASK_SIZE_64 + str x2, [tsk, #TSK_TI_ADDR_LIMIT] + ALTERNATIVE(nop, SET_PSTATE_UAO(0), ARM64_HAS_UAO, CONFIG_ARM64_UAO) +#endif + ret lr + /* * This is how we return from a fork. */ -- 2.12.1.500.gab5fba24ee-goog