Skip to content

Commit 482e59e

Browse files
committed
smb: client: validate dacloffset before building DACL pointers
jira VULN-188330 cve CVE-2026-46195 commit-author Michael Bommarito <michael.bommarito@gmail.com> commit f98b481 parse_sec_desc(), build_sec_desc(), and the chown path in id_mode_to_cifs_acl() all add the server-supplied dacloffset to pntsd before proving a DACL header fits inside the returned security descriptor. On 32-bit builds a malicious server can return dacloffset near U32_MAX, wrap the derived DACL pointer below end_of_acl, and then slip past the later pointer-based bounds checks. build_sec_desc() and id_mode_to_cifs_acl() can then dereference DACL fields from the wrapped pointer in the chmod/chown rewrite paths. Validate dacloffset numerically before building any DACL pointer and reuse the same helper at the three DACL entry points. Fixes: bc3e9dd ("cifs: Change SIDs in ACEs while transferring file ownership.") Cc: stable@vger.kernel.org Assisted-by: Claude:claude-opus-4-6 Signed-off-by: Michael Bommarito <michael.bommarito@gmail.com> Signed-off-by: Steve French <stfrench@microsoft.com> (cherry picked from commit f98b481) Signed-off-by: Marcin Wcisło <marcin.wcislo@conclusive.pl>
1 parent ea9d20a commit 482e59e

1 file changed

Lines changed: 32 additions & 3 deletions

File tree

fs/smb/client/cifsacl.c

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,6 +1265,17 @@ static int parse_sid(struct smb_sid *psid, char *end_of_acl)
12651265
return 0;
12661266
}
12671267

1268+
static bool dacl_offset_valid(unsigned int acl_len, __u32 dacloffset)
1269+
{
1270+
if (acl_len < sizeof(struct smb_acl))
1271+
return false;
1272+
1273+
if (dacloffset < sizeof(struct smb_ntsd))
1274+
return false;
1275+
1276+
return dacloffset <= acl_len - sizeof(struct smb_acl);
1277+
}
1278+
12681279

12691280
/* Convert CIFS ACL to POSIX form */
12701281
static int parse_sec_desc(struct cifs_sb_info *cifs_sb,
@@ -1285,7 +1296,6 @@ static int parse_sec_desc(struct cifs_sb_info *cifs_sb,
12851296
group_sid_ptr = (struct smb_sid *)((char *)pntsd +
12861297
le32_to_cpu(pntsd->gsidoffset));
12871298
dacloffset = le32_to_cpu(pntsd->dacloffset);
1288-
dacl_ptr = (struct smb_acl *)((char *)pntsd + dacloffset);
12891299
cifs_dbg(NOISY, "revision %d type 0x%x ooffset 0x%x goffset 0x%x sacloffset 0x%x dacloffset 0x%x\n",
12901300
pntsd->revision, pntsd->type, le32_to_cpu(pntsd->osidoffset),
12911301
le32_to_cpu(pntsd->gsidoffset),
@@ -1316,11 +1326,18 @@ static int parse_sec_desc(struct cifs_sb_info *cifs_sb,
13161326
return rc;
13171327
}
13181328

1319-
if (dacloffset)
1329+
if (dacloffset) {
1330+
if (!dacl_offset_valid(acl_len, dacloffset)) {
1331+
cifs_dbg(VFS, "Server returned illegal DACL offset\n");
1332+
return -EINVAL;
1333+
}
1334+
1335+
dacl_ptr = (struct smb_acl *)((char *)pntsd + dacloffset);
13201336
parse_dacl(dacl_ptr, end_of_acl, owner_sid_ptr,
13211337
group_sid_ptr, fattr, get_mode_from_special_sid);
1322-
else
1338+
} else {
13231339
cifs_dbg(FYI, "no ACL\n"); /* BB grant all or default perms? */
1340+
}
13241341

13251342
return rc;
13261343
}
@@ -1343,6 +1360,11 @@ static int build_sec_desc(struct smb_ntsd *pntsd, struct smb_ntsd *pnntsd,
13431360

13441361
dacloffset = le32_to_cpu(pntsd->dacloffset);
13451362
if (dacloffset) {
1363+
if (!dacl_offset_valid(secdesclen, dacloffset)) {
1364+
cifs_dbg(VFS, "Server returned illegal DACL offset\n");
1365+
return -EINVAL;
1366+
}
1367+
13461368
dacl_ptr = (struct smb_acl *)((char *)pntsd + dacloffset);
13471369
rc = validate_dacl(dacl_ptr, end_of_acl);
13481370
if (rc)
@@ -1718,6 +1740,12 @@ id_mode_to_cifs_acl(struct inode *inode, const char *path, __u64 *pnmode,
17181740
nsecdesclen = sizeof(struct smb_ntsd) + (sizeof(struct smb_sid) * 2);
17191741
dacloffset = le32_to_cpu(pntsd->dacloffset);
17201742
if (dacloffset) {
1743+
if (!dacl_offset_valid(secdesclen, dacloffset)) {
1744+
cifs_dbg(VFS, "Server returned illegal DACL offset\n");
1745+
rc = -EINVAL;
1746+
goto id_mode_to_cifs_acl_exit;
1747+
}
1748+
17211749
dacl_ptr = (struct smb_acl *)((char *)pntsd + dacloffset);
17221750
rc = validate_dacl(dacl_ptr, (char *)pntsd + secdesclen);
17231751
if (rc) {
@@ -1760,6 +1788,7 @@ id_mode_to_cifs_acl(struct inode *inode, const char *path, __u64 *pnmode,
17601788
rc = ops->set_acl(pnntsd, nsecdesclen, inode, path, aclflag);
17611789
cifs_dbg(NOISY, "set_cifs_acl rc: %d\n", rc);
17621790
}
1791+
id_mode_to_cifs_acl_exit:
17631792
cifs_put_tlink(tlink);
17641793

17651794
kfree(pnntsd);

0 commit comments

Comments
 (0)