From patchwork Fri Feb 10 19:22:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Russell King (Oracle)" X-Patchwork-Id: 9567341 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 8EB92601C3 for ; Fri, 10 Feb 2017 19:23:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7F839285B7 for ; Fri, 10 Feb 2017 19:23:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 74365285BC; Fri, 10 Feb 2017 19:23:17 +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_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 22321285B7 for ; Fri, 10 Feb 2017 19:23:15 +0000 (UTC) Received: (qmail 10041 invoked by uid 550); 10 Feb 2017 19:23:14 -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 10014 invoked from network); 10 Feb 2017 19:23:13 -0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2014; h=Sender:In-Reply-To:Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date; bh=qf5ROMzd0UlzDQ6bTXz8bsorj03wkHjGLuipO/soRrU=; b=im1IWSD/QogQlDZ+9Atn/+7dO0XXj6/MaCDTQ3Rg6FuNmIneE619/FPQjhF/I8JKTf/3xYETZjMS6+bE1hfpT2AYUAJfq4r3SYYrUj7fFx5jnEgGqVuhEY7HYhKqkV/JRWj+PnBIiZyyCl7ETvLMzCxPG7oxRn3bzLHLjaaOrZk=; Date: Fri, 10 Feb 2017 19:22:42 +0000 From: Russell King - ARM Linux To: Andy Lutomirski Cc: Thomas Garnier , Stephen Bates , "linux-s390@vger.kernel.org" , Kees Cook , Arnd Bergmann , "kernel-hardening@lists.openwall.com" , Linux API , Will Deacon , LKML , Dave Hansen , Jeff Moyer , =?iso-8859-1?Q?Ren=E9?= Nyffenegger , Milosz Tanski , "linux-arm-kernel@lists.infradead.org" Message-ID: <20170210192242.GM27312@n2100.armlinux.org.uk> References: <20170209183358.103094-1-thgarnie@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) Sender: Russell King - ARM Linux Subject: [kernel-hardening] Re: [RFC] syscalls: Restore address limit after a syscall X-Virus-Scanned: ClamAV using ClamSMTP On Thu, Feb 09, 2017 at 06:42:34PM -0800, Andy Lutomirski wrote: > On Thu, Feb 9, 2017 at 3:41 PM, Thomas Garnier wrote: > > So by default it is in the wrapper. If selected, an architecture can > > disable the wrapper put it in the best places. Understood correctly? > > Sounds good to me. > > Presumably the result should go through -mm. Want to cc: akpm and > linux-arch@ on the next version? > > I've also cc'd arm and s390 folks -- those are the other arches that > try to be on top of hardening. The best place for this on ARM is in the assembly code, rather than in the hundreds of system calls - having it in one place is surely better for reducing the cache impact. This (untested) patch should be sufficient for ARM - there's two choices which I think make sense to do this: 1. Immediately after returning the syscall 2. Immediately before any returning to userspace (1) has the advantage that the address limit will be forced for the exit-path works that we do, preventing those making accesses to kernel space. (2) has the advantage that we'd guarantee that the address limit will be forced while userspace is running for the next entry into kernel space. There's actually a third option as well: (3) forcing the address limit on entry to the kernel from userspace. This patch implements option 1. arch/arm/kernel/entry-common.S | 6 ++++++ 1 files changed, 6 insertions(+) diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S index eb5cd77bf1d8..6a717a2ccb88 100644 --- a/arch/arm/kernel/entry-common.S +++ b/arch/arm/kernel/entry-common.S @@ -39,6 +39,8 @@ ret_fast_syscall: UNWIND(.fnstart ) UNWIND(.cantunwind ) + mov r1, #TASK_SIZE + str r1, [tsk, #TI_ADDR_LIMIT] disable_irq_notrace @ disable interrupts ldr r1, [tsk, #TI_FLAGS] @ re-check for syscall tracing tst r1, #_TIF_SYSCALL_WORK | _TIF_WORK_MASK @@ -64,6 +66,8 @@ ENDPROC(ret_fast_syscall) ret_fast_syscall: UNWIND(.fnstart ) UNWIND(.cantunwind ) + mov r1, #TASK_SIZE + str r1, [tsk, #TI_ADDR_LIMIT] str r0, [sp, #S_R0 + S_OFF]! @ save returned r0 disable_irq_notrace @ disable interrupts ldr r1, [tsk, #TI_FLAGS] @ re-check for syscall tracing @@ -262,6 +266,8 @@ ENDPROC(vector_swi) b ret_slow_syscall __sys_trace_return: + mov r1, #TASK_SIZE + str r1, [tsk, #TI_ADDR_LIMIT] str r0, [sp, #S_R0 + S_OFF]! @ save returned r0 mov r0, sp bl syscall_trace_exit