Skip to contentSkip to conversation

fs:Fix Possible deadlock on spinlock "ctx_lock" when user aborts process using async-IO with ctrl-C

PATCH New Nicholas Krause 1 participant 1 message Aug 26, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fs:Fix Possible deadlock on spinlock "ctx_lock" when user aborts process using async-IO with ctrl-C

This fixes a possible deadlock on spinlock ctx_lock used the percpu ref structure before calling kiocb_cancel, this is due to the issue of us reattempting to lock on calling aio_complete from within kiob_cancel as the kiocb_cancel_fn function pointer which in term causes a deadlock. This is easily fixed by unlocking the ctx_lock with spin_lock_irq and locking afterward the call to kiocb_cancel in order to avoid this deadlock when the user aborts a process using async-IO with ctrl-C.

---
 fs/aio.c | 2 ++
 1 file changed, 2 insertions(+)
fs/aio.c +2 -0
index fb8e45b..3107b92 100644
@@ -615,7 +615,9 @@ static void free_ioctx_users(struct percpu_ref *ref)
 				       struct aio_kiocb, ki_list);
 
 		list_del_init(&req->ki_list);
+		spin_unlock_irq(&ctx->ctx_lock);
 		kiocb_cancel(req);
+		spin_lock_irq(&ctx->ctx_lock);
 	}
 
 	spin_unlock_irq(&ctx->ctx_lock);
Signature · 7 lines
2.7.4

--
To unsubscribe, send a message with 'unsubscribe linux-aio' in
the body to [email protected].  For more info on Linux AIO,
see: http://www.kvack.org/aio/
Don't email: <a href=mailto:"[email protected]">[email protected]</a>