Skip to content

Commit 45cec0d

Browse files
Christoph Hellwigaxboe
authored andcommitted
iomap: free the bio before completing the dio
There are good arguments for processing the user completions ASAP vs. freeing resources ASAP, but freeing the bio first here removes potential use after free hazards when checking flags, and will simplify the upcoming bounce buffer support. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Darrick J. Wong <djwong@kernel.org> Reviewed-by: Darrick J. Wong <djwong@kernel.org> Tested-by: Anuj Gupta <anuj20.g@samsung.com> Reviewed-by: Damien Le Moal <dlemoal@kernel.org> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent e2fcff5 commit 45cec0d

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

fs/iomap/direct-io.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,15 @@ static void iomap_dio_done(struct iomap_dio *dio)
214214
static void __iomap_dio_bio_end_io(struct bio *bio, bool inline_completion)
215215
{
216216
struct iomap_dio *dio = bio->bi_private;
217-
bool should_dirty = (dio->flags & IOMAP_DIO_DIRTY);
217+
218+
if (dio->flags & IOMAP_DIO_DIRTY) {
219+
bio_check_pages_dirty(bio);
220+
} else {
221+
bio_release_pages(bio, false);
222+
bio_put(bio);
223+
}
224+
225+
/* Do not touch bio below, we just gave up our reference. */
218226

219227
if (atomic_dec_and_test(&dio->ref)) {
220228
/*
@@ -225,13 +233,6 @@ static void __iomap_dio_bio_end_io(struct bio *bio, bool inline_completion)
225233
dio->flags &= ~IOMAP_DIO_COMP_WORK;
226234
iomap_dio_done(dio);
227235
}
228-
229-
if (should_dirty) {
230-
bio_check_pages_dirty(bio);
231-
} else {
232-
bio_release_pages(bio, false);
233-
bio_put(bio);
234-
}
235236
}
236237

237238
void iomap_dio_bio_end_io(struct bio *bio)

0 commit comments

Comments
 (0)