Skip to content

Commit d6e13e1

Browse files
namjaejeonSteve French
authored andcommitted
ksmbd: fix out-of-bounds in parse_sec_desc()
If osidoffset, gsidoffset and dacloffset could be greater than smb_ntsd struct size. If it is smaller, It could cause slab-out-of-bounds. And when validating sid, It need to check it included subauth array size. Cc: [email protected] Reported-by: Norbert Szetei <[email protected]> Tested-by: Norbert Szetei <[email protected]> Signed-off-by: Namjae Jeon <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent 4dd541f commit d6e13e1

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

fs/smb/server/smbacl.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,13 @@ static int parse_sid(struct smb_sid *psid, char *end_of_acl)
807807
return -EINVAL;
808808
}
809809

810+
if (!psid->num_subauth)
811+
return 0;
812+
813+
if (psid->num_subauth > SID_MAX_SUB_AUTHORITIES ||
814+
end_of_acl < (char *)psid + 8 + sizeof(__le32) * psid->num_subauth)
815+
return -EINVAL;
816+
810817
return 0;
811818
}
812819

@@ -848,6 +855,9 @@ int parse_sec_desc(struct mnt_idmap *idmap, struct smb_ntsd *pntsd,
848855
pntsd->type = cpu_to_le16(DACL_PRESENT);
849856

850857
if (pntsd->osidoffset) {
858+
if (le32_to_cpu(pntsd->osidoffset) < sizeof(struct smb_ntsd))
859+
return -EINVAL;
860+
851861
rc = parse_sid(owner_sid_ptr, end_of_acl);
852862
if (rc) {
853863
pr_err("%s: Error %d parsing Owner SID\n", __func__, rc);
@@ -863,6 +873,9 @@ int parse_sec_desc(struct mnt_idmap *idmap, struct smb_ntsd *pntsd,
863873
}
864874

865875
if (pntsd->gsidoffset) {
876+
if (le32_to_cpu(pntsd->gsidoffset) < sizeof(struct smb_ntsd))
877+
return -EINVAL;
878+
866879
rc = parse_sid(group_sid_ptr, end_of_acl);
867880
if (rc) {
868881
pr_err("%s: Error %d mapping Owner SID to gid\n",
@@ -884,6 +897,9 @@ int parse_sec_desc(struct mnt_idmap *idmap, struct smb_ntsd *pntsd,
884897
pntsd->type |= cpu_to_le16(DACL_PROTECTED);
885898

886899
if (dacloffset) {
900+
if (dacloffset < sizeof(struct smb_ntsd))
901+
return -EINVAL;
902+
887903
parse_dacl(idmap, dacl_ptr, end_of_acl,
888904
owner_sid_ptr, group_sid_ptr, fattr);
889905
}

0 commit comments

Comments
 (0)