diff options
author | Christoph Hellwig <hch@lst.de> | 2018-04-09 08:57:56 -0400 |
---|---|---|
committer | Christoph Hellwig <hch@lst.de> | 2018-05-02 13:52:59 -0400 |
commit | 75321b50a37a5ba612125a04bfc9e43e3da5b305 (patch) | |
tree | c7a3e25787f7350fc3b48350de5b3622ac265329 /fs/aio.c | |
parent | c213dc826c591cec9e1a458f17ae474af6c8e00c (diff) |
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 <hch@lst.de>
Acked-by: Jeff Moyer <jmoyer@redhat.com>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Diffstat (limited to 'fs/aio.c')
-rw-r--r-- | fs/aio.c | 13 |
1 files changed, 6 insertions, 7 deletions
@@ -553,13 +553,12 @@ void kiocb_set_cancel_fn(struct kiocb *iocb, kiocb_cancel_fn *cancel) | |||
553 | struct kioctx *ctx = req->ki_ctx; | 553 | struct kioctx *ctx = req->ki_ctx; |
554 | unsigned long flags; | 554 | unsigned long flags; |
555 | 555 | ||
556 | spin_lock_irqsave(&ctx->ctx_lock, flags); | 556 | if (WARN_ON_ONCE(!list_empty(&req->ki_list))) |
557 | 557 | return; | |
558 | if (!req->ki_list.next) | ||
559 | list_add(&req->ki_list, &ctx->active_reqs); | ||
560 | 558 | ||
559 | spin_lock_irqsave(&ctx->ctx_lock, flags); | ||
560 | list_add_tail(&req->ki_list, &ctx->active_reqs); | ||
561 | req->ki_cancel = cancel; | 561 | req->ki_cancel = cancel; |
562 | |||
563 | spin_unlock_irqrestore(&ctx->ctx_lock, flags); | 562 | spin_unlock_irqrestore(&ctx->ctx_lock, flags); |
564 | } | 563 | } |
565 | EXPORT_SYMBOL(kiocb_set_cancel_fn); | 564 | EXPORT_SYMBOL(kiocb_set_cancel_fn); |
@@ -1039,7 +1038,7 @@ static inline struct aio_kiocb *aio_get_req(struct kioctx *ctx) | |||
1039 | goto out_put; | 1038 | goto out_put; |
1040 | 1039 | ||
1041 | percpu_ref_get(&ctx->reqs); | 1040 | percpu_ref_get(&ctx->reqs); |
1042 | 1041 | INIT_LIST_HEAD(&req->ki_list); | |
1043 | req->ki_ctx = ctx; | 1042 | req->ki_ctx = ctx; |
1044 | return req; | 1043 | return req; |
1045 | out_put: | 1044 | out_put: |
@@ -1107,7 +1106,7 @@ static void aio_complete(struct kiocb *kiocb, long res, long res2) | |||
1107 | file_end_write(file); | 1106 | file_end_write(file); |
1108 | } | 1107 | } |
1109 | 1108 | ||
1110 | if (iocb->ki_list.next) { | 1109 | if (!list_empty_careful(&iocb->ki_list)) { |
1111 | unsigned long flags; | 1110 | unsigned long flags; |
1112 | 1111 | ||
1113 | spin_lock_irqsave(&ctx->ctx_lock, flags); | 1112 | spin_lock_irqsave(&ctx->ctx_lock, flags); |