linux-hyperv.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] uio_hv_generic: Fix a memory leak in error handling paths
@ 2021-05-09  7:13 Christophe JAILLET
  2021-05-09  7:13 ` [PATCH 2/2] uio_hv_generic: Fix another " Christophe JAILLET
  2021-05-11  9:52 ` [PATCH 1/2] uio_hv_generic: Fix a " Wei Liu
  0 siblings, 2 replies; 9+ messages in thread
From: Christophe JAILLET @ 2021-05-09  7:13 UTC (permalink / raw)
  To: kys, haiyangz, sthemmin, wei.liu, decui, gregkh
  Cc: linux-hyperv, linux-kernel, kernel-janitors, Christophe JAILLET

If 'vmbus_establish_gpadl()' fails, the (recv|send)_gpadl will not be
updated and 'hv_uio_cleanup()' in the error handling path will not be
able to free the corresponding buffer.

In such a case, we need to free the buffer explicitly.

Fixes: cdfa835c6e5e ("uio_hv_generic: defer opening vmbus until first use")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
Before commit cdfa835c6e5e, the 'vfree' were done unconditionally
in 'hv_uio_cleanup()'.
So, another way for fixing the potential leak is to modify
'hv_uio_cleanup()' and revert to the previous behavior.

I don't know the underlying reason for this change so I don't know which is
the best way to fix this error handling path. Unless there is a specific
reason, changing 'hv_uio_cleanup()' could be better because it would keep
the error handling path of the probe cleaner, IMHO.
---
 drivers/uio/uio_hv_generic.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/uio/uio_hv_generic.c b/drivers/uio/uio_hv_generic.c
index 0330ba99730e..eebc399f2cc7 100644
--- a/drivers/uio/uio_hv_generic.c
+++ b/drivers/uio/uio_hv_generic.c
@@ -296,8 +296,10 @@ hv_uio_probe(struct hv_device *dev,
 
 	ret = vmbus_establish_gpadl(channel, pdata->recv_buf,
 				    RECV_BUFFER_SIZE, &pdata->recv_gpadl);
-	if (ret)
+	if (ret) {
+		vfree(pdata->recv_buf);
 		goto fail_close;
+	}
 
 	/* put Global Physical Address Label in name */
 	snprintf(pdata->recv_name, sizeof(pdata->recv_name),
@@ -316,8 +318,10 @@ hv_uio_probe(struct hv_device *dev,
 
 	ret = vmbus_establish_gpadl(channel, pdata->send_buf,
 				    SEND_BUFFER_SIZE, &pdata->send_gpadl);
-	if (ret)
+	if (ret) {
+		vfree(pdata->send_buf);
 		goto fail_close;
+	}
 
 	snprintf(pdata->send_name, sizeof(pdata->send_name),
 		 "send:%u", pdata->send_gpadl);
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2021-05-18 21:53 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-09  7:13 [PATCH 1/2] uio_hv_generic: Fix a memory leak in error handling paths Christophe JAILLET
2021-05-09  7:13 ` [PATCH 2/2] uio_hv_generic: Fix another " Christophe JAILLET
2021-05-11  9:52 ` [PATCH 1/2] uio_hv_generic: Fix a " Wei Liu
2021-05-11 18:18   ` Christophe JAILLET
2021-05-15 16:09     ` Wei Liu
2021-05-18 20:46       ` Christophe JAILLET
2021-05-18 11:01   ` Wei Liu
2021-05-18 21:50     ` Long Li
2021-05-18 21:53       ` Wei Liu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).