Skip to content

Commit 3569b65

Browse files
jbeulichksacilotto
authored andcommitted
xen-blkback: fix error handling in xen_blkbk_map()
BugLink: https://bugs.launchpad.net/bugs/1918168 commit 871997b upstream. The function uses a goto-based loop, which may lead to an earlier error getting discarded by a later iteration. Exit this ad-hoc loop when an error was encountered. The out-of-memory error path additionally fails to fill a structure field looked at by xen_blkbk_unmap_prepare() before inspecting the handle which does get properly set (to BLKBACK_INVALID_HANDLE). Since the earlier exiting from the ad-hoc loop requires the same field filling (invalidation) as that on the out-of-memory path, fold both paths. While doing so, drop the pr_alert(), as extra log messages aren't going to help the situation (the kernel will log oom conditions already anyway). This is XSA-365. Signed-off-by: Jan Beulich <jbeulich@suse.com> Reviewed-by: Juergen Gross <jgross@suse.com> Reviewed-by: Julien Grall <julien@xen.org> Signed-off-by: Juergen Gross <jgross@suse.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Kamal Mostafa <kamal@canonical.com> Signed-off-by: Kelsey Skunberg <kelsey.skunberg@canonical.com>
1 parent 5f74695 commit 3569b65

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

drivers/block/xen-blkback/blkback.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -850,8 +850,11 @@ static int xen_blkbk_map(struct xen_blkif_ring *ring,
850850
pages[i]->page = persistent_gnt->page;
851851
pages[i]->persistent_gnt = persistent_gnt;
852852
} else {
853-
if (get_free_page(ring, &pages[i]->page))
854-
goto out_of_memory;
853+
if (get_free_page(ring, &pages[i]->page)) {
854+
put_free_pages(ring, pages_to_gnt, segs_to_map);
855+
ret = -ENOMEM;
856+
goto out;
857+
}
855858
addr = vaddr(pages[i]->page);
856859
pages_to_gnt[segs_to_map] = pages[i]->page;
857860
pages[i]->persistent_gnt = NULL;
@@ -935,17 +938,18 @@ static int xen_blkbk_map(struct xen_blkif_ring *ring,
935938
}
936939
segs_to_map = 0;
937940
last_map = map_until;
938-
if (map_until != num)
941+
if (!ret && map_until != num)
939942
goto again;
940943

941-
return ret;
942-
943-
out_of_memory:
944-
pr_alert("%s: out of memory\n", __func__);
945-
put_free_pages(ring, pages_to_gnt, segs_to_map);
946-
for (i = last_map; i < num; i++)
944+
out:
945+
for (i = last_map; i < num; i++) {
946+
/* Don't zap current batch's valid persistent grants. */
947+
if(i >= last_map + segs_to_map)
948+
pages[i]->persistent_gnt = NULL;
947949
pages[i]->handle = BLKBACK_INVALID_HANDLE;
948-
return -ENOMEM;
950+
}
951+
952+
return ret;
949953
}
950954

951955
static int xen_blkbk_map_seg(struct pending_req *pending_req)

0 commit comments

Comments
 (0)