From ce7f20d0d231f9d673681fef846dff4aa4eb81c7 Mon Sep 17 00:00:00 2001 From: Lin Yujun Date: Tue, 20 Sep 2022 18:01:02 +0800 Subject: [PATCH] Re-add padlen to the structure alt_instr hulk inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I5QC2M CVE: NA -------------------------------- After optimize_nops() is optimized, redundant padlen is deleted, and ALT_ENTRY_SIZE is reduced to 12. However, the ALT_ENTRY_SIZE used by previously compiled .ko is still 13. As a result, an error is reported when the previously compiled .ko is inserted: kernel BUG at arch/x86/kernel/alternative.c:444! invalid opcode: 000 [#1] SMP PTI Add 'padlen' back and change ALT_ENTRY_SIZE back to 13 to solve the problem. Fixes: e68db6f780c6 ("x86/alternatives: Optimize optimize_nops()") Signed-off-by: Lin Yujun Reviewed-by: Zhang Jianhua Signed-off-by: Zheng Zengkai --- arch/x86/include/asm/alternative.h | 14 +++++++++----- tools/objtool/arch/x86/include/arch_special.h | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h index 0e777b27972b..3dc831571f80 100644 --- a/arch/x86/include/asm/alternative.h +++ b/arch/x86/include/asm/alternative.h @@ -65,6 +65,7 @@ struct alt_instr { u16 cpuid; /* cpuid bit set for replacement */ u8 instrlen; /* length of original instruction */ u8 replacementlen; /* length of new instruction */ + u8 padlen; /* length of build-time padding */ } __packed; /* @@ -105,6 +106,7 @@ static inline int alternatives_text_reserved(void *start, void *end) #define alt_end_marker "663" #define alt_slen "662b-661b" +#define alt_pad_len alt_end_marker"b-662b" #define alt_total_slen alt_end_marker"b-661b" #define alt_rlen(num) e_replacement(num)"f-"b_replacement(num)"f" @@ -151,7 +153,8 @@ static inline int alternatives_text_reserved(void *start, void *end) " .long " b_replacement(num)"f - .\n" /* new instruction */ \ " .word " __stringify(feature) "\n" /* feature bit */ \ " .byte " alt_total_slen "\n" /* source len */ \ - " .byte " alt_rlen(num) "\n" /* replacement len */ + " .byte " alt_rlen(num) "\n" /* replacement len */ \ + " .byte " alt_pad_len "\n" /* pad len */ #define ALTINSTR_REPLACEMENT(newinstr, feature, num) /* replacement */ \ "# ALT: replacement " #num "\n" \ @@ -311,12 +314,13 @@ static inline int alternatives_text_reserved(void *start, void *end) * enough information for the alternatives patching code to patch an * instruction. See apply_alternatives(). */ -.macro altinstruction_entry orig alt feature orig_len alt_len +.macro altinstruction_entry orig alt feature orig_len alt_len pad_len .long \orig - . .long \alt - . .word \feature .byte \orig_len .byte \alt_len + .byte \pad_len .endm /* @@ -333,7 +337,7 @@ static inline int alternatives_text_reserved(void *start, void *end) 142: .pushsection .altinstructions,"a" - altinstruction_entry 140b,143f,\feature,142b-140b,144f-143f + altinstruction_entry 140b,143f,\feature,142b-140b,144f-143f,142b-141b .popsection .pushsection .altinstr_replacement,"ax" @@ -370,8 +374,8 @@ static inline int alternatives_text_reserved(void *start, void *end) 142: .pushsection .altinstructions,"a" - altinstruction_entry 140b,143f,\feature1,142b-140b,144f-143f - altinstruction_entry 140b,144f,\feature2,142b-140b,145f-144f + altinstruction_entry 140b,143f,\feature1,142b-140b,144f-143f,142b-141b + altinstruction_entry 140b,144f,\feature2,142b-140b,145f-144f,142b-141b .popsection .pushsection .altinstr_replacement,"ax" diff --git a/tools/objtool/arch/x86/include/arch_special.h b/tools/objtool/arch/x86/include/arch_special.h index 14271cca0c74..d818b2bffa02 100644 --- a/tools/objtool/arch/x86/include/arch_special.h +++ b/tools/objtool/arch/x86/include/arch_special.h @@ -10,7 +10,7 @@ #define JUMP_ORIG_OFFSET 0 #define JUMP_NEW_OFFSET 4 -#define ALT_ENTRY_SIZE 12 +#define ALT_ENTRY_SIZE 13 #define ALT_ORIG_OFFSET 0 #define ALT_NEW_OFFSET 4 #define ALT_FEATURE_OFFSET 8 -- GitLab