Skip to content

Commit d139bca

Browse files
author
Peter Zijlstra
committed
objtool: Fix IBT tail-call detection
Objtool reports: arch/x86/crypto/poly1305-x86_64.o: warning: objtool: poly1305_blocks_avx() falls through to next function poly1305_blocks_x86_64() arch/x86/crypto/poly1305-x86_64.o: warning: objtool: poly1305_emit_avx() falls through to next function poly1305_emit_x86_64() arch/x86/crypto/poly1305-x86_64.o: warning: objtool: poly1305_blocks_avx2() falls through to next function poly1305_blocks_x86_64() Which reads like: 0000000000000040 <poly1305_blocks_x86_64>: 40: f3 0f 1e fa endbr64 ... 0000000000000400 <poly1305_blocks_avx>: 400: f3 0f 1e fa endbr64 404: 44 8b 47 14 mov 0x14(%rdi),%r8d 408: 48 81 fa 80 00 00 00 cmp $0x80,%rdx 40f: 73 09 jae 41a <poly1305_blocks_avx+0x1a> 411: 45 85 c0 test %r8d,%r8d 414: 0f 84 2a fc ff ff je 44 <poly1305_blocks_x86_64+0x4> ... These are simple conditional tail-calls and *should* be recognised as such by objtool, however due to a mistake in commit 08f87a9 ("objtool: Validate IBT assumptions") this is failing. Specifically, the jump_dest is +4, this means the instruction pointed at will not be ENDBR and as such it will fail the second clause of is_first_func_insn() that was supposed to capture this exact case. Instead, have is_first_func_insn() look at the previous instruction. Fixes: 08f87a9 ("objtool: Validate IBT assumptions") Reported-by: Stephen Rothwell <sfr@canb.auug.org.au> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Link: https://lkml.kernel.org/r/20220322115125.811582125@infradead.org
1 parent 9ce02f0 commit d139bca

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

tools/objtool/check.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,11 +1239,20 @@ static bool same_function(struct instruction *insn1, struct instruction *insn2)
12391239
return insn1->func->pfunc == insn2->func->pfunc;
12401240
}
12411241

1242-
static bool is_first_func_insn(struct instruction *insn)
1242+
static bool is_first_func_insn(struct objtool_file *file, struct instruction *insn)
12431243
{
1244-
return insn->offset == insn->func->offset ||
1245-
(insn->type == INSN_ENDBR &&
1246-
insn->offset == insn->func->offset + insn->len);
1244+
if (insn->offset == insn->func->offset)
1245+
return true;
1246+
1247+
if (ibt) {
1248+
struct instruction *prev = prev_insn_same_sym(file, insn);
1249+
1250+
if (prev && prev->type == INSN_ENDBR &&
1251+
insn->offset == insn->func->offset + prev->len)
1252+
return true;
1253+
}
1254+
1255+
return false;
12471256
}
12481257

12491258
/*
@@ -1327,7 +1336,7 @@ static int add_jump_destinations(struct objtool_file *file)
13271336
insn->jump_dest->func->pfunc = insn->func;
13281337

13291338
} else if (!same_function(insn, insn->jump_dest) &&
1330-
is_first_func_insn(insn->jump_dest)) {
1339+
is_first_func_insn(file, insn->jump_dest)) {
13311340
/* internal sibling call (without reloc) */
13321341
add_call_dest(file, insn, insn->jump_dest->func, true);
13331342
}

0 commit comments

Comments
 (0)