ksmbd: count the ACL header when bounding the DACL size
Subsystems (3)
PATCH 1/1 ksmbd: count the ACL header when bounding the DACL size
set_posix_acl_entries_dacl() and set_ntacl_dacl() stop adding ACEs when their total size would no longer fit in 16 bits. The 8-byte ACL header is added to that total afterwards, so when the ACEs take 65528 to 65535 bytes, the DACL size wraps to a value below 8. A POSIX ACL with about 1800 entries is enough, and tmpfs and XFS can hold one. The security descriptor built for a new file is then stored cut off before its DACL, and a query returns DACL_PRESENT with no DACL, which reads as a NULL DACL.
Leave room for the header when bounding the ACEs.
---
Tested on ksmbd-for-next 4616bbc5389a with KASAN, on tmpfs. For a new file whose POSIX ACL has 1819 named users and one named group, a query now returns a DACL of 65516 bytes, which leaves out the last ACE. POSIX ACLs with 1800 and 1820 named users give the same results as before. smbtorture results match the base.
This patch was developed with LLM assistance.
fs/smb/server/smbacl.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-)
fs/smb/server/smbacl.c +16 -9
@@ -628,6 +628,18 @@ static int parse_dacl(const struct mnt_idmap *idmap,return ret; } +/* +* Add the size of an ACE to the size of the ACEs in a DACL. Fail when the +* DACL with its header would no longer fit in its 16-bit size. +*/ +static bool dacl_add_ace_size (u16 *size,u16 ace_sz) +{ +if (*size + ace_sz >U16_MAX -sizeof (struct smb_acl )) +return false; + *size += ace_sz; +return true; +} + static void set_posix_acl_entries_dacl(const struct mnt_idmap *idmap, struct smb_ace *pndace, struct smb_fattr *fattr, u16 *num_aces,
@@ -685,8 +697,7 @@ static void set_posix_acl_entries_dacl(const struct mnt_idmap *idmap, ntace = (struct smb_ace *)((char *)pndace + *size); ace_sz =fill_ace_for_sid (ntace, sid,ACCESS_ALLOWED , flags, pace->e_perm,0777 ); -if (check_add_overflow (*size, ace_sz, size)) { - *size -= ace_sz; +if (!dacl_add_ace_size (size, ace_sz)) {kfree (sid);break ; }
@@ -700,8 +711,7 @@ static void set_posix_acl_entries_dacl(const struct mnt_idmap *idmap, ntace = (struct smb_ace *)((char *)pndace + *size); ace_sz =fill_ace_for_sid (ntace, sid,ACCESS_ALLOWED ,0x03 , pace->e_perm,0777 ); -if (check_add_overflow (*size, ace_sz, size)) { - *size -= ace_sz; +if (!dacl_add_ace_size (size, ace_sz)) {kfree (sid);break ; }
@@ -746,8 +756,7 @@ static void set_posix_acl_entries_dacl(const struct mnt_idmap *idmap, ntace = (struct smb_ace *)((char *)pndace + *size); ace_sz =fill_ace_for_sid (ntace, sid,ACCESS_ALLOWED ,0x0b , pace->e_perm,0777 ); -if (check_add_overflow (*size, ace_sz, size)) { - *size -= ace_sz; +if (!dacl_add_ace_size (size, ace_sz)) {kfree (sid);break ; }
@@ -798,10 +807,8 @@ static void set_ntacl_dacl(const struct mnt_idmap *idmap, goto next_ace;memcpy ((char *)pndace + size, ntace, nt_ace_size); -if (check_add_overflow (size, nt_ace_size, &size)) { - size -= nt_ace_size; +if (!dacl_add_ace_size (&size, nt_ace_size))break ; - } num_aces++; next_ace:
Signature · 1 line
2.47.3
Quoted 10 lines · Ian Bridges
set_posix_acl_entries_dacl()andset_ntacl_dacl()stop adding ACEs when their total size would no longer fit in 16 bits. The 8-byte ACL header is added to that total afterwards, so when the ACEs take 65528 to 65535 bytes, the DACL size wraps to a value below 8. A POSIX ACL with about 1800 entries is enough, and tmpfs and XFS can hold one. The security descriptor built for a new file is then stored cut off before its DACL, and a query returnsDACL_PRESENTwith no DACL, which reads as a NULL DACL.
Quoted 5 lines
Leave room for the header when bounding the ACEs.
Fixes 299f962c0b02 ("ksmbd: use check_add_overflow() to prevent u16 DACL size overflow")Signed-off-by Ian Bridges <[email protected]>
Applied it to #ksmbd-for-next.
Thanks!