Skip to content

Commit 705318a

Browse files
isilenceaxboe
authored andcommitted
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. Cc: <[email protected]> Fixes: 0091bfc ("io_uring/af_unix: defer registered files gc to io_uring release") Reported-and-suggested-by: Jann Horn <[email protected]> Signed-off-by: Pavel Begunkov <[email protected]> Link: https://lore.kernel.org/r/c716c88321939156909cfa1bd8b0faaf1c804103.1701868795.git.asml.silence@gmail.com Signed-off-by: Jens Axboe <[email protected]>
1 parent 9865346 commit 705318a

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

io_uring/rsrc.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,10 @@ int io_sqe_files_register(struct io_ring_ctx *ctx, void __user *arg,
7777

7878
int __io_scm_file_account(struct io_ring_ctx *ctx, struct file *file);
7979

80-
#if defined(CONFIG_UNIX)
81-
static inline bool io_file_need_scm(struct file *filp)
82-
{
83-
return !!unix_get_socket(filp);
84-
}
85-
#else
8680
static inline bool io_file_need_scm(struct file *filp)
8781
{
8882
return false;
8983
}
90-
#endif
9184

9285
static inline int io_scm_file_account(struct io_ring_ctx *ctx,
9386
struct file *file)

net/core/scm.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <linux/nsproxy.h>
2727
#include <linux/slab.h>
2828
#include <linux/errqueue.h>
29+
#include <linux/io_uring.h>
2930

3031
#include <linux/uaccess.h>
3132

@@ -103,6 +104,11 @@ static int scm_fp_copy(struct cmsghdr *cmsg, struct scm_fp_list **fplp)
103104

104105
if (fd < 0 || !(file = fget_raw(fd)))
105106
return -EBADF;
107+
/* don't allow io_uring files */
108+
if (io_uring_get_socket(file)) {
109+
fput(file);
110+
return -EINVAL;
111+
}
106112
*fpp++ = file;
107113
fpl->count++;
108114
}

0 commit comments

Comments
 (0)