提交 aabd9319 编写于 作者: J Joe Lawrence 提交者: Zheng Zengkai

objtool: Make .altinstructions section entry size consistent

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

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

commit dc023681 upstream.

Commit e31694e0 ("objtool: Don't make .altinstructions writable")
aligned objtool-created and kernel-created .altinstructions section
flags, but there remains a minor discrepency in their use of a section
entry size: objtool sets one while the kernel build does not.

While sh_entsize of sizeof(struct alt_instr) seems intuitive, this small
deviation can cause failures with external tooling (kpatch-build).

Fix this by creating new .altinstructions sections with sh_entsize of 0
and then later updating sec->sh_size as alternatives are added to the
section.  An added benefit is avoiding the data descriptor and buffer
created by elf_create_section(), but previously unused by
elf_add_alternative().

Fixes: 9bc0bb50 ("objtool/x86: Rewrite retpoline thunk calls")
Signed-off-by: NJoe Lawrence <joe.lawrence@redhat.com>
Reviewed-by: NMiroslav Benes <mbenes@suse.cz>
Signed-off-by: NJosh Poimboeuf <jpoimboe@redhat.com>
Link: https://lore.kernel.org/r/20210822225037.54620-2-joe.lawrence@redhat.com
Cc: Andy Lavr <andy.lavr@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: x86@kernel.org
Cc: linux-kernel@vger.kernel.org
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>
上级 07f68ced
...@@ -611,7 +611,7 @@ static int elf_add_alternative(struct elf *elf, ...@@ -611,7 +611,7 @@ static int elf_add_alternative(struct elf *elf,
sec = find_section_by_name(elf, ".altinstructions"); sec = find_section_by_name(elf, ".altinstructions");
if (!sec) { if (!sec) {
sec = elf_create_section(elf, ".altinstructions", sec = elf_create_section(elf, ".altinstructions",
SHF_ALLOC, size, 0); SHF_ALLOC, 0, 0);
if (!sec) { if (!sec) {
WARN_ELF("elf_create_section"); WARN_ELF("elf_create_section");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册