io_uring/msg_ring: enforce target ring fixed-file update restrictions
PATCH 1/1 io_uring/msg_ring: enforce target ring fixed-file update restrictions
When transferring a fixed file descriptor between rings via IORING_OP_MSG_RING with IORING_MSG_SEND_FD, restrictions are currently evaluated only on the sending ring. io_msg_send_fd() checks that target_ctx does not have IORING_SETUP_R_DISABLED set, and then installs src_file into target_ctx's fixed-file table via __io_fixed_fd_install() without checking target_ctx's register restrictions.
If an application broker populates fixed-file slots on a ring, locks it with IORING_REGISTER_RESTRICTIONS disallowing IORING_REGISTER_FILES_UPDATE and IORING_REGISTER_FILES_UPDATE2, and passes that ring to a sandboxed process that can still create a second unrestricted ring, the process can use IORING_MSG_SEND_FD to install or overwrite fixed-file slots in the restricted target ring.
After the smp_load_acquire(&target_ctx->flags) check in io_msg_send_fd(), reject the operation with -EACCES if target_ctx->restrictions.reg_registered is set and neither IORING_REGISTER_FILES_UPDATE nor IORING_REGISTER_FILES_UPDATE2 is permitted in target_ctx->restrictions.register_op. Checking the immutable reg_registered field avoids racing with uring_lock-protected updates to target_ctx->int_flags.
This issue was discovered with an AI-assisted code review tool (ARTIST) and reproduced in QEMU/KVM on an unmodified v7.4-rc3 kernel without kernel modifications or error injection; a standalone reproducer is available upon maintainers' request. This fix was compile-tested with -Werror and checked with checkpatch.pl --strict; an equivalent fix was verified against the reproducer in QEMU/KVM.
--- io_uring/msg_ring.c | 6 ++++++ 1 file changed, 6 insertions(+)
io_uring/msg_ring.c +6 -0
@@ -267,6 +267,12 @@ static int io_msg_send_fd(struct io_kiocb *req, unsigned int issue_flags)*/ if (smp_load_acquire (&target_ctx->flags) &IORING_SETUP_R_DISABLED )return -EBADFD ; +if (target_ctx->restrictions.reg_registered && + !test_bit (IORING_REGISTER_FILES_UPDATE , + target_ctx->restrictions.register_op) && + !test_bit (IORING_REGISTER_FILES_UPDATE2 , + target_ctx->restrictions.register_op)) +return -EACCES ;if (!msg->src_file) {int ret =io_msg_grab_file (req, issue_flags);if (unlikely (ret))
Signature · 1 line
2.56.1.750.gf70dc682cf-goog