From patchwork Wed Apr 26 18:34:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Garnier X-Patchwork-Id: 9701829 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 61C2A6032C for ; Wed, 26 Apr 2017 18:35:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5697128399 for ; Wed, 26 Apr 2017 18:35:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4AC90285E7; Wed, 26 Apr 2017 18:35:37 +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=-1.9 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BDF9E28399 for ; Wed, 26 Apr 2017 18:35:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=Psi2IO6wy8cROKTwJPZbqmQLMX89tWtKfvsnOCGOLIs=; b=BYyTmxvoUlpLEYsac36ylFv/Bj jvkLqm0me+WtiFv98VeDJEKRHJGYPfQRW5+VHxzJ0JD2zq1TGMyQw5JMA9nslYh+44PlVJgGyHBSA Do/WvPrlPp9J8VQ+tVC4Tf4SGoktF8/tRDl4HsFTWBjU/gxy3LOlUIGtQY1KmJyy74sPysicARRec da8YObdNb4ZdRHsJb3UZ/rEugaZYtB2G9bGEP5unrNVQpulxLtgSw/qUYwE05yHCFWqRHQgTHUotJ wCN9mQbGHy0Au6OM0S9HlGAqcxJ5pDXEtozIxVuKqvVHRgdSf/0Mb5gxKbQa4FDDFOlAsEX5SKFRE s8vq0mTg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1d3Rmo-0005cI-Lh; Wed, 26 Apr 2017 18:35:34 +0000 Received: from mail-pg0-x232.google.com ([2607:f8b0:400e:c05::232]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1d3RmU-0003j0-Gq for linux-arm-kernel@lists.infradead.org; Wed, 26 Apr 2017 18:35:16 +0000 Received: by mail-pg0-x232.google.com with SMTP id 63so4118795pgh.0 for ; Wed, 26 Apr 2017 11:34:54 -0700 (PDT) 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=AEsiL4efND+x0zrxnH0YjlVdWPifFwuaV0q5B2wXkpw=; b=Ga+d6zCt8g+wU9nQ4XbMNHrJcks0Zy9m2wb9GMWYP+ftMfriBFZuq62XMDeb4KJh2Y OcVU3BCelRev3aM50LPfSFkyO1U01UkEkIL91k/V+dcpdlbOmKcXcoJ3AvjaCkqJvyS7 KdtVr7BoGashORWO+jbRHRMUiKv9W01Z4U2z3ugJ5Y3i1aKaz7HNWjSVjPhqDCyNiS+m qySTekagKTO7CLNKAan9dlsfoWsPzj2cQv4e78kfoGAKSE8UO/A+5+nacpiACZqdnGgh FKwkNOkwGzS1luUg/syjVkagQYYEcmVeGQ+3LW9k+SwHQ8+lcR8Xa//lgaSd2Lp5ubsu ciHw== 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=AEsiL4efND+x0zrxnH0YjlVdWPifFwuaV0q5B2wXkpw=; b=P6WYu1bQ32TbwrXGfbEul/M5XGFjs7J4Q/9L42KhUu2Qqn3QTh9P0q0YYpGonCEqXW tUjH0wyZw3iq0opWO/BOkVk8NS5wyR+XpsCO80aQxoAcvBpb3MEdLwa01jrq7wvpL0Zq KwZSkHErpG5xpdiXVPqkf9T9BrKqDAKdFoHjmIxi5QJEVqgKY0xRfPvTJhOKhYOlh78b FQs4O6SuV9nsna7Ox+/fms1xD9JSYgttEEUhwbNteteHqJJxL1K3M+Bl3UIdUer4JfC6 rg7/PqgL+yA8xXvepyQNZRB2zMl2SOPCdFoFxoF+bych54vlBGRqUe0zGGskwPCXqNmL 6+qw== X-Gm-Message-State: AN3rC/5TX9y7EL1ggYRpBD4xSRT6Ci1M1IZnk3oCaBNKm11kbPwSqFAp 6abwhVmfF+e9eh2b X-Received: by 10.99.163.67 with SMTP id v3mr1286964pgn.206.1493231693121; Wed, 26 Apr 2017 11:34:53 -0700 (PDT) Received: from skynet.sea.corp.google.com ([100.100.206.164]) by smtp.gmail.com with ESMTPSA id g89sm60083pfk.25.2017.04.26.11.34.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 26 Apr 2017 11:34:52 -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 Subject: [PATCH v8 3/4] arm/syscalls: Optimize address limit check Date: Wed, 26 Apr 2017 11:34:24 -0700 Message-Id: <20170426183425.32158-3-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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170426_113514_690626_16EC091E X-CRM114-Status: GOOD ( 13.51 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-s390@vger.kernel.org, kernel-hardening@lists.openwall.com, linux-api@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org 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 path as well as the irq user-mode return function. If the address limit was changed, a generic handler is called to stop the kernel on an explicit check. Signed-off-by: Thomas Garnier --- Based on next-20170426 --- arch/arm/Kconfig | 1 + arch/arm/kernel/entry-common.S | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index 4c1a35f15838..f17f30084a4e 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -12,6 +12,7 @@ config ARM select ARCH_HAVE_CUSTOM_GPIO_H select ARCH_HAS_GCOV_PROFILE_ALL select ARCH_MIGHT_HAVE_PC_PARPORT + select ADDR_LIMIT_CHECK select ARCH_OPTIONAL_KERNEL_RWX if ARCH_HAS_STRICT_KERNEL_RWX select ARCH_OPTIONAL_KERNEL_RWX_DEFAULT if CPU_V7 select ARCH_SUPPORTS_ATOMIC_RMW diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S index eb5cd77bf1d8..c83927498f40 100644 --- a/arch/arm/kernel/entry-common.S +++ b/arch/arm/kernel/entry-common.S @@ -12,6 +12,7 @@ #include #include #include +#include #ifdef CONFIG_AEABI #include #endif @@ -27,7 +28,6 @@ #include "entry-header.S" - .align 5 #if !(IS_ENABLED(CONFIG_TRACE_IRQFLAGS) || IS_ENABLED(CONFIG_CONTEXT_TRACKING)) /* @@ -40,9 +40,12 @@ ret_fast_syscall: UNWIND(.fnstart ) UNWIND(.cantunwind ) disable_irq_notrace @ disable interrupts + ldr r2, [tsk, #TI_ADDR_LIMIT] ldr r1, [tsk, #TI_FLAGS] @ re-check for syscall tracing tst r1, #_TIF_SYSCALL_WORK | _TIF_WORK_MASK bne fast_work_pending + cmp r2, #TASK_SIZE + blne addr_limit_check_failed /* perform architecture specific actions before user return */ arch_ret_to_user r1, lr @@ -66,6 +69,7 @@ ret_fast_syscall: UNWIND(.cantunwind ) str r0, [sp, #S_R0 + S_OFF]! @ save returned r0 disable_irq_notrace @ disable interrupts + ldr r2, [tsk, #TI_ADDR_LIMIT] ldr r1, [tsk, #TI_FLAGS] @ re-check for syscall tracing tst r1, #_TIF_SYSCALL_WORK | _TIF_WORK_MASK beq no_work_pending @@ -82,6 +86,7 @@ slow_work_pending: mov r2, why @ 'syscall' bl do_work_pending cmp r0, #0 + ldreq r2, [tsk, #TI_ADDR_LIMIT] beq no_work_pending movlt scno, #(__NR_restart_syscall - __NR_SYSCALL_BASE) ldmia sp, {r0 - r6} @ have to reload r0 - r6 @@ -99,9 +104,12 @@ ret_slow_syscall: disable_irq_notrace @ disable interrupts ENTRY(ret_to_user_from_irq) ldr r1, [tsk, #TI_FLAGS] + ldr r2, [tsk, #TI_ADDR_LIMIT] tst r1, #_TIF_WORK_MASK bne slow_work_pending no_work_pending: + cmp r2, #TASK_SIZE + blne addr_limit_check_failed asm_trace_hardirqs_on save = 0 /* perform architecture specific actions before user return */