Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp512395pxu; Thu, 3 Dec 2020 06:10:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJwRZ234Veigql9NduGHqQS6pxuRTzBU+gM9RzVIXy3QU/flzWdQwKFhHLAJ6JMn7FhkL3tQ X-Received: by 2002:a17:906:3712:: with SMTP id d18mr2742870ejc.178.1607004602054; Thu, 03 Dec 2020 06:10:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607004602; cv=none; d=google.com; s=arc-20160816; b=YSsQ2Kk0SFzFEqVdRDzP0Umr6cISnn3ub1VQlLAy66R/Z376NiZV1UiGfEh2U9eLdH 6pwTxqRx43y65aepq8RNZDkW3J8CvZK5kJsBGKEUWJAJpBN7f4XHOZZ0mEY8JjH0DGnV uNJqyAQq0MraDldGBsH++SbC9djbkHLkNAHvxLxunjBYbyx+3O3tlEAN9syJRsagly4D OfLGzv6XpTW9gzTTJNg9K2XRHNvowhJpWWlHdiu6NlKWcG6M4R1q9XlbO5n4Rt34YbzI TULIlPWbLGOk6EPIk6OoXWXE26QZQVZ4TtQIgsPg92L9Jjd7BuUfng807cCFckq3YpWk ujCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=QFnw1VAMIMbQicaf3rgoSZRJ6IT9RzN8Pv4ZM1fxb14=; b=CVCax85tbuo6ZQ/cTzoWpHkTL/ATclpYECFcn9F5+AhzgH0V3ido74qwM/Ib0hTXGW cVailj9lhdg0oiIM8xU17+IdhmYpiiZdJv/vKUmXFzztroMfTSHwA4evjqQS/4so/RT+ 5TC3AfK5saR/8mD/r606if+5wBgNHbcN0GdPs2vv0/jJbYWx+2M0ayZdYGWlZOLRis2u mtmYJgpHIIQUg2QOFG81oWQ+DaeXlToNHb5Wuk/mG6O1qOMXG/AlkOBDPebGs+p5KFo8 j6A1T5YEf7TEaQzB1gAfq9YGifO2EWfjCaefbj/OyhSjzQYQGCjQM3EZh/KsuNGZlwD9 P2Uw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail (test mode) header.i=@armlinux.org.uk header.s=pandora-2019 header.b=v+PlqEPt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=armlinux.org.uk Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bz13si1148097ejc.437.2020.12.03.06.09.37; Thu, 03 Dec 2020 06:10:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail (test mode) header.i=@armlinux.org.uk header.s=pandora-2019 header.b=v+PlqEPt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=armlinux.org.uk Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730871AbgLCOGI (ORCPT + 99 others); Thu, 3 Dec 2020 09:06:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36426 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727242AbgLCOGI (ORCPT ); Thu, 3 Dec 2020 09:06:08 -0500 Received: from pandora.armlinux.org.uk (pandora.armlinux.org.uk [IPv6:2001:4d48:ad52:32c8:5054:ff:fe00:142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 049C8C061A4E; Thu, 3 Dec 2020 06:05:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2019; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=QFnw1VAMIMbQicaf3rgoSZRJ6IT9RzN8Pv4ZM1fxb14=; b=v+PlqEPtOHZQXJBag6IUKH0QS WYGHluAVUxystXwSqMh1BGc6fWamXExl7QyzeUjlsxhIZIztWKny4hYzmWwYfQucdiphA/W8IOi6J cyCixIG1llVtduxNbXriWI1n/DclNg/F5xPuAhA8pHIGwaOKEaWiHOKJuqBGijmdMiXto4YmIKysA sf62p2IGRAtwCAIYove4EDk61sfuvjUNyjmkjSLvzlGo5BI3Py+42hFjxKfl63O/7trDPkBqTB/q2 kNdsFI7jEEyZfWENgvZkBudMHZMcArbCBwl4JmWdyeXQLN5BOdNaUrxqUQVDp3fU9XnFAyibTDl45 3BzBafBdA==; Received: from shell.armlinux.org.uk ([fd8f:7570:feb6:1:5054:ff:fe00:4ec]:39274) by pandora.armlinux.org.uk with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kkpEB-00038k-FQ; Thu, 03 Dec 2020 14:04:59 +0000 Received: from linux by shell.armlinux.org.uk with local (Exim 4.92) (envelope-from ) id 1kkpE2-000871-J6; Thu, 03 Dec 2020 14:04:50 +0000 Date: Thu, 3 Dec 2020 14:04:50 +0000 From: Russell King - ARM Linux admin To: Geert Uytterhoeven Cc: Nicolas Pitre , Ard Biesheuvel , Marek Szyprowski , Dmitry Osipenko , Linus Walleij , Arnd Bergmann , Eric Miao , Uwe =?iso-8859-1?Q?Kleine-K=F6nig?= , Lukasz Stelmach , Stephen Boyd , Chris Brandt , linux-arm-kernel@lists.infradead.org, linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v10 3/3] ARM: uncompress: Validate start of physical memory against passed DTB Message-ID: <20201203140450.GH1551@shell.armlinux.org.uk> References: <20201203121916.2870975-1-geert+renesas@glider.be> <20201203121916.2870975-4-geert+renesas@glider.be> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201203121916.2870975-4-geert+renesas@glider.be> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: Russell King - ARM Linux admin Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Dec 03, 2020 at 01:19:16PM +0100, Geert Uytterhoeven wrote: > diff --git a/arch/arm/boot/compressed/head.S b/arch/arm/boot/compressed/head.S > index d9cce7238a365081..1b6425df87e84e71 100644 > --- a/arch/arm/boot/compressed/head.S > +++ b/arch/arm/boot/compressed/head.S > @@ -282,10 +282,36 @@ not_angel: > * are already placing their zImage in (eg) the top 64MB > * of this range. > */ > - mov r4, pc > - and r4, r4, #0xf8000000 > + mov r0, pc > + and r0, r0, #0xf8000000 > +#ifdef CONFIG_USE_OF > + adr r1, LC1 > +#ifdef CONFIG_ARM_APPENDED_DTB > + /* > + * Look for an appended DTB. If found, we cannot use it to > + * validate the calculated start of physical memory, as its > + * memory nodes may need to be augmented by ATAGS stored at > + * an offset from the same start of physical memory. > + */ > + ldr r2, [r1, #4] @ get &_edata > + add r2, r2, r1 @ relocate it > + ldr r2, [r2] @ get DTB signature > + ldr r3, =OF_DT_MAGIC > + cmp r2, r3 @ do we have a DTB there? > + beq 1f @ if yes, skip validation > +#endif /* CONFIG_ARM_APPENDED_DTB */ > + > + /* Make sure we have some stack */ > + ldr sp, [r1] @ get stack location > + add sp, sp, r1 @ apply relocation > + > + /* Validate calculated start against passed DTB */ > + mov r1, r8 > + bl fdt_check_mem_start I don't think this is going to work. You can only run C code when it has been linked for a specific address and is loaded at the correct address as it contains absolute addresses. We work around that in the decompressor by (ab)using the GOT table, and the code that fixes up the GOT table is run later, after you've called out to some C code here. Quite how this works for you without the GOT fixups having been done, I'm not sure. -- RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!