Skip to content

Commit

Permalink
xen/gntdevt: Fix race condition in gntdev_release()
Browse files Browse the repository at this point in the history
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 <marmarek@invisiblethingslab.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: David Vrabel <david.vrabel@citrix.com>
  • Loading branch information
Marek Marczykowski-Górecki authored and David Vrabel committed Jun 30, 2015
1 parent 6684fa1 commit 30b03d0
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions drivers/xen/gntdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -568,12 +568,14 @@ static int gntdev_release(struct inode *inode, struct file *flip)

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

mutex_lock(&priv->lock);
while (!list_empty(&priv->maps)) {
map = list_entry(priv->maps.next, struct grant_map, next);
list_del(&map->next);
gntdev_put_map(NULL /* already removed */, map);
}
WARN_ON(!list_empty(&priv->freeable_maps));
mutex_unlock(&priv->lock);

if (use_ptemod)
mmu_notifier_unregister(&priv->mn, priv->mm);
Expand Down

0 comments on commit 30b03d0

Please sign in to comment.