Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp420873pxa; Fri, 31 Jul 2020 16:10:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzHXMVlEyRU442bj2w53SkiYeXFz3IP5ownKIPadttI/zQyuIZrabLhpIG6gAQ6y+K5BX+v X-Received: by 2002:a17:906:d7b1:: with SMTP id pk17mr6275827ejb.554.1596237003875; Fri, 31 Jul 2020 16:10:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596237003; cv=none; d=google.com; s=arc-20160816; b=Z9NOBKMNdPWPhM/HDcLylw/VohnAtse34/fZiIQMv4GrNLJLCr726XZmwjhteOXdSv kFf+7MT1mTGqZh19LmLaVH5g4nX+dEKQhHVUdXbkob0uavphJOrT+01S1auYOqOoSjsW jWr2X8Cq3mmGzmnae7il4nZgnzJjGLI6ZqluH/vC8T1LIJ8srv6zTyqJynWpLyRuKgGr g4Z1DYD2nFZvtZq+Z5M3LEjcTlS8p13KRcarqpn5uA5FOAax1iLiZi2+JBCLBamqgPpJ DzAx+9zrYedYzR8I/23GeNglvSsgyEg2Dj1y5OQw5B0XUYR29Yk1xUoqSeEhOeTpb/nN jVag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=jrAblmr6ozIS72tPylywn6+f+xtS4UhaP8bWtW4yv24=; b=VjigP+P6fn8UA2PhFb7d24N5D/GuwQI0ikdHqTwotYHbGVXB7TJAolCmtbWa6VtuWB pGZeUeCaWUsb9MmBM5Ub4FpxuAnUiu/7BPZzs/r9Gw0pz7z0x+xPtuc/SZkRkKD2gYGH Q84r/0eYB4xsCaj7bFclRVEkuWRdQhpUufvbm3BIhSONUHbojTcsb9p1dS+E2dOZnNT2 50xSOBSSzA84pU8bpGdhB39td1N5S31HE31eIVC69s+qzipnW8OBeaDebMOLq5KGu0J9 3y6vvu7TxDrU/vVisrLDcRiqEK3DkZYTOpyHInI5kGl+Ud9+IX8Ii6hcpyVgaSQdWx+r 60vw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="dE/Lv+CU"; 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 q22si5478153edr.317.2020.07.31.16.09.41; Fri, 31 Jul 2020 16:10:03 -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="dE/Lv+CU"; 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 S1727957AbgGaXJJ (ORCPT + 99 others); Fri, 31 Jul 2020 19:09:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727961AbgGaXIt (ORCPT ); Fri, 31 Jul 2020 19:08:49 -0400 Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 57D53C0617B1 for ; Fri, 31 Jul 2020 16:08:49 -0700 (PDT) Received: by mail-pf1-x444.google.com with SMTP id f193so4771271pfa.12 for ; Fri, 31 Jul 2020 16:08:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jrAblmr6ozIS72tPylywn6+f+xtS4UhaP8bWtW4yv24=; b=dE/Lv+CUA/T7hFTSyS/prDIBwKu/ji5fc0y2Bvs2zCPUa36aaYuKYtGCWE1TiPc+U5 VmeZKoRZYCjcKC45iW2ezGMhW8mV6FXFni0hFNHu5kzRpTCuDIkn88ZAPH+X6Su8OTPX dsyMxubhpOlOMQIDeQNqP4d+u9LhnVaPCznvQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jrAblmr6ozIS72tPylywn6+f+xtS4UhaP8bWtW4yv24=; b=c1fLnpy+F+la7l7LVvu/Ez6VoMWm4Mh7pw5iOyJHvJw1pGitqHBmyJ/yWeXKkrqheb c/ZktZYuspMXOcZOXdvDf5C4ZRVOV01BBYBCDGJ4I6lNIF5K/dQbGyzPLJIlEDaIxbLs 40PeUPF8Q/0X2cFPn0zGAfL5NtusUAEEox0qS7m0nigN8phm9G6PF2J47ImowJVjJYIK RBJtlctcB+U6RVbpJXNUhIf7xb6DdACNJL3JTjKhl6roGK6iFa2UeZGOgDWt9enHSSvC 8Pz994ucIoDjrKte1yL2WqHpyA28bIxBoCnMJ5oNk6Ho9olsjTpyn0afE+IkAdiXBGrV Bx/g== X-Gm-Message-State: AOAM5316dQWAYrDh4HkSLd7W6oL9JNlbwmNaIay5L1Ste9hFPftk0lyc nRygknh4HeKyRTmNnOyFXHowVw== X-Received: by 2002:a62:6083:: with SMTP id u125mr5816247pfb.286.1596236928921; Fri, 31 Jul 2020 16:08:48 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id k4sm7192916pjg.48.2020.07.31.16.08.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jul 2020 16:08:44 -0700 (PDT) From: Kees Cook To: Thomas Gleixner , Will Deacon Cc: Kees Cook , Catalin Marinas , Mark Rutland , Ard Biesheuvel , Peter Collingbourne , James Morse , Borislav Petkov , Ingo Molnar , Russell King , Masahiro Yamada , Arvind Sankar , 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: [PATCH v5 32/36] x86/boot/compressed: Reorganize zero-size section asserts Date: Fri, 31 Jul 2020 16:08:16 -0700 Message-Id: <20200731230820.1742553-33-keescook@chromium.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200731230820.1742553-1-keescook@chromium.org> References: <20200731230820.1742553-1-keescook@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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