nbd: Fix memory leak in nbd_add_socket
authorZheng Bin <zhengbin13@huawei.com>
Mon, 29 Jun 2020 01:23:49 +0000 (09:23 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 16 Jul 2020 06:13:23 +0000 (08:13 +0200)
commit95e6c7f6d569b70b76dda42a347adada2a6bd706
treec1214f5703e7dbdd946d58712ebee32f5b2adaa3
parent5c4487e7e901a18325d85d06aab81dc33b5a5818
nbd: Fix memory leak in nbd_add_socket

[ Upstream commit 579dd91ab3a5446b148e7f179b6596b270dace46 ]

When adding first socket to nbd, if nsock's allocation failed, the data
structure member "config->socks" was reallocated, but the data structure
member "config->num_connections" was not updated. A memory leak will occur
then because the function "nbd_config_put" will free "config->socks" only
when "config->num_connections" is not zero.

Fixes: 03bf73c315ed ("nbd: prevent memory leak")
Reported-by: syzbot+934037347002901b8d2a@syzkaller.appspotmail.com
Signed-off-by: Zheng Bin <zhengbin13@huawei.com>
Reviewed-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/block/nbd.c