All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jiri Slaby <jirislaby@gmail.com>
To: "Michael S. Tsirkin" <mst@redhat.com>
Cc: netdev@vger.kernel.org, LKML <linux-kernel@vger.kernel.org>
Subject: locking issue in vhost_net_set_backend
Date: Tue, 16 Mar 2010 14:58:23 +0100	[thread overview]
Message-ID: <4B9F8E7F.7070709@gmail.com> (raw)

Hi,

Stanse found a locking problem in the following function:

static long vhost_net_set_backend(struct vhost_net *n, unsigned index, 
int fd)
{
         struct socket *sock, *oldsock;
         struct vhost_virtqueue *vq;
         int r;

         mutex_lock(&n->dev.mutex);
         r = vhost_dev_check_owner(&n->dev);
         if (r)
                 goto err;

         if (index >= VHOST_NET_VQ_MAX) {
                 r = -ENOBUFS;
                 goto err;
         }
         vq = n->vqs + index;
         mutex_lock(&vq->mutex);        <---  locked

         /* Verify that ring has been setup correctly. */
         if (!vhost_vq_access_ok(vq)) {
                 r = -EFAULT;
                 goto err;              <--- not unlocked
         }
         sock = get_socket(fd);
         if (IS_ERR(sock)) {
                 r = PTR_ERR(sock);
                 goto err;              <--- not unlocked
         }

         /* start polling new socket */
         oldsock = vq->private_data;
         if (sock == oldsock)
                 goto done;             <--- not unlocked

         vhost_net_disable_vq(n, vq);
         rcu_assign_pointer(vq->private_data, sock);
         vhost_net_enable_vq(n, vq);
         mutex_unlock(&vq->mutex);
done:
         if (oldsock) {
                 vhost_net_flush_vq(n, index);
                 fput(oldsock->file);
         }
err:
         mutex_unlock(&n->dev.mutex);
         return r;
}


I don't see how the lock is unlocked on the error paths and as it is not 
on none of the them maybe I'm missing something?

thanks,
-- 
js

             reply	other threads:[~2010-03-16 13:58 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-16 13:58 Jiri Slaby [this message]
2010-03-16 14:01 ` locking issue in vhost_net_set_backend Jiri Slaby
2010-03-16 14:48   ` Michael S. Tsirkin
2010-03-16 16:11 ` Jeff Dike

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4B9F8E7F.7070709@gmail.com \
    --to=jirislaby@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.