Skip to content

Commit

Permalink
io_uring/af_unix: disable sending io_uring over sockets
Browse files Browse the repository at this point in the history
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: stable@vger.kernel.org
Fixes: 0091bfc ("io_uring/af_unix: defer registered files gc to io_uring release")
Reported-and-suggested-by: Jann Horn <jannh@google.com>
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Acked-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Pavel Begunkov authored and David S. Miller committed Dec 9, 2023
1 parent 15319a4 commit 69db702
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
7 changes: 0 additions & 7 deletions io_uring/rsrc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions net/core/scm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down Expand Up @@ -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++;
}
Expand Down

0 comments on commit 69db702

Please sign in to comment.