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,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 E5AE0C433DF for ; Sat, 1 Aug 2020 17:03:05 +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 B2AA5206E9 for ; Sat, 1 Aug 2020 17:03:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="mwA8ltdt"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="nUZWj8j7" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B2AA5206E9 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=alum.mit.edu 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:Date:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=mb8PJ8Xk66d8MUyL8E/JM420FUkPB5MhBMwJzFPZ+Lc=; b=mwA8ltdtE4/egM4C6Hy/QA8Ed YJKOHD9P1jdDyhKNfdkZh7/rs/HSN5grv7xLEsWi5j1HAIdR4s28SNY3uE3v9boXuwxlEBGTKHlWD EitYmz1uF7VlLgFN0woFVcWQdR3jAp7Rg8WcbLhuWEQachDWsBIVTnC0ZcgmGBiF/eNSbxzUrsTAj hne1bZkqrr9r/0R8ztnP15Qw5g/fwc0DP2wujlXZOILuZsn+WPyt1Jwgs/bvSNsJL5LtAHb76YkLr vfN1dPyi0ZOpLJxLXYDxEQgRtwWMV0GJurdnNfpwvsz4yeFCUqHwVKqqZp9r/v85ulnv1VxtLwU5/ bf9keTIjQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1k1usU-0003Ft-C7; Sat, 01 Aug 2020 17:00:58 +0000 Received: from mail-qk1-x741.google.com ([2607:f8b0:4864:20::741]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1k1usQ-0003Ef-O5 for linux-arm-kernel@lists.infradead.org; Sat, 01 Aug 2020 17:00:56 +0000 Received: by mail-qk1-x741.google.com with SMTP id l64so24926254qkb.8 for ; Sat, 01 Aug 2020 10:00:54 -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=mJ6hTZT24AWhGEqcPC20wN8kBdsxrLI/peNCFh80II0=; b=nUZWj8j7d2X5T3sH7PVKVcJ/tJMEQcJ4psgs1gcLJol13d1RvdpJ4+3wBuHldXvZBk SjZOvjpj18wRh7IwgoW/w72o85g6VIRQqsdhKjeIodtrCeem5YngLBL+85bAezTuvvQ9 gEA47e7rp1XiVJR6GxAXnZ2zwYbpQ+pT01pVgaUCkcAdJldxGCrlhU5wzfAzTNrVtyoU 4P/Sa+lAMZnq3EELOqy7A33g+g3Vfw0ZCcJ8dsIqesEfsByzZ6GVh9zuW/kiQbWuhoYR vFRgJxZpHOWpv2hrariGEk0FnyOTVNVtkFKl2PLFAHHG4yf9tW71qTdizyL74bOdX69I 0Ttw== 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=mJ6hTZT24AWhGEqcPC20wN8kBdsxrLI/peNCFh80II0=; b=lAjOJfUErHS6ObFJa46SzCQbPUP9xwcRZ+lK99avf5q1MRObqdJi2rVnjlNDCELYMy LE2/+epElO60v8EHVk+uIW6lj1JGOBU7XDzG8PLxyNCLseDf+hyZEt9lQSLi04aVlW5X 0W0SjtUXS23yx/HGE5fiL34Beqj+LmgOzP7mIyRkwQyNGDJrthwB8ZY4RAFh6RtRV7Sb 4kK83Dy9CcqQsx0d93LqG4S1ZWi4MAiyFT7JDBqpkYEbcFeLlFKURQoF16tg1E6k4LOY Z9dgCTGUqaLIbl4F12TmSVPfJLqFvXPsj1vn8lKhyZqSWZEP4SbTxWAsCqYBdgDwjsg3 /mHQ== X-Gm-Message-State: AOAM531uGRXd33ldOQFiu03PbEsf1XUEcB5iySYZRgJDEfamqCw+tWKF NaCYEoEI6bM95JxB+jgQJ9U= X-Google-Smtp-Source: ABdhPJzCKZ2YWRRKt7EbAjYlMwe4HoJyEC/wkWrDWjL843q2i/oFkciOE/2KezdZ9h6RIJbu6Yv/dQ== X-Received: by 2002:a37:aa56:: with SMTP id t83mr9283794qke.150.1596301252633; Sat, 01 Aug 2020 10:00:52 -0700 (PDT) Received: from rani.riverdale.lan ([2001:470:1f07:5f3::b55f]) by smtp.gmail.com with ESMTPSA id m26sm14886142qtc.83.2020.08.01.10.00.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Aug 2020 10:00:51 -0700 (PDT) From: Arvind Sankar X-Google-Original-From: Arvind Sankar Date: Sat, 1 Aug 2020 13:00:49 -0400 To: Kees Cook Subject: Re: [PATCH v5 32/36] x86/boot/compressed: Reorganize zero-size section asserts Message-ID: <20200801170049.GA3249534@rani.riverdale.lan> References: <20200731230820.1742553-1-keescook@chromium.org> <20200731230820.1742553-33-keescook@chromium.org> <20200801014755.GA2700342@rani.riverdale.lan> <202007312233.1BA0E2EFC@keescook> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <202007312233.1BA0E2EFC@keescook> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200801_130054_830430_E6E62FD2 X-CRM114-Status: GOOD ( 33.95 ) 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, Arvind Sankar , 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:35:14PM -0700, Kees Cook 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. > > 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. Neither LLD nor BFD is creating 0-sized .got or .rel sections in my builds. In any case, if they're 0-sized, NOLOAD shouldn't affect anything: it doesn't remove them from disk, it stops them being loaded into memory, which is a nop if it was 0-sized. > > > 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 Sorry, my sentence is confusingly worded: it's always non-empty on x86-32. I meant, move .got.plt to the end (after _end), add (INFO) to it, and it might save a few bytes, or not, depending on alignment padding. If it's left in the middle, it still pushes the addresses of the remaining sections out, so it doesn't save anything. I'd tested that out the last time we talked about this, but left it out of my series as Fangrui was negative about the idea. I tested with NOLOAD instead of INFO, and at least ld.bfd actually errors out if .got.plt is marked NOLOAD, no matter where it's located. LDS arch/x86/boot/compressed/vmlinux.lds LD arch/x86/boot/compressed/vmlinux ld: final link failed: section has no contents Side note: I also discovered something peculiar with the gcc/lld combo. On x86-64, it turns out that this still generates a .got.plt section, which was unexpected as _GLOBAL_OFFSET_TABLE_ shouldn't be referenced on 64-bit. It turns out that when gcc (or even clang) generates an out-of-line call to memcpy from a __builtin_memcpy call, it doesn't declare the memcpy as hidden even with Ard's hidden.h, or even if memcpy was explicitly declared with hidden visibility. It uses memcpy@PLT instead of memcpy, and this generates a reference to _GLOBAL_OFFSET_TABLE_ in the .o file. The linker later converts this to a direct call to the function, but LLD leaves .got.plt in the executable, while BFD strips it out. It also turns out that clang's integrated assembler, unlike gas, does not generate a reference to _GLOBAL_OFFSET_TABLE for a foo@PLT call. And because we redefine KBUILD_CFLAGS in boot/compressed Makefile, we lose the -no-integrated-as option, and clang is using its integrated assembler when building the compressed kernel. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel