浏览代码

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 <mbroz@redhat.com>
Signed-off-by: Alasdair G Kergon <agk@redhat.com>
Milan Broz 16 年之前
父节点
当前提交
4e59409891
共有 1 个文件被更改,包括 2 次插入3 次删除
  1. 2 3
      drivers/md/dm-crypt.c

+ 2 - 3
drivers/md/dm-crypt.c

@@ -719,16 +719,15 @@ static void kcryptd_crypt_write_convert(struct dm_crypt_io *io)
 
 
 		remaining -= clone->bi_size;
 		remaining -= clone->bi_size;
 
 
+		crypt_inc_pending(io);
 		r = crypt_convert(cc, &io->ctx);
 		r = crypt_convert(cc, &io->ctx);
 
 
 		if (atomic_dec_and_test(&io->ctx.pending)) {
 		if (atomic_dec_and_test(&io->ctx.pending)) {
 			/* processed, no running async crypto  */
 			/* processed, no running async crypto  */
-			crypt_inc_pending(io);
 			kcryptd_crypt_write_io_submit(io, r, 0);
 			kcryptd_crypt_write_io_submit(io, r, 0);
 			if (unlikely(r < 0))
 			if (unlikely(r < 0))
 				break;
 				break;
-		} else
-			crypt_inc_pending(io);
+		}
 
 
 		/* out of memory -> run queues */
 		/* out of memory -> run queues */
 		if (unlikely(remaining)) {
 		if (unlikely(remaining)) {