From nobody Mon Nov 23 04:32:08 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1794205472; cv=none; d=zohomail.com; s=zohoarc; b=JSZx5EPlAR3n2OaTX6O0X0YFSzr70wKSWUB+SqQt9rdNot68HKjfk4JZddXfurgJnTYojdLs8KSWcb49mSqdvR9O8LAFDnsOrxg7FkSuIXlAZSIZBKOLVBEqAxt3tMoBWrDxcRnz7fI5k6YiWkxTxrlB4bAdGtQuqpO8yXbZQdU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794205472; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=54Yt/HRHUf73M1ZeOD79PJvJP775P4DcRNSZq34Dw+o=; b=jzs5dm6i+geDGB61eG7/9537ySf2fK81DBHUe8lDmO9hdNSfQ/wM5T3Cvip6D3rV2H26EqiQks1cIwehq0RkRX9v8t5yoa6V5o4qZ0513E7oEU1g088Pn68IafRTsy9IW7V5llzWdpb5A6DiM1bM+g39VyFGz+tBQG8fX4OxQWo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794205472649633.8127979180313; Sun, 8 Nov 2026 22:24:32 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xQInk-00023T-7O; Mon, 09 Nov 2026 01:24:23 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xQInf-000233-9u for qemu-devel@nongnu.org; Mon, 09 Nov 2026 01:24:17 -0500 Received: from forwardcorp1d.mail.yandex.net ([178.154.239.200]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xQInb-0002h5-04 for qemu-devel@nongnu.org; Mon, 09 Nov 2026 01:24:14 -0500 Received: from mail-nwsmtp-smtp-corp-main-68 (mail-nwsmtp-smtp-corp-main-68.yp-c.yandex.net) by forwardcorp1d.mail.yandex.net (postfix) with ESMTPS id 2D18480844; Mon, 09 Nov 2026 09:24:07 +0300 (MSK) Received: from dtalexundeer-nx.yandex-team.ru by mail-nwsmtp-smtp-corp-main-68 with ESMTPSA id nNKLppCamiE0-HKe8ksFt; Mon, 09 Nov 2026 09:24:06 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1794205446; bh=54Yt/HRHUf73M1ZeOD79PJvJP775P4DcRNSZq34Dw+o=; h=Message-Id:Date:Cc:Subject:To:From; b=aYaEtiYQPsf0eCxIz0iBy2oElQFaUnCvxxPvXx7oQUJlUT78MGlTayMYn1LVKArVf tlKXRzIDiqCD8UKCegw9VACD37zPweQdHVuOfnZcIMmvHnBXm+u7/+9TwA6e7O/uwR 5DAFlSt6Wz4yoaGv9ot7BcIGndf1GBeVJnHlGlQc= Authentication-Results: mail-nwsmtp-smtp-corp-main-68; dkim=pass header.i=@yandex-team.ru From: Alexandr Moshkov To: qemu-devel@nongnu.org Cc: "Dr . David Alan Gilbert" , "yc-core@yandex-team.ru" , Stefan Hajnoczi , "Michael S. Tsirkin" , virtio-fs@lists.linux.dev, Stefano Garzarella , Alexandr Moshkov Subject: [PATCH v2] vhost-user-fs: fix virtqueue array leak on realize failure Date: Mon, 9 Nov 2026 11:24:01 +0500 Message-Id: <20261109062401.81161-1-dtalexundeer@yandex-team.ru> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=lists1p.gnu.org; Received-SPF: pass client-ip=178.154.239.200; envelope-from=dtalexundeer@yandex-team.ru; helo=forwardcorp1d.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1794205475718158500 Content-Type: text/plain; charset="utf-8" On failure, vhost_dev_init() clears vhost_dev, so the error path frees NULL instead of the virtqueue array. Keep the pointer in the existing vhost_vqs field and use it to free the array on failure and unrealize. Fixes: 98fc1ada4cf7 ("virtio: add vhost-user-fs base device") Signed-off-by: Alexandr Moshkov Reviewed-by: Stefano Garzarella --- v1 -> v2: - use the existing VHostUserFS.vhost_vqs field in realize and unrealize instead of local vars. hw/virtio/vhost-user-fs.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/hw/virtio/vhost-user-fs.c b/hw/virtio/vhost-user-fs.c index 0d8842817a..f26b5b611a 100644 --- a/hw/virtio/vhost-user-fs.c +++ b/hw/virtio/vhost-user-fs.c @@ -255,7 +255,8 @@ static void vuf_device_realize(DeviceState *dev, Error = **errp) =20 /* 1 high prio queue, plus the number configured */ fs->vhost_dev.nvqs =3D 1 + fs->conf.num_request_queues; - fs->vhost_dev.vqs =3D g_new0(struct vhost_virtqueue, fs->vhost_dev.nvq= s); + fs->vhost_vqs =3D g_new0(struct vhost_virtqueue, fs->vhost_dev.nvqs); + fs->vhost_dev.vqs =3D fs->vhost_vqs; ret =3D vhost_dev_init(&fs->vhost_dev, &fs->vhost_user, VHOST_BACKEND_TYPE_USER, 0, errp); if (ret < 0) { @@ -272,14 +273,14 @@ err_virtio: } g_free(fs->req_vqs); virtio_cleanup(vdev); - g_free(fs->vhost_dev.vqs); + g_free(fs->vhost_vqs); + fs->vhost_vqs =3D NULL; } =20 static void vuf_device_unrealize(DeviceState *dev) { VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); VHostUserFS *fs =3D VHOST_USER_FS(dev); - struct vhost_virtqueue *vhost_vqs =3D fs->vhost_dev.vqs; int i; =20 /* This will stop vhost backend if appropriate. */ @@ -295,7 +296,8 @@ static void vuf_device_unrealize(DeviceState *dev) } g_free(fs->req_vqs); virtio_cleanup(vdev); - g_free(vhost_vqs); + g_free(fs->vhost_vqs); + fs->vhost_vqs =3D NULL; } =20 static struct vhost_dev *vuf_get_vhost(VirtIODevice *vdev) --=20 2.34.1