Skip to contentSkip to conversation

io-uring: Make statx api stable

PATCH Superseded Stefan Roesch 2 participants 5 messages Feb 15, 2022

Subsystems (2)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover io-uring: Make statx api stable

One of the key architectual tenets of io-uring is to keep the parameters for io-uring stable. After the call has been submitted, its value can be changed. Unfortunaltely this is not the case for the current statx implementation.

Patches:
Patch 1: fs: replace const char* parameter in vfs_statx and do_statx with
struct filename
Create filename object outside of do_statx and vfs_statx, so io-uring can create the filename object during the prepare phase

Patch 2: io-uring: Copy path name during prepare stage for statx
Create and store filename object during prepare phase

There is also a patch for the liburing libray to add a new test case. This patch makes sure that the api is stable.
"liburing: add test for stable statx api"

The patch has been tested with the liburing test suite and fstests.

Changes:
V2: don't check name in vfs_fstatat

Stefan Roesch (2):
fs: replace const char* parameter in vfs_statx and do_statx with
struct filename
io-uring: Copy path name during prepare stage for statx

 fs/internal.h |  4 +++-
 fs/io_uring.c | 22 ++++++++++++++++++++--
 fs/stat.c     | 48 +++++++++++++++++++++++++++++++++++-------------
 3 files changed, 58 insertions(+), 16 deletions(-)

base-commit: 754e0b0e35608ed5206d6a67a791563c631cec07

Signature · 1 line
2.30.2
#4 lore raw

PATCH v2 2/2 io-uring: Copy path name during prepare stage for statx

One of the key architectual tenets is to keep the parameters for io-uring stable. After the call has been submitted, its value can be changed. Unfortunaltely this is not the case for the current statx implementation.

This changes replaces the const char * filename pointer in the io_statx structure with a struct filename *. In addition it also creates the filename object during the prepare phase.

With this change, the opcode also needs to invoke cleanup, so the filename object gets freed after processing the request.

---
 fs/io_uring.c | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)
fs/io_uring.c +20 -2
index 77b9c7e4793b..28b09b163df1 100644
@@ -642,7 +642,7 @@ struct io_statx {
 	int				dfd;
 	unsigned int			mask;
 	unsigned int			flags;
-	const char __user		*filename;
+	struct filename			*filename;
 	struct statx __user		*buffer;
 };
 
@@ -4721,6 +4721,8 @@ static int io_fadvise(struct io_kiocb *req, unsigned int issue_flags)
 
 static int io_statx_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
 {
+	const char __user *path;
+
 	if (unlikely(req->ctx->flags & IORING_SETUP_IOPOLL))
 		return -EINVAL;
 	if (sqe->ioprio || sqe->buf_index || sqe->splice_fd_in)
@@ -4730,10 +4732,22 @@ static int io_statx_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
 
 	req->statx.dfd = READ_ONCE(sqe->fd);
 	req->statx.mask = READ_ONCE(sqe->len);
-	req->statx.filename = u64_to_user_ptr(READ_ONCE(sqe->addr));
+	path = u64_to_user_ptr(READ_ONCE(sqe->addr));
 	req->statx.buffer = u64_to_user_ptr(READ_ONCE(sqe->addr2));
 	req->statx.flags = READ_ONCE(sqe->statx_flags);
 
+	req->statx.filename = getname_flags(path,
+					getname_statx_lookup_flags(req->statx.flags),
+					NULL);
+
+	if (IS_ERR(req->statx.filename)) {
+		int ret = PTR_ERR(req->statx.filename);
+
+		req->statx.filename = NULL;
+		return ret;
+	}
+
+	req->flags |= REQ_F_NEED_CLEANUP;
 	return 0;
 }
 
@@ -6708,6 +6722,10 @@ static void io_clean_op(struct io_kiocb *req)
 			putname(req->hardlink.oldpath);
 			putname(req->hardlink.newpath);
 			break;
+		case IORING_OP_STATX:
+			if (req->statx.filename)
+				putname(req->statx.filename);
+			break;
 		}
 	}
 	if ((req->flags & REQ_F_POLLED) && req->apoll) {
Signature · 1 line
2.30.2
#1 lore raw

PATCH v2 1/2 fs: replace const char* parameter in vfs_statx and do_statx with struct filename

In reply to Stefan Roesch

This replaces the const char* __user filename parameter in the two functions do_statx and vfs_statx with a struct filename *. In addition to be able to correctly construct a filename object a new helper function getname_statx_lookup_flags is introduced. The function makes sure that do_statx and vfs_statx is invoked with the correct lookup flags.

---
 fs/internal.h |  4 +++-
 fs/stat.c     | 48 +++++++++++++++++++++++++++++++++++-------------
 2 files changed, 38 insertions(+), 14 deletions(-)
fs/internal.h +3 -1
index 8590c973c2f4..56c0477f4215 100644
@@ -184,7 +184,9 @@ int sb_init_dio_done_wq(struct super_block *sb);
 /*
  * fs/stat.c:
  */
-int do_statx(int dfd, const char __user *filename, unsigned flags,
+
+int getname_statx_lookup_flags(int flags);
+int do_statx(int dfd, struct filename *filename, unsigned int flags,
 	     unsigned int mask, struct statx __user *buffer);
 
 /*
fs/stat.c +35 -13

85 lines not on this page · raw message

Signature · 1 line
2.30.2
maintainer
#2 lore raw

Re: [PATCH v2 1/2] fs: replace const char* parameter in vfs_statx and do_statx with struct filename

fs/stat.c SYSCALL_DEFINE5(statx, · line 659

Quoted 9 lines · Stefan Roesch

{

fs/stat.c +7 -1
-	return do_statx(dfd, filename, flags, mask, buffer);
+	int ret;
+	struct filename *name;
+
+	name = getname_flags(filename, getname_statx_lookup_flags(flags), NULL);
+	ret = do_statx(dfd, name, flags, mask, buffer);
+	if (name)
+		putname(name);

... and the same comment goes for this one - getname... does *not* report a failure as NULL; it's ERR_PTR(), and putname(ERR_PTR(...)) is an explicit no-op.

#3 lore raw

Re: [PATCH v2 1/2] fs: replace const char* parameter in vfs_statx and do_statx with struct filename

Quoted 14 lines · Al Viro

fs/stat.c SYSCALL_DEFINE5(statx, · line 659

Quoted 9 lines · Stefan Roesch

{

fs/stat.c +7 -1
-	return do_statx(dfd, filename, flags, mask, buffer);
+	int ret;
+	struct filename *name;
+
+	name = getname_flags(filename, getname_statx_lookup_flags(flags), NULL);
+	ret = do_statx(dfd, name, flags, mask, buffer);
+	if (name)
+		putname(name);

... and the same comment goes for this one - getname... does *not* report a failure as NULL; it's ERR_PTR(), and putname(ERR_PTR(...)) is an explicit no-op.

I addressed this with v3 of the patch.