Commit ce7f20d0 authored by Lin Yujun's avatar Lin Yujun Committed by Zheng Zengkai
Browse files

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: default avatarLin Yujun <linyujun809@huawei.com>
Reviewed-by: default avatarZhang Jianhua <chris.zjh@huawei.com>
Signed-off-by: default avatarZheng Zengkai <zhengzengkai@huawei.com>
parent 055190f0
Loading
Loading
Loading
Loading
+9 −5
Original line number Diff line number Diff line
@@ -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"
+1 −1
Original line number Diff line number Diff line
@@ -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