From patchwork Thu Mar 9 01:24:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Garnier X-Patchwork-Id: 9612181 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 5508960414 for ; Thu, 9 Mar 2017 01:25:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 351782860E for ; Thu, 9 Mar 2017 01:25:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2954228646; Thu, 9 Mar 2017 01:25:57 +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 5AF782860E for ; Thu, 9 Mar 2017 01:25:56 +0000 (UTC) Received: (qmail 16332 invoked by uid 550); 9 Mar 2017 01:25:41 -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 16216 invoked from network); 9 Mar 2017 01:25:39 -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=LbQg5LfFxURMxaCinWeDtVWeh/iK0NraDJ627L9IHZs=; b=qrhJR+Cyh2PcuiV//ty+EsXvlAqhCzFKR0voNDEjoBN5tikoIDfxVjZ8PYHiQRj8Ch nrxrlwht1+aitkGgcVoO7WmJTMcOtpvYf4OhDIUVjAyGGdHUblEUtTLqVvnJmgro1rTA AtEonm3Nv7nuO9Dxah6X3DXfIebEQw3vE1aWo3ug/+fdKXylj125eo1eH4W3AVnzZdqm jhTUSXhPjTnY1HFsHtjZlkOVKVzNfBBojFinM/Xwt6x1V9j5uOoVRtcfd4YBcdoXVKzu H5Nw5TRvnlXtkwrAPeaDPZcaxOzUl62EVtNqLHZtuHWn9fMHtqgg2aY7i/Vfc1X5D8Xc TBPQ== 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=LbQg5LfFxURMxaCinWeDtVWeh/iK0NraDJ627L9IHZs=; b=Ybqaonp4YIDEOoaeazhQmwc0NBUGqdqH6R/BwpUZF3wu5Ki+4xy2zZpNOw1JitN9PM 0WpNOXaNSb0tzKOtdBh2k8GE7FqbdjDsJKOMBnQHQ6A4bltqik55DsphbMrEfGqDAIaE ErVQbr2gyGTZFGRmsbDrQSidE13XWVBeu00mRKBvG2IWL+o7eF37GVA4nzo4ZeFGn7S3 ++YpZSLEYmogVwlMI7rJ6ItqqVtIWn/k1HngxQHfaHEJhflCzs9AgFqtxk3y1cS615q0 mN/V7jSsZ0XA28WKA/jQUq9fuEPoa9AlBqzDG4i4fdptl8tGvLwhV3dEgHdxIpLX7zSS Raow== X-Gm-Message-State: AMke39mkWfNPc7Uj0apZcGKZj9BY7uFdAFZmFj27rAHDGwzTGOeUd9zBDF2YC+4sttQlj9/9 X-Received: by 10.84.162.204 with SMTP id o12mr13014713plg.132.1489022727210; Wed, 08 Mar 2017 17:25:27 -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:56 -0800 Message-Id: <20170309012456.5631-4-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 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-20170308 --- 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 896eba61e5ed..da54774838d8 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..eca392ae63e9 100644 --- a/arch/arm64/kernel/entry.S +++ b/arch/arm64/kernel/entry.S @@ -737,6 +737,19 @@ ENTRY(cpu_switch_to) ret ENDPROC(cpu_switch_to) +#ifdef CONFIG_BUG_ON_DATA_CORRUPTION +.macro VERIFY_PRE_USERMODE_STATE + bl verify_pre_usermode_state +.endm +#else +/* Similar to set_fs(USER_DS) in verify_pre_usermode_state without a warning. */ +.macro VERIFY_PRE_USERMODE_STATE + mov x1, #TASK_SIZE_64 + str x1, [tsk, #TSK_TI_ADDR_LIMIT] +.endm +#endif + + /* * This is the fast syscall return path. We do as little as possible here, * and this includes saving x0 back into the kernel stack. @@ -744,6 +757,7 @@ ENDPROC(cpu_switch_to) ret_fast_syscall: disable_irq // disable interrupts str x0, [sp, #S_X0] // returned x0 + VERIFY_PRE_USERMODE_STATE 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 +785,7 @@ work_pending: */ ret_to_user: disable_irq // disable interrupts + VERIFY_PRE_USERMODE_STATE ldr x1, [tsk, #TSK_TI_FLAGS] and x2, x1, #_TIF_WORK_MASK cbnz x2, work_pending