Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp674661pxa; Wed, 12 Aug 2020 10:44:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxNuOEAW7CujM3lX5gXtyppKAosM2IT6yF9G/KQCaUQ3TDAZsFyH9jjkz3M0qwKyTrsaHSe X-Received: by 2002:a17:906:248b:: with SMTP id e11mr915095ejb.280.1597254265801; Wed, 12 Aug 2020 10:44:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597254265; cv=none; d=google.com; s=arc-20160816; b=U6KZ9/ctiglS5mwtczIQWI5XTX9qjf3p85Ff8JO8BCXpm+bZfZznvKoZMAZrsPvg77 at1ohGEZM9HU9CfaGtagQOIsmF3NU8DkzfLFX/t+cMMb1Oo66HQjXKW22EEyALI6c2vc tXC3E7cwPyfR7eYxxRqWCZahrSx/RnKndSVovfhsI6sHa7yViaZWcpUy3zgJeq5o3oxU RCRxMkODdZsszs6dOExuKzBpjojfY/bC0nwf1W+ANT7zrDWEa7sxPcBqgJ6JBn3vaKct lK6pc8kMiM0TlR5Y6qBWkyFyZfmvYotDcjdbsbR1FA8U0zX7M2OmUzDoOQ64rTzsQRML 6qTw== 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=a7lVOCmkI+O7/barsvdFAonBSJY77xfLcdY4hWtrU8E=; b=ogm7KWIhLkUifFqUs12JPcxaVdc2pHYz4/aaLxRu3MC0CFr5I28YG631hdlNaiJ2Bg t/3eWzSDxTyv+HWRVkdS9ZHUnx4dQjzM/d6rf94/s8B5IQ0nv8t5VQiDnsswxQufMMVK 2Ai7p9Z98BE9dy9OclceHDYF3VUcH+2CX46+WMJ+Jk8rmwZcol1614HDcEsmVM++UXob 0slGmkJ31+ZqgHbrfoLSOfQAtpHPzKeu/G6h2CU4B9bcPh2adDLApGmDx+O4BxkigDzV g7pdJZyofveErzWXWAiy78ikDhaTsAR/AI/qszYZ2fc1DbhNAE1X4stO38ZyNEXJXL9x q2Sg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=jahJjF01; 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 v8si2102548edl.307.2020.08.12.10.44.03; Wed, 12 Aug 2020 10:44:25 -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=jahJjF01; 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 S1726542AbgHLRms (ORCPT + 99 others); Wed, 12 Aug 2020 13:42:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48060 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726276AbgHLRmr (ORCPT ); Wed, 12 Aug 2020 13:42:47 -0400 Received: from mail-pl1-x642.google.com (mail-pl1-x642.google.com [IPv6:2607:f8b0:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A4769C061384 for ; Wed, 12 Aug 2020 10:42:45 -0700 (PDT) Received: by mail-pl1-x642.google.com with SMTP id f10so1428210plj.8 for ; Wed, 12 Aug 2020 10:42:45 -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=a7lVOCmkI+O7/barsvdFAonBSJY77xfLcdY4hWtrU8E=; b=jahJjF019IWeZ+BNfrxeznJTrfR1c2QYGhhSLhuAHR5iJp24yKoX7RP6BGWItP1ekC ERyp/j0bljsW8ojmOumYe2oGwKKa9OcJgL4uQMtWduQgWjYFs6BYMCLdcpUfiUVi1RwI bHzFigpwBmCXiYSQMlqhPv5daXMIYO8Z+USVnvoK5XP143Iu1bWnt66+F3POP8uJA8GH lPFBb4y2pG5a2ovbbl325favh4TsFqlLDXfZGYcs/lKzrdvrCt8TWdsNGX/hQAJYWxtS duqPqvQRKZYysxAkjEQGTuebp/R3BBcgE8Q7wr3bKtX3AyAXmQvwbO8eQQtWN0ceqSR9 WJxw== 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=a7lVOCmkI+O7/barsvdFAonBSJY77xfLcdY4hWtrU8E=; b=rYgllQlotVMxL3+sB+m0oGNloFFBh2GupDq3YCKXHKFGK3HFMVo9L3fYPyrYBDd8vT 5V1NN3wBen7nntnOVE6sPmFnfcUbgTCNrFHbDPbttfY/NfDWU/L2Q/u6fH3Da1YVeNaZ 6/2W6TPLVAz1Erk/YznZ9SHtPqRGdUdMba8zTneS2+zknNZdsS6TxgCu1Rx8Hi9SSW4i nQ+G/tyvvJGo8Xoc8YBfVgTuCgjDGR0A8dKxsXylWCfpkUFPzkmMFlCF82eHaXVJbNht 7zdBqPJv7z5ZiaS43j9twjLMk4moUMEkhP433BWmfUy7BKkxPTVl02luR+c4yGzsAXC+ SVGA== X-Gm-Message-State: AOAM531AtSTZxPAruCTp93vi/iCufxPYL6eBgnqhGtyuOlsqE6DVw2nx SPEno8HgN2/agMu9mIAMjej9gNKZq6Htgw3hN84jcA== X-Received: by 2002:a17:90a:3ad1:: with SMTP id b75mr1067394pjc.25.1597254165017; Wed, 12 Aug 2020 10:42:45 -0700 (PDT) MIME-Version: 1.0 References: <20200812004158.GA1447296@rani.riverdale.lan> <20200812004308.1448603-1-nivedita@alum.mit.edu> In-Reply-To: <20200812004308.1448603-1-nivedita@alum.mit.edu> From: Nick Desaulniers Date: Wed, 12 Aug 2020 10:42:34 -0700 Message-ID: Subject: Re: [PATCH v2] x86/boot/compressed: Disable relocation relaxation 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 5:43 PM 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. 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 LGTM > --- > 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 > -- Thanks, ~Nick Desaulniers