Skip to content

Commit 08ef8c4

Browse files
author
Peter Zijlstra
committed
objtool: Allow symbol range comparisons for IBT/ENDBR
A semi common pattern is where code checks if a code address is within a specific range. All text addresses require either ENDBR or ANNOTATE_ENDBR, however the ANNOTATE_NOENDBR past the range is unnatural. Instead, suppress this warning when this is exactly at the end of a symbol that itself starts with either ENDBR/ANNOTATE_ENDBR. Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 5da6aea commit 08ef8c4

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

arch/x86/entry/entry_64_compat.S

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ SYM_INNER_LABEL(entry_SYSENTER_compat_after_hwframe, SYM_L_GLOBAL)
128128
popfq
129129
jmp .Lsysenter_flags_fixed
130130
SYM_INNER_LABEL(__end_entry_SYSENTER_compat, SYM_L_GLOBAL)
131-
ANNOTATE_NOENDBR // is_sysenter_singlestep
132131
SYM_CODE_END(entry_SYSENTER_compat)
133132

134133
/*

tools/objtool/check.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4033,6 +4033,24 @@ static void mark_endbr_used(struct instruction *insn)
40334033
list_del_init(&insn->call_node);
40344034
}
40354035

4036+
static bool noendbr_range(struct objtool_file *file, struct instruction *insn)
4037+
{
4038+
struct symbol *sym = find_symbol_containing(insn->sec, insn->offset-1);
4039+
struct instruction *first;
4040+
4041+
if (!sym)
4042+
return false;
4043+
4044+
first = find_insn(file, sym->sec, sym->offset);
4045+
if (!first)
4046+
return false;
4047+
4048+
if (first->type != INSN_ENDBR && !first->noendbr)
4049+
return false;
4050+
4051+
return insn->offset == sym->offset + sym->len;
4052+
}
4053+
40364054
static int validate_ibt_insn(struct objtool_file *file, struct instruction *insn)
40374055
{
40384056
struct instruction *dest;
@@ -4105,9 +4123,19 @@ static int validate_ibt_insn(struct objtool_file *file, struct instruction *insn
41054123
continue;
41064124
}
41074125

4126+
/*
4127+
* Accept anything ANNOTATE_NOENDBR.
4128+
*/
41084129
if (dest->noendbr)
41094130
continue;
41104131

4132+
/*
4133+
* Accept if this is the instruction after a symbol
4134+
* that is (no)endbr -- typical code-range usage.
4135+
*/
4136+
if (noendbr_range(file, dest))
4137+
continue;
4138+
41114139
WARN_FUNC("relocation to !ENDBR: %s",
41124140
insn->sec, insn->offset,
41134141
offstr(dest->sec, dest->offset));

0 commit comments

Comments
 (0)