Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp478763pxa; Fri, 14 Aug 2020 09:09:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzSlVvrD2RPCb40ROQ/kdo91GG+R6VW9ixibDuxU8hdXLlJV3hH7Ib18BtGFt2tplmq6eRx X-Received: by 2002:a17:906:a1d7:: with SMTP id bx23mr3135666ejb.273.1597421346699; Fri, 14 Aug 2020 09:09:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597421346; cv=none; d=google.com; s=arc-20160816; b=wQFYhT8PhlEF97vk6KoVMADRSjUn8s/Ze94xjFVLyyMwayW8KorKSW4pyPetwaKaM9 R5xUIPscFKe/iuMP9ZbGEMhuxI+sBOxJmybEUxkGKYprQtsczsfbaZu1GSjkB8me/QIy MOZKWE74kxzsdicd9ZpG5pDlmtCsFmmva+GWg2qZagVZphEiPmf38MdjVqh3z3en2w4y MqnnLLBRFE3mceu4HqjgJB7gOcMwSem1mSyAhj1inqHZ7xZx/mWFB98GnCVEYY8XbjHD 7x+srlurJZSCbgXWW+vBCRkBIVkuuQ1e+aEW1MMdUGM3ABdBIJQ4W8UQm9p1pT06nU3v exJQ== 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 :robot-unsubscribe:robot-id:message-id:mime-version:references :in-reply-to:cc:subject:to:reply-to:from:dkim-signature :dkim-signature:date; bh=nmtdFfauGiznSlg8o2ZnjV2IVRXngrz1eioIF3iGN7U=; b=iiDMhgJwqkNuowmqVLgUthM34hW7+C2Co2DTLJdt22dmqedqppqDD/gk5dYiMjNmn3 HWZ3EGp6ZfF44ZACFGV2Cms1Ot2zY32b6AYJsGKXknQlm/SvW7xizPuZB0Aio7a7+r+l uGat3N5BG6Uz4VLQREgWGM1trALDbLyOFswlvOUoeymkyZ5ULcaG5y04U+yzEb1hHVWg dhGEx9OOVI2HVm+INBTC9CaFvkQBa649f6rNX11dr33/ktQqGMMuUe3ruPpSimarxI1q 9t1skKXnzLCQ67vlVSZaYeMj3DhtCGAsr23CfjBBmJ/v0R8O3zFjPUI5Igl6sA+PTWu0 oKxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linutronix.de header.s=2020 header.b="O8v/a9gZ"; dkim=neutral (no key) header.i=@linutronix.de; 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=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j26si5486371ejx.454.2020.08.14.09.08.42; Fri, 14 Aug 2020 09:09:06 -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=fail header.i=@linutronix.de header.s=2020 header.b="O8v/a9gZ"; dkim=neutral (no key) header.i=@linutronix.de; 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=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727930AbgHNPXm (ORCPT + 99 others); Fri, 14 Aug 2020 11:23:42 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:37412 "EHLO galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727879AbgHNPXl (ORCPT ); Fri, 14 Aug 2020 11:23:41 -0400 Date: Fri, 14 Aug 2020 15:23:38 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1597418618; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nmtdFfauGiznSlg8o2ZnjV2IVRXngrz1eioIF3iGN7U=; b=O8v/a9gZP+3KWJVABUsIXl5eghmXJZDHckOkvQOoreBbC5vLjGipQe3tmC+SzhbwIJR46c EOfHpt9TeZxp+NLF5F1hW9QbkZRuaWAonNY4EsEOymC6nLvU5UIQkswpg8hVst9RURrRx7 UVS0beX4usmMaPfIabWRhHoE+PWUnO4s5kGDCoPoHOjJFEaaOo7fxfBYhpzFa8T+ZPoQNZ 1oDIQaeVVUWKeM40RoZDNoEWa/X0kRNm4G68bSD/XsBwXHu6WTD+u06FmwKeaYZrovnsnq 8mh7hftQ5cgP+XpTRl1TSZRICKLu7UU3b7oO7nPJKXHyvy5wpqrMEUdG5/QRtg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1597418618; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nmtdFfauGiznSlg8o2ZnjV2IVRXngrz1eioIF3iGN7U=; b=J+aw+GAn3J/+pMr9D0zHCaNthX5JsPnPHkMxscLtcBT+gMhfuYAwOS7urwwdUvCZ92PXg3 QRr65BW+Er6DZHBQ== From: "tip-bot2 for Arvind Sankar" Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/boot] x86/boot: Remove run-time relocations from head_{32,64}.S Cc: Arvind Sankar , Kees Cook , Ingo Molnar , Nick Desaulniers , Sedat Dilek , Ard Biesheuvel , Fangrui Song , x86 , LKML In-Reply-To: <20200731230820.1742553-7-keescook@chromium.org> References: <20200731230820.1742553-7-keescook@chromium.org> MIME-Version: 1.0 Message-ID: <159741861819.3192.15659330144869548929.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the x86/boot branch of tip: Commit-ID: 3f086189cd3641d212949ff044d8e4486c93d55e Gitweb: https://git.kernel.org/tip/3f086189cd3641d212949ff044d8e4486c93d55e Author: Arvind Sankar AuthorDate: Fri, 31 Jul 2020 16:07:50 -07:00 Committer: Ingo Molnar CommitterDate: Fri, 14 Aug 2020 12:52:35 +02:00 x86/boot: Remove run-time relocations from head_{32,64}.S 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 Signed-off-by: Arvind Sankar Signed-off-by: Kees Cook Signed-off-by: Ingo Molnar Tested-by: Nick Desaulniers Tested-by: Sedat Dilek Reviewed-by: Kees Cook Reviewed-by: Ard Biesheuvel Reviewed-by: Fangrui Song Link: https://lore.kernel.org/r/20200731230820.1742553-7-keescook@chromium.org --- 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 7c687a7..7d25089 100644 --- a/arch/x86/boot/compressed/Makefile +++ b/arch/x86/boot/compressed/Makefile @@ -52,16 +52,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 8c1a4f5..659fad5 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 1142909..9e46729 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 7e01248..52aa56c 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)