FAILED: patch "[PATCH] smb: client: avoid using uninitialized SIDs in" failed to apply to 5.10-stable tree
Subsystems (2)
[email protected]
maintainerThe patch below does not apply to the 5.10-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.10.y
git checkout FETCH_HEAD
git cherry-pick -x da6e25842431982d5a53cf00d925b98c690f4467
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026091630-sherry-congenial-9b1f@gregkh' --subject-prefix 'PATCH 5.10.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From da6e25842431982d5a53cf00d925b98c690f4467 Mon Sep 17 00:00:00 2001
From: Paulo Alcantara <[email protected]>
Date: Sun, 6 Sep 2026 14:40:39 -0300
Subject: [PATCH] smb: client: avoid using uninitialized SIDs in
cifs_posix_to_fattr()
cifs_posix_to_fattr() ignores the return value of posix_info_parse(). When a malformed POSIX directory entry is encountered (e.g. invalid SID lengths from an untrusted server), posix_info_parse() returns -1 without populating the 'parsed' struct. The uninitialized stack memory in parsed.owner and parsed.group is then passed to sid_to_id(), which processes the garbage bytes and passes them to request_key() to construct a SID string, potentially leaking kernel stack contents to the userspace idmap daemon.
Fix this by checking the return value and skipping the SID-to-id mapping when parsing fails. The remaining fattr fields (timestamps, mode, etc.) are populated directly from the 'info' pointer so they are unaffected.
fs/smb/client/readdir.c +11 -5
@@ -244,8 +244,9 @@ cifs_posix_to_fattr(struct cifs_fattr *fattr, struct smb2_posix_info *info, {unsigned int sbflags =cifs_sb_flags (cifs_sb);struct smb2_posix_info_parsed parsed; +int rc; -posix_info_parse (info,NULL , &parsed); + rc =posix_info_parse (info,NULL , &parsed);memset (fattr,0 ,sizeof (*fattr)); fattr->cf_uniqueid =le64_to_cpu (info->Inode);
@@ -284,10 +285,15 @@ cifs_posix_to_fattr(struct cifs_fattr *fattr, struct smb2_posix_info *info, fattr->cf_uid = cifs_sb->ctx->linux_uid; fattr->cf_gid = cifs_sb->ctx->linux_gid; -if (!(sbflags &CIFS_MOUNT_OVERR_UID )) -sid_to_id (cifs_sb, &parsed.owner, fattr,SIDOWNER ); -if (!(sbflags &CIFS_MOUNT_OVERR_GID )) -sid_to_id (cifs_sb, &parsed.group, fattr,SIDGROUP ); +if (rc <0 ) { +cifs_dbg (VFS ,"%s: failed to parse SIDs: %d\n" , + __func__, rc); + }else { +if (!(sbflags &CIFS_MOUNT_OVERR_UID )) +sid_to_id (cifs_sb, &parsed.owner, fattr,SIDOWNER ); +if (!(sbflags &CIFS_MOUNT_OVERR_GID )) +sid_to_id (cifs_sb, &parsed.group, fattr,SIDGROUP ); + } }static void __dir_info_to_fattr (struct cifs_fattr *fattr,const void *info)
Sasha Levin
maintainerPATCH 1/2 smb: client: honor forceuid/forcegid when mapping SIDs to uid/gid
From: Paulo Alcantara <[email protected]>
[ Upstream commit 18a72975e9f35aadecc75b031f693f2d1f49308f ]
When the administrator mounts with forceuid or forcegid (uid=/gid= mount options), they expect all files to appear owned by the specified user/group. However, several code paths unconditionally called sid_to_id() to overwrite cf_uid/cf_gid with server-provided values, ignoring the administrator's explicit override:
- smb311_posix_info_to_fattr() (stat via POSIX extensions)
- cifs_posix_to_fattr() (readdir via POSIX extensions)
- parse_sec_desc() (CIFS ACL ownership mapping)
This allowed an untrusted server to dictate local file ownership even when the mount was configured to force specific uid/gid values.
Fix all three call sites to check CIFS_MOUNT_OVERR_UID and CIFS_MOUNT_OVERR_GID before calling sid_to_id(), following the same pattern already used by cifs_unix_basic_to_fattr() for unix extensions.
Backport notes for 5.10:
- Keep the client in fs/cifs and use the existing mnt_cifs_flags value.
- Drop the inode.c hunk: smb311_posix_info_to_fattr() already takes both IDs from mnt_uid/mnt_gid and does not map ownership SIDs in this tree.
- Apply the ACL checks to fs/cifs/cifsacl.c, retaining its existing parse_sid() validation and initializing ownership from the mount IDs.
- Alias ctx[0].linux_uid/linux_gid and mnt_uid/mnt_gid through an anonymous union. The aliases share the existing storage, require no allocation or initialization, and preserve updates through either spelling. This is only an ownership compatibility view, not a new filesystem context. Keeping the upstream ownership assignments in cifs_posix_to_fattr() lets the target SID-parsing fix cherry-pick without the adjacent-line conflict caused by replacing those assignments with the older field names. Preserve the existing file-type/revalidation logic.
[ sashal: Reduced backport -- upstream 18a72975e9f35 touches 3 file(s), this
backport carries 3. Not backported here:
fs/smb/client/cifsacl.c
fs/smb/client/inode.c
fs/smb/client/readdir.c
This note is generated from the file lists only; see the resolution record for the reasoning. ]
Stable-dep-of: da6e25842431 ("smb: client: avoid using uninitialized SIDs in cifs_posix_to_fattr()")
--- fs/cifs/cifs_fs_sb.h | 13 +++++++++++-- fs/cifs/cifsacl.c | 29 ++++++++++++++++++----------- fs/cifs/readdir.c | 9 +++++++-- 3 files changed, 36 insertions(+), 15 deletions(-)
fs/cifs/cifs_fs_sb.h +11 -2
@@ -66,8 +66,17 @@ struct cifs_sb_info {unsigned int wsize;unsigned long actimeo;/* attribute cache timeout (jiffies) */ atomic_t active; -kuid_t mnt_uid; -kgid_t mnt_gid; +/* Share mount ownership with the names used by newer SID mapping code. */ +union { +struct { +kuid_t mnt_uid; +kgid_t mnt_gid; + }; +struct { +kuid_t linux_uid; +kgid_t linux_gid; + } ctx[1 ]; + };kuid_t mnt_backupuid;kgid_t mnt_backupgid;umode_t mnt_file_mode;
fs/cifs/cifsacl.c +18 -11
@@ -947,6 +947,7 @@ static int parse_sec_desc(struct cifs_sb_info *cifs_sb, {int rc =0 ;struct cifs_sid *owner_sid_ptr, *group_sid_ptr; +unsigned int sbflags = cifs_sb->mnt_cifs_flags;struct cifs_acl *dacl_ptr;/* no need for SACL ptr */ char *end_of_acl = ((char *)pntsd) + acl_len;__u32 dacloffset;
@@ -964,17 +965,21 @@ static int parse_sec_desc(struct cifs_sb_info *cifs_sb, pntsd->revision, pntsd->type,le32_to_cpu (pntsd->osidoffset),le32_to_cpu (pntsd->gsidoffset), le32_to_cpu(pntsd->sacloffset), dacloffset); -/* cifs_dump_mem("owner_sid: ", owner_sid_ptr, 64); */ + fattr->cf_uid = cifs_sb->mnt_uid; + fattr->cf_gid = cifs_sb->mnt_gid; + rc =parse_sid (owner_sid_ptr, end_of_acl);if (rc) {cifs_dbg (FYI ,"%s: Error %d parsing Owner SID\n" , __func__, rc);return rc; } - rc =sid_to_id (cifs_sb, owner_sid_ptr, fattr,SIDOWNER ); -if (rc) { -cifs_dbg (FYI ,"%s: Error %d mapping Owner SID to uid\n" , - __func__, rc); -return rc; +if (!(sbflags &CIFS_MOUNT_OVERR_UID )) { + rc =sid_to_id (cifs_sb, owner_sid_ptr, fattr,SIDOWNER ); +if (rc) { +cifs_dbg (FYI ,"%s: Error %d mapping Owner SID to uid\n" , + __func__, rc); +return rc; + } } rc =parse_sid (group_sid_ptr, end_of_acl);
@@ -983,11 +988,13 @@ static int parse_sec_desc(struct cifs_sb_info *cifs_sb, __func__, rc);return rc; } - rc =sid_to_id (cifs_sb, group_sid_ptr, fattr,SIDGROUP ); -if (rc) { -cifs_dbg (FYI ,"%s: Error %d mapping Group SID to gid\n" , - __func__, rc); -return rc; +if (!(sbflags &CIFS_MOUNT_OVERR_GID )) { + rc =sid_to_id (cifs_sb, group_sid_ptr, fattr,SIDGROUP ); +if (rc) { +cifs_dbg (FYI ,"%s: Error %d mapping Group SID to gid\n" , + __func__, rc); +return rc; + } }if (dacloffset)
fs/cifs/readdir.c +7 -2
@@ -246,6 +246,7 @@ static void cifs_posix_to_fattr(struct cifs_fattr *fattr, struct smb2_posix_info *info, struct cifs_sb_info *cifs_sb) { + unsigned int sbflags = cifs_sb->mnt_cifs_flags;struct smb2_posix_info_parsed parsed;posix_info_parse (info,NULL , &parsed);
@@ -290,8 +291,12 @@ cifs_posix_to_fattr(struct cifs_fattr *fattr, struct smb2_posix_info *info,if (reparse_file_needs_reval (fattr)) fattr->cf_flags |=CIFS_FATTR_NEED_REVAL ; -sid_to_id (cifs_sb, &parsed.owner, fattr,SIDOWNER ); -sid_to_id (cifs_sb, &parsed.group, fattr,SIDGROUP ); + fattr->cf_uid = cifs_sb->ctx->linux_uid; + fattr->cf_gid = cifs_sb->ctx->linux_gid; +if (!(sbflags &CIFS_MOUNT_OVERR_UID )) +sid_to_id (cifs_sb, &parsed.owner, fattr,SIDOWNER ); +if (!(sbflags &CIFS_MOUNT_OVERR_GID )) +sid_to_id (cifs_sb, &parsed.group, fattr,SIDGROUP ); }static void __dir_info_to_fattr (struct cifs_fattr *fattr,const void *info)
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/2 smb: client: avoid using uninitialized SIDs in cifs_posix_to_fattr()
From: Paulo Alcantara <[email protected]>
[ Upstream commit da6e25842431982d5a53cf00d925b98c690f4467 ]
cifs_posix_to_fattr() ignores the return value of posix_info_parse(). When a malformed POSIX directory entry is encountered (e.g. invalid SID lengths from an untrusted server), posix_info_parse() returns -1 without populating the 'parsed' struct. The uninitialized stack memory in parsed.owner and parsed.group is then passed to sid_to_id(), which processes the garbage bytes and passes them to request_key() to construct a SID string, potentially leaking kernel stack contents to the userspace idmap daemon.
Fix this by checking the return value and skipping the SID-to-id mapping when parsing fails. The remaining fattr fields (timestamps, mode, etc.) are populated directly from the 'info' pointer so they are unaffected.
--- fs/cifs/readdir.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)
fs/cifs/readdir.c +11 -5
@@ -248,8 +248,9 @@ cifs_posix_to_fattr(struct cifs_fattr *fattr, struct smb2_posix_info *info, {unsigned int sbflags = cifs_sb->mnt_cifs_flags;struct smb2_posix_info_parsed parsed; +int rc; -posix_info_parse (info,NULL , &parsed); + rc =posix_info_parse (info,NULL , &parsed);memset (fattr,0 ,sizeof (*fattr)); fattr->cf_uniqueid =le64_to_cpu (info->Inode);
@@ -293,10 +294,15 @@ cifs_posix_to_fattr(struct cifs_fattr *fattr, struct smb2_posix_info *info, fattr->cf_uid = cifs_sb->ctx->linux_uid; fattr->cf_gid = cifs_sb->ctx->linux_gid; -if (!(sbflags &CIFS_MOUNT_OVERR_UID )) -sid_to_id (cifs_sb, &parsed.owner, fattr,SIDOWNER ); -if (!(sbflags &CIFS_MOUNT_OVERR_GID )) -sid_to_id (cifs_sb, &parsed.group, fattr,SIDGROUP ); +if (rc <0 ) { +cifs_dbg (VFS ,"%s: failed to parse SIDs: %d\n" , + __func__, rc); + }else { +if (!(sbflags &CIFS_MOUNT_OVERR_UID )) +sid_to_id (cifs_sb, &parsed.owner, fattr,SIDOWNER ); +if (!(sbflags &CIFS_MOUNT_OVERR_GID )) +sid_to_id (cifs_sb, &parsed.group, fattr,SIDGROUP ); + } }static void __dir_info_to_fattr (struct cifs_fattr *fattr,const void *info)
Signature · 1 line
2.53.0