Skip to contentSkip to conversation

smb: client: fix OOB pointer arithmetic in cifs_to_posix_acl()

PATCH In review Frank Sorenson 2 participants 3 messages Aug 24 – Aug 25

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

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.

Fixes bd9684b042dc ("cifs: implement get acl method")
---
 fs/smb/client/cifssmb.c | 3 +++
 1 file changed, 3 insertions(+)
fs/smb/client/cifssmb.c +3 -0
index f5aad5f61dce..fdcdebba8b69 100644
@@ -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
maintainer
#1 lore raw
Quoted 4 lines · Frank Sorenson

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:

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_ACCESS path.

#2 lore raw

Review

Quoted 13 lines · Namjae Jeon
Quoted 3 lines · Frank Sorenson

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:

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_ACCESS path.

Signature · 4 lines
Frank Sorenson
[email protected]
Principal Software Maintenance Engineer, filesystems
Red Hat