Skip to content

Commit 0e844ef

Browse files
Christian Braunersmfrench
authored andcommitted
ksmbd: fix translation in acl entries
The ksmbd server performs translation of posix acls to smb acls. Currently the translation is wrong since the idmapping of the mount is used to map the ids into raw userspace ids but what is relevant is the user namespace of ksmbd itself. The user namespace of ksmbd itself which is the initial user namespace. The operation is similar to asking "What *ids would a userspace process see given that k*id in the relevant user namespace?". Before the final translation we need to apply the idmapping of the mount in case any is used. Add two simple helpers for ksmbd. 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 43205ca commit 0e844ef

File tree

3 files changed

+33
-10
lines changed

3 files changed

+33
-10
lines changed

fs/ksmbd/smbacl.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -587,14 +587,14 @@ static void set_posix_acl_entries_dacl(struct user_namespace *user_ns,
587587
uid_t uid;
588588
unsigned int sid_type = SIDOWNER;
589589

590-
uid = from_kuid(user_ns, pace->e_uid);
590+
uid = posix_acl_uid_translate(user_ns, pace);
591591
if (!uid)
592592
sid_type = SIDUNIX_USER;
593593
id_to_sid(uid, sid_type, sid);
594594
} else if (pace->e_tag == ACL_GROUP) {
595595
gid_t gid;
596596

597-
gid = from_kgid(user_ns, pace->e_gid);
597+
gid = posix_acl_gid_translate(user_ns, pace);
598598
id_to_sid(gid, SIDUNIX_GROUP, sid);
599599
} else if (pace->e_tag == ACL_OTHER && !nt_aces_num) {
600600
smb_copy_sid(sid, &sid_everyone);
@@ -653,12 +653,12 @@ static void set_posix_acl_entries_dacl(struct user_namespace *user_ns,
653653
if (pace->e_tag == ACL_USER) {
654654
uid_t uid;
655655

656-
uid = from_kuid(user_ns, pace->e_uid);
656+
uid = posix_acl_uid_translate(user_ns, pace);
657657
id_to_sid(uid, SIDCREATOR_OWNER, sid);
658658
} else if (pace->e_tag == ACL_GROUP) {
659659
gid_t gid;
660660

661-
gid = from_kgid(user_ns, pace->e_gid);
661+
gid = posix_acl_gid_translate(user_ns, pace);
662662
id_to_sid(gid, SIDCREATOR_GROUP, sid);
663663
} else {
664664
kfree(sid);
@@ -1234,11 +1234,9 @@ int smb_check_perm_dacl(struct ksmbd_conn *conn, struct path *path,
12341234
pa_entry = posix_acls->a_entries;
12351235
for (i = 0; i < posix_acls->a_count; i++, pa_entry++) {
12361236
if (pa_entry->e_tag == ACL_USER)
1237-
id = from_kuid(user_ns,
1238-
pa_entry->e_uid);
1237+
id = posix_acl_uid_translate(user_ns, pa_entry);
12391238
else if (pa_entry->e_tag == ACL_GROUP)
1240-
id = from_kgid(user_ns,
1241-
pa_entry->e_gid);
1239+
id = posix_acl_gid_translate(user_ns, pa_entry);
12421240
else
12431241
continue;
12441242

fs/ksmbd/smbacl.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,4 +209,29 @@ int set_info_sec(struct ksmbd_conn *conn, struct ksmbd_tree_connect *tcon,
209209
bool type_check);
210210
void id_to_sid(unsigned int cid, uint sidtype, struct smb_sid *ssid);
211211
void ksmbd_init_domain(u32 *sub_auth);
212+
213+
static inline uid_t posix_acl_uid_translate(struct user_namespace *mnt_userns,
214+
struct posix_acl_entry *pace)
215+
{
216+
kuid_t kuid;
217+
218+
/* If this is an idmapped mount, apply the idmapping. */
219+
kuid = kuid_into_mnt(mnt_userns, pace->e_uid);
220+
221+
/* Translate the kuid into a userspace id ksmbd would see. */
222+
return from_kuid(&init_user_ns, kuid);
223+
}
224+
225+
static inline gid_t posix_acl_gid_translate(struct user_namespace *mnt_userns,
226+
struct posix_acl_entry *pace)
227+
{
228+
kgid_t kgid;
229+
230+
/* If this is an idmapped mount, apply the idmapping. */
231+
kgid = kgid_into_mnt(mnt_userns, pace->e_gid);
232+
233+
/* Translate the kgid into a userspace id ksmbd would see. */
234+
return from_kgid(&init_user_ns, kgid);
235+
}
236+
212237
#endif /* _SMBACL_H */

fs/ksmbd/vfs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1390,14 +1390,14 @@ static struct xattr_smb_acl *ksmbd_vfs_make_xattr_posix_acl(struct user_namespac
13901390
switch (pa_entry->e_tag) {
13911391
case ACL_USER:
13921392
xa_entry->type = SMB_ACL_USER;
1393-
xa_entry->uid = from_kuid(user_ns, pa_entry->e_uid);
1393+
xa_entry->uid = posix_acl_uid_translate(user_ns, pa_entry);
13941394
break;
13951395
case ACL_USER_OBJ:
13961396
xa_entry->type = SMB_ACL_USER_OBJ;
13971397
break;
13981398
case ACL_GROUP:
13991399
xa_entry->type = SMB_ACL_GROUP;
1400-
xa_entry->gid = from_kgid(user_ns, pa_entry->e_gid);
1400+
xa_entry->gid = posix_acl_gid_translate(user_ns, pa_entry);
14011401
break;
14021402
case ACL_GROUP_OBJ:
14031403
xa_entry->type = SMB_ACL_GROUP_OBJ;

0 commit comments

Comments
 (0)