Olaf Hering c48440
From: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Olaf Hering c48440
Date: Sun, 9 May 2021 09:13:03 +0200
Olaf Hering c48440
Patch-mainline: v5.13-rc3
Olaf Hering c48440
References: git-fixes
Olaf Hering c48440
Subject: uio_hv_generic: Fix a memory leak in error handling paths
Olaf Hering c48440
Git-commit: 3ee098f96b8b6c1a98f7f97915f8873164e6af9d
Olaf Hering c48440
Olaf Hering c48440
If 'vmbus_establish_gpadl()' fails, the (recv|send)_gpadl will not be
Olaf Hering c48440
updated and 'hv_uio_cleanup()' in the error handling path will not be
Olaf Hering c48440
able to free the corresponding buffer.
Olaf Hering c48440
Olaf Hering c48440
In such a case, we need to free the buffer explicitly.
Olaf Hering c48440
Olaf Hering c48440
Fixes: cdfa835c6e5e ("uio_hv_generic: defer opening vmbus until first use")
Olaf Hering c48440
Cc: stable <stable@vger.kernel.org>
Olaf Hering c48440
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Olaf Hering c48440
Link: https://lore.kernel.org/r/4fdaff557deef6f0475d02ba7922ddbaa1ab08a6.1620544055.git.christophe.jaillet@wanadoo.fr
Olaf Hering c48440
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Olaf Hering c48440
Acked-by: Olaf Hering <ohering@suse.de>
Olaf Hering c48440
---
Olaf Hering c48440
 drivers/uio/uio_hv_generic.c | 8 ++++++--
Olaf Hering c48440
 1 file changed, 6 insertions(+), 2 deletions(-)
Olaf Hering c48440
Olaf Hering c48440
diff --git a/drivers/uio/uio_hv_generic.c b/drivers/uio/uio_hv_generic.c
Olaf Hering c48440
--- a/drivers/uio/uio_hv_generic.c
Olaf Hering c48440
+++ b/drivers/uio/uio_hv_generic.c
Olaf Hering c48440
@@ -296,8 +296,10 @@ hv_uio_probe(struct hv_device *dev,
Olaf Hering c48440
 
Olaf Hering c48440
 	ret = vmbus_establish_gpadl(channel, pdata->recv_buf,
Olaf Hering c48440
 				    RECV_BUFFER_SIZE, &pdata->recv_gpadl);
Olaf Hering c48440
-	if (ret)
Olaf Hering c48440
+	if (ret) {
Olaf Hering c48440
+		vfree(pdata->recv_buf);
Olaf Hering c48440
 		goto fail_close;
Olaf Hering c48440
+	}
Olaf Hering c48440
 
Olaf Hering c48440
 	/* put Global Physical Address Label in name */
Olaf Hering c48440
 	snprintf(pdata->recv_name, sizeof(pdata->recv_name),
Olaf Hering c48440
@@ -316,8 +318,10 @@ hv_uio_probe(struct hv_device *dev,
Olaf Hering c48440
 
Olaf Hering c48440
 	ret = vmbus_establish_gpadl(channel, pdata->send_buf,
Olaf Hering c48440
 				    SEND_BUFFER_SIZE, &pdata->send_gpadl);
Olaf Hering c48440
-	if (ret)
Olaf Hering c48440
+	if (ret) {
Olaf Hering c48440
+		vfree(pdata->send_buf);
Olaf Hering c48440
 		goto fail_close;
Olaf Hering c48440
+	}
Olaf Hering c48440
 
Olaf Hering c48440
 	snprintf(pdata->send_name, sizeof(pdata->send_name),
Olaf Hering c48440
 		 "send:%u", pdata->send_gpadl);