Skip to content

Commit 932f8e9

Browse files
Peter ZijlstraIngo Molnar
authored andcommitted
objtool: Add STT_NOTYPE noinstr validation
Make sure to also check STT_NOTYPE symbols for noinstr violations. Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Reviewed-by: Miroslav Benes <[email protected]> Reviewed-by: Alexandre Chartre <[email protected]> Acked-by: Josh Poimboeuf <[email protected]> Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent 4b5e2e7 commit 932f8e9

File tree

1 file changed

+30
-16
lines changed

1 file changed

+30
-16
lines changed

tools/objtool/check.c

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,18 @@ static void init_cfi_state(struct cfi_state *cfi)
229229
cfi->drap_offset = -1;
230230
}
231231

232-
static void clear_insn_state(struct insn_state *state)
232+
static void init_insn_state(struct insn_state *state, struct section *sec)
233233
{
234234
memset(state, 0, sizeof(*state));
235235
init_cfi_state(&state->cfi);
236+
237+
/*
238+
* We need the full vmlinux for noinstr validation, otherwise we can
239+
* not correctly determine insn->call_dest->sec (external symbols do
240+
* not have a section).
241+
*/
242+
if (vmlinux && sec)
243+
state->noinstr = sec->noinstr;
236244
}
237245

238246
/*
@@ -2354,24 +2362,34 @@ static int validate_branch(struct objtool_file *file, struct symbol *func,
23542362
return 0;
23552363
}
23562364

2357-
static int validate_unwind_hints(struct objtool_file *file)
2365+
static int validate_unwind_hints(struct objtool_file *file, struct section *sec)
23582366
{
23592367
struct instruction *insn;
2360-
int ret, warnings = 0;
23612368
struct insn_state state;
2369+
int ret, warnings = 0;
23622370

23632371
if (!file->hints)
23642372
return 0;
23652373

2366-
clear_insn_state(&state);
2374+
init_insn_state(&state, sec);
23672375

2368-
for_each_insn(file, insn) {
2376+
if (sec) {
2377+
insn = find_insn(file, sec, 0);
2378+
if (!insn)
2379+
return 0;
2380+
} else {
2381+
insn = list_first_entry(&file->insn_list, typeof(*insn), list);
2382+
}
2383+
2384+
while (&insn->list != &file->insn_list && (!sec || insn->sec == sec)) {
23692385
if (insn->hint && !insn->visited) {
23702386
ret = validate_branch(file, insn->func, insn, state);
23712387
if (ret && backtrace)
23722388
BT_FUNC("<=== (hint)", insn);
23732389
warnings += ret;
23742390
}
2391+
2392+
insn = list_next_entry(insn, list);
23752393
}
23762394

23772395
return warnings;
@@ -2518,19 +2536,11 @@ static int validate_section(struct objtool_file *file, struct section *sec)
25182536
struct symbol *func;
25192537
int warnings = 0;
25202538

2521-
/*
2522-
* We need the full vmlinux for noinstr validation, otherwise we can
2523-
* not correctly determine insn->call_dest->sec (external symbols do
2524-
* not have a section).
2525-
*/
2526-
if (vmlinux)
2527-
state.noinstr = sec->noinstr;
2528-
25292539
list_for_each_entry(func, &sec->symbol_list, list) {
25302540
if (func->type != STT_FUNC)
25312541
continue;
25322542

2533-
clear_insn_state(&state);
2543+
init_insn_state(&state, sec);
25342544
state.cfi.cfa = initial_func_cfi.cfa;
25352545
memcpy(&state.cfi.regs, &initial_func_cfi.regs,
25362546
CFI_NUM_REGS * sizeof(struct cfi_reg));
@@ -2545,12 +2555,16 @@ static int validate_section(struct objtool_file *file, struct section *sec)
25452555
static int validate_vmlinux_functions(struct objtool_file *file)
25462556
{
25472557
struct section *sec;
2558+
int warnings = 0;
25482559

25492560
sec = find_section_by_name(file->elf, ".noinstr.text");
25502561
if (!sec)
25512562
return 0;
25522563

2553-
return validate_section(file, sec);
2564+
warnings += validate_section(file, sec);
2565+
warnings += validate_unwind_hints(file, sec);
2566+
2567+
return warnings;
25542568
}
25552569

25562570
static int validate_functions(struct objtool_file *file)
@@ -2635,7 +2649,7 @@ int check(const char *_objname, bool orc)
26352649
goto out;
26362650
warnings += ret;
26372651

2638-
ret = validate_unwind_hints(&file);
2652+
ret = validate_unwind_hints(&file, NULL);
26392653
if (ret < 0)
26402654
goto out;
26412655
warnings += ret;

0 commit comments

Comments
 (0)