From patchwork Wed Jan 25 10:39:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 92427 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp2145317qgi; Wed, 25 Jan 2017 02:39:36 -0800 (PST) X-Received: by 10.84.229.143 with SMTP id c15mr2570097plk.177.1485340776296; Wed, 25 Jan 2017 02:39:36 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p8si22998214pgd.73.2017.01.25.02.39.36; Wed, 25 Jan 2017 02:39:36 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751853AbdAYKjf (ORCPT + 2 others); Wed, 25 Jan 2017 05:39:35 -0500 Received: from mail-wm0-f45.google.com ([74.125.82.45]:37847 "EHLO mail-wm0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751672AbdAYKjf (ORCPT ); Wed, 25 Jan 2017 05:39:35 -0500 Received: by mail-wm0-f45.google.com with SMTP id c206so23129625wme.0 for ; Wed, 25 Jan 2017 02:39:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=SwIUIqdJhj+UpwiraNXSveFi6hlDTLGA5bfiArJrQsM=; b=JYQtrhuO6ewumbtEw26uiWTjaZgnafNmts0Ks+fm4LJdKQA97IdNY4FNPgT2Zke1vB zvrZxxXbLeYmO496s5O9A8rePYPWgawHxXZ4Av/my7xpj3SyOW5TB/lu4LToOgUjdbn/ jQT6QG9Mdp9FAUV2NTBK/qfuNC7TJHTAR05Q8= 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; bh=SwIUIqdJhj+UpwiraNXSveFi6hlDTLGA5bfiArJrQsM=; b=XDNSRmmKzYQ4enGIzA3MsYaCKvC2gnqHqtfngoNxrlR1mO6zVJ6NZ/jW3f9fbqWfTn D/MnXksp57ZgRkjaDI3bsAt1TJSlaNnLPZffvsyqPl68v2PBrHVtOtdVAW1p70AMvMrW 71Owyv3IpISJhxZwBH0g+93RsAnbPQM96VSGnRdv44jN9xtb3gHWJPVwZjNLnyV15YjP eEh0MTx5quI16cqwf79H1RbsXCFjlFTCwsTgd+tCHYLbJJCayaf8IJOerc/3aAAPU8Iu 4WckKIq8Z1Ky2G4jQfioCjLKd0SzEACC4HFnQgfPpZnpk41Vy1ce89xN73T1Gt31bN1v A5ig== X-Gm-Message-State: AIkVDXIdNqYXRCE+zYJcWJ55u3q2sWX+qw5Hb2+QcAexYEeyQjlE4NXmeHvrG596hl0+AUJv X-Received: by 10.28.217.83 with SMTP id q80mr20738348wmg.58.1485340773466; Wed, 25 Jan 2017 02:39:33 -0800 (PST) Received: from localhost.localdomain ([160.163.215.165]) by smtp.gmail.com with ESMTPSA id o70sm5674153wrc.20.2017.01.25.02.39.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 25 Jan 2017 02:39:32 -0800 (PST) From: Ard Biesheuvel To: linux-efi@vger.kernel.org, linux-arm-kernel@lists.infradead.org, will.deacon@arm.com, catalin.marinas@arm.com, leif.lindholm@linaro.org, mark.rutland@arm.com, matt@codeblueprint.co.uk Cc: Ard Biesheuvel Subject: [PATCH v2 1/2] efi: libstub: Preserve .debug sections after absolute relocation check Date: Wed, 25 Jan 2017 10:39:18 +0000 Message-Id: <1485340759-28975-2-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1485340759-28975-1-git-send-email-ard.biesheuvel@linaro.org> References: <1485340759-28975-1-git-send-email-ard.biesheuvel@linaro.org> Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org The build commands for the ARM and arm64 EFI stubs strip the .debug sections and other sections that may legally contain absolute relocations, in order to inspect the remaining sections for the presence of such relocations. This leaves us without debugging symbols in the stub for no good reason, considering that these sections are omitted from the kernel binary anyway, and that these relocations are thus only consumed by users of the ELF binary, such as debuggers. So move to 'strip' for performing the relocation check, and if it succeeds, invoke objcopy as before, but leaving the .debug sections in place. Note that these sections may refer to ksymtab/kcrctab contents, so leave those in place as well. Cc: Matt Fleming Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/libstub/Makefile | 24 +++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) -- 2.7.4 -- To unsubscribe from this list: send the line "unsubscribe linux-efi" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/firmware/efi/libstub/Makefile b/drivers/firmware/efi/libstub/Makefile index d564d25df8ab..33e0e2f1a730 100644 --- a/drivers/firmware/efi/libstub/Makefile +++ b/drivers/firmware/efi/libstub/Makefile @@ -11,7 +11,7 @@ cflags-$(CONFIG_X86) += -m$(BITS) -D__KERNEL__ -O2 \ -mno-mmx -mno-sse cflags-$(CONFIG_ARM64) := $(subst -pg,,$(KBUILD_CFLAGS)) -cflags-$(CONFIG_ARM) := $(subst -pg,,$(KBUILD_CFLAGS)) -g0 \ +cflags-$(CONFIG_ARM) := $(subst -pg,,$(KBUILD_CFLAGS)) \ -fno-builtin -fpic -mno-single-pic-base cflags-$(CONFIG_EFI_ARMSTUB) += -I$(srctree)/scripts/dtc/libfdt @@ -60,7 +60,7 @@ CFLAGS_arm64-stub.o := -DTEXT_OFFSET=$(TEXT_OFFSET) extra-$(CONFIG_EFI_ARMSTUB) := $(lib-y) lib-$(CONFIG_EFI_ARMSTUB) := $(patsubst %.o,%.stub.o,$(lib-y)) -STUBCOPY_FLAGS-y := -R .debug* -R *ksymtab* -R *kcrctab* +STUBCOPY_RM-y := -R *ksymtab* -R *kcrctab* STUBCOPY_FLAGS-$(CONFIG_ARM64) += --prefix-alloc-sections=.init \ --prefix-symbols=__efistub_ STUBCOPY_RELOC-$(CONFIG_ARM64) := R_AARCH64_ABS @@ -68,17 +68,25 @@ STUBCOPY_RELOC-$(CONFIG_ARM64) := R_AARCH64_ABS $(obj)/%.stub.o: $(obj)/%.o FORCE $(call if_changed,stubcopy) +# +# Strip debug sections and some other sections that may legally contain +# absolute relocations, so that we can inspect the remaining sections for +# such relocations. If none are found, regenerate the output object, but +# this time, use objcopy and leave all sections in place. +# quiet_cmd_stubcopy = STUBCPY $@ - cmd_stubcopy = if $(OBJCOPY) $(STUBCOPY_FLAGS-y) $< $@; then \ - $(OBJDUMP) -r $@ | grep $(STUBCOPY_RELOC-y) \ - && (echo >&2 "$@: absolute symbol references not allowed in the EFI stub"; \ - rm -f $@; /bin/false); else /bin/false; fi + cmd_stubcopy = if $(STRIP) --strip-debug $(STUBCOPY_RM-y) -o $@ $<; \ + then if $(OBJDUMP) -r $@ | grep $(STUBCOPY_RELOC-y); \ + then (echo >&2 "$@: absolute symbol references not allowed in the EFI stub"; \ + rm -f $@; /bin/false); \ + else $(OBJCOPY) $(STUBCOPY_FLAGS-y) $< $@; fi \ + else /bin/false; fi # # ARM discards the .data section because it disallows r/w data in the # decompressor. So move our .data to .data.efistub, which is preserved # explicitly by the decompressor linker script. # -STUBCOPY_FLAGS-$(CONFIG_ARM) += --rename-section .data=.data.efistub \ - -R ___ksymtab+sort -R ___kcrctab+sort +STUBCOPY_FLAGS-$(CONFIG_ARM) += --rename-section .data=.data.efistub +STUBCOPY_RM-$(CONFIG_ARM) += -R ___ksymtab+sort -R ___kcrctab+sort STUBCOPY_RELOC-$(CONFIG_ARM) := R_ARM_ABS