From nobody Thu Nov 13 20:40:38 2025 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; 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 ARC-Seal: i=1; a=rsa-sha256; t=1582526675; cv=none; d=zohomail.com; s=zohoarc; b=CJ4SOtyioG8AMoXVuwjTATtuHx26udbpSe3QbattLTEe8Wuvrw2W0S5yEd8soxBdNFPlD93e2+BhFVIYlsWGaOB5iDlUxF+UYSBpZ7PbSJgOaK+iW0/yU9SRJgexu5blDvRCOmwf9dpcqPsIMeZAW6N07R3G+oQYtc8ZCLWIYTg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582526675; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=lGcGwBBlwA60tfWZXda8MC9iS5912yUNj+EPVEd+5xg=; b=c1gOfKdOllPXSRDH6AQ6vLJmTgm19wT4lCLdOGJ2vz3BnyFeekZS3CYCTDFE274/+rUgWAW/32IkoovA8WJhMR5jvIUaNcN2lL8bVIYJwt29R/fu7/j4t+3a3z618xF/cOyOIvqx7gziKmmDCO3CZddg/fIHG+491Y3DDi/1Tp4= ARC-Authentication-Results: i=1; mx.zohomail.com; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 158252667553821.264571566476548; Sun, 23 Feb 2020 22:44:35 -0800 (PST) Received: from localhost ([::1]:60544 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j67Tm-00016w-JI for importer@patchew.org; Mon, 24 Feb 2020 01:44:34 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:47383) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j67S9-000792-WB for qemu-devel@nongnu.org; Mon, 24 Feb 2020 01:42:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j67S9-0008WJ-1h for qemu-devel@nongnu.org; Mon, 24 Feb 2020 01:42:53 -0500 Received: from szxga07-in.huawei.com ([45.249.212.35]:56942 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j67S8-0008V1-MF for qemu-devel@nongnu.org; Mon, 24 Feb 2020 01:42:52 -0500 Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 836BE7125658CEED0852; Mon, 24 Feb 2020 14:42:50 +0800 (CST) Received: from DESKTOP-27KDQMV.china.huawei.com (10.173.228.124) by DGGEMS405-HUB.china.huawei.com (10.3.19.205) with Microsoft SMTP Server id 14.3.439.0; Mon, 24 Feb 2020 14:42:43 +0800 From: "Longpeng(Mike)" To: , Subject: [PATCH RESEND 2/3] vhost: fix a null pointer reference of vhost_log Date: Mon, 24 Feb 2020 14:42:18 +0800 Message-ID: <20200224064219.1434-3-longpeng2@huawei.com> X-Mailer: git-send-email 2.25.0.windows.1 In-Reply-To: <20200224064219.1434-1-longpeng2@huawei.com> References: <20200224064219.1434-1-longpeng2@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.173.228.124] X-CFilter-Loop: Reflected 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: 45.249.212.35 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: longpeng2@huawei.com, arei.gonglei@huawei.com, huangzhichao@huawei.com, qemu-devel@nongnu.org, weifuqiang@huawei.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Longpeng vhost_log_alloc() may fails and returned pointer of log is null. However there're two places derefernce the return pointer without check. Signed-off-by: Longpeng --- hw/virtio/vhost.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 9edfadc..c7ad6e5 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -219,6 +219,10 @@ static struct vhost_log *vhost_log_get(uint64_t size, = bool share) =20 if (!log || log->size !=3D size) { log =3D vhost_log_alloc(size, share); + if (!log) { + return NULL; + } + if (share) { vhost_log_shm =3D log; } else { @@ -270,10 +274,17 @@ static bool vhost_dev_log_is_shared(struct vhost_dev = *dev) =20 static inline void vhost_dev_log_resize(struct vhost_dev *dev, uint64_t si= ze) { - struct vhost_log *log =3D vhost_log_get(size, vhost_dev_log_is_shared(= dev)); - uint64_t log_base =3D (uintptr_t)log->log; + struct vhost_log *log; + uint64_t log_base; int r; =20 + log =3D vhost_log_get(size, vhost_dev_log_is_shared(dev)); + if (!log) { + return; + } + + log_base =3D (uintptr_t)log->log; + /* inform backend of log switching, this must be done before releasing the current log, to ensure no logging is lost */ r =3D dev->vhost_ops->vhost_set_log_base(dev, log_base, log); @@ -1640,6 +1651,10 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODe= vice *vdev) hdev->log_size =3D vhost_get_log_size(hdev); hdev->log =3D vhost_log_get(hdev->log_size, vhost_dev_log_is_shared(hdev)); + if (!hdev->log) { + goto fail_vq; + } + log_base =3D (uintptr_t)hdev->log->log; r =3D hdev->vhost_ops->vhost_set_log_base(hdev, hdev->log_size ? log_base = : 0, --=20 1.8.3.1