Skip to content

Commit

Permalink
xen-gnt: prevent adding duplicate gnt callbacks
Browse files Browse the repository at this point in the history
commit 5f338d9001094a56cf87bd8a280b4e7ff953bb59 upstream.

With the current implementation, the callback in the tail of the list
can be added twice, because the check done in
gnttab_request_free_callback is bogus, callback->next can be NULL if
it is the last callback in the list. If we add the same callback twice
we end up with an infinite loop, were callback == callback->next.

Replace this check with a proper one that iterates over the list to
see if the callback has already been added.

Signed-off-by: Roger Pau Monné <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: David Vrabel <[email protected]>
Signed-off-by: Konrad Rzeszutek Wilk <[email protected]>
Acked-by: Matt Wilson <[email protected]>
Reviewed-by: David Vrabel <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
Signed-off-by: bgn9000 <[email protected]>
  • Loading branch information
royger authored and bgn9000 committed Oct 15, 2013
1 parent 005c9e3 commit 4b7e307
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions drivers/xen/grant-table.c
Original file line number Diff line number Diff line change
Expand Up @@ -355,9 +355,18 @@ void gnttab_request_free_callback(struct gnttab_free_callback *callback,
void (*fn)(void *), void *arg, u16 count)
{
unsigned long flags;
struct gnttab_free_callback *cb;

spin_lock_irqsave(&gnttab_list_lock, flags);
if (callback->next)
goto out;

/* Check if the callback is already on the list */
cb = gnttab_free_callback_list;
while (cb) {
if (cb == callback)
goto out;
cb = cb->next;
}

callback->fn = fn;
callback->arg = arg;
callback->count = count;
Expand Down

0 comments on commit 4b7e307

Please sign in to comment.