Skip to content

Commit ffc41cf

Browse files
snitmtorvalds
authored andcommitted
nbd: prevent sock_xmit from attempting to use a NULL socket
NBD does not protect the nbd_device's socket from becoming NULL during receives. This closes a race with the NBD_CLEAR_SOCK ioctl (nbd-client -d) setting the nbd_device's socket to NULL right before NBD calls sock_xmit. Signed-off-by: Mike Snitzer <snitzer@gmail.com> Cc: Paul Clements <paul.clements@steeleye.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent f2b2ea6 commit ffc41cf

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

‎drivers/block/nbd.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,12 @@ static int sock_xmit(struct nbd_device *lo, int send, void *buf, int size,
153153
struct kvec iov;
154154
sigset_t blocked, oldset;
155155

156+
if (unlikely(!sock)) {
157+
printk(KERN_ERR "%s: Attempted %s on closed socket in sock_xmit\n",
158+
lo->disk->disk_name, (send ? "send" : "recv"));
159+
return -EINVAL;
160+
}
161+
156162
/* Allow interception of SIGKILL only
157163
* Don't allow other signals to interrupt the transmission */
158164
siginitsetinv(&blocked, sigmask(SIGKILL));

0 commit comments

Comments
 (0)