From patchwork Tue Apr 4 17:47:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Garnier X-Patchwork-Id: 9662281 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 55DB46032D for ; Tue, 4 Apr 2017 17:48:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 49F0A283A6 for ; Tue, 4 Apr 2017 17:48:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3E4DC28520; Tue, 4 Apr 2017 17:48:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.wl.linuxfoundation.org (Postfix) with SMTP id 7800B283A6 for ; Tue, 4 Apr 2017 17:48:11 +0000 (UTC) Received: (qmail 14029 invoked by uid 550); 4 Apr 2017 17:47:53 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Delivered-To: mailing list kernel-hardening@lists.openwall.com Received: (qmail 13850 invoked from network); 4 Apr 2017 17:47:51 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=cBGY51w5bWGTCdxoYiNgEo8Hq/WUs+og/EUmvk6S5vk=; b=NUsAQo5ZKB2CPWxOXE0EBWiUPaxS4EtwA9WmsIe29Q6/Wtf91Ts3li494S8ubwITp4 4Qo9saqHIMek2zQ3LA+fYjRGN2u2qUvQSDKNH+xMrNSIHSBMSmnTdTmhfYEFEHtgDIn3 1zzWljVyvMBQUyXUpFgk5xqTssrk7lpA8RzGA4B9xQB3xEGyeSjWKbB3FU33wQYPJwXq M098Ng1sPNuhlB+CI48aK7OfpQUV9AYDiwM6hQKU3D1NPAdo3UE/D0lJrKKKn4zOclAO +1L5Aoizl5h1k94cK42+UylIW3ZcF4PsxXXqJLzx9lMSFc10MIchNX8QL8afz3aFJPJq lw2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=cBGY51w5bWGTCdxoYiNgEo8Hq/WUs+og/EUmvk6S5vk=; b=JaSMBsbhht4SJYtfyjSXhdGOCEtr+wyr40bYOVGN8jGpp9Z3oQZSx96Rp4pkZTBeND AV5v51v+HgumiIA6JqcXcytEpc4mvA36/seeU/z52B2d/WDC+ilVRITYwx4t/G68D3zs gPMHq/yT32PIpO2ounUs6ycFvdEkkOW+0113eNjHwuEgJ1ORgbAJzeWCcCPIGJAGf6Ir rMHeSFyQIZuXWxsmE8dSF27WdOYonmfnPLaYrhujpFke1QzZ3iaItw9jdTNRrkXuDnlY 5+kFv0p5kh4CJw8I8Uw6RHCsCEFFdrB8/92epBl5XrqWyBOsfPqZl9E+k0Y2zKIsz+Ym sFBQ== X-Gm-Message-State: AFeK/H3eQctrNNEi3Yye6m3+4s5NgZMKZZq/4A7DQKXCRmEJSBFEdWMQhQVF3/9sSuNR0LxQ X-Received: by 10.84.202.194 with SMTP id q2mr30396760plh.108.1491328058917; Tue, 04 Apr 2017 10:47:38 -0700 (PDT) From: Thomas Garnier To: Martin Schwidefsky , Heiko Carstens , Dave Hansen , Arnd Bergmann , Thomas Gleixner , Al Viro , David Howells , Thomas Garnier , =?UTF-8?q?Ren=C3=A9=20Nyffenegger?= , Andrew Morton , "Paul E . McKenney" , Ingo Molnar , Oleg Nesterov , Stephen Smalley , Pavel Tikhomirov , Ingo Molnar , "H . Peter Anvin" , Andy Lutomirski , Paolo Bonzini , Kees Cook , Rik van Riel , Josh Poimboeuf , Borislav Petkov , Brian Gerst , "Kirill A . Shutemov" , Christian Borntraeger , Russell King , 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 Date: Tue, 4 Apr 2017 10:47:27 -0700 Message-Id: <20170404174727.35478-4-thgarnie@google.com> X-Mailer: git-send-email 2.12.2.715.g7642488e1d-goog In-Reply-To: <20170404174727.35478-1-thgarnie@google.com> References: <20170404174727.35478-1-thgarnie@google.com> Subject: [kernel-hardening] [PATCH v6 4/4] arm64/syscalls: Specific usage of verify_pre_usermode_state X-Virus-Scanned: ClamAV using ClamSMTP Implement specific usage of verify_pre_usermode_state for user-mode returns for arm64. Signed-off-by: Thomas Garnier --- Based on next-20170404 --- arch/arm64/Kconfig | 1 + arch/arm64/kernel/entry.S | 15 +++++++++++++++ 2 files changed, 16 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..6d598e7051c3 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,12 @@ finish_ret_to_user: kernel_exit 0 ENDPROC(ret_to_user) +addr_limit_fail: + stp x0, lr, [sp,#-16]! + bl asm_verify_pre_usermode_state + ldp x0, lr, [sp],#16 + ret lr + /* * This is how we return from a fork. */