From patchwork Fri Apr 28 15:32:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Garnier X-Patchwork-Id: 9704987 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 BECB8602BE for ; Fri, 28 Apr 2017 15:32:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B0A3C28458 for ; Fri, 28 Apr 2017 15:32:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A434328682; Fri, 28 Apr 2017 15:32:49 +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 AF3F428677 for ; Fri, 28 Apr 2017 15:32:48 +0000 (UTC) Received: (qmail 19853 invoked by uid 550); 28 Apr 2017 15:32:36 -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 19821 invoked from network); 28 Apr 2017 15:32: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=68rUV1Obe1nXeeAR3Sq6t1+zNIwvCCqApG8V2fhDN/c=; b=nl9/DSkjDQK56qMMVX8+PMVMdlMJqMgmv4cwKk74tSZ1kWbAi66rY6B+1PrUdDYS9B 9+/gyOWT7cHJ2LPqlg5TgjcMooMoMK8odsQg/Rk4TF6iGQvcynxuDGVJrPxogbRal/o1 A+ZPwg0+kNdeuRHxaDEs8JIKiLLZNP/n3IwSavfeYoxrGj7tXQ99SMmqScISgwKAOosH vaVRWN5Fa9NxEktfssQyprKu9k/xCnEzV2SCJybIexlAZb362zZEIC03WOhOToImEYHx hWHn5XB74R3NZWfZLJ5lByr7Vc1FfoUPlOC0Cwr+iVVvPiB7zRA8xrWHq7T2LckiEAHp yVIw== 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=68rUV1Obe1nXeeAR3Sq6t1+zNIwvCCqApG8V2fhDN/c=; b=TGm3ibl61y7seYGNrmTxJyWvaLOryogTLj3ypdSb/fPxZxSanlgmeq6gstrUS7O2IJ dqcX4arc/M59HVoqqyTy+7EVWZYt+NvP9e+1OqMFD5c2+tQ5K7rr4gWrUfqnNWXOm/ZG aFVdhoC8MCIktlquikrfPwilm1YyR98Zc+2KQUK2/TSXUerFZOBxzBgoTccApMxGz7QG eH9GWwQDqru9+q3+k+RD6jGOEGnRy/SFlZXmQA4QKOKHLrLqJ1xXxbattIILwZTfC7eG 9H+zazreEwzYVN+k+tI+pekQ1pPhI26fSeZR/c8dchBNxMjI1qb6uOY+ufU/byyuey+X qJiQ== X-Gm-Message-State: AN3rC/66dZVjJY07Qpzmp5WXvAONqtHlBLlunQ+NWGD398UiRe2FT397 0gJSal2WJ+UsdJ6V X-Received: by 10.99.44.14 with SMTP id s14mr12817381pgs.15.1493393543183; Fri, 28 Apr 2017 08:32:23 -0700 (PDT) From: Thomas Garnier To: Martin Schwidefsky , Heiko Carstens , Dave Hansen , Arnd Bergmann , Thomas Gleixner , David Howells , Thomas Garnier , =?UTF-8?q?Ren=C3=A9=20Nyffenegger?= , Andrew Morton , "Paul E . McKenney" , Ingo Molnar , "Eric W . Biederman" , Oleg Nesterov , Pavel Tikhomirov , 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 , 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: Fri, 28 Apr 2017 08:32:13 -0700 Message-Id: <20170428153213.137279-4-thgarnie@google.com> X-Mailer: git-send-email 2.13.0.rc0.306.g87b477812d-goog In-Reply-To: <20170428153213.137279-1-thgarnie@google.com> References: <20170428153213.137279-1-thgarnie@google.com> Subject: [kernel-hardening] [PATCH v9 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..ae82b1f067da 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -6,6 +6,7 @@ config ARM64 select ACPI_REDUCED_HARDWARE_ONLY if ACPI select ACPI_MCFG if ACPI select ACPI_SPCR_TABLE if ACPI + select ADDR_LIMIT_CHECK select ARCH_CLOCKSOURCE_DATA select ARCH_HAS_DEBUG_VIRTUAL select ARCH_HAS_DEVMEM_IS_ALLOWED 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)