From patchwork Mon Apr 10 20:07:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Garnier X-Patchwork-Id: 9674213 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 7BDCB60231 for ; Mon, 10 Apr 2017 20:08:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6834C281AA for ; Mon, 10 Apr 2017 20:08:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5A7A628490; Mon, 10 Apr 2017 20:08:41 +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 E116B281AA for ; Mon, 10 Apr 2017 20:08:40 +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=AFrEqVNGNBTGzaRCNLKfn1iQAXOiReLAMccz90SFJws=; b=QITtcJ8EqkayzQmoojusqmdQeQ VRjKqeBiGv1t57pNK91YJu0QuF0lG2HmLkxxGsTIfdieU9ezQ83HzS/16XE+4+oV5fEosb9JHwMu0 3ivjkB72TJjq9J7AwrcBt3Wes8/3uNE6/S3eg5dYW08bMY6kAGdO6ols4iuWf8OQwgMonvq047/P1 xZJT66YyU9S0rGnmWgcyGmOfbNzgfB5swJhK+3dO5NVMHdVWB4C6ilKRzE/Bq/k+xigEUVEIMuaJG Ql8WcNULGDhDNFzhRJPDQQ96hzRMi9qQD4rH5Dto2JA1aRyO2WFKtmT9SfCWKOdRTdNG1+MlpcXWG rdG641Cw==; 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 1cxfc8-0001iF-1v; Mon, 10 Apr 2017 20:08:40 +0000 Received: from mail-pf0-x229.google.com ([2607:f8b0:400e:c00::229]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cxfc4-0001f4-NL for linux-arm-kernel@lists.infradead.org; Mon, 10 Apr 2017 20:08:38 +0000 Received: by mail-pf0-x229.google.com with SMTP id o126so38165641pfb.3 for ; Mon, 10 Apr 2017 13:08:15 -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=5vzqKcBl9fOUcxyQnq6TbIo7atT0k9ffY9PwFPzTTvw=; b=uzA7VeJ2/mpqw6rjWXEeYimTN/+MtzASE+6WwEYBsi40rXVhoZ23tYrqbs9rt2UwXf hrvROP8c/78Kbb+S2+GhJqJg2DcT0PorgjNiIjM3oUjo41nn9/YEqT8nF+3IkuFHzGfb VtMijHJ/vZJaxuiKjs4TnbeG0tj0FzRK5wDJlksFcjd0i6PSWBSll6gUR3oe5dHwpU7h y+UUiKJoWBYhCFNtdZxpdX23QKh+7++MKs9NSfLlpCCoags3aqtd8+pnp1dGcLRbTfFy rhvGFhCuS5/O3FM+D3is+eFZWbHb3HxkOIEgcDOQtb4o9+xJGYuduomqiLIq3If0SliU 3XrQ== 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=5vzqKcBl9fOUcxyQnq6TbIo7atT0k9ffY9PwFPzTTvw=; b=FPCIiEC1Hu9KcCB01/ib9z9e+VJb/bNmvIkywfXGMYmznm1fZS6zRQZiNexJWuCsoS YkTpMZ2yvfKuY5zYjKaite/P7KAcPodjoGD67zGBpfeTM8F3pUqdf+UHvgF7LB9gt4+k PlctZvw620Jb3brwECN8jQtU94KugxN68Zmc7TxEYt8h+o7XBpslh38DiFxGzEmT8nrr SGJdA9dClYmM7SJOZKvSChdvqi+bMV6ArgTN5YuUuWcTLbdmlkSKQu/AO6hz9946hBKl IMSTgdyU50Ztf6RrVAqeCmyxfzN3PslE7xXQrtUYssmRAZnOttvnGYckpfS+DzLoaTOR usPg== X-Gm-Message-State: AFeK/H1ZtD1uKawXw5Oty8XhceysGA3iD8xxIlfddhX4bbb3f7lVqP35QcqnrNQD34WhZJwt X-Received: by 10.99.109.67 with SMTP id i64mr57027825pgc.56.1491854894865; Mon, 10 Apr 2017 13:08:14 -0700 (PDT) Received: from skynet.sea.corp.google.com ([100.100.206.164]) by smtp.gmail.com with ESMTPSA id p68sm26205968pga.6.2017.04.10.13.08.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 10 Apr 2017 13:08:14 -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 Subject: [PATCH v7 4/4] arm64/syscalls: Architecture specific pre-usermode check Date: Mon, 10 Apr 2017 13:07:56 -0700 Message-Id: <20170410200756.15945-1-thgarnie@google.com> X-Mailer: git-send-email 2.12.2.715.g7642488e1d-goog In-Reply-To: <20170410171240.GE30647@e104818-lin.cambridge.arm.com> References: <20170410171240.GE30647@e104818-lin.cambridge.arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170410_130836_783494_F6599591 X-CRM114-Status: GOOD ( 14.31 ) 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 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 Fix comments from Catalin and add review-by in the message. --- 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 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..04c44c6f41b1 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 address_limit_check_failed + +/* * This is how we return from a fork. */ ENTRY(ret_from_fork)