]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
fuse-uring: refactor io-uring header copying from ring
authorJoanne Koong <joannelkoong@gmail.com>
Fri, 12 Jun 2026 21:05:06 +0000 (14:05 -0700)
committerMiklos Szeredi <mszeredi@redhat.com>
Mon, 15 Jun 2026 12:06:20 +0000 (14:06 +0200)
Move header copying from ring logic into a new copy_header_from_ring()
function. This makes the copy_from_user() logic more clear and
centralizes error handling / rate-limited logging.

Reviewed-by: Bernd Schubert <bschubert@ddn.com>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Reviewed-by: Baokun Li <libaokun@linux.alibaba.com>
Signed-off-by: Joanne Koong <joannelkoong@gmail.com>
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
fs/fuse/dev_uring.c

index 1d37a2ee5532729cbe23cbd1e9ab5b375ac0caf8..42627838cfa69078f6430a57eb79af5714653004 100644 (file)
@@ -590,6 +590,18 @@ static __always_inline int copy_header_to_ring(void __user *ring,
        return 0;
 }
 
+static __always_inline int copy_header_from_ring(void *header,
+                                                const void __user *ring,
+                                                size_t header_size)
+{
+       if (copy_from_user(header, ring, header_size)) {
+               pr_info_ratelimited("Copying header from ring failed.\n");
+               return -EFAULT;
+       }
+
+       return 0;
+}
+
 static int fuse_uring_copy_from_ring(struct fuse_ring *ring,
                                     struct fuse_req *req,
                                     struct fuse_ring_ent *ent)
@@ -600,10 +612,10 @@ static int fuse_uring_copy_from_ring(struct fuse_ring *ring,
        int err;
        struct fuse_uring_ent_in_out ring_in_out;
 
-       err = copy_from_user(&ring_in_out, &ent->headers->ring_ent_in_out,
-                            sizeof(ring_in_out));
+       err = copy_header_from_ring(&ring_in_out, &ent->headers->ring_ent_in_out,
+                                   sizeof(ring_in_out));
        if (err)
-               return -EFAULT;
+               return err;
 
        err = import_ubuf(ITER_SOURCE, ent->payload, ring->max_payload_sz,
                          &iter);
@@ -810,8 +822,8 @@ static void fuse_uring_commit(struct fuse_ring_ent *ent, struct fuse_req *req,
        struct fuse_ring *ring = ent->queue->ring;
        ssize_t err = -EFAULT;
 
-       if (copy_from_user(&req->out.h, &ent->headers->in_out,
-                          sizeof(req->out.h)))
+       if (copy_header_from_ring(&req->out.h, &ent->headers->in_out,
+                                 sizeof(req->out.h)))
                goto out;
 
        err = fuse_uring_out_header_has_err(&req->out.h, req);