Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: Wentao Guan <guanwentao@uniontech.com>
To: gregkh@linuxfoundation.org
Cc: guanwentao@uniontech.com, linkinjeon@kernel.org,
	stable@vger.kernel.org, stfrench@microsoft.com
Subject: [PATCH 6.6.y && 6.12.y && 6.18.y && 7.1.y v3 3/4] ksmbd: bound DACL dedup walk to copied ACEs
Date: Thu, 30 Jul 2026 03:00:26 +0800	[thread overview]
Message-ID: <20260729190023.46584-4-guanwentao@uniontech.com> (raw)
In-Reply-To: <2026072936-equipment-calculate-e753@gregkh>

From: Namjae Jeon <linkinjeon@kernel.org>

set_ntacl_dacl() can stop copying ACEs before consuming the full input
DACL when size accounting overflows.

When that happens, num_aces reflects only the ACEs that were actually
copied into the output DACL, but set_posix_acl_entries_dacl() still
receives nt_num_aces and uses it to walk the existing ACE array during
dedup.

That makes the dedup walk scan past the copied ACE array and inspect
buffer tail that does not contain valid ACEs.

Split the two meanings currently carried by the NT ACE count. Pass the
number of copied NT ACEs to bound the dedup walk, and preserve the
original "input DACL had NT ACEs" state separately for the
Everyone/default ACL fallback.

This keeps the dedup walk aligned with the ACEs that are actually
present in the rebuilt DACL.

Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
Signed-off-by: Steve French <stfrench@microsoft.com>
(cherry picked from commit 58d97fcd0bf1aee694e244cc28635b9df95b543b)
Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
---
 fs/smb/server/smbacl.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/fs/smb/server/smbacl.c b/fs/smb/server/smbacl.c
index 5621c50a80571..f869639913088 100644
--- a/fs/smb/server/smbacl.c
+++ b/fs/smb/server/smbacl.c
@@ -595,7 +595,8 @@ static void parse_dacl(struct mnt_idmap *idmap,
 static void set_posix_acl_entries_dacl(struct mnt_idmap *idmap,
 				       struct smb_ace *pndace,
 				       struct smb_fattr *fattr, u16 *num_aces,
-				       u16 *size, u32 nt_aces_num)
+				       u16 *size, u16 existing_nt_aces,
+				       bool had_nt_aces)
 {
 	struct posix_acl_entry *pace;
 	struct smb_sid *sid;
@@ -627,14 +628,14 @@ static void set_posix_acl_entries_dacl(struct mnt_idmap *idmap,
 
 			gid = posix_acl_gid_translate(idmap, pace);
 			id_to_sid(gid, SIDUNIX_GROUP, sid);
-		} else if (pace->e_tag == ACL_OTHER && !nt_aces_num) {
+		} else if (pace->e_tag == ACL_OTHER && !had_nt_aces) {
 			smb_copy_sid(sid, &sid_everyone);
 		} else {
 			kfree(sid);
 			continue;
 		}
 		ntace = pndace;
-		for (j = 0; j < nt_aces_num; j++) {
+		for (j = 0; j < existing_nt_aces; j++) {
 			if (ntace->sid.sub_auth[ntace->sid.num_subauth - 1] ==
 					sid->sub_auth[sid->num_subauth - 1])
 				goto pass_same_sid;
@@ -678,7 +679,7 @@ static void set_posix_acl_entries_dacl(struct mnt_idmap *idmap,
 		kfree(sid);
 	}
 
-	if (nt_aces_num)
+	if (had_nt_aces)
 		return;
 
 posix_default_acl:
@@ -732,6 +733,7 @@ static void set_ntacl_dacl(struct mnt_idmap *idmap,
 {
 	struct smb_ace *ntace, *pndace;
 	u16 nt_num_aces = le16_to_cpu(nt_dacl->num_aces), num_aces = 0;
+	u16 copied_nt_aces;
 	unsigned short size = 0;
 	int i;
 
@@ -765,8 +767,10 @@ static void set_ntacl_dacl(struct mnt_idmap *idmap,
 		}
 	}
 
+	copied_nt_aces = num_aces;
 	set_posix_acl_entries_dacl(idmap, pndace, fattr,
-				   &num_aces, &size, nt_num_aces);
+				   &num_aces, &size, copied_nt_aces,
+				   nt_num_aces != 0);
 	pndacl->num_aces = cpu_to_le16(num_aces);
 	pndacl->size = cpu_to_le16(le16_to_cpu(pndacl->size) + size);
 }
@@ -784,7 +788,7 @@ static void set_mode_dacl(struct mnt_idmap *idmap,
 
 	if (fattr->cf_acls) {
 		set_posix_acl_entries_dacl(idmap, pndace, fattr,
-					   &num_aces, &size, num_aces);
+					   &num_aces, &size, num_aces, false);
 		goto out;
 	}
 
-- 
2.30.2


  parent reply	other threads:[~2026-07-29 19:02 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-29 13:55 FAILED: patch "[PATCH] ksmbd: restore DACL size on check_add_overflow() to avoid" failed to apply to 6.18-stable tree gregkh
2026-07-29 18:09 ` [PATCH 6.18.y 1/2] ksmbd: validate num_subauth when copying ACE in set_ntacl_dacl Wentao Guan
2026-07-29 18:09   ` [PATCH 6.18.y 2/2] ksmbd: restore DACL size on check_add_overflow() to avoid malformed ACL Wentao Guan
2026-07-29 18:25 ` [PATCH 6.18.y v2 1/3] ksmbd: validate num_subauth when copying ACE in set_ntacl_dacl Wentao Guan
2026-07-29 18:25   ` [PATCH 6.18.y v2 2/3] ksmbd: restore DACL size on check_add_overflow() to avoid malformed ACL Wentao Guan
2026-07-29 18:25   ` [PATCH 6.18.y v2 3/3] ksmbd: validate ACE size against SID sub-authorities Wentao Guan
2026-07-29 19:00 ` [PATCH 6.6.y && 6.12.y && 6.18.y && 7.1.y v3 0/4] Backport fixes for ksmbd Wentao Guan
2026-07-30  2:40   ` Sasha Levin
2026-07-29 19:00 ` [PATCH 6.6.y && 6.12.y && 6.18.y && 7.1.y v3 1/4] ksmbd: validate num_subauth when copying ACE in set_ntacl_dacl Wentao Guan
2026-07-29 19:00 ` [PATCH 6.6.y && 6.12.y && 6.18.y && 7.1.y v3 2/4] ksmbd: restore DACL size on check_add_overflow() to avoid malformed ACL Wentao Guan
2026-07-29 19:00 ` Wentao Guan [this message]
2026-07-29 19:00 ` [PATCH 6.6.y && 6.12.y && 6.18.y && 7.1.y v3 4/4] ksmbd: validate ACE size against SID sub-authorities Wentao Guan

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=20260729190023.46584-4-guanwentao@uniontech.com \
    --to=guanwentao@uniontech.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linkinjeon@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=stfrench@microsoft.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