From: Pavel Begunkov <[email protected]> To: [email protected] Cc: Jens Axboe <[email protected]>, [email protected], [email protected] Subject: [PATCH 1/1] io_uring/af_unix: disable sending io_uring over sockets Date: Wed, 6 Dec 2023 13:26:47 +0000 [thread overview] Message-ID: <c716c88321939156909cfa1bd8b0faaf1c804103.1701868795.git.asml.silence@gmail.com> (raw) 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: 0091bfc81741b ("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]> --- Note, it's a minimal patch intended for backporting, all the leftovers will be cleaned up separately. io_uring/rsrc.h | 7 ------- net/core/scm.c | 6 ++++++ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/io_uring/rsrc.h b/io_uring/rsrc.h index 8625181fb87a..08ac0d8e07ef 100644 --- a/io_uring/rsrc.h +++ b/io_uring/rsrc.h @@ -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) diff --git a/net/core/scm.c b/net/core/scm.c index 880027ecf516..7dc47c17d863 100644 --- a/net/core/scm.c +++ b/net/core/scm.c @@ -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++; } -- 2.43.0
WARNING: multiple messages have this Message-ID (diff)
From: Pavel Begunkov <[email protected]> To: [email protected] Cc: Jens Axboe <[email protected]>, [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected] Subject: [PATCH RESEND] io_uring/af_unix: disable sending io_uring over sockets Date: Wed, 6 Dec 2023 13:55:19 +0000 [thread overview] Message-ID: <c716c88321939156909cfa1bd8b0faaf1c804103.1701868795.git.asml.silence@gmail.com> (raw) Message-ID: <20231206135519.yBMlNoeFNa7HFhE2CuH-5kgU6pwEGY_P6xlXBgW6qEY@z> (raw) 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: 0091bfc81741b ("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]> --- Note, it's a minimal patch intended for backporting, all the leftovers will be cleaned up separately. io_uring/rsrc.h | 7 ------- net/core/scm.c | 6 ++++++ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/io_uring/rsrc.h b/io_uring/rsrc.h index 8625181fb87a..08ac0d8e07ef 100644 --- a/io_uring/rsrc.h +++ b/io_uring/rsrc.h @@ -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) diff --git a/net/core/scm.c b/net/core/scm.c index 880027ecf516..7dc47c17d863 100644 --- a/net/core/scm.c +++ b/net/core/scm.c @@ -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++; } -- 2.43.0
next reply other threads:[~2023-12-06 13:29 UTC|newest] Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-12-06 13:26 Pavel Begunkov [this message] 2023-12-06 13:53 ` [PATCH 1/1] io_uring/af_unix: disable sending io_uring over sockets Pavel Begunkov 2023-12-06 13:55 ` [PATCH RESEND] " Pavel Begunkov 2023-12-07 20:33 ` [PATCH 1/1] " Jens Axboe 2023-12-08 14:59 ` Jeff Moyer 2023-12-08 15:09 ` Jann Horn 2023-12-08 16:06 ` Jeff Moyer 2023-12-08 16:28 ` Jens Axboe 2023-12-08 17:08 ` Jeff Moyer 2023-12-10 1:23 ` Pavel Begunkov 2023-12-09 1:40 ` [PATCH RESEND] " Jakub Kicinski 2023-12-09 21:30 ` patchwork-bot+netdevbpf 2023-12-10 1:18 ` Pavel Begunkov 2023-12-12 2:39 ` Jakub Kicinski 2023-12-12 4:45 ` Jens Axboe
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=c716c88321939156909cfa1bd8b0faaf1c804103.1701868795.git.asml.silence@gmail.com \ [email protected] \ [email protected] \ [email protected] \ [email protected] \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox