From patchwork Wed Apr 26 18:34:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Garnier X-Patchwork-Id: 9701823 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 D0653603F7 for ; Wed, 26 Apr 2017 18:35:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C6D1B2846C for ; Wed, 26 Apr 2017 18:35:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BA684285E7; Wed, 26 Apr 2017 18:35:23 +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 EB7E028399 for ; Wed, 26 Apr 2017 18:35:22 +0000 (UTC) Received: (qmail 21764 invoked by uid 550); 26 Apr 2017 18:35:08 -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 21634 invoked from network); 26 Apr 2017 18:35:06 -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=U1kGXz0wmnWU83hPm/EVbM1+9oeuu4ogU+HKdCkIDoU=; b=B7ph6BYtUnkv3KXLvocZNX3+n19VGDwkOAeL3N77mEDwWYNop+dhC79WikLGEJCjZM M9Y0DUl4FscvmNCTeLjrHKgxrmqbNqm+zhqy/EYkrdmkK1iuDC1qQybCZR8ejl3HGnr9 G2t2TBF3kNouoglgc2uBOZPHWIcwzPocdENxLPlvEiWKoWNJzwd42p3awSK+blDthOXb CP3JFsxh1AGlg5b7lBfmj0usve1JVaGAD2jvKJmuXwXjfDXf3XwdXIC6MHnjz+RXv5Ji YXWtzNQhf27nIBYM/KJc8790yPyYjVMWC0tvncS1hxpZolI+RtOmBK55BR5GiFDrlNQf l+Nw== 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=U1kGXz0wmnWU83hPm/EVbM1+9oeuu4ogU+HKdCkIDoU=; b=DnZG94OWEW9mj8hkufQvzKynq4pnW7S8hik0afSgNgn4TVlFuiso9JKUwB8qTTKi+r NlhPgPwFWF+qvcQ7SJ8+mb9ueUxG7RnbNe6RUqzeHnnKGD9rOjnyV7OaCp98Lp+yei1C Y/XJvLEmnm12onLDSUALtGwnAsE7O2/uUyIovpcTXPacoqKnM9T5/dQjdXD50HF/hjnk 1PsF0CqKJZ19WZi7CNB4/8jsH6o2+ImQbXgkfdW9hXB4RXCCH4y6vGTQ9mMwivSeVcba S3hrjYxH3CuDb9C3j5E61eCbaqLHB+SyczNj/DOjFcVY91XxQDZP+uC1Qh7LJGWXN2gb 3HcQ== X-Gm-Message-State: AN3rC/6lGWw4vGW/TvmDgoihGcU1Aa9jy8kgwvStIY8+GBzblldA6OwX xG65oCXqQ6+r8ld8 X-Received: by 10.98.79.214 with SMTP id f83mr1292369pfj.201.1493231694427; Wed, 26 Apr 2017 11:34:54 -0700 (PDT) From: Thomas Garnier To: Martin Schwidefsky , Heiko Carstens , Dave Hansen , Arnd Bergmann , David Howells , =?UTF-8?q?Ren=C3=A9=20Nyffenegger?= , Thomas Garnier , Andrew Morton , "Paul E . McKenney" , Ingo Molnar , "Eric W . Biederman" , Thomas Gleixner , Oleg Nesterov , 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: Wed, 26 Apr 2017 11:34:25 -0700 Message-Id: <20170426183425.32158-4-thgarnie@google.com> X-Mailer: git-send-email 2.13.0.rc0.306.g87b477812d-goog In-Reply-To: <20170426183425.32158-1-thgarnie@google.com> References: <20170426183425.32158-1-thgarnie@google.com> Subject: [kernel-hardening] [PATCH v8 4/4] arm64/syscalls: Optimize address limit check X-Virus-Scanned: ClamAV using ClamSMTP Disable the generic address limit check in favor of an architecture specific optimized implementation. 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-20170426 --- 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 3dcd7ec69bca..fe9466d3bf94 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -25,6 +25,7 @@ config ARM64 select ARCH_WANT_COMPAT_IPC_PARSE_VERSION select ARCH_WANT_FRAME_POINTERS select ARCH_HAS_UBSAN_SANITIZE_ALL + select ADDR_LIMIT_CHECK 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..c895c4402d32 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 addr_limit_check_failed + +/* * This is how we return from a fork. */ ENTRY(ret_from_fork)