ksmbd: port to vfs{g,u}id_t and associated helpers
Subsystems (2)
PATCH 1/1 ksmbd: port to vfs{g,u}id_t and associated helpers
A while ago we introduced a dedicated vfs{g,u}id_t type in commit 1e5267cd0895 ("mnt_idmapping: add vfs{g,u}id_t"). We already switched over a good part of the VFS. Ultimately we will remove all legacy idmapped mount helpers that operate only on k{g,u}id_t in favor of the new type safe helpers that operate on vfs{g,u}id_t.
--- fs/ksmbd/ndr.c | 8 ++++++-- fs/ksmbd/oplock.c | 8 ++++---- fs/ksmbd/smb2pdu.c | 7 +++++-- fs/ksmbd/smbacl.c | 6 ++++-- fs/ksmbd/smbacl.h | 12 ++++++------ 5 files changed, 25 insertions(+), 16 deletions(-)
fs/ksmbd/ndr.c +6 -2
@@ -345,6 +345,8 @@ int ndr_encode_posix_acl(struct ndr *n, {unsigned int ref_id =0x00020000 ;int ret; +vfsuid_t vfsuid; +vfsgid_t vfsgid; n->offset =0 ; n->length =1024 ;
@@ -372,10 +374,12 @@ int ndr_encode_posix_acl(struct ndr *n,if (ret)return ret; - ret =ndr_write_int64 (n,from_kuid (&init_user_ns,i_uid_into_mnt (user_ns, inode))); + vfsuid =i_uid_into_vfsuid (user_ns, inode); + ret =ndr_write_int64 (n,from_kuid (&init_user_ns,vfsuid_into_kuid (vfsuid)));if (ret)return ret; - ret =ndr_write_int64 (n,from_kgid (&init_user_ns,i_gid_into_mnt (user_ns, inode))); + vfsgid =i_gid_into_vfsgid (user_ns, inode); + ret =ndr_write_int64 (n,from_kgid (&init_user_ns,vfsgid_into_kgid (vfsgid)));if (ret)return ret; ret =ndr_write_int32 (n, inode->i_mode);
fs/ksmbd/oplock.c +4 -4
@@ -1609,6 +1609,8 @@ void create_posix_rsp_buf(char *cc, struct ksmbd_file *fp)struct create_posix_rsp *buf;struct inode *inode =file_inode (fp->filp);struct user_namespace *user_ns =file_mnt_user_ns (fp->filp); +vfsuid_t vfsuid =i_uid_into_vfsuid (user_ns, inode); +vfsgid_t vfsgid =i_gid_into_vfsgid (user_ns, inode); buf = (struct create_posix_rsp *)cc;memset (buf,0 ,sizeof (struct create_posix_rsp ));
@@ -1639,11 +1641,9 @@ void create_posix_rsp_buf(char *cc, struct ksmbd_file *fp) buf->nlink =cpu_to_le32 (inode->i_nlink); buf->reparse_tag =cpu_to_le32 (fp->volatile_id); buf->mode =cpu_to_le32 (inode->i_mode); -id_to_sid (from_kuid_munged (&init_user_ns, -i_uid_into_mnt (user_ns, inode)), +id_to_sid (from_kuid_munged (&init_user_ns,vfsuid_into_kuid (vfsuid)),SIDNFS_USER , (struct smb_sid *)&buf->SidBuffer[0 ]); -id_to_sid (from_kgid_munged (&init_user_ns, -i_gid_into_mnt (user_ns, inode)), +id_to_sid (from_kgid_munged (&init_user_ns,vfsgid_into_kgid (vfsgid)),SIDNFS_GROUP , (struct smb_sid *)&buf->SidBuffer[20 ]); }
fs/ksmbd/smb2pdu.c +5 -2
@@ -2477,8 +2477,11 @@ static void ksmbd_acls_fattr(struct smb_fattr *fattr,struct user_namespace *mnt_userns, struct inode *inode) { - fattr->cf_uid = i_uid_into_mnt(mnt_userns, inode); - fattr->cf_gid =i_gid_into_mnt (mnt_userns, inode); + vfsuid_t vfsuid = i_uid_into_vfsuid(mnt_userns, inode); +vfsgid_t vfsgid =i_gid_into_vfsgid (mnt_userns, inode); + + fattr->cf_uid =vfsuid_into_kuid (vfsuid); + fattr->cf_gid =vfsgid_into_kgid (vfsgid); fattr->cf_mode = inode->i_mode; fattr->cf_acls =NULL ; fattr->cf_dacls =NULL ;
fs/ksmbd/smbacl.c +4 -2
@@ -275,7 +275,8 @@ static int sid_to_id(struct user_namespace *user_ns,uid_t id; id =le32_to_cpu (psid->sub_auth[psid->num_subauth -1 ]); - uid =mapped_kuid_user (user_ns, &init_user_ns,KUIDT_INIT (id)); + uid =KUIDT_INIT (id); + uid =from_vfsuid (user_ns, &init_user_ns,VFSUIDT_INIT (uid));if (uid_valid (uid)) { fattr->cf_uid = uid; rc =0 ;
@@ -285,7 +286,8 @@ static int sid_to_id(struct user_namespace *user_ns,gid_t id; id =le32_to_cpu (psid->sub_auth[psid->num_subauth -1 ]); - gid =mapped_kgid_user (user_ns, &init_user_ns,KGIDT_INIT (id)); + gid =KGIDT_INIT (id); + gid =from_vfsgid (user_ns, &init_user_ns,VFSGIDT_INIT (gid));if (gid_valid (gid)) { fattr->cf_gid = gid; rc =0 ;
fs/ksmbd/smbacl.h +6 -6
@@ -214,25 +214,25 @@ void ksmbd_init_domain(u32 *sub_auth);static inline uid_t posix_acl_uid_translate (struct user_namespace *mnt_userns,struct posix_acl_entry *pace) { -kuid_t kuid; +vfsuid_t vfsuid;/* If this is an idmapped mount, apply the idmapping. */ - kuid =mapped_kuid_fs (mnt_userns, &init_user_ns, pace->e_uid); + vfsuid =make_vfsuid (mnt_userns, &init_user_ns, pace->e_uid);/* Translate the kuid into a userspace id ksmbd would see. */ -return from_kuid (&init_user_ns, kuid); +return from_kuid (&init_user_ns,vfsuid_into_kuid (vfsuid)); }static inline gid_t posix_acl_gid_translate (struct user_namespace *mnt_userns,struct posix_acl_entry *pace) { -kgid_t kgid; +vfsgid_t vfsgid;/* If this is an idmapped mount, apply the idmapping. */ - kgid =mapped_kgid_fs (mnt_userns, &init_user_ns, pace->e_gid); + vfsgid =make_vfsgid (mnt_userns, &init_user_ns, pace->e_gid);/* Translate the kgid into a userspace id ksmbd would see. */ -return from_kgid (&init_user_ns, kgid); +return from_kgid (&init_user_ns,vfsgid_into_kgid (vfsgid)); }#endif /* _SMBACL_H */
base-commit: 7e18e42e4b280c85b76967a9106a13ca61c16179
Signature · 1 line
2.34.1
2022-09-09 19:51 GMT+09:00, Christian Brauner <[email protected]>:
Quoted 6 lines
A while ago we introduced a dedicated vfs{g,u}id_t type in commit
1e5267cd0895("mnt_idmapping: add vfs{g,u}id_t"). We already switched over a good part of the VFS. Ultimately we will remove all legacy idmapped mount helpers that operate only on k{g,u}id_t in favor of the new type safe helpers that operate on vfs{g,u}id_t.
Quoted 8 lines
Cc Seth Forshee (Digital Ocean) <[email protected]>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]>Signed-off-by Christian Brauner (Microsoft) <[email protected]>
Thanks!