Skip to contentSkip to conversation

nbd: fix potential NULL pointer fault in nbd_genl_disconnect

PATCH Superseded Sun Ke 1 participant 1 message Jan 20, 2020

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Sun Ke

author
#0 lore raw

PATCH 1/1 nbd: fix potential NULL pointer fault in nbd_genl_disconnect

Open /dev/nbdX first, the config_refs will be 1 and the pointers in nbd_device are still null. Disconnect /dev/nbdX, then reference a null recv_workq. The protection by config_refs in nbd_genl_disconnect is useless.

To fix it, just add a check for a non null task_recv in nbd_genl_disconnect.

---
 drivers/block/nbd.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/block/nbd.c +2 -0
index b4607dd96185..5e1530bcb81a 100644
@@ -2008,6 +2008,8 @@ static int nbd_genl_disconnect(struct sk_buff *skb, struct genl_info *info)
 		       index);
 		return -EINVAL;
 	}
+	if (!nbd->task_recv)
+		return -EINVAL;
 	if (!refcount_inc_not_zero(&nbd->refs)) {
 		mutex_unlock(&nbd_index_mutex);
 		printk(KERN_ERR "nbd: device at index %d is going down\n",
Signature · 1 line
2.17.2