Skip to contentSkip to conversation

io_uring: ensure fput() called correspondingly when direct install fails

PATCH Applied Xiaoguang Wang 2 participants 4 messages May 27, 2022 – May 28, 2022

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

PATCH 1/1 io_uring: ensure fput() called correspondingly when direct install fails

io_fixed_fd_install() may fail for short of free fixed file bitmap, in this case, need to call fput() correspondingly.

---
 fs/io_uring.c | 5 +++++
 1 file changed, 5 insertions(+)
fs/io_uring.c +5 -0
index d50bbf8de4fb..0190947fb1bf 100644
@@ -5438,6 +5438,10 @@ static int io_file_bitmap_get(struct io_ring_ctx *ctx)
 	return -ENFILE;
 }
 
+/*
+ * Note when io_fixed_fd_install() returns error value, it will ensure
+ * fput() is called correspondingly.
+ */
 static int io_fixed_fd_install(struct io_kiocb *req, unsigned int issue_flags,
 			       struct file *file, unsigned int file_slot)
 {
@@ -5450,6 +5454,7 @@ static int io_fixed_fd_install(struct io_kiocb *req, unsigned int issue_flags,
 		ret = io_file_bitmap_get(ctx);
 		if (unlikely(ret < 0)) {
 			io_ring_submit_unlock(ctx, issue_flags);
+			fput(file);
 			return ret;
 		}
 
Signature · 1 line
2.14.4.44.g2045bb6
maintainer
#1 lore raw
Quoted 2 lines · Xiaoguang Wang

io_fixed_fd_install() may fail for short of free fixed file bitmap, in this case, need to call fput() correspondingly.

Good catch - but it's a bit confusing how we handle this case internally, and the other error case relies on that function doing the fput (which it does).

Any chance we can get that cleaned up at the same time? Would make errors in this error less likely in the future.

Signature · 1 line
Jens Axboe
#2 lore raw

hi,

Quoted 9 lines · Xiaoguang Wang
Quoted 2 lines

io_fixed_fd_install() may fail for short of free fixed file bitmap, in this case, need to call fput() correspondingly.

Good catch - but it's a bit confusing how we handle this case internally, and the other error case relies on that function doing the fput (which it does).

Any chance we can get that cleaned up at the same time? Would make errors in this error less likely in the future.

OK, sure, will try to prepare a better one.

Regards,
Xiaoguang Wang

Quoted 1 line
maintainer Applied
#3 lore raw
In reply to Xiaoguang Wang
Quoted 4 lines · Xiaoguang Wang

io_fixed_fd_install() may fail for short of free fixed file bitmap, in this case, need to call fput() correspondingly.

Applied, thanks!

[1/1] io_uring: ensure fput() called correspondingly when direct install fails

      commit: 1c145c7f3616ec48725edeac8edf26ee6ed4b661

Best regards,

Signature · 1 line
Jens Axboe