Linux io-uring development
 help / color / mirror / Atom feed
From: Jens Axboe <axboe@kernel.dk>
To: io-uring@vger.kernel.org
Cc: Chris Mason <mason@kernel.org>, Jens Axboe <axboe@kernel.dk>
Subject: [PATCH 05/10] io_uring/filetable: don't install O_PATH files
Date: Wed, 25 Nov 2026 11:43:14 -0700	[thread overview]
Message-ID: <20261125184439.58077-6-axboe@kernel.dk> (raw)
In-Reply-To: <20261125184439.58077-1-axboe@kernel.dk>

From: Chris Mason <mason@kernel.org>

IORING_OP_FADVISE with POSIX_FADV_WILLNEED on a fixed file that was
opened with O_PATH can dereference a NULL pointer in the readahead code
of the filesystem.

The opcode handlers are written like the system calls that they mirror,
which get their file from fdget() and so never see an O_PATH file.
io_uring has to keep that true for req->file. io_file_get_normal() does,
with fget(). io_file_get_fixed() checks nothing, so a fixed file table
must never hold an O_PATH file. The register and update paths take their
files from fget(). But a direct open, IORING_OP_OPENAT or
IORING_OP_OPENAT2 with sqe->file_index set, installs the file that
do_file_open() returns, and io_install_fixed_file() refuses nothing but
io_uring files.

With O_PATH, do_dentry_open() returns before it calls ->open(), so
file->private_data stays NULL. generic_fadvise() has no check of its own
and starts readahead with that file, and fuse_send_readpages(), for one,
dereferences file->private_data.

The fix used here is to refuse O_PATH files in io_install_fixed_file()
as well, so that a direct open gives what an open followed by a register
gives.

A direct open with O_PATH now fails with -EBADF. Until now the slot
could be turned into a descriptor with IORING_OP_FIXED_FD_INSTALL,
passed to another ring with IORING_MSG_SEND_FD, and used with
IORING_OP_FGETXATTR and IORING_OP_FSETXATTR. No program that does so is
known, and a fixed file can't serve as the directory of a lookup.

Fixes: b9445598d8c6 ("io_uring: openat directly into fixed fd table")
Signed-off-by: Chris Mason <mason@kernel.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
 io_uring/filetable.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/io_uring/filetable.c b/io_uring/filetable.c
index cb1838c9fc37..f547ab1193b1 100644
--- a/io_uring/filetable.c
+++ b/io_uring/filetable.c
@@ -67,6 +67,9 @@ static int io_install_fixed_file(struct io_ring_ctx *ctx, struct file *file,
 
 	if (io_is_uring_fops(file))
 		return -EBADF;
+	/* Registered files come from fget(), which refuses these too */
+	if (file->f_mode & FMODE_PATH)
+		return -EBADF;
 	if (!ctx->file_table.data.nr)
 		return -ENXIO;
 	if (slot_index >= ctx->file_table.data.nr)
-- 
2.55.0


  parent reply	other threads:[~2026-11-25 18:44 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25 18:43 [PATCHSET 0/10] Various fixes Jens Axboe
2026-11-25 18:43 ` [PATCH 01/10] io_uring/net: don't copy msg_name on a recvmsg retry Jens Axboe
2026-11-25 18:43 ` [PATCH 02/10] io_uring/kbuf: clear REQ_F_BL_NO_RECYCLE on buffer put Jens Axboe
2026-11-25 18:43 ` [PATCH 03/10] io_uring: free the ring after a grace period Jens Axboe
2026-11-25 18:43 ` [PATCH 04/10] io_uring: free the ring from an RCU work Jens Axboe
2026-11-25 18:43 ` Jens Axboe [this message]
2026-11-25 18:43 ` [PATCH 06/10] io_uring/timeout: hold timeout_lock for the link splice Jens Axboe
2026-11-25 18:43 ` [PATCH 07/10] io_uring/cancel: always walk links under timeout_lock Jens Axboe
2026-11-25 18:43 ` [PATCH 08/10] io_uring/net: don't count the buffers of a send bundle Jens Axboe
2026-11-25 18:43 ` [PATCH 09/10] io_uring: drop cached task refs on ring release Jens Axboe
2026-11-25 18:43 ` [PATCH 10/10] io_uring/net: restore the cmsg buffer on recvmsg retry Jens Axboe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261125184439.58077-6-axboe@kernel.dk \
    --to=axboe@kernel.dk \
    --cc=io-uring@vger.kernel.org \
    --cc=mason@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox