Skip to contentSkip to conversation

NFSv4: nfs4_proc_set_acl needs to restore NFS_CAP_UIDGID_NOMAP on error.

PATCH In review Dai Ngo 2 participants 4 messages May 19, 2021 – May 28, 2021

Subsystems (2)
lore
Share & tools
lore

Dai Ngo

author reviewer
#0 lore raw

PATCH v2 1/1 NFSv4: nfs4_proc_set_acl needs to restore NFS_CAP_UIDGID_NOMAP on error.

Currently if __nfs4_proc_set_acl fails with NFS4ERR_BADOWNER it re-enables the idmapper by clearing NFS_CAP_UIDGID_NOMAP before retrying again. The NFS_CAP_UIDGID_NOMAP remains cleared even if the retry fails. This causes problem for subsequent setattr requests for v4 server that does not have idmapping configured.

This patch modifies nfs4_proc_set_acl to detect NFS4ERR_BADOWNER and NFS4ERR_BADNAME and skips the retry, since the kernel isn't involved in encoding the ACEs, and return -EINVAL.

Steps to reproduce the problem:

 # mount -o vers=4.1,sec=sys server:/export/test /tmp/mnt
 # touch /tmp/mnt/file1
 # chown 99 /tmp/mnt/file1
 # nfs4_setfacl -a A::[email protected]:wrtncy /tmp/mnt/file1
 Failed setxattr operation: Invalid argument
 # chown 99 /tmp/mnt/file1
 chown: changing ownership of ‘/tmp/mnt/file1’: Invalid argument
 # umount /tmp/mnt
 # mount -o vers=4.1,sec=sys server:/export/test /tmp/mnt
 # chown 99 /tmp/mnt/file1
 #

v2: detect NFS4ERR_BADOWNER and NFS4ERR_BADNAME and skip retry
in nfs4_proc_set_acl.

---
 fs/nfs/nfs4proc.c | 8 ++++++++
 1 file changed, 8 insertions(+)
fs/nfs/nfs4proc.c +8 -0
index 87d04f2c9385..4e052c7f0614 100644
@@ -5968,6 +5968,14 @@ static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen
 	do {
 		err = __nfs4_proc_set_acl(inode, buf, buflen);
 		trace_nfs4_set_acl(inode, err);
+		if (err == -NFS4ERR_BADOWNER || err == -NFS4ERR_BADNAME) {
+			/*
+			 * no need to retry since the kernel
+			 * isn't involved in encoding the ACEs.
+			 */
+			err = -EINVAL;
+			break;
+		}
 		err = nfs4_handle_exception(NFS_SERVER(inode), err,
 				&exception);
 	} while (exception.retry);
Signature · 1 line
2.9.5
author reviewer
#1 lore raw

Hi Trond,

Just a reminder that this patch is ready for your review.

Thanks,
-Dai

Quoted 50 lines · Dai Ngo

Currently if __nfs4_proc_set_acl fails with NFS4ERR_BADOWNER it re-enables the idmapper by clearing NFS_CAP_UIDGID_NOMAP before retrying again. The NFS_CAP_UIDGID_NOMAP remains cleared even if the retry fails. This causes problem for subsequent setattr requests for v4 server that does not have idmapping configured.

This patch modifies nfs4_proc_set_acl to detect NFS4ERR_BADOWNER and NFS4ERR_BADNAME and skips the retry, since the kernel isn't involved in encoding the ACEs, and return -EINVAL.

Steps to reproduce the problem:

  # mount -o vers=4.1,sec=sys server:/export/test /tmp/mnt
  # touch /tmp/mnt/file1
  # chown 99 /tmp/mnt/file1
  # nfs4_setfacl -a A::[email protected]:wrtncy /tmp/mnt/file1
  Failed setxattr operation: Invalid argument
  # chown 99 /tmp/mnt/file1
  chown: changing ownership of ‘/tmp/mnt/file1’: Invalid argument
  # umount /tmp/mnt
  # mount -o vers=4.1,sec=sys server:/export/test /tmp/mnt
  # chown 99 /tmp/mnt/file1
  #

v2: detect NFS4ERR_BADOWNER and NFS4ERR_BADNAME and skip retry
in nfs4_proc_set_acl.

---
  fs/nfs/nfs4proc.c | 8 ++++++++
  1 file changed, 8 insertions(+)
fs/nfs/nfs4proc.c +8 -0
index 87d04f2c9385..4e052c7f0614 100644
@@ -5968,6 +5968,14 @@ static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen
  	do {
  		err = __nfs4_proc_set_acl(inode, buf, buflen);
  		trace_nfs4_set_acl(inode, err);
+		if (err == -NFS4ERR_BADOWNER || err == -NFS4ERR_BADNAME) {
+			/*
+			 * no need to retry since the kernel
+			 * isn't involved in encoding the ACEs.
+			 */
+			err = -EINVAL;
+			break;
+		}
  		err = nfs4_handle_exception(NFS_SERVER(inode), err,
  				&exception);
  	} while (exception.retry);
#2 lore raw
Quoted 3 lines · On Fri, 2021-05-28 at 10:30 -0700, [email protected] wrote:

Hi Trond,

Just a reminder that this patch is ready for your review.

Sorry. I missed that update for some reason.

Quoted 49 lines

Thanks,
-Dai

Quoted 44 lines · Dai Ngo

