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: 9701831 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 D192E6032C for ; Wed, 26 Apr 2017 18:35:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C622A285F0 for ; Wed, 26 Apr 2017 18:35:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BA28B285F2; Wed, 26 Apr 2017 18:35:46 +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 659B92846C for ; Wed, 26 Apr 2017 18:35:46 +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=Ga543RqG7NQC/fVDbmVjypMj9HL4/xEAhBQqSvjGAHQ=; b=UbYYVn7ARMAuRGy5wtDFeDmpPg tcozV3Lr6aSBRqdV2cEsxFDnb8y379/wabU2v1rv+jjqCQBTQ+wNDZ9BwASRNpdWMHiyuWqPc+iO4 bfXAgqBhWUOyAKxUfTJo82cHSATFGBWArBo0xO9sTWWVFi7Gp3jb+Xonaoy2g2x5dSlhKA7gESn2U MfS7aWno8cR61wbTflIb3/oERXnhbPKn8bfzGEvK4Qcj/L1gO8lomdjI9+w2DFI3LY/oc6TQzIs2v pQ9qrM9mGRGtfplWCPca/ObihW+ybHs9HGluAjV+gCC7vpw5TyH56VbLVjzhvXP2u68OQlmmM2WjN fA2UgL+w==; 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 1d3Rmz-0005rX-FU; Wed, 26 Apr 2017 18:35:45 +0000 Received: from mail-pf0-x231.google.com ([2607:f8b0:400e:c00::231]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1d3RmV-0003j4-LF for linux-arm-kernel@lists.infradead.org; Wed, 26 Apr 2017 18:35:17 +0000 Received: by mail-pf0-x231.google.com with SMTP id v14so3963132pfd.2 for ; Wed, 26 Apr 2017 11:34:55 -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=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=pJurUQADq4PfO3VCBQCcOSXkY6REUrC9VzwRLL3K3aDQf4hOef1w6G/gAjSb7CeMP5 jUSfFlDdfLRrpe65GLvh//1oaB1BVjNMrD6qm+cDigMlKXVRCnlITrTBOkgtE4HpN7uK zkiK7ZGhlTxWPnk0XBVBabwYMmYbZgMSYEAzZYEnMc5wx2nTRExwePL6ENKJYwIbfjxK +9uXlys/56MBY+hQ/gj9FKmPHC7lQ8tULKjAd5j4X4EjLZ3Nv0eRM3MbRiW/yK0HZPz6 FRNehwHPy94Ycyu2I8NqgkTWS8yu3ChJN27HTWEM6h2yJfC6mR/7q/1l+QBrHBtG7tTz GGoQ== X-Gm-Message-State: AN3rC/4q/rqqcHs4gV33tRu4LLbAerdyQpZhSEImcj0r9BeyipbiOt8a N6dE4eoZ/D4GP2+d X-Received: by 10.98.79.214 with SMTP id f83mr1292369pfj.201.1493231694427; Wed, 26 Apr 2017 11:34:54 -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.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 26 Apr 2017 11:34:53 -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 4/4] arm64/syscalls: Optimize address limit check 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170426_113515_799401_443FAB23 X-CRM114-Status: GOOD ( 13.61 ) 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. 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)