Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp520252pxa; Fri, 31 Jul 2020 19:55:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy16l1OVNQjIdkwQsHfD8jeDqPmSM+++uN0F+uSXWeNG5VLnXSiKGlOn6e2bcOur+BwObpZ X-Received: by 2002:a17:906:3c59:: with SMTP id i25mr6776541ejg.202.1596250542736; Fri, 31 Jul 2020 19:55:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596250542; cv=none; d=google.com; s=arc-20160816; b=GgcOuLVjAdNJTMjj58gtD+CMuppveBuFD5jhtNkl5Tul4os76CcnJYz6GpwhVGmYgU V4gNK5gsoclGTFZx1D4Svi0whU4H7BicgmAwOHW9JETM0GdiE1TUq/a8r7f2ogG0OsGk gNZLssK7QrFzraT2rbaNvX+h7Mw2HuDchO03XYPaj4lNrcKZ5gar9TKkmXgTKoMlKU2F j19oMmb5ydHjbVbBoGaJGjLy4UsxEMD0V4lXfdKxi7pw/H3FhbH3E2On3+Mugw7K5YU8 JhnP5ooSPE4BBva1ZuJW2qpu+4TsjlPMBWNZJT/lOc+k/hqYf+SRpYPuEE8neKOAsPIU uADA== 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=qQWOKnsvuGAQthwsVhbKAAVxRkrCLknLmfWwO2EQo/0=; b=sUMQc2wYrj9kDv3zfxxrsccHTPVAnqa0nI4k/lAyYPdfULT6XoKlk8Q7bBdPL/qJb5 4B72uiDzGUnua+GzpmgmLqCNqJSIHdkpE4GY7gQjy0VWebo+rQ1BMDJHwBOe0PniDU6n R8BDbXj9iXFGzW2UIHpUsYHWvGHaW5qrlDv+k4o2Fv7n87wZEMl1Cepw87fcsx3Qv6xZ dtw2i0xJ4KcWcfsBakNd86YvKGMxkoADyR2ZidKLAcaskSI7AEujV7hhby28sMtk1NeM uM1Mjj0xln9bqwXhU+U0SMAutdFQk5HGY+kkChdm6tWEVZdgZbV/D+Z1YqWzwiHFUguf A4og== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=rmevkkZp; 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 z65si6755316ede.610.2020.07.31.19.55.20; Fri, 31 Jul 2020 19:55:42 -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=rmevkkZp; 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 S1728416AbgHACx3 (ORCPT + 99 others); Fri, 31 Jul 2020 22:53:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727047AbgHACx3 (ORCPT ); Fri, 31 Jul 2020 22:53: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 3D523C06174A; Fri, 31 Jul 2020 19:53:29 -0700 (PDT) Received: by mail-qv1-xf42.google.com with SMTP id b2so4489418qvp.9; Fri, 31 Jul 2020 19:53:29 -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=qQWOKnsvuGAQthwsVhbKAAVxRkrCLknLmfWwO2EQo/0=; b=rmevkkZp5ggJO7jft1muP1MvMxO25crEs8f10wHPc61/gQKrozxih1B/VYK6LG0xTd FCN6o88kweQ+PcUrzYbBKnrPnqyBSX39y6i7VliZJx2/1q2HopeQ6LKwrzJEr5VRpv7j daXppJVg0m8mj0/gP38wKrrNpLf4N8MJxun6npq2C3xxNDPOK1mxpe3q6pKzuKTSKJMq WkI7NcEAKCPHBeqnhvsdUJkfZBGI+jOVhN5fR6j+HzXv6xluLLANoYNy0iszcvVXGe2t NqJldwET6SEe09TvdDekJwbwsWGmKXiSdEMf0Dq6ShNroR0pNerL2UG3QotbZTTmnh9H 5Ihw== 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=qQWOKnsvuGAQthwsVhbKAAVxRkrCLknLmfWwO2EQo/0=; b=k6li/Io2XU8a7aeRWwFWYPVonExPQ91PLqgEuKJhwEEbt1oEwcoKAdNJ0Y6xj5vyLb oQyIV/5dk6nkxhJZHbGgMYQFn6kSUo5lCMDBmArN8n+ibSDqZqGlXVl8zvysXeguesnr L1VXJ8cRtPXrW2r7scnk04X+xGCsea02r+qTYwxmilI8MZjI0HdMPqXwag8ZjNaHIbQM JnB1t/8YPAEHlJfkyUGufaPJ4mDTmvvyHZs56+urSlqtajSv+x67W6jN2C9TVqFRiCke Y0gnpmG5wKftD0J4czdnzBa/5I/VTOc5nrUFpmK3QfrjCyxJfmzNnjLE/Y+QSGlk2btl UXGg== X-Gm-Message-State: AOAM532rTR/Np/onlPbcCsme+ob/fsUWCUPfpIkVAE3IcAobwe6s09AS 1qSnft1gcnuT4uDL5KxuTHE= X-Received: by 2002:a0c:b999:: with SMTP id v25mr6978810qvf.32.1596250408454; Fri, 31 Jul 2020 19:53:28 -0700 (PDT) Received: from rani.riverdale.lan ([2001:470:1f07:5f3::b55f]) by smtp.gmail.com with ESMTPSA id p33sm9274408qtp.49.2020.07.31.19.53.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jul 2020 19:53:27 -0700 (PDT) From: Arvind Sankar X-Google-Original-From: Arvind Sankar Date: Fri, 31 Jul 2020 22:53:25 -0400 To: Arvind Sankar Cc: Kees Cook , 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: <20200801025325.GA2800311@rani.riverdale.lan> References: <20200731230820.1742553-1-keescook@chromium.org> <20200731230820.1742553-33-keescook@chromium.org> <20200801014755.GA2700342@rani.riverdale.lan> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20200801014755.GA2700342@rani.riverdale.lan> 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 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.