2019-05-19 13:51:43 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
2017-06-28 15:11:05 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2017 Josh Poimboeuf <jpoimboe@redhat.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _CHECK_H
|
|
|
|
#define _CHECK_H
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
2017-06-28 15:11:07 +00:00
|
|
|
#include "cfi.h"
|
2017-06-28 15:11:05 +00:00
|
|
|
#include "arch.h"
|
|
|
|
|
2017-06-28 15:11:07 +00:00
|
|
|
struct insn_state {
|
2020-03-25 13:04:45 +00:00
|
|
|
struct cfi_state cfi;
|
2019-02-25 11:50:09 +00:00
|
|
|
unsigned int uaccess_stack;
|
2020-03-25 13:04:45 +00:00
|
|
|
bool uaccess;
|
|
|
|
bool df;
|
2020-03-10 17:57:41 +00:00
|
|
|
bool noinstr;
|
|
|
|
s8 instr;
|
2017-06-28 15:11:07 +00:00
|
|
|
};
|
|
|
|
|
2017-06-28 15:11:05 +00:00
|
|
|
struct instruction {
|
|
|
|
struct list_head list;
|
|
|
|
struct hlist_node hash;
|
|
|
|
struct section *sec;
|
|
|
|
unsigned long offset;
|
2017-06-28 15:11:07 +00:00
|
|
|
unsigned int len;
|
2019-07-18 01:36:56 +00:00
|
|
|
enum insn_type type;
|
2017-06-28 15:11:05 +00:00
|
|
|
unsigned long immediate;
|
2020-04-14 10:36:11 +00:00
|
|
|
bool dead_end, ignore, ignore_alts;
|
2020-04-01 14:54:26 +00:00
|
|
|
bool hint;
|
2018-01-16 09:24:06 +00:00
|
|
|
bool retpoline_safe;
|
2020-03-10 17:57:41 +00:00
|
|
|
s8 instr;
|
2019-07-24 22:47:26 +00:00
|
|
|
u8 visited;
|
2020-04-01 14:38:19 +00:00
|
|
|
u8 ret_offset;
|
2020-04-14 10:36:11 +00:00
|
|
|
int alt_group;
|
2017-06-28 15:11:05 +00:00
|
|
|
struct symbol *call_dest;
|
|
|
|
struct instruction *jump_dest;
|
2018-02-08 13:02:32 +00:00
|
|
|
struct instruction *first_jump_src;
|
objtool: Support repeated uses of the same C jump table
This fixes objtool for both a GCC issue and a Clang issue:
1) GCC issue:
kernel/bpf/core.o: warning: objtool: ___bpf_prog_run()+0x8d5: sibling call from callable instruction with modified stack frame
With CONFIG_RETPOLINE=n, GCC is doing the following optimization in
___bpf_prog_run().
Before:
select_insn:
jmp *jumptable(,%rax,8)
...
ALU64_ADD_X:
...
jmp select_insn
ALU_ADD_X:
...
jmp select_insn
After:
select_insn:
jmp *jumptable(, %rax, 8)
...
ALU64_ADD_X:
...
jmp *jumptable(, %rax, 8)
ALU_ADD_X:
...
jmp *jumptable(, %rax, 8)
This confuses objtool. It has never seen multiple indirect jump
sites which use the same jump table.
For GCC switch tables, the only way of detecting the size of a table
is by continuing to scan for more tables. The size of the previous
table can only be determined after another switch table is found, or
when the scan reaches the end of the function.
That logic was reused for C jump tables, and was based on the
assumption that each jump table only has a single jump site. The
above optimization breaks that assumption.
2) Clang issue:
drivers/usb/misc/sisusbvga/sisusb.o: warning: objtool: sisusb_write_mem_bulk()+0x588: can't find switch jump table
With clang 9, code can be generated where a function contains two
indirect jump instructions which use the same switch table.
The fix is the same for both issues: split the jump table parsing into
two passes.
In the first pass, locate the heads of all switch tables for the
function and mark their locations.
In the second pass, parse the switch tables and add them.
Fixes: e55a73251da3 ("bpf: Fix ORC unwinding in non-JIT BPF code")
Reported-by: Randy Dunlap <rdunlap@infradead.org>
Reported-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Jann Horn <jannh@google.com>
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Tested-by: Nick Desaulniers <ndesaulniers@google.com>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/e995befaada9d4d8b2cf788ff3f566ba900d2b4d.1563413318.git.jpoimboe@redhat.com
Co-developed-by: Josh Poimboeuf <jpoimboe@redhat.com>
2019-07-18 01:36:54 +00:00
|
|
|
struct rela *jump_table;
|
2017-06-28 15:11:05 +00:00
|
|
|
struct list_head alts;
|
|
|
|
struct symbol *func;
|
2020-03-27 15:28:47 +00:00
|
|
|
struct list_head stack_ops;
|
2020-03-25 13:04:45 +00:00
|
|
|
struct cfi_state cfi;
|
2017-07-11 15:33:42 +00:00
|
|
|
struct orc_entry orc;
|
2017-06-28 15:11:05 +00:00
|
|
|
};
|
|
|
|
|
2017-07-11 15:33:42 +00:00
|
|
|
struct instruction *find_insn(struct objtool_file *file,
|
|
|
|
struct section *sec, unsigned long offset);
|
2017-06-28 15:11:05 +00:00
|
|
|
|
2017-06-28 15:11:07 +00:00
|
|
|
#define for_each_insn(file, insn) \
|
|
|
|
list_for_each_entry(insn, &file->insn_list, list)
|
|
|
|
|
2017-07-11 15:33:42 +00:00
|
|
|
#define sec_for_each_insn(file, sec, insn) \
|
|
|
|
for (insn = find_insn(file, sec, 0); \
|
|
|
|
insn && &insn->list != &file->insn_list && \
|
|
|
|
insn->sec == sec; \
|
|
|
|
insn = list_next_entry(insn, list))
|
|
|
|
|
|
|
|
|
2017-06-28 15:11:05 +00:00
|
|
|
#endif /* _CHECK_H */
|