io_uring: fix registered files leak
Subsystems (2)
PATCH 1/1 io_uring: fix registered files leak
No upstream commit exists for this patch.
Backport of commit 705318a99a13 ("io_uring/af_unix: disable sending io_uring over sockets") introduced registered files leaks in 5.10/5.15 stable branches when CONFIG_UNIX is enabled.
The 5.10/5.15 backports removed io_sqe_file_register() calls from io_install_fixed_file() and __io_sqe_files_update() so that newly added files aren't passed to UNIX-related skbs and thus can't be put during unregistering process. Skbs in the ring socket receive queue are released but there is no skb having reference to the newly updated file.
In other words, when CONFIG_UNIX is enabled there would be no fput() when files are unregistered for the corresponding fget() from io_install_fixed_file() and __io_sqe_files_update().
Drop several code paths related to SCM_RIGHTS as a partial change from commit 6e5e6d274956 ("io_uring: drop any code related to SCM_RIGHTS"). This code is useless in stable branches now, too, but is causing leaks in 5.10/5.15.
As stated above, the affected code was removed in upstream by commit 6e5e6d274956 ("io_uring: drop any code related to SCM_RIGHTS").
Fresher stables from 6.1 have io_file_need_scm() stub function which usage is effectively equivalent to dropping most of SCM-related code.
5.4 seems not to be affected with this problem since SCM-related functions have been dropped there by the backport-patch.
Found by Linux Verification Center (linuxtesting.org) with Syzkaller.
---
I feel io_uring-SCM related code should be dropped entirely from the stable branches as the backports already differ greatly between versions and some parts are still kept, some have been dropped in a non-consistent order. Though this might contradict with stable kernel rules or be inappropriate for some other reason.
io_uring/io_uring.c | 177 -------------------------------------------- 1 file changed, 177 deletions(-)
io_uring/io_uring.c +0 -177
@@ -62,7 +62,6 @@#include <linux/net.h> #include <net/sock.h> #include <net/af_unix.h> -#include <net/scm.h> #include <linux/anon_inodes.h> #include <linux/sched/mm.h> #include <linux/uaccess.h>
@@ -7989,15 +7988,6 @@ static void io_free_file_tables(struct io_file_table *table)static void __io_sqe_files_unregister (struct io_ring_ctx *ctx) { -#if defined(CONFIG_UNIX ) -if (ctx->ring_sock) { -struct sock *sock = ctx->ring_sock->sk; -struct sk_buff *skb; - -while ((skb =skb_dequeue (&sock->sk_receive_queue)) !=NULL ) -kfree_skb (skb); - } -#else int i;for (i =0 ; i < ctx->nr_user_files; i++) {
@@ -8007,7 +7997,6 @@ static void __io_sqe_files_unregister(struct io_ring_ctx *ctx)if (file)fput (file); } -#endif io_free_file_tables (&ctx->file_table);io_rsrc_data_free (ctx->file_data); ctx->file_data =NULL ;
@@ -8159,170 +8148,10 @@ static struct io_sq_data *io_get_sq_data(struct io_uring_params *p,return sqd; } -#if defined(CONFIG_UNIX ) -/* -* 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, nr_files; - - 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 ; - - nr_files =0 ; - fpl->user =get_uid (current_user ()); -for (i =0 ; i < nr; i++) { -struct file *file =io_file_from_index (ctx, i + offset); - -if (!file) -continue ; - fpl->fp[nr_files] =get_file (file); -unix_inflight (fpl->user, fpl->fp[nr_files]); - nr_files++; - } - -if (nr_files) { - fpl->max =SCM_MAX_FD ; - fpl->count = nr_files; -UNIXCB (skb).fp = fpl; - skb->destructor = unix_destruct_scm; -refcount_add (skb->truesize, &sk->sk_wmem_alloc); -skb_queue_head (&sk->sk_receive_queue, skb); - -for (i =0 ; i < nr; i++) { -struct file *file =io_file_from_index (ctx, i + offset); - -if (file) -fput (file); - } - }else { -kfree_skb (skb); -free_uid (fpl->user); -kfree (fpl); - } - -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) { -struct file *file =io_file_from_index (ctx, total); - -if (file) -fput (file); - total++; - } - -return ret; -} -#else -static int io_sqe_files_scm (struct io_ring_ctx *ctx) -{ -return 0 ; -} -#endif -static void io_rsrc_file_put (struct io_ring_ctx *ctx,struct io_rsrc_put *prsrc) {struct file *file = prsrc->file; -#if defined(CONFIG_UNIX ) -struct sock *sock = ctx->ring_sock->sk; -struct sk_buff_head list, *head = &sock->sk_receive_queue; -struct sk_buff *skb; -int i; - -__skb_queue_head_init (&list); - -/* -* Find the skb that holds this file in its SCM_RIGHTS. When found, -* remove this entry and rearrange the file array. -*/ - skb =skb_dequeue (head); -while (skb) { -struct scm_fp_list *fp; - - fp =UNIXCB (skb).fp; -for (i =0 ; i < fp->count; i++) { -int left; - -if (fp->fp[i] != file) -continue ; - -unix_notinflight (fp->user, fp->fp[i]); - left = fp->count -1 - i; -if (left) { -memmove (&fp->fp[i], &fp->fp[i +1 ], - left *sizeof (struct file *)); - } - fp->count--; -if (!fp->count) { -kfree_skb (skb); - skb =NULL ; - }else { -__skb_queue_tail (&list, skb); - } -fput (file); - file =NULL ; -break ; - } - -if (!file) -break ; - -__skb_queue_tail (&list, skb); - - skb =skb_dequeue (head); - } - -if (skb_peek (&list)) { -spin_lock_irq (&head->lock); -while ((skb =__skb_dequeue (&list)) !=NULL ) -__skb_queue_tail (head, skb); -spin_unlock_irq (&head->lock); - } -#else fput (file); -#endif }static void __io_rsrc_put_work (struct io_rsrc_node *ref_node)
@@ -8433,12 +8262,6 @@ static int io_sqe_files_register(struct io_ring_ctx *ctx, void __user *arg,io_fixed_file_set (io_fixed_file_slot (&ctx->file_table, i), file); } - ret =io_sqe_files_scm (ctx); -if (ret) { -__io_sqe_files_unregister (ctx); -return ret; - } -io_rsrc_node_switch (ctx,NULL );return ret; out_fput:
Signature · 1 line
2.44.0
Jens Axboe
maintainerQuoted 32 lines · Fedor Pchelkin
No upstream commit exists for this patch.
Backport of commit
705318a99a13("io_uring/af_unix: disable sendingio_uringover sockets") introduced registered files leaks in 5.10/5.15 stable branches whenCONFIG_UNIXis enabled.The 5.10/5.15 backports removed
io_sqe_file_register()calls fromio_install_fixed_file()and__io_sqe_files_update()so that newly added files aren't passed to UNIX-related skbs and thus can't be put during unregistering process. Skbs in the ring socket receive queue are released but there is no skb having reference to the newly updated file.In other words, when
CONFIG_UNIXis enabled there would be nofput()when files are unregistered for the correspondingfget()fromio_install_fixed_file()and__io_sqe_files_update().Drop several code paths related to
SCM_RIGHTSas a partial change from commit6e5e6d274956("io_uring: drop any code related toSCM_RIGHTS"). This code is useless in stable branches now, too, but is causing leaks in 5.10/5.15.As stated above, the affected code was removed in upstream by commit
6e5e6d274956("io_uring: drop any code related toSCM_RIGHTS").Fresher stables from 6.1 have
io_file_need_scm()stub function which usage is effectively equivalent to dropping most of SCM-related code.5.4 seems not to be affected with this problem since SCM-related functions have been dropped there by the backport-patch.
Found by Linux Verification Center (linuxtesting.org) with Syzkaller.
Quoted 8 lines
Fixes 705318a99a13 ("io_uring/af_unix: disable sending io_uring over sockets")Signed-off-by Fedor Pchelkin <[email protected]>---
I feel io_uring-SCM related code should be dropped entirely from the stable branches as the backports already differ greatly between versions and some parts are still kept, some have been dropped in a non-consistent order. Though this might contradict with stable kernel rules or be inappropriate for some other reason.
Looks fine to me, and I agree, it makes much more sense to drop it all from 5.10/5.15-stable as well to keep them in sync with upstream. And I think this is fine for stable, dropping code is always a good thing.
Signature · 1 line
Jens Axboe
Quoted 1 line · Jens Axboe
On 3/12/24 8:23 AM, Fedor Pchelkin wrote:
[...]
Quoted 10 lines
Quoted 5 lines
I feel io_uring-SCM related code should be dropped entirely from the stable branches as the backports already differ greatly between versions and some parts are still kept, some have been dropped in a non-consistent order. Though this might contradict with stable kernel rules or be inappropriate for some other reason.
Looks fine to me, and I agree, it makes much more sense to drop it all from 5.10/5.15-stable as well to keep them in sync with upstream. And I think this is fine for stable, dropping code is always a good thing.
Alright, got it. So that would require dropping it from all of the supported 5.4, 6.1, 6.6, 6.7, too.
Would it be okay if I'll send this as a series?
--
Fedor
Jens Axboe
maintainerQuoted 16 lines · Fedor Pchelkin
Quoted 1 line · Jens Axboe
On 3/12/24 8:23 AM, Fedor Pchelkin wrote:
[...]
Quoted 10 lines
Quoted 5 lines
I feel io_uring-SCM related code should be dropped entirely from the stable branches as the backports already differ greatly between versions and some parts are still kept, some have been dropped in a non-consistent order. Though this might contradict with stable kernel rules or be inappropriate for some other reason.
Looks fine to me, and I agree, it makes much more sense to drop it all from 5.10/5.15-stable as well to keep them in sync with upstream. And I think this is fine for stable, dropping code is always a good thing.
Quoted 4 lines
Alright, got it. So that would require dropping it from all of the supported 5.4, 6.1, 6.6, 6.7, too.
Would it be okay if I'll send this as a series?
Yeah I think so, keeping the code more in sync is always a good thing when it comes to stable. Just make sure you mark the backport commits with the appropriate upstream shas. Thanks!
Signature · 1 line
Jens Axboe
Jens Axboe
maintainerQuoted 17 lines · Jens Axboe
Quoted 16 lines · Fedor Pchelkin
Quoted 1 line · Jens Axboe
On 3/12/24 8:23 AM, Fedor Pchelkin wrote:
[...]
Quoted 10 lines
Quoted 5 lines
I feel io_uring-SCM related code should be dropped entirely from the stable branches as the backports already differ greatly between versions and some parts are still kept, some have been dropped in a non-consistent order. Though this might contradict with stable kernel rules or be inappropriate for some other reason.
Looks fine to me, and I agree, it makes much more sense to drop it all from 5.10/5.15-stable as well to keep them in sync with upstream. And I think this is fine for stable, dropping code is always a good thing.
Quoted 8 lines
Quoted 4 lines
Alright, got it. So that would require dropping it from all of the supported 5.4, 6.1, 6.6, 6.7, too.
Would it be okay if I'll send this as a series?
Yeah I think so, keeping the code more in sync is always a good thing when it comes to stable. Just make sure you mark the backport commits with the appropriate upstream shas. Thanks!
I'll just do these backports myself, thanks for bringing it up.
Signature · 1 line
Jens Axboe
Quoted 21 lines · Jens Axboe
Quoted 20 lines · Jens Axboe
Quoted 19 lines · Fedor Pchelkin
Quoted 1 line · Jens Axboe
On 3/12/24 8:23 AM, Fedor Pchelkin wrote:
[...]
Quoted 10 lines
Quoted 5 lines
I feel io_uring-SCM related code should be dropped entirely from the stable branches as the backports already differ greatly between versions and some parts are still kept, some have been dropped in a non-consistent order. Though this might contradict with stable kernel rules or be inappropriate for some other reason.
Looks fine to me, and I agree, it makes much more sense to drop it all from 5.10/5.15-stable as well to keep them in sync with upstream. And I think this is fine for stable, dropping code is always a good thing.
Alright, got it. So that would require dropping it from all of the supported 5.4, 6.1, 6.6, 6.7, too.
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
Would it be okay if I'll send this as a series?
Yeah I think so, keeping the code more in sync is always a good thing when it comes to stable. Just make sure you mark the backport commits with the appropriate upstream shas. Thanks!
I'll just do these backports myself, thanks for bringing it up.
Great, thanks!
--
Fedor
Jens Axboe
maintainerHi,
OK, here they are. Two patches attached for every stable kernel, that gets rid of the remnants of the SCM related code:
5.4
5.10 and 5.15 (same patches)
6.1
6.6
6.7
Would appreciate if Fedor and Pavel could give them a once over, but I think they are all fine. It's just deleting the code...
Barring no complaints, Greg can you queue them up? Thanks!
Signature · 1 line
Jens Axboe
From 53e9e0ced4e4146ff57635c8ee65a57f3ed33fe3 Mon Sep 17 00:00:00 2001
From: Jens Axboe <[email protected]>
Date: Wed, 13 Mar 2024 18:33:48 -0600
Subject: [PATCH 1/2] io_uring/unix: drop usage of io_uring socket
Commit a4104821ad651d8a0b374f0b2474c345bbb42f82 upstream.
Since we no longer allow sending io_uring fds over SCM_RIGHTS, move to using io_is_uring_fops() to detect whether this is a io_uring fd or not. With that done, kill off io_uring_get_socket() as nobody calls it anymore.
This is in preparation to yanking out the rest of the core related to unix gc with io_uring.
--- fs/io_uring.c | 18 +++++------------- include/linux/fs.h | 6 +++--- net/core/scm.c | 2 +- net/unix/scm.c | 4 +--- 4 files changed, 10 insertions(+), 20 deletions(-)
fs/io_uring.c +5 -13
@@ -381,19 +381,6 @@ static struct kmem_cache *req_cachep;static const struct file_operations io_uring_fops; -struct sock *io_uring_get_socket (struct file *file) -{ -#if defined(CONFIG_UNIX ) -if (file->f_op == &io_uring_fops) { -struct io_ring_ctx *ctx = file->private_data; - -return ctx->ring_sock->sk; - } -#endif -return NULL ; -} -EXPORT_SYMBOL (io_uring_get_socket); -static void io_ring_ctx_ref_free (struct percpu_ref *ref) { struct io_ring_ctx *ctx = container_of(ref, struct io_ring_ctx, refs);
@@ -3794,6 +3781,11 @@ static const struct file_operations io_uring_fops = { .fasync = io_uring_fasync, }; +bool io_is_uring_fops (struct file *file) +{ +return file->f_op == &io_uring_fops; +} +static int io_allocate_scq_urings (struct io_ring_ctx *ctx,struct io_uring_params *p) {
include/linux/fs.h +3 -3
@@ -3614,11 +3614,11 @@ extern int generic_fadvise(struct file *file, loff_t offset, loff_t len, int advice);#if defined(CONFIG_IO_URING ) -extern struct sock *io_uring_get_socket (struct file *file); +bool io_is_uring_fops (struct file *file);#else -static inline struct sock *io_uring_get_socket (struct file *file) +static inline bool io_is_uring_fops (struct file *file) { -return NULL ; +return false; }#endif
net/core/scm.c +1 -1
@@ -105,7 +105,7 @@ 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)) { +if (io_is_uring_fops (file)) {fput (file);return -EINVAL ; }
net/unix/scm.c +1 -3
@@ -33,10 +33,8 @@ struct sock *unix_get_socket(struct file *filp)/* PF_UNIX ? */ if (s && sock->ops && sock->ops->family ==PF_UNIX ) u_sock = s; - }else { -/* Could be an io_uring instance */ - u_sock =io_uring_get_socket (filp); } +return u_sock; }EXPORT_SYMBOL (unix_get_socket);
Signature · 1 line
2.43.0
From a21d37be81f8dc59d4cda4aac37312f0774e4b71 Mon Sep 17 00:00:00 2001
From: Jens Axboe <[email protected]>
Date: Wed, 13 Mar 2024 18:36:18 -0600
Subject: [PATCH 2/2] io_uring: drop any code related to SCM_RIGHTS
Commit 6e5e6d274956305f1fc0340522b38f5f5be74bdb upstream.
This is dead code after we dropped support for passing io_uring fds over SCM_RIGHTS, get rid of it.
--- fs/io_uring.c | 47 +++-------------------------------------------- 1 file changed, 3 insertions(+), 44 deletions(-)
fs/io_uring.c +3 -44
98 lines not on this page · raw message
Signature · 1 line
2.43.0
From 25b0645afe6459437da6cff71546984597f209da Mon Sep 17 00:00:00 2001
From: Jens Axboe <[email protected]>
Date: Tue, 19 Dec 2023 12:30:43 -0700
Subject: [PATCH 1/2] io_uring/unix: drop usage of io_uring socket
Commit a4104821ad651d8a0b374f0b2474c345bbb42f82 upstream.
Since we no longer allow sending io_uring fds over SCM_RIGHTS, move to using io_is_uring_fops() to detect whether this is a io_uring fd or not. With that done, kill off io_uring_get_socket() as nobody calls it anymore.
This is in preparation to yanking out the rest of the core related to unix gc with io_uring.
--- include/linux/io_uring.h | 9 +++++---- io_uring/io_uring.c | 13 ------------- io_uring/io_uring.h | 1 - net/core/scm.c | 2 +- net/unix/scm.c | 4 +--- 5 files changed, 7 insertions(+), 22 deletions(-)
include/linux/io_uring.h +5 -4
@@ -93,6 +93,7 @@ int io_uring_cmd_sock(struct io_uring_cmd *cmd, unsigned int issue_flags);void io_uring_cmd_mark_cancelable (struct io_uring_cmd *cmd,unsigned int issue_flags);struct task_struct *io_uring_cmd_get_task (struct io_uring_cmd *cmd); +bool io_is_uring_fops (struct file *file);#else static inline int io_uring_cmd_import_fixed (u64 ubuf,unsigned long len,int rw,struct iov_iter *iter,void *ioucmd)
@@ -111,10 +112,6 @@ static inline void io_uring_cmd_do_in_task_lazy(struct io_uring_cmd *ioucmd, void (*task_work_cb)(struct io_uring_cmd *, unsigned)) { } -static inline struct sock *io_uring_get_socket (struct file *file) -{ -return NULL ; -}static inline void io_uring_task_cancel (void ) { }
@@ -141,6 +138,10 @@ static inline struct task_struct *io_uring_cmd_get_task(struct io_uring_cmd *cmd {return NULL ; } +static inline bool io_is_uring_fops (struct file *file) +{ +return false; +}#endif #endif
io_uring/io_uring.c +0 -13
@@ -177,19 +177,6 @@ static struct ctl_table kernel_io_uring_disabled_table[] = { };#endif -struct sock *io_uring_get_socket (struct file *file) -{ -#if defined(CONFIG_UNIX ) -if (io_is_uring_fops (file)) { -struct io_ring_ctx *ctx = file->private_data; - -return ctx->ring_sock->sk; - } -#endif -return NULL ; -} -EXPORT_SYMBOL (io_uring_get_socket); -static inline void io_submit_flush_completions (struct io_ring_ctx *ctx) { if (!wq_list_empty(&ctx->submit_state.compl_reqs) ||
io_uring/io_uring.h +0 -1
@@ -61,7 +61,6 @@ struct file *io_file_get_fixed(struct io_kiocb *req, int fd, unsigned issue_flags);void __io_req_task_work_add (struct io_kiocb *req,unsigned flags); -bool io_is_uring_fops (struct file *file);bool io_alloc_async_data (struct io_kiocb *req);void io_req_task_queue (struct io_kiocb *req);void io_queue_iowq (struct io_kiocb *req,struct io_tw_state *ts_dont_use);
net/core/scm.c +1 -1
@@ -105,7 +105,7 @@ 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)) { +if (io_is_uring_fops (file)) {fput (file);return -EINVAL ; }
net/unix/scm.c +1 -3
@@ -35,10 +35,8 @@ struct sock *unix_get_socket(struct file *filp)/* PF_UNIX ? */ if (s && ops && ops->family ==PF_UNIX ) u_sock = s; - }else { -/* Could be an io_uring instance */ - u_sock =io_uring_get_socket (filp); } +return u_sock; }EXPORT_SYMBOL (unix_get_socket);
Signature · 1 line
2.43.0
From e742473ca70a1fb2492451bf4959d0e94a0c1c7c Mon Sep 17 00:00:00 2001
From: Jens Axboe <[email protected]>
Date: Tue, 19 Dec 2023 12:36:34 -0700
Subject: [PATCH 2/2] io_uring: drop any code related to SCM_RIGHTS
Commit 6e5e6d274956305f1fc0340522b38f5f5be74bdb upstream.
This is dead code after we dropped support for passing io_uring fds over SCM_RIGHTS, get rid of it.
--- include/linux/io_uring_types.h | 3 - io_uring/filetable.c | 11 +-- io_uring/io_uring.c | 32 +------ io_uring/rsrc.c | 169 +-------------------------------- io_uring/rsrc.h | 15 --- 5 files changed, 10 insertions(+), 220 deletions(-)
include/linux/io_uring_types.h +0 -3
@@ -358,9 +358,6 @@ struct io_ring_ctx {struct wait_queue_head rsrc_quiesce_wq;unsigned rsrc_quiesce; -#if defined(CONFIG_UNIX ) -struct socket *ring_sock; -#endif /* hashed buffered write serialization */ struct io_wq_hash *hash_map;
io_uring/filetable.c +4 -7
@@ -87,13 +87,10 @@ static int io_install_fixed_file(struct io_ring_ctx *ctx, struct file *file,io_file_bitmap_clear (&ctx->file_table, slot_index); } - ret =io_scm_file_account (ctx, file); -if (!ret) { - *io_get_tag_slot (ctx->file_data, slot_index) =0 ; -io_fixed_file_set (file_slot, file); -io_file_bitmap_set (&ctx->file_table, slot_index); - } -return ret; + *io_get_tag_slot (ctx->file_data, slot_index) =0 ; +io_fixed_file_set (file_slot, file); +io_file_bitmap_set (&ctx->file_table, slot_index); +return 0 ; } int __io_fixed_fd_install(struct io_ring_ctx *ctx, struct file *file,
io_uring/io_uring.c +2 -30
@@ -60,7 +60,6 @@#include <linux/net.h> #include <net/sock.h> #include <net/af_unix.h> -#include <net/scm.h> #include <linux/anon_inodes.h> #include <linux/sched/mm.h> #include <linux/uaccess.h>
@@ -2939,13 +2938,6 @@ static __cold void io_ring_ctx_free(struct io_ring_ctx *ctx)io_rsrc_node_destroy (ctx, ctx->rsrc_node);WARN_ON_ONCE (!list_empty (&ctx->rsrc_ref_list)); - -#if defined(CONFIG_UNIX ) -if (ctx->ring_sock) { - ctx->ring_sock->file =NULL ;/* so that iput() is called */ -sock_release (ctx->ring_sock); - } -#endif WARN_ON_ONCE (!list_empty (&ctx->ltimeout_list));io_alloc_cache_free (&ctx->rsrc_node_cache, io_rsrc_node_cache_free);
@@ -3867,32 +3859,12 @@ static int io_uring_install_fd(struct file *file)/* * Allocate an anonymous fd, this is what constitutes the application * visible backing of an io_uring instance. The application mmaps this -* fd to gain access to the SQ/CQ ring details. If UNIX sockets are enabled, -* we have to tie this fd to a socket for file garbage collection purposes. +* fd to gain access to the SQ/CQ ring details. */ static struct file *io_uring_get_file (struct io_ring_ctx *ctx) { -struct file *file; -#if defined(CONFIG_UNIX ) -int ret; - - ret =sock_create_kern (&init_net,PF_UNIX ,SOCK_RAW ,IPPROTO_IP , - &ctx->ring_sock); -if (ret) -return ERR_PTR (ret); -#endif - - file =anon_inode_getfile_secure ("[io_uring]" , &io_uring_fops, ctx, +return anon_inode_getfile_secure ("[io_uring]" , &io_uring_fops, ctx,O_RDWR |O_CLOEXEC ,NULL ); -#if defined(CONFIG_UNIX ) -if (IS_ERR (file)) { -sock_release (ctx->ring_sock); - ctx->ring_sock =NULL ; - }else { - ctx->ring_sock->file = file; - } -#endif -return file; } static __cold int io_uring_create(unsigned entries, struct io_uring_params *p,
io_uring/rsrc.c +4 -165
221 lines not on this page · raw message
io_uring/rsrc.h +0 -15
@@ -75,21 +75,6 @@ int io_sqe_files_unregister(struct io_ring_ctx *ctx);int io_sqe_files_register (struct io_ring_ctx *ctx,void __user *arg,unsigned nr_args,u64 __user *tags); -int __io_scm_file_account (struct io_ring_ctx *ctx,struct file *file); - -static inline bool io_file_need_scm (struct file *filp) -{ -return false; -} - -static inline int io_scm_file_account (struct io_ring_ctx *ctx, -struct file *file) -{ -if (likely (!io_file_need_scm (file))) -return 0 ; -return __io_scm_file_account (ctx, file); -} -int io_register_files_update (struct io_ring_ctx *ctx,void __user *arg,unsigned nr_args); int io_register_rsrc_update(struct io_ring_ctx *ctx, void __user *arg,
Signature · 1 line
2.43.0
From cbe948d42e1ff43e77d60f21823d3d798f92835e Mon Sep 17 00:00:00 2001
From: Jens Axboe <[email protected]>
Date: Tue, 19 Dec 2023 12:36:34 -0700
Subject: [PATCH 2/2] io_uring: drop any code related to SCM_RIGHTS
This is dead code after we dropped support for passing io_uring fds over SCM_RIGHTS, get rid of it.
--- include/linux/io_uring_types.h | 3 - io_uring/filetable.c | 11 +-- io_uring/io_uring.c | 32 +------ io_uring/rsrc.c | 169 +-------------------------------- io_uring/rsrc.h | 15 --- 5 files changed, 10 insertions(+), 220 deletions(-)
include/linux/io_uring_types.h +0 -3
@@ -347,9 +347,6 @@ struct io_ring_ctx {struct list_head io_buffers_pages; -#if defined(CONFIG_UNIX ) -struct socket *ring_sock; -#endif /* hashed buffered write serialization */ struct io_wq_hash *hash_map;
io_uring/filetable.c +4 -7
@@ -87,13 +87,10 @@ static int io_install_fixed_file(struct io_ring_ctx *ctx, struct file *file,io_file_bitmap_clear (&ctx->file_table, slot_index); } - ret =io_scm_file_account (ctx, file); -if (!ret) { - *io_get_tag_slot (ctx->file_data, slot_index) =0 ; -io_fixed_file_set (file_slot, file); -io_file_bitmap_set (&ctx->file_table, slot_index); - } -return ret; + *io_get_tag_slot (ctx->file_data, slot_index) =0 ; +io_fixed_file_set (file_slot, file); +io_file_bitmap_set (&ctx->file_table, slot_index); +return 0 ; } int __io_fixed_fd_install(struct io_ring_ctx *ctx, struct file *file,
io_uring/io_uring.c +2 -30
@@ -60,7 +60,6 @@#include <linux/net.h> #include <net/sock.h> #include <net/af_unix.h> -#include <net/scm.h> #include <linux/anon_inodes.h> #include <linux/sched/mm.h> #include <linux/uaccess.h>
@@ -2931,13 +2930,6 @@ static __cold void io_ring_ctx_free(struct io_ring_ctx *ctx)io_rsrc_node_destroy (ctx, ctx->rsrc_node);WARN_ON_ONCE (!list_empty (&ctx->rsrc_ref_list)); - -#if defined(CONFIG_UNIX ) -if (ctx->ring_sock) { - ctx->ring_sock->file =NULL ;/* so that iput() is called */ -sock_release (ctx->ring_sock); - } -#endif WARN_ON_ONCE (!list_empty (&ctx->ltimeout_list));io_alloc_cache_free (&ctx->rsrc_node_cache, io_rsrc_node_cache_free);
@@ -3825,32 +3817,12 @@ static int io_uring_install_fd(struct file *file)/* * Allocate an anonymous fd, this is what constitutes the application * visible backing of an io_uring instance. The application mmaps this -* fd to gain access to the SQ/CQ ring details. If UNIX sockets are enabled, -* we have to tie this fd to a socket for file garbage collection purposes. +* fd to gain access to the SQ/CQ ring details. */ static struct file *io_uring_get_file (struct io_ring_ctx *ctx) { -struct file *file; -#if defined(CONFIG_UNIX ) -int ret; - - ret =sock_create_kern (&init_net,PF_UNIX ,SOCK_RAW ,IPPROTO_IP , - &ctx->ring_sock); -if (ret) -return ERR_PTR (ret); -#endif - - file =anon_inode_getfile_secure ("[io_uring]" , &io_uring_fops, ctx, +return anon_inode_getfile_secure ("[io_uring]" , &io_uring_fops, ctx,O_RDWR |O_CLOEXEC ,NULL ); -#if defined(CONFIG_UNIX ) -if (IS_ERR (file)) { -sock_release (ctx->ring_sock); - ctx->ring_sock =NULL ; - }else { - ctx->ring_sock->file = file; - } -#endif -return file; } static __cold int io_uring_create(unsigned entries, struct io_uring_params *p,
io_uring/rsrc.c +4 -165
221 lines not on this page · raw message
io_uring/rsrc.h +0 -15
@@ -75,21 +75,6 @@ int io_sqe_files_unregister(struct io_ring_ctx *ctx);int io_sqe_files_register (struct io_ring_ctx *ctx,void __user *arg,unsigned nr_args,u64 __user *tags); -int __io_scm_file_account (struct io_ring_ctx *ctx,struct file *file); - -static inline bool io_file_need_scm (struct file *filp) -{ -return false; -} - -static inline int io_scm_file_account (struct io_ring_ctx *ctx, -struct file *file) -{ -if (likely (!io_file_need_scm (file))) -return 0 ; -return __io_scm_file_account (ctx, file); -} -int io_register_files_update (struct io_ring_ctx *ctx,void __user *arg,unsigned nr_args); int io_register_rsrc_update(struct io_ring_ctx *ctx, void __user *arg,
Signature · 1 line
2.43.0
From b706187d02eacef15922de5fafedd65bc2db0576 Mon Sep 17 00:00:00 2001
From: Jens Axboe <[email protected]>
Date: Tue, 19 Dec 2023 12:30:43 -0700
Subject: [PATCH 1/2] io_uring/unix: drop usage of io_uring socket
Commit a4104821ad651d8a0b374f0b2474c345bbb42f82 upstream.
Since we no longer allow sending io_uring fds over SCM_RIGHTS, move to using io_is_uring_fops() to detect whether this is a io_uring fd or not. With that done, kill off io_uring_get_socket() as nobody calls it anymore.
This is in preparation to yanking out the rest of the core related to unix gc with io_uring.
--- include/linux/io_uring.h | 10 +++++----- io_uring/io_uring.c | 13 ------------- io_uring/io_uring.h | 1 - net/core/scm.c | 2 +- net/unix/scm.c | 4 +--- 5 files changed, 7 insertions(+), 23 deletions(-)
include/linux/io_uring.h +5 -5
@@ -46,7 +46,6 @@ int io_uring_cmd_import_fixed(u64 ubuf, unsigned long len, int rw, struct iov_iter *iter, void *ioucmd);void io_uring_cmd_done (struct io_uring_cmd *cmd,ssize_t ret,ssize_t res2,unsigned issue_flags); -struct sock *io_uring_get_socket (struct file *file);void __io_uring_cancel (bool cancel_all);void __io_uring_free (struct task_struct *tsk);void io_uring_unreg_ringfd (void );
@@ -82,6 +81,7 @@ static inline void io_uring_free(struct task_struct *tsk) __io_uring_free(tsk); }int io_uring_cmd_sock (struct io_uring_cmd *cmd,unsigned int issue_flags); +bool io_is_uring_fops (struct file *file);#else static inline int io_uring_cmd_import_fixed (u64 ubuf,unsigned long len,int rw,struct iov_iter *iter,void *ioucmd)
@@ -100,10 +100,6 @@ static inline void io_uring_cmd_do_in_task_lazy(struct io_uring_cmd *ioucmd, void (*task_work_cb)(struct io_uring_cmd *, unsigned)) { } -static inline struct sock *io_uring_get_socket (struct file *file) -{ -return NULL ; -}static inline void io_uring_task_cancel (void ) { }
@@ -122,6 +118,10 @@ static inline int io_uring_cmd_sock(struct io_uring_cmd *cmd, {return -EOPNOTSUPP ; } +static inline bool io_is_uring_fops (struct file *file) +{ +return false; +}#endif #endif
io_uring/io_uring.c +0 -13
@@ -175,19 +175,6 @@ static struct ctl_table kernel_io_uring_disabled_table[] = { };#endif -struct sock *io_uring_get_socket (struct file *file) -{ -#if defined(CONFIG_UNIX ) -if (io_is_uring_fops (file)) { -struct io_ring_ctx *ctx = file->private_data; - -return ctx->ring_sock->sk; - } -#endif -return NULL ; -} -EXPORT_SYMBOL (io_uring_get_socket); -static inline void io_submit_flush_completions (struct io_ring_ctx *ctx) { if (!wq_list_empty(&ctx->submit_state.compl_reqs) ||
io_uring/io_uring.h +0 -1
@@ -61,7 +61,6 @@ struct file *io_file_get_fixed(struct io_kiocb *req, int fd, unsigned issue_flags);void __io_req_task_work_add (struct io_kiocb *req,unsigned flags); -bool io_is_uring_fops (struct file *file);bool io_alloc_async_data (struct io_kiocb *req);void io_req_task_queue (struct io_kiocb *req);void io_queue_iowq (struct io_kiocb *req,struct io_tw_state *ts_dont_use);
net/core/scm.c +1 -1
@@ -105,7 +105,7 @@ 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)) { +if (io_is_uring_fops (file)) {fput (file);return -EINVAL ; }
net/unix/scm.c +1 -3
@@ -35,10 +35,8 @@ struct sock *unix_get_socket(struct file *filp)/* PF_UNIX ? */ if (s && ops && ops->family ==PF_UNIX ) u_sock = s; - }else { -/* Could be an io_uring instance */ - u_sock =io_uring_get_socket (filp); } +return u_sock; }EXPORT_SYMBOL (unix_get_socket);
Signature · 1 line
2.43.0
From 42d0449f65e6632ddc638929c53676fb776d8412 Mon Sep 17 00:00:00 2001
From: Jens Axboe <[email protected]>
Date: Wed, 13 Mar 2024 18:10:12 -0600
Subject: [PATCH 1/2] io_uring/unix: drop usage of io_uring socket
Commit a4104821ad651d8a0b374f0b2474c345bbb42f82 upstream.
Since we no longer allow sending io_uring fds over SCM_RIGHTS, move to using io_is_uring_fops() to detect whether this is a io_uring fd or not. With that done, kill off io_uring_get_socket() as nobody calls it anymore.
This is in preparation to yanking out the rest of the core related to unix gc with io_uring.
--- include/linux/io_uring.h | 10 +++++----- io_uring/io_uring.c | 13 ------------- io_uring/io_uring.h | 1 - net/core/scm.c | 2 +- net/unix/scm.c | 4 +--- 5 files changed, 7 insertions(+), 23 deletions(-)
include/linux/io_uring.h +5 -5
@@ -42,11 +42,11 @@ void io_uring_cmd_done(struct io_uring_cmd *cmd, ssize_t ret, ssize_t res2, unsigned issue_flags);void io_uring_cmd_complete_in_task (struct io_uring_cmd *ioucmd,void (*task_work_cb)(struct io_uring_cmd *,unsigned )); -struct sock *io_uring_get_socket (struct file *file);void __io_uring_cancel (bool cancel_all);void __io_uring_free (struct task_struct *tsk);void io_uring_unreg_ringfd (void );const char *io_uring_get_opcode (u8 opcode); +bool io_is_uring_fops (struct file *file);static inline void io_uring_files_cancel (void ) {
@@ -71,6 +71,10 @@ static inline int io_uring_cmd_import_fixed(u64 ubuf, unsigned long len, int rw, {return -EOPNOTSUPP ; } +static inline bool io_is_uring_fops (struct file *file) +{ +return false; +}static inline void io_uring_cmd_done (struct io_uring_cmd *cmd,ssize_t ret,ssize_t ret2,unsigned issue_flags) {
@@ -79,10 +83,6 @@ static inline void io_uring_cmd_complete_in_task(struct io_uring_cmd *ioucmd, void (*task_work_cb)(struct io_uring_cmd *, unsigned)) { } -static inline struct sock *io_uring_get_socket (struct file *file) -{ -return NULL ; -}static inline void io_uring_task_cancel (void ) { }
io_uring/io_uring.c +0 -13
@@ -153,19 +153,6 @@ static void __io_submit_flush_completions(struct io_ring_ctx *ctx);static struct kmem_cache *req_cachep; -struct sock *io_uring_get_socket (struct file *file) -{ -#if defined(CONFIG_UNIX ) -if (io_is_uring_fops (file)) { -struct io_ring_ctx *ctx = file->private_data; - -return ctx->ring_sock->sk; - } -#endif -return NULL ; -} -EXPORT_SYMBOL (io_uring_get_socket); -static inline void io_submit_flush_completions (struct io_ring_ctx *ctx) {if (!wq_list_empty (&ctx->submit_state.compl_reqs))
io_uring/io_uring.h +0 -1
@@ -52,7 +52,6 @@ static inline bool io_req_ffs_set(struct io_kiocb *req) }void __io_req_task_work_add (struct io_kiocb *req,bool allow_local); -bool io_is_uring_fops (struct file *file);bool io_alloc_async_data (struct io_kiocb *req);void io_req_task_queue (struct io_kiocb *req);void io_queue_iowq (struct io_kiocb *req,bool *dont_use);
net/core/scm.c +1 -1
@@ -105,7 +105,7 @@ 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)) { +if (io_is_uring_fops (file)) {fput (file);return -EINVAL ; }
net/unix/scm.c +1 -3
@@ -34,10 +34,8 @@ struct sock *unix_get_socket(struct file *filp)/* PF_UNIX ? */ if (s && sock->ops && sock->ops->family ==PF_UNIX ) u_sock = s; - }else { -/* Could be an io_uring instance */ - u_sock =io_uring_get_socket (filp); } +return u_sock; }EXPORT_SYMBOL (unix_get_socket);
Signature · 1 line
2.43.0
From 083974002b6f45bb84090a9aed025d8a3d8479cb Mon Sep 17 00:00:00 2001
From: Jens Axboe <[email protected]>
Date: Wed, 13 Mar 2024 18:15:05 -0600
Subject: [PATCH 2/2] io_uring: drop any code related to SCM_RIGHTS
Commit 6e5e6d274956305f1fc0340522b38f5f5be74bdb upstream.
This is dead code after we dropped support for passing io_uring fds over SCM_RIGHTS, get rid of it.
--- include/linux/io_uring_types.h | 3 - io_uring/filetable.c | 10 +-- io_uring/io_uring.c | 31 +------ io_uring/rsrc.c | 151 +-------------------------------- io_uring/rsrc.h | 15 ---- 5 files changed, 8 insertions(+), 202 deletions(-)
include/linux/io_uring_types.h +0 -3
@@ -330,9 +330,6 @@ struct io_ring_ctx {struct list_head io_buffers_pages; -#if defined(CONFIG_UNIX ) -struct socket *ring_sock; -#endif /* hashed buffered write serialization */ struct io_wq_hash *hash_map;
io_uring/filetable.c +4 -6
@@ -95,12 +95,10 @@ static int io_install_fixed_file(struct io_ring_ctx *ctx, struct file *file, needs_switch = true; } - ret =io_scm_file_account (ctx, file); -if (!ret) { - *io_get_tag_slot (ctx->file_data, slot_index) =0 ; -io_fixed_file_set (file_slot, file); -io_file_bitmap_set (&ctx->file_table, slot_index); - } + *io_get_tag_slot (ctx->file_data, slot_index) =0 ; +io_fixed_file_set (file_slot, file); +io_file_bitmap_set (&ctx->file_table, slot_index); +return 0 ; err:if (needs_switch)io_rsrc_node_switch (ctx, ctx->file_data);
io_uring/io_uring.c +2 -29
@@ -60,7 +60,6 @@#include <linux/net.h> #include <net/sock.h> #include <net/af_unix.h> -#include <net/scm.h> #include <linux/anon_inodes.h> #include <linux/sched/mm.h> #include <linux/uaccess.h>
@@ -2628,12 +2627,6 @@ static __cold void io_ring_ctx_free(struct io_ring_ctx *ctx)WARN_ON_ONCE (!list_empty (&ctx->rsrc_ref_list));WARN_ON_ONCE (!llist_empty (&ctx->rsrc_put_llist)); -#if defined(CONFIG_UNIX ) -if (ctx->ring_sock) { - ctx->ring_sock->file =NULL ;/* so that iput() is called */ -sock_release (ctx->ring_sock); - } -#endif WARN_ON_ONCE (!list_empty (&ctx->ltimeout_list));if (ctx->mm_account) {
@@ -3438,32 +3431,12 @@ static int io_uring_install_fd(struct io_ring_ctx *ctx, struct file *file)/* * Allocate an anonymous fd, this is what constitutes the application * visible backing of an io_uring instance. The application mmaps this -* fd to gain access to the SQ/CQ ring details. If UNIX sockets are enabled, -* we have to tie this fd to a socket for file garbage collection purposes. +* fd to gain access to the SQ/CQ ring details. */ static struct file *io_uring_get_file (struct io_ring_ctx *ctx) { -struct file *file; -#if defined(CONFIG_UNIX ) -int ret; - - ret =sock_create_kern (&init_net,PF_UNIX ,SOCK_RAW ,IPPROTO_IP , - &ctx->ring_sock); -if (ret) -return ERR_PTR (ret); -#endif - - file =anon_inode_getfile_secure ("[io_uring]" , &io_uring_fops, ctx, +return anon_inode_getfile_secure ("[io_uring]" , &io_uring_fops, ctx,O_RDWR |O_CLOEXEC ,NULL ); -#if defined(CONFIG_UNIX ) -if (IS_ERR (file)) { -sock_release (ctx->ring_sock); - ctx->ring_sock =NULL ; - }else { - ctx->ring_sock->file = file; - } -#endif -return file; } static __cold int io_uring_create(unsigned entries, struct io_uring_params *p,
io_uring/rsrc.c +2 -149
190 lines not on this page · raw message
io_uring/rsrc.h +0 -15
@@ -77,21 +77,6 @@ int io_sqe_files_unregister(struct io_ring_ctx *ctx);int io_sqe_files_register (struct io_ring_ctx *ctx,void __user *arg,unsigned nr_args,u64 __user *tags); -int __io_scm_file_account (struct io_ring_ctx *ctx,struct file *file); - -static inline bool io_file_need_scm (struct file *filp) -{ -return false; -} - -static inline int io_scm_file_account (struct io_ring_ctx *ctx, -struct file *file) -{ -if (likely (!io_file_need_scm (file))) -return 0 ; -return __io_scm_file_account (ctx, file); -} -int io_register_files_update (struct io_ring_ctx *ctx,void __user *arg,unsigned nr_args); int io_register_rsrc_update(struct io_ring_ctx *ctx, void __user *arg,
Signature · 1 line
2.43.0
From 63fcaffd0b3d0db784cbe3950549766936355e84 Mon Sep 17 00:00:00 2001
From: Jens Axboe <[email protected]>
Date: Wed, 13 Mar 2024 17:59:01 -0600
Subject: [PATCH 2/2] io_uring: drop any code related to SCM_RIGHTS
Commit 6e5e6d274956305f1fc0340522b38f5f5be74bdb upstream.
This is dead code after we dropped support for passing io_uring fds over SCM_RIGHTS, get rid of it.
--- io_uring/io_uring.c | 211 +------------------------------------------- 1 file changed, 3 insertions(+), 208 deletions(-)
io_uring/io_uring.c +3 -208
267 lines not on this page · raw message
Signature · 1 line
2.43.0
From 7c36fae9614f48c971c458f3bb12b97d3414abab Mon Sep 17 00:00:00 2001
From: Jens Axboe <[email protected]>
Date: Wed, 13 Mar 2024 17:54:49 -0600
Subject: [PATCH 1/2] io_uring/unix: drop usage of io_uring socket
Commit a4104821ad651d8a0b374f0b2474c345bbb42f82 upstream.
Since we no longer allow sending io_uring fds over SCM_RIGHTS, move to using io_is_uring_fops() to detect whether this is a io_uring fd or not. With that done, kill off io_uring_get_socket() as nobody calls it anymore.
This is in preparation to yanking out the rest of the core related to unix gc with io_uring.
--- include/linux/io_uring.h | 10 +++++----- io_uring/io_uring.c | 18 +++++------------- net/core/scm.c | 2 +- net/unix/scm.c | 4 +--- 4 files changed, 12 insertions(+), 22 deletions(-)
include/linux/io_uring.h +5 -5
@@ -6,9 +6,9 @@#include <linux/xarray.h> #if defined(CONFIG_IO_URING ) -struct sock *io_uring_get_socket (struct file *file);void __io_uring_cancel (bool cancel_all);void __io_uring_free (struct task_struct *tsk); +bool io_is_uring_fops (struct file *file);static inline void io_uring_files_cancel (void ) {
@@ -26,10 +26,6 @@ static inline void io_uring_free(struct task_struct *tsk) __io_uring_free(tsk); }#else -static inline struct sock *io_uring_get_socket (struct file *file) -{ -return NULL ; -}static inline void io_uring_task_cancel (void ) { }
@@ -39,6 +35,10 @@ static inline void io_uring_files_cancel(void)static inline void io_uring_free (struct task_struct *tsk) { } +static inline bool io_is_uring_fops (struct file *file) +{ +return false; +}#endif #endif
io_uring/io_uring.c +5 -13
@@ -1116,19 +1116,6 @@ static struct kmem_cache *req_cachep;static const struct file_operations io_uring_fops; -struct sock *io_uring_get_socket (struct file *file) -{ -#if defined(CONFIG_UNIX ) -if (file->f_op == &io_uring_fops) { -struct io_ring_ctx *ctx = file->private_data; - -return ctx->ring_sock->sk; - } -#endif -return NULL ; -} -EXPORT_SYMBOL (io_uring_get_socket); -static inline void io_tw_lock (struct io_ring_ctx *ctx,bool *locked) {if (!*locked) {
@@ -10445,6 +10432,11 @@ static const struct file_operations io_uring_fops = {#endif }; +bool io_is_uring_fops (struct file *file) +{ +return file->f_op == &io_uring_fops; +} +static int io_allocate_scq_urings (struct io_ring_ctx *ctx,struct io_uring_params *p) {
net/core/scm.c +1 -1
@@ -105,7 +105,7 @@ 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)) { +if (io_is_uring_fops (file)) {fput (file);return -EINVAL ; }
net/unix/scm.c +1 -3
@@ -34,10 +34,8 @@ struct sock *unix_get_socket(struct file *filp)/* PF_UNIX ? */ if (s && sock->ops && sock->ops->family ==PF_UNIX ) u_sock = s; - }else { -/* Could be an io_uring instance */ - u_sock =io_uring_get_socket (filp); } +return u_sock; }EXPORT_SYMBOL (unix_get_socket);
Signature · 1 line
2.43.0
Quoted 5 lines · Jens Axboe
Hi,
OK, here they are. Two patches attached for every stable kernel, that gets rid of the remnants of the SCM related code:
Quoted 8 lines
5.4
5.10 and 5.15 (same patches)
6.1
6.6
6.7Would appreciate if Fedor and Pavel could give them a once over, but I think they are all fine. It's just deleting the code...
Thank you, Jens!
FWIW, I think it's all good and it eliminates the reported problem obviously. Compiled and tested the repro with my kernel config.
Just a minor notice - stable rules declare two common ways for upstream patch mentioning in backports [1]. And the first one starts from lowercase. No big deal here definitely but maybe somebody has some handling of these two variants - by regexps or similar, I actually don't know. But I see in the git history that Greg also applies the variant you've used.
[1]: https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html#option-3
--
Fedor
Jens Axboe
maintainerQuoted 12 lines · Fedor Pchelkin
Quoted 11 lines · Jens Axboe
Hi,
OK, here they are. Two patches attached for every stable kernel, that gets rid of the remnants of the SCM related code:
5.4
5.10 and 5.15 (same patches)
6.1
6.6
6.7
Quoted 7 lines
Quoted 2 lines
Would appreciate if Fedor and Pavel could give them a once over, but I think they are all fine. It's just deleting the code...
Thank you, Jens!
FWIW, I think it's all good and it eliminates the reported problem obviously. Compiled and tested the repro with my kernel config.
Great, thanks for checking!
Quoted 6 lines
Just a minor notice - stable rules declare two common ways for upstream patch mentioning in backports [1]. And the first one starts from lowercase. No big deal here definitely but maybe somebody has some handling of these two variants - by regexps or similar, I actually don't know. But I see in the git history that Greg also applies the variant you've used.
Honestly that doesn't matter, as long as the upstream commit is referenced. I always do it this way, not my first stable rodeo.
Signature · 1 line
Jens Axboe
Jens Axboe
maintainerPATCH 1/1 io_uring: fix registered files leak
In reply to Jens AxboeHi Greg/stable,
Can you queue these up? Two patches for each stable kernel, all named appropriately.
Thanks!
-------- Forwarded Message --------
Subject: Re: [PATCH 5.10/5.15] io_uring: fix registered files leak
Date: Wed, 13 Mar 2024 18:40:29 -0600
From: Jens Axboe <[email protected]>
To: Fedor Pchelkin <[email protected]>
CC: Pavel Begunkov <[email protected]>, Greg Kroah-Hartman <[email protected]>, [email protected], [email protected], [email protected], Alexey Khoroshilov <[email protected]>, [email protected], Nikita Zhandarovich <[email protected]>, Roman Belyaev <[email protected]>
Hi,
OK, here they are. Two patches attached for every stable kernel, that gets rid of the remnants of the SCM related code:
5.4
5.10 and 5.15 (same patches)
6.1
6.6
6.7
Would appreciate if Fedor and Pavel could give them a once over, but I think they are all fine. It's just deleting the code...
Barring no complaints, Greg can you queue them up? Thanks!
Signature · 5 lines
Jens Axboe -- Jens Axboe
From 53e9e0ced4e4146ff57635c8ee65a57f3ed33fe3 Mon Sep 17 00:00:00 2001
From: Jens Axboe <[email protected]>
Date: Wed, 13 Mar 2024 18:33:48 -0600
Subject: [PATCH 1/2] io_uring/unix: drop usage of io_uring socket
Commit a4104821ad651d8a0b374f0b2474c345bbb42f82 upstream.
Since we no longer allow sending io_uring fds over SCM_RIGHTS, move to using io_is_uring_fops() to detect whether this is a io_uring fd or not. With that done, kill off io_uring_get_socket() as nobody calls it anymore.
This is in preparation to yanking out the rest of the core related to unix gc with io_uring.
--- fs/io_uring.c | 18 +++++------------- include/linux/fs.h | 6 +++--- net/core/scm.c | 2 +- net/unix/scm.c | 4 +--- 4 files changed, 10 insertions(+), 20 deletions(-)
fs/io_uring.c +5 -13
@@ -381,19 +381,6 @@ static struct kmem_cache *req_cachep;static const struct file_operations io_uring_fops; -struct sock *io_uring_get_socket (struct file *file) -{ -#if defined(CONFIG_UNIX ) -if (file->f_op == &io_uring_fops) { -struct io_ring_ctx *ctx = file->private_data; - -return ctx->ring_sock->sk; - } -#endif -return NULL ; -} -EXPORT_SYMBOL (io_uring_get_socket); -static void io_ring_ctx_ref_free (struct percpu_ref *ref) { struct io_ring_ctx *ctx = container_of(ref, struct io_ring_ctx, refs);
@@ -3794,6 +3781,11 @@ static const struct file_operations io_uring_fops = { .fasync = io_uring_fasync, }; +bool io_is_uring_fops (struct file *file) +{ +return file->f_op == &io_uring_fops; +} +static int io_allocate_scq_urings (struct io_ring_ctx *ctx,struct io_uring_params *p) {
include/linux/fs.h +3 -3
@@ -3614,11 +3614,11 @@ extern int generic_fadvise(struct file *file, loff_t offset, loff_t len, int advice);#if defined(CONFIG_IO_URING ) -extern struct sock *io_uring_get_socket (struct file *file); +bool io_is_uring_fops (struct file *file);#else -static inline struct sock *io_uring_get_socket (struct file *file) +static inline bool io_is_uring_fops (struct file *file) { -return NULL ; +return false; }#endif
net/core/scm.c +1 -1
@@ -105,7 +105,7 @@ 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)) { +if (io_is_uring_fops (file)) {fput (file);return -EINVAL ; }
net/unix/scm.c +1 -3
@@ -33,10 +33,8 @@ struct sock *unix_get_socket(struct file *filp)/* PF_UNIX ? */ if (s && sock->ops && sock->ops->family ==PF_UNIX ) u_sock = s; - }else { -/* Could be an io_uring instance */ - u_sock =io_uring_get_socket (filp); } +return u_sock; }EXPORT_SYMBOL (unix_get_socket);
Signature · 1 line
2.43.0
From a21d37be81f8dc59d4cda4aac37312f0774e4b71 Mon Sep 17 00:00:00 2001
From: Jens Axboe <[email protected]>
Date: Wed, 13 Mar 2024 18:36:18 -0600
Subject: [PATCH 2/2] io_uring: drop any code related to SCM_RIGHTS
Commit 6e5e6d274956305f1fc0340522b38f5f5be74bdb upstream.
This is dead code after we dropped support for passing io_uring fds over SCM_RIGHTS, get rid of it.
--- fs/io_uring.c | 47 +++-------------------------------------------- 1 file changed, 3 insertions(+), 44 deletions(-)
fs/io_uring.c +3 -44
98 lines not on this page · raw message
Signature · 1 line
2.43.0
From 25b0645afe6459437da6cff71546984597f209da Mon Sep 17 00:00:00 2001
From: Jens Axboe <[email protected]>
Date: Tue, 19 Dec 2023 12:30:43 -0700
Subject: [PATCH 1/2] io_uring/unix: drop usage of io_uring socket
Commit a4104821ad651d8a0b374f0b2474c345bbb42f82 upstream.
Since we no longer allow sending io_uring fds over SCM_RIGHTS, move to using io_is_uring_fops() to detect whether this is a io_uring fd or not. With that done, kill off io_uring_get_socket() as nobody calls it anymore.
This is in preparation to yanking out the rest of the core related to unix gc with io_uring.
--- include/linux/io_uring.h | 9 +++++---- io_uring/io_uring.c | 13 ------------- io_uring/io_uring.h | 1 - net/core/scm.c | 2 +- net/unix/scm.c | 4 +--- 5 files changed, 7 insertions(+), 22 deletions(-)
include/linux/io_uring.h +5 -4
@@ -93,6 +93,7 @@ int io_uring_cmd_sock(struct io_uring_cmd *cmd, unsigned int issue_flags);void io_uring_cmd_mark_cancelable (struct io_uring_cmd *cmd,unsigned int issue_flags);struct task_struct *io_uring_cmd_get_task (struct io_uring_cmd *cmd); +bool io_is_uring_fops (struct file *file);#else static inline int io_uring_cmd_import_fixed (u64 ubuf,unsigned long len,int rw,struct iov_iter *iter,void *ioucmd)
@@ -111,10 +112,6 @@ static inline void io_uring_cmd_do_in_task_lazy(struct io_uring_cmd *ioucmd, void (*task_work_cb)(struct io_uring_cmd *, unsigned)) { } -static inline struct sock *io_uring_get_socket (struct file *file) -{ -return NULL ; -}static inline void io_uring_task_cancel (void ) { }
@@ -141,6 +138,10 @@ static inline struct task_struct *io_uring_cmd_get_task(struct io_uring_cmd *cmd {return NULL ; } +static inline bool io_is_uring_fops (struct file *file) +{ +return false; +}#endif #endif
io_uring/io_uring.c +0 -13
@@ -177,19 +177,6 @@ static struct ctl_table kernel_io_uring_disabled_table[] = { };#endif -struct sock *io_uring_get_socket (struct file *file) -{ -#if defined(CONFIG_UNIX ) -if (io_is_uring_fops (file)) { -struct io_ring_ctx *ctx = file->private_data; - -return ctx->ring_sock->sk; - } -#endif -return NULL ; -} -EXPORT_SYMBOL (io_uring_get_socket); -static inline void io_submit_flush_completions (struct io_ring_ctx *ctx) { if (!wq_list_empty(&ctx->submit_state.compl_reqs) ||
io_uring/io_uring.h +0 -1
@@ -61,7 +61,6 @@ struct file *io_file_get_fixed(struct io_kiocb *req, int fd, unsigned issue_flags);void __io_req_task_work_add (struct io_kiocb *req,unsigned flags); -bool io_is_uring_fops (struct file *file);bool io_alloc_async_data (struct io_kiocb *req);void io_req_task_queue (struct io_kiocb *req);void io_queue_iowq (struct io_kiocb *req,struct io_tw_state *ts_dont_use);
net/core/scm.c +1 -1
@@ -105,7 +105,7 @@ 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)) { +if (io_is_uring_fops (file)) {fput (file);return -EINVAL ; }
net/unix/scm.c +1 -3
@@ -35,10 +35,8 @@ struct sock *unix_get_socket(struct file *filp)/* PF_UNIX ? */ if (s && ops && ops->family ==PF_UNIX ) u_sock = s; - }else { -/* Could be an io_uring instance */ - u_sock =io_uring_get_socket (filp); } +return u_sock; }EXPORT_SYMBOL (unix_get_socket);
Signature · 1 line
2.43.0
From e742473ca70a1fb2492451bf4959d0e94a0c1c7c Mon Sep 17 00:00:00 2001
From: Jens Axboe <[email protected]>
Date: Tue, 19 Dec 2023 12:36:34 -0700
Subject: [PATCH 2/2] io_uring: drop any code related to SCM_RIGHTS
Commit 6e5e6d274956305f1fc0340522b38f5f5be74bdb upstream.
This is dead code after we dropped support for passing io_uring fds over SCM_RIGHTS, get rid of it.
--- include/linux/io_uring_types.h | 3 - io_uring/filetable.c | 11 +-- io_uring/io_uring.c | 32 +------ io_uring/rsrc.c | 169 +-------------------------------- io_uring/rsrc.h | 15 --- 5 files changed, 10 insertions(+), 220 deletions(-)
include/linux/io_uring_types.h +0 -3
@@ -358,9 +358,6 @@ struct io_ring_ctx {struct wait_queue_head rsrc_quiesce_wq;unsigned rsrc_quiesce; -#if defined(CONFIG_UNIX ) -struct socket *ring_sock; -#endif /* hashed buffered write serialization */ struct io_wq_hash *hash_map;
io_uring/filetable.c +4 -7
@@ -87,13 +87,10 @@ static int io_install_fixed_file(struct io_ring_ctx *ctx, struct file *file,io_file_bitmap_clear (&ctx->file_table, slot_index); } - ret =io_scm_file_account (ctx, file); -if (!ret) { - *io_get_tag_slot (ctx->file_data, slot_index) =0 ; -io_fixed_file_set (file_slot, file); -io_file_bitmap_set (&ctx->file_table, slot_index); - } -return ret; + *io_get_tag_slot (ctx->file_data, slot_index) =0 ; +io_fixed_file_set (file_slot, file); +io_file_bitmap_set (&ctx->file_table, slot_index); +return 0 ; } int __io_fixed_fd_install(struct io_ring_ctx *ctx, struct file *file,
io_uring/io_uring.c +2 -30
@@ -60,7 +60,6 @@#include <linux/net.h> #include <net/sock.h> #include <net/af_unix.h> -#include <net/scm.h> #include <linux/anon_inodes.h> #include <linux/sched/mm.h> #include <linux/uaccess.h>
@@ -2939,13 +2938,6 @@ static __cold void io_ring_ctx_free(struct io_ring_ctx *ctx)io_rsrc_node_destroy (ctx, ctx->rsrc_node);WARN_ON_ONCE (!list_empty (&ctx->rsrc_ref_list)); - -#if defined(CONFIG_UNIX ) -if (ctx->ring_sock) { - ctx->ring_sock->file =NULL ;/* so that iput() is called */ -sock_release (ctx->ring_sock); - } -#endif WARN_ON_ONCE (!list_empty (&ctx->ltimeout_list));io_alloc_cache_free (&ctx->rsrc_node_cache, io_rsrc_node_cache_free);
@@ -3867,32 +3859,12 @@ static int io_uring_install_fd(struct file *file)/* * Allocate an anonymous fd, this is what constitutes the application * visible backing of an io_uring instance. The application mmaps this -* fd to gain access to the SQ/CQ ring details. If UNIX sockets are enabled, -* we have to tie this fd to a socket for file garbage collection purposes. +* fd to gain access to the SQ/CQ ring details. */ static struct file *io_uring_get_file (struct io_ring_ctx *ctx) { -struct file *file; -#if defined(CONFIG_UNIX ) -int ret; - - ret =sock_create_kern (&init_net,PF_UNIX ,SOCK_RAW ,IPPROTO_IP , - &ctx->ring_sock); -if (ret) -return ERR_PTR (ret); -#endif - - file =anon_inode_getfile_secure ("[io_uring]" , &io_uring_fops, ctx, +return anon_inode_getfile_secure ("[io_uring]" , &io_uring_fops, ctx,O_RDWR |O_CLOEXEC ,NULL ); -#if defined(CONFIG_UNIX ) -if (IS_ERR (file)) { -sock_release (ctx->ring_sock); - ctx->ring_sock =NULL ; - }else { - ctx->ring_sock->file = file; - } -#endif -return file; } static __cold int io_uring_create(unsigned entries, struct io_uring_params *p,
io_uring/rsrc.c +4 -165
221 lines not on this page · raw message
io_uring/rsrc.h +0 -15
@@ -75,21 +75,6 @@ int io_sqe_files_unregister(struct io_ring_ctx *ctx);int io_sqe_files_register (struct io_ring_ctx *ctx,void __user *arg,unsigned nr_args,u64 __user *tags); -int __io_scm_file_account (struct io_ring_ctx *ctx,struct file *file); - -static inline bool io_file_need_scm (struct file *filp) -{ -return false; -} - -static inline int io_scm_file_account (struct io_ring_ctx *ctx, -struct file *file) -{ -if (likely (!io_file_need_scm (file))) -return 0 ; -return __io_scm_file_account (ctx, file); -} -int io_register_files_update (struct io_ring_ctx *ctx,void __user *arg,unsigned nr_args); int io_register_rsrc_update(struct io_ring_ctx *ctx, void __user *arg,
Signature · 1 line
2.43.0
From cbe948d42e1ff43e77d60f21823d3d798f92835e Mon Sep 17 00:00:00 2001
From: Jens Axboe <[email protected]>
Date: Tue, 19 Dec 2023 12:36:34 -0700
Subject: [PATCH 2/2] io_uring: drop any code related to SCM_RIGHTS
This is dead code after we dropped support for passing io_uring fds over SCM_RIGHTS, get rid of it.
--- include/linux/io_uring_types.h | 3 - io_uring/filetable.c | 11 +-- io_uring/io_uring.c | 32 +------ io_uring/rsrc.c | 169 +-------------------------------- io_uring/rsrc.h | 15 --- 5 files changed, 10 insertions(+), 220 deletions(-)
include/linux/io_uring_types.h +0 -3
@@ -347,9 +347,6 @@ struct io_ring_ctx {struct list_head io_buffers_pages; -#if defined(CONFIG_UNIX ) -struct socket *ring_sock; -#endif /* hashed buffered write serialization */ struct io_wq_hash *hash_map;
io_uring/filetable.c +4 -7
@@ -87,13 +87,10 @@ static int io_install_fixed_file(struct io_ring_ctx *ctx, struct file *file,io_file_bitmap_clear (&ctx->file_table, slot_index); } - ret =io_scm_file_account (ctx, file); -if (!ret) { - *io_get_tag_slot (ctx->file_data, slot_index) =0 ; -io_fixed_file_set (file_slot, file); -io_file_bitmap_set (&ctx->file_table, slot_index); - } -return ret; + *io_get_tag_slot (ctx->file_data, slot_index) =0 ; +io_fixed_file_set (file_slot, file); +io_file_bitmap_set (&ctx->file_table, slot_index); +return 0 ; } int __io_fixed_fd_install(struct io_ring_ctx *ctx, struct file *file,
io_uring/io_uring.c +2 -30
@@ -60,7 +60,6 @@#include <linux/net.h> #include <net/sock.h> #include <net/af_unix.h> -#include <net/scm.h> #include <linux/anon_inodes.h> #include <linux/sched/mm.h> #include <linux/uaccess.h>
@@ -2931,13 +2930,6 @@ static __cold void io_ring_ctx_free(struct io_ring_ctx *ctx)io_rsrc_node_destroy (ctx, ctx->rsrc_node);WARN_ON_ONCE (!list_empty (&ctx->rsrc_ref_list)); - -#if defined(CONFIG_UNIX ) -if (ctx->ring_sock) { - ctx->ring_sock->file =NULL ;/* so that iput() is called */ -sock_release (ctx->ring_sock); - } -#endif WARN_ON_ONCE (!list_empty (&ctx->ltimeout_list));io_alloc_cache_free (&ctx->rsrc_node_cache, io_rsrc_node_cache_free);
@@ -3825,32 +3817,12 @@ static int io_uring_install_fd(struct file *file)/* * Allocate an anonymous fd, this is what constitutes the application * visible backing of an io_uring instance. The application mmaps this -* fd to gain access to the SQ/CQ ring details. If UNIX sockets are enabled, -* we have to tie this fd to a socket for file garbage collection purposes. +* fd to gain access to the SQ/CQ ring details. */ static struct file *io_uring_get_file (struct io_ring_ctx *ctx) { -struct file *file; -#if defined(CONFIG_UNIX ) -int ret; - - ret =sock_create_kern (&init_net,PF_UNIX ,SOCK_RAW ,IPPROTO_IP , - &ctx->ring_sock); -if (ret) -return ERR_PTR (ret); -#endif - - file =anon_inode_getfile_secure ("[io_uring]" , &io_uring_fops, ctx, +return anon_inode_getfile_secure ("[io_uring]" , &io_uring_fops, ctx,O_RDWR |O_CLOEXEC ,NULL ); -#if defined(CONFIG_UNIX ) -if (IS_ERR (file)) { -sock_release (ctx->ring_sock); - ctx->ring_sock =NULL ; - }else { - ctx->ring_sock->file = file; - } -#endif -return file; } static __cold int io_uring_create(unsigned entries, struct io_uring_params *p,
io_uring/rsrc.c +4 -165
221 lines not on this page · raw message
io_uring/rsrc.h +0 -15
@@ -75,21 +75,6 @@ int io_sqe_files_unregister(struct io_ring_ctx *ctx);int io_sqe_files_register (struct io_ring_ctx *ctx,void __user *arg,unsigned nr_args,u64 __user *tags); -int __io_scm_file_account (struct io_ring_ctx *ctx,struct file *file); - -static inline bool io_file_need_scm (struct file *filp) -{ -return false; -} - -static inline int io_scm_file_account (struct io_ring_ctx *ctx, -struct file *file) -{ -if (likely (!io_file_need_scm (file))) -return 0 ; -return __io_scm_file_account (ctx, file); -} -int io_register_files_update (struct io_ring_ctx *ctx,void __user *arg,unsigned nr_args); int io_register_rsrc_update(struct io_ring_ctx *ctx, void __user *arg,
Signature · 1 line
2.43.0
From b706187d02eacef15922de5fafedd65bc2db0576 Mon Sep 17 00:00:00 2001
From: Jens Axboe <[email protected]>
Date: Tue, 19 Dec 2023 12:30:43 -0700
Subject: [PATCH 1/2] io_uring/unix: drop usage of io_uring socket
Commit a4104821ad651d8a0b374f0b2474c345bbb42f82 upstream.
Since we no longer allow sending io_uring fds over SCM_RIGHTS, move to using io_is_uring_fops() to detect whether this is a io_uring fd or not. With that done, kill off io_uring_get_socket() as nobody calls it anymore.
This is in preparation to yanking out the rest of the core related to unix gc with io_uring.
--- include/linux/io_uring.h | 10 +++++----- io_uring/io_uring.c | 13 ------------- io_uring/io_uring.h | 1 - net/core/scm.c | 2 +- net/unix/scm.c | 4 +--- 5 files changed, 7 insertions(+), 23 deletions(-)
include/linux/io_uring.h +5 -5
@@ -46,7 +46,6 @@ int io_uring_cmd_import_fixed(u64 ubuf, unsigned long len, int rw, struct iov_iter *iter, void *ioucmd);void io_uring_cmd_done (struct io_uring_cmd *cmd,ssize_t ret,ssize_t res2,unsigned issue_flags); -struct sock *io_uring_get_socket (struct file *file);void __io_uring_cancel (bool cancel_all);void __io_uring_free (struct task_struct *tsk);void io_uring_unreg_ringfd (void );
@@ -82,6 +81,7 @@ static inline void io_uring_free(struct task_struct *tsk) __io_uring_free(tsk); }int io_uring_cmd_sock (struct io_uring_cmd *cmd,unsigned int issue_flags); +bool io_is_uring_fops (struct file *file);#else static inline int io_uring_cmd_import_fixed (u64 ubuf,unsigned long len,int rw,struct iov_iter *iter,void *ioucmd)
@@ -100,10 +100,6 @@ static inline void io_uring_cmd_do_in_task_lazy(struct io_uring_cmd *ioucmd, void (*task_work_cb)(struct io_uring_cmd *, unsigned)) { } -static inline struct sock *io_uring_get_socket (struct file *file) -{ -return NULL ; -}static inline void io_uring_task_cancel (void ) { }
@@ -122,6 +118,10 @@ static inline int io_uring_cmd_sock(struct io_uring_cmd *cmd, {return -EOPNOTSUPP ; } +static inline bool io_is_uring_fops (struct file *file) +{ +return false; +}#endif #endif
io_uring/io_uring.c +0 -13
@@ -175,19 +175,6 @@ static struct ctl_table kernel_io_uring_disabled_table[] = { };#endif -struct sock *io_uring_get_socket (struct file *file) -{ -#if defined(CONFIG_UNIX ) -if (io_is_uring_fops (file)) { -struct io_ring_ctx *ctx = file->private_data; - -return ctx->ring_sock->sk; - } -#endif -return NULL ; -} -EXPORT_SYMBOL (io_uring_get_socket); -static inline void io_submit_flush_completions (struct io_ring_ctx *ctx) { if (!wq_list_empty(&ctx->submit_state.compl_reqs) ||
io_uring/io_uring.h +0 -1
@@ -61,7 +61,6 @@ struct file *io_file_get_fixed(struct io_kiocb *req, int fd, unsigned issue_flags);void __io_req_task_work_add (struct io_kiocb *req,unsigned flags); -bool io_is_uring_fops (struct file *file);bool io_alloc_async_data (struct io_kiocb *req);void io_req_task_queue (struct io_kiocb *req);void io_queue_iowq (struct io_kiocb *req,struct io_tw_state *ts_dont_use);
net/core/scm.c +1 -1
@@ -105,7 +105,7 @@ 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)) { +if (io_is_uring_fops (file)) {fput (file);return -EINVAL ; }
net/unix/scm.c +1 -3
@@ -35,10 +35,8 @@ struct sock *unix_get_socket(struct file *filp)/* PF_UNIX ? */ if (s && ops && ops->family ==PF_UNIX ) u_sock = s; - }else { -/* Could be an io_uring instance */ - u_sock =io_uring_get_socket (filp); } +return u_sock; }EXPORT_SYMBOL (unix_get_socket);
Signature · 1 line
2.43.0
From 42d0449f65e6632ddc638929c53676fb776d8412 Mon Sep 17 00:00:00 2001
From: Jens Axboe <[email protected]>
Date: Wed, 13 Mar 2024 18:10:12 -0600
Subject: [PATCH 1/2] io_uring/unix: drop usage of io_uring socket
Commit a4104821ad651d8a0b374f0b2474c345bbb42f82 upstream.
Since we no longer allow sending io_uring fds over SCM_RIGHTS, move to using io_is_uring_fops() to detect whether this is a io_uring fd or not. With that done, kill off io_uring_get_socket() as nobody calls it anymore.
This is in preparation to yanking out the rest of the core related to unix gc with io_uring.
--- include/linux/io_uring.h | 10 +++++----- io_uring/io_uring.c | 13 ------------- io_uring/io_uring.h | 1 - net/core/scm.c | 2 +- net/unix/scm.c | 4 +--- 5 files changed, 7 insertions(+), 23 deletions(-)
include/linux/io_uring.h +5 -5
@@ -42,11 +42,11 @@ void io_uring_cmd_done(struct io_uring_cmd *cmd, ssize_t ret, ssize_t res2, unsigned issue_flags);void io_uring_cmd_complete_in_task (struct io_uring_cmd *ioucmd,void (*task_work_cb)(struct io_uring_cmd *,unsigned )); -struct sock *io_uring_get_socket (struct file *file);void __io_uring_cancel (bool cancel_all);void __io_uring_free (struct task_struct *tsk);void io_uring_unreg_ringfd (void );const char *io_uring_get_opcode (u8 opcode); +bool io_is_uring_fops (struct file *file);static inline void io_uring_files_cancel (void ) {
@@ -71,6 +71,10 @@ static inline int io_uring_cmd_import_fixed(u64 ubuf, unsigned long len, int rw, {return -EOPNOTSUPP ; } +static inline bool io_is_uring_fops (struct file *file) +{ +return false; +}static inline void io_uring_cmd_done (struct io_uring_cmd *cmd,ssize_t ret,ssize_t ret2,unsigned issue_flags) {
@@ -79,10 +83,6 @@ static inline void io_uring_cmd_complete_in_task(struct io_uring_cmd *ioucmd, void (*task_work_cb)(struct io_uring_cmd *, unsigned)) { } -static inline struct sock *io_uring_get_socket (struct file *file) -{ -return NULL ; -}static inline void io_uring_task_cancel (void ) { }
io_uring/io_uring.c +0 -13
@@ -153,19 +153,6 @@ static void __io_submit_flush_completions(struct io_ring_ctx *ctx);static struct kmem_cache *req_cachep; -struct sock *io_uring_get_socket (struct file *file) -{ -#if defined(CONFIG_UNIX ) -if (io_is_uring_fops (file)) { -struct io_ring_ctx *ctx = file->private_data; - -return ctx->ring_sock->sk; - } -#endif -return NULL ; -} -EXPORT_SYMBOL (io_uring_get_socket); -static inline void io_submit_flush_completions (struct io_ring_ctx *ctx) {if (!wq_list_empty (&ctx->submit_state.compl_reqs))
io_uring/io_uring.h +0 -1
@@ -52,7 +52,6 @@ static inline bool io_req_ffs_set(struct io_kiocb *req) }void __io_req_task_work_add (struct io_kiocb *req,bool allow_local); -bool io_is_uring_fops (struct file *file);bool io_alloc_async_data (struct io_kiocb *req);void io_req_task_queue (struct io_kiocb *req);void io_queue_iowq (struct io_kiocb *req,bool *dont_use);
net/core/scm.c +1 -1
@@ -105,7 +105,7 @@ 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)) { +if (io_is_uring_fops (file)) {fput (file);return -EINVAL ; }
net/unix/scm.c +1 -3
@@ -34,10 +34,8 @@ struct sock *unix_get_socket(struct file *filp)/* PF_UNIX ? */ if (s && sock->ops && sock->ops->family ==PF_UNIX ) u_sock = s; - }else { -/* Could be an io_uring instance */ - u_sock =io_uring_get_socket (filp); } +return u_sock; }EXPORT_SYMBOL (unix_get_socket);
Signature · 1 line
2.43.0
From 083974002b6f45bb84090a9aed025d8a3d8479cb Mon Sep 17 00:00:00 2001
From: Jens Axboe <[email protected]>
Date: Wed, 13 Mar 2024 18:15:05 -0600
Subject: [PATCH 2/2] io_uring: drop any code related to SCM_RIGHTS
Commit 6e5e6d274956305f1fc0340522b38f5f5be74bdb upstream.
This is dead code after we dropped support for passing io_uring fds over SCM_RIGHTS, get rid of it.
--- include/linux/io_uring_types.h | 3 - io_uring/filetable.c | 10 +-- io_uring/io_uring.c | 31 +------ io_uring/rsrc.c | 151 +-------------------------------- io_uring/rsrc.h | 15 ---- 5 files changed, 8 insertions(+), 202 deletions(-)
include/linux/io_uring_types.h +0 -3
@@ -330,9 +330,6 @@ struct io_ring_ctx {struct list_head io_buffers_pages; -#if defined(CONFIG_UNIX ) -struct socket *ring_sock; -#endif /* hashed buffered write serialization */ struct io_wq_hash *hash_map;
io_uring/filetable.c +4 -6
@@ -95,12 +95,10 @@ static int io_install_fixed_file(struct io_ring_ctx *ctx, struct file *file, needs_switch = true; } - ret =io_scm_file_account (ctx, file); -if (!ret) { - *io_get_tag_slot (ctx->file_data, slot_index) =0 ; -io_fixed_file_set (file_slot, file); -io_file_bitmap_set (&ctx->file_table, slot_index); - } + *io_get_tag_slot (ctx->file_data, slot_index) =0 ; +io_fixed_file_set (file_slot, file); +io_file_bitmap_set (&ctx->file_table, slot_index); +return 0 ; err:if (needs_switch)io_rsrc_node_switch (ctx, ctx->file_data);
io_uring/io_uring.c +2 -29
@@ -60,7 +60,6 @@#include <linux/net.h> #include <net/sock.h> #include <net/af_unix.h> -#include <net/scm.h> #include <linux/anon_inodes.h> #include <linux/sched/mm.h> #include <linux/uaccess.h>
@@ -2628,12 +2627,6 @@ static __cold void io_ring_ctx_free(struct io_ring_ctx *ctx)WARN_ON_ONCE (!list_empty (&ctx->rsrc_ref_list));WARN_ON_ONCE (!llist_empty (&ctx->rsrc_put_llist)); -#if defined(CONFIG_UNIX ) -if (ctx->ring_sock) { - ctx->ring_sock->file =NULL ;/* so that iput() is called */ -sock_release (ctx->ring_sock); - } -#endif WARN_ON_ONCE (!list_empty (&ctx->ltimeout_list));if (ctx->mm_account) {
@@ -3438,32 +3431,12 @@ static int io_uring_install_fd(struct io_ring_ctx *ctx, struct file *file)/* * Allocate an anonymous fd, this is what constitutes the application * visible backing of an io_uring instance. The application mmaps this -* fd to gain access to the SQ/CQ ring details. If UNIX sockets are enabled, -* we have to tie this fd to a socket for file garbage collection purposes. +* fd to gain access to the SQ/CQ ring details. */ static struct file *io_uring_get_file (struct io_ring_ctx *ctx) { -struct file *file; -#if defined(CONFIG_UNIX ) -int ret; - - ret =sock_create_kern (&init_net,PF_UNIX ,SOCK_RAW ,IPPROTO_IP , - &ctx->ring_sock); -if (ret) -return ERR_PTR (ret); -#endif - - file =anon_inode_getfile_secure ("[io_uring]" , &io_uring_fops, ctx, +return anon_inode_getfile_secure ("[io_uring]" , &io_uring_fops, ctx,O_RDWR |O_CLOEXEC ,NULL ); -#if defined(CONFIG_UNIX ) -if (IS_ERR (file)) { -sock_release (ctx->ring_sock); - ctx->ring_sock =NULL ; - }else { - ctx->ring_sock->file = file; - } -#endif -return file; } static __cold int io_uring_create(unsigned entries, struct io_uring_params *p,
io_uring/rsrc.c +2 -149
190 lines not on this page · raw message
io_uring/rsrc.h +0 -15
@@ -77,21 +77,6 @@ int io_sqe_files_unregister(struct io_ring_ctx *ctx);int io_sqe_files_register (struct io_ring_ctx *ctx,void __user *arg,unsigned nr_args,u64 __user *tags); -int __io_scm_file_account (struct io_ring_ctx *ctx,struct file *file); - -static inline bool io_file_need_scm (struct file *filp) -{ -return false; -} - -static inline int io_scm_file_account (struct io_ring_ctx *ctx, -struct file *file) -{ -if (likely (!io_file_need_scm (file))) -return 0 ; -return __io_scm_file_account (ctx, file); -} -int io_register_files_update (struct io_ring_ctx *ctx,void __user *arg,unsigned nr_args); int io_register_rsrc_update(struct io_ring_ctx *ctx, void __user *arg,
Signature · 1 line
2.43.0
From 63fcaffd0b3d0db784cbe3950549766936355e84 Mon Sep 17 00:00:00 2001
From: Jens Axboe <[email protected]>
Date: Wed, 13 Mar 2024 17:59:01 -0600
Subject: [PATCH 2/2] io_uring: drop any code related to SCM_RIGHTS
Commit 6e5e6d274956305f1fc0340522b38f5f5be74bdb upstream.
This is dead code after we dropped support for passing io_uring fds over SCM_RIGHTS, get rid of it.
--- io_uring/io_uring.c | 211 +------------------------------------------- 1 file changed, 3 insertions(+), 208 deletions(-)
io_uring/io_uring.c +3 -208
267 lines not on this page · raw message
Signature · 1 line
2.43.0
From 7c36fae9614f48c971c458f3bb12b97d3414abab Mon Sep 17 00:00:00 2001
From: Jens Axboe <[email protected]>
Date: Wed, 13 Mar 2024 17:54:49 -0600
Subject: [PATCH 1/2] io_uring/unix: drop usage of io_uring socket
Commit a4104821ad651d8a0b374f0b2474c345bbb42f82 upstream.
Since we no longer allow sending io_uring fds over SCM_RIGHTS, move to using io_is_uring_fops() to detect whether this is a io_uring fd or not. With that done, kill off io_uring_get_socket() as nobody calls it anymore.
This is in preparation to yanking out the rest of the core related to unix gc with io_uring.
--- include/linux/io_uring.h | 10 +++++----- io_uring/io_uring.c | 18 +++++------------- net/core/scm.c | 2 +- net/unix/scm.c | 4 +--- 4 files changed, 12 insertions(+), 22 deletions(-)
include/linux/io_uring.h +5 -5
@@ -6,9 +6,9 @@#include <linux/xarray.h> #if defined(CONFIG_IO_URING ) -struct sock *io_uring_get_socket (struct file *file);void __io_uring_cancel (bool cancel_all);void __io_uring_free (struct task_struct *tsk); +bool io_is_uring_fops (struct file *file);static inline void io_uring_files_cancel (void ) {
@@ -26,10 +26,6 @@ static inline void io_uring_free(struct task_struct *tsk) __io_uring_free(tsk); }#else -static inline struct sock *io_uring_get_socket (struct file *file) -{ -return NULL ; -}static inline void io_uring_task_cancel (void ) { }
@@ -39,6 +35,10 @@ static inline void io_uring_files_cancel(void)static inline void io_uring_free (struct task_struct *tsk) { } +static inline bool io_is_uring_fops (struct file *file) +{ +return false; +}#endif #endif
io_uring/io_uring.c +5 -13
@@ -1116,19 +1116,6 @@ static struct kmem_cache *req_cachep;static const struct file_operations io_uring_fops; -struct sock *io_uring_get_socket (struct file *file) -{ -#if defined(CONFIG_UNIX ) -if (file->f_op == &io_uring_fops) { -struct io_ring_ctx *ctx = file->private_data; - -return ctx->ring_sock->sk; - } -#endif -return NULL ; -} -EXPORT_SYMBOL (io_uring_get_socket); -static inline void io_tw_lock (struct io_ring_ctx *ctx,bool *locked) {if (!*locked) {
@@ -10445,6 +10432,11 @@ static const struct file_operations io_uring_fops = {#endif }; +bool io_is_uring_fops (struct file *file) +{ +return file->f_op == &io_uring_fops; +} +static int io_allocate_scq_urings (struct io_ring_ctx *ctx,struct io_uring_params *p) {
net/core/scm.c +1 -1
@@ -105,7 +105,7 @@ 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)) { +if (io_is_uring_fops (file)) {fput (file);return -EINVAL ; }
net/unix/scm.c +1 -3
@@ -34,10 +34,8 @@ struct sock *unix_get_socket(struct file *filp)/* PF_UNIX ? */ if (s && sock->ops && sock->ops->family ==PF_UNIX ) u_sock = s; - }else { -/* Could be an io_uring instance */ - u_sock =io_uring_get_socket (filp); } +return u_sock; }EXPORT_SYMBOL (unix_get_socket);
Signature · 1 line
2.43.0
Sasha Levin
maintainerQuoted 4 lines · Jens Axboe
Hi Greg/stable,
Can you queue these up? Two patches for each stable kernel, all named appropriately.
I'll queue it up, thanks!
Signature · 2 lines
Thanks, Sasha
Jens Axboe
maintainerQuoted 7 lines · Sasha Levin
Quoted 4 lines · Jens Axboe
Hi Greg/stable,
Can you queue these up? Two patches for each stable kernel, all named appropriately.
I'll queue it up, thanks!
Thanks!
Signature · 1 line
Jens Axboe