From patchwork Thu Mar 23 17:25:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Garnier X-Patchwork-Id: 9641691 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 7EB6F602CA for ; Thu, 23 Mar 2017 17:26:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 69A8625D99 for ; Thu, 23 Mar 2017 17:26:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5BA0E2841E; Thu, 23 Mar 2017 17:26:25 +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 0B90F25D99 for ; Thu, 23 Mar 2017 17:26:25 +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=Vr0PHklovT5+nl7CpWePxaYFRzBJobafSfI8hDjPAt0=; b=QEi07L5B0NyoDU4UQvOC1XFA49 lzdSfySGdVd/LfANDmj394pMyyj+jYDxHtfWuiWutfbm2XL4iYBhNS2+y5w/02aEfLnyE8LZB0hod Kbrngkvw4/24uuYM9WE9zOobDe515hDbnpPs+FOMByBMZ1DXsSaq4GMiT/PXEbQSfZM9IwycEEbbr vWZ1D5wf/PNrEwTez7fj39198Vx0TKj4OK9UsR48ybS/tDqaI7cO8cne0YVpJ+pY3HiXfvjM7tIGi iOEoYP627sJOMImu1EvR2yNiJ56WKiTkr8BGtxiCx+ZLMpmJ1/JZ18XTa/x9XyuHktgvIdFI250jS UOHilpuQ==; 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 1cr6VE-0001C2-Iy; Thu, 23 Mar 2017 17:26:24 +0000 Received: from mail-pg0-x234.google.com ([2607:f8b0:400e:c05::234]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cr6Ub-0000o6-94 for linux-arm-kernel@lists.infradead.org; Thu, 23 Mar 2017 17:25:46 +0000 Received: by mail-pg0-x234.google.com with SMTP id g2so126342127pge.3 for ; Thu, 23 Mar 2017 10:25:26 -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=KoQKR+Datuy55aOz5DdX9WIBdGixCVv5gQMGXYPuvYc=; b=IsXnWq1qrjj2acyhF9pfD4NhvSQn3IOkQi0AQ90C6Cof0nb9McsPLDK/ezPByoNb4h PG1+5IwgT93qlHC02KHVAqSbzojSy1qxy3VK4h9AOjCUxAWxRfMXk9+L1gKCrkJr/7Zj sRKWjiKQvaGv73Ak+fVpCR39pK7iTQLGXIFz4wlq6do1msoAhcSCrDCK2VECDrBuK6OZ 0EU5HPylaS/j15noH45mk9CDzkFIJNshsXQgi0UQqQph1+Cy9LcY3Pk+/gJ/07ejD1uu F/BZ0bgbXfS2dPuJS/uC9/ZHi/uUa5bCOHOVIkmA1pRT0VGWhueSPkbbVULOQxFBC7MI 0EOA== 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=KoQKR+Datuy55aOz5DdX9WIBdGixCVv5gQMGXYPuvYc=; b=lAKNQ7GxTzsYzNZUkoNILBiCtNrxYXwurACX/8Gg7n/QnqwYXIes3crKtnIYG/xAv7 oyrgm8xWB7lr8a4nu6LmttSTi/IAdGqCZVMDaOHmMgFrtUu0Zn+kYvvRgTMQgh+W10d/ k2+rS9BsRW8Ed9aS9WuvJF80246X8N4ceEEoQXIXv+NYcrhmYSOJjIChzsFoLymrVuQ8 dWopbH7nO0YbivNxYYrVtWWGQRMXHypR1wpF0xQawko/w1rDdtgwzDXunO4OaEi0Izzc ycdp10vZ0HPrTe8Nx0kfMWre7Tlq4sZhH1zHNqsyk3rVNYKpKsRsZIXqH2Px4ado6Esl xckg== X-Gm-Message-State: AFeK/H1ZaDtPfKrG7fk3L0I3RHsg4fyzJF5xNfwCA+dQTaCHpWTTF4LGjXlAIjNYUdU8Pjfc X-Received: by 10.98.1.10 with SMTP id 10mr4281097pfb.117.1490289925982; Thu, 23 Mar 2017 10:25:25 -0700 (PDT) Received: from skynet.sea.corp.google.com ([100.100.206.164]) by smtp.gmail.com with ESMTPSA id d1sm11500887pfa.5.2017.03.23.10.25.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 23 Mar 2017 10:25:25 -0700 (PDT) From: Thomas Garnier To: Martin Schwidefsky , Heiko Carstens , David Howells , Arnd Bergmann , Dave Hansen , Al Viro , Thomas Gleixner , =?UTF-8?q?Ren=C3=A9=20Nyffenegger?= , Thomas Garnier , Andrew Morton , "Paul E . McKenney" , Ingo Molnar , Oleg Nesterov , Pavel Tikhomirov , Stephen Smalley , 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 v5 4/4] arm64/syscalls: Specific usage of verify_pre_usermode_state Date: Thu, 23 Mar 2017 10:25:15 -0700 Message-Id: <20170323172515.27950-4-thgarnie@google.com> X-Mailer: git-send-email 2.12.1.500.gab5fba24ee-goog In-Reply-To: <20170323172515.27950-1-thgarnie@google.com> References: <20170323172515.27950-1-thgarnie@google.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170323_102545_363412_D6B1D618 X-CRM114-Status: GOOD ( 12.22 ) 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 Implement specific usage of verify_pre_usermode_state for user-mode returns for arm64. Signed-off-by: Thomas Garnier --- Based on next-20170322 --- arch/arm64/Kconfig | 1 + arch/arm64/kernel/entry.S | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index f2b0b528037d..0e86d87259f4 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..6d598e7051c3 100644 --- a/arch/arm64/kernel/entry.S +++ b/arch/arm64/kernel/entry.S @@ -744,6 +744,10 @@ 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 + mov x1, #TASK_SIZE_64 + cmp x2, x1 + b.ne 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 +775,11 @@ work_pending: */ ret_to_user: disable_irq // disable interrupts + ldr x2, [tsk, #TSK_TI_ADDR_LIMIT] // check addr limit change + mov x1, #TASK_SIZE_64 + cmp x2, x1 + b.ne addr_limit_fail + ldr x1, [tsk, #TSK_TI_FLAGS] and x2, x1, #_TIF_WORK_MASK cbnz x2, work_pending @@ -779,6 +788,12 @@ finish_ret_to_user: kernel_exit 0 ENDPROC(ret_to_user) +addr_limit_fail: + stp x0, lr, [sp,#-16]! + bl asm_verify_pre_usermode_state + ldp x0, lr, [sp],#16 + ret lr + /* * This is how we return from a fork. */