From patchwork Thu Mar 9 01:24:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Garnier X-Patchwork-Id: 9612179 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 8F48960414 for ; Thu, 9 Mar 2017 01:25:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6E2BD2860E for ; Thu, 9 Mar 2017 01:25:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5FAE22864B; Thu, 9 Mar 2017 01:25:52 +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 8C2A22860E for ; Thu, 9 Mar 2017 01:25:51 +0000 (UTC) Received: (qmail 16265 invoked by uid 550); 9 Mar 2017 01: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 16068 invoked from network); 9 Mar 2017 01: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=Xuy4/HNv6jSdVQv1ujJ0SsQzfbSJd1MPCSZJT5tHJZ8=; b=FWfCeTl9KwCsJ5M8GC5FmnawTsdMOJneKl/e1X/yjfitA1RXQ++DiFUPpAkgzRjveS j0+fitchuVpDv6iqbdWmIo4EhTzqsVIW5mLYavwEn2LyKGItO9T1iIi0HffBOovEuKUc kYoUNks8vihZZzWPqR/NfiMEScs2JlqzVuFBzjKKoSAEqV4ZjgF9ba9TRzS+H3MqR7+e pG4KhJdBCMfo9SFnB/Kd8e49fz58DgV7+qNjT5dqO3Igc/5vkgZXVRWt2n06Uwbwk3YI D1Fs+xbqKOX5Fd4zjuQhJFXFzUQwCucuRxnMQdRUdUlrHCRKAWaovvizs15Vyv+g+3ox 94WQ== 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=Xuy4/HNv6jSdVQv1ujJ0SsQzfbSJd1MPCSZJT5tHJZ8=; b=mRgtnYD7XLhz7UgwFnfO+ewqbDzgMesoAko/7IQSF43rS0FNgpxRNCJuTixwY3Tx12 GKcK+HFEU1fugfVX9OMNNvW+G/WdLWWfT7nuRXyHcK/Yi6KL2TeiVG2zz3oJdb5V2whe Z6XttrbpBvDk+Zqx47wz6mELR2j713QOYsrO1KDwp3ysmgsHCSGAsL8FsHCATMRxIL6g g81qEiIigfWvIhxMtSs9vqDAp24jnggoMjq4hqb4P/CDGXT7kTltQutsOMPDg1nSmzl8 WOlibbQIQ1wVFtQzUwIeOHx2tqsZeMOtT0z53+PBMPeJdPVXrjglAdtEVufjzUect9Ev lROw== X-Gm-Message-State: AMke39l/TF8hAXQGHglTZ1k38QkhnwU66qwLH10mElGhEDocPFg/3vSMRBUHGOFL2ZYY7fPq X-Received: by 10.99.51.76 with SMTP id z73mr10679647pgz.137.1489022725960; Wed, 08 Mar 2017 17:25:25 -0800 (PST) From: Thomas Garnier To: David Howells , Dave Hansen , Arnd Bergmann , Al Viro , =?UTF-8?q?Ren=C3=A9=20Nyffenegger?= , Thomas Garnier , Andrew Morton , Kees Cook , "Paul E . McKenney" , "David S . Miller" , Andy Lutomirski , Ard Biesheuvel , Nicolas Pitre , Petr Mladek , Sebastian Andrzej Siewior , Sergey Senozhatsky , Helge Deller , Rik van Riel , Ingo Molnar , Oleg Nesterov , John Stultz , Thomas Gleixner , Pavel Tikhomirov , Frederic Weisbecker , Stephen Smalley , Stanislav Kinsburskiy , Ingo Molnar , "H . Peter Anvin" , Paolo Bonzini , Borislav Petkov , Josh Poimboeuf , Brian Gerst , Jan Beulich , Christian Borntraeger , "Luis R . Rodriguez" , He Chen , Russell King , Will Deacon , Catalin Marinas , Mark Rutland , James Morse , Pratyush Anand , Vladimir Murzin , Chris Metcalf , Andre Przywara Cc: linux-api@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org, linux-arm-kernel@lists.infradead.org, kernel-hardening@lists.openwall.com Date: Wed, 8 Mar 2017 17:24:55 -0800 Message-Id: <20170309012456.5631-3-thgarnie@google.com> X-Mailer: git-send-email 2.12.0.246.ga2ecc84866-goog In-Reply-To: <20170309012456.5631-1-thgarnie@google.com> References: <20170309012456.5631-1-thgarnie@google.com> Subject: [kernel-hardening] [PATCH v2 3/4] arm/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 arm. --- Based on next-20170308 --- arch/arm/Kconfig | 1 + arch/arm/kernel/entry-common.S | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index 0d4e71b42c77..704fd8f197fa 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -12,6 +12,7 @@ config ARM select ARCH_HAVE_CUSTOM_GPIO_H select ARCH_HAS_GCOV_PROFILE_ALL select ARCH_MIGHT_HAVE_PC_PARPORT + select ARCH_NO_SYSCALL_VERIFY_PRE_USERMODE_STATE select ARCH_OPTIONAL_KERNEL_RWX if ARCH_HAS_STRICT_KERNEL_RWX select ARCH_OPTIONAL_KERNEL_RWX_DEFAULT if CPU_V7 select ARCH_SUPPORTS_ATOMIC_RMW diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S index eb5cd77bf1d8..a2cdf3d7bcff 100644 --- a/arch/arm/kernel/entry-common.S +++ b/arch/arm/kernel/entry-common.S @@ -12,6 +12,7 @@ #include #include #include +#include #ifdef CONFIG_AEABI #include #endif @@ -27,6 +28,23 @@ #include "entry-header.S" +#ifdef CONFIG_BUG_ON_DATA_CORRUPTION +.macro VERIFY_PRE_USERMODE_STATE +#if !(IS_ENABLED(CONFIG_TRACE_IRQFLAGS) || IS_ENABLED(CONFIG_CONTEXT_TRACKING)) + stmdb sp!, {r0} + bl verify_pre_usermode_state + ldmia sp!, {r0} +#else + bl verify_pre_usermode_state +#endif +.endm +#else +/* Similar to set_fs(USER_DS) in verify_pre_usermode_state without a warning. */ +.macro VERIFY_PRE_USERMODE_STATE + mov r1, $TASK_SIZE + str r1, [tsk, #TI_ADDR_LIMIT] +.endm +#endif .align 5 #if !(IS_ENABLED(CONFIG_TRACE_IRQFLAGS) || IS_ENABLED(CONFIG_CONTEXT_TRACKING)) @@ -39,6 +57,7 @@ ret_fast_syscall: UNWIND(.fnstart ) UNWIND(.cantunwind ) + VERIFY_PRE_USERMODE_STATE disable_irq_notrace @ disable interrupts ldr r1, [tsk, #TI_FLAGS] @ re-check for syscall tracing tst r1, #_TIF_SYSCALL_WORK | _TIF_WORK_MASK @@ -65,6 +84,7 @@ ret_fast_syscall: UNWIND(.fnstart ) UNWIND(.cantunwind ) str r0, [sp, #S_R0 + S_OFF]! @ save returned r0 + VERIFY_PRE_USERMODE_STATE disable_irq_notrace @ disable interrupts ldr r1, [tsk, #TI_FLAGS] @ re-check for syscall tracing tst r1, #_TIF_SYSCALL_WORK | _TIF_WORK_MASK @@ -263,6 +283,7 @@ __sys_trace: __sys_trace_return: str r0, [sp, #S_R0 + S_OFF]! @ save returned r0 + VERIFY_PRE_USERMODE_STATE mov r0, sp bl syscall_trace_exit b ret_slow_syscall