smb: client: fix OOB pointer arithmetic in cifs_to_posix_acl()
Subsystems (3)
PATCH 1/1 smb: client: fix OOB pointer arithmetic in cifs_to_posix_acl()
In the ACL_TYPE_DEFAULT branch, cifs_to_posix_acl() forms a pointer from the server-supplied access_entry_count before the size check that bounds it:
pACE = &cifs_acl->ace_array[count]; /* count = access_entry_count */
count = le16_to_cpu(cifs_acl->default_entry_count);
size += sizeof(struct cifs_posix_ace) * count;
if (size_of_data_area < size) /* too late */
return -EINVAL;The pointer arithmetic is undefined behaviour before any bounds check.
Add an access-ACE size check before the pointer computation, matching the existing guard in the ACL_TYPE_ACCESS path.
--- fs/smb/client/cifssmb.c | 3 +++ 1 file changed, 3 insertions(+)
fs/smb/client/cifssmb.c +3 -0
@@ -3345,6 +3345,9 @@ static int cifs_to_posix_acl(struct posix_acl **acl, char *src, count =le16_to_cpu (cifs_acl->access_entry_count); size =sizeof (struct cifs_posix_acl ); size +=sizeof (struct cifs_posix_ace ) * count; +/* validate access ACE count before pointer arithmetic */ +if (size_of_data_area < size) +return -EINVAL ;/* skip past access ACEs to get to default ACEs */ pACE = &cifs_acl->ace_array[count]; count =le16_to_cpu (cifs_acl->default_entry_count);
Signature · 1 line
2.55.0
Namjae Jeon
maintainerQuoted 4 lines · Frank Sorenson
In the
ACL_TYPE_DEFAULTbranch,cifs_to_posix_acl()forms a pointer from the server-suppliedaccess_entry_countbefore the size check that bounds it:
There seems to be still oob issue in this function although this patch is applied.
Should we also validate acl header before accessing ->version ?
+ if (size_of_data_area < sizeof(*cifs_acl))
+ return -EINVAL;
if (le16_to_cpu(cifs_acl->version) != CIFS_ACL_VERSION)
return -EOPNOTSUPP;Quoted 11 lines
pACE = &cifs_acl->ace_array[count]; /* count = access_entry_count */ count = le16_to_cpu(cifs_acl->default_entry_count); size += sizeof(struct cifs_posix_ace) * count; if (size_of_data_area < size) /* too late */ return -EINVAL;The pointer arithmetic is undefined behaviour before any bounds check.
Add an access-ACE size check before the pointer computation, matching the existing guard in the
ACL_TYPE_ACCESSpath.
Review
Quoted 13 lines · Namjae Jeon
Quoted 3 lines · Frank Sorenson
In the
ACL_TYPE_DEFAULTbranch,cifs_to_posix_acl()forms a pointer from the server-suppliedaccess_entry_countbefore the size check that bounds it:There seems to be still oob issue in this function although this patch is applied.
Should we also validate acl header before accessing ->version ?(quoted diff) +2
-0+ if (size_of_data_area < sizeof(*cifs_acl)) + return -EINVAL; if (le16_to_cpu(cifs_acl->version) != CIFS_ACL_VERSION) return -EOPNOTSUPP;
Ah, you are correct. I'll respin with all the necessary validation.
Frank
Quoted 10 lines
Quoted 10 lines
pACE = &cifs_acl->ace_array[count]; /* count = access_entry_count */ count = le16_to_cpu(cifs_acl->default_entry_count); size += sizeof(struct cifs_posix_ace) * count; if (size_of_data_area < size) /* too late */ return -EINVAL;The pointer arithmetic is undefined behaviour before any bounds check.
Add an access-ACE size check before the pointer computation, matching the existing guard in the
ACL_TYPE_ACCESSpath.
Signature · 4 lines
Frank Sorenson [email protected] Principal Software Maintenance Engineer, filesystems Red Hat