Skip to content

Commit 8fafac2

Browse files
Dan Carpenterjgross1
authored andcommitted
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: 5db4d28 ("xen/pvcalls: implement connect command") Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org> Reviewed-by: Juergen Gross <jgross@suse.com> Link: https://lore.kernel.org/r/e5f98dc2-0305-491f-a860-71bbd1398a2f@kili.mountain Signed-off-by: Juergen Gross <jgross@suse.com>
1 parent b6ebaa8 commit 8fafac2

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

drivers/xen/pvcalls-back.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,10 @@ static struct sock_mapping *pvcalls_new_active_socket(
325325
void *page;
326326

327327
map = kzalloc(sizeof(*map), GFP_KERNEL);
328-
if (map == NULL)
328+
if (map == NULL) {
329+
sock_release(sock);
329330
return NULL;
331+
}
330332

331333
map->fedata = fedata;
332334
map->sock = sock;
@@ -418,10 +420,8 @@ static int pvcalls_back_connect(struct xenbus_device *dev,
418420
req->u.connect.ref,
419421
req->u.connect.evtchn,
420422
sock);
421-
if (!map) {
423+
if (!map)
422424
ret = -EFAULT;
423-
sock_release(sock);
424-
}
425425

426426
out:
427427
rsp = RING_GET_RESPONSE(&fedata->ring, fedata->ring.rsp_prod_pvt++);
@@ -561,7 +561,6 @@ static void __pvcalls_back_accept(struct work_struct *work)
561561
sock);
562562
if (!map) {
563563
ret = -EFAULT;
564-
sock_release(sock);
565564
goto out_error;
566565
}
567566

0 commit comments

Comments
 (0)