]> git.baikalelectronics.ru Git - kernel.git/commitdiff
ksmbd: port to vfs{g,u}id_t and associated helpers
authorChristian Brauner <brauner@kernel.org>
Fri, 9 Sep 2022 10:51:19 +0000 (12:51 +0200)
committerSteve French <stfrench@microsoft.com>
Wed, 5 Oct 2022 06:15:37 +0000 (01:15 -0500)
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.

Cc: Seth Forshee (Digital Ocean) <sforshee@kernel.org>
Cc: Steve French <sfrench@samba.org>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Namjae Jeon <linkinjeon@kernel.org>
Cc: Hyunchul Lee <hyc.lee@gmail.com>
Cc: Sergey Senozhatsky <senozhatsky@chromium.org>
Cc: linux-cifs@vger.kernel.org
Signed-off-by: Christian Brauner (Microsoft) <brauner@kernel.org>
Acked-by: Namjae Jeon <linkinjeon@kernel.org>
Signed-off-by: Steve French <stfrench@microsoft.com>
fs/ksmbd/ndr.c
fs/ksmbd/oplock.c
fs/ksmbd/smb2pdu.c
fs/ksmbd/smbacl.c
fs/ksmbd/smbacl.h

index 5052be9261d91efb810757256efb913eb97ebc7b..0ae8d08d85a87da22995083e87ebada3118db7d3 100644 (file)
@@ -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);
index 9046cff4374b2c7505a20c11d1626df36e34ae58..2e56dac1fa6eecaff479024f1effa9ad54cde2f0 100644 (file)
@@ -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]);
 }
 
index 634e21bba770213e2ab9cf053914e5b052081f79..c505399483240be957eecdb15440c8bcd7e1146b 100644 (file)
@@ -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;
index 85c4de640ed358c6770385646cda276eb886c5c0..b05ff9b146b550881b3bcd427351edcaca34f996 100644 (file)
@@ -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;
index f06abf247445f5d9634e8bf7271be2914bdfbe20..618f2e0236b31315bcf07c27166dfdc2bf449401 100644 (file)
@@ -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 */