From: Jori Koolstra <jkoolstra@xs4all.nl>
To: Hengyu Liang <hengyul@cs.unc.edu>, Jens Axboe <axboe@kernel.dk>
Cc: Christian Brauner <brauner@kernel.org>,
Aleksa Sarai <cyphar@cyphar.com>,
io-uring@vger.kernel.org, linux-fsdevel@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] io_uring/openclose: allow an empty path with O_EMPTYPATH
Date: Wed, 25 Nov 2026 22:27:16 +0100 (CET) [thread overview]
Message-ID: <170898867.2781789.1795642036410@kpc.webmail.kpnmail.nl> (raw)
In-Reply-To: <20261125180817.3682397-1-hengyul@cs.unc.edu>
> Op 25-11-2026 19:08 CET schreef Hengyu Liang <hengyul@cs.unc.edu>:
>
>
> Commit 31cf44efa6df ("vfs: add O_EMPTYPATH to openat(2)/openat2(2)")
> made build_open_flags() accept O_EMPTYPATH and turn it into
> LOOKUP_EMPTY, so that openat(fd, "", O_EMPTYPATH) reopens the file
> behind fd.
>
> However, io_uring also uses build_open_flags(), but __io_openat_prep()
> still copies the name with delayed_getname(), which rejects an empty
> name with -ENOENT. As of now, IORING_OP_OPENAT and IORING_OP_OPENAT2
> accept O_EMPTYPATH, but fail on the empty path this flag is meant for.
>
I think you should leave the reproducer from the commit message.
> The issue can be reproduced with this program:
>
> #define _GNU_SOURCE
> #include <fcntl.h>
> #include <liburing.h>
> #include <stdio.h>
>
> #ifndef O_EMPTYPATH
> #define O_EMPTYPATH (1 << 26)
> #endif
>
> int main(void)
> {
> struct io_uring ring;
> struct io_uring_sqe *sqe;
> struct io_uring_cqe *cqe;
> int fd = open("/etc/passwd", O_PATH);
>
> printf("openat: %d\n", openat(fd, "", O_RDONLY | O_EMPTYPATH));
>
> io_uring_queue_init(1, &ring, 0);
> sqe = io_uring_get_sqe(&ring);
> io_uring_prep_openat(sqe, fd, "", O_RDONLY | O_EMPTYPATH, 0);
> io_uring_submit_and_wait(&ring, 1);
> io_uring_peek_cqe(&ring, &cqe);
> printf("IORING_OP_OPENAT: %d\n", cqe->res);
> return 0;
> }
>
> Before that commit (v7.1), both calls fail: it prints "openat: -1" and
> "IORING_OP_OPENAT: -2". After that commit (v7.2), the result is:
>
> openat: 4
> IORING_OP_OPENAT: -2
>
> This patch will copy the name with delayed_getname_uflags() and
> AT_EMPTY_PATH when O_EMPTYPATH is set, as io_uring's statx already does
> for AT_EMPTY_PATH.
It ain't a sin, but try to avoid "this patch" references.
>
> Fixes: 31cf44efa6df ("vfs: add O_EMPTYPATH to openat(2)/openat2(2)")
> Signed-off-by: Hengyu Liang <hengyul@cs.unc.edu>
> ---
> I found this while comparing the behavior of different kernel versions.
> I used an LLM to analyze the problem and to draft the patch and this
> message, and I analyzed the result myself.
>
> Tested on io_uring-7.4 (0659e44ce739) with KASAN and lockdep. A test
> that runs 24 cases through IORING_OP_OPENAT/OPENAT2 and through
> openat(2)/openat2(2) now gets the same result from both (32 of 42
> results differed before). The cases include O_PATH and regular fds,
> AT_FDCWD, forced async opens, RESOLVE_CACHED, a direct descriptor slot,
> a bad pointer and an unprivileged reopen of a 0600 file (EACCES). The
> liburing open tests and the openat2 selftests pass on both kernels.
>
> io_uring/openclose.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/io_uring/openclose.c b/io_uring/openclose.c
> index 24cf3ce2e2bc..29fe31f16a2b 100644
> --- a/io_uring/openclose.c
> +++ b/io_uring/openclose.c
> @@ -54,6 +54,7 @@ static int __io_openat_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe
> {
> struct io_open *open = io_kiocb_to_cmd(req, struct io_open);
> const char __user *fname;
> + int uflags = 0;
> int ret;
>
> if (unlikely(sqe->buf_index))
> @@ -67,7 +68,9 @@ static int __io_openat_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe
>
> open->dfd = READ_ONCE(sqe->fd);
> fname = u64_to_user_ptr(READ_ONCE(sqe->addr));
> - ret = delayed_getname(&open->filename, fname);
> + if (open->how.flags & O_EMPTYPATH)
> + uflags = AT_EMPTY_PATH;
> + ret = delayed_getname_uflags(&open->filename, fname, uflags);
> if (unlikely(ret))
> return ret;
> req->flags |= REQ_F_NEED_CLEANUP;
>
> base-commit: 0659e44ce739ecd856164c75a5325b7959a2921d
> --
> 2.53.0
Reviewed-by: Jori Koolstra (CIQ) <jkoolstra@xs4all.nl>
@Jens - You've pulled this already, I don't know if io_uring appreciates reviews
after pull. Let me know if not.
Thanks,
Jori.
next prev parent reply other threads:[~2026-11-25 21:27 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 18:08 Hengyu Liang
2026-11-25 18:46 ` Jens Axboe
2026-11-25 21:27 ` Jori Koolstra [this message]
2026-11-25 21:47 ` Jens Axboe
2026-11-25 22:02 ` Jori Koolstra
2026-11-26 1:48 ` 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=170898867.2781789.1795642036410@kpc.webmail.kpnmail.nl \
--to=jkoolstra@xs4all.nl \
--cc=axboe@kernel.dk \
--cc=brauner@kernel.org \
--cc=cyphar@cyphar.com \
--cc=hengyul@cs.unc.edu \
--cc=io-uring@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.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
all inboxes | Powered by JetHome®