* [PATCH] io_uring/nop: fix file reference leak with IOSQE_FIXED_FILE
@ 2026-06-15 14:45 Vasileios Almpanis
2026-06-15 16:08 ` Jens Axboe
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Vasileios Almpanis @ 2026-06-15 14:45 UTC (permalink / raw)
To: Jens Axboe; +Cc: io-uring, linux-kernel
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.
Cc: stable@vger.kernel.org
Fixes: a85f31052bce ("io_uring/nop: add support for testing registered files and buffers")
Reported-by: syzbot+2cd473471e77bda12b0e@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?id=879092631b98f73a28ea405adacfa5bb34a14a25
Signed-off-by: Vasileios Almpanis <vasilisalmpanis@gmail.com>
---
io_uring/nop.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/io_uring/nop.c b/io_uring/nop.c
index 91ae0b2e7e55..60ab19604b36 100644
--- a/io_uring/nop.c
+++ b/io_uring/nop.c
@@ -40,6 +40,8 @@ int io_nop_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
nop->fd = READ_ONCE(sqe->fd);
else
nop->fd = -1;
+ if (nop->flags & IORING_NOP_FIXED_FILE)
+ req->flags |= REQ_F_FIXED_FILE;
if (nop->flags & IORING_NOP_FIXED_BUFFER)
req->buf_index = READ_ONCE(sqe->buf_index);
if (nop->flags & IORING_NOP_CQE32) {
@@ -59,12 +61,10 @@ int io_nop(struct io_kiocb *req, unsigned int issue_flags)
int ret = nop->result;
if (nop->flags & IORING_NOP_FILE) {
- if (nop->flags & IORING_NOP_FIXED_FILE) {
+ if (req->flags & REQ_F_FIXED_FILE)
req->file = io_file_get_fixed(req, nop->fd, issue_flags);
- req->flags |= REQ_F_FIXED_FILE;
- } else {
+ else
req->file = io_file_get_normal(req, nop->fd);
- }
if (!req->file) {
ret = -EBADF;
goto done;
--
2.47.3
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] io_uring/nop: fix file reference leak with IOSQE_FIXED_FILE
2026-06-15 14:45 [PATCH] io_uring/nop: fix file reference leak with IOSQE_FIXED_FILE Vasileios Almpanis
@ 2026-06-15 16:08 ` Jens Axboe
2026-06-15 16:09 ` Jens Axboe
2026-06-15 16:11 ` Jens Axboe
2 siblings, 0 replies; 4+ messages in thread
From: Jens Axboe @ 2026-06-15 16:08 UTC (permalink / raw)
To: Vasileios Almpanis; +Cc: io-uring, linux-kernel
On Mon, 15 Jun 2026 16:45:57 +0200, Vasileios Almpanis wrote:
> 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:
>
> [...]
Applied, thanks!
[1/1] io_uring/nop: fix file reference leak with IOSQE_FIXED_FILE
commit: 571999ce5d657440f22e7f97c21ba86886fa987b
Best regards,
--
Jens Axboe
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] io_uring/nop: fix file reference leak with IOSQE_FIXED_FILE
2026-06-15 14:45 [PATCH] io_uring/nop: fix file reference leak with IOSQE_FIXED_FILE Vasileios Almpanis
2026-06-15 16:08 ` Jens Axboe
@ 2026-06-15 16:09 ` Jens Axboe
2026-06-15 16:11 ` Jens Axboe
2 siblings, 0 replies; 4+ messages in thread
From: Jens Axboe @ 2026-06-15 16:09 UTC (permalink / raw)
To: Vasileios Almpanis; +Cc: io-uring, linux-kernel
On 6/15/26 8:45 AM, Vasileios Almpanis wrote:
> 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.
Fix looks good to me! I've written a test case for this as well, it's
in liburing.
--
Jens Axboe
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] io_uring/nop: fix file reference leak with IOSQE_FIXED_FILE
2026-06-15 14:45 [PATCH] io_uring/nop: fix file reference leak with IOSQE_FIXED_FILE Vasileios Almpanis
2026-06-15 16:08 ` Jens Axboe
2026-06-15 16:09 ` Jens Axboe
@ 2026-06-15 16:11 ` Jens Axboe
2 siblings, 0 replies; 4+ messages in thread
From: Jens Axboe @ 2026-06-15 16:11 UTC (permalink / raw)
To: Vasileios Almpanis; +Cc: io-uring, linux-kernel
On Mon, 15 Jun 2026 16:45:57 +0200, Vasileios Almpanis wrote:
> 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:
>
> [...]
Applied, thanks!
[1/1] io_uring/nop: fix file reference leak with IOSQE_FIXED_FILE
commit: 1abb79a6afcfb45a46e1f4cd99321e561a46a444
Best regards,
--
Jens Axboe
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-06-15 16:11 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-06-15 14:45 [PATCH] io_uring/nop: fix file reference leak with IOSQE_FIXED_FILE Vasileios Almpanis
2026-06-15 16:08 ` Jens Axboe
2026-06-15 16:09 ` Jens Axboe
2026-06-15 16:11 ` Jens Axboe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®