]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
fuse-uring: fix EFAULT clobber in fuse_uring_commit
authorChris Mason <clm@meta.com>
Fri, 5 Jun 2026 19:27:06 +0000 (12:27 -0700)
committerMiklos Szeredi <mszeredi@redhat.com>
Mon, 15 Jun 2026 12:06:13 +0000 (14:06 +0200)
copy_from_user() returns the number of bytes not copied as an unsigned
residual on failure (1..sizeof(struct fuse_out_header)). fuse_uring_commit
stores that residual in ssize_t err, sets req->out.h.error to -EFAULT,
then jumps to out: with err still holding the positive residual.

    err = copy_from_user(&req->out.h, &ent->headers->in_out,
                         sizeof(req->out.h));
    if (err) {
        req->out.h.error = -EFAULT;
        goto out;          /* err is the positive residual */
    }
    ...
    out:
        fuse_uring_req_end(ent, req, err);

fuse_uring_req_end() then runs

    if (error)
        req->out.h.error = error;

which overwrites the just-assigned -EFAULT with the positive residual.
FUSE callers such as fuse_simple_request() test err < 0 to detect
failure, so the positive value is interpreted as success and the
caller proceeds with an uninitialised or partial req->out.args.

Fix by assigning err = -EFAULT in the failure branch before jumping
to out, so fuse_uring_req_end() receives a negative errno and sets
req->out.h.error to -EFAULT.

Fixes: c090c8abae4b ("fuse: Add io-uring sqe commit and fetch support")
Cc: stable@vger.kernel.org
Reviewed-by: Joanne Koong <joannelkoong@gmail.com>
Assisted-by: kres (claude-opus-4-7)
Signed-off-by: Chris Mason <clm@meta.com>
Reviewed-by: Bernd Schubert <bernd@bsbernd.com>
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
fs/fuse/dev_uring.c

index 7b9822e8837bce8c96ef6b3f0fe6990656fc5787..c79652a0e3378e2883895c6858a8fe015751cd19 100644 (file)
@@ -813,14 +813,11 @@ static void fuse_uring_commit(struct fuse_ring_ent *ent, struct fuse_req *req,
 {
        struct fuse_ring *ring = ent->queue->ring;
        struct fuse_conn *fc = ring->fc;
-       ssize_t err = 0;
+       ssize_t err = -EFAULT;
 
-       err = copy_from_user(&req->out.h, &ent->headers->in_out,
-                            sizeof(req->out.h));
-       if (err) {
-               req->out.h.error = -EFAULT;
+       if (copy_from_user(&req->out.h, &ent->headers->in_out,
+                          sizeof(req->out.h)))
                goto out;
-       }
 
        err = fuse_uring_out_header_has_err(&req->out.h, req, fc);
        if (err) {