From patchwork Sat Mar 11 00:05:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Garnier X-Patchwork-Id: 9618229 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 B0C676046A for ; Sat, 11 Mar 2017 00:05:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A1665287A9 for ; Sat, 11 Mar 2017 00:05:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 953C5287B7; Sat, 11 Mar 2017 00:05:57 +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 269FD287A9 for ; Sat, 11 Mar 2017 00:05:55 +0000 (UTC) Received: (qmail 27792 invoked by uid 550); 11 Mar 2017 00:05:38 -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 27677 invoked from network); 11 Mar 2017 00:05:35 -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=tMJns0JAjzY3kV6xMshKvMgpMbTWgr/89iONzFxloss=; b=SlV7C1vulN2dcVJAz+L6zCq0MF4CaDRHK5A+M29SqITDidlErSpfMdiBAUTe7AkqQu 5wu5AxxFrC/TLlUBD4CXsogENJVVW+YkHLItuuqfgSGWGn4gH2ilkTiebV5sn8VY3C/+ SACksPL6YMD8ibvEiLD9Jy8bFcuy3KnBDL5wMRUsYWzy92K2x7c43+fwP+mtHHwQiCzf IIvFvvkOUq+pVDQ4I6YRyYTKtqkFYIfkB6ROvC0uISlz/odyTm26esNM/W2JAXo9Msp3 mkIEODPf/vRVTvXk0kr1Xs7rGfAweGkqF6qYhPFayLLS+XLKbqAF2/1bHTDCvWSZ1BeR W0xQ== 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=tMJns0JAjzY3kV6xMshKvMgpMbTWgr/89iONzFxloss=; b=GM2u3zlYnVOYqNj51a5bezBYHef/lNMoQqIqvGvUy1KIjDs2GKxPlsMQuIynthmz+q KB6uMHA+2VwiwgOCyHvjlI2WKQUH6XSk6t1zFSo1lgwtmdmFVM8wTyhQrDj8y//h14vW BwhRRrtz8wUiX2hew/AXmfGfc21fVPdI92iKklnr5/YdnpmwEVOW04a78mESnGf+Scm0 dZ1IrDzdLxoSj9OG+B+aYCK6s7Vb4wJIVHkPPFPuJKg76ajO7uyRoi1WDxcgHHeYnlpt kJ4XHYEDO5rc90Ez2tQhgvTPwgIOPhpwDFB5/CLQKFN5l88M0Lgdf9zN/G/K3sDn6eFA o+8Q== X-Gm-Message-State: AMke39n5IXLe5hiHcjg5erUaQa5PoCnh4ewxH2U/aEaalIwAUzpM88dR2EtpxUx0wn6TTthO X-Received: by 10.98.194.88 with SMTP id l85mr23949793pfg.55.1489190723044; Fri, 10 Mar 2017 16:05:23 -0800 (PST) From: Thomas Garnier To: Martin Schwidefsky , Heiko Carstens , David Howells , Arnd Bergmann , Al Viro , Dave Hansen , Thomas Garnier , =?UTF-8?q?Ren=C3=A9=20Nyffenegger?= , Andrew Morton , Kees Cook , "Paul E . McKenney" , Andy Lutomirski , Ard Biesheuvel , Nicolas Pitre , Petr Mladek , Sebastian Andrzej Siewior , Sergey Senozhatsky , Helge Deller , Rik van Riel , Ingo Molnar , John Stultz , Thomas Gleixner , Oleg Nesterov , Stephen Smalley , Pavel Tikhomirov , Frederic Weisbecker , Stanislav Kinsburskiy , Ingo Molnar , "H . Peter Anvin" , Paolo Bonzini , Dmitry Safonov , Borislav Petkov , Josh Poimboeuf , Brian Gerst , Jan Beulich , Christian Borntraeger , Fenghua Yu , He Chen , Russell King , Vladimir Murzin , Will Deacon , Catalin Marinas , Mark Rutland , James Morse , "David A . Long" , Pratyush Anand , Laura Abbott , Andre Przywara , Chris Metcalf 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: Fri, 10 Mar 2017 16:05:01 -0800 Message-Id: <20170311000501.46607-4-thgarnie@google.com> X-Mailer: git-send-email 2.12.0.246.ga2ecc84866-goog In-Reply-To: <20170311000501.46607-1-thgarnie@google.com> References: <20170311000501.46607-1-thgarnie@google.com> Subject: [kernel-hardening] [PATCH v3 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. --- Based on next-20170308 --- 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 896eba61e5ed..da54774838d8 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. */