提交 a1329d9c 编写于 作者: P Peter Zijlstra 提交者: Zheng Zengkai

objtool: Add straight-line-speculation validation

stable inclusion
from stable-v5.10.133
commit 0f8532c2837793acdaa07c6b47fda0bf1fa61f40
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I5PTAS
CVE: CVE-2022-29900,CVE-2022-23816,CVE-2022-29901

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=0f8532c2837793acdaa07c6b47fda0bf1fa61f40

--------------------------------

commit 1cc1e4c8 upstream.

Teach objtool to validate the straight-line-speculation constraints:

 - speculation trap after indirect calls
 - speculation trap after RET

Notable: when an instruction is annotated RETPOLINE_SAFE, indicating
  speculation isn't a problem, also don't care about sls for that
  instruction.
Signed-off-by: NPeter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: NBorislav Petkov <bp@suse.de>
Link: https://lore.kernel.org/r/20211204134908.023037659@infradead.orgSigned-off-by: NSasha Levin <sashal@kernel.org>
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
[bwh: Backported to 5.10: adjust filenames, context]
Signed-off-by: NBen Hutchings <ben@decadent.org.uk>
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: NLin Yujun <linyujun809@huawei.com>
Reviewed-by: NZhang Jianhua <chris.zjh@huawei.com>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
上级 7d420da1
...@@ -26,6 +26,7 @@ enum insn_type { ...@@ -26,6 +26,7 @@ enum insn_type {
INSN_CLAC, INSN_CLAC,
INSN_STD, INSN_STD,
INSN_CLD, INSN_CLD,
INSN_TRAP,
INSN_OTHER, INSN_OTHER,
}; };
......
...@@ -456,6 +456,11 @@ int arch_decode_instruction(const struct elf *elf, const struct section *sec, ...@@ -456,6 +456,11 @@ int arch_decode_instruction(const struct elf *elf, const struct section *sec,
break; break;
case 0xcc:
/* int3 */
*type = INSN_TRAP;
break;
case 0xe3: case 0xe3:
/* jecxz/jrcxz */ /* jecxz/jrcxz */
*type = INSN_JUMP_CONDITIONAL; *type = INSN_JUMP_CONDITIONAL;
...@@ -592,10 +597,10 @@ const char *arch_ret_insn(int len) ...@@ -592,10 +597,10 @@ const char *arch_ret_insn(int len)
{ {
static const char ret[5][5] = { static const char ret[5][5] = {
{ BYTE_RET }, { BYTE_RET },
{ BYTE_RET, 0x90 }, { BYTE_RET, 0xcc },
{ BYTE_RET, 0x66, 0x90 }, { BYTE_RET, 0xcc, 0x90 },
{ BYTE_RET, 0x0f, 0x1f, 0x00 }, { BYTE_RET, 0xcc, 0x66, 0x90 },
{ BYTE_RET, 0x0f, 0x1f, 0x40, 0x00 }, { BYTE_RET, 0xcc, 0x0f, 0x1f, 0x00 },
}; };
if (len < 1 || len > 5) { if (len < 1 || len > 5) {
......
...@@ -18,7 +18,8 @@ ...@@ -18,7 +18,8 @@
#include "builtin.h" #include "builtin.h"
#include "objtool.h" #include "objtool.h"
bool no_fp, no_unreachable, retpoline, module, backtrace, uaccess, stats, validate_dup, vmlinux; bool no_fp, no_unreachable, retpoline, module, backtrace, uaccess, stats,
validate_dup, vmlinux, sls;
static const char * const check_usage[] = { static const char * const check_usage[] = {
"objtool check [<options>] file.o", "objtool check [<options>] file.o",
...@@ -35,6 +36,7 @@ const struct option check_options[] = { ...@@ -35,6 +36,7 @@ const struct option check_options[] = {
OPT_BOOLEAN('s', "stats", &stats, "print statistics"), OPT_BOOLEAN('s', "stats", &stats, "print statistics"),
OPT_BOOLEAN('d', "duplicate", &validate_dup, "duplicate validation for vmlinux.o"), OPT_BOOLEAN('d', "duplicate", &validate_dup, "duplicate validation for vmlinux.o"),
OPT_BOOLEAN('l', "vmlinux", &vmlinux, "vmlinux.o validation"), OPT_BOOLEAN('l', "vmlinux", &vmlinux, "vmlinux.o validation"),
OPT_BOOLEAN('S', "sls", &sls, "validate straight-line-speculation"),
OPT_END(), OPT_END(),
}; };
......
...@@ -8,7 +8,8 @@ ...@@ -8,7 +8,8 @@
#include <subcmd/parse-options.h> #include <subcmd/parse-options.h>
extern const struct option check_options[]; extern const struct option check_options[];
extern bool no_fp, no_unreachable, retpoline, module, backtrace, uaccess, stats, validate_dup, vmlinux; extern bool no_fp, no_unreachable, retpoline, module, backtrace, uaccess, stats,
validate_dup, vmlinux, sls;
extern int cmd_check(int argc, const char **argv); extern int cmd_check(int argc, const char **argv);
extern int cmd_orc(int argc, const char **argv); extern int cmd_orc(int argc, const char **argv);
......
...@@ -2775,6 +2775,12 @@ static int validate_branch(struct objtool_file *file, struct symbol *func, ...@@ -2775,6 +2775,12 @@ static int validate_branch(struct objtool_file *file, struct symbol *func,
switch (insn->type) { switch (insn->type) {
case INSN_RETURN: case INSN_RETURN:
if (next_insn && next_insn->type == INSN_TRAP) {
next_insn->ignore = true;
} else if (sls && !insn->retpoline_safe) {
WARN_FUNC("missing int3 after ret",
insn->sec, insn->offset);
}
return validate_return(func, insn, &state); return validate_return(func, insn, &state);
case INSN_CALL: case INSN_CALL:
...@@ -2818,6 +2824,14 @@ static int validate_branch(struct objtool_file *file, struct symbol *func, ...@@ -2818,6 +2824,14 @@ static int validate_branch(struct objtool_file *file, struct symbol *func,
break; break;
case INSN_JUMP_DYNAMIC: case INSN_JUMP_DYNAMIC:
if (next_insn && next_insn->type == INSN_TRAP) {
next_insn->ignore = true;
} else if (sls && !insn->retpoline_safe) {
WARN_FUNC("missing int3 after indirect jump",
insn->sec, insn->offset);
}
/* fallthrough */
case INSN_JUMP_DYNAMIC_CONDITIONAL: case INSN_JUMP_DYNAMIC_CONDITIONAL:
if (is_sibling_call(insn)) { if (is_sibling_call(insn)) {
ret = validate_sibling_call(insn, &state); ret = validate_sibling_call(insn, &state);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册