Skip to contentSkip to conversation

fs: move the posix_acl_fix_xattr_{to_from}_user out of xattr code

PATCH In review Christoph Hellwig 2 participants 2 messages Mar 24, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fs: move the posix_acl_fix_xattr_{to_from}_user out of xattr code

There is no excuse to ever perform actions related to a specific handler directly from the generic xattr code as we have handler that understand the specific data in given attrs. As a nice sideeffect this removes tons of pointless boilerplate code.

---

Changes since v1:
- fix up file systems that have their own ACL xattr handlers

 fs/9p/acl.c                     |  4 +--
 fs/overlayfs/dir.c              |  2 +-
 fs/overlayfs/super.c            |  2 +-
 fs/posix_acl.c                  | 62 ++-------------------------------
 fs/xattr.c                      |  8 +----
 include/linux/posix_acl_xattr.h | 12 -------
 6 files changed, 7 insertions(+), 83 deletions(-)
fs/9p/acl.c +2 -2
index 6261719f6f2a..f3455ba2a84d 100644
@@ -232,7 +232,7 @@ static int v9fs_xattr_get_acl(const struct xattr_handler *handler,
 		return PTR_ERR(acl);
 	if (acl == NULL)
 		return -ENODATA;
-	error = posix_acl_to_xattr(&init_user_ns, acl, buffer, size);
+	error = posix_acl_to_xattr(current_user_ns(), acl, buffer, size);
 	posix_acl_release(acl);
 
 	return error;
@@ -262,7 +262,7 @@ static int v9fs_xattr_set_acl(const struct xattr_handler *handler,
 		return -EPERM;
 	if (value) {
 		/* update the cached acl value */
-		acl = posix_acl_from_xattr(&init_user_ns, value, size);
+		acl = posix_acl_from_xattr(current_user_ns(), value, size);
 		if (IS_ERR(acl))
 			return PTR_ERR(acl);
 		else if (acl) {
fs/overlayfs/dir.c +1 -1
index 8e57d5372b8f..0b07e99475fd 100644
@@ -416,7 +416,7 @@ static int ovl_set_upper_acl(struct dentry *upperdentry, const char *name,
 	if (!buffer)
 		return -ENOMEM;
 
-	err = posix_acl_to_xattr(&init_user_ns, acl, buffer, size);
+	err = posix_acl_to_xattr(current_user_ns(), acl, buffer, size);
 	if (err < 0)
 		goto out_free;
 
fs/overlayfs/super.c +1 -1
index 319fe0d355b0..4c62636f295b 100644
@@ -874,7 +874,7 @@ ovl_posix_acl_xattr_set(const struct xattr_handler *handler,
 
 	/* Check that everything is OK before copy-up */
 	if (value) {
-		acl = posix_acl_from_xattr(&init_user_ns, value, size);
+		acl = posix_acl_from_xattr(current_user_ns(), value, size);
 		if (IS_ERR(acl))
 			return PTR_ERR(acl);
 	}
fs/posix_acl.c +2 -60

80 lines not on this page · raw message

fs/xattr.c +1 -7
index 90dd78f0eb27..c31e9a9ea172 100644
@@ -437,10 +437,7 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
 			error = -EFAULT;
 			goto out;
 		}
-		if ((strcmp(kname, XATTR_NAME_POSIX_ACL_ACCESS) == 0) ||
-		    (strcmp(kname, XATTR_NAME_POSIX_ACL_DEFAULT) == 0))
-			posix_acl_fix_xattr_from_user(kvalue, size);
-		else if (strcmp(kname, XATTR_NAME_CAPS) == 0) {
+		if (strcmp(kname, XATTR_NAME_CAPS) == 0) {
 			error = cap_convert_nscap(d, &kvalue, size);
 			if (error < 0)
 				goto out;
@@ -537,9 +534,6 @@ getxattr(struct dentry *d, const char __user *name, void __user *value,
 
 	error = vfs_getxattr(d, kname, kvalue, size);
 	if (error > 0) {
-		if ((strcmp(kname, XATTR_NAME_POSIX_ACL_ACCESS) == 0) ||
-		    (strcmp(kname, XATTR_NAME_POSIX_ACL_DEFAULT) == 0))
-			posix_acl_fix_xattr_to_user(kvalue, error);
 		if (size && copy_to_user(value, kvalue, error))
 			error = -EFAULT;
 	} else if (error == -ERANGE && size >= XATTR_SIZE_MAX) {
include/linux/posix_acl_xattr.h +0 -12
index 2387709991b5..8f5e70a1bd05 100644
@@ -32,18 +32,6 @@ posix_acl_xattr_count(size_t size)
 	return size / sizeof(struct posix_acl_xattr_entry);
 }
 
-#ifdef CONFIG_FS_POSIX_ACL
-void posix_acl_fix_xattr_from_user(void *value, size_t size);
-void posix_acl_fix_xattr_to_user(void *value, size_t size);
-#else
-static inline void posix_acl_fix_xattr_from_user(void *value, size_t size)
-{
-}
-static inline void posix_acl_fix_xattr_to_user(void *value, size_t size)
-{
-}
-#endif
-
 struct posix_acl *posix_acl_from_xattr(struct user_namespace *user_ns, 
 				       const void *value, size_t size);
 int posix_acl_to_xattr(struct user_namespace *user_ns,
Signature · 1 line
2.25.1
maintainer
#1 lore raw
Quoted 25 lines · Christoph Hellwig

There is no excuse to ever perform actions related to a specific handler directly from the generic xattr code as we have handler that understand the specific data in given attrs. As a nice sideeffect this removes tons of pointless boilerplate code.

---

Changes since v1:
- fix up file systems that have their own ACL xattr handlers

 fs/9p/acl.c                     |  4 +--
 fs/overlayfs/dir.c              |  2 +-
 fs/overlayfs/super.c            |  2 +-
 fs/posix_acl.c                  | 62 ++-------------------------------
 fs/xattr.c                      |  8 +----
 include/linux/posix_acl_xattr.h | 12 -------
 6 files changed, 7 insertions(+), 83 deletions(-)
fs/9p/acl.c +0 -0
index 6261719f6f2a..f3455ba2a84d 100644

fs/9p/acl.c static int v9fs_xattr_get_acl(const struct xattr_handler *handler, · line 235

Quoted 5 lines
fs/9p/acl.c +1 -1
@@ -232,7 +232,7 @@ static int v9fs_xattr_get_acl(const struct xattr_handler *handler,
                return PTR_ERR(acl);
        if (acl == NULL)
                return -ENODATA;
-       error = posix_acl_to_xattr(&init_user_ns, acl, buffer, size);
+       error = posix_acl_to_xattr(current_user_ns(), acl, buffer, size);

Okay, but the uncached cache is still broken. It needs the xattr to be converted to acl (posix_acl_to_xattr(&init_user_ns, ...)) then back to xattr here.

fs/9p/acl.c static int v9fs_xattr_set_acl(const struct xattr_handler *handler, · line 265

Quoted 9 lines
fs/9p/acl.c +1 -1
        posix_acl_release(acl);
 
        return error;
@@ -262,7 +262,7 @@ static int v9fs_xattr_set_acl(const struct xattr_handler *handler,
                return -EPERM;
        if (value) {
                /* update the cached acl value */
-               acl = posix_acl_from_xattr(&init_user_ns, value, size);
+               acl = posix_acl_from_xattr(current_user_ns(), value, size);

Same in this function.

Thanks,
Miklos