qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] kvm: Potential NULL pointer dereference in kvm_arch_init_vcpu()
@ 2019-01-30 14:49 Liam Merwick
  2019-01-30 15:20 ` Paolo Bonzini
  2019-01-31 18:01 ` no-reply
  0 siblings, 2 replies; 3+ messages in thread
From: Liam Merwick @ 2019-01-30 14:49 UTC (permalink / raw)
  To: rth, ehabkost, qemu-devel; +Cc: pbonzini, mtosatti, liam.merwick

From: Liam Merwick <Liam.Merwick@oracle.com>

In kvm_arch_init_vcpu() a call to cpuid_find_entry() can return
NULL so the pointer returned should be checked before dereferencing it.

Reported by the Parfait static code analysis tool

Signed-off-by: Liam Merwick <Liam.Merwick@oracle.com>
---
 target/i386/kvm.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/target/i386/kvm.c b/target/i386/kvm.c
index 9af4542fb8a8..89fac4a5576c 100644
--- a/target/i386/kvm.c
+++ b/target/i386/kvm.c
@@ -1308,7 +1308,9 @@ int kvm_arch_init_vcpu(CPUState *cs)
         c->ecx = c->edx = 0;
 
         c = cpuid_find_entry(&cpuid_data.cpuid, kvm_base, 0);
-        c->eax = MAX(c->eax, KVM_CPUID_SIGNATURE | 0x10);
+        if (c) {
+            c->eax = MAX(c->eax, KVM_CPUID_SIGNATURE | 0x10);
+	}
     }
 
     cpuid_data.cpuid.nent = cpuid_i;
-- 
1.8.3.1

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

* Re: [Qemu-devel] [PATCH] kvm: Potential NULL pointer dereference in kvm_arch_init_vcpu()
  2019-01-30 14:49 [Qemu-devel] [PATCH] kvm: Potential NULL pointer dereference in kvm_arch_init_vcpu() Liam Merwick
@ 2019-01-30 15:20 ` Paolo Bonzini
  2019-01-31 18:01 ` no-reply
  1 sibling, 0 replies; 3+ messages in thread
From: Paolo Bonzini @ 2019-01-30 15:20 UTC (permalink / raw)
  To: Liam Merwick, rth, ehabkost, qemu-devel; +Cc: mtosatti

On 30/01/19 15:49, Liam Merwick wrote:
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/target/i386/kvm.c b/target/i386/kvm.c
> index 9af4542fb8a8..89fac4a5576c 100644
> --- a/target/i386/kvm.c
> +++ b/target/i386/kvm.c
> @@ -1308,7 +1308,9 @@ int kvm_arch_init_vcpu(CPUState *cs)
>          c->ecx = c->edx = 0;
>  
>          c = cpuid_find_entry(&cpuid_data.cpuid, kvm_base, 0);
> -        c->eax = MAX(c->eax, KVM_CPUID_SIGNATURE | 0x10);
> +        if (c) {
> +            c->eax = MAX(c->eax, KVM_CPUID_SIGNATURE | 0x10);
> +	}
>      }
>  
>      cpuid_data.cpuid.nent = cpuid_i;
> -- 1.8.3.1

That cannot happen, the line is inside "if (cpu->expose_kvm)" which in
turn has added that CPUID entry to cpuid_data.

Thanks,

Paolo

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

* Re: [Qemu-devel] [PATCH] kvm: Potential NULL pointer dereference in kvm_arch_init_vcpu()
  2019-01-30 14:49 [Qemu-devel] [PATCH] kvm: Potential NULL pointer dereference in kvm_arch_init_vcpu() Liam Merwick
  2019-01-30 15:20 ` Paolo Bonzini
@ 2019-01-31 18:01 ` no-reply
  1 sibling, 0 replies; 3+ messages in thread
From: no-reply @ 2019-01-31 18:01 UTC (permalink / raw)
  To: liam.merwick; +Cc: fam, rth, ehabkost, qemu-devel, pbonzini, mtosatti

Patchew URL: https://patchew.org/QEMU/1548859760-10654-1-git-send-email-liam.merwick@oracle.com/



Hi,

This series seems to have some coding style problems. See output below for
more information:

Subject: [Qemu-devel] [PATCH] kvm: Potential NULL pointer dereference in kvm_arch_init_vcpu()
Type: series
Message-id: 1548859760-10654-1-git-send-email-liam.merwick@oracle.com

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
Switched to a new branch 'test'
f01539b22b kvm: Potential NULL pointer dereference in kvm_arch_init_vcpu()

=== OUTPUT BEGIN ===
ERROR: code indent should never use tabs
#26: FILE: target/i386/kvm.c:1313:
+^I}$

total: 1 errors, 0 warnings, 10 lines checked

Commit f01539b22bda (kvm: Potential NULL pointer dereference in kvm_arch_init_vcpu()) has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
=== OUTPUT END ===

Test command exited with code: 1


The full log is available at
http://patchew.org/logs/1548859760-10654-1-git-send-email-liam.merwick@oracle.com/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to patchew-devel@redhat.com

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

end of thread, other threads:[~2019-01-31 18:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-01-30 14:49 [Qemu-devel] [PATCH] kvm: Potential NULL pointer dereference in kvm_arch_init_vcpu() Liam Merwick
2019-01-30 15:20 ` Paolo Bonzini
2019-01-31 18:01 ` no-reply

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).