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=-18.0 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 5DEC3C433DF for ; Wed, 12 Aug 2020 00:43:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 456412080C for ; Wed, 12 Aug 2020 00:43:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726474AbgHLAnL (ORCPT ); Tue, 11 Aug 2020 20:43:11 -0400 Received: from mail-qk1-f193.google.com ([209.85.222.193]:33579 "EHLO mail-qk1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726143AbgHLAnL (ORCPT ); Tue, 11 Aug 2020 20:43:11 -0400 Received: by mail-qk1-f193.google.com with SMTP id p4so685734qkf.0; Tue, 11 Aug 2020 17:43:10 -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=GCDImrRgW3iCWcpk2/WqD39sC7GwesCsUaBl58SFiQk=; b=PoH0BzxBnfdXZMDSBo6OEj5QWb5mst9LLE7YPEqOCButpr32c+Q0LmGFoAmlTfvTNT lQFEqqjKUs2Xm5chKOoYo/qFRYYejqoNIdCzmcEOsoZ5LkP6Np4/lQFsFRiiZNLSftWO uLsERcWu8zG+fSJrTVD6F1Bob/8isnTfyJ31uxLco/YVSmC/yvSTWIlDBs6gUzPru557 sy7WQS26f7JzNAgoReH2LX1OmYZulLvFqJFoAqHNerzh6JuUSxoH44fi+yG6FwCmtOGn 4dcEIHISfbKEdNaMOy59zNVppto4rqhgpklN5UwSz8jDiCQbhgBG5A/m/kmNjMk3hHSz yrmQ== X-Gm-Message-State: AOAM532MxVBnByZGPyQ0hTIJYGHDWltSVpUzqrkq2v5piWQe0sxx2OxV wnPG8tIq/ZoSwz/1oiM+IZQ= X-Google-Smtp-Source: ABdhPJzw++bT0HF3bP2CRKw/mU0GoHv5y3se5aR+Iut3/cRRo4mbJTF32+0nEvHbyQxtm+Wq5sUNtw== X-Received: by 2002:a37:a354:: with SMTP id m81mr3762457qke.277.1597192989829; Tue, 11 Aug 2020 17:43:09 -0700 (PDT) Received: from rani.riverdale.lan ([2001:470:1f07:5f3::b55f]) by smtp.gmail.com with ESMTPSA id x13sm549749qts.23.2020.08.11.17.43.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Aug 2020 17:43:09 -0700 (PDT) From: Arvind Sankar To: Nick Desaulniers Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Fangrui Song , clang-built-linux , e5ten.arch@gmail.com, "maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" , "H. Peter Anvin" , Masahiro Yamada , Ard Biesheuvel , Kees Cook , LKML , stable@vger.kernel.org Subject: [PATCH v2] x86/boot/compressed: Disable relocation relaxation Date: Tue, 11 Aug 2020 20:43:08 -0400 Message-Id: <20200812004308.1448603-1-nivedita@alum.mit.edu> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200812004158.GA1447296@rani.riverdale.lan> References: <20200812004158.GA1447296@rani.riverdale.lan> 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 The x86-64 psABI [0] specifies special relocation types (R_X86_64_[REX_]GOTPCRELX) for indirection through the Global Offset Table, semantically equivalent to R_X86_64_GOTPCREL, which the linker can take advantage of for optimization (relaxation) at link time. This is supported by LLD and binutils versions 2.26 onwards. The compressed kernel is position-independent code, however, when using LLD or binutils versions before 2.27, it must be linked without the -pie option. In this case, the linker may optimize certain instructions into a non-position-independent form, by converting foo@GOTPCREL(%rip) to $foo. This potential issue has been present with LLD and binutils-2.26 for a long time, but it has never manifested itself before now: - LLD and binutils-2.26 only relax movq foo@GOTPCREL(%rip), %reg to leaq foo(%rip), %reg which is still position-independent, rather than mov $foo, %reg which is permitted by the psABI when -pie is not enabled. - gcc happens to only generate GOTPCREL relocations on mov instructions. - clang does generate GOTPCREL relocations on non-mov instructions, but when building the compressed kernel, it uses its integrated assembler (due to the redefinition of KBUILD_CFLAGS dropping -no-integrated-as), which has so far defaulted to not generating the GOTPCRELX relocations. Nick Desaulniers reports [1,2]: A recent change [3] to a default value of configuration variable (ENABLE_X86_RELAX_RELOCATIONS OFF -> ON) in LLVM now causes Clang's integrated assembler to emit R_X86_64_GOTPCRELX/R_X86_64_REX_GOTPCRELX relocations. LLD will relax instructions with these relocations based on whether the image is being linked as position independent or not. When not, then LLD will relax these instructions to use absolute addressing mode (R_RELAX_GOT_PC_NOPIC). This causes kernels built with Clang and linked with LLD to fail to boot. Patch series [4] is a solution to allow the compressed kernel to be linked with -pie unconditionally, but even if merged is unlikely to be backported. As a simple solution that can be applied to stable as well, prevent the assembler from generating the relaxed relocation types using the -mrelax-relocations=no option. For ease of backporting, do this unconditionally. [0] https://gitlab.com/x86-psABIs/x86-64-ABI/-/blob/master/x86-64-ABI/linker-optimization.tex#L65 [1] https://lore.kernel.org/lkml/20200807194100.3570838-1-ndesaulniers@google.com/ [2] https://github.com/ClangBuiltLinux/linux/issues/1121 [3] https://reviews.llvm.org/rGc41a18cf61790fc898dcda1055c3efbf442c14c0 [4] https://lore.kernel.org/lkml/20200731202738.2577854-1-nivedita@alum.mit.edu/ Signed-off-by: Arvind Sankar Reported-by: Nick Desaulniers Reviewed-by: Nick Desaulniers Tested-by: Nick Desaulniers Cc: stable@vger.kernel.org Signed-off-by: Arvind Sankar --- arch/x86/boot/compressed/Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile index 3962f592633d..ff7894f39e0e 100644 --- a/arch/x86/boot/compressed/Makefile +++ b/arch/x86/boot/compressed/Makefile @@ -43,6 +43,8 @@ KBUILD_CFLAGS += -Wno-pointer-sign KBUILD_CFLAGS += $(call cc-option,-fmacro-prefix-map=$(srctree)/=) KBUILD_CFLAGS += -fno-asynchronous-unwind-tables KBUILD_CFLAGS += -D__DISABLE_EXPORTS +# Disable relocation relaxation in case the link is not PIE. +KBUILD_CFLAGS += $(call as-option,-Wa$(comma)-mrelax-relocations=no) KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__ GCOV_PROFILE := n -- 2.26.2