Received: by 2002:a25:2c96:0:0:0:0:0 with SMTP id s144csp386571ybs; Sun, 24 May 2020 08:18:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxZFAjSyny+hHlVOepvIBxBsFLJTVY7xzb4U8dc/BC+2WwUOO+h4yONgPif4e1T4KAIG1/V X-Received: by 2002:a17:906:355b:: with SMTP id s27mr15287060eja.436.1590333524903; Sun, 24 May 2020 08:18:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590333524; cv=none; d=google.com; s=arc-20160816; b=KiiTkkg0zERaJ9x0YOMDCo0LF2cAMv3uHllvRhOUqJZQCG4AKaX63bdlNBHK+Rbg2d DbHRkS3GCl5Mkgc7cs8OwciBOpx/PF1x/FznbeN3CzOZiezBw6KNXHXZkrcBsZCx0yzv 3toiVcLyfNw6b+E9ImXsr/Ahz1HjqOIyN4Rtnd2Z+ayrdrBJq6sOuisLRbp/a8xqwDQG BeyoZpxYQ/lUw5fVKdX08RKAozqZpNsGrAikVEPAJp2/8n17gY6j5eIT63FJhduP2iRR BsUZVZNmhNoptien2er7dNWL7wdVNJ7Y/R5wXiURVC/+zTB3MhBEMOVSsUsEMDDK/z7I iQMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=oziPQ2XbXOvI/olxc4gQtwWvXNbQonx0M809pCxssE8=; b=k5lDwibE4roCzO74Qo6pG6QmSWZkceMnIGmjvLtthQmBXKUUM9WkSu8uj0YnmZitD/ o+m0qIzM2S/YSjXUJCeYIKBxW4+SCb80zPrEBbK1XLUv2V/Bc4ZvQahAm5QN0cca/w3Y Fa0w0elpcD3hj6KTWr8DRvEtHmpRbAgDt05z6KsDaj/6t3u7RNUKNB3hLSJVoD6Zkbqg avnfpCXSMgNYOPn9/0XWa/YMERVzZf5m9+zlDw/LrV0CGGOwPniEW9zmLoFXCMea0XlZ QPoHyHGxNOyd1YKeUIcQcJa+PcwFmaUotcMhRHfZMo1Cr5GPrexsGKmZS3krSnKiypu/ AcTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=VxCPXpEL; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d1si947075ejb.134.2020.05.24.08.18.21; Sun, 24 May 2020 08:18:44 -0700 (PDT) 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 header.i=@gmail.com header.s=20161025 header.b=VxCPXpEL; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729779AbgEXPOb (ORCPT + 99 others); Sun, 24 May 2020 11:14:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727985AbgEXPOb (ORCPT ); Sun, 24 May 2020 11:14:31 -0400 Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF56FC061A0E; Sun, 24 May 2020 08:14:30 -0700 (PDT) Received: by mail-wm1-x343.google.com with SMTP id f5so6382512wmh.2; Sun, 24 May 2020 08:14:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=oziPQ2XbXOvI/olxc4gQtwWvXNbQonx0M809pCxssE8=; b=VxCPXpELeZl8kz/PBPmi7B032uBR5oPR1bicbh/3Qv5VmPfgZnbxCBIPNr/qHqJyCj 2oFRQHwAZmsVA3ZI100YaPrhOHPzcu1hb3eZuLyk3aIIBKppNAErDxW/wvWDmiAnYecU WXV38XVh6Q9yZOoAKpeS8xPWzPG0QtDndCJQHCfX9toOV++IXYdmKlR6ExoFfgzqA4qk tME2M8s+Po5PxnZD9xzC6h9RNlcKl7W4E7DK5TjWqPOeJn78QVSSLvlkHzHffHAkKF4W SqlC74pTAZXwGBdYOTbQA02XUKa1mTDfIgTnvMUTeK5EAqgBJq3eIyJ/kX4EoSrjyckt Jy7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to; bh=oziPQ2XbXOvI/olxc4gQtwWvXNbQonx0M809pCxssE8=; b=jYV3gT3ydS5SXHxnS2gpfuKx/q9FjMu/m9q7SyPvVD7ZlbI4MfPy+Q0uoU1RKtcv8C WrAdRCATyCPQ9d9GaxzdQm4fXjZJcaNlfj/cq44FxhujTrGApZKac7CUaUw67pwlATIM JFFa/PnV6g53E90PhXDDf+2bqoR1qNTSagTW/4uRZpWrfccZMlpt0M75UDFf8nXaQefz Js5osjUkLIQA04Gpseg/0YKaxSp95+BojmLerRq6M0FmX/1FmX1l58Cr3S2ichd337WY hrGljq9t0kxe0uuvcMvmjStNa26pqv9bv7xHSgpfR6jRhWgjw98pikVMzTt2dtlrE4ys gG2A== X-Gm-Message-State: AOAM53211n7nYx+OfM50+UxLWqmp9ACfGn6xtohhjghNzvO8hoEbV+Jc E5snHeRLwwtMMamHp4mnGYyE8oin X-Received: by 2002:a05:600c:293:: with SMTP id 19mr22369589wmk.71.1590333268550; Sun, 24 May 2020 08:14:28 -0700 (PDT) Received: from gmail.com (54033286.catv.pool.telekom.hu. [84.3.50.134]) by smtp.gmail.com with ESMTPSA id q15sm14588318wrf.87.2020.05.24.08.14.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 May 2020 08:14:27 -0700 (PDT) Date: Sun, 24 May 2020 17:14:26 +0200 From: Ingo Molnar To: Ard Biesheuvel Cc: linux-efi , X86 ML , Linux Kernel Mailing List , Maarten Lankhorst , Linus Torvalds , Arvind Sankar Subject: Re: [PATCH v2 1/3] x86/boot/compressed: move .got.plt entries out of the .got section Message-ID: <20200524151426.GC11617@gmail.com> References: <20200523120021.34996-1-ardb@kernel.org> <20200523120021.34996-2-ardb@kernel.org> <20200524150841.GA11617@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org * Ard Biesheuvel wrote: > On Sun, 24 May 2020 at 17:08, Ingo Molnar wrote: > > > > > > * Ard Biesheuvel wrote: > > > > > The .got.plt section contains the part of the GOT which is used by PLT > > > entries, and which gets updated lazily by the dynamic loader when > > > function calls are dispatched through those PLT entries. > > > > > > On fully linked binaries such as the kernel proper or the decompressor, > > > this never happens, and so in practice, the .got.plt section consists > > > only of the first 3 magic entries that are meant to point at the _DYNAMIC > > > section and at the fixup routine in the loader. However, since we don't > > > use a dynamic loader, those entries are never populated or used. > > > > > > This means that treating those entries like ordinary GOT entries, and > > > updating their values based on the actual placement of the executable in > > > memory is completely pointless, and we can just ignore the .got.plt > > > section entirely, provided that it has no additional entries beyond > > > the first 3 ones. > > > > > > So add an assertion in the linker script to ensure that this assumption > > > holds, and move the contents out of the [_got, _egot) memory range that > > > is modified by the GOT fixup routines. > > > > > > Signed-off-by: Ard Biesheuvel > > > --- > > > arch/x86/boot/compressed/vmlinux.lds.S | 13 ++++++++++++- > > > 1 file changed, 12 insertions(+), 1 deletion(-) > > > > > > diff --git a/arch/x86/boot/compressed/vmlinux.lds.S b/arch/x86/boot/compressed/vmlinux.lds.S > > > index 0dc5c2b9614b..ce3fdfb93b57 100644 > > > --- a/arch/x86/boot/compressed/vmlinux.lds.S > > > +++ b/arch/x86/boot/compressed/vmlinux.lds.S > > > @@ -44,10 +44,13 @@ SECTIONS > > > } > > > .got : { > > > _got = .; > > > - KEEP(*(.got.plt)) > > > KEEP(*(.got)) > > > _egot = .; > > > } > > > + .got.plt : { > > > + KEEP(*(.got.plt)) > > > + } > > > + > > > .data : { > > > _data = . ; > > > *(.data) > > > @@ -75,3 +78,11 @@ SECTIONS > > > . = ALIGN(PAGE_SIZE); /* keep ZO size page aligned */ > > > _end = .; > > > } > > > + > > > +#ifdef CONFIG_X86_64 > > > +ASSERT (SIZEOF(.got.plt) == 0 || SIZEOF(.got.plt) == 0x18, > > > + "Unexpected GOT/PLT entries detected!") > > > +#else > > > +ASSERT (SIZEOF(.got.plt) == 0 || SIZEOF(.got.plt) == 0xc, > > > + "Unexpected GOT/PLT entries detected!") > > > +#endif > > > > Cool debugging check! > > > > Minor consistent-style nit: > > > > s/ASSERT ( > > /ASSERT( > > > > ok > > > Optional: maybe even merge these on a single line, as a special exception to the col80 rule? > > > > #ifdef CONFIG_X86_64 > > ASSERT(SIZEOF(.got.plt) == 0 || SIZEOF(.got.plt) == 0x18, "Unexpected GOT/PLT entries detected!") > > #else > > ASSERT(SIZEOF(.got.plt) == 0 || SIZEOF(.got.plt) == 0xc, "Unexpected GOT/PLT entries detected!") > > #endif > > > > But fine either way. > > > > SIZEOF(.got.plt) <= 0x18 > > could be used as well, given that the section is either empty, or has > at least the 3 magic entries. This this has bitten us before, so I think the precise assert is better. Two-line version is OK too. Thanks, Ingo