Skip to content

Commit 75321b5

Browse files
author
Christoph Hellwig
committed
aio: sanitize ki_list handling
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]>
1 parent c213dc8 commit 75321b5

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

fs/aio.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -553,13 +553,12 @@ void kiocb_set_cancel_fn(struct kiocb *iocb, kiocb_cancel_fn *cancel)
553553
struct kioctx *ctx = req->ki_ctx;
554554
unsigned long flags;
555555

556-
spin_lock_irqsave(&ctx->ctx_lock, flags);
557-
558-
if (!req->ki_list.next)
559-
list_add(&req->ki_list, &ctx->active_reqs);
556+
if (WARN_ON_ONCE(!list_empty(&req->ki_list)))
557+
return;
560558

559+
spin_lock_irqsave(&ctx->ctx_lock, flags);
560+
list_add_tail(&req->ki_list, &ctx->active_reqs);
561561
req->ki_cancel = cancel;
562-
563562
spin_unlock_irqrestore(&ctx->ctx_lock, flags);
564563
}
565564
EXPORT_SYMBOL(kiocb_set_cancel_fn);
@@ -1039,7 +1038,7 @@ static inline struct aio_kiocb *aio_get_req(struct kioctx *ctx)
10391038
goto out_put;
10401039

10411040
percpu_ref_get(&ctx->reqs);
1042-
1041+
INIT_LIST_HEAD(&req->ki_list);
10431042
req->ki_ctx = ctx;
10441043
return req;
10451044
out_put:
@@ -1107,7 +1106,7 @@ static void aio_complete(struct kiocb *kiocb, long res, long res2)
11071106
file_end_write(file);
11081107
}
11091108

1110-
if (iocb->ki_list.next) {
1109+
if (!list_empty_careful(&iocb->ki_list)) {
11111110
unsigned long flags;
11121111

11131112
spin_lock_irqsave(&ctx->ctx_lock, flags);

0 commit comments

Comments
 (0)