From patchwork Mon Apr 10 16:44:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Garnier X-Patchwork-Id: 9673345 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 B0396600CB for ; Mon, 10 Apr 2017 16:44:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B1FB82811C for ; Mon, 10 Apr 2017 16:44:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A65DC2823E; Mon, 10 Apr 2017 16:44:59 +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 D9A7C28174 for ; Mon, 10 Apr 2017 16:44:58 +0000 (UTC) Received: (qmail 7741 invoked by uid 550); 10 Apr 2017 16:44:42 -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 7662 invoked from network); 10 Apr 2017 16:44:40 -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=40uxhJLm70VKAINHkGDKiBAm1GDfl9ArlYUHuxuPBdY=; b=FHeGuOZKMNAAnofzg4ZZatfbQfY2Zgjm6V60OlneNUau7K3zqncopGmuYb77avSQJQ MgCuTU/Ykpp5fVOxlSiwH0ctALZEDwXOE8uBb2FFXrQgnqrTqlfQAmo7NmmZyG3ntNak Z0pxTTZQTc7V3/TSvdFbT083ejVS5IrwERsRFfMWBpIEXFXlhOQE4/97IPwLJVwFqmYL zyB4Ghsu8aPg/GNTXzaKkicY68KRlV8xRer2IvZqH6OH8E0vFVD3sY+BtPmH19bSMD6e MZxW1Q5yF0jcYoEWz3Th+ITh6Y+nX8YFHP/o6v2Axd9/n+KD6d8CHjpNTcXhcBGVfIo/ +RoA== 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=40uxhJLm70VKAINHkGDKiBAm1GDfl9ArlYUHuxuPBdY=; b=jBA5W0oevzP93WbjM5PY5XiFc3AROoJj3cSeuegmJSS9krymYVMwA07Q3DViwmV5yn eamCj7MYBHr3LiMoR6qh+r+rTAHK3gZ0GHeSHXuVm7dI65oDtZOjc41tiNWxXO3Osk6U U772TG5PnJYsy5aDqfb3v1Bea/JNJbwS1xnmY7AruKApXvc2AIuCb9rMy27/1Llolcms BQUmw5EiZmg/tP2IRsg8ZPJ/xu++i2el6IW1lyTCJBo2klCssw0SBOcCxfs4LQj+nmJb mv4HwDgQVDYxnRhfjGjUAThl8+hPXIcXsAonchX4gEPL3DUlxJYfyQMg3Z1JE6gKyPVI 1YQQ== X-Gm-Message-State: AFeK/H2f/8x5uBuG4p5NYzgYI4gco7Agqm/7C36HwlmvoJfjz88xWa8pUYHcG/cnyCqu9R4T X-Received: by 10.99.107.72 with SMTP id g69mr57507169pgc.149.1491842668753; Mon, 10 Apr 2017 09:44:28 -0700 (PDT) From: Thomas Garnier To: Martin Schwidefsky , Heiko Carstens , Arnd Bergmann , Dave Hansen , Andrew Morton , Thomas Garnier , David Howells , =?UTF-8?q?Ren=C3=A9=20Nyffenegger?= , "Paul E . McKenney" , Ingo Molnar , Thomas Gleixner , 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: Mon, 10 Apr 2017 09:44:20 -0700 Message-Id: <20170410164420.64003-4-thgarnie@google.com> X-Mailer: git-send-email 2.12.2.715.g7642488e1d-goog In-Reply-To: <20170410164420.64003-1-thgarnie@google.com> References: <20170410164420.64003-1-thgarnie@google.com> Subject: [kernel-hardening] [PATCH v7 4/4] arm64/syscalls: Architecture specific pre-usermode check X-Virus-Scanned: ClamAV using ClamSMTP 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 Reviewed-by: Catalin Marinas --- 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)