lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220531184125.2665210-5-usama.arif@bytedance.com>
Date:   Tue, 31 May 2022 19:41:24 +0100
From:   Usama Arif <usama.arif@...edance.com>
To:     io-uring@...r.kernel.org, axboe@...nel.dk,
        linux-kernel@...r.kernel.org
Cc:     fam.zheng@...edance.com, Usama Arif <usama.arif@...edance.com>
Subject: [PATCH 4/5] io_uring: add symlink opcode for current working directory

This provides consistency between io_uring and the respective I/O syscall
and avoids having the user of liburing specify the cwd in sqe for
IORING_OP_SYMLINKAT.

Signed-off-by: Usama Arif <usama.arif@...edance.com>
---
 fs/io_uring.c                 | 20 +++++++++++++++-----
 include/uapi/linux/io_uring.h |  1 +
 2 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/fs/io_uring.c b/fs/io_uring.c
index 9c9fa0b3938d..4050377619d3 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -1312,6 +1312,7 @@ static const struct io_op_def io_op_defs[] = {
 	[IORING_OP_UNLINKAT] = {},
 	[IORING_OP_MKDIR] = {},
 	[IORING_OP_MKDIRAT] = {},
+	[IORING_OP_SYMLINK] = {},
 	[IORING_OP_SYMLINKAT] = {},
 	[IORING_OP_LINKAT] = {},
 	[IORING_OP_MSG_RING] = {
@@ -1464,6 +1465,8 @@ const char *io_uring_get_opcode(u8 opcode)
 		return "MKDIR";
 	case IORING_OP_MKDIRAT:
 		return "MKDIRAT";
+	case IORING_OP_SYMLINK:
+		return "SYMLINK";
 	case IORING_OP_SYMLINKAT:
 		return "SYMLINKAT";
 	case IORING_OP_LINKAT:
@@ -4941,8 +4944,8 @@ static int io_mkdir(struct io_kiocb *req, unsigned int issue_flags)
 	return 0;
 }
 
-static int io_symlinkat_prep(struct io_kiocb *req,
-			    const struct io_uring_sqe *sqe)
+static int io_symlink_prep(struct io_kiocb *req,
+			    const struct io_uring_sqe *sqe, bool is_cwd)
 {
 	struct io_symlink *sl = &req->symlink;
 	const char __user *oldpath, *newpath;
@@ -4952,7 +4955,10 @@ static int io_symlinkat_prep(struct io_kiocb *req,
 	if (unlikely(req->flags & REQ_F_FIXED_FILE))
 		return -EBADF;
 
-	sl->new_dfd = READ_ONCE(sqe->fd);
+	if (is_cwd)
+		sl->new_dfd = AT_FDCWD;
+	else
+		sl->new_dfd = READ_ONCE(sqe->fd);
 	oldpath = u64_to_user_ptr(READ_ONCE(sqe->addr));
 	newpath = u64_to_user_ptr(READ_ONCE(sqe->addr2));
 
@@ -4970,7 +4976,7 @@ static int io_symlinkat_prep(struct io_kiocb *req,
 	return 0;
 }
 
-static int io_symlinkat(struct io_kiocb *req, unsigned int issue_flags)
+static int io_symlink(struct io_kiocb *req, unsigned int issue_flags)
 {
 	struct io_symlink *sl = &req->symlink;
 	int ret;
@@ -8107,8 +8113,10 @@ static int io_req_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
 		return io_mkdir_prep(req, sqe, 1);
 	case IORING_OP_MKDIRAT:
 		return io_mkdir_prep(req, sqe, 0);
+	case IORING_OP_SYMLINK:
+		return io_symlink_prep(req, sqe, 1);
 	case IORING_OP_SYMLINKAT:
-		return io_symlinkat_prep(req, sqe);
+		return io_symlink_prep(req, sqe, 0);
 	case IORING_OP_LINKAT:
 		return io_linkat_prep(req, sqe);
 	case IORING_OP_MSG_RING:
@@ -8267,6 +8275,7 @@ static void io_clean_op(struct io_kiocb *req)
 		case IORING_OP_MKDIRAT:
 			putname(req->mkdir.filename);
 			break;
+		case IORING_OP_SYMLINK:
 		case IORING_OP_SYMLINKAT:
 			putname(req->symlink.oldpath);
 			putname(req->symlink.newpath);
@@ -8435,6 +8444,7 @@ static int io_issue_sqe(struct io_kiocb *req, unsigned int issue_flags)
 	case IORING_OP_MKDIRAT:
 		ret = io_mkdirat(req, issue_flags);
 		break;
+	case IORING_OP_SYMLINK:
 	case IORING_OP_SYMLINKAT:
 		ret = io_symlinkat(req, issue_flags);
 		break;
diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.h
index 58f2e0611152..74e6b70638ee 100644
--- a/include/uapi/linux/io_uring.h
+++ b/include/uapi/linux/io_uring.h
@@ -192,6 +192,7 @@ enum io_uring_op {
 	IORING_OP_RENAME,
 	IORING_OP_UNLINK,
 	IORING_OP_MKDIR,
+	IORING_OP_SYMLINK,
 
 	/* this goes last, obviously */
 	IORING_OP_LAST,
-- 
2.25.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