Skip to content

Commit

Permalink
xen/gntalloc: safely delete grefs in add_grefs() undo path
Browse files Browse the repository at this point in the history
If a gref could not be added (perhaps because the limit has been
reached or there are no more grant references available), the undo
path may crash because __del_gref() frees the gref while it is being
used for a list iteration.

A comment suggests that using list_for_each_entry() is safe since the
gref isn't removed from the list being iterated over, but it is freed
and thus list_for_each_entry_safe() must be used.

Also, explicitly delete the gref from the local per-file list, even
though this is not strictly necessary.

Signed-off-by: David Vrabel <david.vrabel@citrix.com>
Reviewed-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
  • Loading branch information
David Vrabel committed Sep 4, 2014
1 parent e9de2e5 commit 5903c6b
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions drivers/xen/gntalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ static int add_grefs(struct ioctl_gntalloc_alloc_gref *op,
int i, rc, readonly;
LIST_HEAD(queue_gref);
LIST_HEAD(queue_file);
struct gntalloc_gref *gref;
struct gntalloc_gref *gref, *next;

readonly = !(op->flags & GNTALLOC_FLAG_WRITABLE);
rc = -ENOMEM;
Expand Down Expand Up @@ -160,8 +160,8 @@ static int add_grefs(struct ioctl_gntalloc_alloc_gref *op,
mutex_lock(&gref_mutex);
gref_size -= (op->count - i);

list_for_each_entry(gref, &queue_file, next_file) {
/* __del_gref does not remove from queue_file */
list_for_each_entry_safe(gref, next, &queue_file, next_file) {
list_del(&gref->next_file);
__del_gref(gref);
}

Expand Down

0 comments on commit 5903c6b

Please sign in to comment.