[PATCH] xen/pvcalls-back: fix double frees with pvcalls_new_active_socket()

Dan Carpenter posted 1 patch 1 year, 6 months ago
Failed in applying to current master (apply log)
drivers/xen/pvcalls-back.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
[PATCH] xen/pvcalls-back: fix double frees with pvcalls_new_active_socket()
Posted by Dan Carpenter 1 year, 6 months ago
In the pvcalls_new_active_socket() function, most error paths call
pvcalls_back_release_active(fedata->dev, fedata, map) which calls
sock_release() on "sock".  The bug is that the caller also frees sock.

Fix this by making every error path in pvcalls_new_active_socket()
release the sock, and don't free it in the caller.

Fixes: 5db4d286a8ef ("xen/pvcalls: implement connect command")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
 drivers/xen/pvcalls-back.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/xen/pvcalls-back.c b/drivers/xen/pvcalls-back.c
index 1f5219e12cc3..7beaf2c41fbb 100644
--- a/drivers/xen/pvcalls-back.c
+++ b/drivers/xen/pvcalls-back.c
@@ -325,8 +325,10 @@ static struct sock_mapping *pvcalls_new_active_socket(
 	void *page;
 
 	map = kzalloc(sizeof(*map), GFP_KERNEL);
-	if (map == NULL)
+	if (map == NULL) {
+		sock_release(sock);
 		return NULL;
+	}
 
 	map->fedata = fedata;
 	map->sock = sock;
@@ -418,10 +420,8 @@ static int pvcalls_back_connect(struct xenbus_device *dev,
 					req->u.connect.ref,
 					req->u.connect.evtchn,
 					sock);
-	if (!map) {
+	if (!map)
 		ret = -EFAULT;
-		sock_release(sock);
-	}
 
 out:
 	rsp = RING_GET_RESPONSE(&fedata->ring, fedata->ring.rsp_prod_pvt++);
@@ -561,7 +561,6 @@ static void __pvcalls_back_accept(struct work_struct *work)
 					sock);
 	if (!map) {
 		ret = -EFAULT;
-		sock_release(sock);
 		goto out_error;
 	}
 
-- 
2.39.2
Re: [PATCH] xen/pvcalls-back: fix double frees with pvcalls_new_active_socket()
Posted by Juergen Gross 1 year, 6 months ago
On 03.05.23 17:11, Dan Carpenter wrote:
> In the pvcalls_new_active_socket() function, most error paths call
> pvcalls_back_release_active(fedata->dev, fedata, map) which calls
> sock_release() on "sock".  The bug is that the caller also frees sock.
> 
> Fix this by making every error path in pvcalls_new_active_socket()
> release the sock, and don't free it in the caller.
> 
> Fixes: 5db4d286a8ef ("xen/pvcalls: implement connect command")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>

Reviewed-by: Juergen Gross <jgross@suse.com>


Juergen