From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1F60AC433DF for ; Sat, 1 Aug 2020 05:37:28 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DD0E3206E9 for ; Sat, 1 Aug 2020 05:37:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="t3cHKs2k"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="fM/bL01w" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DD0E3206E9 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=g90CH9ULgXVbnXBG/onAA8ckBR8NRHmK+oLs9cpLa0E=; b=t3cHKs2k7PX2ZwNmBMKou7M8K QtjLTXv8s3u8Oybui80rIfzANWF3mcYZNmZUmUnHgLG8dlkWfDyLymRZ4n23QLoRONXlBduYL6e1E WD32fzQ8IRzwuUxL3/yyZgxgQglOTEOIuNCyZszjwHGOaASaXmEfykRhjq8/kbWKOpP6T5wvaWLTC i/qKH5eNfIPzuT38bmAnf3TX/k6ZxP4jDtzdlYhsr99QMlecxeC/LZePSD/7GhJoR+cTKBh0FgsGd FwiQ1i6XCe+7MqjKjnxtEAEVJPihIl9IPZXkc0jFgNt82JYeETl2eebxhrC6Y0+PfrZkgq3vYJGnT zqYOXyIyA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1k1kBi-00046H-EJ; Sat, 01 Aug 2020 05:36:06 +0000 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1k1kBg-00045I-DX for linux-arm-kernel@lists.infradead.org; Sat, 01 Aug 2020 05:36:05 +0000 Received: by mail-pl1-x644.google.com with SMTP id k13so10535481plk.13 for ; Fri, 31 Jul 2020 22:36:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=TiksbxZAq651HXyzgXud8H+oOdlAwciZhMVaJuNaJO0=; b=fM/bL01waNwSe4ZuLsFiF5lgrC0CZA3LVoNOKHEfJt+W4CsL008YBdKU0zkDxQHZw2 If/SNkBwc6Tx0xWwSQyfs78u5lB0K3VImeoFLJnGn/imzBJdZ8I0C1jevEYAxqawGVjv sMOW37bYu6qq1l0NJXfCWFFmyxa0Wn9Rx1lL8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=TiksbxZAq651HXyzgXud8H+oOdlAwciZhMVaJuNaJO0=; b=TvxjFP2Ttdb/QPq6uaR7uX0Ixtz0D2oLQC9Iy1h7Tr7LlhG3vNtJ/sqAYiyyFHuwEG cDoubMEwka2KBjxaYn/e72Do/NCtK2UCMq0cLLISAJNCSXTLcynERqAjgl7cENKJWwDY GzXjeXRtyGCfgq+0l9w7xs2OBi0brf+r33qVPQKNX5ErTmG2vtOcBt+kmtGrUTFhp7mj D0pfiXlBN5swmjE1+mucEJ7lZw28lB+2FuCQlQ6DhfBAYxyywdAsOk/dmafAiyKMw/wO lxFHCCq/TJcfka9ftg6Mj672spLjq1tF6GEWOGRjGGBbh4DsRM3mEBjM/kaVwk9NXV5z Lrsg== X-Gm-Message-State: AOAM532GbsFUkX0uCvfFNIYzs4EVhLu+wl7juc0AIMpkfXTHpdWOOGiT OqeQ0Jc9wdSJ199WXyO7CPH2rg== X-Google-Smtp-Source: ABdhPJxBoVsLIfUCbTZK4Pt16UaZpEaNpjnTwzZAWj8yK7T+WP153kIvw3NqlQm5VCwH7XEDaByGhQ== X-Received: by 2002:a17:90a:d195:: with SMTP id fu21mr7200561pjb.100.1596260162387; Fri, 31 Jul 2020 22:36:02 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id i7sm11886481pgh.58.2020.07.31.22.36.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jul 2020 22:36:01 -0700 (PDT) Date: Fri, 31 Jul 2020 22:36:00 -0700 From: Kees Cook To: Arvind Sankar Subject: Re: [PATCH v5 32/36] x86/boot/compressed: Reorganize zero-size section asserts Message-ID: <202007312235.4A48157938@keescook> References: <20200731230820.1742553-1-keescook@chromium.org> <20200731230820.1742553-33-keescook@chromium.org> <20200801014755.GA2700342@rani.riverdale.lan> <20200801025325.GA2800311@rani.riverdale.lan> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20200801025325.GA2800311@rani.riverdale.lan> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200801_013604_465505_45D7263B X-CRM114-Status: GOOD ( 27.40 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , linux-arch@vger.kernel.org, linux-efi@vger.kernel.org, Arnd Bergmann , Peter Collingbourne , Catalin Marinas , Masahiro Yamada , x86@kernel.org, Nick Desaulniers , Russell King , linux-kernel@vger.kernel.org, Nathan Chancellor , clang-built-linux@googlegroups.com, Ingo Molnar , James Morse , Thomas Gleixner , Borislav Petkov , Will Deacon , Ard Biesheuvel , linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel