FAILED: patch "[PATCH] io_uring/net: commit partial buffers on retry" failed to apply to 6.6-stable tree
Subsystems (2)
[email protected]
maintainerThe patch below does not apply to the 6.6-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.6.y
git checkout FETCH_HEAD
git cherry-pick -x 41b70df5b38bc80967d2e0ed55cc3c3896bba781
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2025081549-shorter-borrower-941d@gregkh' --subject-prefix 'PATCH 6.6.y' HEAD^..
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 41b70df5b38bc80967d2e0ed55cc3c3896bba781 Mon Sep 17 00:00:00 2001
From: Jens Axboe <[email protected]>
Date: Tue, 12 Aug 2025 08:30:11 -0600
Subject: [PATCH] io_uring/net: commit partial buffers on retry
Ring provided buffers are potentially only valid within the single execution context in which they were acquired. io_uring deals with this and invalidates them on retry. But on the networking side, if MSG_WAITALL is set, or if the socket is of the streaming type and too little was processed, then it will hang on to the buffer rather than recycle or commit it. This is problematic for two reasons:
1) If someone unregisters the provided buffer ring before a later retry, then the req->buf_list will no longer be valid.
2) If multiple sockers are using the same buffer group, then multiple receives can consume the same memory. This can cause data corruption in the application, as either receive could land in the same userspace buffer.
Fix this by disallowing partial retries from pinning a provided buffer across multiple executions, if ring provided buffers are used.
io_uring/net.c +15 -12
@@ -494,6 +494,15 @@ static int io_bundle_nbufs(struct io_async_msghdr *kmsg, int ret)return nbufs; } +static int io_net_kbuf_recyle (struct io_kiocb *req, +struct io_async_msghdr *kmsg,int len) +{ + req->flags |=REQ_F_BL_NO_RECYCLE ; +if (req->flags &REQ_F_BUFFERS_COMMIT ) +io_kbuf_commit (req, req->buf_list, len,io_bundle_nbufs (kmsg, len)); +return IOU_RETRY ; +} +static inline bool io_send_finish (struct io_kiocb *req,int *ret,struct io_async_msghdr *kmsg,unsigned issue_flags)
@@ -562,8 +571,7 @@ int io_sendmsg(struct io_kiocb *req, unsigned int issue_flags) kmsg->msg.msg_controllen =0 ; kmsg->msg.msg_control =NULL ; sr->done_io += ret; - req->flags |=REQ_F_BL_NO_RECYCLE ; -return -EAGAIN ; +return io_net_kbuf_recyle (req, kmsg, ret); }if (ret == -ERESTARTSYS ) ret = -EINTR ;
@@ -674,8 +682,7 @@ int io_send(struct io_kiocb *req, unsigned int issue_flags) sr->len -= ret; sr->buf += ret; sr->done_io += ret; - req->flags |=REQ_F_BL_NO_RECYCLE ; -return -EAGAIN ; +return io_net_kbuf_recyle (req, kmsg, ret); }if (ret == -ERESTARTSYS ) ret = -EINTR ;
@@ -1071,8 +1078,7 @@ int io_recvmsg(struct io_kiocb *req, unsigned int issue_flags) }if (ret >0 &&io_net_retry (sock, flags)) { sr->done_io += ret; - req->flags |=REQ_F_BL_NO_RECYCLE ; -return IOU_RETRY ; +return io_net_kbuf_recyle (req, kmsg, ret); }if (ret == -ERESTARTSYS ) ret = -EINTR ;
@@ -1218,8 +1224,7 @@ int io_recv(struct io_kiocb *req, unsigned int issue_flags) sr->len -= ret; sr->buf += ret; sr->done_io += ret; - req->flags |=REQ_F_BL_NO_RECYCLE ; -return -EAGAIN ; +return io_net_kbuf_recyle (req, kmsg, ret); }if (ret == -ERESTARTSYS ) ret = -EINTR ;
@@ -1500,8 +1505,7 @@ int io_send_zc(struct io_kiocb *req, unsigned int issue_flags) zc->len -= ret; zc->buf += ret; zc->done_io += ret; - req->flags |=REQ_F_BL_NO_RECYCLE ; -return -EAGAIN ; +return io_net_kbuf_recyle (req, kmsg, ret); }if (ret == -ERESTARTSYS ) ret = -EINTR ;
@@ -1571,8 +1575,7 @@ int io_sendmsg_zc(struct io_kiocb *req, unsigned int issue_flags)if (ret >0 &&io_net_retry (sock, flags)) { sr->done_io += ret; - req->flags |=REQ_F_BL_NO_RECYCLE ; -return -EAGAIN ; +return io_net_kbuf_recyle (req, kmsg, ret); }if (ret == -ERESTARTSYS ) ret = -EINTR ;
Jens Axboe
maintainerQuoted 6 lines · On 8/15/25 9:26 AM, [email protected] wrote:
The patch below does not apply to the 6.6-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]>.
Quoted 8 lines
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.6.y
git checkoutFETCH_HEAD
git cherry-pick -x41b70df5b38bc80967d2e0ed55cc3c3896bba781
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2025081549-shorter-borrower-941d@gregkh' --subject-prefix 'PATCH 6.6.y' HEAD^..
Here's one for 6.6-stable.
Signature · 1 line
Jens Axboe
From c16cb4e2a4b1a487ca7feae5931dfb22ac495b76 Mon Sep 17 00:00:00 2001
From: Jens Axboe <[email protected]>
Date: Tue, 12 Aug 2025 08:30:11 -0600
Subject: [PATCH] io_uring/net: commit partial buffers on retry
Commit a6dfda7da5c65b282c1663326be16e57aec3d1bd upstream.
Ring provided buffers are potentially only valid within the single execution context in which they were acquired. io_uring deals with this and invalidates them on retry. But on the networking side, if MSG_WAITALL is set, or if the socket is of the streaming type and too little was processed, then it will hang on to the buffer rather than recycle or commit it. This is problematic for two reasons:
1) If someone unregisters the provided buffer ring before a later retry, then the req->buf_list will no longer be valid.
2) If multiple sockers are using the same buffer group, then multiple receives can consume the same memory. This can cause data corruption in the application, as either receive could land in the same userspace buffer.
Fix this by disallowing partial retries from pinning a provided buffer across multiple executions, if ring provided buffers are used.
--- io_uring/net.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-)
io_uring/net.c +13 -6
@@ -351,6 +351,13 @@ static int io_setup_async_addr(struct io_kiocb *req,return -EAGAIN ; } +static void io_net_kbuf_recyle (struct io_kiocb *req) +{ + req->flags |=REQ_F_PARTIAL_IO ; +if (req->flags &REQ_F_BUFFER_RING ) +io_kbuf_recycle_ring (req); +} +int io_sendmsg_prep_async (struct io_kiocb *req) {int ret;
@@ -442,7 +449,7 @@ int io_sendmsg(struct io_kiocb *req, unsigned int issue_flags) kmsg->msg.msg_controllen =0 ; kmsg->msg.msg_control =NULL ; sr->done_io += ret; - req->flags |=REQ_F_PARTIAL_IO ; +io_net_kbuf_recyle (req);return io_setup_async_msg (req, kmsg, issue_flags); }if (ret == -ERESTARTSYS )
@@ -521,7 +528,7 @@ int io_send(struct io_kiocb *req, unsigned int issue_flags) sr->len -= ret; sr->buf += ret; sr->done_io += ret; - req->flags |=REQ_F_PARTIAL_IO ; +io_net_kbuf_recyle (req);return io_setup_async_addr (req, &__address, issue_flags); }if (ret == -ERESTARTSYS )
@@ -891,7 +898,7 @@ int io_recvmsg(struct io_kiocb *req, unsigned int issue_flags) }if (ret >0 &&io_net_retry (sock, flags)) { sr->done_io += ret; - req->flags |=REQ_F_PARTIAL_IO ; +io_net_kbuf_recyle (req);return io_setup_async_msg (req, kmsg, issue_flags); }if (ret == -ERESTARTSYS )
@@ -991,7 +998,7 @@ int io_recv(struct io_kiocb *req, unsigned int issue_flags) sr->len -= ret; sr->buf += ret; sr->done_io += ret; - req->flags |=REQ_F_PARTIAL_IO ; +io_net_kbuf_recyle (req);return -EAGAIN ; }if (ret == -ERESTARTSYS )
@@ -1235,7 +1242,7 @@ int io_send_zc(struct io_kiocb *req, unsigned int issue_flags) zc->len -= ret; zc->buf += ret; zc->done_io += ret; - req->flags |=REQ_F_PARTIAL_IO ; +io_net_kbuf_recyle (req);return io_setup_async_addr (req, &__address, issue_flags); }if (ret == -ERESTARTSYS )
@@ -1306,7 +1313,7 @@ int io_sendmsg_zc(struct io_kiocb *req, unsigned int issue_flags)if (ret >0 &&io_net_retry (sock, flags)) { sr->done_io += ret; - req->flags |=REQ_F_PARTIAL_IO ; +io_net_kbuf_recyle (req);return io_setup_async_msg (req, kmsg, issue_flags); }if (ret == -ERESTARTSYS )
Signature · 1 line
2.50.1
Greg KH
maintainerQuoted 9 lines · Jens Axboe
Quoted 8 lines · On 8/15/25 9:26 AM, [email protected] wrote:
The patch below does not apply to the 6.6-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:
Quoted 18 lines
Quoted 6 lines
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.6.y
git checkoutFETCH_HEAD
git cherry-pick -x41b70df5b38bc80967d2e0ed55cc3c3896bba781
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2025081549-shorter-borrower-941d@gregkh' --subject-prefix 'PATCH 6.6.y' HEAD^..Here's one for 6.6-stable.
Signature · 8 lines
Jens Axboe From c16cb4e2a4b1a487ca7feae5931dfb22ac495b76 Mon Sep 17 00:00:00 2001 From: Jens Axboe <[email protected]> Date: Tue, 12 Aug 2025 08:30:11 -0600 Subject: [PATCH] io_uring/net: commit partial buffers on retry Commit a6dfda7da5c65b282c1663326be16e57aec3d1bd upstream.
Nit, wrong git id :(
I'll go fix it, thanks.
greg k-h
Jens Axboe
maintainerQuoted 27 lines · Greg KH
Quoted 26 lines · Jens Axboe
Quoted 6 lines · On 8/15/25 9:26 AM, [email protected] wrote:
The patch below does not apply to the 6.6-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]>.Quoted 8 lines
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.6.y
git checkoutFETCH_HEAD
git cherry-pick -x41b70df5b38bc80967d2e0ed55cc3c3896bba781
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2025081549-shorter-borrower-941d@gregkh' --subject-prefix 'PATCH 6.6.y' HEAD^..Here's one for 6.6-stable.
Signature · 6 lines
Jens Axboe From c16cb4e2a4b1a487ca7feae5931dfb22ac495b76 Mon Sep 17 00:00:00 2001 From: Jens Axboe <[email protected]> Date: Tue, 12 Aug 2025 08:30:11 -0600 Subject: [PATCH] io_uring/net: commit partial buffers on retry
Quoted 5 lines
Quoted 1 line
Commit
a6dfda7da5c65b282c1663326be16e57aec3d1bdupstream.Nit, wrong git id :(
I'll go fix it, thanks.
Oops sorry about that, guess I took it from the other my other backport rather than upstream.
Signature · 1 line
Jens Axboe