Skip to content

Commit

Permalink
Merge tag 'objtool_urgent_for_v6.4' of git://git.kernel.org/pub/scm/l…
Browse files Browse the repository at this point in the history
…inux/kernel/git/tip/tip

Pull objtool fix from Borislav Petkov:

 - Add a ORC format hash to vmlinux and modules in order for other tools
   which use it, to detect changes to it and adapt accordingly

* tag 'objtool_urgent_for_v6.4' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
  x86/unwind/orc: Add ELF section with ORC version identifier
  • Loading branch information
Linus Torvalds committed Jun 25, 2023
2 parents 661e723 + b9f174c commit 300edd7
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 0 deletions.
12 changes: 12 additions & 0 deletions arch/x86/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,18 @@ ifeq ($(RETPOLINE_CFLAGS),)
endif
endif

ifdef CONFIG_UNWINDER_ORC
orc_hash_h := arch/$(SRCARCH)/include/generated/asm/orc_hash.h
orc_hash_sh := $(srctree)/scripts/orc_hash.sh
targets += $(orc_hash_h)
quiet_cmd_orc_hash = GEN $@
cmd_orc_hash = mkdir -p $(dir $@); \
$(CONFIG_SHELL) $(orc_hash_sh) < $< > $@
$(orc_hash_h): $(srctree)/arch/x86/include/asm/orc_types.h $(orc_hash_sh) FORCE
$(call if_changed,orc_hash)
archprepare: $(orc_hash_h)
endif

archclean:
$(Q)rm -rf $(objtree)/arch/i386
$(Q)rm -rf $(objtree)/arch/x86_64
Expand Down
1 change: 1 addition & 0 deletions arch/x86/include/asm/Kbuild
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# SPDX-License-Identifier: GPL-2.0


generated-y += orc_hash.h
generated-y += syscalls_32.h
generated-y += syscalls_64.h
generated-y += syscalls_x32.h
Expand Down
19 changes: 19 additions & 0 deletions arch/x86/include/asm/orc_header.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
/* Copyright (c) Meta Platforms, Inc. and affiliates. */

#ifndef _ORC_HEADER_H
#define _ORC_HEADER_H

#include <linux/types.h>
#include <linux/compiler.h>
#include <asm/orc_hash.h>

/*
* The header is currently a 20-byte hash of the ORC entry definition; see
* scripts/orc_hash.sh.
*/
#define ORC_HEADER \
__used __section(".orc_header") __aligned(4) \
static const u8 orc_header[] = { ORC_HASH }

#endif /* _ORC_HEADER_H */
3 changes: 3 additions & 0 deletions arch/x86/kernel/unwind_orc.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
#include <asm/unwind.h>
#include <asm/orc_types.h>
#include <asm/orc_lookup.h>
#include <asm/orc_header.h>

ORC_HEADER;

#define orc_warn(fmt, ...) \
printk_deferred_once(KERN_WARNING "WARNING: " fmt, ##__VA_ARGS__)
Expand Down
3 changes: 3 additions & 0 deletions include/asm-generic/vmlinux.lds.h
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,9 @@

#ifdef CONFIG_UNWINDER_ORC
#define ORC_UNWIND_TABLE \
.orc_header : AT(ADDR(.orc_header) - LOAD_OFFSET) { \
BOUNDED_SECTION_BY(.orc_header, _orc_header) \
} \
. = ALIGN(4); \
.orc_unwind_ip : AT(ADDR(.orc_unwind_ip) - LOAD_OFFSET) { \
BOUNDED_SECTION_BY(.orc_unwind_ip, _orc_unwind_ip) \
Expand Down
5 changes: 5 additions & 0 deletions scripts/mod/modpost.c
Original file line number Diff line number Diff line change
Expand Up @@ -1979,6 +1979,11 @@ static void add_header(struct buffer *b, struct module *mod)
buf_printf(b, "#include <linux/vermagic.h>\n");
buf_printf(b, "#include <linux/compiler.h>\n");
buf_printf(b, "\n");
buf_printf(b, "#ifdef CONFIG_UNWINDER_ORC\n");
buf_printf(b, "#include <asm/orc_header.h>\n");
buf_printf(b, "ORC_HEADER;\n");
buf_printf(b, "#endif\n");
buf_printf(b, "\n");
buf_printf(b, "BUILD_SALT;\n");
buf_printf(b, "BUILD_LTO_INFO;\n");
buf_printf(b, "\n");
Expand Down
16 changes: 16 additions & 0 deletions scripts/orc_hash.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0-or-later
# Copyright (c) Meta Platforms, Inc. and affiliates.

set -e

printf '%s' '#define ORC_HASH '

awk '
/^#define ORC_(REG|TYPE)_/ { print }
/^struct orc_entry {$/ { p=1 }
p { print }
/^}/ { p=0 }' |
sha1sum |
cut -d " " -f 1 |
sed 's/\([0-9a-f]\{2\}\)/0x\1,/g'

0 comments on commit 300edd7

Please sign in to comment.