Skip to content

Commit

Permalink
aio: sanitize ki_list handling
Browse files Browse the repository at this point in the history
Instead of handcoded non-null checks always initialize ki_list to an
empty list and use list_empty / list_empty_careful on it.  While we're
at it also error out on a double call to kiocb_set_cancel_fn instead
of ignoring it.

Signed-off-by: Christoph Hellwig <[email protected]>
Acked-by: Jeff Moyer <[email protected]>
Reviewed-by: Greg Kroah-Hartman <[email protected]>
Reviewed-by: Darrick J. Wong <[email protected]>
  • Loading branch information
Christoph Hellwig committed May 2, 2018
1 parent c213dc8 commit 75321b5
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions fs/aio.c
Original file line number Diff line number Diff line change
Expand Up @@ -553,13 +553,12 @@ void kiocb_set_cancel_fn(struct kiocb *iocb, kiocb_cancel_fn *cancel)
struct kioctx *ctx = req->ki_ctx;
unsigned long flags;

spin_lock_irqsave(&ctx->ctx_lock, flags);

if (!req->ki_list.next)
list_add(&req->ki_list, &ctx->active_reqs);
if (WARN_ON_ONCE(!list_empty(&req->ki_list)))
return;

spin_lock_irqsave(&ctx->ctx_lock, flags);
list_add_tail(&req->ki_list, &ctx->active_reqs);
req->ki_cancel = cancel;

spin_unlock_irqrestore(&ctx->ctx_lock, flags);
}
EXPORT_SYMBOL(kiocb_set_cancel_fn);
Expand Down Expand Up @@ -1039,7 +1038,7 @@ static inline struct aio_kiocb *aio_get_req(struct kioctx *ctx)
goto out_put;

percpu_ref_get(&ctx->reqs);

INIT_LIST_HEAD(&req->ki_list);
req->ki_ctx = ctx;
return req;
out_put:
Expand Down Expand Up @@ -1107,7 +1106,7 @@ static void aio_complete(struct kiocb *kiocb, long res, long res2)
file_end_write(file);
}

if (iocb->ki_list.next) {
if (!list_empty_careful(&iocb->ki_list)) {
unsigned long flags;

spin_lock_irqsave(&ctx->ctx_lock, flags);
Expand Down

0 comments on commit 75321b5

Please sign in to comment.