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: 9704999 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 BDD6D602BE for ; Fri, 28 Apr 2017 15:33:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AD5CA28677 for ; Fri, 28 Apr 2017 15:33:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A053228687; Fri, 28 Apr 2017 15:33:23 +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 0AC5528677 for ; Fri, 28 Apr 2017 15:33:23 +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=hHs8tvGv8zuj+KecdMO0+/LhuVTBjR14W7AgG9qMPy4=; b=msi1FAFAcxoAFdxBStR4blh1By CdSLovmKqFuDAD4hhKD6pxCE5KANzOd195WfGo92vpXNSh0YDf5KDRPBwkv6T3kvFsXNjHq7TY00v eUVAbRUJy+s7+drNFsWjYZ+duw5R0GRvUdCx/DyeGsICxBCbILE10mSH8C9udTyjTA+JaSqqUZpVs Cy9alTlv4sbvHMPN80d6kvYP76OSapeZkKgIjjhy+bPsA3wnN5Bf37DF8QYqOU1w4SG3W7l5xEt+3 7f4xFLhRvT/wusmHPnODrhhokXzwHdmGnet9Jaz3K1bua8imzj1NX0AjxRf1DuZ1rR8n3aaV/Vevx RhgCyC2w==; 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 1d47tZ-0002zx-89; Fri, 28 Apr 2017 15:33:21 +0000 Received: from mail-pg0-x235.google.com ([2607:f8b0:400e:c05::235]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1d47sy-0002GR-J6 for linux-arm-kernel@lists.infradead.org; Fri, 28 Apr 2017 15:32:46 +0000 Received: by mail-pg0-x235.google.com with SMTP id v1so16610644pgv.1 for ; Fri, 28 Apr 2017 08:32:23 -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=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=MrRwHi1pYLnUuus5ZSyWs5hyczMrLQLqUBQVRqxIsNbgY3CAaLZnKRSwRyH91v+qPt xA3HpQWMBHPuyZJLnFPcpsfx4SlWpakYQEW8ehp5AJ73/FkNqSARcWj0U8fawoqTC0Rk opcJT5KTD4nuVUa+mO9iHECJGtZ0p5Kgwi7NxD2WOUTUULNoTHcKIlIIIPJnOfN9jbGd idg7q6I/pW45ayBo3U0RpghdAqVzVx1cp8V8nzbyxp57O5pK8dXpQfruTpiTglHnVJhL BX5TJdM19kcLonNVS91VhtRv0HvaGNsRZiXrrt0KA+tj49YthEQqqHiUtdKoFCFi9p8l 8X8w== X-Gm-Message-State: AN3rC/4P+BiLX8P/XPYtld3HqsWtW01O38ZOxefX0gqlmaUgOXJ3zOpb bsp4MFtGhJNfr1mO X-Received: by 10.99.44.14 with SMTP id s14mr12817381pgs.15.1493393543183; Fri, 28 Apr 2017 08:32:23 -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.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 28 Apr 2017 08:32:22 -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 4/4] arm64/syscalls: Optimize address limit check 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170428_083244_716578_965DD7A6 X-CRM114-Status: GOOD ( 13.81 ) 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..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)