public inbox for [email protected]
 help / color / mirror / Atom feed
From: Christian Brauner <[email protected]>
To: Stefan Roesch <[email protected]>
Cc: [email protected], [email protected],
	[email protected], [email protected]
Subject: Re: [PATCH v9 2/5] fs: split off setxattr_copy and do_setxattr function from setxattr
Date: Wed, 29 Dec 2021 15:48:02 +0100	[thread overview]
Message-ID: <20211229144802.udabxntfvcsxlnii@wittgenstein> (raw)
In-Reply-To: <[email protected]>

On Tue, Dec 28, 2021 at 10:41:42AM -0800, Stefan Roesch wrote:
> This splits of the setup part of the function
> setxattr in its own dedicated function called
> setxattr_copy. In addition it also exposes a
> new function called do_setxattr for making the
> setxattr call.
> 
> This makes it possible to call these two functions
> from io_uring in the processing of an xattr request.
> 
> Signed-off-by: Stefan Roesch <[email protected]>
> ---

(One completely optional thing below.)

Looks good,
Acked-by: Christian Brauner <[email protected]>

>  fs/internal.h | 21 +++++++++++++
>  fs/xattr.c    | 82 ++++++++++++++++++++++++++++++++++++---------------
>  2 files changed, 80 insertions(+), 23 deletions(-)
> 
> diff --git a/fs/internal.h b/fs/internal.h
> index 432ea3ce76ec..00c98b0cd634 100644
> --- a/fs/internal.h
> +++ b/fs/internal.h
> @@ -202,3 +202,24 @@ struct linux_dirent64;
>  
>  int vfs_getdents(struct file *file, struct linux_dirent64 __user *dirent,
>  		 unsigned int count, loff_t *pos);
> +
> + /*
> +  * fs/xattr.c:
> +  */
> +struct xattr_name {
> +	char name[XATTR_NAME_MAX + 1];
> +};

Fwiw, one additional idea is to implement this similar to struct
filename and have it keep the __user name together with the kernel name:

struct xattr_name {
	const __user char	*uname;	/* original userland pointer */
	char name[XATTR_NAME_MAX + 1];
};

and then sm like:

From 3d85d31eb65f007e48e838fce776f16811732fc0 Mon Sep 17 00:00:00 2001
From: Christian Brauner <[email protected]>
Date: Wed, 29 Dec 2021 15:43:46 +0100
Subject: [PATCH] UNTESTED

---
 fs/internal.h |  3 ++-
 fs/io_uring.c | 18 ++++++++----------
 fs/xattr.c    | 20 +++++++++++---------
 3 files changed, 21 insertions(+), 20 deletions(-)

