Skip to contentSkip to conversation

x86/kernel: Fix unchecked return value

PATCH-next Khaled ROMDHANI 3 participants 4 messages May 15, 2021 – May 16, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

From the coverity scan analysis, the return value from insn_decode_kernel is not checked. It is a macro constructed from the insn_decode function which may fail and return negative integer. Fix this by explicitly checking the return value.

Addresses-Coverity: ("Unchecked return value")

---
 arch/x86/kernel/jump_label.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/jump_label.c +1 -1
index a762dc1c615e..bf0ea003b6e7 100644
@@ -23,7 +23,7 @@ int arch_jump_entry_size(struct jump_entry *entry)
 {
 	struct insn insn = {};
 
-	insn_decode_kernel(&insn, (void *)jump_entry_code(entry));
+	WARN_ON(insn_decode_kernel(&insn, (void *)jump_entry_code(entry)));
 	BUG_ON(insn.length != 2 && insn.length != 5);
 
 	return insn.length;
Signature · 1 line
2.17.1
maintainer
#1 lore raw
Quoted 17 lines · Khaled ROMDHANI

From the coverity scan analysis, the return value from insn_decode_kernel is not checked. It is a macro constructed from the insn_decode function which may fail and return negative integer. Fix this by explicitly checking the return value.

Addresses-Coverity: ("Unchecked return value")

---
 arch/x86/kernel/jump_label.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/jump_label.c +0 -0
index a762dc1c615e..bf0ea003b6e7 100644

arch/x86/kernel/jump_label.c int arch_jump_entry_size(struct jump_entry *entry) · line 26

Quoted 5 lines
arch/x86/kernel/jump_label.c +1 -1
@@ -23,7 +23,7 @@ int arch_jump_entry_size(struct jump_entry *entry)
 {
 	struct insn insn = {};
 
-	insn_decode_kernel(&insn, (void *)jump_entry_code(entry));
+	WARN_ON(insn_decode_kernel(&insn, (void *)jump_entry_code(entry)));

I don't think coverity is smart enough to notice...

arch/x86/kernel/jump_label.c int arch_jump_entry_size(struct jump_entry *entry) · line 27

Quoted 1 line
arch/x86/kernel/jump_label.c +0 -0
 	BUG_ON(insn.length != 2 && insn.length != 5);
	^^^^^^^^^^^^^

... this line.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
#2 lore raw
Quoted 26 lines · Borislav Petkov
Quoted 17 lines · Khaled ROMDHANI

From the coverity scan analysis, the return value from insn_decode_kernel is not checked. It is a macro constructed from the insn_decode function which may fail and return negative integer. Fix this by explicitly checking the return value.

Addresses-Coverity: ("Unchecked return value")

---
 arch/x86/kernel/jump_label.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/jump_label.c +0 -0
index a762dc1c615e..bf0ea003b6e7 100644

arch/x86/kernel/jump_label.c int arch_jump_entry_size(struct jump_entry *entry) · line 26

Quoted 5 lines
arch/x86/kernel/jump_label.c +1 -1
@@ -23,7 +23,7 @@ int arch_jump_entry_size(struct jump_entry *entry)
 {
 	struct insn insn = {};
 
-	insn_decode_kernel(&insn, (void *)jump_entry_code(entry));
+	WARN_ON(insn_decode_kernel(&insn, (void *)jump_entry_code(entry)));

I don't think coverity is smart enough to notice...

Quoted 6 lines

arch/x86/kernel/jump_label.c int arch_jump_entry_size(struct jump_entry *entry) · line 27

Quoted 1 line
arch/x86/kernel/jump_label.c +0 -0
 	BUG_ON(insn.length != 2 && insn.length != 5);
	^^^^^^^^^^^^^

... this line.

Indeed. One needs to be careful with false positives with Coverity.

Colin

#3 lore raw
Quoted 28 lines · Colin Ian King
Quoted 27 lines · Borislav Petkov
Quoted 17 lines · Khaled ROMDHANI

From the coverity scan analysis, the return value from insn_decode_kernel is not checked. It is a macro constructed from the insn_decode function which may fail and return negative integer. Fix this by explicitly checking the return value.

Addresses-Coverity: ("Unchecked return value")

---
 arch/x86/kernel/jump_label.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/jump_label.c +0 -0
index a762dc1c615e..bf0ea003b6e7 100644

arch/x86/kernel/jump_label.c int arch_jump_entry_size(struct jump_entry *entry) · line 26

Quoted 5 lines
arch/x86/kernel/jump_label.c +1 -1
@@ -23,7 +23,7 @@ int arch_jump_entry_size(struct jump_entry *entry)
 {
 	struct insn insn = {};
 
-	insn_decode_kernel(&insn, (void *)jump_entry_code(entry));
+	WARN_ON(insn_decode_kernel(&insn, (void *)jump_entry_code(entry)));

I don't think coverity is smart enough to notice...

Quoted 1 line
arch/x86/kernel/jump_label.c +0 -0
 	BUG_ON(insn.length != 2 && insn.length != 5);
Quoted 8 lines
Quoted 5 lines
	^^^^^^^^^^^^^

... this line.

Indeed. One needs to be careful with false positives with Coverity.

Colin

Yes. I shall be.

Thanks,

Khaled.