Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp982291rwb; Fri, 28 Jul 2023 03:00:00 -0700 (PDT) X-Google-Smtp-Source: APBJJlFGHZdcQnrY6fJhWQIOgClpQg/C//1ExHyA4ha6P+zziZ1qaUO9k/prsPm5XRaT7KihTAiQ X-Received: by 2002:a05:6a20:5526:b0:137:3803:33c with SMTP id ko38-20020a056a20552600b001373803033cmr914444pzb.54.1690538400491; Fri, 28 Jul 2023 03:00:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690538400; cv=none; d=google.com; s=arc-20160816; b=Fy0nbieIpVfNkHqUlR8ezeUaZvqC2c/7JP9geoktCvpiScQ0zhOMKbQFkslhhlOUDq z0ckAYnqZjdgVabWlhbjH99Pr0Vj7RBAHGuK4E91ni7c4zLcpLr1K/pgc65KCRsYb4PK cdWILA0cgReCgJq4R9LQFTe74KwsW2R67VRk9sZ7ExqE9MS3H+baA/3gBGY6/K+UJl9J n1pMtycnxCrKKmYcJyjDjG+s219FS/4cP2vz/BUivoNuuXkykN8I9va6mBj3f3rAVfNu 16guElMTjofDlH6FQOP3dglmdnjFmBjtKRFQhMxCJ3sX6/jmuxI47WLCzQJskhrrwjaM mHvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=KYOkmOGcj5ITQvAC7xwjyaqazCxHiOZiCCPD+Qv95PY=; fh=UoPnrMfWVKGOqsML3Cwqzr4dYAyNRBpPmY/ITnBmPi0=; b=EpnM6vaqNJjfG0HbvQDPGGwvUZ/ar8mUDuJCNJgV5Mtr59Bibmvg3GrNybxVCDtIWq 8P4FsR4IiDoFVy38dCZN+ZSC14DnZnJlG5cnGsUKAbo4SIfq80y77HWrn2YQyXn6GcyJ rHS2wLfuVEzNYX/ZWbFcxq1u66tcKm4ET/tV8rMVFwFvNVMmwMmt2oAp/X9DunuiCGP8 T2BWKUN0RGOYqSkPXO40yPkm4TEa6s+45XtcfxW644n8AJD3RN2yHuvwmrvOONYDubpt kWus0z5RHRJ1kevXZtDbnbyOjznp7Xx5LnvF591x4JmEQPhkx89sImGqC/mNafr+M3IY y34w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=kN0S4sE+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j22-20020a63fc16000000b0055c79b73046si2713330pgi.494.2023.07.28.02.59.48; Fri, 28 Jul 2023 03:00:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=kN0S4sE+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233488AbjG1JPW (ORCPT + 99 others); Fri, 28 Jul 2023 05:15:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34532 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235563AbjG1JNS (ORCPT ); Fri, 28 Jul 2023 05:13:18 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05B664C29; Fri, 28 Jul 2023 02:11:59 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 1CDA362030; Fri, 28 Jul 2023 09:11:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C1F62C433D9; Fri, 28 Jul 2023 09:11:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690535518; bh=ppN7zQL1x7ZvuZXSOdbWV8+ub1ZQTxRxdZn3/MofGlg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kN0S4sE+JHciOcmzSwsLVKDIP568tMQvpL60kqazvN1q/BIxTKQSwgG4ZqR0Mc8d0 HkumRmsWcFzd8OqZpanbLrCgv7oKsJoVtfRCmUapeFYtUh1BDRQQGHWr63WzIgTuln YOX9wZqd4vt51pKI1PphMSInV9ZOlgcc4RSIbdVEt/voexBHSYR97XFOodQjkQqAJz CScb2ftN5T/V6t6llUr3N8l/J5/gubx9bpFGGTUeQPFzsnIyr7Dm2r6V/Z4MU1NGnl qR2u2XutIYaled3kWKHy296BTYBjL0+xoC2ijoydvbhJG5O/QNmnZ1wxQ1Zuln9NhY g+Ok27a7Y8VSA== From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Ard Biesheuvel , Evgeniy Baskov , Borislav Petkov , Andy Lutomirski , Dave Hansen , Ingo Molnar , Peter Zijlstra , Thomas Gleixner , Alexey Khoroshilov , Peter Jones , Gerd Hoffmann , Dave Young , Mario Limonciello , Kees Cook , Tom Lendacky , "Kirill A . Shutemov" , Linus Torvalds , Joerg Roedel Subject: [PATCH v7 18/22] x86/decompressor: Move global symbol references to C code Date: Fri, 28 Jul 2023 11:09:12 +0200 Message-Id: <20230728090916.1538550-19-ardb@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230728090916.1538550-1-ardb@kernel.org> References: <20230728090916.1538550-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=5080; i=ardb@kernel.org; h=from:subject; bh=ppN7zQL1x7ZvuZXSOdbWV8+ub1ZQTxRxdZn3/MofGlg=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIeVw67YtB0+UxC8/9WOBv+0ippO2Yi0fuh7KdPfrbMx+/ qQr7f3HjlIWBjEOBlkxRRaB2X/f7Tw9UarWeZYszBxWJpAhDFycAjAR61+MDGue3peP6ruR6Wby /FUyr1ZDZcjBQy4Xsuxm3dMOq2r/r8LIcFOId0uRc3jX29+Kezaz7y7ILcgTksq+If2u8Lg17/R HHAA= X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org It is no longer necessary to be cautious when referring to global variables in the position independent decompressor code, now that it is built using PIE codegen and makes an assertion in the linker script that no GOT entries exist (which would require adjustment for the actual runtime load address of the decompressor binary). This means global variables can be referenced directly from C code, instead of having to pass their runtime addresses into C routines from asm code, which needs to happen at each call site. Do so for the code that will be called directly from the EFI stub after a subsequent patch, and avoid the need to duplicate this logic a third time. Signed-off-by: Ard Biesheuvel --- arch/x86/boot/compressed/head_32.S | 8 -------- arch/x86/boot/compressed/head_64.S | 8 +------- arch/x86/boot/compressed/misc.c | 16 +++++++++------- 3 files changed, 10 insertions(+), 22 deletions(-) diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S index 3530465b5b85ccf3..beee858058df4403 100644 --- a/arch/x86/boot/compressed/head_32.S +++ b/arch/x86/boot/compressed/head_32.S @@ -168,13 +168,7 @@ SYM_FUNC_START_LOCAL_NOALIGN(.Lrelocated) */ /* push arguments for extract_kernel: */ - 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 */ - leal boot_heap@GOTOFF(%ebx), %eax - pushl %eax /* heap area */ pushl %esi /* real mode pointer */ call extract_kernel /* returns kernel entry point in %eax */ addl $24, %esp @@ -202,8 +196,6 @@ SYM_DATA_END_LABEL(gdt, SYM_L_LOCAL, gdt_end) */ .bss .balign 4 -boot_heap: - .fill BOOT_HEAP_SIZE, 1, 0 boot_stack: .fill BOOT_STACK_SIZE, 1, 0 boot_stack_end: diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S index eb33edf1e75d4b02..a9237e48f2f7cfd5 100644 --- a/arch/x86/boot/compressed/head_64.S +++ b/arch/x86/boot/compressed/head_64.S @@ -493,11 +493,7 @@ SYM_FUNC_START_LOCAL_NOALIGN(.Lrelocated) * Do the extraction, and jump to the new kernel.. */ movq %r15, %rdi /* pass struct boot_params pointer */ - leaq boot_heap(%rip), %rsi /* malloc area for uncompression */ - leaq input_data(%rip), %rdx /* input_data */ - movl input_len(%rip), %ecx /* input_len */ - movq %rbp, %r8 /* output target address */ - movl output_len(%rip), %r9d /* decompressed length, end of relocs */ + movq %rbp, %rsi /* output target address */ call extract_kernel /* returns kernel entry point in %rax */ /* @@ -661,8 +657,6 @@ SYM_DATA_END_LABEL(boot_idt, SYM_L_GLOBAL, boot_idt_end) */ .bss .balign 4 -SYM_DATA_LOCAL(boot_heap, .fill BOOT_HEAP_SIZE, 1, 0) - SYM_DATA_START_LOCAL(boot_stack) .fill BOOT_STACK_SIZE, 1, 0 .balign 16 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c index 94b7abcf624b3b55..2d91d56b59e1af93 100644 --- a/arch/x86/boot/compressed/misc.c +++ b/arch/x86/boot/compressed/misc.c @@ -330,6 +330,11 @@ static size_t parse_elf(void *output) return ehdr.e_entry - LOAD_PHYSICAL_ADDR; } +static u8 boot_heap[BOOT_HEAP_SIZE] __aligned(4); + +extern unsigned char input_data[]; +extern unsigned int input_len, output_len; + /* * The compressed kernel image (ZO), has been moved so that its position * is against the end of the buffer used to hold the uncompressed kernel @@ -347,14 +352,11 @@ static size_t parse_elf(void *output) * |-------uncompressed kernel image---------| * */ -asmlinkage __visible void *extract_kernel(void *rmode, memptr heap, - unsigned char *input_data, - unsigned long input_len, - unsigned char *output, - unsigned long output_len) +asmlinkage __visible void *extract_kernel(void *rmode, unsigned char *output) { const unsigned long kernel_total_size = VO__end - VO__text; unsigned long virt_addr = LOAD_PHYSICAL_ADDR; + memptr heap = (memptr)boot_heap; unsigned long needed_size; size_t entry_offset; @@ -412,7 +414,7 @@ asmlinkage __visible void *extract_kernel(void *rmode, memptr heap, * entries. This ensures the full mapped area is usable RAM * and doesn't include any reserved areas. */ - needed_size = max(output_len, kernel_total_size); + needed_size = max_t(unsigned long, output_len, kernel_total_size); #ifdef CONFIG_X86_64 needed_size = ALIGN(needed_size, MIN_KERNEL_ALIGN); #endif @@ -443,7 +445,7 @@ asmlinkage __visible void *extract_kernel(void *rmode, memptr heap, #ifdef CONFIG_X86_64 if (heap > 0x3fffffffffffUL) error("Destination address too large"); - if (virt_addr + max(output_len, kernel_total_size) > KERNEL_IMAGE_SIZE) + if (virt_addr + needed_size > KERNEL_IMAGE_SIZE) error("Destination virtual address is beyond the kernel mapping area"); #else if (heap > ((-__PAGE_OFFSET-(128<<20)-1) & 0x7fffffff)) -- 2.39.2