Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp917968pxa; Sat, 1 Aug 2020 10:13:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwrOIPWl7LknKQhEUmqLvzs7GNs3/GVZsU/7e5o252tLQBpubv2uGj8qRT0YSYzWifcseTy X-Received: by 2002:a05:6402:325:: with SMTP id q5mr9201350edw.343.1596301982817; Sat, 01 Aug 2020 10:13:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596301982; cv=none; d=google.com; s=arc-20160816; b=L8H9rpfpnwdKybKVG5wdZZ8gh2J0r7YUC5UPLv0kUSvzmva3Sm+x6/zsjQoa7jMzio 1qkuz4g8ImOR1y2+Qez9Ve49snXkgooNXi8LYVA1qSYkap7aLTxRTIH+IlRrZRqJXOrL KxG+hhPX3nyK9/N+4p9oR0TtwqeU8K43J9tucVD+Odj0zs/hsQ34NPQhswgf8mX9psAP UxY+3QC4DdQ3EDjBJU3ESjV4W5dJc/ubDrfbQKIog4BSIczo7vGey4MPZwdNL7+IAl8E 2QFS+dh7MsUjBhp+6PESn+k//d4LVNU+G9Xo/PKRzPAr1Wvhz/6qU10e4BWY228X9an8 bLUQ== 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:date:from :dkim-signature; bh=2o6GVTZCy3XlmzBSwd7fA26VADSjJEkCYNl3YQKOr2M=; b=lSjNZ73+48UfUfwZMd5BVcwfmq+PPp7MRmg5bWnJHjdk5jdYJ+NviQYPTNNwIS4P4i 8zecC6SERChKPuHYuX2x8clQpUDEMfrvR4s+8qzHVjoNmzAm8Y07jETv3+GwMPGE8cE3 2Lvr4+qzkOU5M1YjMqQHslgPrxUOVgInbv4bNjeSoTFbD9IVAo4t4obuv/2AHco+lH9M gKuyrBe4CH/sxlFlaiA3qWAFcUpPGyRoaOe2LVdR4eMOAHgQpigNFjo52RFAJXAa7ij7 kPZzIo5ulMpwrialkT6GxffmYO/kmRtj5wmDC/EcFgH9orzvihXY/fV+TZqKUClzYw1l T7Aw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=Ldn6PBxD; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ch10si7354762edb.28.2020.08.01.10.12.39; Sat, 01 Aug 2020 10:13:02 -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=Ldn6PBxD; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727037AbgHARM3 (ORCPT + 99 others); Sat, 1 Aug 2020 13:12:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726494AbgHARM3 (ORCPT ); Sat, 1 Aug 2020 13:12:29 -0400 Received: from mail-qv1-xf42.google.com (mail-qv1-xf42.google.com [IPv6:2607:f8b0:4864:20::f42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D5460C06174A; Sat, 1 Aug 2020 10:12:28 -0700 (PDT) Received: by mail-qv1-xf42.google.com with SMTP id c9so1876482qvu.5; Sat, 01 Aug 2020 10:12:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:date:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=2o6GVTZCy3XlmzBSwd7fA26VADSjJEkCYNl3YQKOr2M=; b=Ldn6PBxD4m7lMPymQjipKfl27zylKQuiR2k8wfxVSrmlQ5jpqIVVImGSZWjlPgIbGC hDJ7BkFuGFrS7733Sa79QeGiqV0qQCemUiXRE/QiwWnLbm5EQ82dmxs/kG3UyfU7E7n8 nL536EWJMI21gMA9GAQJpy1F9/6iR1lsI9mBQIIRfbo6g7chxN3cmdc3uVhPEga7RQ4V TEliR1I27x7f40QWq2Ktg3mUvoW/3WDyyvpBb63myjZ0gnPKNIW0MqE9glVDJBy3Bgqw In5hjK+9C4XkaeRowWu/SdcdFCcOWgZbXvoQRkQSw2xxEZumWAOjTxrQxGG+33eaNoFE aj7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:date:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to; bh=2o6GVTZCy3XlmzBSwd7fA26VADSjJEkCYNl3YQKOr2M=; b=Dlxkj4gwDa3VAZVNrv9hw1JojMt5+vpiOLB+vkYEQBPdwM9S5jDV2rIGne+HuUAQOU 7BlQ/YkXTwh/eVktZHaijfYequ8PWQge+Kk4a/24lKyW5IAq/lQuS8ylOiK2n+Ui4wQp 7EnrtXgTPfBhCPqZq4DlY58FS7qjlMRiBU9pKOHU5K6UULrmMwWLV6LUuwFR2mdNugu0 in8ILi+AU9zuXaELgilZFz8+sIOVlpLFCJDMxymC+A9W+q3wMsQiKZZM+z5nsyfuitK8 RSx21XmrDqODOHGNAu12ZpUO/S/t/hhT+CqFkLlOROoPeREm/4TrqdHi/nHqPrieo+FD 7UVA== X-Gm-Message-State: AOAM532WSU+s03VmHGTa7xM8vcen43CLZOlnvD59LN4QYCPK5lKZeCdM VXIHBrZ/aXx6iBtB9kUSxKA= X-Received: by 2002:a0c:ffc6:: with SMTP id h6mr9551061qvv.251.1596301947711; Sat, 01 Aug 2020 10:12:27 -0700 (PDT) Received: from rani.riverdale.lan ([2001:470:1f07:5f3::b55f]) by smtp.gmail.com with ESMTPSA id i19sm12760874qkk.68.2020.08.01.10.12.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Aug 2020 10:12:27 -0700 (PDT) From: Arvind Sankar X-Google-Original-From: Arvind Sankar Date: Sat, 1 Aug 2020 13:12:25 -0400 To: Kees Cook Cc: Arvind Sankar , Thomas Gleixner , Will Deacon , Catalin Marinas , Mark Rutland , Ard Biesheuvel , Peter Collingbourne , James Morse , Borislav Petkov , Ingo Molnar , Russell King , Masahiro Yamada , Nick Desaulniers , Nathan Chancellor , Arnd Bergmann , x86@kernel.org, clang-built-linux@googlegroups.com, linux-arch@vger.kernel.org, linux-efi@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v5 32/36] x86/boot/compressed: Reorganize zero-size section asserts Message-ID: <20200801171225.GB3249534@rani.riverdale.lan> References: <20200731230820.1742553-1-keescook@chromium.org> <20200731230820.1742553-33-keescook@chromium.org> <20200801014755.GA2700342@rani.riverdale.lan> <20200801025325.GA2800311@rani.riverdale.lan> <202007312235.4A48157938@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <202007312235.4A48157938@keescook> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jul 31, 2020 at 10:36:00PM -0700, Kees Cook wrote: > On Fri, Jul 31, 2020 at 10:53:25PM -0400, Arvind Sankar wrote: > > On Fri, Jul 31, 2020 at 09:47:55PM -0400, Arvind Sankar wrote: > > > On Fri, Jul 31, 2020 at 04:08:16PM -0700, Kees Cook wrote: > > > > For readability, move the zero-sized sections to the end after DISCARDS > > > > and mark them NOLOAD for good measure. > > > > > > > > Signed-off-by: Kees Cook > > > > --- > > > > arch/x86/boot/compressed/vmlinux.lds.S | 42 +++++++++++++++----------- > > > > 1 file changed, 25 insertions(+), 17 deletions(-) > > > > > > > > diff --git a/arch/x86/boot/compressed/vmlinux.lds.S b/arch/x86/boot/compressed/vmlinux.lds.S > > > > index 3c2ee9a5bf43..42dea70a5091 100644 > > > > --- a/arch/x86/boot/compressed/vmlinux.lds.S > > > > +++ b/arch/x86/boot/compressed/vmlinux.lds.S > > > > @@ -42,18 +42,16 @@ SECTIONS > > > > *(.rodata.*) > > > > _erodata = . ; > > > > } > > > > - .rel.dyn : { > > > > - *(.rel.*) > > > > - } > > > > - .rela.dyn : { > > > > - *(.rela.*) > > > > - } > > > > - .got : { > > > > - *(.got) > > > > - } > > > > .got.plt : { > > > > *(.got.plt) > > > > } > > > > + ASSERT(SIZEOF(.got.plt) == 0 || > > > > +#ifdef CONFIG_X86_64 > > > > + SIZEOF(.got.plt) == 0x18, > > > > +#else > > > > + SIZEOF(.got.plt) == 0xc, > > > > +#endif > > > > + "Unexpected GOT/PLT entries detected!") > > > > > > > > .data : { > > > > _data = . ; > > > > @@ -85,13 +83,23 @@ SECTIONS > > > > ELF_DETAILS > > > > > > > > DISCARDS > > > > -} > > > > > > > > -ASSERT(SIZEOF(.got) == 0, "Unexpected GOT entries detected!") > > > > -#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 > > > > + /* > > > > + * Sections that should stay zero sized, which is safer to > > > > + * explicitly check instead of blindly discarding. > > > > + */ > > > > + .got (NOLOAD) : { > > > > + *(.got) > > > > + } > > > > + ASSERT(SIZEOF(.got) == 0, "Unexpected GOT entries detected!") > > > > > > > > -ASSERT(SIZEOF(.rel.dyn) == 0 && SIZEOF(.rela.dyn) == 0, "Unexpected run-time relocations detected!") > > > > + /* ld.lld does not like .rel* sections being made "NOLOAD". */ > > > > + .rel.dyn : { > > > > + *(.rel.*) > > > > + } > > > > + ASSERT(SIZEOF(.rel.dyn) == 0, "Unexpected run-time relocations (.rel) detected!") > > > > + .rela.dyn : { > > > > + *(.rela.*) > > > > + } > > > > + ASSERT(SIZEOF(.rela.dyn) == 0, "Unexpected run-time relocations (.rela) detected!") > > > > +} > > > > -- > > > > 2.25.1 > > > > > > > > > > There's no point in marking zero-size sections NOLOAD -- if the ASSERT's > > > passed, they won't be present in the file at all anyway. > > > > > > The only section for which there might be a point is .got.plt, which is > > > non-empty on 32-bit, and only if it is first moved to the end. That > > > saves a few bytes. > > > > Btw, you should move .got.plt also to the end anyway for readability, > > it's unused even if non-empty. And with the ASSERT being placed > > immediately after it, it's even more distracting from the actual section > > layout. > > ld.bfd (if I'm remembering correctly) was extraordinarily upset about it > being at the end. I will retest and report back. > > -- > Kees Cook Actually, moving it to the end also requires marking it INFO or stripping it out when creating the bzImage. Otherwise we get back to that old problem of materializing .bss/.pgtable in the bzImage.