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: 9641683 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 B2064602CA for ; Thu, 23 Mar 2017 17:25:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9ECA825D99 for ; Thu, 23 Mar 2017 17:25:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 92CAC2841E; Thu, 23 Mar 2017 17:25:55 +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=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.wl.linuxfoundation.org (Postfix) with SMTP id A4B2C25D99 for ; Thu, 23 Mar 2017 17:25:54 +0000 (UTC) Received: (qmail 19611 invoked by uid 550); 23 Mar 2017 17:25:39 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Delivered-To: mailing list kernel-hardening@lists.openwall.com Received: (qmail 19466 invoked from network); 23 Mar 2017 17:25:37 -0000 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=fIkOQHQbCOLVQLHA/+IK6oa0MzxCw27QzTUvjWzHkPc/JA4ORFEnskBLusxxBd+Mp3 T3TRknqJRVLtth0QhAHA0rtpGssT5ZV+l/PSCyCmjofnTl+aibnMwRc35VAjxvg2DAxf oGmq5I6mohiAUSgdbnX7XWK/Y1e1vgUn6FwVcyxs2cpt9ZZIeypLauijlKeM2KITG5g5 L49fMZvojShTkPHN2T2VkcsFT6VL8BWaeUEHRV89/YpbykEhTP3c40w3WwYpWnq6fw9R P63P54s3B6GyBy+CWCe2SEIYwhaBD+tY1q8PWkTZ9BqlnJKk8CqAy+4BLtDrHLR3VFxI IiMw== X-Gm-Message-State: AFeK/H2DpaFT2Yi9qEtP0grKMmcTvJUVa58LK5jF8KcnzJ6uzCjLLpxpFtTm0ZIMZ+mNVon4 X-Received: by 10.98.1.10 with SMTP id 10mr4281097pfb.117.1490289925982; 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 Cc: linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, x86@kernel.org, linux-arm-kernel@lists.infradead.org, kernel-hardening@lists.openwall.com 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> Subject: [kernel-hardening] [PATCH v5 4/4] arm64/syscalls: Specific usage of verify_pre_usermode_state 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. */