From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56377) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ws9FJ-00053m-2L for qemu-devel@nongnu.org; Wed, 04 Jun 2014 07:20:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ws9FA-0005rN-1l for qemu-devel@nongnu.org; Wed, 04 Jun 2014 07:20:41 -0400 Received: from mail-wi0-x236.google.com ([2a00:1450:400c:c05::236]:43174) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ws9F9-0005qt-Hu for qemu-devel@nongnu.org; Wed, 04 Jun 2014 07:20:31 -0400 Received: by mail-wi0-f182.google.com with SMTP id r20so1233209wiv.3 for ; Wed, 04 Jun 2014 04:20:29 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Date: Wed, 4 Jun 2014 13:20:09 +0200 Message-Id: <1401880812-818-9-git-send-email-pbonzini@redhat.com> In-Reply-To: <1401880812-818-1-git-send-email-pbonzini@redhat.com> References: <1401880812-818-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PULL 08/11] kvm: Ensure negative return value on kvm_init() error handling path List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Eduardo Habkost From: Eduardo Habkost We need to ensure ret < 0 when going through the error path, or QEMU may try to run the half-initialized VM and crash. Signed-off-by: Eduardo Habkost Signed-off-by: Paolo Bonzini --- kvm-all.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/kvm-all.c b/kvm-all.c index a343ede..f7fe9c6 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -1374,7 +1374,7 @@ int kvm_init(MachineClass *mc) ret = kvm_ioctl(s, KVM_GET_API_VERSION, 0); if (ret < KVM_API_VERSION) { - if (ret > 0) { + if (ret >= 0) { ret = -EINVAL; } fprintf(stderr, "kvm version too old\n"); @@ -1425,6 +1425,7 @@ int kvm_init(MachineClass *mc) if (mc->kvm_type) { type = mc->kvm_type(kvm_type); } else if (kvm_type) { + ret = -EINVAL; fprintf(stderr, "Invalid argument kvm-type=%s\n", kvm_type); goto err; } @@ -1525,6 +1526,7 @@ int kvm_init(MachineClass *mc) return 0; err: + assert(ret < 0); if (s->vmfd >= 0) { close(s->vmfd); } -- 1.8.3.1