diff --git a/fs/internal.h b/fs/internal.h
index 942b2005a2be..bb97042ebd04 100644
--- a/fs/internal.h
+++ b/fs/internal.h
@@ -207,7 +207,8 @@ int vfs_getdents(struct file *file, struct linux_dirent64 __user *dirent,
   * fs/xattr.c:
   */
 struct xattr_name {
-	char name[XATTR_NAME_MAX + 1];
+	const char __user *uname;
+	char kname[XATTR_NAME_MAX + 1];
 };
 
 struct xattr_ctx {
diff --git a/fs/io_uring.c b/fs/io_uring.c
index c88916b8cccc..55ad854d3c64 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -3916,7 +3916,6 @@ static int __io_getxattr_prep(struct io_kiocb *req,
 			      const struct io_uring_sqe *sqe)
 {
 	struct io_xattr *ix = &req->xattr;
-	const char __user *name;
 	int ret;
 
 	if (unlikely(req->ctx->flags & IORING_SETUP_IOPOLL))
@@ -3928,7 +3927,7 @@ static int __io_getxattr_prep(struct io_kiocb *req,
 
 	ix->filename = NULL;
 	ix->ctx.kvalue = NULL;
-	name = u64_to_user_ptr(READ_ONCE(sqe->addr));
+	ix->ctx.name = u64_to_user_ptr(READ_ONCE(sqe->addr));
 	ix->ctx.value = u64_to_user_ptr(READ_ONCE(sqe->addr2));
 	ix->ctx.size = READ_ONCE(sqe->len);
 	ix->ctx.flags = READ_ONCE(sqe->xattr_flags);
@@ -3940,9 +3939,9 @@ static int __io_getxattr_prep(struct io_kiocb *req,
 	if (!ix->ctx.kname)
 		return -ENOMEM;
 
-	ret = strncpy_from_user(ix->ctx.kname->name, name,
-				sizeof(ix->ctx.kname->name));
-	if (!ret || ret == sizeof(ix->ctx.kname->name))
+	ret = strncpy_from_user(ix->ctx.kname->kname, ix->ctx.name,
+				sizeof(ix->ctx.kname->kname));
+	if (!ret || ret == sizeof(ix->ctx.kname->kname))
 		ret = -ERANGE;
 	if (ret < 0) {
 		kfree(ix->ctx.kname);
@@ -3991,7 +3990,7 @@ static int io_fgetxattr(struct io_kiocb *req, unsigned int issue_flags)
 
 	ret = do_getxattr(mnt_user_ns(req->file->f_path.mnt),
 			req->file->f_path.dentry,
-			ix->ctx.kname->name,
+			ix->ctx.kname->kname,
 			(void __user *)ix->ctx.value,
 			ix->ctx.size);
 
@@ -4019,7 +4018,7 @@ static int io_getxattr(struct io_kiocb *req, unsigned int issue_flags)
 	if (!ret) {
 		ret = do_getxattr(mnt_user_ns(path.mnt),
 				path.dentry,
-				ix->ctx.kname->name,
+				ix->ctx.kname->kname,
 				(void __user *)ix->ctx.value,
 				ix->ctx.size);
 
@@ -4044,7 +4043,6 @@ static int __io_setxattr_prep(struct io_kiocb *req,
 			const struct io_uring_sqe *sqe)
 {
 	struct io_xattr *ix = &req->xattr;
-	const char __user *name;
 	int ret;
 
 	if (unlikely(req->ctx->flags & IORING_SETUP_IOPOLL))
@@ -4055,7 +4053,7 @@ static int __io_setxattr_prep(struct io_kiocb *req,
 		return -EBADF;
 
 	ix->filename = NULL;
-	name = u64_to_user_ptr(READ_ONCE(sqe->addr));
+	ix->ctx.name = u64_to_user_ptr(READ_ONCE(sqe->addr));
 	ix->ctx.value = u64_to_user_ptr(READ_ONCE(sqe->addr2));
 	ix->ctx.kvalue = NULL;
 	ix->ctx.size = READ_ONCE(sqe->len);
@@ -4065,7 +4063,7 @@ static int __io_setxattr_prep(struct io_kiocb *req,
 	if (!ix->ctx.kname)
 		return -ENOMEM;
 
-	ret = setxattr_copy(name, &ix->ctx);
+	ret = setxattr_copy(&ix->ctx);
 	if (ret) {
 		kfree(ix->ctx.kname);
 		return ret;
diff --git a/fs/xattr.c b/fs/xattr.c
index 3b6d683d07b9..27c64bb0ca65 100644
--- a/fs/xattr.c
+++ b/fs/xattr.c
@@ -542,16 +542,16 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
  * Extended attribute SET operations
  */
 
-int setxattr_copy(const char __user *name, struct xattr_ctx *ctx)
+int setxattr_copy(struct xattr_ctx *ctx)
 {
 	int error;
 
 	if (ctx->flags & ~(XATTR_CREATE|XATTR_REPLACE))
 		return -EINVAL;
 
-	error = strncpy_from_user(ctx->kname->name, name,
-				sizeof(ctx->kname->name));
-	if (error == 0 || error == sizeof(ctx->kname->name))
+	error = strncpy_from_user(ctx->kname->kname, ctx->kname->name,
+				sizeof(ctx->kname->kname));
+	if (error == 0 || error == sizeof(ctx->kname->kname))
 		return  -ERANGE;
 	if (error < 0)
 		return error;
@@ -577,8 +577,8 @@ static void setxattr_convert(struct user_namespace *mnt_userns,
 			struct xattr_ctx *ctx)
 {
 	if (ctx->size &&
-		((strcmp(ctx->kname->name, XATTR_NAME_POSIX_ACL_ACCESS) == 0) ||
-		(strcmp(ctx->kname->name, XATTR_NAME_POSIX_ACL_DEFAULT) == 0)))
+		((strcmp(ctx->kname->kname, XATTR_NAME_POSIX_ACL_ACCESS) == 0) ||
+		(strcmp(ctx->kname->kname, XATTR_NAME_POSIX_ACL_DEFAULT) == 0)))
 		posix_acl_fix_xattr_from_user(mnt_userns, ctx->kvalue, ctx->size);
 }
 
@@ -586,7 +586,7 @@ int do_setxattr(struct user_namespace *mnt_userns, struct dentry *dentry,
 		struct xattr_ctx *ctx)
 {
 	setxattr_convert(mnt_userns, ctx);
-	return vfs_setxattr(mnt_userns, dentry, ctx->kname->name,
+	return vfs_setxattr(mnt_userns, dentry, ctx->kname->kname,
 			ctx->kvalue, ctx->size, ctx->flags);
 }
 
@@ -595,7 +595,9 @@ setxattr(struct user_namespace *mnt_userns, struct dentry *d,
 	const char __user *name, const void __user *value, size_t size,
 	int flags)
 {
-	struct xattr_name kname;
+	struct xattr_name kname = {
+		.uname = name;
+	};
 	struct xattr_ctx ctx = {
 		.value    = value,
 		.kvalue   = NULL,
@@ -605,7 +607,7 @@ setxattr(struct user_namespace *mnt_userns, struct dentry *d,
 	};
 	int error;
 
-	error = setxattr_copy(name, &ctx);
+	error = setxattr_copy(&ctx);
 	if (error)
 		return error;
 
-- 
2.30.2


  reply	other threads:[~2021-12-29 14:48 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-28 18:41 [PATCH v9 0/5] io_uring: add xattr support Stefan Roesch
2021-12-28 18:41 ` [PATCH v9 1/5] fs: split off do_user_path_at_empty from user_path_at_empty() Stefan Roesch
2021-12-29 14:31   ` Christian Brauner
2021-12-29 20:34     ` Stefan Roesch
2021-12-28 18:41 ` [PATCH v9 2/5] fs: split off setxattr_copy and do_setxattr function from setxattr Stefan Roesch
2021-12-29 14:48   ` Christian Brauner [this message]
2021-12-28 18:41 ` [PATCH v9 3/5] fs: split off do_getxattr from getxattr Stefan Roesch
2021-12-28 18:41 ` [PATCH v9 4/5] io_uring: add fsetxattr and setxattr support Stefan Roesch
2021-12-29 14:51   ` Christian Brauner
2021-12-29 20:35     ` Stefan Roesch
2021-12-28 18:41 ` [PATCH v9 5/5] io_uring: add fgetxattr and getxattr support Stefan Roesch

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=20211229144802.udabxntfvcsxlnii@wittgenstein \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    /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