Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp338212pxa; Fri, 31 Jul 2020 13:30:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxNyxgmZldabwuvXodgVJu50WNbnBorrpGvqV1zRpCa1Xe5euW02fpcBs7TKXFlvb+aR+78 X-Received: by 2002:a17:906:845:: with SMTP id f5mr5807500ejd.34.1596227429931; Fri, 31 Jul 2020 13:30:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596227429; cv=none; d=google.com; s=arc-20160816; b=Y9BKSrDA/HjoPMWPfV3d9Kn++BiPy54jVvpEXuouhAn2xp3IqyNFTF4pCTMRZufjiJ wjLjs6zLW0D8b8JaKIsc3kNaGOFbmFzIpuAjPJPmLYO9luLBUJ6ae9+gb8hre27EvH2W dpbOLshaOsh+eNxRpAJJlMBdEKkRZHStMpzHREgBTbFYWglR59rAiHqRpjDCb4rrKhPe EgK6zwQzF6gF9v65oGolfIHMge/EJN4dR0p/AFo7JtchP2+NKZXCNBNAeJRrt7R9uZVn IUFAOUspwfzP3v4Qp0EnvBr/jBBC1TkjGH/yfu9Tlr/2aoT5Wllre5Sn87+wJpOtPkLg QyWw== 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=HNlG0r3f7+DcMDWbQ/vbYvO7FSu0jmedmwBxasWw2g0=; b=TFmfBQixedVtxgVZR2q743moTMzwoJKqdO/a/3LB76eBanQcUJ03tXlRlF7xsdO9Uz xNF/9ob0aB8+VhE/MmsIylOvDsbxSlEpCfdW0U7w/Xxe3rVbkL5S2qY05/sKzZUvjRXW JNUG7T4QAUR5Xk5E1iT6VxRaO1Vq3khOSYe72A0DFoIaGWeNp9XW3ORZJ6b09Xu2UsDW 8IQHNwOOwAhN9c7OsR1iTHICynsJEGLtJdJT1LfqFR5I3lckOlKTWwPQOgUvZzaBOWJ8 Hin6uIAJWInEGUhY6dW2lXCZxXWIwg1Xfp+aAutwphj1ENy1JHYXIcmv6vK+TqtJVtlD cfkQ== 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 f27si5815418ejj.255.2020.07.31.13.30.07; Fri, 31 Jul 2020 13:30:29 -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 S1730254AbgGaU1u (ORCPT + 99 others); Fri, 31 Jul 2020 16:27:50 -0400 Received: from mail-qk1-f195.google.com ([209.85.222.195]:37633 "EHLO mail-qk1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730127AbgGaU1r (ORCPT ); Fri, 31 Jul 2020 16:27:47 -0400 Received: by mail-qk1-f195.google.com with SMTP id b14so28300509qkn.4 for ; Fri, 31 Jul 2020 13:27:46 -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=HNlG0r3f7+DcMDWbQ/vbYvO7FSu0jmedmwBxasWw2g0=; b=D9nLSqDC1NaX+bz2ysxVK/cNfROFn3mCOVK7yjUOxSIe7Tnfudmc414/vBPeARpXj3 6+QskglY0CijgJCUW3WNJvkInvWVmJ5kWuFTTUx6dEUAW/TIFyTVQ7/vByMKV/j9BUky peHdDan+3HJIhbI9ugcO0ltsLrwIYwCsejL4HBCVrCYGwrbi8s3UmkejIkpBKEy0UVpt Hxg3NmTeDHYtCxkuNnEf2VewMvFTUgC49IhwQbvnc2Wf0Rov2WN+WKj9cHo7isOluhHP JwK16vY5SK6KtW7sBqJga0Hy1d0yGNjLsWFn3oGLUVWiB1ULzj0kvicoFwFy0usTCiVL Pw4A== X-Gm-Message-State: AOAM531nRjOnHnZDoiRh/e0PbLCUZ17FgUUlD1rthk6VqaHuSb6MBpMO sGy35uBResU3JoT7L79F3Ok= X-Received: by 2002:a37:6594:: with SMTP id z142mr5693346qkb.10.1596227266118; Fri, 31 Jul 2020 13:27:46 -0700 (PDT) Received: from rani.riverdale.lan ([2001:470:1f07:5f3::b55f]) by smtp.gmail.com with ESMTPSA id t35sm10607976qth.79.2020.07.31.13.27.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jul 2020 13:27:45 -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 , Sedat Dilek , Kees Cook , Nathan Chancellor , Arnd Bergmann , "H . J . Lu" , linux-kernel@vger.kernel.org Subject: [PATCH v6 6/7] x86/boot: Remove run-time relocations from head_{32,64}.S Date: Fri, 31 Jul 2020 16:27:37 -0400 Message-Id: <20200731202738.2577854-7-nivedita@alum.mit.edu> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200731202738.2577854-1-nivedita@alum.mit.edu> References: <20200731202738.2577854-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 The BFD linker generates run-time relocations for z_input_len and z_output_len, even though they are absolute symbols. This is fixed for binutils-2.35 [1]. Work around this for earlier versions by defining two variables input_len and output_len in addition to the symbols, and use them via position-independent references. This eliminates the last two run-time relocations in the head code and allows us to drop the -z noreloc-overflow flag to the linker. Move the -pie and --no-dynamic-linker LDFLAGS to LDFLAGS_vmlinux instead of KBUILD_LDFLAGS. There shouldn't be anything else getting linked, but this is the more logical location for these flags, and modversions might call the linker if an EXPORT_SYMBOL is left over accidentally in one of the decompressors. [1] https://sourceware.org/bugzilla/show_bug.cgi?id=25754 Tested-by: Nick Desaulniers Tested-by: Sedat Dilek Reviewed-by: Kees Cook Reviewed-by: Ard Biesheuvel Reviewed-by: Fangrui Song Signed-off-by: Arvind Sankar --- arch/x86/boot/compressed/Makefile | 12 ++---------- arch/x86/boot/compressed/head_32.S | 17 ++++++++--------- arch/x86/boot/compressed/head_64.S | 4 ++-- arch/x86/boot/compressed/mkpiggy.c | 6 ++++++ 4 files changed, 18 insertions(+), 21 deletions(-) diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile index 489fea16bcfb..7db0102a573d 100644 --- a/arch/x86/boot/compressed/Makefile +++ b/arch/x86/boot/compressed/Makefile @@ -51,16 +51,8 @@ UBSAN_SANITIZE :=n KBUILD_LDFLAGS := -m elf_$(UTS_MACHINE) # Compressed kernel should be built as PIE since it may be loaded at any # address by the bootloader. -ifeq ($(CONFIG_X86_32),y) -KBUILD_LDFLAGS += $(call ld-option, -pie) $(call ld-option, --no-dynamic-linker) -else -# To build 64-bit compressed kernel as PIE, we disable relocation -# overflow check to avoid relocation overflow error with a new linker -# command-line option, -z noreloc-overflow. -KBUILD_LDFLAGS += $(shell $(LD) --help 2>&1 | grep -q "\-z noreloc-overflow" \ - && echo "-z noreloc-overflow -pie --no-dynamic-linker") -endif -LDFLAGS_vmlinux := -T +LDFLAGS_vmlinux := $(call ld-option, -pie) $(call ld-option, --no-dynamic-linker) +LDFLAGS_vmlinux += -T hostprogs := mkpiggy HOST_EXTRACFLAGS += -I$(srctree)/tools/include diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S index 8c1a4f5610f5..659fad53ca82 100644 --- a/arch/x86/boot/compressed/head_32.S +++ b/arch/x86/boot/compressed/head_32.S @@ -178,18 +178,17 @@ SYM_FUNC_START_LOCAL_NOALIGN(.Lrelocated) /* * Do the extraction, and jump to the new kernel.. */ - /* push arguments for extract_kernel: */ - pushl $z_output_len /* decompressed length, end of relocs */ + /* push arguments for extract_kernel: */ - pushl %ebp /* output address */ - - pushl $z_input_len /* input_len */ + pushl output_len@GOTOFF(%ebx) /* decompressed length, end of relocs */ + pushl %ebp /* output address */ + pushl input_len@GOTOFF(%ebx) /* input_len */ leal input_data@GOTOFF(%ebx), %eax - pushl %eax /* input_data */ + pushl %eax /* input_data */ leal boot_heap@GOTOFF(%ebx), %eax - pushl %eax /* heap area */ - pushl %esi /* real mode pointer */ - call extract_kernel /* returns kernel location in %eax */ + pushl %eax /* heap area */ + pushl %esi /* real mode pointer */ + call extract_kernel /* returns kernel location in %eax */ addl $24, %esp /* diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S index 11429092c224..9e46729cf162 100644 --- a/arch/x86/boot/compressed/head_64.S +++ b/arch/x86/boot/compressed/head_64.S @@ -534,9 +534,9 @@ SYM_FUNC_START_LOCAL_NOALIGN(.Lrelocated) movq %rsi, %rdi /* real mode address */ leaq boot_heap(%rip), %rsi /* malloc area for uncompression */ leaq input_data(%rip), %rdx /* input_data */ - movl $z_input_len, %ecx /* input_len */ + movl input_len(%rip), %ecx /* input_len */ movq %rbp, %r8 /* output target address */ - movl $z_output_len, %r9d /* decompressed length, end of relocs */ + movl output_len(%rip), %r9d /* decompressed length, end of relocs */ call extract_kernel /* returns kernel location in %rax */ popq %rsi diff --git a/arch/x86/boot/compressed/mkpiggy.c b/arch/x86/boot/compressed/mkpiggy.c index 7e01248765b2..52aa56cdbacc 100644 --- a/arch/x86/boot/compressed/mkpiggy.c +++ b/arch/x86/boot/compressed/mkpiggy.c @@ -60,6 +60,12 @@ int main(int argc, char *argv[]) printf(".incbin \"%s\"\n", argv[1]); printf("input_data_end:\n"); + printf(".section \".rodata\",\"a\",@progbits\n"); + printf(".globl input_len\n"); + printf("input_len:\n\t.long %lu\n", ilen); + printf(".globl output_len\n"); + printf("output_len:\n\t.long %lu\n", (unsigned long)olen); + retval = 0; bail: if (f) -- 2.26.2