Skip to contentSkip to conversation

io_uring resource handling fixes

PATCH Applied Pavel Begunkov 2 participants 4 messages Apr 6, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover io_uring resource handling fixes

Two small fixes for rsrc infrastructure

Pavel Begunkov (2):
io_uring: nospec index for tags on files update
io_uring: don't touch scm_fp_list after queueing skb

 fs/io_uring.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
Signature · 1 line
2.35.1
#1 lore raw

PATCH 1/2 io_uring: nospec index for tags on files update

Don't forget to array_index_nospec() for indexes before updating rsrc tags in __io_sqe_files_update(), just use already safe and precalculated index @i.

Fixes c3bdad0271834 ("io_uring: add generic rsrc update with tags")
---
 fs/io_uring.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/io_uring.c +1 -1
index f95b44a91b7d..449d4ea419cb 100644
@@ -9294,7 +9294,7 @@ static int __io_sqe_files_update(struct io_ring_ctx *ctx,
 				err = -EBADF;
 				break;
 			}
-			*io_get_tag_slot(data, up->offset + done) = tag;
+			*io_get_tag_slot(data, i) = tag;
 			io_fixed_file_set(file_slot, file);
 			err = io_sqe_file_register(ctx, file, i);
 			if (err) {
Signature · 1 line
2.35.1
#2 lore raw

PATCH 2/2 io_uring: don't touch scm_fp_list after queueing skb

In reply to Pavel Begunkov

It's safer to not touch scm_fp_list after we queued an skb to which it was assigned, there might be races lurking if we screw subtle sync guarantees on the io_uring side.

Fixes 6b06314c47e14 ("io_uring: add file set registration")
---
 fs/io_uring.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
fs/io_uring.c +6 -2
index 449d4ea419cb..481e12115dbb 100644
@@ -8831,8 +8831,12 @@ static int __io_sqe_files_scm(struct io_ring_ctx *ctx, int nr, int offset)
 		refcount_add(skb->truesize, &sk->sk_wmem_alloc);
 		skb_queue_head(&sk->sk_receive_queue, skb);
 
-		for (i = 0; i < nr_files; i++)
-			fput(fpl->fp[i]);
+		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);
Signature · 1 line
2.35.1
maintainer Applied
#3 lore raw
In reply to Pavel Begunkov
Quoted 8 lines · Pavel Begunkov

Two small fixes for rsrc infrastructure

Pavel Begunkov (2):
io_uring: nospec index for tags on files update
io_uring: don't touch scm_fp_list after queueing skb

 fs/io_uring.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

Thanks, applied.

Signature · 1 line
Jens Axboe