Received: by 2002:a25:2c96:0:0:0:0:0 with SMTP id s144csp1673648ybs; Tue, 26 May 2020 00:21:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwhiLL1iWQZutn6vn5ztoKyxQRJ9X04SgaQ+D/X570wnUoKDenDDYrSVd7LdA6snItY8BuI X-Received: by 2002:a17:907:36d:: with SMTP id rs13mr22248170ejb.478.1590477663720; Tue, 26 May 2020 00:21:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590477663; cv=none; d=google.com; s=arc-20160816; b=RYHalLCWisWw1By0GNGDBnsyd4/1imd+737csqtJn4f7MAVald/qhyaf51qH/jumpI SavtyqO1TXYCnV+JFxEHLYwUTs7fHxME2Xvq8e/NV+eoY/SCddA/ZsbTRNuhKrqmwZgw HFVu/p3+19nqdC+SqR7imuGgpn2lu2BpXZcF4AYEmorz5LuHu2ZadYYaT+UZ61tydvnh Ar8O9AHFd363ZoQ0TbhPCFxCLkletDokIvKz9x9YeE9UBZPcreau32uJxJT7ZpaYLOxi 9P2qpRu7KfL+ics/rbFnUfuVg/K7cmum+97lf8z0FlUrd7I6APFcGVKpwu2uJXTUjKkW ig3g== 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 :in-reply-to:references:mime-version:dkim-signature; bh=CZ2KB/JqLrzZBTXstYQj3yTIz/g3Hw4MphdnkKhXlHQ=; b=jqy3SbdmwMnud3ItXTA0Med7o2U0OUSG6WecXUWugA1GR8THuuzUOp+OJTQc38Eoj0 pcwMgZhOQl7G2CecgB9yErTaYkzaugcPaMVYu6j+u/GV0crkc4blvePx7IHwK4sCPHU1 EGnmMlXwHy52rdfw453ObRCZNgyzYmtiHA4DVvOybIBcNpyOoaR0xBE3ajiFofDTFipH B6JN9VjHHAH6yA9dixNSPtELpz+HNCGvM8klS9qzTxPhPcVoHpF9CCnp2HLtQtNJObXG ZkK/UF1w31bO1ZlN79jtHMo5wB2sNq4AikQlSuDfzyj0/YgtJZudsTe8RQn8ih7TH+nw O+JQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=wYzi42jJ; 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 o14si10269039ejx.69.2020.05.26.00.20.41; Tue, 26 May 2020 00:21:03 -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=wYzi42jJ; 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 S1729479AbgEZGMJ (ORCPT + 99 others); Tue, 26 May 2020 02:12:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:59824 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726363AbgEZGMI (ORCPT ); Tue, 26 May 2020 02:12:08 -0400 Received: from mail-io1-f53.google.com (mail-io1-f53.google.com [209.85.166.53]) (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 A71FA20EDD for ; Tue, 26 May 2020 06:12:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1590473527; bh=ySEa+3x56DEhXDsJ/5BxjWyMNs8ZHKcIGhjiyVJvg+Q=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=wYzi42jJMIcztM9lOAVmyApIDg2YsU4yqUmxwqz5SZYzeoYOr1L/7rW32T5YrVb4F 5vtCOpzRXR5Rwz8Fo70V9JvsTZsBhTz8AUCiCbns36n7aaWZFsB/BX7h9ui3I1Nr+Z sMVCw3KZApN4kp/Oor+fxolkBAKxnNEt8qb+UT9M= Received: by mail-io1-f53.google.com with SMTP id d7so20768748ioq.5 for ; Mon, 25 May 2020 23:12:07 -0700 (PDT) X-Gm-Message-State: AOAM5328II0QKuEjjN7nwYm25qzi+W2lbm4pDVxtRcHU2PFUdnNS29Zt 3EGjywKniMxi+I1Fs0i58nJBt1WQ6E98biDeC30= X-Received: by 2002:a02:956f:: with SMTP id y102mr9289995jah.68.1590473526930; Mon, 25 May 2020 23:12:06 -0700 (PDT) MIME-Version: 1.0 References: <20200524212816.243139-1-nivedita@alum.mit.edu> <20200525225918.1624470-5-nivedita@alum.mit.edu> In-Reply-To: <20200525225918.1624470-5-nivedita@alum.mit.edu> From: Ard Biesheuvel Date: Tue, 26 May 2020 08:11:56 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 4/4] x86/boot: Check that there are no runtime relocations To: Arvind Sankar Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , X86 ML , Nick Desaulniers , Fangrui Song , Dmitry Golovin , clang-built-linux , Masahiro Yamada , Daniel Kiper , Linux Kernel Mailing List 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 Tue, 26 May 2020 at 00:59, Arvind Sankar wrote: > > Add a linker script check that there are no runtime relocations, and > remove the old one that tries to check via looking for specially-named > sections in the object files. > > Drop the tests for -fPIE compiler option and -pie linker option, as they > are available in all supported gcc and binutils versions (as well as > clang and lld). > > Signed-off-by: Arvind Sankar > --- > arch/x86/boot/compressed/Makefile | 28 +++----------------------- > arch/x86/boot/compressed/vmlinux.lds.S | 8 ++++++++ > 2 files changed, 11 insertions(+), 25 deletions(-) > > diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile > index d3e882e855ee..679a2b383bfe 100644 > --- a/arch/x86/boot/compressed/Makefile > +++ b/arch/x86/boot/compressed/Makefile > @@ -27,7 +27,7 @@ targets := vmlinux vmlinux.bin vmlinux.bin.gz vmlinux.bin.bz2 vmlinux.bin.lzma \ > vmlinux.bin.xz vmlinux.bin.lzo vmlinux.bin.lz4 > > KBUILD_CFLAGS := -m$(BITS) -O2 > -KBUILD_CFLAGS += -fno-strict-aliasing $(call cc-option, -fPIE, -fPIC) > +KBUILD_CFLAGS += -fno-strict-aliasing -fPIE > KBUILD_CFLAGS += -DDISABLE_BRANCH_PROFILING > cflags-$(CONFIG_X86_32) := -march=i386 > cflags-$(CONFIG_X86_64) := -mcmodel=small > @@ -49,7 +49,7 @@ 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. > -KBUILD_LDFLAGS += $(call ld-option, -pie) $(call ld-option, --no-dynamic-linker) > +KBUILD_LDFLAGS += -pie $(call ld-option, --no-dynamic-linker) Do we still need -pie linking with these changes applied? > LDFLAGS_vmlinux := -T > > hostprogs := mkpiggy > @@ -84,30 +84,8 @@ vmlinux-objs-$(CONFIG_ACPI) += $(obj)/acpi.o > vmlinux-objs-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a > vmlinux-objs-$(CONFIG_EFI_MIXED) += $(obj)/efi_thunk_$(BITS).o > > -# The compressed kernel is built with -fPIC/-fPIE so that a boot loader > -# can place it anywhere in memory and it will still run. However, since > -# it is executed as-is without any ELF relocation processing performed > -# (and has already had all relocation sections stripped from the binary), > -# none of the code can use data relocations (e.g. static assignments of > -# pointer values), since they will be meaningless at runtime. This check > -# will refuse to link the vmlinux if any of these relocations are found. > -quiet_cmd_check_data_rel = DATAREL $@ > -define cmd_check_data_rel > - for obj in $(filter %.o,$^); do \ > - $(READELF) -S $$obj | grep -qF .rel.local && { \ > - echo "error: $$obj has data relocations!" >&2; \ > - exit 1; \ > - } || true; \ > - done > -endef > - > -# We need to run two commands under "if_changed", so merge them into a > -# single invocation. > -quiet_cmd_check-and-link-vmlinux = LD $@ > - cmd_check-and-link-vmlinux = $(cmd_check_data_rel); $(cmd_ld) > - > $(obj)/vmlinux: $(vmlinux-objs-y) FORCE > - $(call if_changed,check-and-link-vmlinux) > + $(call if_changed,ld) > > OBJCOPYFLAGS_vmlinux.bin := -R .comment -S > $(obj)/vmlinux.bin: vmlinux FORCE > diff --git a/arch/x86/boot/compressed/vmlinux.lds.S b/arch/x86/boot/compressed/vmlinux.lds.S > index d826ab38a8f9..f9902c6ffe29 100644 > --- a/arch/x86/boot/compressed/vmlinux.lds.S > +++ b/arch/x86/boot/compressed/vmlinux.lds.S > @@ -42,6 +42,12 @@ SECTIONS > *(.rodata.*) > _erodata = . ; > } > + .rel.dyn : { > + *(.rel.*) > + } > + .rela.dyn : { > + *(.rela.*) > + } > .got : { > *(.got) > } > @@ -83,3 +89,5 @@ ASSERT(SIZEOF(.got.plt) == 0 || SIZEOF(.got.plt) == 0x18, "Unexpected GOT/PLT en > #else > ASSERT(SIZEOF(.got.plt) == 0 || SIZEOF(.got.plt) == 0xc, "Unexpected GOT/PLT entries detected!") > #endif > + > +ASSERT(SIZEOF(.rel.dyn) == 0 && SIZEOF(.rela.dyn) == 0, "Unexpected runtime relocations detected!") > -- > 2.26.2 >