[tip: objtool/core] objtool: Check for missing annotation entries in read_annotate()

tip-bot2 for Josh Poimboeuf posted 1 patch 3 months, 3 weeks ago
tools/objtool/check.c | 5 +++++
1 file changed, 5 insertions(+)
[tip: objtool/core] objtool: Check for missing annotation entries in read_annotate()
Posted by tip-bot2 for Josh Poimboeuf 3 months, 3 weeks ago
The following commit has been merged into the objtool/core branch of tip:

Commit-ID:     3e4b5f66cf1a7879a081f5044ff1796aa33cb999
Gitweb:        https://git.kernel.org/tip/3e4b5f66cf1a7879a081f5044ff1796aa33cb999
Author:        Josh Poimboeuf <jpoimboe@kernel.org>
AuthorDate:    Wed, 17 Sep 2025 09:03:31 -07:00
Committer:     Josh Poimboeuf <jpoimboe@kernel.org>
CommitterDate: Tue, 14 Oct 2025 14:45:24 -07:00

objtool: Check for missing annotation entries in read_annotate()

Add a sanity check to make sure none of the relocations for the
.discard.annotate_insn section have gone missing.

Acked-by: Petr Mladek <pmladek@suse.com>
Tested-by: Joe Lawrence <joe.lawrence@redhat.com>
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
---
 tools/objtool/check.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index c2e46f9..49d2db7 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -2293,6 +2293,11 @@ static int read_annotate(struct objtool_file *file,
 		sec->sh.sh_entsize = 8;
 	}
 
+	if (sec_num_entries(sec) != sec_num_entries(sec->rsec)) {
+		ERROR("bad .discard.annotate_insn section: missing relocs");
+		return -1;
+	}
+
 	for_each_reloc(sec->rsec, reloc) {
 		type = *(u32 *)(sec->data->d_buf + (reloc_idx(reloc) * sec->sh.sh_entsize) + 4);
 		type = bswap_if_needed(file->elf, type);