]> git.hungrycats.org Git - linux/commitdiff
ksmbd: fix invalid pointer dereference when get_inode_acl() fails
authorHenry Hu <huhai@kylinos.cn>
Tue, 3 Nov 2026 17:03:40 +0000 (12:03 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 6 Nov 2026 17:10:53 +0000 (12:10 -0500)
[ Upstream commit 19d180c7baab7126af5848ed87d5f7b5add0cef2 ]

When get_inode_acl() fails, it returns an ERR_PTR(), but
ksmbd_acls_fattr() stored that pointer in smb_fattr without
checking for errors. Later callers then passed the error pointer
to security descriptor helpers or posix_acl_release(), resulting
in an invalid pointer dereference.

This was reproduced on an XFS-backed share when xfs_get_acl()
returned ERR_PTR(-ENOMEM). Querying the SMB ACL from a CIFS client
triggered the crash:

  BUG: unable to handle page fault for address: fffffffffffffff8
  RIP: smb_acl_sec_desc_scratch_len+0x58/0x90 [ksmbd]
  Call Trace:
   smb2_query_info+0x40d/0x17c0 [ksmbd]
   handle_ksmbd_work+0x1ca/0x770 [ksmbd]

Fix this by checking the return values from get_inode_acl() in
ksmbd_acls_fattr(). Treat -EOPNOTSUPP as indicating that no ACL is
available, and propagate all other errors to the callers. Update
smb2_open() and smb2_get_info_sec() to handle these errors.

Cc: stable@vger.kernel.org
Fixes: e2f34481b24d ("cifsd: add server-side procedures for SMB3")
Assisted-by: Codex:gpt-5.6-sol
Reviewed-by: ChenXiaoSong <chenxiaosong@kylinos.cn>
Signed-off-by: Henry Hu <huhai@kylinos.cn>
Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
[ sashal: Retained the non-const struct mnt_idmap * parameter in ksmbd_acls_fattr() to match the existing UID/GID mapping helpers. ]
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/smb/server/smb2pdu.c

index fa1c8f613ddd8af99d6da6bc654bd99ce9e57acb..ce33c2475325e85475aee7c9b149ad30d2a2adfc 100644 (file)
@@ -3694,10 +3694,11 @@ static int smb2_create_sd_buffer(struct ksmbd_work *work,
                            le32_to_cpu(sd_buf->ccontext.DataLength), true, false);
 }
 
-static void ksmbd_acls_fattr(struct smb_fattr *fattr,
-                            struct mnt_idmap *idmap,
-                            struct inode *inode)
+static int ksmbd_acls_fattr(struct smb_fattr *fattr,
+                           struct mnt_idmap *idmap,
+                           struct inode *inode)
 {
+       struct posix_acl *acl;
        vfsuid_t vfsuid = i_uid_into_vfsuid(idmap, inode);
        vfsgid_t vfsgid = i_gid_into_vfsgid(idmap, inode);
 
@@ -3708,10 +3709,28 @@ static void ksmbd_acls_fattr(struct smb_fattr *fattr,
        fattr->cf_dacls = NULL;
 
        if (IS_ENABLED(CONFIG_FS_POSIX_ACL)) {
-               fattr->cf_acls = get_inode_acl(inode, ACL_TYPE_ACCESS);
-               if (S_ISDIR(inode->i_mode))
-                       fattr->cf_dacls = get_inode_acl(inode, ACL_TYPE_DEFAULT);
+               acl = get_inode_acl(inode, ACL_TYPE_ACCESS);
+               if (IS_ERR(acl)) {
+                       if (acl != ERR_PTR(-EOPNOTSUPP))
+                               return PTR_ERR(acl);
+                       acl = NULL;
+               }
+               fattr->cf_acls = acl;
+
+               if (S_ISDIR(inode->i_mode)) {
+                       acl = get_inode_acl(inode, ACL_TYPE_DEFAULT);
+                       if (IS_ERR(acl)) {
+                               if (acl != ERR_PTR(-EOPNOTSUPP)) {
+                                       posix_acl_release(fattr->cf_acls);
+                                       return PTR_ERR(acl);
+                               }
+                               acl = NULL;
+                       }
+                       fattr->cf_dacls = acl;
+               }
        }
+
+       return 0;
 }
 
 enum {
@@ -4931,7 +4950,10 @@ resolve_path:
                                        int pntsd_size;
                                        size_t scratch_len;
 
-                                       ksmbd_acls_fattr(&fattr, idmap, inode);
+                                       rc = ksmbd_acls_fattr(&fattr, idmap, inode);
+                                       if (rc)
+                                               goto err_out;
+
                                        scratch_len = smb_acl_sec_desc_scratch_len(&fattr,
                                                        NULL, 0,
                                                        OWNER_SECINFO | GROUP_SECINFO |
@@ -7793,7 +7815,11 @@ static int smb2_get_info_sec(struct ksmbd_work *work,
 
        idmap = file_mnt_idmap(fp->filp);
        inode = file_inode(fp->filp);
-       ksmbd_acls_fattr(&fattr, idmap, inode);
+       rc = ksmbd_acls_fattr(&fattr, idmap, inode);
+       if (rc) {
+               ksmbd_fd_put(work, fp);
+               return rc;
+       }
 
        if (test_share_config_flag(work->tcon->share_conf,
                                   KSMBD_SHARE_FLAG_ACL_XATTR))