ksmbd: fix out-of-bounds read in smb_check_perm_dacl()
Subsystems (3)
PATCH 1/1 ksmbd: fix out-of-bounds read in smb_check_perm_dacl()
The permission-check ACE walk in smb_check_perm_dacl() validates the ACE header size and caps sid.num_subauth at SID_MAX_SUB_AUTHORITIES, but it never checks that ace->size is actually large enough to contain num_subauth sub-authorities before compare_sids() dereferences them.
CIFS_SID_BASE_SIZE covers the SID header up to but excluding the sub_auth[] array, and offsetof(struct smb_ace, sid) is the ACE header, so the existing guards only guarantee the 8-byte SID base, i.e. zero sub-authorities. compare_sids() then reads ace->sid.sub_auth[i] for i < min(local_sid->num_subauth, ace->sid.num_subauth). The local comparison SIDs (sid_everyone, sid_unix_NFS_mode, and the id_to_sid() result) always have at least one sub-authority, and an attacker controls the ACE revision and authority bytes (which lie within the in-bounds SID base), so they can match one of those SIDs and force the sub_auth read.
A crafted ACE with size == 16 and num_subauth >= 1 placed at the tail of the security descriptor therefore causes a heap out-of-bounds read of up to SID_MAX_SUB_AUTHORITIES * sizeof(__le32) bytes past the pntsd allocation. The security descriptor is loaded by ksmbd_vfs_get_sd_xattr() into a buffer sized exactly to the on-disk data (kzalloc(sd_size) in ndr_decode_v4_ntacl()), so the read lands past the allocation. The malformed descriptor can be stored verbatim via SMB2_SET_INFO (the DACL is not normalised before being written to the security.NTACL xattr) and the read fires on a subsequent SMB2_CREATE access check, making this reachable by an authenticated client on a share that uses ACL xattrs.
Add the missing num_subauth-versus-ace_size check, mirroring the identical guards already present in the sibling parsers parse_dacl() and smb_inherit_dacl().
--- fs/smb/server/smbacl.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
fs/smb/server/smbacl.c +3 -1
@@ -1477,7 +1477,9 @@ int smb_check_perm_dacl(struct ksmbd_conn *conn, const struct path *path,break ; aces_size -= ace_size; -if (ace->sid.num_subauth >SID_MAX_SUB_AUTHORITIES ) +if (ace->sid.num_subauth >SID_MAX_SUB_AUTHORITIES || + ace_size < offsetof(struct smb_ace , sid) +CIFS_SID_BASE_SIZE + +sizeof (__le32) * ace->sid.num_subauth)break ; if (!compare_sids(&sid, &ace->sid) ||
Signature · 1 line
2.34.1
Quoted 27 lines · Hem Parekh
The permission-check ACE walk in
smb_check_perm_dacl()validates the ACE header size and caps sid.num_subauth atSID_MAX_SUB_AUTHORITIES, but it never checks thatace->sizeis actually large enough to containnum_subauthsub-authorities beforecompare_sids()dereferences them.
CIFS_SID_BASE_SIZEcovers the SID header up to but excluding the sub_auth[] array, andoffsetof(struct smb_ace, sid)is the ACE header, so the existing guards only guarantee the 8-byte SID base, i.e. zero sub-authorities.compare_sids()then reads ace->sid.sub_auth[i] for i <min(local_sid->num_subauth, ace->sid.num_subauth). The local comparison SIDs (sid_everyone,sid_unix_NFS_mode, and theid_to_sid()result) always have at least one sub-authority, and an attacker controls the ACE revision and authority bytes (which lie within the in-bounds SID base), so they can match one of those SIDs and force thesub_authread.A crafted ACE with size == 16 and
num_subauth>= 1 placed at the tail of the security descriptor therefore causes a heap out-of-bounds read of up toSID_MAX_SUB_AUTHORITIES*sizeof(__le32)bytes past the pntsd allocation. The security descriptor is loaded byksmbd_vfs_get_sd_xattr()into a buffer sized exactly to the on-disk data (kzalloc(sd_size)inndr_decode_v4_ntacl()), so the read lands past the allocation. The malformed descriptor can be stored verbatim viaSMB2_SET_INFO(the DACL is not normalised before being written to the security.NTACL xattr) and the read fires on a subsequentSMB2_CREATEaccess check, making this reachable by an authenticated client on a share that uses ACL xattrs.
Quoted 7 lines
Add the missing num_subauth-versus-ace_size check, mirroring the identical guards already present in the sibling parsers
parse_dacl()andsmb_inherit_dacl().Fixes d07b26f39246 ("ksmbd: require minimum ACE size in smb_check_perm_dacl()")Signed-off-by Hem Parekh <[email protected]>
Applied it to #ksmbd-for-next-next.
Thanks!