Currently if __nfs4_proc_set_acl fails with NFS4ERR_BADOWNER it re-enables the idmapper by clearing NFS_CAP_UIDGID_NOMAP before retrying again. The NFS_CAP_UIDGID_NOMAP remains cleared even if the retry fails. This causes problem for subsequent setattr requests for v4 server that does not have idmapping configured.

This patch modifies nfs4_proc_set_acl to detect NFS4ERR_BADOWNER and NFS4ERR_BADNAME and skips the retry, since the kernel isn't involved in encoding the ACEs, and return -EINVAL.

Steps to reproduce the problem:

  # mount -o vers=4.1,sec=sys server:/export/test /tmp/mnt
  # touch /tmp/mnt/file1
  # chown 99 /tmp/mnt/file1
  # nfs4_setfacl -a A::[email protected]:wrtncy /tmp/mnt/file1
  Failed setxattr operation: Invalid argument
  # chown 99 /tmp/mnt/file1
  chown: changing ownership of ‘/tmp/mnt/file1’: Invalid argument
  # umount /tmp/mnt
  # mount -o vers=4.1,sec=sys server:/export/test /tmp/mnt
  # chown 99 /tmp/mnt/file1
  #

v2: detect NFS4ERR_BADOWNER and NFS4ERR_BADNAME and skip retry in nfs4_proc_set_acl.

---
  fs/nfs/nfs4proc.c | 8 ++++++++

  1 file changed, 8 insertions(+)
fs/nfs/nfs4proc.c +3 -0
index 87d04f2c9385..4e052c7f0614 100644
@@ -5968,6 +5968,14 @@ static int nfs4_proc_set_acl(struct inode
 *inode, const void *buf, size_t buflen
         do {
                 err = __nfs4_proc_set_acl(inode, buf, buflen);
                 trace_nfs4_set_acl(inode, err);
+               if (err == -NFS4ERR_BADOWNER || err == -
 NFS4ERR_BADNAME) {
+                       /*
+                        * no need to retry since the kernel
Quoted 8 lines
Quoted 8 lines
fs/nfs/nfs4proc.c +5 -0
+                        * isn't involved in encoding the ACEs.
+                        */
+                       err = -EINVAL;
+                       break;
+               }
                 err = nfs4_handle_exception(NFS_SERVER(inode), err,

                                &exception);
        } while (exception.retry);

Yes, this looks OK.

Signature · 3 lines
Trond Myklebust
Linux NFS client maintainer, Hammerspace
[email protected]
author reviewer
#3 lore raw
Quoted 5 lines · Trond Myklebust
Quoted 3 lines · On Fri, 2021-05-28 at 10:30 -0700, [email protected] wrote:

Hi Trond,

Just a reminder that this patch is ready for your review.

Sorry. I missed that update for some reason.

it's ok. It can wait for the next pull.

Thanks,
-Dai

Quoted 59 lines
Quoted 49 lines

Thanks,
-Dai

Quoted 44 lines · Dai Ngo

Currently if __nfs4_proc_set_acl fails with NFS4ERR_BADOWNER it re-enables the idmapper by clearing NFS_CAP_UIDGID_NOMAP before retrying again. The NFS_CAP_UIDGID_NOMAP remains cleared even if the retry fails. This causes problem for subsequent setattr requests for v4 server that does not have idmapping configured.

This patch modifies nfs4_proc_set_acl to detect NFS4ERR_BADOWNER and NFS4ERR_BADNAME and skips the retry, since the kernel isn't involved in encoding the ACEs, and return -EINVAL.

Steps to reproduce the problem:

   # mount -o vers=4.1,sec=sys server:/export/test /tmp/mnt
   # touch /tmp/mnt/file1
   # chown 99 /tmp/mnt/file1
   # nfs4_setfacl -a A::[email protected]:wrtncy /tmp/mnt/file1
   Failed setxattr operation: Invalid argument
   # chown 99 /tmp/mnt/file1
   chown: changing ownership of ‘/tmp/mnt/file1’: Invalid argument
   # umount /tmp/mnt
   # mount -o vers=4.1,sec=sys server:/export/test /tmp/mnt
   # chown 99 /tmp/mnt/file1
   #

v2: detect NFS4ERR_BADOWNER and NFS4ERR_BADNAME and skip retry
        in nfs4_proc_set_acl.

---
   fs/nfs/nfs4proc.c | 8 ++++++++
   1 file changed, 8 insertions(+)
fs/nfs/nfs4proc.c +3 -0
index 87d04f2c9385..4e052c7f0614 100644
@@ -5968,6 +5968,14 @@ static int nfs4_proc_set_acl(struct inode
 *inode, const void *buf, size_t buflen
         do {
                 err = __nfs4_proc_set_acl(inode, buf, buflen);
                 trace_nfs4_set_acl(inode, err);
+               if (err == -NFS4ERR_BADOWNER || err == -
 NFS4ERR_BADNAME) {
+                       /*
+                        * no need to retry since the kernel
Quoted 8 lines
Quoted 8 lines
fs/nfs/nfs4proc.c +5 -0
+                        * isn't involved in encoding the ACEs.
+                        */
+                       err = -EINVAL;
+                       break;
+               }
                 err = nfs4_handle_exception(NFS_SERVER(inode), err,

                                &exception);
        } while (exception.retry);

Yes, this looks OK.