io_uring: implement ->flush() sequence to handle ->files validity io_uring-files_struct
authorJens Axboe <axboe@kernel.dk>
Thu, 10 Sep 2020 22:06:21 +0000 (16:06 -0600)
committerJens Axboe <axboe@kernel.dk>
Fri, 11 Sep 2020 22:36:38 +0000 (16:36 -0600)
commit426edbc9ac48900d6d43e30ec7c84cb5afd96a08
treeaf07a48e4d0d73086379bce19a65816c18afb3fa
parent3d2f5519f3bd904bd8ac25278daef33e9919b142
io_uring: implement ->flush() sequence to handle ->files validity

The current scheme stashes away ->ring_fd and ->ring_file, and uses
that to check against whether or not ->files could have changed. This
works, but doesn't work so well for SQPOLL. If the application does
close the ring_fd, then we require that applications enter the kernel
to refresh our state.

Add an atomic sequence for the ->flush() count on the ring fd, and if
we get a mismatch between checking this sequence before and after
grabbing the ->files, then we fail the request.

This should offer the same protection that we currently have, with the
added benefit of being able to update the ->files automatically.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
fs/io_uring.c