On Tue, Sep 17, 2019 at 02:25:59PM +0200, Johannes Berg wrote: > diff --git a/contrib/libvhost-user/libvhost-user.c b/contrib/libvhost-user/libvhost-user.c > index f1677da21201..17b7833d1f6b 100644 > --- a/contrib/libvhost-user/libvhost-user.c > +++ b/contrib/libvhost-user/libvhost-user.c > @@ -920,6 +920,7 @@ static bool > vu_check_queue_msg_file(VuDev *dev, VhostUserMsg *vmsg) > { > int index = vmsg->payload.u64 & VHOST_USER_VRING_IDX_MASK; > + bool nofd = vmsg->payload.u64 & VHOST_USER_VRING_NOFD_MASK; > > if (index >= dev->max_queues) { > vmsg_close_fds(vmsg); > @@ -927,8 +928,12 @@ vu_check_queue_msg_file(VuDev *dev, VhostUserMsg *vmsg) > return false; > } > > - if (vmsg->payload.u64 & VHOST_USER_VRING_NOFD_MASK || > - vmsg->fd_num != 1) { > + if (nofd) { > + vmsg_close_fds(vmsg); > + return true; > + } With the following change to vmsg_close_fds(): for (i = 0; i < vmsg->fd_num; i++) { close(vmsg->fds[i]); } + for (i = 0; i < sizeof(vmsg->fd_num) / sizeof(vmsg->fd_num[0]); i++) { + vmsg->fds[i] = -1; + } + vmsg->fd_num = 0; ...the message handler functions below can use vmsg->fds[0] (-1) without worrying about NOFD. This makes the code simpler.