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 From patchwork Wed Jan 25 10:39:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 92428 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp2145324qgi; Wed, 25 Jan 2017 02:39:38 -0800 (PST) X-Received: by 10.84.128.33 with SMTP id 30mr2573193pla.128.1485340778047; Wed, 25 Jan 2017 02:39:38 -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.37; Wed, 25 Jan 2017 02:39:38 -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 S1751864AbdAYKjh (ORCPT + 2 others); Wed, 25 Jan 2017 05:39:37 -0500 Received: from mail-wm0-f47.google.com ([74.125.82.47]:38579 "EHLO mail-wm0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751672AbdAYKjg (ORCPT ); Wed, 25 Jan 2017 05:39:36 -0500 Received: by mail-wm0-f47.google.com with SMTP id r144so23077822wme.1 for ; Wed, 25 Jan 2017 02:39:36 -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=jkXL+S++2mlSxxdTgKfe0kLM16cUFCPcSK+zjXzS7f4=; b=YyNzR0mzeI5kR58moVWQzvk2VYrDPTRecczVfzwh7MqAKnECZfIg7aiwiRffkjhfoh VDcV/tbNcpZCSWk98g9OKp+242uVX31bhTo7Ak36dv+8O2jK+nYwA1nDsQiMKCU1dQUd /VPil5nkE8DbyZWfswNc0FoS2POqlBDQ5SKkU= 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=jkXL+S++2mlSxxdTgKfe0kLM16cUFCPcSK+zjXzS7f4=; b=FVwAEledwQAMlSBsVXcZqcdietCp6syXcWrLZ6uHhkT484fEyVRC0azPgDeIXsmoaE dADWOrTrR+BlsxyIkaroyBQOy1pEO6s0QQ7NSiEvR/9qlmWBBozBTQkgwGoYIOvhbm4i 1SYVcBggKxd81YGu2S4c3UdbO1GsFwSmak1qVSjQu+5fHRtZI30jJ0GtQXt2nI6iF3J7 8lP2/tUTO6+BqIDpdWEhwjlzvZMC3IAo6ENthwvGLY+t+f4rUftdXFbVX5sjbC1JAag3 0KSF23tE9KRTnnZvHo2y9x40zWy1Nvdzk5VZWW0IKH0uHnCSSkj2YllRfswyB33ORfDp wTiw== X-Gm-Message-State: AIkVDXLi6g4f6nQy5DoHEEdHpb/bGO8t++lzEZLaXasULpD0OZq1A/SAV1cZxcgHGNndVffC X-Received: by 10.223.165.76 with SMTP id j12mr32144131wrb.17.1485340775450; Wed, 25 Jan 2017 02:39:35 -0800 (PST) Received: from localhost.localdomain ([160.163.215.165]) by smtp.gmail.com with ESMTPSA id o70sm5674153wrc.20.2017.01.25.02.39.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 25 Jan 2017 02:39:34 -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 2/2] arm64: efi: add vmlinux debug link to the Image binary Date: Wed, 25 Jan 2017 10:39:19 +0000 Message-Id: <1485340759-28975-3-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 When building with debugging symbols, take the absolute path to the vmlinux binary and add it to the special PE/COFF debug table entry. These entries are used internally by EDK2 based* debug builds of UEFI to populate the DebugImageInfo table, which can be used by debuggers as well as by the OS itself to retrieve information about all loaded PE/COFF executables. This is highly useful for source level debugging of the UEFI stub. * for AArch64, this probably means all of them Cc: Matt Fleming Signed-off-by: Ard Biesheuvel --- arch/arm64/kernel/Makefile | 4 +++ arch/arm64/kernel/head.S | 34 +++++++++++++++++++- arch/arm64/kernel/image.h | 3 ++ 3 files changed, 40 insertions(+), 1 deletion(-) -- 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/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile index 7d66bbaafc0c..6dbc0e5527f5 100644 --- a/arch/arm64/kernel/Makefile +++ b/arch/arm64/kernel/Makefile @@ -55,3 +55,7 @@ obj-y += $(arm64-obj-y) vdso/ probes/ obj-m += $(arm64-obj-m) head-y := head.o extra-y += $(head-y) vmlinux.lds + +ifeq ($(CONFIG_EFI)$(CONFIG_DEBUG_INFO),yy) +AFLAGS_head.o += -DVMLINUX_PATH="\"$(shell readlink -f $(objtree)/vmlinux)\"" +endif diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S index 4b1abac3485a..b462ab1f11ef 100644 --- a/arch/arm64/kernel/head.S +++ b/arch/arm64/kernel/head.S @@ -149,7 +149,7 @@ extra_header_fields: .quad 0 // SizeOfHeapReserve .quad 0 // SizeOfHeapCommit .long 0 // LoaderFlags - .long 0x6 // NumberOfRvaAndSizes + .long (section_table - .) / 8 // NumberOfRvaAndSizes .quad 0 // ExportTable .quad 0 // ImportTable @@ -158,6 +158,11 @@ extra_header_fields: .quad 0 // CertificationTable .quad 0 // BaseRelocationTable +#ifdef CONFIG_DEBUG_INFO + .long efi_debug_table - _head // DebugTable + .long efi_debug_table_size +#endif + // Section table section_table: @@ -204,6 +209,33 @@ section_table: */ .align 12 efi_header_end: + +#ifdef CONFIG_DEBUG_INFO + __INITDATA + +efi_debug_table: + // EFI_IMAGE_DEBUG_DIRECTORY_ENTRY + .long 0 // Characteristics + .long 0 // TimeDateStamp + .short 0 // MajorVersion + .short 0 // MinorVersion + .long 2 // Type == EFI_IMAGE_DEBUG_TYPE_CODEVIEW + .long efi_debug_entry_size // SizeOfData + .long efi_debug_entry_offset // RVA + .long efi_debug_entry_offset // FileOffset + +ENTRY(efi_debug_entry) + // EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY + .long 0x3031424E // Signature + .long 0 // Unknown + .long 0 // Unknown2 + .long 0 // Unknown3 + + .asciz VMLINUX_PATH + + .set efi_debug_entry_size, . - efi_debug_entry + .set efi_debug_table_size, . - efi_debug_table +#endif #endif __INIT diff --git a/arch/arm64/kernel/image.h b/arch/arm64/kernel/image.h index c7fcb232fe47..ad5406f011c2 100644 --- a/arch/arm64/kernel/image.h +++ b/arch/arm64/kernel/image.h @@ -116,6 +116,9 @@ __efistub__end = KALLSYMS_HIDE(_end); __efistub__edata = KALLSYMS_HIDE(_edata); __efistub_screen_info = KALLSYMS_HIDE(screen_info); +#ifdef CONFIG_DEBUG_INFO +efi_debug_entry_offset = efi_debug_entry - _text; +#endif #endif #endif /* __ASM_IMAGE_H */