mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ian Bridges <icb@fastmail.org>
To: linkinjeon@kernel.org
Cc: senozhatsky@chromium.org, tom@talpey.com,
	chenxiaosong@chenxiaosong.com, linux-cifs@vger.kernel.org,
	linux-kernel@vger.kernel.org, tristan@talencesecurity.com,
	Ian Bridges <icb@fastmail.org>,
	stable@vger.kernel.org
Subject: [PATCH] ksmbd: count the ACL header when bounding the DACL size
Date: Thu, 19 Nov 2026 13:20:07 -0600	[thread overview]
Message-ID: <20261119192007.198258-1-icb@fastmail.org> (raw)

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


                 reply	other threads:[~2026-11-19 19:20 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261119192007.198258-1-icb@fastmail.org \
    --to=icb@fastmail.org \
    --cc=chenxiaosong@chenxiaosong.com \
    --cc=linkinjeon@kernel.org \
    --cc=linux-cifs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=senozhatsky@chromium.org \
    --cc=stable@vger.kernel.org \
    --cc=tom@talpey.com \
    --cc=tristan@talencesecurity.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®