Commit 8fafac20 authored by Dan Carpenter's avatar Dan Carpenter Committed by Juergen Gross

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

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: 5db4d286 ("xen/pvcalls: implement connect command")
Signed-off-by: default avatarDan Carpenter <dan.carpenter@linaro.org>
Reviewed-by: default avatarJuergen Gross <jgross@suse.com>
Link: https://lore.kernel.org/r/e5f98dc2-0305-491f-a860-71bbd1398a2f@kili.mountainSigned-off-by: default avatarJuergen Gross <jgross@suse.com>
parent b6ebaa81
...@@ -325,8 +325,10 @@ static struct sock_mapping *pvcalls_new_active_socket( ...@@ -325,8 +325,10 @@ static struct sock_mapping *pvcalls_new_active_socket(
void *page; void *page;
map = kzalloc(sizeof(*map), GFP_KERNEL); map = kzalloc(sizeof(*map), GFP_KERNEL);
if (map == NULL) if (map == NULL) {
sock_release(sock);
return NULL; return NULL;
}
map->fedata = fedata; map->fedata = fedata;
map->sock = sock; map->sock = sock;
...@@ -418,10 +420,8 @@ static int pvcalls_back_connect(struct xenbus_device *dev, ...@@ -418,10 +420,8 @@ static int pvcalls_back_connect(struct xenbus_device *dev,
req->u.connect.ref, req->u.connect.ref,
req->u.connect.evtchn, req->u.connect.evtchn,
sock); sock);
if (!map) { if (!map)
ret = -EFAULT; ret = -EFAULT;
sock_release(sock);
}
out: out:
rsp = RING_GET_RESPONSE(&fedata->ring, fedata->ring.rsp_prod_pvt++); rsp = RING_GET_RESPONSE(&fedata->ring, fedata->ring.rsp_prod_pvt++);
...@@ -561,7 +561,6 @@ static void __pvcalls_back_accept(struct work_struct *work) ...@@ -561,7 +561,6 @@ static void __pvcalls_back_accept(struct work_struct *work)
sock); sock);
if (!map) { if (!map) {
ret = -EFAULT; ret = -EFAULT;
sock_release(sock);
goto out_error; goto out_error;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment