diff mbox series

block: nbd: fix a missing check for nla_nest_start

Message ID 20190315063138.17666-1-kjlu@umn.edu (mailing list archive)
State New, archived
Headers show
Series block: nbd: fix a missing check for nla_nest_start | expand

Commit Message

Kangjie Lu March 15, 2019, 6:31 a.m. UTC
nla_nest_start may fail and thus deserves a check.

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

Signed-off-by: Kangjie Lu <kjlu@umn.edu>
---
 drivers/block/nbd.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Josef Bacik March 15, 2019, 1:27 p.m. UTC | #1
On Fri, Mar 15, 2019 at 01:31:38AM -0500, Kangjie Lu wrote:
> 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
diff mbox series

Patch

diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index 7c9a949e876b..810c8c20b142 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -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) {