Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp581647pxa; Fri, 31 Jul 2020 22:39:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwyspvvQRgyQe3qguLgVHG0TBF7aeO2W2LstdPPDTFEFMpOUzt0hAtBzdAIUvzVtJ7Rge0Z X-Received: by 2002:a17:906:925a:: with SMTP id c26mr7057428ejx.121.1596260352130; Fri, 31 Jul 2020 22:39:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596260352; cv=none; d=google.com; s=arc-20160816; b=tIaYKgEGDjcY8nHOxv4kLHBCx21habJ2PM6VBOh8dYcvlwDLHRVHxAmPsb28YpYZVS 4VKSrPFnvsBccba0We1zV1nQvUjAqNDR6hfh63jw69k14QIRj7ltoFBKJfpVKpFQgj4y O/fNtQ1d4C9ddl0l4EX+/ihH3SBczSMtaCGRhNy+oK4B68bfsA9bGqQnwniY45XYbOEm w9sCAdsLgIhECjcDi/3OOEHiEwnKd1tIJytD2b+4IoeUo3zuTwVIi20LNUmnXJp2MjYC JQPwAmYtE+fe2X+Y9jZIslQ3nhUiQL2L480vSnYj67dn8Tz5Abe9/1qybfFHq+OcUCjM K21g== 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=TiksbxZAq651HXyzgXud8H+oOdlAwciZhMVaJuNaJO0=; b=kstPEfY+u5wtj2j8lBeK1YAPP0HTfHdmPsHD0ZGOXBieYTIWppMOfRWMqLLQcOd4xR MfCI+xo0JJ6oyl0RiuOhgf28DZzHzjTLj5XnBJJrR88XDF0KpieUQ/rtQKRwByu2GVvE 8TeOXhrmO4nEdpAusGswnMJLwSxKs5D4RNOfKnbWltgKgnE1UVNBoUYd0zK0d14mcxUb 2a/GAkgIVURltzjnAAyr7w3eXVLX63HEIJE5NaT9rZQTsLFpR1zzPjm0eUSs0nn4U56K IAkUy/v6eE4OEJbS4phxAZO1ogXKCju+Fm1sylta0Qs+qarWwaxb0089mrSYhMTJ6kNi vH5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="fM/bL01w"; 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 s9si2542766edh.16.2020.07.31.22.38.50; Fri, 31 Jul 2020 22:39:12 -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="fM/bL01w"; 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 S1727024AbgHAFgD (ORCPT + 99 others); Sat, 1 Aug 2020 01:36:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48406 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726187AbgHAFgC (ORCPT ); Sat, 1 Aug 2020 01:36:02 -0400 Received: from mail-pj1-x1042.google.com (mail-pj1-x1042.google.com [IPv6:2607:f8b0:4864:20::1042]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D954DC061757 for ; Fri, 31 Jul 2020 22:36:02 -0700 (PDT) Received: by mail-pj1-x1042.google.com with SMTP id mt12so8339355pjb.4 for ; Fri, 31 Jul 2020 22:36:02 -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=K4Sfwhh3jADG25/JDC2IxUtW+4wzYncSn0woJTlD7Ij5OrUHq/EUmOxVxVOzfnKkDX ZQCdm5TWZNTeiGgfvDldwVuBbO6MYF/pfusbgZRReia1UzlDvRDdAEfkEY1uB6xlvvh0 /PNLx0TCBOeg1ModT0VW8ubmDLHv7Sj9TXMCGmyHHa6hIUBXSO8DLvKNLYQ//RpEglON Dyb85RSoG0UuvOgQm0zWabqKEjv9RvpC5GB1OHICO0jpAudlXQfgylhIyfoynxH4f2Ge CaYlXs5e/YO7bAL9eYazfCDVyN+bUWptW/PGd9wCvJf6fzejF/o7uwvdBwGHu32NI0vS 4dLQ== X-Gm-Message-State: AOAM531A5xoHQsOKlcPE8Piiy2QvLbcd1FlgaPP1vsRBJRcMbsZ52d7b vphdydFrTVaqpqYtIXyqkO07o6Kx2ug= 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 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: <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-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200801025325.GA2800311@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 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