Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp305283ybh; Wed, 15 Jul 2020 02:24:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyQ6N/yO8MJYBJAAWrPiNCbtoNEKwVdhhO4RMX320+VCjtFt5bMUz/aOfXWYB623Ic1djFL X-Received: by 2002:a17:906:c30b:: with SMTP id s11mr8682054ejz.263.1594805054024; Wed, 15 Jul 2020 02:24:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594805054; cv=none; d=google.com; s=arc-20160816; b=gDzNJfBovM+WM+XxVGWhd4wyRWVfE04h0csQxoKM0t81gL1SMfKS42ApRVZBceBBpl QeXo3llyCOWDJ2I6v5QsCdtBMYgKbhZXgoBzDq40m3whyE5yg6ruX8oME0AuJU/UQesy jSZ8j2Um4QZPaLVRcp6n7Ix6Ix23HEGKCOXZX6K8Dz+m3qj9SeopsMyfq6CIdeIQTt23 FE32VM+rcq+3ZdpdaKXt2toN663NW++s3Nl7bqJV7K/xUUjzghj0vHvHu9xLtuqM/sYG d9SU46nxyz1gNHn8c7uTG3bmd9yhpcU21uuNCO6kmmfvBFww2//1/CGItC9h7xtkXMQd /DPw== 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 :reply-to:in-reply-to:references:mime-version:dkim-signature; bh=jvfhiaQ0ZxylHig36vxLZl3dur0kELp+OxDh9AgCRVc=; b=A9BcGjkFNKSHDlX5ydbBwvx4qT8lU79S/SOAcWbkkPkh22EwKc2OqTyPFgEbomdaBP 49s2VrnYxaD1iobBRGIdI2Uey8uUp6rOF/xbIIKQmO5fDlGSlDeUbeCUg1xxrOjTuC6p aNUXcyV2JYuts2aag3SQkT/aCQKsyzKwhVEYSGbuPtHNisMvPpf29y/3FGok+OwjRynn srdgbxHcUGp/3VGZkf3HkbDpJ6RgzeDsCZe1JbktBb0xnfLpdq5pxfOO3/mDhyZT+nMZ M+pekukjwbMEAK4rH4zinYNXOk7gzNzcUoigxseobGeYAE4GZCmWRynVYLR2im8vKSmy xz5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Q3qqHi6V; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id lw21si893410ejb.302.2020.07.15.02.23.51; Wed, 15 Jul 2020 02:24:14 -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=@gmail.com header.s=20161025 header.b=Q3qqHi6V; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729775AbgGOI6N (ORCPT + 99 others); Wed, 15 Jul 2020 04:58:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56768 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727930AbgGOI6M (ORCPT ); Wed, 15 Jul 2020 04:58:12 -0400 Received: from mail-io1-xd41.google.com (mail-io1-xd41.google.com [IPv6:2607:f8b0:4864:20::d41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B4CB6C061755 for ; Wed, 15 Jul 2020 01:58:12 -0700 (PDT) Received: by mail-io1-xd41.google.com with SMTP id k23so1414431iom.10 for ; Wed, 15 Jul 2020 01:58:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:reply-to:from:date:message-id :subject:to:cc; bh=jvfhiaQ0ZxylHig36vxLZl3dur0kELp+OxDh9AgCRVc=; b=Q3qqHi6Vb4wkdksxz46tFM+5xx30OqKZbSSKW3ASJdtpDmCnfcEhLFQhgDvk9lDm9u SBzD9obwRzrhS5z70GLrDUJGJQJh3A1YaPfy4G+8hvpWp6Xo0p2I95y0bvTSUw47vKR5 TnoVMCtHyHTRbOnpwRncyhTPThc70sZc3eAuKNmRDQaa8eloLqWc4LNojxiLXdpX2WN2 5Wz35K+OW4Nn3RcUTZztpKGRZdXVL0ZfMDx20nIf4xL9V/ffN8SvoUmf2XqanncWKddO K8DpnvcAcwJtoBR7/z+fJNOPOE3RauvE7S+JJRc/Y9/OxiSZ8ieANMG6ULsffxqGeR/+ jksw== 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:reply-to :from:date:message-id:subject:to:cc; bh=jvfhiaQ0ZxylHig36vxLZl3dur0kELp+OxDh9AgCRVc=; b=PwvXtWLfDme7rs8oCgrncsoB+Ezlhu1S4OSWxUWrnmd+i3bNwEPku4IMfOtu+csH4U WLBSFgJ2jEODgnvDYIf836LU7rwYlquuo1BpmkEKAxNAZM2/uzt0FcJjSxbiWMUHPcjS vSVqRjcLa1Qm8FuCW+tIkeZEyvL7guunyMTgfHkQVmR7WDmjNf57c13KquG/OWPqqx+3 qN83BY/T6UgFxLHUGXxnMgCC/Ywe6HnXFjlffY05VqprDJ40UPSVHIfcPV0dxBuJMA+Q 9sJKDxXY9NJ+ZXRJK0meNqtvRioL2N++FE2gDVjQwqL7kij+2CIy766g6XlK3U9Qg4xG Hs/Q== X-Gm-Message-State: AOAM533BTNhCmj/F6QmcrLOuQjmelxHUaplSHt9/CEIkw8M/unT1ZbxK IIhHdgKwuHwomrg0YPRQoWjj2XeW3qGjZrNfStc= X-Received: by 2002:a5e:c91a:: with SMTP id z26mr888628iol.70.1594803491962; Wed, 15 Jul 2020 01:58:11 -0700 (PDT) MIME-Version: 1.0 References: <20200714023836.2310569-1-nivedita@alum.mit.edu> <20200715004133.1430068-7-nivedita@alum.mit.edu> In-Reply-To: <20200715004133.1430068-7-nivedita@alum.mit.edu> Reply-To: sedat.dilek@gmail.com From: Sedat Dilek Date: Wed, 15 Jul 2020 10:58:00 +0200 Message-ID: Subject: Re: [PATCH v5 6/7] x86/boot: Remove run-time relocations from head_{32,64}.S To: Arvind Sankar Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , x86@kernel.org, Nick Desaulniers , Fangrui Song , Dmitry Golovin , Clang-Built-Linux ML , Ard Biesheuvel , Masahiro Yamada , Daniel Kiper , Kees Cook , Nathan Chancellor , Arnd Bergmann , "H . J . Lu" , linux-kernel@vger.kernel.org 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 Wed, Jul 15, 2020 at 2:41 AM Arvind Sankar wrote: > > 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. > Tested-by: Sedat Dilek Reported-by: Sedat Dilek Reported breakage with LLD in previous patchset version. - Sedat - > [1] https://sourceware.org/bugzilla/show_bug.cgi?id=25754 > > 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 c829d874dcac..ae2c0dc98a6a 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 >