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

objtool: Explicitly avoid self modifying code in .altinstr_replacement

stable inclusion
from stable-v5.10.133
commit 023e78bbf13c15a55013ca25641509a6697170e1
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=023e78bbf13c15a55013ca25641509a6697170e1

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

commit dd003ede upstream.

Assume ALTERNATIVE()s know what they're doing and do not change, or
cause to change, instructions in .altinstr_replacement sections.
Signed-off-by: NPeter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: NBorislav Petkov <bp@suse.de>
Acked-by: NJosh Poimboeuf <jpoimboe@redhat.com>
Tested-by: NAlexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/r/20211026120309.722511775@infradead.org
[cascardo: context adjustment]
Signed-off-by: NThadeu Lima de Souza Cascardo <cascardo@canonical.com>
[bwh: Backported to 5.10: objtool doesn't have any mcount handling]
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>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
上级 9bdf3111
...@@ -870,18 +870,27 @@ static void remove_insn_ops(struct instruction *insn) ...@@ -870,18 +870,27 @@ static void remove_insn_ops(struct instruction *insn)
} }
} }
static void add_call_dest(struct objtool_file *file, struct instruction *insn, static void annotate_call_site(struct objtool_file *file,
struct symbol *dest, bool sibling) struct instruction *insn, bool sibling)
{ {
struct reloc *reloc = insn_reloc(file, insn); struct reloc *reloc = insn_reloc(file, insn);
struct symbol *sym = insn->call_dest;
insn->call_dest = dest; if (!sym)
if (!dest) sym = reloc->sym;
/*
* Alternative replacement code is just template code which is
* sometimes copied to the original instruction. For now, don't
* annotate it. (In the future we might consider annotating the
* original instruction if/when it ever makes sense to do so.)
*/
if (!strcmp(insn->sec->name, ".altinstr_replacement"))
return; return;
if (insn->call_dest->static_call_tramp) { if (sym->static_call_tramp) {
list_add_tail(&insn->call_node, list_add_tail(&insn->call_node, &file->static_call_list);
&file->static_call_list); return;
} }
/* /*
...@@ -889,7 +898,7 @@ static void add_call_dest(struct objtool_file *file, struct instruction *insn, ...@@ -889,7 +898,7 @@ static void add_call_dest(struct objtool_file *file, struct instruction *insn,
* so they need a little help, NOP out any KCOV calls from noinstr * so they need a little help, NOP out any KCOV calls from noinstr
* text. * text.
*/ */
if (insn->sec->noinstr && insn->call_dest->kcov) { if (insn->sec->noinstr && sym->kcov) {
if (reloc) { if (reloc) {
reloc->type = R_NONE; reloc->type = R_NONE;
elf_write_reloc(file->elf, reloc); elf_write_reloc(file->elf, reloc);
...@@ -901,7 +910,16 @@ static void add_call_dest(struct objtool_file *file, struct instruction *insn, ...@@ -901,7 +910,16 @@ static void add_call_dest(struct objtool_file *file, struct instruction *insn,
: arch_nop_insn(insn->len)); : arch_nop_insn(insn->len));
insn->type = sibling ? INSN_RETURN : INSN_NOP; insn->type = sibling ? INSN_RETURN : INSN_NOP;
return;
} }
}
static void add_call_dest(struct objtool_file *file, struct instruction *insn,
struct symbol *dest, bool sibling)
{
insn->call_dest = dest;
if (!dest)
return;
/* /*
* Whatever stack impact regular CALLs have, should be undone * Whatever stack impact regular CALLs have, should be undone
...@@ -911,6 +929,8 @@ static void add_call_dest(struct objtool_file *file, struct instruction *insn, ...@@ -911,6 +929,8 @@ static void add_call_dest(struct objtool_file *file, struct instruction *insn,
* are converted to JUMP, see read_intra_function_calls(). * are converted to JUMP, see read_intra_function_calls().
*/ */
remove_insn_ops(insn); remove_insn_ops(insn);
annotate_call_site(file, insn, sibling);
} }
/* /*
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册