All of lore.kernel.org
 help / color / mirror / Atom feed
* vhost-vdpa potential fd leak (coverity issue)
@ 2025-07-10 15:46 Peter Maydell
  2025-07-10 16:40 ` Michael S. Tsirkin
  0 siblings, 1 reply; 7+ messages in thread
From: Peter Maydell @ 2025-07-10 15:46 UTC (permalink / raw)
  To: QEMU Developers
  Cc: Jason Wang, Eugenio Pérez, Michael S. Tsirkin,
	Stefano Garzarella

Hi; Coverity complains about a potential filedescriptor leak in
net/vhost-vdpa.c:net_init_vhost_vdpa(). This is CID 1490785.

Specifically, in this function we do:
    queue_pairs = vhost_vdpa_get_max_queue_pairs(vdpa_device_fd, features,
                                                 &has_cvq, errp);
    if (queue_pairs < 0) {
        [exit with failure]
    }
    ...
    ncs = g_malloc0(sizeof(*ncs) * queue_pairs);
    for (i = 0; i < queue_pairs; i++) {
       ...
       ncs[i] = net_vhost_vdpa_init(..., vdpa_device_fd, ...)
       ...
    }
    if (has_cvq) {
       ...
       nc = net_host_vdpa_init(..., vdpa_device_fd, ...)
       ...
    }

So if queue_pairs is zero we will malloc(0) which seems dubious;
and if queue_pairs is zero and has_cvq is false then the init
function will exit success without ever calling net_vhost_vdpa_init()
and it will leak the vdpa_device_fd.

My guess is that queue_pairs == 0 should be an error, or possibly
that (queue_pairs == 0 && !has_cvq) should be an error.

Could somebody who knows more about this code tell me which, and
perhaps produce a patch to make it handle that case?

Q: should this file be listed in the "vhost" subcategory of MAINTAINERS?
At the moment it only gets caught by "Network device backends".

thanks
-- PMM


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2025-07-14 10:33 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-10 15:46 vhost-vdpa potential fd leak (coverity issue) Peter Maydell
2025-07-10 16:40 ` Michael S. Tsirkin
2025-07-14  9:18   ` Stefano Garzarella
2025-07-14  9:48     ` Peter Maydell
2025-07-14 10:33       ` Stefano Garzarella
2025-07-14  9:57     ` Michael S. Tsirkin
2025-07-14 10:20     ` Stefano Garzarella

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.