[PATCH v1 12/17] Call sort_pacl_range() for decoded POSIX draft ACLs

rick.macklem
2025-12-31T02:22:30Z

posix_valid_check() expects the ACEs in a POSIX draft ACL
to be sorted, so sort them. Since sort_pacl_range() uses bubble
sort, it will only make a single pass through the ACEs if they
are already sorted, which will often be the case.

Signed-off-by: Rick Macklem <rmacklem@uoguelph.ca>
---
fs/nfsd/nfs4xdr.c | 10 ++++++++++
1 file changed, 10 insertions(+)

diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index d12e479c18d3..72530203e985 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -483,6 +483,16 @@ nfsd4_decode_posix_acl(struct nfsd4_compoundargs *argp, struct posix_acl **acl)
}
}

+ /*
+ * posix_acl_valid() requires the ACEs to be sorted.
+ * If they are already sorted, sort_pacl_range() will return
+ * after one pass through the ACEs, since it implements bubble sort.
+ * Note that a count == 0 is used to delete a POSIX ACL and a count
+ * of 1 or 2 will always be found invalid by posix_acl_valid().
+ */
+ if (count >= 3)
+ sort_pacl_range(*acl, 0, count - 1);
+
return nfs_ok;
}

--
2.49.0