From patchwork Wed Mar 22 20:38:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Garnier X-Patchwork-Id: 9640025 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 5481C60327 for ; Wed, 22 Mar 2017 20:39:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 475B028461 for ; Wed, 22 Mar 2017 20:39:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3B6CC28485; Wed, 22 Mar 2017 20:39:16 +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 CC72E28461 for ; Wed, 22 Mar 2017 20:39:14 +0000 (UTC) Received: (qmail 30135 invoked by uid 550); 22 Mar 2017 20:39:01 -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 29970 invoked from network); 22 Mar 2017 20:39:00 -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=xN6EWu/AguiNYM9B8s95tlpmM54FcYxpsDmFjEM13YQ=; b=ecr51TW/bZa5ccf3VPX+TZ9YvSLd7GPkxI54utIDdNTcyXq6N5gJOKKpWtVN1R2zel Qlkm58H4xhfQ5gzC+ZOAXpwQznah1zijN96SU3K8nCLpJBKcMeKtpQE/AOM6ICRKld6i xrCFaVUX6mGoYB2FA/XW5JeG4mT26RBLg0wB5zYB59qL1fvbGdT9QpVFjHX3iot41pB/ rTTjsxaZEK/pj0dlnndxbZCNtEsdFJ544dIUhrS1KBEI0+9rJPlDUNWhIVsMkIuQIvMC 46CWkftwPJsGsMfX87epi4cBOCMAxEQl1ho03zM/kd6HrA3ze9YweYJGYdiTKt67u2D5 Hk5A== 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=xN6EWu/AguiNYM9B8s95tlpmM54FcYxpsDmFjEM13YQ=; b=BEpE3GbeVSfYL6gtRhDmByyxE7UUAsZMyqQLHa9vFN7sbJW4gOeh2sM55tiMMtney7 Ped6e7W2oAAB90/UP5YyPXtBIEHTF+v/2xdzkj9NXiyo/9ZZA1IX4MrjzFwmW05Hxg4D YRNFTOu/uW/LILNAX/MIy2fMzaGdtuCft6Gab5yKD226QtUM7rqffrhyK2UaJYOU6fYS LtBFgvbBn7Gf/iqryEZks8db/t99Ixsl4K1mnF76mlMa4Z4vvFbGd8lBCIYklgP+s02r BTuVHjJ96gm2ggnqh1bXJNnhH39me87gw8DJ6J+TJ2WmMtm0xZVeQsMfyXz6cWMl51GZ 4xhQ== X-Gm-Message-State: AFeK/H3cc15z3h42ztf/G5zlfTtAGXwOv1edwyrCTAO6GYJE8WEJwpbupfmPTu8F07jWXo/g X-Received: by 10.99.8.194 with SMTP id 185mr45549562pgi.37.1490215128404; Wed, 22 Mar 2017 13:38:48 -0700 (PDT) From: Thomas Garnier To: Martin Schwidefsky , Heiko Carstens , Dave Hansen , David Howells , Al Viro , Arnd Bergmann , Thomas Garnier , =?UTF-8?q?Ren=C3=A9=20Nyffenegger?= , Andrew Morton , "Paul E . McKenney" , Ingo Molnar , Thomas Gleixner , 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 , Vladimir Murzin , 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: Wed, 22 Mar 2017 13:38:34 -0700 Message-Id: <20170322203834.67556-4-thgarnie@google.com> X-Mailer: git-send-email 2.12.1.500.gab5fba24ee-goog In-Reply-To: <20170322203834.67556-1-thgarnie@google.com> References: <20170322203834.67556-1-thgarnie@google.com> Subject: [kernel-hardening] [PATCH v4 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. --- Based on next-20170322 --- arch/arm64/Kconfig | 1 + arch/arm64/kernel/entry.S | 25 +++++++++++++++++++++++++ 2 files changed, 26 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..685b43771ac9 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,22 @@ finish_ret_to_user: kernel_exit 0 ENDPROC(ret_to_user) +addr_limit_fail: +#ifdef CONFIG_BUG_ON_DATA_CORRUPTION + stp x0, lr, [sp,#-16]! + bl verify_pre_usermode_state + ldp x0, lr, [sp],#16 +#else + /* + * Similar to set_fs(USER_DS) in verify_pre_usermode_state without a + * warning. + */ + mov x2, #TASK_SIZE_64 + str x2, [tsk, #TSK_TI_ADDR_LIMIT] + ALTERNATIVE(nop, SET_PSTATE_UAO(0), ARM64_HAS_UAO, CONFIG_ARM64_UAO) +#endif + ret lr + /* * This is how we return from a fork. */