Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp581412pxa; Fri, 31 Jul 2020 22:38:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyVHMFmlymJx+MdKeH8ey/9svlDE98krSLcNSEpd+UEdM7bffEvH6vU0REBrYes4rh6miRG X-Received: by 2002:a17:906:78e:: with SMTP id l14mr7696002ejc.67.1596260301771; Fri, 31 Jul 2020 22:38:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596260301; cv=none; d=google.com; s=arc-20160816; b=v74w2JLYyoDasJ0J7F+oFJPZ4wdlijzicwXdKOxhXlwnSAoMlRxA55QsuER+q2LQHV IBPEHLONd/SSnS4JJTCHAPl6a2CP66INwXNOh7tuwvAn0vAe81IEERVbATtcgDmblV4h l6uedbbA0sKer1URw+kQKgg2HIeh2zujy3TaEAYQu2FZGu/5P4KEb2tRm2KEg0IQcSJ2 tx2KspDA86hk7Jft9kJNN4Dtep5nz8X3i/GUlMAgqsM5sGsKARyX0unyF850R65rpgS7 SxFECb8l4fq0UcyDS/enu1BPQPcDTeYL+ExwPrwUJ1GTqNjDykVF3DRNNsNbYh5aU4LG nmbA== 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=sBcnbrjbFajVyHxfld/Fszj/ZWv73cYyddExdUQ2/uM=; b=lpIWlTXbCmyN4OPGmkUsvD4wsWUce0jfafkhfEwLucSUmCigP4OdIC8ZTWEGNnd1P2 vK4dxWqMzMZrF0zS1bP2xJyJfLwGSMem7NhF+hq8aKe/M6y2QNV6csIA9zaAEsNLMFXm p2tr8OwoxbIuRt7TQ7hs2iSC5aTKQ07T/O3gMHN3LlLrt9kNjvrBmVTrEFMPaD3mNcFn 4eXCPg6idwTMTzF1CXAeHc4TXBrER95m0KdgyM935lyF5nKMYVIhrAqamXiBrjTEP3Cg SoNlHPDAIF8tiJ8oL90sPioW5EVAPaQYAgAhHwu+/DRRbVW4pETO22LpuKNto6xW9FHB jVvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=cFCUN8WX; 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=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r20si6370531ejc.678.2020.07.31.22.37.59; Fri, 31 Jul 2020 22:38:21 -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=pass header.i=@chromium.org header.s=google header.b=cFCUN8WX; 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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727933AbgHAFfR (ORCPT + 99 others); Sat, 1 Aug 2020 01:35:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48280 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726062AbgHAFfQ (ORCPT ); Sat, 1 Aug 2020 01:35:16 -0400 Received: from mail-pf1-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A710C061757 for ; Fri, 31 Jul 2020 22:35:16 -0700 (PDT) Received: by mail-pf1-x442.google.com with SMTP id j20so15484084pfe.5 for ; Fri, 31 Jul 2020 22:35:16 -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=sBcnbrjbFajVyHxfld/Fszj/ZWv73cYyddExdUQ2/uM=; b=cFCUN8WXYxpQmHqvnAsD23Rv5tXKfwQzwAyoxQ1/JYow58GgNyXFPX7XCri2QGRyOz fMUDsZUFNJ1c3ZWyB9hIi75jCK6E730XjbidYpIfiKW9JQgUuI+PdO+zmUr54szeh1Sp bAMamjFO4xz22zoSMDGpRAWZ5EifvoT6RMeQU= 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=sBcnbrjbFajVyHxfld/Fszj/ZWv73cYyddExdUQ2/uM=; b=JZI5zfDbvKpJ/YFA8wygM+zqIbqC7vGkaJIJ8lTAP7V2XoiWDWUwEbKEBY2tmUj/kd RTKF+CuiHChkmNDawUOQznU/vuLQzfePaQoNO2qM6qybodDTtscXZNGpYOSZxRV3MJG1 GwAYISAvdAOaINT1BstZaHnFS/qLY69mo8egSaKTqg0s+LkE2MaZZoDbOZZSPUUtr/IZ u9x9noUc0W/jFol83J9KLIuLKtCInYrowisp18+4WyOM2kZFs4GiGU3khAR/QG3suE+2 FcFZ7MV/AHoHXLAjSkJyQyOsT+L7aBF2VWNHMN03io2v0vfMPivBxldI9ynHwZQ5jjNF MKCA== X-Gm-Message-State: AOAM531CvtB+4AV5invfTadVEqKSY7uU6mqLNqA19cDkvabfGBllViwI sOCltMDSwOptGXEg9wKq1+cEJA== X-Received: by 2002:a62:164a:: with SMTP id 71mr6825401pfw.266.1596260115966; Fri, 31 Jul 2020 22:35:15 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id i21sm12412582pfa.18.2020.07.31.22.35.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jul 2020 22:35:15 -0700 (PDT) Date: Fri, 31 Jul 2020 22:35:14 -0700 From: Kees Cook To: Arvind Sankar Cc: 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: <202007312233.1BA0E2EFC@keescook> 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=us-ascii 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. I did not find that universally true. I found some sections be written out with a 0 size. Some I could remove from disk with NOLOAD, others did not like that so much. > 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. What do you mean about "only if it is first moved to the end"? Would it be zero-sized if it was closer to .text? -- Kees Cook