io_uring: fix poll file assign deadlock
authorPavel Begunkov <asml.silence@gmail.com>
Mon, 18 Apr 2022 12:40:30 +0000 (06:40 -0600)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 20 Apr 2022 07:36:28 +0000 (09:36 +0200)
commit cce64ef01308b677a687d90927fc2b2e0e1cba67 upstream.

We pass "unlocked" into io_assign_file() in io_poll_check_events(),
which can lead to double locking.

Fixes: 6bf9c47a3989 ("io_uring: defer file assignment")
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Link: https://lore.kernel.org/r/2476d4ae46554324b599ee4055447b105f20a75a.1649862516.git.asml.silence@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/io_uring.c

index 34e540755c9f9334bb11dd9718539c08846f9f6e..6ddafa3af17010801559d5395edb940cb970d4a1 100644 (file)
@@ -5510,8 +5510,9 @@ static int io_poll_check_events(struct io_kiocb *req, bool locked)
 
                if (!req->result) {
                        struct poll_table_struct pt = { ._key = poll->events };
+                       unsigned flags = locked ? 0 : IO_URING_F_UNLOCKED;
 
-                       if (unlikely(!io_assign_file(req, IO_URING_F_UNLOCKED)))
+                       if (unlikely(!io_assign_file(req, flags)))
                                req->result = -EBADF;
                        else
                                req->result = vfs_poll(req->file, &pt) & poll->events;