* [PATCH] ksmbd: count the ACL header when bounding the DACL size
@ 2026-11-19 19:20 Ian Bridges
0 siblings, 0 replies; only message in thread
From: Ian Bridges @ 2026-11-19 19:20 UTC (permalink / raw)
To: linkinjeon
Cc: senozhatsky, tom, chenxiaosong, linux-cifs, linux-kernel,
tristan, Ian Bridges, stable
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.
Fixes: 299f962c0b02 ("ksmbd: use check_add_overflow() to prevent u16 DACL size overflow")
Cc: stable@vger.kernel.org
Signed-off-by: Ian Bridges <icb@fastmail.org>
---
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(-)
diff --git a/fs/smb/server/smbacl.c b/fs/smb/server/smbacl.c
index 2651214c939a..86a59878ae87 100644
--- a/fs/smb/server/smbacl.c
+++ b/fs/smb/server/smbacl.c
@@ -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:
--
2.47.3
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-19 19:20 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-19 19:20 [PATCH] ksmbd: count the ACL header when bounding the DACL size Ian Bridges
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®