Skip to content

Commit 43205ca

Browse files
Christian Braunersmfrench
authored andcommitted
ksmbd: fix translation in ksmbd_acls_fattr()
When creating new filesystem objects ksmbd translates between k*ids and s*ids. For this it often uses struct smb_fattr and stashes the k*ids in cf_uid and cf_gid. Let cf_uid and cf_gid always contain the final information taking any potential idmapped mounts into account. When finally translation cf_*id into s*ids translate them into the user namespace of ksmbd since that is the relevant user namespace here. Cc: Steve French <[email protected]> Cc: Christoph Hellwig <[email protected]> Cc: Namjae Jeon <[email protected]> Cc: Hyunchul Lee <[email protected]> Cc: Sergey Senozhatsky <[email protected]> Cc: [email protected] Signed-off-by: Christian Brauner <[email protected]> Signed-off-by: Namjae Jeon <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent 3cdc20e commit 43205ca

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

fs/ksmbd/smb2pdu.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2381,10 +2381,12 @@ static int smb2_create_sd_buffer(struct ksmbd_work *work,
23812381
le32_to_cpu(sd_buf->ccontext.DataLength), true);
23822382
}
23832383

2384-
static void ksmbd_acls_fattr(struct smb_fattr *fattr, struct inode *inode)
2384+
static void ksmbd_acls_fattr(struct smb_fattr *fattr,
2385+
struct user_namespace *mnt_userns,
2386+
struct inode *inode)
23852387
{
2386-
fattr->cf_uid = inode->i_uid;
2387-
fattr->cf_gid = inode->i_gid;
2388+
fattr->cf_uid = i_uid_into_mnt(mnt_userns, inode);
2389+
fattr->cf_gid = i_gid_into_mnt(mnt_userns, inode);
23882390
fattr->cf_mode = inode->i_mode;
23892391
fattr->cf_acls = NULL;
23902392
fattr->cf_dacls = NULL;
@@ -2893,7 +2895,7 @@ int smb2_open(struct ksmbd_work *work)
28932895
struct smb_ntsd *pntsd;
28942896
int pntsd_size, ace_num = 0;
28952897

2896-
ksmbd_acls_fattr(&fattr, inode);
2898+
ksmbd_acls_fattr(&fattr, user_ns, inode);
28972899
if (fattr.cf_acls)
28982900
ace_num = fattr.cf_acls->a_count;
28992901
if (fattr.cf_dacls)
@@ -5006,7 +5008,7 @@ static int smb2_get_info_sec(struct ksmbd_work *work,
50065008

50075009
user_ns = file_mnt_user_ns(fp->filp);
50085010
inode = file_inode(fp->filp);
5009-
ksmbd_acls_fattr(&fattr, inode);
5011+
ksmbd_acls_fattr(&fattr, user_ns, inode);
50105012

50115013
if (test_share_config_flag(work->tcon->share_conf,
50125014
KSMBD_SHARE_FLAG_ACL_XATTR))

fs/ksmbd/smbacl.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ static void set_mode_dacl(struct user_namespace *user_ns,
723723
}
724724

725725
/* owner RID */
726-
uid = from_kuid(user_ns, fattr->cf_uid);
726+
uid = from_kuid(&init_user_ns, fattr->cf_uid);
727727
if (uid)
728728
sid = &server_conf.domain_sid;
729729
else
@@ -739,7 +739,7 @@ static void set_mode_dacl(struct user_namespace *user_ns,
739739
ace_size = fill_ace_for_sid(pace, &sid_unix_groups,
740740
ACCESS_ALLOWED, 0, fattr->cf_mode, 0070);
741741
pace->sid.sub_auth[pace->sid.num_subauth++] =
742-
cpu_to_le32(from_kgid(user_ns, fattr->cf_gid));
742+
cpu_to_le32(from_kgid(&init_user_ns, fattr->cf_gid));
743743
pace->size = cpu_to_le16(ace_size + 4);
744744
size += le16_to_cpu(pace->size);
745745
pace = (struct smb_ace *)((char *)pndace + size);
@@ -880,7 +880,7 @@ int build_sec_desc(struct user_namespace *user_ns,
880880
if (!nowner_sid_ptr)
881881
return -ENOMEM;
882882

883-
uid = from_kuid(user_ns, fattr->cf_uid);
883+
uid = from_kuid(&init_user_ns, fattr->cf_uid);
884884
if (!uid)
885885
sid_type = SIDUNIX_USER;
886886
id_to_sid(uid, sid_type, nowner_sid_ptr);
@@ -891,7 +891,7 @@ int build_sec_desc(struct user_namespace *user_ns,
891891
return -ENOMEM;
892892
}
893893

894-
gid = from_kgid(user_ns, fattr->cf_gid);
894+
gid = from_kgid(&init_user_ns, fattr->cf_gid);
895895
id_to_sid(gid, SIDUNIX_GROUP, ngroup_sid_ptr);
896896

897897
offset = sizeof(struct smb_ntsd);

0 commit comments

Comments
 (0)