Skip to content

Commit 6aabb70

Browse files
committed
ksmbd: fix out-of-bounds in parse_sec_desc()
Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
1 parent af111b3 commit 6aabb70

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

smbacl.c

+10-7
Original file line numberDiff line numberDiff line change
@@ -899,14 +899,12 @@ static void set_mode_dacl(struct user_namespace *user_ns,
899899

900900
static int parse_sid(struct smb_sid *psid, char *end_of_acl)
901901
{
902-
/*
903-
* validate that we do not go past end of ACL - sid must be at least 8
904-
* bytes long (assuming no sub-auths - e.g. the null SID
905-
*/
906-
if (end_of_acl < (char *)psid + 8) {
907-
pr_err("ACL too small to parse SID %p\n", psid);
902+
char *acl_base = (char *)psid;
903+
904+
if (psid->num_subauth > SID_MAX_SUB_AUTHORITIES ||
905+
(end_of_acl - acl_base <
906+
offsetof(struct smb_sid, sub_auth) + sizeof(__le32) * psid->num_subauth))
908907
return -EINVAL;
909-
}
910908

911909
return 0;
912910
}
@@ -944,6 +942,11 @@ int parse_sec_desc(struct user_namespace *user_ns, struct smb_ntsd *pntsd,
944942
le32_to_cpu(pntsd->gsidoffset),
945943
le32_to_cpu(pntsd->sacloffset), dacloffset);
946944

945+
if (le32_to_cpu(pntsd->osidoffset) < sizeof(struct smb_ntsd) ||
946+
le32_to_cpu(pntsd->gsidoffset) < sizeof(struct smb_ntsd) ||
947+
dacloffset < sizeof(struct smb_ntsd))
948+
return -EINVAL;
949+
947950
pntsd_type = le16_to_cpu(pntsd->type);
948951
if (!(pntsd_type & DACL_PRESENT)) {
949952
ksmbd_debug(SMB, "DACL_PRESENT in DACL type is not set\n");

0 commit comments

Comments
 (0)