Skip to content

Commit 535297a

Browse files
committed
vhost: fix error handling in vring ioctls
Stanse found a locking problem in vhost_set_vring: several returns from VHOST_SET_VRING_KICK, VHOST_SET_VRING_CALL, VHOST_SET_VRING_ERR with the vq->mutex held. Fix these up. Reported-by: Jiri Slaby <[email protected]> Acked-by: Laurent Chavey <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]>
1 parent 0e25557 commit 535297a

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

drivers/vhost/vhost.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -476,8 +476,10 @@ static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
476476
if (r < 0)
477477
break;
478478
eventfp = f.fd == -1 ? NULL : eventfd_fget(f.fd);
479-
if (IS_ERR(eventfp))
480-
return PTR_ERR(eventfp);
479+
if (IS_ERR(eventfp)) {
480+
r = PTR_ERR(eventfp);
481+
break;
482+
}
481483
if (eventfp != vq->kick) {
482484
pollstop = filep = vq->kick;
483485
pollstart = vq->kick = eventfp;
@@ -489,8 +491,10 @@ static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
489491
if (r < 0)
490492
break;
491493
eventfp = f.fd == -1 ? NULL : eventfd_fget(f.fd);
492-
if (IS_ERR(eventfp))
493-
return PTR_ERR(eventfp);
494+
if (IS_ERR(eventfp)) {
495+
r = PTR_ERR(eventfp);
496+
break;
497+
}
494498
if (eventfp != vq->call) {
495499
filep = vq->call;
496500
ctx = vq->call_ctx;
@@ -505,8 +509,10 @@ static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
505509
if (r < 0)
506510
break;
507511
eventfp = f.fd == -1 ? NULL : eventfd_fget(f.fd);
508-
if (IS_ERR(eventfp))
509-
return PTR_ERR(eventfp);
512+
if (IS_ERR(eventfp)) {
513+
r = PTR_ERR(eventfp);
514+
break;
515+
}
510516
if (eventfp != vq->error) {
511517
filep = vq->error;
512518
vq->error = eventfp;

0 commit comments

Comments
 (0)