Skip to contentSkip to conversation

block: nbd: fix a missing check for nla_nest_start

PATCH In review Kangjie Lu 2 participants 2 messages Mar 15, 2019

Subsystems (2)
lore
Share & tools
lore

Kangjie Lu

author
#0 lore raw

PATCH 1/1 block: nbd: fix a missing check for nla_nest_start

nla_nest_start may fail and thus deserves a check.

The fix inserts such a check and exits gracefully in case it fails.

---
 drivers/block/nbd.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/block/nbd.c +4 -0
index 7c9a949e876b..810c8c20b142 100644
@@ -2099,6 +2099,10 @@ static int nbd_genl_status(struct sk_buff *skb, struct genl_info *info)
 	}
 
 	dev_list = nla_nest_start(reply, NBD_ATTR_DEVICE_LIST);
+	if (!dev_list) {
+		nlmsg_free(reply);
+		goto out;
+	}
 	if (index == -1) {
 		ret = idr_for_each(&nbd_index_idr, &status_cb, reply);
 		if (ret) {
Signature · 1 line
2.17.1
maintainer
#1 lore raw
Quoted 5 lines · Kangjie Lu

nla_nest_start may fail and thus deserves a check.

The fix inserts such a check and exits gracefully in case it fails.

Except it won't because we pre-reserve enough space for that attr. Subsequent calls could fail, and those are checked properly, but this one won't. Thanks,

Josef