NOP file-acquisition support choses between a fixed (registered) file and a normal fget()'d file based on its own IORING_NOP_FIXED_FILE flag in sqe->nop_flags. However, a request's REQ_F_FIXED_FILE is set independently from the generic IOSQE_FIXED_FILE sqe flag during request init, before the issue handler runs. If a NOP is submitted with IOSQE_FIXED_FILE set (so REQ_F_FIXED_FILE is set) but without IORING_NOP_FIXED_FILE, io_nop() takes the normal path and grabs a real reference via io_file_get_normal(). On completion, io_put_file() only drops the reference when REQ_F_FIXED_FILE is clear, so the fget()'d file is never released and leaks: BUG: memory leak unreferenced object 0xffff88800f42c240 (size 176): kmem_cache_alloc_noprof+0x358/0x440 alloc_empty_file+0x57/0x180 path_openat+0x44/0x1e50 do_file_open+0x121/0x200 do_sys_openat2+0xa7/0x150 __x64_sys_openat+0x82/0xf0 Decide between fixed and normal file acquisition from REQ_F_FIXED_FILE, the same way io_assign_file() does for every other opcode, and fold IORING_NOP_FIXED_FILE into REQ_F_FIXED_FILE at prep time.
Showing the changes to io_uring (1 of 1 file). Show all
Unified · Split
| @@ -40,6 +40,8 @@ int io_nop_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) · 39 unmodified lines | ||
| 40 | 40 | nop->fd = READ_ONCE(sqe->fd); |
| 41 | 41 | else |
| 42 | 42 | nop->fd = -1; |
| 43 | + if (nop->flags & IORING_NOP_FIXED_FILE) | |
| 44 | + req->flags |= REQ_F_FIXED_FILE; | |
| 43 | 45 | if (nop->flags & IORING_NOP_FIXED_BUFFER) |
| 44 | 46 | req->buf_index = READ_ONCE(sqe->buf_index); |
| 45 | 47 | if (nop->flags & IORING_NOP_CQE32) { |
| @@ -59,12 +61,10 @@ int io_nop(struct io_kiocb *req, unsigned int issue_flags) · 13 unmodified lines | ||
| 59 | 61 | int ret = nop->result; |
| 60 | 62 | |
| 61 | 63 | if (nop->flags & IORING_NOP_FILE) { |
| 62 | − if (nop->flags & IORING_NOP_FIXED_FILE) { | |
| 64 | + if (req->flags & REQ_F_FIXED_FILE) | |
| 63 | 65 | req->file = io_file_get_fixed(req, nop->fd, issue_flags); |
| 64 | − req->flags |= REQ_F_FIXED_FILE; | |
| 65 | − } else { | |
| 66 | + else | |
| 66 | 67 | req->file = io_file_get_normal(req, nop->fd); |
| 67 | − } | |
| 68 | 68 | if (!req->file) { |
| 69 | 69 | ret = -EBADF; |
| 70 | 70 | goto done; |