NFS: reject invalid decoded NFSACLs
Subsystems (2)
PATCH 1/1 NFS: reject invalid decoded NFSACLs
posix_acl_from_nfsacl() sorts decoded NFSACL entries and removes the extra mask entry used by Solaris, but it does not validate the resulting POSIX ACL. A malicious NFS server can therefore return an ACL that ends in ACL_GROUP and lacks the required ACL_MASK and ACL_OTHER entries.
If that NFS mount is re-exported, NFSD can pass the invalid ACL to _posix_to_nfsv4_one(). Its group walk assumes that posix_acl_valid() has already succeeded, so it can read beyond the ACL and emit more than the 2 * a_count ACEs allocated by nfsd4_get_nfs4_acl(), causing a heap out-of-bounds write.
Validate the ACL after sorting and applying the Solaris compatibility fix. Have the NFSD request decoders record validation failures as semantic errors so that invalid SETACL requests continue to receive the protocol's INVAL response instead of RPC GARBAGE_ARGS.
Validated on the nfsd-testing base shown below with an x86-64 kernel built by GCC 13.3 with W=1, CONFIG_WERROR=y, Generic KASAN, and lockdep. A validation-only fixture on the unpatched kernel supplied a three-entry GROUP-tail ACL with extra backing entries. The NFSv4 ACL converter emitted eight ACEs into a six-ACE allocation, and KASAN reported a slab-out-of-bounds write.
On the patched kernel, the malformed ACL returned -EINVAL, while a valid Solaris ACL normalized successfully. In two-VM re-export tests, both Solaris and extended named-group ACLs produced successful downstream NFSv4.1 GETACL responses; 64 malformed ACL replies were rejected in each run. Normal NFSv4.1 mount, read/write, and unmount tests passed. No KASAN, lockdep, Oops, or panic report occurred in the patched runs.
The vulnerability research and validation were conducted by members of the Tobabz team as part of the Best of the Best 15th program.
--- fs/nfs_common/nfsacl.c | 5 +++-- fs/nfsd/nfs2acl.c | 4 +++- fs/nfsd/nfs3acl.c | 4 +++- 3 files changed, 9 insertions(+), 4 deletions(-)
fs/nfs_common/nfsacl.c +3 -2
@@ -224,7 +224,8 @@ cmp_acl_entry(const void *x, const void *y)* Sorts the entries into POSIX 1003.1e draft 17 order and removes the * bogus ACL_MASK entry Solaris adds to a minimal ACL. * -* Return: 0. Always succeeds; a NULL @acl is a no-op. +* Return: 0 if @acl is valid, otherwise a negative error code. A NULL @acl +* is a no-op. */ int posix_acl_from_nfsacl (struct posix_acl *acl)
@@ -260,7 +261,7 @@ posix_acl_from_nfsacl(struct posix_acl *acl) sizeof(struct posix_acl_entry)); acl->a_count =3 ; } -return 0 ; +return posix_acl_valid (&init_user_ns, acl); }EXPORT_SYMBOL_GPL (posix_acl_from_nfsacl);
fs/nfsd/nfs2acl.c +3 -1
@@ -695,7 +695,9 @@ bool nfs_acl2_secattr_decode_end(struct xdrgen_aggregate_cursor *c, bool ok)*/ if (!ok || argp->invalid)return true; -return posix_acl_from_nfsacl (acl) ==0 ; +if (posix_acl_from_nfsacl (acl)) + argp->invalid = true; +return true; }/*
fs/nfsd/nfs3acl.c +3 -1
@@ -570,7 +570,9 @@ bool nfs_acl3_secattr_decode_end(struct xdrgen_aggregate_cursor *c, bool ok)*/ if (!ok || argp->invalid)return true; -return posix_acl_from_nfsacl (acl) ==0 ; +if (posix_acl_from_nfsacl (acl)) + argp->invalid = true; +return true; }/*
base-commit: 36fd4049e3c2bb901118e11be63bf7a7922bea8c
Signature · 1 line
2.50.1 (Apple Git-155)
Quoted 96 lines · Yeonsu Jung
posix_acl_from_nfsacl()sorts decoded NFSACL entries and removes the extra mask entry used by Solaris, but it does not validate the resulting POSIX ACL. A malicious NFS server can therefore return an ACL that ends inACL_GROUPand lacks the requiredACL_MASKandACL_OTHERentries.If that NFS mount is re-exported, NFSD can pass the invalid ACL to
_posix_to_nfsv4_one(). Its group walk assumes thatposix_acl_valid()has already succeeded, so it can read beyond the ACL and emit more than the 2 *a_countACEs allocated bynfsd4_get_nfs4_acl(), causing a heap out-of-bounds write.Validate the ACL after sorting and applying the Solaris compatibility fix. Have the NFSD request decoders record validation failures as semantic errors so that invalid SETACL requests continue to receive the protocol's INVAL response instead of RPC
GARBAGE_ARGS.Validated on the nfsd-testing base shown below with an x86-64 kernel built by GCC 13.3 with W=1,
CONFIG_WERROR=y, Generic KASAN, and lockdep. A validation-only fixture on the unpatched kernel supplied a three-entry GROUP-tail ACL with extra backing entries. The NFSv4 ACL converter emitted eight ACEs into a six-ACE allocation, and KASAN reported a slab-out-of-bounds write.On the patched kernel, the malformed ACL returned
-EINVAL, while a valid Solaris ACL normalized successfully. In two-VM re-export tests, both Solaris and extended named-group ACLs produced successful downstream NFSv4.1 GETACL responses; 64 malformed ACL replies were rejected in each run. Normal NFSv4.1 mount, read/write, and unmount tests passed. No KASAN, lockdep, Oops, or panic report occurred in the patched runs.The vulnerability research and validation were conducted by members of the Tobabz team as part of the Best of the Best 15th program.
Fixes b7fa0554cf1b ("[PATCH] NFS: Add support for NFSv3 ACLs")Signed-off-by Yeonsu Jung <[email protected]>--- fs/nfs_common/nfsacl.c | 5 +++-- fs/nfsd/nfs2acl.c | 4 +++- fs/nfsd/nfs3acl.c | 4 +++- 3 files changed, 9 insertions(+), 4 deletions(-)fs/nfs_common/nfsacl.c +3
-2@@ -224,7 +224,8 @@ cmp_acl_entry(const void *x, const void *y)* Sorts the entries into POSIX 1003.1e draft 17 order and removes the * bogus ACL_MASK entry Solaris adds to a minimal ACL. * -* Return: 0. Always succeeds; a NULL @acl is a no-op. +* Return: 0 if @acl is valid, otherwise a negative error code. A NULL @acl +* is a no-op. */ int posix_acl_from_nfsacl (struct posix_acl *acl)@@ -260,7 +261,7 @@ posix_acl_from_nfsacl(struct posix_acl *acl) sizeof(struct posix_acl_entry)); acl->a_count =3 ; } -return 0 ; +return posix_acl_valid (&init_user_ns, acl); }EXPORT_SYMBOL_GPL (posix_acl_from_nfsacl);fs/nfsd/nfs2acl.c +3
-1@@ -695,7 +695,9 @@ bool nfs_acl2_secattr_decode_end(struct xdrgen_aggregate_cursor *c, bool ok)*/ if (!ok || argp->invalid)return true; -return posix_acl_from_nfsacl (acl) ==0 ; +if (posix_acl_from_nfsacl (acl)) + argp->invalid = true; +return true; }/* fs/nfsd/nfs3acl.c +3
-1@@ -570,7 +570,9 @@ bool nfs_acl3_secattr_decode_end(struct xdrgen_aggregate_cursor *c, bool ok)*/ if (!ok || argp->invalid)return true; -return posix_acl_from_nfsacl (acl) ==0 ; +if (posix_acl_from_nfsacl (acl)) + argp->invalid = true; +return true; }/*
Quoted 1 line
base-commit:
36fd4049e3c2bb901118e11be63bf7a7922bea8c