From patchwork Sat Jul 29 03:51:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Pitre X-Patchwork-Id: 9869719 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 CC0816035E for ; Sat, 29 Jul 2017 03:52:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BEC0028799 for ; Sat, 29 Jul 2017 03:52:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B3230287AE; Sat, 29 Jul 2017 03:52:32 +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=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9CF3928799 for ; Sat, 29 Jul 2017 03:52:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=MSHjxsOFOnh3qYd6Ysdmlxz8OhhxU7R0/dPyWjT5KK8=; b=dsGqoVc+RDX0ctSDzTtLpr727K +OZKNhk8d8xINkxsrSAl38taRrCIY0oZncOAm9Dm7cSsGiE43ihEYFYziANHwORJ+U/fT6G48/ilM QYWRNQBlYvnIrvc85UA2tqsJh0/U0gG/QnPSdY39Rg+AEJvcg14iAeLIzI0DdeT8xAUK2itCVE2YV GS2p/OiMXE/j7mL9ROPyi9ZLYGI3xavRcyDUUqZnI1mM+5TkHDJTXaw1hZ99oBk3xLH/g+tNXfW27 lgu0/vmFEbXuQSU5AWMiJJ2VVPqbhRXwGPXmyvN0ZCdu4PN6CPxcFbtIJerpipTcF5EY5xvmVO8rw W171h0HA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dbIng-0001dn-6S; Sat, 29 Jul 2017 03:52:24 +0000 Received: from pb-smtp1.pobox.com ([64.147.108.70] helo=sasl.smtp.pobox.com) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dbInb-0001bz-D7 for linux-arm-kernel@lists.infradead.org; Sat, 29 Jul 2017 03:52:22 +0000 Received: from sasl.smtp.pobox.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id A0CBA9EE23; Fri, 28 Jul 2017 23:51:56 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to:cc :subject:date:message-id:in-reply-to:references; s=sasl; bh=Gghc 3lr2CzFFh2dlGyyVoB9mHXE=; b=dDvRyVE76SztNZ8Tcs31YTiJcExZXlB1ntUy IyZ95nzAVy2M7BzRS94CFGg9haQ+j8XRO0BgYSg6wiUbgZd/o8Gmd9SL4RYc6/Ty dk54U5ADy/kWq4HWG6SxmlrE5uGCzWvAvG/ZJVRdJMo6NMiH+wSccSM0csVQ0egN 2UuwcDE= Received: from pb-smtp1.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id 97C389EE22; Fri, 28 Jul 2017 23:51:56 -0400 (EDT) Received: from yoda.home (unknown [96.23.157.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp1.pobox.com (Postfix) with ESMTPSA id EEE0B9EE1F; Fri, 28 Jul 2017 23:51:55 -0400 (EDT) Received: from xanadu.home (xanadu.home [192.168.2.2]) by yoda.home (Postfix) with ESMTP id 2F5DF2DA0660; Fri, 28 Jul 2017 23:51:55 -0400 (EDT) From: Nicolas Pitre To: Russell King - ARM Linux , linux-arm-kernel@lists.infradead.org Subject: [PATCH 2/4] ARM: start_thread(): don't clear all regs with !MMU Date: Fri, 28 Jul 2017 23:51:48 -0400 Message-Id: <20170729035150.5214-3-nicolas.pitre@linaro.org> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170729035150.5214-1-nicolas.pitre@linaro.org> References: <20170729035150.5214-1-nicolas.pitre@linaro.org> X-Pobox-Relay-ID: 43DD7C3A-7411-11E7-9C44-FE4B1A68708C-78420484!pb-smtp1.pobox.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170728_205219_620855_B769E90E X-CRM114-Status: GOOD ( 14.21 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Mickael Guene ." , Alexandre Torgue MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP The elf_fdpic binary format driver has to initialize extra registers other than the stack and program counter as required by the corresponding ABI. So let's avoid clearing all registers in the !MMU case. Only lr is still cleared in case some user space bug would attempt a direct return which could turn out to be very confusing indeed. There is no actual security argument with !MMU anyway so potential leaks across executables here are irrelevant. While at it let's get rid of start_thread_nommu(). Signed-off-by: Nicolas Pitre --- arch/arm/include/asm/processor.h | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/arch/arm/include/asm/processor.h b/arch/arm/include/asm/processor.h index c3d5fc124a..527d44c8d2 100644 --- a/arch/arm/include/asm/processor.h +++ b/arch/arm/include/asm/processor.h @@ -47,15 +47,17 @@ struct thread_struct { #define INIT_THREAD { } -#ifdef CONFIG_MMU -#define nommu_start_thread(regs) do { } while (0) -#else -#define nommu_start_thread(regs) regs->ARM_r10 = current->mm->start_data -#endif - #define start_thread(regs,pc,sp) \ ({ \ - memset(regs->uregs, 0, sizeof(regs->uregs)); \ + if (!IS_ENABLED(CONFIG_MMU)) { \ + /* \ + * Don't clear all regs as some binfmts have \ + * initialized some of them already. \ + */ \ + regs->ARM_r10 = current->mm->start_data; \ + regs->ARM_lr = 0; \ + } else \ + memset(regs->uregs, 0, sizeof(regs->uregs)); \ if (current->personality & ADDR_LIMIT_32BIT) \ regs->ARM_cpsr = USR_MODE; \ else \ @@ -65,7 +67,6 @@ struct thread_struct { regs->ARM_cpsr |= PSR_ENDSTATE; \ regs->ARM_pc = pc & ~1; /* pc */ \ regs->ARM_sp = sp; /* sp */ \ - nommu_start_thread(regs); \ }) /* Forward declaration, a strange C thing */