mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] arch/x86/kernel: check the return value of insn_decode_kernel()
@ 2022-09-07  8:52 Li Zhong
  0 siblings, 0 replies; 2+ messages in thread
From: Li Zhong @ 2022-09-07  8:52 UTC (permalink / raw)
  To: linux-kernel
  Cc: peterz, jpoimboe, jbaron, rostedt, ardb, tglx, mingo, bp,
	dave.hansen, x86, hpa, lily

From: lily <floridsleeves@gmail.com>

insn_decode() could fail and the insn.length could be invalid. So we
need to check the return value first.

Signed-off-by: Li Zhong <floridsleeves@gmail.com>
---
 arch/x86/kernel/jump_label.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c
index f5b8ef02d172..59385700f579 100644
--- a/arch/x86/kernel/jump_label.c
+++ b/arch/x86/kernel/jump_label.c
@@ -20,9 +20,10 @@
 int arch_jump_entry_size(struct jump_entry *entry)
 {
 	struct insn insn = {};
+	int ret;
 
-	insn_decode_kernel(&insn, (void *)jump_entry_code(entry));
-	BUG_ON(insn.length != 2 && insn.length != 5);
+	ret = insn_decode_kernel(&insn, (void *)jump_entry_code(entry));
+	BUG_ON(ret < 0 || (insn.length != 2 && insn.length != 5));
 
 	return insn.length;
 }
-- 
2.25.1


^ permalink raw reply	[flat|nested] 2+ messages in thread
* [PATCH v2] arch/x86/kernel: check the return value of insn_decode_kernel()
@ 2022-09-07  8:54 Li Zhong
  0 siblings, 0 replies; 2+ messages in thread
From: Li Zhong @ 2022-09-07  8:54 UTC (permalink / raw)
  To: linux-kernel
  Cc: peterz, jpoimboe, jbaron, rostedt, ardb, tglx, mingo, bp,
	dave.hansen, x86, hpa, Li Zhong

insn_decode() could fail and the insn.length could be invalid. So we
need to check the return value first.

Signed-off-by: Li Zhong <floridsleeves@gmail.com>
---
 arch/x86/kernel/jump_label.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c
index f5b8ef02d172..59385700f579 100644
--- a/arch/x86/kernel/jump_label.c
+++ b/arch/x86/kernel/jump_label.c
@@ -20,9 +20,10 @@
 int arch_jump_entry_size(struct jump_entry *entry)
 {
 	struct insn insn = {};
+	int ret;
 
-	insn_decode_kernel(&insn, (void *)jump_entry_code(entry));
-	BUG_ON(insn.length != 2 && insn.length != 5);
+	ret = insn_decode_kernel(&insn, (void *)jump_entry_code(entry));
+	BUG_ON(ret < 0 || (insn.length != 2 && insn.length != 5));
 
 	return insn.length;
 }
-- 
2.25.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-09-07  8:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-07  8:52 [PATCH v2] arch/x86/kernel: check the return value of insn_decode_kernel() Li Zhong
2022-09-07  8:54 Li Zhong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®