* [PATCH] accel/kvm: Check ioctl(KVM_SET_USER_MEMORY_REGION) return value
@ 2020-02-21 16:33 Philippe Mathieu-Daudé
2020-02-21 16:44 ` Peter Xu
2020-02-21 17:03 ` Paolo Bonzini
0 siblings, 2 replies; 3+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-02-21 16:33 UTC (permalink / raw)
To: qemu-devel
Cc: kvm, Alexey Kardashevskiy, Dr . David Alan Gilbert, Peter Xu,
Paolo Bonzini, Philippe Mathieu-Daudé
kvm_vm_ioctl() can fail, check its return value, and log an error
when it failed. This fixes Coverity CID 1412229:
Unchecked return value (CHECKED_RETURN)
check_return: Calling kvm_vm_ioctl without checking return value
Reported-by: Coverity (CID 1412229)
Fixes: 235e8982ad3 ("support using KVM_MEM_READONLY flag for regions")
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
accel/kvm/kvm-all.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
index c111312dfd..6df3a4d030 100644
--- a/accel/kvm/kvm-all.c
+++ b/accel/kvm/kvm-all.c
@@ -308,13 +308,23 @@ static int kvm_set_user_memory_region(KVMMemoryListener *kml, KVMSlot *slot, boo
/* Set the slot size to 0 before setting the slot to the desired
* value. This is needed based on KVM commit 75d61fbc. */
mem.memory_size = 0;
- kvm_vm_ioctl(s, KVM_SET_USER_MEMORY_REGION, &mem);
+ ret = kvm_vm_ioctl(s, KVM_SET_USER_MEMORY_REGION, &mem);
+ if (ret < 0) {
+ goto err;
+ }
}
mem.memory_size = slot->memory_size;
ret = kvm_vm_ioctl(s, KVM_SET_USER_MEMORY_REGION, &mem);
slot->old_flags = mem.flags;
+err:
trace_kvm_set_user_memory(mem.slot, mem.flags, mem.guest_phys_addr,
mem.memory_size, mem.userspace_addr, ret);
+ if (ret < 0) {
+ error_report("%s: KVM_SET_USER_MEMORY_REGION failed, slot=%d,"
+ " start=0x%" PRIx64 ", size=0x%" PRIx64 ": %s",
+ __func__, mem.slot, slot->start_addr,
+ (uint64_t)mem.memory_size, strerror(errno));
+ }
return ret;
}
--
2.21.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] accel/kvm: Check ioctl(KVM_SET_USER_MEMORY_REGION) return value
2020-02-21 16:33 [PATCH] accel/kvm: Check ioctl(KVM_SET_USER_MEMORY_REGION) return value Philippe Mathieu-Daudé
@ 2020-02-21 16:44 ` Peter Xu
2020-02-21 17:03 ` Paolo Bonzini
1 sibling, 0 replies; 3+ messages in thread
From: Peter Xu @ 2020-02-21 16:44 UTC (permalink / raw)
To: Philippe Mathieu-Daudé
Cc: Alexey Kardashevskiy, Paolo Bonzini, qemu-devel, kvm,
Dr . David Alan Gilbert
On Fri, Feb 21, 2020 at 05:33:36PM +0100, Philippe Mathieu-Daudé wrote:
> kvm_vm_ioctl() can fail, check its return value, and log an error
> when it failed. This fixes Coverity CID 1412229:
>
> Unchecked return value (CHECKED_RETURN)
>
> check_return: Calling kvm_vm_ioctl without checking return value
>
> Reported-by: Coverity (CID 1412229)
> Fixes: 235e8982ad3 ("support using KVM_MEM_READONLY flag for regions")
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Peter Xu <peterx@redhat.com>
--
Peter Xu
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] accel/kvm: Check ioctl(KVM_SET_USER_MEMORY_REGION) return value
2020-02-21 16:33 [PATCH] accel/kvm: Check ioctl(KVM_SET_USER_MEMORY_REGION) return value Philippe Mathieu-Daudé
2020-02-21 16:44 ` Peter Xu
@ 2020-02-21 17:03 ` Paolo Bonzini
1 sibling, 0 replies; 3+ messages in thread
From: Paolo Bonzini @ 2020-02-21 17:03 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
Cc: Alexey Kardashevskiy, kvm, Peter Xu, Dr . David Alan Gilbert
On 21/02/20 17:33, Philippe Mathieu-Daudé wrote:
> kvm_vm_ioctl() can fail, check its return value, and log an error
> when it failed. This fixes Coverity CID 1412229:
>
> Unchecked return value (CHECKED_RETURN)
>
> check_return: Calling kvm_vm_ioctl without checking return value
>
> Reported-by: Coverity (CID 1412229)
> Fixes: 235e8982ad3 ("support using KVM_MEM_READONLY flag for regions")
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> ---
> accel/kvm/kvm-all.c | 12 +++++++++++-
> 1 file changed, 11 insertions(+), 1 deletion(-)
>
> diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
> index c111312dfd..6df3a4d030 100644
> --- a/accel/kvm/kvm-all.c
> +++ b/accel/kvm/kvm-all.c
> @@ -308,13 +308,23 @@ static int kvm_set_user_memory_region(KVMMemoryListener *kml, KVMSlot *slot, boo
> /* Set the slot size to 0 before setting the slot to the desired
> * value. This is needed based on KVM commit 75d61fbc. */
> mem.memory_size = 0;
> - kvm_vm_ioctl(s, KVM_SET_USER_MEMORY_REGION, &mem);
> + ret = kvm_vm_ioctl(s, KVM_SET_USER_MEMORY_REGION, &mem);
> + if (ret < 0) {
> + goto err;
> + }
> }
> mem.memory_size = slot->memory_size;
> ret = kvm_vm_ioctl(s, KVM_SET_USER_MEMORY_REGION, &mem);
> slot->old_flags = mem.flags;
> +err:
> trace_kvm_set_user_memory(mem.slot, mem.flags, mem.guest_phys_addr,
> mem.memory_size, mem.userspace_addr, ret);
> + if (ret < 0) {
> + error_report("%s: KVM_SET_USER_MEMORY_REGION failed, slot=%d,"
> + " start=0x%" PRIx64 ", size=0x%" PRIx64 ": %s",
> + __func__, mem.slot, slot->start_addr,
> + (uint64_t)mem.memory_size, strerror(errno));
> + }
> return ret;
> }
>
>
Queued, thanks.
Paolo
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-02-21 17:05 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-02-21 16:33 [PATCH] accel/kvm: Check ioctl(KVM_SET_USER_MEMORY_REGION) return value Philippe Mathieu-Daudé
2020-02-21 16:44 ` Peter Xu
2020-02-21 17:03 ` Paolo Bonzini
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).