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=HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham 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 8BBE4C433E2 for ; Mon, 29 Jun 2020 18:58:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7C45E2067D for ; Mon, 29 Jun 2020 18:58:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730218AbgF2S6G (ORCPT ); Mon, 29 Jun 2020 14:58:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730144AbgF2S5o (ORCPT ); Mon, 29 Jun 2020 14:57:44 -0400 Received: from mail-qt1-x841.google.com (mail-qt1-x841.google.com [IPv6:2607:f8b0:4864:20::841]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F0FFC02E2E0 for ; Mon, 29 Jun 2020 07:09:33 -0700 (PDT) Received: by mail-qt1-x841.google.com with SMTP id x62so12905359qtd.3 for ; Mon, 29 Jun 2020 07:09:33 -0700 (PDT) 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=tEZERuD4U9x45d3XL5Tb2EKEgqxOltAsxA1Ga9THj/Q=; b=kN62gCu1h1hmiwF5cULW4dme5DEZe6ff82I0RoZQQQecmAJdU0HankVMWbaRz8ad2E 54H+tr8eUi+jr6HRFqt3uop0WkF86gl6xL9H+tXhbUd0plogLpGWr4vHprlphSzN/R47 FPVahVX55X/dzsLbK1EqypoRri1yF7/PnZaGNq4LxSMY4oyhpvcQDQS5lvzyelBxrUJZ kF6co4HOmwRHu+1Wk9JjN6gZqVhffePr5xgi0ZKab4Ryr2PS+uRSoW36yUUYv3lBIgBg 7cnnBAb1BAxogdjt+n8Xy7mPF+15DNUwhLuHsssFYhuwfYgaXMOdBwrODlKqkJvl7m3k y1TA== X-Gm-Message-State: AOAM533n56sjJ4zQftf3+4wj7MQtNOSyyxuAEucep3pkzBcxf5foqaCi 73Efj91s8Rvn2Q+u8/ixBvw= X-Google-Smtp-Source: ABdhPJxKVYmAwxmHAwz6aSqzYJnqE6ZSLC25nGL860MCT/f/BlRph9L2xC5X8TXsetqrzvLN3xx9eQ== X-Received: by 2002:ac8:7284:: with SMTP id v4mr16251160qto.267.1593439772367; Mon, 29 Jun 2020 07:09:32 -0700 (PDT) Received: from rani.riverdale.lan ([2001:470:1f07:5f3::b55f]) by smtp.gmail.com with ESMTPSA id i26sm10741461qkh.14.2020.06.29.07.09.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jun 2020 07:09:32 -0700 (PDT) From: Arvind Sankar To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , x86@kernel.org Cc: Nick Desaulniers , Fangrui Song , Dmitry Golovin , clang-built-linux@googlegroups.com, Ard Biesheuvel , Masahiro Yamada , Daniel Kiper , Sedat Dilek , Kees Cook , Nathan Chancellor , Arnd Bergmann , "H . J . Lu" , linux-kernel@vger.kernel.org Subject: [PATCH v3 2/7] x86/boot/compressed: Force hidden visibility for all symbol references Date: Mon, 29 Jun 2020 10:09:23 -0400 Message-Id: <20200629140928.858507-3-nivedita@alum.mit.edu> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200629140928.858507-1-nivedita@alum.mit.edu> References: <20200629140928.858507-1-nivedita@alum.mit.edu> 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 From: Ard Biesheuvel Eliminate all GOT entries in the decompressor binary, by forcing hidden visibility for all symbol references, which informs the compiler that such references will be resolved at link time without the need for allocating GOT entries. To ensure that no GOT entries will creep back in, add an assertion to the decompressor linker script that will fire if the .got section has a non-zero size. [Arvind: fixup -include hidden.h to -include $(srctree)/$(src)/hidden.h] Signed-off-by: Ard Biesheuvel Acked-by: Arvind Sankar Signed-off-by: Arvind Sankar From: Ard Biesheuvel Link: https://lore.kernel.org/r/20200523120021.34996-3-ardb@kernel.org --- arch/x86/boot/compressed/Makefile | 1 + arch/x86/boot/compressed/hidden.h | 19 +++++++++++++++++++ arch/x86/boot/compressed/vmlinux.lds.S | 1 + 3 files changed, 21 insertions(+) create mode 100644 arch/x86/boot/compressed/hidden.h diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile index 7619742f91c9..b01c8aed0f23 100644 --- a/arch/x86/boot/compressed/Makefile +++ b/arch/x86/boot/compressed/Makefile @@ -42,6 +42,7 @@ KBUILD_CFLAGS += $(call cc-disable-warning, gnu) KBUILD_CFLAGS += -Wno-pointer-sign KBUILD_CFLAGS += $(call cc-option,-fmacro-prefix-map=$(srctree)/=) KBUILD_CFLAGS += -fno-asynchronous-unwind-tables +KBUILD_CFLAGS += -include $(srctree)/$(src)/hidden.h KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__ GCOV_PROFILE := n diff --git a/arch/x86/boot/compressed/hidden.h b/arch/x86/boot/compressed/hidden.h new file mode 100644 index 000000000000..49a17b6b5962 --- /dev/null +++ b/arch/x86/boot/compressed/hidden.h @@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * When building position independent code with GCC using the -fPIC option, + * (or even the -fPIE one on older versions), it will assume that we are + * building a dynamic object (either a shared library or an executable) that + * may have symbol references that can only be resolved at load time. For a + * variety of reasons (ELF symbol preemption, the CoW footprint of the section + * that is modified by the loader), this results in all references to symbols + * with external linkage to go via entries in the Global Offset Table (GOT), + * which carries absolute addresses which need to be fixed up when the + * executable image is loaded at an offset which is different from its link + * time offset. + * + * Fortunately, there is a way to inform the compiler that such symbol + * references will be satisfied at link time rather than at load time, by + * giving them 'hidden' visibility. + */ + +#pragma GCC visibility push(hidden) diff --git a/arch/x86/boot/compressed/vmlinux.lds.S b/arch/x86/boot/compressed/vmlinux.lds.S index b17d218ccdf9..4bcc943842ab 100644 --- a/arch/x86/boot/compressed/vmlinux.lds.S +++ b/arch/x86/boot/compressed/vmlinux.lds.S @@ -81,6 +81,7 @@ SECTIONS 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 -- 2.26.2