From: Navid Emamdoost Date: Sun, 18 Feb 2024 04:25:38 +0000 (-0800) Subject: nbd: null check for nla_nest_start X-Git-Tag: microblaze-v6.10~216^2~94 X-Git-Url: http://git.monstr.eu/?a=commitdiff_plain;h=31edf4bbe0ba27fd03ac7d87eb2ee3d2a231af6d;p=linux-2.6-microblaze.git nbd: null check for nla_nest_start nla_nest_start() may fail and return NULL. Insert a check and set errno based on other call sites within the same source code. Signed-off-by: Navid Emamdoost Reviewed-by: Michal Kubecek Fixes: 47d902b90a32 ("nbd: add a status netlink command") Signed-off-by: Kees Cook Link: https://lore.kernel.org/r/20240218042534.it.206-kees@kernel.org Signed-off-by: Jens Axboe --- diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c index 30ae3cc12e77..d2b422d842b7 100644 --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c @@ -2433,6 +2433,12 @@ static int nbd_genl_status(struct sk_buff *skb, struct genl_info *info) } dev_list = nla_nest_start_noflag(reply, NBD_ATTR_DEVICE_LIST); + if (!dev_list) { + nlmsg_free(reply); + ret = -EMSGSIZE; + goto out; + } + if (index == -1) { ret = idr_for_each(&nbd_index_idr, &status_cb, reply); if (ret) {