io_uring/uring_cmd: don't assume io_uring_cmd_data layout
authorCaleb Sander Mateos <csander@purestorage.com>
Wed, 12 Feb 2025 20:45:45 +0000 (13:45 -0700)
committerJens Axboe <axboe@kernel.dk>
Wed, 12 Feb 2025 20:58:43 +0000 (13:58 -0700)
eaf72f7b414f ("io_uring/uring_cmd: cleanup struct io_uring_cmd_data
layout") removed most of the places assuming struct io_uring_cmd_data
has sqes as its first field. However, the EAGAIN case in io_uring_cmd()
still compares ioucmd->sqe to the struct io_uring_cmd_data pointer using
a void * cast. Since fa3595523d72 ("io_uring: get rid of alloc cache
init_once handling"), sqes is no longer io_uring_cmd_data's first field.
As a result, the pointers will always compare unequal and memcpy() may
be called with the same source and destination.

Replace the incorrect void * cast with the address of the sqes field.

Signed-off-by: Caleb Sander Mateos <csander@purestorage.com>
Fixes: eaf72f7b414f ("io_uring/uring_cmd: cleanup struct io_uring_cmd_data layout")
Link: https://lore.kernel.org/r/20250212204546.3751645-2-csander@purestorage.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
io_uring/uring_cmd.c

index 1f6a82128b475f29017a1f77c175fd555405855a..cfb22e1de0e757112e73799c3a6806aa450295ac 100644 (file)
@@ -252,7 +252,7 @@ int io_uring_cmd(struct io_kiocb *req, unsigned int issue_flags)
        if (ret == -EAGAIN) {
                struct io_uring_cmd_data *cache = req->async_data;
 
-               if (ioucmd->sqe != (void *) cache)
+               if (ioucmd->sqe != cache->sqes)
                        memcpy(cache->sqes, ioucmd->sqe, uring_sqe_size(req->ctx));
                return -EAGAIN;
        } else if (ret == -EIOCBQUEUED) {