Skip to content

Commit

Permalink
aio: lookup_ioctx can return the wrong value when looking up a bogus …
Browse files Browse the repository at this point in the history
…context

The libaio test harness turned up a problem whereby lookup_ioctx on a
bogus io context was returning the 1 valid io context from the list
(harness/cases/3.p).

Because of that, an extra put_iocontext was done, and when the process
exited, it hit a BUG_ON in the put_iocontext macro called from exit_aio
(since we expect a users count of 1 and instead get 0).

The problem was introduced by "aio: make the lookup_ioctx() lockless"
(commit abf137d).

Thanks to Zach for pointing out that hlist_for_each_entry_rcu will not
return with a NULL tpos at the end of the loop, even if the entry was
not found.

Signed-off-by: Jeff Moyer <[email protected]>
Acked-by: Zach Brown <[email protected]>
Acked-by: Jens Axboe <[email protected]>
Cc: Benjamin LaHaise <[email protected]>
Cc: <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
JeffMoyer authored and torvalds committed Mar 19, 2009
1 parent 87c3a86 commit 65c2449
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions fs/aio.c
Original file line number Diff line number Diff line change
Expand Up @@ -587,20 +587,21 @@ int aio_put_req(struct kiocb *req)
static struct kioctx *lookup_ioctx(unsigned long ctx_id)
{
struct mm_struct *mm = current->mm;
struct kioctx *ctx = NULL;
struct kioctx *ctx, *ret = NULL;
struct hlist_node *n;

rcu_read_lock();

hlist_for_each_entry_rcu(ctx, n, &mm->ioctx_list, list) {
if (ctx->user_id == ctx_id && !ctx->dead) {
get_ioctx(ctx);
ret = ctx;
break;
}
}

rcu_read_unlock();
return ctx;
return ret;
}

/*
Expand Down

0 comments on commit 65c2449

Please sign in to comment.