Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp73765pxa; Tue, 11 Aug 2020 17:46:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxnJWPobsME9xPqst1FTMdsNSn+b5TtVu6WDvtz6PIswYmyZRfVbq3IC//oP3KWoKWHIYbZ X-Received: by 2002:a17:906:248b:: with SMTP id e11mr28529293ejb.280.1597193204042; Tue, 11 Aug 2020 17:46:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597193204; cv=none; d=google.com; s=arc-20160816; b=cxR9h4N8HkV/FMC2LwXl8M5hWC3ZZ03HdxvqjBY/7puZmKTqShoiIiAQYOe0xqh6IK 6bAPfz3EEdml1t+tuVaTb+4Qps32ciImvI7X5CIY0jQv5BDePcC/1TY7hp4swKXmSeho 3PpRuM/UaUUKq9ZMBSSCdGT+OjGWkEMPuhLc0+/jJXwO1141c2Fwlr5ucDhS3jnLH95B ZXQWwKDwVcEOWw5GSq6UzMjNO74nrJ4jE0c3YiUTydXsunpy03BE/nWaPLD5ROK8Cq/V K0W16wzen2N9paGfsQtM5BBg5nnyVKMzeut3CpHsLzxqhBJ/V7nOiBtERnJfi9D4nKza 3vOg== 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=GCDImrRgW3iCWcpk2/WqD39sC7GwesCsUaBl58SFiQk=; b=GxHn3hX2IdmgMAwPBWt1tskNMZenh2T1Mmv77zbNLIvt07lG74l1XHuPJk3PkGToQw Q24Y4VPNT3vr3eIvs+0OnLaVShtbrgB1nZS02k5tc/5je6H6UKF6hguoWgcFPqP/cnEL evzWBq+ZXLxR0Hrpv9luFkt2jdetfsqVb2wHwRJwR4f+/GnuZEQx5R2oyxxn3O4mbhVe EQLu50ilgRJTl6Ri1eEA1Hgnsd5CCQ+5YsYl3HpUQRhZ8AeQqYHe6PhodsZQ8XYqCFC3 ih1PBEVJ9UBBDgd/Ceefzud0frxVeAO8IhsBRTVKUJrL5emVuq8gKlHBHyNcnWgq6C3D 9COw== 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 q8si143899ejm.507.2020.08.11.17.46.21; Tue, 11 Aug 2020 17:46:44 -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 S1726468AbgHLAnL (ORCPT + 99 others); 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-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