From patchwork Fri Apr 28 15:32:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Garnier X-Patchwork-Id: 9704995 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 C6F9E602BE for ; Fri, 28 Apr 2017 15:33:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B7EE028677 for ; Fri, 28 Apr 2017 15:33:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AAEFC28687; Fri, 28 Apr 2017 15:33:07 +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=ham 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 3676428677 for ; Fri, 28 Apr 2017 15:33:07 +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=1nGW1w+KcgprCCBqZr/3e11FP1aWVxuCOVxg99JWEW0=; b=BLVT3MyPGCr/jQuTKA3X7ZXymK 9DeoNRHsEIaCx6/XolXnv9yTqeKbM5+qz5GWIGIgC+J3Bxyo3fEmtEyvC748Nv7qterN4R2vt1Exi hvg1L5R2tZL24c8sh66ygPMS+WDei1KhcymtHyQN9ex4IKvmVPTQR+1cLhfuODqJojh6hcvjRLlAC sE1aSpTCTt00knjgA4biefwUSjzRipw3MNn1+tmPdNj82gdCHFibyGl58aNCZ4uBxqwndikYlWWt+ hhrhJVtpk65gr/3tgO2gM84mGnfx6zGsnXPaKrC5Yrivq13oj7TgDZsk76GIO2RAp3mA0d2vSFlT2 vAcdXn3g==; 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 1d47tD-0002Wv-HD; Fri, 28 Apr 2017 15:32:59 +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 1d47sx-0002GF-HL for linux-arm-kernel@lists.infradead.org; Fri, 28 Apr 2017 15:32:45 +0000 Received: by mail-pg0-x232.google.com with SMTP id y4so11287176pge.0 for ; Fri, 28 Apr 2017 08:32:22 -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=ilWHgkyJCcyrxp7g/rhzKaDhZS/+isuZEul6nd94cY8=; b=Q8JAKKjU86Tg4ZWgqoU1w74Fg1JUW3ozQfT8L2Wpaj6ZqIWBxX2g21ex7IhJ3RN0zg r6sp40O7MAtVKT/O2ubHL0iE1WDaNGsPALNXK2weEohx7ecV72TlosC0+FoBFKtDPcwl qLsyjgHAyvOkHQl3g7XIHrnnJIcfKCcz4V4rXxOe7AsH1Av+w4ouHXL4BPPymRdIk26X zgdiZPUCcZl1f5et+DDUbAWn4KZ6WHDRSQSZ1JEMb8N+K1mci0MVeSrE17Crhd3NnztQ z+PwYBlHS7nWMfhGP8ampvHd6LXUVKCQDmqSDKzoC6mMcWZjUN1cd8rel5MSicHMogbn sh9g== 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=ilWHgkyJCcyrxp7g/rhzKaDhZS/+isuZEul6nd94cY8=; b=a/DujFWF7jGXDzRLvkQNQIGjrT9K65v2GF0JKs6QCVq22R//dJmxYY6xj/x6oqk5VV JMdgRAWYtN/S6/B7h3oWRJPvxWslIz3FPuyz4rf9vKh7deAJTtasFN4ECZW0e7Svfsyl jt92QK0YSmcSmddWW12hgR3EtifX68li7VEhIZf3xl4MkG9UiraGsgd8XtnxpmpgPsTQ Nor2IyqAgHOAANspahb2sFUkPmwQUtzJCMU4hc+JaZtiFY+0KGkwkqek1febSdiKm+q4 ny/3XzfyrWIGQnpIOqWeNGAauWekoF2mK7ZfyISajJo8zJfGjxdtq+JTFYfwe/kGNdDd ZxhQ== X-Gm-Message-State: AN3rC/7Z1d8SfDyM0pXpoeodnO4eD/IpHxfvt2uaoJlQYeR3A62mQnhc KQiaoCLTslUJjMjN X-Received: by 10.99.96.1 with SMTP id u1mr12899272pgb.159.1493393542021; Fri, 28 Apr 2017 08:32:22 -0700 (PDT) Received: from skynet.sea.corp.google.com ([100.100.206.164]) by smtp.gmail.com with ESMTPSA id p6sm12583434pgn.9.2017.04.28.08.32.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 28 Apr 2017 08:32:21 -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 Subject: [PATCH v9 3/4] arm/syscalls: Optimize address limit check Date: Fri, 28 Apr 2017 08:32:12 -0700 Message-Id: <20170428153213.137279-3-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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170428_083243_605106_9F7B9A56 X-CRM114-Status: GOOD ( 14.14 ) 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..c7322f2bb818 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -1,6 +1,7 @@ config ARM bool default y + select ADDR_LIMIT_CHECK select ARCH_CLOCKSOURCE_DATA select ARCH_HAS_DEBUG_VIRTUAL select ARCH_HAS_DEVMEM_IS_ALLOWED 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 */