Skip to content

Commit 5cadd4b

Browse files
committed
xen/9p: use alloc/free_pages_exact()
Instead of __get_free_pages() and free_pages() use alloc_pages_exact() and free_pages_exact(). This is in preparation of a change of gnttab_end_foreign_access() which will prohibit use of high-order pages. By using the local variable "order" instead of ring->intf->ring_order in the error path of xen_9pfs_front_alloc_dataring() another bug is fixed, as the error path can be entered before ring->intf->ring_order is being set. By using alloc_pages_exact() the size in bytes is specified for the allocation, which fixes another bug for the case of order < (PAGE_SHIFT - XEN_PAGE_SHIFT). This is part of CVE-2022-23041 / XSA-396. Reported-by: Simon Gaiser <[email protected]> Signed-off-by: Juergen Gross <[email protected]> Reviewed-by: Jan Beulich <[email protected]> --- V4: - new patch
1 parent cd7bcfa commit 5cadd4b

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

net/9p/trans_xen.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -281,9 +281,9 @@ static void xen_9pfs_front_free(struct xen_9pfs_front_priv *priv)
281281
ref = priv->rings[i].intf->ref[j];
282282
gnttab_end_foreign_access(ref, 0, 0);
283283
}
284-
free_pages((unsigned long)priv->rings[i].data.in,
285-
priv->rings[i].intf->ring_order -
286-
(PAGE_SHIFT - XEN_PAGE_SHIFT));
284+
free_pages_exact(priv->rings[i].data.in,
285+
1UL << (priv->rings[i].intf->ring_order +
286+
XEN_PAGE_SHIFT));
287287
}
288288
gnttab_end_foreign_access(priv->rings[i].ref, 0, 0);
289289
free_page((unsigned long)priv->rings[i].intf);
@@ -322,8 +322,8 @@ static int xen_9pfs_front_alloc_dataring(struct xenbus_device *dev,
322322
if (ret < 0)
323323
goto out;
324324
ring->ref = ret;
325-
bytes = (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO,
326-
order - (PAGE_SHIFT - XEN_PAGE_SHIFT));
325+
bytes = alloc_pages_exact(1UL << (order + XEN_PAGE_SHIFT),
326+
GFP_KERNEL | __GFP_ZERO);
327327
if (!bytes) {
328328
ret = -ENOMEM;
329329
goto out;
@@ -354,9 +354,7 @@ static int xen_9pfs_front_alloc_dataring(struct xenbus_device *dev,
354354
if (bytes) {
355355
for (i--; i >= 0; i--)
356356
gnttab_end_foreign_access(ring->intf->ref[i], 0, 0);
357-
free_pages((unsigned long)bytes,
358-
ring->intf->ring_order -
359-
(PAGE_SHIFT - XEN_PAGE_SHIFT));
357+
free_pages_exact(bytes, 1UL << (order + XEN_PAGE_SHIFT));
360358
}
361359
gnttab_end_foreign_access(ring->ref, 0, 0);
362360
free_page((unsigned long)ring->intf);

0 commit comments

Comments
 (0)