[PATCH 5.3 23/95] nbd:fix memory leak in nbd_get_socket()

From: Greg Kroah-Hartman
Date: Wed Nov 27 2019 - 16:09:10 EST


From: Sun Ke <sunke32@xxxxxxxxxx>

commit dff10bbea4be47bdb615b036c834a275b7c68133 upstream.

Before returning NULL, put the sock first.

Cc: stable@xxxxxxxxxxxxxxx
Fixes: cf1b2326b734 ("nbd: verify socket is supported during setup")
Reviewed-by: Josef Bacik <josef@xxxxxxxxxxxxxx>
Reviewed-by: Mike Christie <mchristi@xxxxxxxxxx>
Signed-off-by: Sun Ke <sunke32@xxxxxxxxxx>
Signed-off-by: Jens Axboe <axboe@xxxxxxxxx>
Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>

---
drivers/block/nbd.c | 1 +
1 file changed, 1 insertion(+)

--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -956,6 +956,7 @@ static struct socket *nbd_get_socket(str
if (sock->ops->shutdown == sock_no_shutdown) {
dev_err(disk_to_dev(nbd->disk), "Unsupported socket: shutdown callout must be supported.\n");
*err = -EINVAL;
+ sockfd_put(sock);
return NULL;
}