Skip to content

Commit 7778877

Browse files
committed
io_uring: don't assume mm is constant across submits
If we COW the identity, we assume that ->mm never changes. But this isn't true of multiple processes end up sharing the ring. Hence treat id->mm like like any other process compontent when it comes to the identity mapping. This is pretty trivial, just moving the existing grab into io_grab_identity(), and including a check for the match. Cc: [email protected] # 5.10 Fixes: 1e6fa52 ("io_uring: COW io_identity on mismatch") Reported-by: Christian Brauner <[email protected]>: Tested-by: Christian Brauner <[email protected]>: Signed-off-by: Jens Axboe <[email protected]>
1 parent 5c8fe58 commit 7778877

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

fs/io_uring.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,6 +1501,13 @@ static bool io_grab_identity(struct io_kiocb *req)
15011501
spin_unlock_irq(&ctx->inflight_lock);
15021502
req->work.flags |= IO_WQ_WORK_FILES;
15031503
}
1504+
if (!(req->work.flags & IO_WQ_WORK_MM) &&
1505+
(def->work_flags & IO_WQ_WORK_MM)) {
1506+
if (id->mm != current->mm)
1507+
return false;
1508+
mmgrab(id->mm);
1509+
req->work.flags |= IO_WQ_WORK_MM;
1510+
}
15041511

15051512
return true;
15061513
}
@@ -1525,13 +1532,6 @@ static void io_prep_async_work(struct io_kiocb *req)
15251532
req->work.flags |= IO_WQ_WORK_UNBOUND;
15261533
}
15271534

1528-
/* ->mm can never change on us */
1529-
if (!(req->work.flags & IO_WQ_WORK_MM) &&
1530-
(def->work_flags & IO_WQ_WORK_MM)) {
1531-
mmgrab(id->mm);
1532-
req->work.flags |= IO_WQ_WORK_MM;
1533-
}
1534-
15351535
/* if we fail grabbing identity, we must COW, regrab, and retry */
15361536
if (io_grab_identity(req))
15371537
return;

0 commit comments

Comments
 (0)