Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp599534ybz; Fri, 24 Apr 2020 06:10:01 -0700 (PDT) X-Google-Smtp-Source: APiQypJM+sIHOeUyCFXe6FEckBT9ESvi0QOPD0U5Tl+Z4I9eaYVHeXjEUoLly/eTXzcDYeC51PHN X-Received: by 2002:a50:d942:: with SMTP id u2mr7199863edj.116.1587733801539; Fri, 24 Apr 2020 06:10:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587733801; cv=none; d=google.com; s=arc-20160816; b=XJFYC+b+a2zV5adGlEBBsDQTMHnvoGW1klJGx08vEzI1KA/DWYMOkqEnfpHzgwsdCg 14xVz1NYfkpGQykRfH5k00v3In6lhOXYthd34HcK5Ixwb56TQdRDYM6sqdXEXni0l7jI Wubp+J4O3+rrioruhwIvfVFBdG0i7xmflsCFv+AV0HFJ6+n74dxWsG3uTShHNCJLi5nI 2CY4wOfqGB3wYOqYFb9C2I2X7PAcawBkCok/L7Oqb3gmoZP7AkN3bvLGBgeLqnI1sy/O +tl2h6uMf65Z9p34I8OzVvU47DRwOiqvTq9LLDO3lmGfgsOtLbJEX4Bce523TZI9EoqY bPmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=vX86igH/Mpvphu5JbByp1ZEor7LUYKT80MBJQyjADnQ=; b=G9nLdGpupYatbYpUHBlOGRBR4JhJAxTSL66+WjGZlAUnur3305R1chFYiYAO8QtcsF mpO4tO3rQeoOsOKOstyKQTFV4QccLWLNLTxJNgz1F7C4DHCaw0petZnFUdlCUhPEtvRs Gezfqq4r5n7LvJSNHysoK/5sNe0uhMmKe2ofH5zPN93d3aksBkLcyfcGrnAovT82F0ae 8EIS4Fr4ZXpbtSGxuekJormkNdeaBgg76Lotk2rgW5G/QS7SDk54m6CwHRliT4OD5WI/ a2E8+scG/k79jVPl36VLhJAxN2TDg9vp2/1dCac5fc4yyqGucTgy4Z9kETCB30vvaoSN APHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Mmgp7U3A; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id me19si3187423ejb.140.2020.04.24.06.09.33; Fri, 24 Apr 2020 06:10:01 -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=@kernel.org header.s=default header.b=Mmgp7U3A; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728277AbgDXNHN (ORCPT + 99 others); Fri, 24 Apr 2020 09:07:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:57880 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728230AbgDXNHL (ORCPT ); Fri, 24 Apr 2020 09:07:11 -0400 Received: from e123331-lin.home (amontpellier-657-1-18-247.w109-210.abo.wanadoo.fr [109.210.65.247]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 072AC20767; Fri, 24 Apr 2020 13:07:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587733630; bh=z4vWpbhlY82t1OAv6bqpRSYDjm9YCuAYbM37/Xdua0g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Mmgp7U3AkhWiLEhCs2HVZS0UxQI607L2q5Kbr6ahEpOs0jUaqS+aljcC4Uhl8uMA2 cz+sdn4sjeO0bECHcw2pCC+UTeh+SB56GoiIbHn7uGzisM7pOeAhS3hDCHVzNsVpxB stbYG+A5AUQGlVfDBKpVKsnWD4ldw7Y5mBOBQxKU= From: Ard Biesheuvel To: linux-efi@vger.kernel.org, Ingo Molnar , Thomas Gleixner Cc: Ard Biesheuvel , linux-kernel@vger.kernel.org, Arvind Sankar , Atish Patra , Palmer Dabbelt , Zou Wei Subject: [PATCH 27/33] efi/x86: Remove __efistub_global and add relocation check Date: Fri, 24 Apr 2020 15:05:25 +0200 Message-Id: <20200424130531.30518-28-ardb@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200424130531.30518-1-ardb@kernel.org> References: <20200424130531.30518-1-ardb@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Arvind Sankar Instead of using __efistub_global to force variables into the .data section, leave them in the .bss but pull the EFI stub's .bss section into .data in the linker script for the compressed kernel. Add relocation checking for x86 as well to catch non-PC-relative relocations that require runtime processing, since the EFI stub does not do any runtime relocation processing. This will catch, for example, data relocations created by static initializers of pointers. Signed-off-by: Arvind Sankar Link: https://lore.kernel.org/r/20200416151227.3360778-3-nivedita@alum.mit.edu Signed-off-by: Ard Biesheuvel --- arch/x86/boot/compressed/vmlinux.lds.S | 1 + drivers/firmware/efi/libstub/Makefile | 32 +++++++++++++++++--------- drivers/firmware/efi/libstub/efistub.h | 4 ---- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/arch/x86/boot/compressed/vmlinux.lds.S b/arch/x86/boot/compressed/vmlinux.lds.S index 508cfa6828c5..0dc5c2b9614b 100644 --- a/arch/x86/boot/compressed/vmlinux.lds.S +++ b/arch/x86/boot/compressed/vmlinux.lds.S @@ -52,6 +52,7 @@ SECTIONS _data = . ; *(.data) *(.data.*) + *(.bss.efistub) _edata = . ; } . = ALIGN(L1_CACHE_BYTES); diff --git a/drivers/firmware/efi/libstub/Makefile b/drivers/firmware/efi/libstub/Makefile index aa3ab9a4105e..8d246b51bd49 100644 --- a/drivers/firmware/efi/libstub/Makefile +++ b/drivers/firmware/efi/libstub/Makefile @@ -60,6 +60,25 @@ lib-$(CONFIG_X86) += x86-stub.o CFLAGS_arm32-stub.o := -DTEXT_OFFSET=$(TEXT_OFFSET) CFLAGS_arm64-stub.o := -DTEXT_OFFSET=$(TEXT_OFFSET) +# +# For x86, bootloaders like systemd-boot or grub-efi do not zero-initialize the +# .bss section, so the .bss section of the EFI stub needs to be included in the +# .data section of the compressed kernel to ensure initialization. Rename the +# .bss section here so it's easy to pick out in the linker script. +# +STUBCOPY_FLAGS-$(CONFIG_X86) += --rename-section .bss=.bss.efistub,load,alloc +STUBCOPY_RELOC-$(CONFIG_X86_32) := R_386_32 +STUBCOPY_RELOC-$(CONFIG_X86_64) := R_X86_64_64 + +# +# ARM discards the .data section because it disallows r/w data in the +# decompressor. So move our .data to .data.efistub and .bss to .bss.efistub, +# which are preserved explicitly by the decompressor linker script. +# +STUBCOPY_FLAGS-$(CONFIG_ARM) += --rename-section .data=.data.efistub \ + --rename-section .bss=.bss.efistub,load,alloc +STUBCOPY_RELOC-$(CONFIG_ARM) := R_ARM_ABS + # # arm64 puts the stub in the kernel proper, which will unnecessarily retain all # code indefinitely unless it is annotated as __init/__initdata/__initconst etc. @@ -74,8 +93,8 @@ CFLAGS_arm64-stub.o := -DTEXT_OFFSET=$(TEXT_OFFSET) # a verification pass to see if any absolute relocations exist in any of the # object files. # -extra-$(CONFIG_EFI_GENERIC_STUB) := $(lib-y) -lib-$(CONFIG_EFI_GENERIC_STUB) := $(patsubst %.o,%.stub.o,$(lib-y)) +extra-y := $(lib-y) +lib-y := $(patsubst %.o,%.stub.o,$(lib-y)) STUBCOPY_FLAGS-$(CONFIG_ARM64) += --prefix-alloc-sections=.init \ --prefix-symbols=__efistub_ @@ -98,12 +117,3 @@ quiet_cmd_stubcopy = STUBCPY $@ /bin/false; \ fi; \ $(OBJCOPY) $(STUBCOPY_FLAGS-y) $< $@ - -# -# ARM discards the .data section because it disallows r/w data in the -# decompressor. So move our .data to .data.efistub and .bss to .bss.efistub, -# which are preserved explicitly by the decompressor linker script. -# -STUBCOPY_FLAGS-$(CONFIG_ARM) += --rename-section .data=.data.efistub \ - --rename-section .bss=.bss.efistub,load,alloc -STUBCOPY_RELOC-$(CONFIG_ARM) := R_ARM_ABS diff --git a/drivers/firmware/efi/libstub/efistub.h b/drivers/firmware/efi/libstub/efistub.h index 96e25b17c88e..5244eacc5d4b 100644 --- a/drivers/firmware/efi/libstub/efistub.h +++ b/drivers/firmware/efi/libstub/efistub.h @@ -25,11 +25,7 @@ #define EFI_ALLOC_ALIGN EFI_PAGE_SIZE #endif -#if defined(CONFIG_X86) -#define __efistub_global __section(.data) -#else #define __efistub_global -#endif extern bool __pure nochunk(void); extern bool __pure nokaslr(void); -- 2.17.1