Skip to content

Commit 689659c

Browse files
committed
Merge tag 'io_uring-6.7-2023-12-08' of git://git.kernel.dk/linux
Pull io_uring fixes from Jens Axboe: "Two minor fixes for issues introduced in this release cycle, and two fixes for issues or potential issues that are heading to stable. One of these ends up disabling passing io_uring file descriptors via SCM_RIGHTS. There really shouldn't be an overlap between that kind of historic use case and modern usage of io_uring, which is why this was deemed appropriate" * tag 'io_uring-6.7-2023-12-08' of git://git.kernel.dk/linux: io_uring/af_unix: disable sending io_uring over sockets io_uring/kbuf: check for buffer list readiness after NULL check io_uring/kbuf: Fix an NULL vs IS_ERR() bug in io_alloc_pbuf_ring() io_uring: fix mutex_unlock with unreferenced ctx
2 parents 8aa7486 + 705318a commit 689659c

File tree

4 files changed

+13
-17
lines changed

4 files changed

+13
-17
lines changed

io_uring/io_uring.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -271,13 +271,15 @@ static __cold void io_fallback_req_func(struct work_struct *work)
271271
struct io_kiocb *req, *tmp;
272272
struct io_tw_state ts = { .locked = true, };
273273

274+
percpu_ref_get(&ctx->refs);
274275
mutex_lock(&ctx->uring_lock);
275276
llist_for_each_entry_safe(req, tmp, node, io_task_work.node)
276277
req->io_task_work.func(req, &ts);
277278
if (WARN_ON_ONCE(!ts.locked))
278279
return;
279280
io_submit_flush_completions(ctx);
280281
mutex_unlock(&ctx->uring_lock);
282+
percpu_ref_put(&ctx->refs);
281283
}
282284

283285
static int io_alloc_hash_table(struct io_hash_table *table, unsigned bits)
@@ -3146,12 +3148,7 @@ static __cold void io_ring_exit_work(struct work_struct *work)
31463148
init_completion(&exit.completion);
31473149
init_task_work(&exit.task_work, io_tctx_exit_cb);
31483150
exit.ctx = ctx;
3149-
/*
3150-
* Some may use context even when all refs and requests have been put,
3151-
* and they are free to do so while still holding uring_lock or
3152-
* completion_lock, see io_req_task_submit(). Apart from other work,
3153-
* this lock/unlock section also waits them to finish.
3154-
*/
3151+
31553152
mutex_lock(&ctx->uring_lock);
31563153
while (!list_empty(&ctx->tctx_list)) {
31573154
WARN_ON_ONCE(time_after(jiffies, timeout));

io_uring/kbuf.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -636,8 +636,8 @@ static int io_alloc_pbuf_ring(struct io_ring_ctx *ctx,
636636
ibf = io_lookup_buf_free_entry(ctx, ring_size);
637637
if (!ibf) {
638638
ptr = io_mem_alloc(ring_size);
639-
if (!ptr)
640-
return -ENOMEM;
639+
if (IS_ERR(ptr))
640+
return PTR_ERR(ptr);
641641

642642
/* Allocate and store deferred free entry */
643643
ibf = kmalloc(sizeof(*ibf), GFP_KERNEL_ACCOUNT);
@@ -756,15 +756,15 @@ void *io_pbuf_get_address(struct io_ring_ctx *ctx, unsigned long bgid)
756756

757757
bl = __io_buffer_get_list(ctx, smp_load_acquire(&ctx->io_bl), bgid);
758758

759+
if (!bl || !bl->is_mmap)
760+
return NULL;
759761
/*
760762
* Ensure the list is fully setup. Only strictly needed for RCU lookup
761763
* via mmap, and in that case only for the array indexed groups. For
762764
* the xarray lookups, it's either visible and ready, or not at all.
763765
*/
764766
if (!smp_load_acquire(&bl->is_ready))
765767
return NULL;
766-
if (!bl || !bl->is_mmap)
767-
return NULL;
768768

769769
return bl->buf_ring;
770770
}

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)