Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp627440pxa; Tue, 11 Aug 2020 10:59:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwc5+kuDgRNie03/eRiPgBiSb10/wNxI/vvgWerHfgGzko5CLOc0lYzSJ9OD4koAqIaLwqf X-Received: by 2002:a17:906:aed4:: with SMTP id me20mr28844277ejb.141.1597168785528; Tue, 11 Aug 2020 10:59:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597168785; cv=none; d=google.com; s=arc-20160816; b=zVt1dwgud2g0UccXBoYE5k5kMf3XfJfhi2iophjkUmIufIan1qDNPHwL2J9PzUk8gb +sPKa1tqv1mAmxJN+9dHKoRwMGSCu3J7FkNL9fIIBKvsJYUA9VVCZaS+2vwjk/BR4Cvr pAF12ljJBlcwbQIsRSSBqXiWoBjArNCdoyDuWzEIprtBu2SLEUUB8CpY4cVt2acpyguA fkXxTY/XYWUa4pYTNrd9WHbni7ATFVafgTFJqhxDn/y+7HbbIYsNF7M23IP6wSbnuic1 TTAIdFlfSgEeW01SKcFf88oY+cYc3i47qSu2DygYunpo1men1uoAMIcipQNZh07edjbW g77A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=PwLucdZe8Zl1sdg+rBs5gzd1/sOQ/Nnh9Dc69W2ZlPY=; b=ldtBWfv0Ey4V2UADb54Hnh3Ov07wCKYvhif/Zij2G3IQeMefe2RWRxR/hi64wZzK8O fmnh+8UhSplRiiglzNBr1Dp03pLGUIXRQQpCtLT1V80Nc31Ovl8GeN3gXyhvvUpnC0xK eKlDfb/dQ4MXQwXtaT2y5ueGEPL289lilQ65PcvmfaZXfT0+9UccurxNby4CfJlafJPb zpzlg2RjlzS26VkfWbdFxDoLAXZFyqdjx9/8+hijNrk1G4WXfySpqp2SGu3Laq+Zv3Qy 89vcfKHJducghY6ueTk3ERxDtTqat2igCK2x/vuHZl+NlCtM9zqM+n3jXCDVuVhZVFBC yHiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=hppMyx4Q; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b2si9068838ejk.222.2020.08.11.10.59.20; Tue, 11 Aug 2020 10:59:45 -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=@google.com header.s=20161025 header.b=hppMyx4Q; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726089AbgHKR6y (ORCPT + 99 others); Tue, 11 Aug 2020 13:58:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725889AbgHKR6w (ORCPT ); Tue, 11 Aug 2020 13:58:52 -0400 Received: from mail-pl1-x641.google.com (mail-pl1-x641.google.com [IPv6:2607:f8b0:4864:20::641]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2924FC061788 for ; Tue, 11 Aug 2020 10:58:52 -0700 (PDT) Received: by mail-pl1-x641.google.com with SMTP id k13so7152193plk.13 for ; Tue, 11 Aug 2020 10:58:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=PwLucdZe8Zl1sdg+rBs5gzd1/sOQ/Nnh9Dc69W2ZlPY=; b=hppMyx4QKg2UJb3qxcOpI1jplSB7I/4IFRBebdNFDIqOIqmv+o7ixbitDdJGq3vcUG /KLrDrbfIybVPxf4/FXQdluXL88QfJ4XeHlgDSolu6c9dhZgMa2k/A4bIO1QoVD7GpgV Xwf3wYgXY3X/aoeA7y5BvM3uCAnmjfQ6O8cf/kfy+Jutrx4PW4ESll6hVdsA6UBh8a9o HzLpmRdRsGUmK5Tgd0bGDdJBTbblNpmqczmsB0ax2StXBX0bj9yxckMDjNwn4O119Kqj 5QrM6y8TkZa3EXfv60POSf2PJEcWYUpNGyED/o7RYz4ryhrU01nYUgmZDFGPDTj1Clfs Oy6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=PwLucdZe8Zl1sdg+rBs5gzd1/sOQ/Nnh9Dc69W2ZlPY=; b=DJmQAMAQf4BIghPFztv9AOPvbZeUDTPuWdxDGOalTetzcPKw9Tdsd5sRjXHhbShFNM LRECmYFTXGrhg3BOaOWlspOAO9NGWdVMntzEf/8Z/Kng34qEoltWDw9b4Phta9c+uC4Q iGP4fZVEvZb+VAnQnk2ZTa2OsTNS7C0HNUBHjHzV1MDmMb5JEAup3Mqz+XEYoMyHlQB7 umX9Bv36bh9tpe5Uk1rWtXdpYCdeJf1vD6+lTHIdA5PdHgKQpWK584SI/YFXnGhN9qi4 jKjl87/VnzKT+c317iqbjJ7UsVzg1OHHn1HIpC+p9FfIQvj9V+3wzvy4CZ1W2M6I2ze0 Uc0w== X-Gm-Message-State: AOAM533gX3XuBXGNm63ig28Q5YEnZllhXafczF5W9ZwgbbngDOEj+X6y jFxIfYH6/LWLQ0Pf8/MPUO8ZyaMYIp68OtKJGljlZw== X-Received: by 2002:a17:90a:a10c:: with SMTP id s12mr2287166pjp.32.1597168731165; Tue, 11 Aug 2020 10:58:51 -0700 (PDT) MIME-Version: 1.0 References: <20200811173655.1162093-1-nivedita@alum.mit.edu> In-Reply-To: <20200811173655.1162093-1-nivedita@alum.mit.edu> From: Nick Desaulniers Date: Tue, 11 Aug 2020 10:58:40 -0700 Message-ID: Subject: Re: [PATCH] x86/boot/compressed: Disable relocation relaxation for non-pie link To: Arvind Sankar 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 , "# 3.4.x" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Aug 11, 2020 at 10:36 AM Arvind Sankar wrote: > > 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. > > [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 # 4.19.x Thanks Arvind, good write up. Just curious about this stable tag, how come you picked 4.19? I can see boot failures in our CI for x86+LLD back to 4.9. Can we amend that tag to use `# 4.9`? I'd be happy to help submit backports should they fail to apply cleanly. https://travis-ci.com/github/ClangBuiltLinux/continuous-integration/builds/179237488 > --- > arch/x86/boot/compressed/Makefile | 6 ++++++ > 1 file changed, 6 insertions(+) > > diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile > index 3962f592633d..c5449bea58ec 100644 > --- a/arch/x86/boot/compressed/Makefile > +++ b/arch/x86/boot/compressed/Makefile > @@ -62,6 +62,12 @@ KBUILD_LDFLAGS += $(shell $(LD) --help 2>&1 | grep -q "\-z noreloc-overflow" \ > endif > LDFLAGS_vmlinux := -T > > +# Disable relocation relaxation if not linking as PIE > +ifeq ($(filter -pie,$(KBUILD_LDFLAGS)),) > +KBUILD_CFLAGS += $(call as-option, -Wa$(comma)-mrelax-relocations=no) > +KBUILD_AFLAGS += $(call as-option, -Wa$(comma)-mrelax-relocations=no) > +endif > + > hostprogs := mkpiggy > HOST_EXTRACFLAGS += -I$(srctree)/tools/include > > -- > 2.26.2 > -- Thanks, ~Nick Desaulniers