From nobody Sat May 4 19:20:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1582303082; cv=none; d=zohomail.com; s=zohoarc; b=hkMpY+ND3+i9gQgv1dvxGziI6TSGAh0srMxOinkTwE+rof0dUG1gd1CeferUDOTZSCBoNCjWtlSueILyeOqVL566RXWSm2eHPNtkNEZ22emCuEstDmU2bFoyBIgvqVkbrIWhsF5lkzJ/Wkt/nGoCTJhMP3zjVS5bAEd50tALIAc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582303082; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=wXH6buGbOPhKCWB/KVR+J3wk1Wee9B4Tm+VBngLJ41E=; b=D5oWYgoOyl20yTu6kHUgkXBggrugHMQGrzCb3C+S9NRejdGY6fQZp9cCY5VJeAhGgKlYjyt4ctLelAz/s+ZI0U5tzhCtcv7sy+AIBF57YaiYvCanq2XalKY0SKHv9pkzNwcQXcFhEl4ipz8ZvhMxz4Zg89aFpvczCl07xWzwMG4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1582303082121927.0482421264761; Fri, 21 Feb 2020 08:38:02 -0800 (PST) Received: from localhost ([::1]:32910 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j5BJR-0000Iv-3f for importer@patchew.org; Fri, 21 Feb 2020 11:38:01 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:49857) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j5BFI-0002fq-EP for qemu-devel@nongnu.org; Fri, 21 Feb 2020 11:33:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j5BFG-0000n0-JW for qemu-devel@nongnu.org; Fri, 21 Feb 2020 11:33:43 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:36772 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j5BFG-0000me-FD for qemu-devel@nongnu.org; Fri, 21 Feb 2020 11:33:42 -0500 Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-151-CqC4uns-MMq6H-EHp8E9tA-1; Fri, 21 Feb 2020 11:33:40 -0500 Received: by mail-wr1-f71.google.com with SMTP id c6so1234619wrm.18 for ; Fri, 21 Feb 2020 08:33:39 -0800 (PST) Received: from x1w.redhat.com (78.red-88-21-202.staticip.rima-tde.net. [88.21.202.78]) by smtp.gmail.com with ESMTPSA id c15sm4522493wrt.1.2020.02.21.08.33.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Feb 2020 08:33:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582302821; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=wXH6buGbOPhKCWB/KVR+J3wk1Wee9B4Tm+VBngLJ41E=; b=XzjINIJ8X081FZZOIB7NKnAnD8XQ5SyAYV3KvlNz33KQ5XA/Hk57E4OKr5IiJs3MpUwDoH Zlwv5uqottpjbPCfXPWHkI2RLVLqAtbfoRCNk1ehiIxd7xpfcwetiQV4xdutA4svaAaOgv O0x+JTnDWbp0RWJLxWUhSpoqqbv8N3w= X-MC-Unique: CqC4uns-MMq6H-EHp8E9tA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=+wtlMqiYMfAtECyCFeq4h5JvYyRA49l8lzkwzoiW88E=; b=mavpUFO44IhyXSAm2+Hz+Qx5MnxhEZJlpSfVDSh4Uoc5QvHQBZh8vX44JeNXIWId2P w1KUjtLzZ4KBidwfDLhZ1xoWXbV4VZeBceU8qKJpSepLTSjTFGqypnPb+VJmvv1TjQ9V nWg9ZV4MEZauy//r/4PHQtfKMlaiWF9I/qG4590ESzLesqb6GgyNRBYElPrQBYUi7Hnh 7T9MOUIQQtXE0VGFsRRVyl9/KZSQQ6ZIaxbu+l1/ime/A4mQ1Vi0DwghfeGZQuKvDZNL f2L1ELbJYiYQAbX9uGeasoRge0OzzKAdmSxMSG8kqMc/8hJAQ5J6Wmkcrhe0QqJ5D1em GIiQ== X-Gm-Message-State: APjAAAUVH/CWUAjE9hvIGItP/3rGoqdbpfiNbYBvh2oBn6nGCq7mrgn2 RHfLyw6PsIwbSpSRUmOqI4+laLDGtVswq5tSc6ciMo/55a0YAUOG08bahsqY1+reH7eC3Jw1Bjy +5lx4M+t4DWzoxHA= X-Received: by 2002:a5d:6411:: with SMTP id z17mr52257866wru.57.1582302818494; Fri, 21 Feb 2020 08:33:38 -0800 (PST) X-Google-Smtp-Source: APXvYqw/P0AiFwTiT7z/wiXEONKmFEX/+8KKpJaNr4hGDqfwDZfa9AgZLuHo195clbdhIrrAhDaBiQ== X-Received: by 2002:a5d:6411:: with SMTP id z17mr52257842wru.57.1582302818224; Fri, 21 Feb 2020 08:33:38 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH] accel/kvm: Check ioctl(KVM_SET_USER_MEMORY_REGION) return value Date: Fri, 21 Feb 2020 17:33:36 +0100 Message-Id: <20200221163336.2362-1-philmd@redhat.com> X-Mailer: git-send-email 2.21.1 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kvm@vger.kernel.org, Alexey Kardashevskiy , "Dr . David Alan Gilbert" , Peter Xu , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8"; text/plain; charset="utf-8" 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=C3=A9 Reviewed-by: Peter Xu --- 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(KVMMemoryListen= er *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 =3D 0; - kvm_vm_ioctl(s, KVM_SET_USER_MEMORY_REGION, &mem); + ret =3D kvm_vm_ioctl(s, KVM_SET_USER_MEMORY_REGION, &mem); + if (ret < 0) { + goto err; + } } mem.memory_size =3D slot->memory_size; ret =3D kvm_vm_ioctl(s, KVM_SET_USER_MEMORY_REGION, &mem); slot->old_flags =3D 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=3D%d," + " start=3D0x%" PRIx64 ", size=3D0x%" PRIx64 ": %s", + __func__, mem.slot, slot->start_addr, + (uint64_t)mem.memory_size, strerror(errno)); + } return ret; } =20 --=20 2.21.1