Skip to content

Commit 4e59409

Browse files
Milan Brozkergon
authored andcommitted
dm crypt: fix async inc_pending
The pending reference count must be incremented *before* the async work is queued to another thread, not after. Otherwise there's a race if the work completes and decrements the reference count before it gets incremented. Signed-off-by: Milan Broz <[email protected]> Signed-off-by: Alasdair G Kergon <[email protected]>
1 parent 6c031f4 commit 4e59409

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

drivers/md/dm-crypt.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -719,16 +719,15 @@ static void kcryptd_crypt_write_convert(struct dm_crypt_io *io)
719719

720720
remaining -= clone->bi_size;
721721

722+
crypt_inc_pending(io);
722723
r = crypt_convert(cc, &io->ctx);
723724

724725
if (atomic_dec_and_test(&io->ctx.pending)) {
725726
/* processed, no running async crypto */
726-
crypt_inc_pending(io);
727727
kcryptd_crypt_write_io_submit(io, r, 0);
728728
if (unlikely(r < 0))
729729
break;
730-
} else
731-
crypt_inc_pending(io);
730+
}
732731

733732
/* out of memory -> run queues */
734733
if (unlikely(remaining)) {

0 commit comments

Comments
 (0)