FAILED: patch "[PATCH] fuse: copy request headers via a stack buffer for io-uring" failed to apply to 6.18-stable tree
Subsystems (3)
[email protected]
maintainerThe patch below does not apply to the 6.18-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.18.y
git checkout FETCH_HEAD
git cherry-pick -x fd10f40af314f07b6d6e028b1ca25c8b49903aab
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026083142-defile-crewmate-74f2@gregkh' --subject-prefix 'PATCH 6.18.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From fd10f40af314f07b6d6e028b1ca25c8b49903aab Mon Sep 17 00:00:00 2001
From: Xiang Mei <[email protected]>
Date: Mon, 27 Jul 2026 16:37:04 -0700
Subject: [PATCH] fuse: copy request headers via a stack buffer for io-uring
The fuse-io-uring transport copies req->in.h out to the ring in fuse_uring_copy_to_ring() and req->out.h back in fuse_uring_commit(). Both headers live inside the fuse_request slab object, whose cache (fuse_req_cachep) is created without a usercopy whitelist, so copying them directly to/from userspace trips CONFIG_HARDENED_USERCOPY and panics:
usercopy: Kernel memory exposure attempt detected from SLUB object 'fuse_request' (offset 56, size 40)!
kernel BUG at mm/usercopy.c:102!
Oops: invalid opcode: 0000 [#1] SMP KASAN NOPTI RIP: 0010:usercopy_abort (mm/usercopy.c:90) Call Trace: __check_heap_object (mm/slub.c:8268) __check_object_size (mm/usercopy.c:197 mm/usercopy.c:258 mm/usercopy.c:223) copy_header_to_ring (fs/fuse/dev_uring.c:618) fuse_uring_prepare_send (fs/fuse/dev_uring.c:776 fs/fuse/dev_uring.c:785) fuse_uring_send_in_task (fs/fuse/dev_uring.c:1306) tctx_task_work_run (io_uring/tw.c:96) task_work_run (kernel/task_work.c:233) io_run_task_work (io_uring/tw.h:84) io_cqring_wait (io_uring/wait.c:278) __do_sys_io_uring_enter (io_uring/io_uring.c:2685) entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:121)
Bounce both headers through an on-stack copy so the usercopy touches stack memory, not the slab object.
fs/fuse/dev_uring.c +8 -4
@@ -922,6 +922,7 @@ static int fuse_uring_copy_to_ring(struct fuse_ring_ent *ent, unsigned int issue_flags) {struct fuse_ring_queue *queue = ent->queue; +struct fuse_in_header in_header;int err; err = -EIO ;
@@ -943,8 +944,9 @@ static int fuse_uring_copy_to_ring(struct fuse_ring_ent *ent, }/* copy fuse_in_header */ -return copy_header_to_ring (ent,FUSE_URING_HEADER_IN_OUT , &req->in.h, -sizeof (req->in.h)); + in_header = req->in.h; +return copy_header_to_ring (ent,FUSE_URING_HEADER_IN_OUT , &in_header, +sizeof (in_header)); } static bool fuse_uring_req_has_copyable_payload(struct fuse_ring_ent *ent,
@@ -1151,11 +1153,13 @@ static struct fuse_req *fuse_uring_ent_assign_req(struct fuse_ring_ent *ent)static void fuse_uring_commit (struct fuse_ring_ent *ent,struct fuse_req *req,unsigned int issue_flags) { +struct fuse_out_header out_header;ssize_t err = -EFAULT ; -if (copy_header_from_ring (ent,FUSE_URING_HEADER_IN_OUT , &req->out.h, -sizeof (req->out.h))) +if (copy_header_from_ring (ent,FUSE_URING_HEADER_IN_OUT , &out_header, +sizeof (out_header))) goto out; + req->out.h = out_header; err =fuse_uring_out_header_has_err (&req->out.h, req);if (err) {
Sasha Levin
maintainerPATCH 1/6 fuse-uring: refactor io-uring header copying to ring
From: Joanne Koong <[email protected]>
[ Upstream commit 6582f8a06698403dccf8a01b7eef176b2c6dd7ff ]
Move header copying to ring logic into a new copy_header_to_ring() function. This makes the copy_to_user() logic more clear and centralizes error handling / rate-limited logging.
Stable-dep-of: fd10f40af314 ("fuse: copy request headers via a stack buffer for io-uring")
--- fs/fuse/dev_uring.c | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-)
fs/fuse/dev_uring.c +21 -18
@@ -579,6 +579,18 @@ static int fuse_uring_out_header_has_err(struct fuse_out_header *oh,return err; } +static __always_inline int copy_header_to_ring(void __user *ring, +const void *header, +size_t header_size) +{ +if (copy_to_user (ring, header, header_size)) { +pr_info_ratelimited ("Copying header to 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)
@@ -641,13 +653,11 @@ static int fuse_uring_args_to_ring(struct fuse_ring *ring, struct fuse_req *req,* Some op code have that as zero size. */ if (args->in_args[0 ].size >0 ) { - err =copy_to_user (&ent->headers->op_in, in_args->value, - in_args->size); -if (err) { -pr_info_ratelimited ( -"Copying the header failed.\n" ); -return -EFAULT ; - } + err =copy_header_to_ring (&ent->headers->op_in, + in_args->value, + in_args->size); +if (err) +return err; } in_args++; num_args--;
@@ -663,9 +673,8 @@ static int fuse_uring_args_to_ring(struct fuse_ring *ring, struct fuse_req *req, } ent_in_out.payload_sz = cs.ring.copied_sz; - err =copy_to_user (&ent->headers->ring_ent_in_out, &ent_in_out, -sizeof (ent_in_out)); -return err ? -EFAULT :0 ; +return copy_header_to_ring (&ent->headers->ring_ent_in_out, &ent_in_out, +sizeof (ent_in_out)); } static int fuse_uring_copy_to_ring(struct fuse_ring_ent *ent,
@@ -694,14 +703,8 @@ static int fuse_uring_copy_to_ring(struct fuse_ring_ent *ent, }/* copy fuse_in_header */ - err =copy_to_user (&ent->headers->in_out, &req->in.h, -sizeof (req->in.h)); -if (err) { - err = -EFAULT ; -return err; - } - -return 0 ; +return copy_header_to_ring (&ent->headers->in_out, &req->in.h, +sizeof (req->in.h)); } static int fuse_uring_prepare_send(struct fuse_ring_ent *ent,
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/6 fuse-uring: refactor io-uring header copying from ring
From: Joanne Koong <[email protected]>
[ Upstream commit ba7d47897fd895533c19af436ca7fc4f6b171238 ]
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.
Stable-dep-of: fd10f40af314 ("fuse: copy request headers via a stack buffer for io-uring")
--- fs/fuse/dev_uring.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-)
fs/fuse/dev_uring.c +17 -5
@@ -591,6 +591,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)
@@ -601,10 +613,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);
@@ -840,8 +852,8 @@ static void fuse_uring_commit(struct fuse_ring_ent *ent, struct fuse_req *req,struct fuse_conn *fc = ring->fc;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, fc);
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 3/6 fuse-uring: use enum types for header copying
In reply to Sasha LevinFrom: Joanne Koong <[email protected]>
[ Upstream commit b2bbd7dcd2433e29b7e9a726aaa9571a78fa8d5f ]
Use enum types to identify which part of the header needs to be copied. This improves the interface and will simplify both kernel-space and user-space header addresses copying when buffer rings are added.
Stable-dep-of: fd10f40af314 ("fuse: copy request headers via a stack buffer for io-uring")
--- fs/fuse/dev_uring.c | 66 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 53 insertions(+), 13 deletions(-)
fs/fuse/dev_uring.c +53 -13
@@ -31,6 +31,15 @@ struct fuse_uring_pdu {static const struct fuse_iqueue_ops fuse_io_uring_ops; +enum fuse_uring_header_type { +/* struct fuse_in_header / struct fuse_out_header */ +FUSE_URING_HEADER_IN_OUT , +/* per op code header */ +FUSE_URING_HEADER_OP , +/* struct fuse_uring_ent_in_out header */ +FUSE_URING_HEADER_RING_ENT , +}; +static void uring_cmd_set_ring_ent (struct io_uring_cmd *cmd,struct fuse_ring_ent *ring_ent) {
@@ -579,10 +588,33 @@ static int fuse_uring_out_header_has_err(struct fuse_out_header *oh,return err; } -static __always_inline int copy_header_to_ring(void __user *ring, -const void *header, -size_t header_size) +static int ring_header_type_offset (enum fuse_uring_header_type type) { +switch (type) { +case FUSE_URING_HEADER_IN_OUT : +return 0 ; +case FUSE_URING_HEADER_OP : +return offsetof(struct fuse_uring_req_header , op_in); +case FUSE_URING_HEADER_RING_ENT : +return offsetof(struct fuse_uring_req_header , ring_ent_in_out); +default : +WARN_ONCE (1 ,"Invalid header type: %d\n" , type); +return -EINVAL ; + } +} + +static int copy_header_to_ring (struct fuse_ring_ent *ent, +enum fuse_uring_header_type type, +const void *header,size_t header_size) +{ +int offset =ring_header_type_offset (type); +void __user *ring; + +if (offset <0 ) +return offset; + + ring = (void __user *)ent->headers + offset; +if (copy_to_user (ring, header, header_size)) {pr_info_ratelimited ("Copying header to ring failed.\n" );return -EFAULT ;
@@ -591,10 +623,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) +static int copy_header_from_ring (struct fuse_ring_ent *ent, +enum fuse_uring_header_type type,void *header, +size_t header_size) { +int offset =ring_header_type_offset (type); +const void __user *ring; + +if (offset <0 ) +return offset; + + ring = (void __user *)ent->headers + offset; +if (copy_from_user (header, ring, header_size)) {pr_info_ratelimited ("Copying header from ring failed.\n" );return -EFAULT ;
@@ -613,8 +653,8 @@ static int fuse_uring_copy_from_ring(struct fuse_ring *ring,int err;struct fuse_uring_ent_in_out ring_in_out; - err =copy_header_from_ring (&ring_in_out, &ent->headers->ring_ent_in_out, -sizeof (ring_in_out)); + err =copy_header_from_ring (ent,FUSE_URING_HEADER_RING_ENT , + &ring_in_out,sizeof (ring_in_out));if (err)return err;
@@ -665,7 +705,7 @@ static int fuse_uring_args_to_ring(struct fuse_ring *ring, struct fuse_req *req,* Some op code have that as zero size. */ if (args->in_args[0 ].size >0 ) { - err =copy_header_to_ring (&ent->headers->op_in, + err =copy_header_to_ring (ent,FUSE_URING_HEADER_OP , in_args->value, in_args->size);if (err)
@@ -685,8 +725,8 @@ static int fuse_uring_args_to_ring(struct fuse_ring *ring, struct fuse_req *req, } ent_in_out.payload_sz = cs.ring.copied_sz; -return copy_header_to_ring (&ent->headers->ring_ent_in_out, &ent_in_out, -sizeof (ent_in_out)); +return copy_header_to_ring (ent,FUSE_URING_HEADER_RING_ENT , + &ent_in_out,sizeof (ent_in_out)); } static int fuse_uring_copy_to_ring(struct fuse_ring_ent *ent,
@@ -715,7 +755,7 @@ static int fuse_uring_copy_to_ring(struct fuse_ring_ent *ent, }/* copy fuse_in_header */ -return copy_header_to_ring (&ent->headers->in_out, &req->in.h, +return copy_header_to_ring (ent,FUSE_URING_HEADER_IN_OUT , &req->in.h,sizeof (req->in.h)); }
@@ -852,7 +892,7 @@ static void fuse_uring_commit(struct fuse_ring_ent *ent, struct fuse_req *req,struct fuse_conn *fc = ring->fc;ssize_t err = -EFAULT ; -if (copy_header_from_ring (&req->out.h, &ent->headers->in_out, +if (copy_header_from_ring (ent,FUSE_URING_HEADER_IN_OUT , &req->out.h,sizeof (req->out.h))) goto out;
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 4/6 fuse-uring: refactor setting up copy state for payload copying
In reply to Sasha LevinFrom: Joanne Koong <[email protected]>
[ Upstream commit c0f9203732fc70de8d20697270bfe405481eac14 ]
Add a new helper function setup_fuse_copy_state() to contain the logic for setting up the copy state for payload copying.
Stable-dep-of: fd10f40af314 ("fuse: copy request headers via a stack buffer for io-uring")
--- fs/fuse/dev_uring.c | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-)
fs/fuse/dev_uring.c +24 -14
@@ -643,6 +643,27 @@ static int copy_header_from_ring(struct fuse_ring_ent *ent,return 0 ; } +static int setup_fuse_copy_state (struct fuse_copy_state *cs, +struct fuse_ring *ring,struct fuse_req *req, +struct fuse_ring_ent *ent,int dir, +struct iov_iter *iter) +{ +int err; + + err =import_ubuf (dir, ent->payload, ring->max_payload_sz, iter); +if (err) { +pr_info_ratelimited ("fuse: Import of user buffer failed\n" ); +return err; + } + +fuse_copy_init (cs, dir ==ITER_DEST , iter); + + cs->is_uring = true; + cs->req = req; + +return 0 ; +} +static int fuse_uring_copy_from_ring (struct fuse_ring *ring,struct fuse_req *req,struct fuse_ring_ent *ent)
@@ -658,15 +679,10 @@ static int fuse_uring_copy_from_ring(struct fuse_ring *ring,if (err)return err; - err =import_ubuf (ITER_SOURCE , ent->payload, ring->max_payload_sz, - &iter); + err =setup_fuse_copy_state (&cs, ring, req, ent,ITER_SOURCE , &iter);if (err)return err; -fuse_copy_init (&cs, false, &iter); - cs.is_uring = true; - cs.req = req; - err =fuse_copy_out_args (&cs, args, ring_in_out.payload_sz);fuse_copy_finish (&cs);return err;
@@ -689,15 +705,9 @@ static int fuse_uring_args_to_ring(struct fuse_ring *ring, struct fuse_req *req, .commit_id = req->in.h.unique, }; - err =import_ubuf (ITER_DEST , ent->payload, ring->max_payload_sz, &iter); -if (err) { -pr_info_ratelimited ("fuse: Import of user buffer failed\n" ); + err =setup_fuse_copy_state (&cs, ring, req, ent,ITER_DEST , &iter); +if (err)return err; - } - -fuse_copy_init (&cs, true, &iter); - cs.is_uring = true; - cs.req = req;if (num_args >0 ) {/*
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 5/6 fuse-uring: use named constants for io-uring iovec indices
In reply to Sasha LevinFrom: Joanne Koong <[email protected]>
[ Upstream commit 8bbb2ad1f687633a991839bd3efae04ccfb29e19 ]
Replace magic indices 0 and 1 for the iovec array with named constants FUSE_URING_IOV_HEADERS and FUSE_URING_IOV_PAYLOAD. This makes the usages self-documenting and prepares for buffer ring support which will also reference these iovec slots by index.
Stable-dep-of: fd10f40af314 ("fuse: copy request headers via a stack buffer for io-uring")
--- fs/fuse/dev_uring.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-)
fs/fuse/dev_uring.c +13 -11
@@ -18,7 +18,8 @@ MODULE_PARM_DESC(enable_uring, "Enable userspace communication through io-uring");#define FUSE_URING_IOV_SEGS 2/* header and payload */ - +#define FUSE_URING_IOV_HEADERS 0 +#define FUSE_URING_IOV_PAYLOAD 1bool fuse_uring_enabled (void ) {
@@ -1103,8 +1104,8 @@ static int fuse_uring_do_register(struct fuse_ring_ent *ent, }/* -* sqe->addr is a ptr to an iovec array, iov[0] has the headers, iov[1] -* the payload +* sqe->addr is a ptr to an iovec array, iov[FUSE_URING_IOV_HEADERS] has the +* headers, iov[FUSE_URING_IOV_PAYLOAD] the payload */ static int fuse_uring_get_iovec_from_sqe (const struct io_uring_sqe *sqe,struct iovec iov[FUSE_URING_IOV_SEGS ])
@@ -1134,8 +1135,8 @@ fuse_uring_create_ring_ent(struct io_uring_cmd *cmd, {struct fuse_ring *ring = queue->ring;struct fuse_ring_ent *ent; -size_t payload_size;struct iovec iov[FUSE_URING_IOV_SEGS ]; +struct iovec *headers, *payload;int err; err =fuse_uring_get_iovec_from_sqe (cmd->sqe, iov);
@@ -1146,15 +1147,16 @@ fuse_uring_create_ring_ent(struct io_uring_cmd *cmd, } err = -EINVAL ; -if (iov[0 ].iov_len <sizeof (struct fuse_uring_req_header )) { -pr_info_ratelimited ("Invalid header len %zu\n" , iov[0 ].iov_len); + headers = &iov[FUSE_URING_IOV_HEADERS ]; +if (headers->iov_len <sizeof (struct fuse_uring_req_header )) { +pr_info_ratelimited ("Invalid header len %zu\n" , headers->iov_len);return ERR_PTR (err); } - payload_size = iov[1 ].iov_len; -if (payload_size < ring->max_payload_sz) { + payload = &iov[FUSE_URING_IOV_PAYLOAD ]; +if (payload->iov_len < ring->max_payload_sz) {pr_info_ratelimited ("Invalid req payload len %zu\n" , - payload_size); + payload->iov_len);return ERR_PTR (err); }
@@ -1166,8 +1168,8 @@ fuse_uring_create_ring_ent(struct io_uring_cmd *cmd,INIT_LIST_HEAD (&ent->list); ent->queue = queue; - ent->headers = iov[0 ].iov_base; - ent->payload = iov[1 ].iov_base; + ent->headers = headers->iov_base; + ent->payload = payload->iov_base;atomic_inc (&ring->queue_refs);return ent;
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 6/6 fuse: copy request headers via a stack buffer for io-uring
In reply to Sasha LevinFrom: Xiang Mei <[email protected]>
[ Upstream commit fd10f40af314f07b6d6e028b1ca25c8b49903aab ]
The fuse-io-uring transport copies req->in.h out to the ring in fuse_uring_copy_to_ring() and req->out.h back in fuse_uring_commit(). Both headers live inside the fuse_request slab object, whose cache (fuse_req_cachep) is created without a usercopy whitelist, so copying them directly to/from userspace trips CONFIG_HARDENED_USERCOPY and panics:
usercopy: Kernel memory exposure attempt detected from SLUB object 'fuse_request' (offset 56, size 40)!
kernel BUG at mm/usercopy.c:102!
Oops: invalid opcode: 0000 [#1] SMP KASAN NOPTI RIP: 0010:usercopy_abort (mm/usercopy.c:90) Call Trace: __check_heap_object (mm/slub.c:8268) __check_object_size (mm/usercopy.c:197 mm/usercopy.c:258 mm/usercopy.c:223) copy_header_to_ring (fs/fuse/dev_uring.c:618) fuse_uring_prepare_send (fs/fuse/dev_uring.c:776 fs/fuse/dev_uring.c:785) fuse_uring_send_in_task (fs/fuse/dev_uring.c:1306) tctx_task_work_run (io_uring/tw.c:96) task_work_run (kernel/task_work.c:233) io_run_task_work (io_uring/tw.h:84) io_cqring_wait (io_uring/wait.c:278) __do_sys_io_uring_enter (io_uring/io_uring.c:2685) entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:121)
Bounce both headers through an on-stack copy so the usercopy touches stack memory, not the slab object.
--- fs/fuse/dev_uring.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
fs/fuse/dev_uring.c +8 -4
@@ -745,6 +745,7 @@ static int fuse_uring_copy_to_ring(struct fuse_ring_ent *ent, {struct fuse_ring_queue *queue = ent->queue;struct fuse_ring *ring = queue->ring; +struct fuse_in_header in_header;int err; err = -EIO ;
@@ -766,8 +767,9 @@ static int fuse_uring_copy_to_ring(struct fuse_ring_ent *ent, }/* copy fuse_in_header */ -return copy_header_to_ring (ent,FUSE_URING_HEADER_IN_OUT , &req->in.h, -sizeof (req->in.h)); + in_header = req->in.h; +return copy_header_to_ring (ent,FUSE_URING_HEADER_IN_OUT , &in_header, +sizeof (in_header)); } static int fuse_uring_prepare_send(struct fuse_ring_ent *ent,
@@ -901,11 +903,13 @@ 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; +struct fuse_out_header out_header;ssize_t err = -EFAULT ; -if (copy_header_from_ring (ent,FUSE_URING_HEADER_IN_OUT , &req->out.h, -sizeof (req->out.h))) +if (copy_header_from_ring (ent,FUSE_URING_HEADER_IN_OUT , &out_header, +sizeof (out_header))) goto out; + req->out.h = out_header; err =fuse_uring_out_header_has_err (&req->out.h, req, fc);if (err) {
Signature · 1 line
2.53.0