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")
Signed-off-by: Khaled ROMDHANI <[email protected]>
---
arch/x86/kernel/jump_label.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c
index a762dc1c615e..bf0ea003b6e7 100644
--- a/arch/x86/kernel/jump_label.c
+++ b/arch/x86/kernel/jump_label.c
@@ -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;
--
2.17.1
On 15/05/2021 21:36, Borislav Petkov wrote:
> On Sat, May 15, 2021 at 09:22:12PM +0100, Khaled ROMDHANI wrote:
>> 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")
>> Signed-off-by: Khaled ROMDHANI <[email protected]>
>> ---
>> arch/x86/kernel/jump_label.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c
>> index a762dc1c615e..bf0ea003b6e7 100644
>> --- a/arch/x86/kernel/jump_label.c
>> +++ b/arch/x86/kernel/jump_label.c
>> @@ -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...
>
>> BUG_ON(insn.length != 2 && insn.length != 5);
> ^^^^^^^^^^^^^
>
> ... this line.
>
>
Indeed. One needs to be careful with false positives with Coverity.
Colin
On Sat, May 15, 2021 at 09:22:12PM +0100, Khaled ROMDHANI wrote:
> 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")
> Signed-off-by: Khaled ROMDHANI <[email protected]>
> ---
> arch/x86/kernel/jump_label.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c
> index a762dc1c615e..bf0ea003b6e7 100644
> --- a/arch/x86/kernel/jump_label.c
> +++ b/arch/x86/kernel/jump_label.c
> @@ -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...
> BUG_ON(insn.length != 2 && insn.length != 5);
^^^^^^^^^^^^^
... this line.
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette
On Sat, May 15, 2021 at 09:51:23PM +0100, Colin Ian King wrote:
> On 15/05/2021 21:36, Borislav Petkov wrote:
> > On Sat, May 15, 2021 at 09:22:12PM +0100, Khaled ROMDHANI wrote:
> >> 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")
> >> Signed-off-by: Khaled ROMDHANI <[email protected]>
> >> ---
> >> arch/x86/kernel/jump_label.c | 2 +-
> >> 1 file changed, 1 insertion(+), 1 deletion(-)
> >>
> >> diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c
> >> index a762dc1c615e..bf0ea003b6e7 100644
> >> --- a/arch/x86/kernel/jump_label.c
> >> +++ b/arch/x86/kernel/jump_label.c
> >> @@ -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...
> >
> >> BUG_ON(insn.length != 2 && insn.length != 5);
> > ^^^^^^^^^^^^^
> >
> > ... this line.
> >
> >
> Indeed. One needs to be careful with false positives with Coverity.
>
> Colin
Yes. I shall be.
Thanks,
Khaled.