Skip to content

Commit 30b03d0

Browse files
marmarekDavid Vrabel
authored and
David Vrabel
committed
xen/gntdevt: Fix race condition in gntdev_release()
While gntdev_release() is called the MMU notifier is still registered and can traverse priv->maps list even if no pages are mapped (which is the case -- gntdev_release() is called after all). But gntdev_release() will clear that list, so make sure that only one of those things happens at the same time. Signed-off-by: Marek Marczykowski-Górecki <[email protected]> Cc: <[email protected]> Signed-off-by: David Vrabel <[email protected]>
1 parent 6684fa1 commit 30b03d0

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

drivers/xen/gntdev.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,12 +568,14 @@ static int gntdev_release(struct inode *inode, struct file *flip)
568568

569569
pr_debug("priv %p\n", priv);
570570

571+
mutex_lock(&priv->lock);
571572
while (!list_empty(&priv->maps)) {
572573
map = list_entry(priv->maps.next, struct grant_map, next);
573574
list_del(&map->next);
574575
gntdev_put_map(NULL /* already removed */, map);
575576
}
576577
WARN_ON(!list_empty(&priv->freeable_maps));
578+
mutex_unlock(&priv->lock);
577579

578580
if (use_ptemod)
579581
mmu_notifier_unregister(&priv->mn, priv->mm);

0 commit comments

Comments
 (0)