Skip to contentSkip to conversation

nbd: prevent sock_xmit from attempting to use a NULL socket

PATCH New Mike Snitzer 1 participant 1 message Mar 28, 2008

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

---
 drivers/block/nbd.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
drivers/block/nbd.c +6 -0
index b53fdb0..bd3c50b 100644
@@ -153,6 +153,12 @@ static int sock_xmit(struct nbd_device *lo, int send, void *buf, int size,
 	struct kvec iov;
 	sigset_t blocked, oldset;
 
+	if (unlikely(!sock)) {
+		printk(KERN_ERR "%s: Attempted %s on closed socket in sock_xmit\n",
+		       lo->disk->disk_name, (send ? "send" : "recv"));
+		return -EINVAL;
+	}
+
 	/* Allow interception of SIGKILL only
 	 * Don't allow other signals to interrupt the transmission */
 	siginitsetinv(&blocked, sigmask(SIGKILL));
Signature · 1 line
1.5.3.4