Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp2978719ybt; Mon, 29 Jun 2020 12:00:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzv3GXDr6cTOC2k7XTHz9JGkHeS4tg5WjPP/dmgFlpWUmc5AQt6bqoQFxsf0MDWCiOSdC87 X-Received: by 2002:a50:8e53:: with SMTP id 19mr1773808edx.185.1593457231870; Mon, 29 Jun 2020 12:00:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593457231; cv=none; d=google.com; s=arc-20160816; b=QaWIR0npFWMetbopDnRjaCWTTmzudH16e6E4FhNU/p20JUeyuv0gxTzzQeYrcbS3e2 049nIayWT4sh5mQYXBrdDyyBejeDzrjqqm8u7htYrrfpmActM+g7Aa65ccElnWZqtVkf 0occd7FQPx9K6cRh2FWwrG2583180B4iS4kCqUYz6kAZvk11RTm0wyL5A/1KOQ3vzCZR /yUNa6jcitnx7OVJ35VJC8KYR4wRx0AfTmVQHw0DB7LPnonBc+wTsVM1NmsQ4qOvlRZ3 utLmgOKIXtTgJW6ZYfCDB1Yz1eDCPLjN9lXrvxwn+bH2tLqnbO9afxD7E1jK2ooSHdBo F0ug== 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; bh=tEZERuD4U9x45d3XL5Tb2EKEgqxOltAsxA1Ga9THj/Q=; b=CHNvt9mnMKpbu1S9uCBJa+1BjBWZHONJ+5OIg538p7qTv6eZk+XCuMk7Fa2AdL3XdJ 1rb7q+U+rT7N0EWE5RvDoghDR6/1vcXEE/6bsoDv9+TmEUY1aZ44mdbQaLO/TBY3ah0g 1KBIwKiDQzjNeyhFAYVChnkjHWq0UUxFzYt0kJAgDaeWUq2yRAbfdyZmOO6Akcw8ee5K AUXsNZFLVBya7Uu80Bs+iq5r8fe9s8Z4r71l9WmGWrjoMaGg9sa724pfxnTbNuJqDsmn UUCvN52eY8O3LNuJuymO0UZcosH0DQhxPD+nfXsiEN2xKVj++H4FOtLkp8j5VI7PY/+v pcBA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d6si212961eds.492.2020.06.29.12.00.08; Mon, 29 Jun 2020 12:00:31 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730216AbgF2S6F (ORCPT + 99 others); Mon, 29 Jun 2020 14:58:05 -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-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