FAILED: patch "[PATCH] io_uring/af_unix: disable sending io_uring over sockets" failed to apply to 5.4-stable tree
Subsystems (5)
[email protected]
maintainerThe patch below does not apply to the 5.4-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-5.4.y
git checkout FETCH_HEAD
git cherry-pick -x 705318a99a138c29a512a72c3e0043b3cd7f55f4
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2023120913-cornea-query-b9bf@gregkh' --subject-prefix 'PATCH 5.4.y' HEAD^..
Possible dependencies:
705318a99a13 ("io_uring/af_unix: disable sending io_uring over sockets") 38eddb2c75fb ("io_uring: remove FFS_SCM")
735729844819 ("io_uring: move rsrc related data, core, and commands") 3b77495a9723 ("io_uring: split provided buffers handling into its own file") 7aaff708a768 ("io_uring: move cancelation into its own file") 329061d3e2f9 ("io_uring: move poll handling into its own file") cfd22e6b3319 ("io_uring: add opcode name to io_op_defs") 92ac8beaea1f ("io_uring: include and forward-declaration sanitation") c9f06aa7de15 ("io_uring: move io_uring_task (tctx) helpers into its own file") a4ad4f748ea9 ("io_uring: move fdinfo helpers to its own file") e5550a1447bf ("io_uring: use io_is_uring_fops() consistently") 17437f311490 ("io_uring: move SQPOLL related handling into its own file") 59915143e89f ("io_uring: move timeout opcodes and handling into its own file") e418bbc97bff ("io_uring: move our reference counting into a header") 36404b09aa60 ("io_uring: move msg_ring into its own file") f9ead18c1058 ("io_uring: split network related opcodes into its own file") e0da14def1ee ("io_uring: move statx handling to its own file") a9c210cebe13 ("io_uring: move epoll handler to its own file") 4cf90495281b ("io_uring: add a dummy -EOPNOTSUPP prep handler") 99f15d8d6136 ("io_uring: move uring_cmd handling to its own file")
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 705318a99a138c29a512a72c3e0043b3cd7f55f4 Mon Sep 17 00:00:00 2001
From: Pavel Begunkov <[email protected]>
Date: Wed, 6 Dec 2023 13:26:47 +0000
Subject: [PATCH] io_uring/af_unix: disable sending io_uring over sockets
File reference cycles have caused lots of problems for io_uring in the past, and it still doesn't work exactly right and races with unix_stream_read_generic(). The safest fix would be to completely disallow sending io_uring files via sockets via SCM_RIGHT, so there are no possible cycles invloving registered files and thus rendering SCM accounting on the io_uring side unnecessary.
io_uring/rsrc.h +0 -7
@@ -77,17 +77,10 @@ int io_sqe_files_register(struct io_ring_ctx *ctx, void __user *arg,int __io_scm_file_account (struct io_ring_ctx *ctx,struct file *file); -#if defined(CONFIG_UNIX ) -static inline bool io_file_need_scm (struct file *filp) -{ -return !!unix_get_socket (filp); -} -#else static inline bool io_file_need_scm (struct file *filp) {return false; } -#endif static inline int io_scm_file_account (struct io_ring_ctx *ctx,struct file *file)
net/core/scm.c +6 -0
@@ -26,6 +26,7 @@#include <linux/nsproxy.h> #include <linux/slab.h> #include <linux/errqueue.h> +#include <linux/io_uring.h> #include <linux/uaccess.h>
@@ -103,6 +104,11 @@ static int scm_fp_copy(struct cmsghdr *cmsg, struct scm_fp_list **fplp)if (fd <0 || !(file =fget_raw (fd)))return -EBADF ; +/* don't allow io_uring files */ +if (io_uring_get_socket (file)) { +fput (file); +return -EINVAL ; + } *fpp++ = file; fpl->count++; }
Jens Axboe
maintainerQuoted 6 lines · On 12/9/23 5:03 AM, [email protected] wrote:
The patch below does not apply to the 5.4-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-5.4.y
git checkoutFETCH_HEAD
git cherry-pick -x705318a99a138c29a512a72c3e0043b3cd7f55f4
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2023120913-cornea-query-b9bf@gregkh' --subject-prefix 'PATCH 5.4.y' HEAD^..
Here's one for 5.4-stable.
Signature · 1 line
Jens Axboe
From 2ad25288b0f67d4a5120fe9fe6279ef6635bb986 Mon Sep 17 00:00:00 2001
From: Pavel Begunkov <[email protected]>
Date: Wed, 6 Dec 2023 13:26:47 +0000
Subject: [PATCH] io_uring/af_unix: disable sending io_uring over sockets
commit 705318a99a138c29a512a72c3e0043b3cd7f55f4 upstream.
File reference cycles have caused lots of problems for io_uring in the past, and it still doesn't work exactly right and races with unix_stream_read_generic(). The safest fix would be to completely disallow sending io_uring files via sockets via SCM_RIGHT, so there are no possible cycles invloving registered files and thus rendering SCM accounting on the io_uring side unnecessary.
--- fs/io_uring.c | 101 +------------------------------------------------ net/core/scm.c | 6 +++ 2 files changed, 7 insertions(+), 100 deletions(-)
fs/io_uring.c +1 -100
@@ -3137,101 +3137,6 @@ static void io_finish_async(struct io_ring_ctx *ctx) } } -#if defined(CONFIG_UNIX ) -static void io_destruct_skb (struct sk_buff *skb) -{ -struct io_ring_ctx *ctx = skb->sk->sk_user_data; -int i; - -for (i =0 ; i <ARRAY_SIZE (ctx->sqo_wq); i++) -if (ctx->sqo_wq[i]) -flush_workqueue (ctx->sqo_wq[i]); - -unix_destruct_scm (skb); -} - -/* -* Ensure the UNIX gc is aware of our file set, so we are certain that -* the io_uring can be safely unregistered on process exit, even if we have -* loops in the file referencing. -*/ -static int __io_sqe_files_scm (struct io_ring_ctx *ctx,int nr,int offset) -{ -struct sock *sk = ctx->ring_sock->sk; -struct scm_fp_list *fpl; -struct sk_buff *skb; -int i; - - fpl =kzalloc (sizeof (*fpl),GFP_KERNEL ); -if (!fpl) -return -ENOMEM ; - - skb =alloc_skb (0 ,GFP_KERNEL ); -if (!skb) { -kfree (fpl); -return -ENOMEM ; - } - - skb->sk = sk; - skb->scm_io_uring =1 ; - skb->destructor = io_destruct_skb; - - fpl->user =get_uid (ctx->user); -for (i =0 ; i < nr; i++) { - fpl->fp[i] =get_file (ctx->user_files[i + offset]); -unix_inflight (fpl->user, fpl->fp[i]); - } - - fpl->max = fpl->count = nr; -UNIXCB (skb).fp = fpl; -refcount_add (skb->truesize, &sk->sk_wmem_alloc); -skb_queue_head (&sk->sk_receive_queue, skb); - -for (i =0 ; i < nr; i++) -fput (fpl->fp[i]); - -return 0 ; -} - -/* -* If UNIX sockets are enabled, fd passing can cause a reference cycle which -* causes regular reference counting to break down. We rely on the UNIX -* garbage collection to take care of this problem for us. -*/ -static int io_sqe_files_scm (struct io_ring_ctx *ctx) -{ -unsigned left, total; -int ret =0 ; - - total =0 ; - left = ctx->nr_user_files; -while (left) { -unsigned this_files =min_t (unsigned, left,SCM_MAX_FD ); - - ret =__io_sqe_files_scm (ctx, this_files, total); -if (ret) -break ; - left -= this_files; - total += this_files; - } - -if (!ret) -return 0 ; - -while (total < ctx->nr_user_files) { -fput (ctx->user_files[total]); - total++; - } - -return ret; -} -#else -static int io_sqe_files_scm (struct io_ring_ctx *ctx) -{ -return 0 ; -} -#endif -static int io_sqe_files_register (struct io_ring_ctx *ctx,void __user *arg,unsigned nr_args) {
@@ -3285,11 +3190,7 @@ static int io_sqe_files_register(struct io_ring_ctx *ctx, void __user *arg,return ret; } - ret =io_sqe_files_scm (ctx); -if (ret) -io_sqe_files_unregister (ctx); - -return ret; +return 0 ; } static int io_sq_offload_start(struct io_ring_ctx *ctx,
net/core/scm.c +6 -0
@@ -26,6 +26,7 @@#include <linux/nsproxy.h> #include <linux/slab.h> #include <linux/errqueue.h> +#include <linux/io_uring.h> #include <linux/uaccess.h>
@@ -103,6 +104,11 @@ static int scm_fp_copy(struct cmsghdr *cmsg, struct scm_fp_list **fplp)if (fd <0 || !(file =fget_raw (fd)))return -EBADF ; +/* don't allow io_uring files */ +if (io_uring_get_socket (file)) { +fput (file); +return -EINVAL ; + } *fpp++ = file; fpl->count++; }
Greg KH
maintainerQuoted 9 lines · Jens Axboe
Quoted 8 lines · On 12/9/23 5:03 AM, [email protected] wrote:
The patch below does not apply to the 5.4-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 8 lines
Quoted 6 lines
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.4.y
git checkoutFETCH_HEAD
git cherry-pick -x705318a99a138c29a512a72c3e0043b3cd7f55f4
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2023120913-cornea-query-b9bf@gregkh' --subject-prefix 'PATCH 5.4.y' HEAD^..Here's one for 5.4-stable.
All now queued up, thanks.
greg k-h