Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <navid.emamdoost@gmail.com>
Reviewed-by: Michal Kubecek <mkubecek@suse.cz>
Fixes: 47d902b90a32 ("nbd: add a status netlink command")
Signed-off-by: Kees Cook <keescook@chromium.org>
Link: https://lore.kernel.org/r/20240218042534.it.206-kees@kernel.org
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Navid Emamdoost and committed by
Jens Axboe
31edf4bb d69591ca

+6
+6
drivers/block/nbd.c
··· 2433 2433 } 2434 2434 2435 2435 dev_list = nla_nest_start_noflag(reply, NBD_ATTR_DEVICE_LIST); 2436 + if (!dev_list) { 2437 + nlmsg_free(reply); 2438 + ret = -EMSGSIZE; 2439 + goto out; 2440 + } 2441 + 2436 2442 if (index == -1) { 2437 2443 ret = idr_for_each(&nbd_index_idr, &status_cb, reply); 2438 2444 if (ret) {