Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp309753ybh; Wed, 15 Jul 2020 02:32:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwunpg/EHlAYCWPNzvz4yDaIRJI+bzYOAyARl42nLhPh4k30VHODZICeRaED9PgN7hsHMui X-Received: by 2002:a17:906:50a:: with SMTP id j10mr8163739eja.113.1594805572131; Wed, 15 Jul 2020 02:32:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594805572; cv=none; d=google.com; s=arc-20160816; b=nI5apfKNpz6a6Za6w40g9aWcpXcaUEX7KeLAgi1CT8lxoQpxIFf6RVScC6wxVcV16g JVyormya6kLADR3YkiK5sE8oQDYrvc7UjKKaMryMQcoMDwxvVufTqkgJyULZvJV7vrSY IkVfKC1uPLSAg10M7u4H8xnONf8rrhh4pbolYNDO77s6vjYAajBjxHDQ2evyRIsGYSah 7aIHCkIOiWfl0j81nJ9x1MGKpsq2maLGHwIdUwdz5+gMAlraLuu6mZcim3MrRV63xctK OD/iQDbiYGoBzKjpVi0EKBnuWN/cfiQufgfQ12oFcOeDsi/Hc45Ilmfz2QJsObbLDAUb tEEw== 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 :reply-to:in-reply-to:references:mime-version:dkim-signature; bh=8rsbdVH+KC3/YgU90lgBBUyoDt5JRerD1kAjn5HbfQs=; b=qLgzfo/Ys/JQdQTkvDn6m9VIYKqmEgjl1VZC56oinY7CYIz6Hf4j5A7a/Y11iq+fSZ Cb05/Z97WmuZl3xZDhAuYFyVCxkF6XhgfTzUpB3JdfYWtsbNuDGQiOLPR1qirjUP4nsd 8XEzrO4MdB0dJJF91gAOh6mbaLFNcaMCz2hV7V6Zkojr/Sf0PZWWhTUziuqYvfcnts1z ZPyp0SGbeh4b4KHOgrO/rAtZEjFjwRD8nWTRjTLjfPiNIi6CrsJgkoenfXIkltv5gpkN /S8GfXllRxIGBxD9wUoGRWXZTdk/9OsOSRVvOGTDfb/RIoY9bhu3R/K58UKWxD5S62ej 6bbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=fTqPG3r7; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id co19si866462edb.605.2020.07.15.02.32.28; Wed, 15 Jul 2020 02:32:52 -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=@gmail.com header.s=20161025 header.b=fTqPG3r7; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730566AbgGOJM3 (ORCPT + 99 others); Wed, 15 Jul 2020 05:12:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730560AbgGOJM1 (ORCPT ); Wed, 15 Jul 2020 05:12:27 -0400 Received: from mail-il1-x142.google.com (mail-il1-x142.google.com [IPv6:2607:f8b0:4864:20::142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F3E24C061755 for ; Wed, 15 Jul 2020 02:12:26 -0700 (PDT) Received: by mail-il1-x142.google.com with SMTP id s21so1358174ilk.5 for ; Wed, 15 Jul 2020 02:12:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:reply-to:from:date:message-id :subject:to:cc; bh=8rsbdVH+KC3/YgU90lgBBUyoDt5JRerD1kAjn5HbfQs=; b=fTqPG3r7k7Rir+aggjqLVPVv93H+pVOYdXx/pVqNA5+R0lb44r//w+YMaAK5TU0iO3 75ItLkjbFI4hetEO7gpm8fS8aAGlR0/ECcsCVhBQM/QbSGfAmqGGjpsr4/1do8Pc4wcH bJa4aBCm/z9f09gKvFKu7d9m2Y4gwQckfw4I0hf2uju3rEkvB76M+QUydQ+6pCW5Y8vd xlciehkKhEVbv1rbwSfitl+iO/+JhAwRnY7E/TPfIN//pZytmQnfgjzgdOQ2qqUfE64a odeHXTKtqbHbjbwLLEqyfWAcH7DdgL00chs7Re1kdjQ/fjxU0Cp3Uj5tHyeH17JyS7ID C1nw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:reply-to :from:date:message-id:subject:to:cc; bh=8rsbdVH+KC3/YgU90lgBBUyoDt5JRerD1kAjn5HbfQs=; b=kznguhEKzOBArFwgTRXubJm85ZYYQuyHC435I+az0wKJFwVAkYA7CML0PUPcIoMW0W Cw+X4m2t8OXOYKn/ePB5x92o26FoDYm9URTXHbXx5/lI5V+ncFj7SbM+dMDLHRwabKhQ 98hZKsKlMEjiU+tNsCFOsSogralzqrLLHjxAtUu9ym0KsKNtLATzWtpjlrfqi3h33cyC AyPIr67vpv6VPVFb9bb7YKsVd5lrEMmVT23UUBBotGcoAIGwy5Nqa4XlXWJ6yVUzq4Lk njvsmphobzcdgzz+CgGmY7WJSWO+62m5QaN5eugd8Na8+X/uGJ2Jw5RQ+I0O/UrF9jgS A7nA== X-Gm-Message-State: AOAM530slHSYPj4CcaocyzsxJggPa9/za0ia3Rikfd8MMIeid1zh+I1y KZakF+Tm8JlWvP8V/EOgxCzImBJCmaqUrSKP3KE= X-Received: by 2002:a92:290a:: with SMTP id l10mr9449309ilg.204.1594804346151; Wed, 15 Jul 2020 02:12:26 -0700 (PDT) MIME-Version: 1.0 References: <20200714023836.2310569-1-nivedita@alum.mit.edu> <20200715004133.1430068-8-nivedita@alum.mit.edu> In-Reply-To: Reply-To: sedat.dilek@gmail.com From: Sedat Dilek Date: Wed, 15 Jul 2020 11:12:14 +0200 Message-ID: Subject: Re: [PATCH v5 7/7] x86/boot: Check that there are no run-time relocations To: Arvind Sankar Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , x86@kernel.org, Nick Desaulniers , Fangrui Song , Dmitry Golovin , Clang-Built-Linux ML , Ard Biesheuvel , Masahiro Yamada , Daniel Kiper , Kees Cook , Nathan Chancellor , Arnd Bergmann , "H . J . Lu" , linux-kernel@vger.kernel.org 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 Wed, Jul 15, 2020 at 11:00 AM Sedat Dilek wrote: > > On Wed, Jul 15, 2020 at 2:41 AM Arvind Sankar wrote: > > > > Add a linker script check that there are no run-time 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). > > > > Tested-by: Sedat Dilek > Reported-by: Sedat Dilek > > Here I reported the breakage with LLD and tested the move to > LDFLAGS_vmlinux with a previous version of the patch. > Feel free to also add my: Reviewed-by: Sedat Dilek - Sedat - > > > Reviewed-by: Kees Cook > > Reviewed-by: Ard Biesheuvel > > Reviewed-by: Fangrui Song > > 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 ae2c0dc98a6a..a9e082b8c720 100644 > > --- a/arch/x86/boot/compressed/Makefile > > +++ b/arch/x86/boot/compressed/Makefile > > @@ -29,7 +29,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 > > @@ -51,7 +51,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. > > -LDFLAGS_vmlinux := $(call ld-option, -pie) $(call ld-option, --no-dynamic-linker) > > +LDFLAGS_vmlinux := -pie $(call ld-option, --no-dynamic-linker) > > LDFLAGS_vmlinux += -T > > > > hostprogs := mkpiggy > > @@ -86,30 +86,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 a4a4a59a2628..29df99b6cc64 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) > > } > > @@ -85,3 +91,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 run-time relocations detected!") > > -- > > 2.26.2 > >