Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp3061897ybt; Mon, 29 Jun 2020 14:16:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwXq0LknTTQbFz0n6RYFyoSLnRSZSqL1FqyZwKA+zJ1mKaSK3fkQeGZIu9ophJt5Lr+mq5o X-Received: by 2002:a05:6402:31ba:: with SMTP id dj26mr13107369edb.181.1593465368146; Mon, 29 Jun 2020 14:16:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593465368; cv=none; d=google.com; s=arc-20160816; b=xWfABuw+d22TyrXbrqJrY9DaNXhTYDjYHUHzHrwa9OkLxFxJAC3FhT56OpIdQ1EaCE Nr/ek+hlE+3KLAtlHfjDEqUU6eQTqaTuqCHCGVv7ODPT+OYR6itD4weejONYTU1ZiSBF eFhsMDtMeX44b+lWiifURs8ZUUFPNwpvjYC6vyeCHAORd2oOOklHbtxZ4oBZoccP6uz1 FktIS4gV7eVTKUihl2wfYOj9AuHTLReZM1lRo8tnomleJCArRAtqFJLzqxgQPXl/HuHU ce/8QJ0UO9zQtwd/r64ZZSsu1SIBqRBpr1eaRO/5+Tfn3Aqg7ra4ujIqrIR7lTFfVf+8 zpIQ== 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=Kb5HpOZ/Vsh+GA+MPpqUIWO4+bocKcpUt2VS/fLgGRk=; b=tME4nvzkYCBdVAq+k+7ofgF+yJx2IlECQ5C4dFaQ87I1Q91OJPdlQv2MkjlIgH3A1O AIDbvknocAsaq5cKC4EIvmSSFzHJLScghzFyjr6qpG+x7XCt3rDJk+qIxobcBSKAzXlv O45tcGz+PVA2ALK7slyTXDf88m7HZva+ORcz6WR7VfgQ9CgBSvItZcrduwRo8B7bqbXj nvfchJ9uLTFHWEuxicA1BHj41+XOkap5oKL41cKHSkdrqyUPqrbkn48QISQRIsjhJViN ObwlPmlqaC9hS7OLUc+Na4Ktgbj4q/1/LZjwn4rnnk+RvVClY0iUCbEkrOg2HuZEvm02 YXNA== 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 gy14si387433ejb.313.2020.06.29.14.15.44; Mon, 29 Jun 2020 14:16:08 -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 S2389871AbgF2VMU (ORCPT + 99 others); Mon, 29 Jun 2020 17:12:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730158AbgF2S5p (ORCPT ); Mon, 29 Jun 2020 14:57:45 -0400 Received: from mail-qk1-x743.google.com (mail-qk1-x743.google.com [IPv6:2607:f8b0:4864:20::743]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 762CBC02E2E1 for ; Mon, 29 Jun 2020 07:09:35 -0700 (PDT) Received: by mail-qk1-x743.google.com with SMTP id 145so12829094qke.9 for ; Mon, 29 Jun 2020 07:09:35 -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=Kb5HpOZ/Vsh+GA+MPpqUIWO4+bocKcpUt2VS/fLgGRk=; b=DwJJ1tXM8Muiod7wUh2j2N17cFcV9GXT7D/n9RD9Je9CbmSAsVoTFUPdW8aDBsCYZy Ne+WQL8tamjyFq8s5WU0V6uHb/dfS/xZ++1WHV7A0YZv3HzNgU22y4QumY0gMI/HLUzH 0RzEXHtyUlhYRqxRVxUOAx1qEMXo1FOYuyMtnBDO1o1Mnb0vqKGv2/dKKlapGE65Ird2 8hY014OgkerhL/uQ1/XJDawIttj+SfyZ82qJq4LNNAaX5veYiJ7UuWiadDXDpvx0o1Rd FZ/YSkY+Q3nPjRI/eKqsB0sI5GjASalrQf3JEVFopQ8/egTgxj7WMv1+++hQJy45YGHr t1Gw== X-Gm-Message-State: AOAM532ulG5wFc+rnBQKpsMkXrRd6yxiFBnUfpUAhjDsFyYP2MtQrKYi 1ao7m5Guq+CeRRfMVCq3bdE= X-Received: by 2002:a37:a616:: with SMTP id p22mr14910355qke.292.1593439773366; Mon, 29 Jun 2020 07:09:33 -0700 (PDT) Received: from rani.riverdale.lan ([2001:470:1f07:5f3::b55f]) by smtp.gmail.com with ESMTPSA id i26sm10741461qkh.14.2020.06.29.07.09.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jun 2020 07:09:33 -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 , Daniel Kiper , Sedat Dilek , Kees Cook , Nathan Chancellor , Arnd Bergmann , "H . J . Lu" , linux-kernel@vger.kernel.org Subject: [PATCH v3 3/7] x86/boot/compressed: Get rid of GOT fixup code Date: Mon, 29 Jun 2020 10:09:24 -0400 Message-Id: <20200629140928.858507-4-nivedita@alum.mit.edu> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200629140928.858507-1-nivedita@alum.mit.edu> References: <20200629140928.858507-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 From: Ard Biesheuvel In a previous patch, we have eliminated GOT entries from the decompressor binary and added an assertion that the .got section is empty. This means that the GOT fixup routines that exist in both the 32-bit and 64-bit startup routines have become dead code, and can be removed. While at it, drop the KEEP() from the linker script, as it has no effect on the contents of output sections that are created by the linker itself. Signed-off-by: Ard Biesheuvel Acked-by: Arvind Sankar Signed-off-by: Arvind Sankar From: Ard Biesheuvel Link: https://lore.kernel.org/r/20200523120021.34996-4-ardb@kernel.org --- arch/x86/boot/compressed/head_32.S | 24 ++--------- arch/x86/boot/compressed/head_64.S | 57 -------------------------- arch/x86/boot/compressed/vmlinux.lds.S | 4 +- 3 files changed, 5 insertions(+), 80 deletions(-) diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S index 03557f2174bf..39f0bb43218f 100644 --- a/arch/x86/boot/compressed/head_32.S +++ b/arch/x86/boot/compressed/head_32.S @@ -49,16 +49,13 @@ * Position Independent Executable (PIE) so that linker won't optimize * R_386_GOT32X relocation to its fixed symbol address. Older * linkers generate R_386_32 relocations against locally defined symbols, - * _bss, _ebss, _got, _egot and _end, in PIE. It isn't wrong, just less - * optimal than R_386_RELATIVE. But the x86 kernel fails to properly handle - * R_386_32 relocations when relocating the kernel. To generate - * R_386_RELATIVE relocations, we mark _bss, _ebss, _got, _egot and _end as - * hidden: + * _bss, _ebss and _end, in PIE. It isn't wrong, just less optimal than + * R_386_RELATIVE. But the x86 kernel fails to properly handle R_386_32 + * relocations when relocating the kernel. To generate R_386_RELATIVE + * relocations, we mark _bss, _ebss and _end as hidden: */ .hidden _bss .hidden _ebss - .hidden _got - .hidden _egot .hidden _end __HEAD @@ -192,19 +189,6 @@ SYM_FUNC_START_LOCAL_NOALIGN(.Lrelocated) shrl $2, %ecx rep stosl -/* - * Adjust our own GOT - */ - leal _got(%ebx), %edx - leal _egot(%ebx), %ecx -1: - cmpl %ecx, %edx - jae 2f - addl %ebx, (%edx) - addl $4, %edx - jmp 1b -2: - /* * Do the extraction, and jump to the new kernel.. */ diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S index 97d37f0a34f5..bf1ab30acc5b 100644 --- a/arch/x86/boot/compressed/head_64.S +++ b/arch/x86/boot/compressed/head_64.S @@ -40,8 +40,6 @@ */ .hidden _bss .hidden _ebss - .hidden _got - .hidden _egot .hidden _end __HEAD @@ -353,25 +351,6 @@ SYM_CODE_START(startup_64) /* Set up the stack */ leaq boot_stack_end(%rbx), %rsp - /* - * paging_prepare() and cleanup_trampoline() below can have GOT - * references. Adjust the table with address we are running at. - * - * Zero RAX for adjust_got: the GOT was not adjusted before; - * there's no adjustment to undo. - */ - xorq %rax, %rax - - /* - * Calculate the address the binary is loaded at and use it as - * a GOT adjustment. - */ - call 1f -1: popq %rdi - subq $1b, %rdi - - call .Ladjust_got - /* * At this point we are in long mode with 4-level paging enabled, * but we might want to enable 5-level paging or vice versa. @@ -464,21 +443,6 @@ trampoline_return: pushq $0 popfq - /* - * Previously we've adjusted the GOT with address the binary was - * loaded at. Now we need to re-adjust for relocation address. - * - * Calculate the address the binary is loaded at, so that we can - * undo the previous GOT adjustment. - */ - call 1f -1: popq %rax - subq $1b, %rax - - /* The new adjustment is the relocation address */ - movq %rbx, %rdi - call .Ladjust_got - /* * Copy the compressed kernel to the end of our buffer * where decompression in place becomes safe. @@ -556,27 +520,6 @@ SYM_FUNC_START_LOCAL_NOALIGN(.Lrelocated) jmp *%rax SYM_FUNC_END(.Lrelocated) -/* - * Adjust the global offset table - * - * RAX is the previous adjustment of the table to undo (use 0 if it's the - * first time we touch GOT). - * RDI is the new adjustment to apply. - */ -.Ladjust_got: - /* Walk through the GOT adding the address to the entries */ - leaq _got(%rip), %rdx - leaq _egot(%rip), %rcx -1: - cmpq %rcx, %rdx - jae 2f - subq %rax, (%rdx) /* Undo previous adjustment */ - addq %rdi, (%rdx) /* Apply the new adjustment */ - addq $8, %rdx - jmp 1b -2: - ret - .code32 /* * This is the 32-bit trampoline that will be copied over to low memory. diff --git a/arch/x86/boot/compressed/vmlinux.lds.S b/arch/x86/boot/compressed/vmlinux.lds.S index 4bcc943842ab..a4a4a59a2628 100644 --- a/arch/x86/boot/compressed/vmlinux.lds.S +++ b/arch/x86/boot/compressed/vmlinux.lds.S @@ -43,9 +43,7 @@ SECTIONS _erodata = . ; } .got : { - _got = .; - KEEP(*(.got)) - _egot = .; + *(.got) } .got.plt : { *(.got.plt) -- 2.26.2