]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
nbd: prevent memory leak
authorNavid Emamdoost <navid.emamdoost@gmail.com>
Mon, 23 Sep 2019 20:09:58 +0000 (15:09 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 29 Nov 2019 09:08:01 +0000 (10:08 +0100)
commit 03bf73c315edca28f47451913177e14cd040a216 upstream.

In nbd_add_socket when krealloc succeeds, if nsock's allocation fail the
reallocted memory is leak. The correct behaviour should be assigning the
reallocted memory to config->socks right after success.

Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/block/nbd.c

index 1406331896303564bb05842a6a79e3204d6570f2..f4140f0773246d4f402604c6827ead95f1e2ee88 100644 (file)
@@ -995,14 +995,15 @@ static int nbd_add_socket(struct nbd_device *nbd, unsigned long arg,
                sockfd_put(sock);
                return -ENOMEM;
        }
+
+       config->socks = socks;
+
        nsock = kzalloc(sizeof(struct nbd_sock), GFP_KERNEL);
        if (!nsock) {
                sockfd_put(sock);
                return -ENOMEM;
        }
 
-       config->socks = socks;
-
        nsock->fallback_index = -1;
        nsock->dead = false;
        mutex_init(&nsock->tx_lock);