diff options
| author | Hyunchul Lee <hyc.lee@gmail.com> | 2021-06-30 18:25:53 +0900 |
|---|---|---|
| committer | Namjae Jeon <namjae.jeon@samsung.com> | 2021-07-02 16:27:10 +0900 |
| commit | af34983e831587472333e47c86a350a2360c6093 (patch) | |
| tree | 0db387e95eb0372e4e6ebb6304671603d0c9690a | |
| parent | ef24c962d0f29036041a007a75bcd0f50233c83e (diff) | |
| download | linux-af34983e831587472333e47c86a350a2360c6093.tar.gz linux-af34983e831587472333e47c86a350a2360c6093.tar.bz2 linux-af34983e831587472333e47c86a350a2360c6093.zip | |
ksmbd: add user namespace support
For user namespace support, call vfs functions
with struct user_namespace got from struct path.
This patch have been tested mannually as below.
Create an id-mapped mount using the mount-idmapped utility
(https://github.com/brauner/mount-idmapped).
$ mount-idmapped --map-mount b:1003:1002:1 /home/foo <EXPORT DIR>/foo
(the user, "foo" is 1003, and the user "bar" is 1002).
And mount the export directory using cifs with the user, "bar".
succeed to create/delete/stat/read/write files and directory in
the <EXPORT DIR>/foo. But fail with a bind mount for /home/foo.
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Hyunchul Lee <hyc.lee@gmail.com>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
| -rw-r--r-- | fs/ksmbd/ndr.c | 8 | ||||
| -rw-r--r-- | fs/ksmbd/ndr.h | 4 | ||||
| -rw-r--r-- | fs/ksmbd/oplock.c | 4 | ||||
| -rw-r--r-- | fs/ksmbd/smb2pdu.c | 113 | ||||
| -rw-r--r-- | fs/ksmbd/smb_common.c | 5 | ||||
| -rw-r--r-- | fs/ksmbd/smb_common.h | 1 | ||||
| -rw-r--r-- | fs/ksmbd/smbacl.c | 99 | ||||
| -rw-r--r-- | fs/ksmbd/smbacl.h | 10 | ||||
| -rw-r--r-- | fs/ksmbd/vfs.c | 172 | ||||
| -rw-r--r-- | fs/ksmbd/vfs.h | 51 | ||||
| -rw-r--r-- | fs/ksmbd/vfs_cache.c | 5 |
11 files changed, 294 insertions, 178 deletions
diff --git a/fs/ksmbd/ndr.c b/fs/ksmbd/ndr.c index bcf13a2aa9d4..cf0df78259c9 100644 --- a/fs/ksmbd/ndr.c +++ b/fs/ksmbd/ndr.c @@ -222,7 +222,9 @@ static int ndr_encode_posix_acl_entry(struct ndr *n, struct xattr_smb_acl *acl) return 0; } -int ndr_encode_posix_acl(struct ndr *n, struct inode *inode, +int ndr_encode_posix_acl(struct ndr *n, + struct user_namespace *user_ns, + struct inode *inode, struct xattr_smb_acl *acl, struct xattr_smb_acl *def_acl) { @@ -250,8 +252,8 @@ int ndr_encode_posix_acl(struct ndr *n, struct inode *inode, ndr_write_int32(n, 0); } - ndr_write_int64(n, from_kuid(&init_user_ns, inode->i_uid)); - ndr_write_int64(n, from_kgid(&init_user_ns, inode->i_gid)); + ndr_write_int64(n, from_kuid(user_ns, inode->i_uid)); + ndr_write_int64(n, from_kgid(user_ns, inode->i_gid)); ndr_write_int32(n, inode->i_mode); if (acl) { diff --git a/fs/ksmbd/ndr.h b/fs/ksmbd/ndr.h index 77b2d1ac93a0..60ca265d1bb0 100644 --- a/fs/ksmbd/ndr.h +++ b/fs/ksmbd/ndr.h @@ -14,8 +14,8 @@ struct ndr { int ndr_encode_dos_attr(struct ndr *n, struct xattr_dos_attrib *da); int ndr_decode_dos_attr(struct ndr *n, struct xattr_dos_attrib *da); -int ndr_encode_posix_acl(struct ndr *n, struct inode *inode, - struct xattr_smb_acl *acl, +int ndr_encode_posix_acl(struct ndr *n, struct user_namespace *user_ns, + struct inode *inode, struct xattr_smb_acl *acl, struct xattr_smb_acl *def_acl); int ndr_encode_v4_ntacl(struct ndr *n, struct xattr_ntacl *acl); int ndr_encode_v3_ntacl(struct ndr *n, struct xattr_ntacl *acl); diff --git a/fs/ksmbd/oplock.c b/fs/ksmbd/oplock.c index a9f171ccf770..5484b5bf75b0 100644 --- a/fs/ksmbd/oplock.c +++ b/fs/ksmbd/oplock.c @@ -1612,9 +1612,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(&init_user_ns, inode->i_uid), + id_to_sid(from_kuid(file_mnt_user_ns(fp->filp), inode->i_uid), SIDNFS_USER, (struct smb_sid *)&buf->SidBuffer[0]); - id_to_sid(from_kgid(&init_user_ns, inode->i_gid), + id_to_sid(from_kgid(file_mnt_user_ns(fp->filp), inode->i_gid), SIDNFS_GROUP, (struct smb_sid *)&buf->SidBuffer[20]); } diff --git a/fs/ksmbd/smb2pdu.c b/fs/ksmbd/smb2pdu.c index d79ea3eb57a7..dda90812feef 100644 --- a/fs/ksmbd/smb2pdu.c +++ b/fs/ksmbd/smb2pdu.c @@ -2081,14 +2081,16 @@ static int smb2_set_ea(struct smb2_ea_info *eabuf, struct path *path) value = (char *)&eabuf->name + eabuf->EaNameLength + 1; if (!eabuf->EaValueLength) { - rc = ksmbd_vfs_casexattr_len(path->dentry, + rc = ksmbd_vfs_casexattr_len(mnt_user_ns(path->mnt), + path->dentry, attr_name, XATTR_USER_PREFIX_LEN + eabuf->EaNameLength); /* delete the EA only when it exits */ if (rc > 0) { - rc = ksmbd_vfs_remove_xattr(path->dentry, + rc = ksmbd_vfs_remove_xattr(mnt_user_ns(path->mnt), + path->dentry, attr_name); if (rc < 0) { @@ -2102,7 +2104,8 @@ static int smb2_set_ea(struct smb2_ea_info *eabuf, struct path *path) /* if the EA doesn't exist, just do nothing. */ rc = 0; } else { - rc = ksmbd_vfs_setxattr(path->dentry, attr_name, value, + rc = ksmbd_vfs_setxattr(mnt_user_ns(path->mnt), + path->dentry, attr_name, value, le16_to_cpu(eabuf->EaValueLength), 0); if (rc < 0) { ksmbd_debug(SMB, @@ -2155,7 +2158,8 @@ static noinline int smb2_set_stream_name_xattr(struct path *path, fp->stream.size = xattr_stream_size; /* Check if there is stream prefix in xattr space */ - rc = ksmbd_vfs_casexattr_len(path->dentry, + rc = ksmbd_vfs_casexattr_len(mnt_user_ns(path->mnt), + path->dentry, xattr_stream_name, xattr_stream_size); if (rc >= 0) @@ -2166,7 +2170,8 @@ static noinline int smb2_set_stream_name_xattr(struct path *path, return -EBADF; } - rc = ksmbd_vfs_setxattr(path->dentry, xattr_stream_name, NULL, 0, 0); + rc = ksmbd_vfs_setxattr(mnt_user_ns(path->mnt), + path->dentry, xattr_stream_name, NULL, 0, 0); if (rc < 0) pr_err("Failed to store XATTR stream name :%d\n", rc); return 0; @@ -2196,7 +2201,8 @@ static int smb2_remove_smb_xattrs(struct path *path) strncmp(&name[XATTR_USER_PREFIX_LEN], STREAM_PREFIX, STREAM_PREFIX_LEN)) continue; - err = ksmbd_vfs_remove_xattr(path->dentry, name); + err = ksmbd_vfs_remove_xattr(mnt_user_ns(path->mnt), + path->dentry, name); if (err) ksmbd_debug(SMB, "remove xattr failed : %s\n", name); } @@ -2240,7 +2246,8 @@ static void smb2_new_xattrs(struct ksmbd_tree_connect *tcon, struct path *path, da.flags = XATTR_DOSINFO_ATTRIB | XATTR_DOSINFO_CREATE_TIME | XATTR_DOSINFO_ITIME; - rc = ksmbd_vfs_set_dos_attrib_xattr(path->dentry, &da); + rc = ksmbd_vfs_set_dos_attrib_xattr(mnt_user_ns(path->mnt), + path->dentry, &da); if (rc) ksmbd_debug(SMB, "failed to store file attribute into xattr\n"); } @@ -2258,7 +2265,8 @@ static void smb2_update_xattrs(struct ksmbd_tree_connect *tcon, KSMBD_SHARE_FLAG_STORE_DOS_ATTRS)) return; - rc = ksmbd_vfs_get_dos_attrib_xattr(path->dentry, &da); + rc = ksmbd_vfs_get_dos_attrib_xattr(mnt_user_ns(path->mnt), + path->dentry, &da); if (rc > 0) { fp->f_ci->m_fattr = cpu_to_le32(da.attr); fp->create_time = da.create_time; @@ -2634,7 +2642,7 @@ int smb2_open(struct ksmbd_work *work) rc = 0; } else { file_present = true; - generic_fillattr(&init_user_ns, d_inode(path.dentry), &stat); + generic_fillattr(mnt_user_ns(path.mnt), d_inode(path.dentry), &stat); } if (stream_name) { if (req->CreateOptions & FILE_DIRECTORY_FILE_LE) { @@ -2695,7 +2703,8 @@ int smb2_open(struct ksmbd_work *work) if (!file_present) { daccess = cpu_to_le32(GENERIC_ALL_FLAGS); } else { - rc = ksmbd_vfs_query_maximal_access(path.dentry, + rc = ksmbd_vfs_query_maximal_access(mnt_user_ns(path.mnt), + path.dentry, &daccess); if (rc) goto err_out; @@ -2738,7 +2747,7 @@ int smb2_open(struct ksmbd_work *work) * is already granted. */ if (daccess & ~(FILE_READ_ATTRIBUTES_LE | FILE_READ_CONTROL_LE)) { - rc = inode_permission(&init_user_ns, + rc = inode_permission(mnt_user_ns(path.mnt), d_inode(path.dentry), may_flags); if (rc) @@ -2746,7 +2755,8 @@ int smb2_open(struct ksmbd_work *work) if ((daccess & FILE_DELETE_LE) || (req->CreateOptions & FILE_DELETE_ON_CLOSE_LE)) { - rc = ksmbd_vfs_may_delete(path.dentry); + rc = ksmbd_vfs_may_delete(mnt_user_ns(path.mnt), + path.dentry); if (rc) goto err_out; } @@ -2809,7 +2819,9 @@ int smb2_open(struct ksmbd_work *work) int posix_acl_rc; struct inode *inode = d_inode(path.dentry); - posix_acl_rc = ksmbd_vfs_inherit_posix_acl(inode, d_inode(path.dentry->d_parent)); + posix_acl_rc = ksmbd_vfs_inherit_posix_acl(mnt_user_ns(path.mnt), + inode, + d_inode(path.dentry->d_parent)); if (posix_acl_rc) ksmbd_debug(SMB, "inherit posix acl failed : %d\n", posix_acl_rc); @@ -2823,7 +2835,8 @@ int smb2_open(struct ksmbd_work *work) rc = smb2_create_sd_buffer(work, req, &path); if (rc) { if (posix_acl_rc) - ksmbd_vfs_set_init_posix_acl(inode); + ksmbd_vfs_set_init_posix_acl(mnt_user_ns(path.mnt), + inode); if (test_share_config_flag(work->tcon->share_conf, KSMBD_SHARE_FLAG_ACL_XATTR)) { @@ -2845,15 +2858,17 @@ int smb2_open(struct ksmbd_work *work) if (!pntsd) goto err_out; - rc = build_sec_desc(pntsd, NULL, + rc = build_sec_desc(mnt_user_ns(path.mnt), + pntsd, NULL, OWNER_SECINFO | - GROUP_SECINFO | - DACL_SECINFO, + GROUP_SECINFO | + DACL_SECINFO, &pntsd_size, &fattr); posix_acl_release(fattr.cf_acls); posix_acl_release(fattr.cf_dacls); rc = ksmbd_vfs_set_sd_xattr(conn, + mnt_user_ns(path.mnt), path.dentry, pntsd, pntsd_size); @@ -2895,7 +2910,7 @@ int smb2_open(struct ksmbd_work *work) rc = ksmbd_vfs_getattr(&path, &stat); if (rc) { - generic_fillattr(&init_user_ns, d_inode(path.dentry), &stat); + generic_fillattr(mnt_user_ns(path.mnt), d_inode(path.dentry), &stat); rc = 0; } @@ -2996,7 +3011,8 @@ int smb2_open(struct ksmbd_work *work) memcpy(fp->client_guid, conn->ClientGUID, SMB2_CLIENT_GUID_SIZE); - generic_fillattr(&init_user_ns, file_inode(fp->filp), &stat); + generic_fillattr(file_mnt_user_ns(fp->filp), file_inode(fp->filp), + &stat); rsp->StructureSize = cpu_to_le16(89); rcu_read_lock(); @@ -3048,7 +3064,8 @@ int smb2_open(struct ksmbd_work *work) struct create_context *mxac_ccontext; if (maximal_access == 0) - ksmbd_vfs_query_maximal_access(path.dentry, + ksmbd_vfs_query_maximal_access(mnt_user_ns(path.mnt), + path.dentry, &maximal_access); mxac_ccontext = (struct create_context *)(rsp->Buffer + le32_to_cpu(rsp->CreateContextsLength)); @@ -3251,6 +3268,7 @@ static int dentry_name(struct ksmbd_dir_info *d_info, int info_level) * @conn: connection instance * @info_level: smb information level * @d_info: structure included variables for query dir + * @user_ns: user namespace * @ksmbd_kstat: ksmbd wrapper of dirent stat information * * if directory has many entries, find first can't read it fully. @@ -3260,6 +3278,7 @@ static int dentry_name(struct ksmbd_dir_info *d_info, int info_level) */ static int smb2_populate_readdir_entry(struct ksmbd_conn *conn, int info_level, struct ksmbd_dir_info *d_info, + struct user_namespace *user_ns, struct ksmbd_kstat *ksmbd_kstat) { int next_entry_offset = 0; @@ -3412,9 +3431,9 @@ static int smb2_populate_readdir_entry(struct ksmbd_conn *conn, int info_level, S_ISDIR(ksmbd_kstat->kstat->mode) ? ATTR_DIRECTORY_LE : ATTR_ARCHIVE_LE; if (d_info->hide_dot_file && d_info->name[0] == '.') posix_info->DosAttributes |= ATTR_HIDDEN_LE; - id_to_sid(from_kuid(&init_user_ns, ksmbd_kstat->kstat->uid), + id_to_sid(from_kuid(user_ns, ksmbd_kstat->kstat->uid), SIDNFS_USER, (struct smb_sid *)&posix_info->SidBuffer[0]); - id_to_sid(from_kgid(&init_user_ns, ksmbd_kstat->kstat->gid), + id_to_sid(from_kgid(user_ns, ksmbd_kstat->kstat->gid), SIDNFS_GROUP, (struct smb_sid *)&posix_info->SidBuffer[20]); memcpy(posix_info->name, conv_name, conv_len); posix_info->name_len = cpu_to_le32(conv_len); @@ -3496,12 +3515,14 @@ static int process_query_dir_entries(struct smb2_query_dir_private *priv) ksmbd_kstat.kstat = &kstat; if (priv->info_level != FILE_NAMES_INFORMATION) ksmbd_vfs_fill_dentry_attrs(priv->work, + file_mnt_user_ns(priv->dir_fp->filp), dent, &ksmbd_kstat); rc = smb2_populate_readdir_entry(priv->work->conn, priv->info_level, priv->d_info, + file_mnt_user_ns(priv->dir_fp->filp), &ksmbd_kstat); dput(dent); if (rc) @@ -3710,7 +3731,8 @@ int smb2_query_dir(struct ksmbd_work *work) } if (!(dir_fp->daccess & FILE_LIST_DIRECTORY_LE) || - inode_permission(&init_user_ns, file_inode(dir_fp->filp), + inode_permission(file_mnt_user_ns(dir_fp->filp), + file_inode(dir_fp->filp), MAY_READ | MAY_EXEC)) { pr_err("no right to enumerate directory (%pd)\n", dir_fp->filp->f_path.dentry); @@ -4035,7 +4057,8 @@ static int smb2_get_ea(struct ksmbd_work *work, struct ksmbd_file *fp, buf_free_len -= (offsetof(struct smb2_ea_info, name) + name_len + 1); /* bailout if xattr can't fit in buf_free_len */ - value_len = ksmbd_vfs_getxattr(path->dentry, name, &buf); + value_len = ksmbd_vfs_getxattr(mnt_user_ns(path->mnt), + path->dentry, name, &buf); if (value_len <= 0) { rc = -ENOENT; rsp->hdr.Status = STATUS_INVALID_HANDLE; @@ -4124,7 +4147,8 @@ static int get_file_basic_info(struct smb2_query_info_rsp *rsp, } basic_info = (struct smb2_file_all_info *)rsp->Buffer; - generic_fillattr(&init_user_ns, file_inode(fp->filp), &stat); + generic_fillattr(file_mnt_user_ns(fp->filp), file_inode(fp->filp), + &stat); basic_info->CreationTime = cpu_to_le64(fp->create_time); time = ksmbd_UnixTimeToNT(stat.atime); basic_info->LastAccessTime = cpu_to_le64(time); @@ -4165,7 +4189,7 @@ static void get_file_standard_info(struct smb2_query_info_rsp *rsp, struct kstat stat; inode = file_inode(fp->filp); - generic_fillattr(&init_user_ns, inode, &stat); + generic_fillattr(file_mnt_user_ns(fp->filp), inode, &stat); sinfo = (struct smb2_file_standard_info *)rsp->Buffer; delete_pending = ksmbd_inode_pending_delete(fp); @@ -4220,7 +4244,7 @@ static int get_file_all_info(struct ksmbd_work *work, return -ENOMEM; inode = file_inode(fp->filp); - generic_fillattr(&init_user_ns, inode, &stat); + generic_fillattr(file_mnt_user_ns(fp->filp), inode, &stat); ksmbd_debug(SMB, "filename = %s\n", filename); delete_pending = ksmbd_inode_pending_delete(fp); @@ -4295,7 +4319,8 @@ static void get_file_stream_info(struct ksmbd_work *work, ssize_t xattr_list_len; int nbytes = 0, streamlen, stream_name_len, next, idx = 0; - generic_fillattr(&init_user_ns, file_inode(fp->filp), &stat); + generic_fillattr(file_mnt_user_ns(fp->filp), file_inode(fp->filp), + &stat); file_info = (struct smb2_file_stream_info *)rsp->Buffer; xattr_list_len = ksmbd_vfs_listxattr(path->dentry, &xattr_list); @@ -4374,7 +4399,8 @@ static void get_file_internal_info(struct smb2_query_info_rsp *rsp, struct smb2_file_internal_info *file_info; struct kstat stat; - generic_fillattr(&init_user_ns, file_inode(fp->filp), &stat); + generic_fillattr(file_mnt_user_ns(fp->filp), file_inode(fp->filp), + &stat); file_info = (struct smb2_file_internal_info *)rsp->Buffer; file_info->IndexNumber = cpu_to_le64(stat.ino); rsp->OutputBufferLength = @@ -4399,7 +4425,7 @@ static int get_file_network_open_info(struct smb2_query_info_rsp *rsp, file_info = (struct smb2_file_ntwrk_info *)rsp->Buffer; inode = file_inode(fp->filp); - generic_fillattr(&init_user_ns, inode, &stat); + generic_fillattr(file_mnt_user_ns(fp->filp), inode, &stat); file_info->CreationTime = cpu_to_le64(fp->create_time); time = ksmbd_UnixTimeToNT(stat.atime); @@ -4460,7 +4486,8 @@ static void get_file_compression_info(struct smb2_query_info_rsp *rsp, struct smb2_file_comp_info *file_info; struct kstat stat; - generic_fillattr(&init_user_ns, file_inode(fp->filp), &stat); + generic_fillattr(file_mnt_user_ns(fp->filp), file_inode(fp->filp), + &stat); file_info = (struct smb2_file_comp_info *)rsp->Buffer; file_info->CompressedFileSize = cpu_to_le64(stat.blocks << 9); @@ -4933,9 +4960,11 @@ static int smb2_get_info_sec(struct ksmbd_work *work, if (test_share_config_flag(work->tcon->share_conf, KSMBD_SHARE_FLAG_ACL_XATTR)) - ksmbd_vfs_get_sd_xattr(work->conn, fp->filp->f_path.dentry, &ppntsd); + ksmbd_vfs_get_sd_xattr(work->conn, file_mnt_user_ns(fp->filp), + fp->filp->f_path.dentry, &ppntsd); - rc = build_sec_desc(pntsd, ppntsd, addition_info, &secdesclen, &fattr); + rc = build_sec_desc(file_mnt_user_ns(fp->filp), + pntsd, ppntsd, addition_info, &secdesclen, &fattr); posix_acl_release(fattr.cf_acls); posix_acl_release(fattr.cf_dacls); kfree(ppntsd); @@ -5228,7 +5257,8 @@ static int smb2_rename(struct ksmbd_work *work, struct ksmbd_file *fp, if (rc) goto out; - rc = ksmbd_vfs_setxattr(fp->filp->f_path.dentry, + rc = ksmbd_vfs_setxattr(file_mnt_user_ns(fp->filp), + fp->filp->f_path.dentry, xattr_stream_name, NULL, 0, 0); if (rc < 0) { @@ -5412,7 +5442,8 @@ static int set_file_basic_info(struct ksmbd_file *fp, char *buf, da.flags = XATTR_DOSINFO_ATTRIB | XATTR_DOSINFO_CREATE_TIME | XATTR_DOSINFO_ITIME; - rc = ksmbd_vfs_set_dos_attrib_xattr(filp->f_path.dentry, &da); + rc = ksmbd_vfs_set_dos_attrib_xattr(file_mnt_user_ns(filp), + filp->f_path.dentry, &da); if (rc) ksmbd_debug(SMB, "failed to restore file attribute in EA\n"); @@ -5433,14 +5464,14 @@ static int set_file_basic_info(struct ksmbd_file *fp, char *buf, if (IS_IMMUTABLE(inode) || IS_APPEND(inode)) return -EACCES; - rc = setattr_prepare(&init_user_ns, dentry, &attrs); + rc = setattr_prepare(file_mnt_user_ns(filp), dentry, &attrs); if (rc) return -EINVAL; inode_lock(inode); - setattr_copy(&init_user_ns, inode, &attrs); + setattr_copy(file_mnt_user_ns(filp), inode, &attrs); attrs.ia_valid &= ~ATTR_CTIME; - rc = notify_change(&init_user_ns, dentry, &attrs, NULL); + rc = notify_change(file_mnt_user_ns(filp), dentry, &attrs, NULL); inode_unlock(inode); } return 0; @@ -7188,12 +7219,14 @@ static inline int fsctl_set_sparse(struct ksmbd_work *work, u64 id, KSMBD_SHARE_FLAG_STORE_DOS_ATTRS)) { struct xattr_dos_attrib da; - ret = ksmbd_vfs_get_dos_attrib_xattr(fp->filp->f_path.dentry, &da); + ret = ksmbd_vfs_get_dos_attrib_xattr(file_mnt_user_ns(fp->filp), + fp->filp->f_path.dentry, &da); if (ret <= 0) goto out; da.attr = le32_to_cpu(fp->f_ci->m_fattr); - ret = ksmbd_vfs_set_dos_attrib_xattr(fp->filp->f_path.dentry, &da); + ret = ksmbd_vfs_set_dos_attrib_xattr(file_mnt_user_ns(fp->filp), + fp->filp->f_path.dentry, &da); if (ret) fp->f_ci->m_fattr = old_fattr; } diff --git a/fs/ksmbd/smb_common.c b/fs/ksmbd/smb_common.c index b573575a1de5..f770f3ffb840 100644 --- a/fs/ksmbd/smb_common.c +++ b/fs/ksmbd/smb_common.c @@ -274,6 +274,7 @@ int ksmbd_populate_dot_dotdot_entries(struct ksmbd_work *work, int info_level, char *search_pattern, int (*fn)(struct ksmbd_conn *, int, struct ksmbd_dir_info *, + struct user_namespace *, struct ksmbd_kstat *)) { int i, rc = 0; @@ -300,9 +301,11 @@ int ksmbd_populate_dot_dotdot_entries(struct ksmbd_work *work, int info_level, ksmbd_kstat.kstat = &kstat; ksmbd_vfs_fill_dentry_attrs(work, + file_mnt_user_ns(dir->filp), dir->filp->f_path.dentry->d_parent, &ksmbd_kstat); - rc = fn(conn, info_level, d_info, &ksmbd_kstat); + rc = fn(conn, info_level, d_info, + file_mnt_user_ns(dir->filp), &ksmbd_kstat); if (rc) break; if (d_info->out_buf_len <= 0) diff --git a/fs/ksmbd/smb_common.h b/fs/ksmbd/smb_common.h index 8489b92229fa..6ab28aa33024 100644 --- a/fs/ksmbd/smb_common.h +++ b/fs/ksmbd/smb_common.h @@ -514,6 +514,7 @@ int ksmbd_populate_dot_dotdot_entries(struct ksmbd_work *work, int (*fn)(struct ksmbd_conn *, int, struct ksmbd_dir_info *, + struct user_namespace *, struct ksmbd_kstat *)); int ksmbd_extract_shortname(struct ksmbd_conn *conn, diff --git a/fs/ksmbd/smbacl.c b/fs/ksmbd/smbacl.c index e0825d3771a1..4ee714b9b351 100644 --- a/fs/ksmbd/smbacl.c +++ b/fs/ksmbd/smbacl.c @@ -253,7 +253,8 @@ void id_to_sid(unsigned int cid, uint sidtype, struct smb_sid *ssid) ssid->num_subauth++; } -static int sid_to_id(struct smb_sid *psid, uint sidtype, +static int sid_to_id(struct user_namespace *user_ns, + struct smb_sid *psid, uint sidtype, struct smb_fattr *fattr) { int rc = -EINVAL; @@ -274,8 +275,8 @@ static int sid_to_id(struct smb_sid *psid, uint sidtype, id = le32_to_cpu(psid->sub_auth[psid->num_subauth - 1]); if (id > 0) { - uid = make_kuid(&init_user_ns, id); - if (uid_valid(uid) && kuid_has_mapping(&init_user_ns, uid)) { + uid = make_kuid(user_ns, id); + if (uid_valid(uid) && kuid_has_mapping(user_ns, uid)) { fattr->cf_uid = uid; rc = 0; } @@ -286,8 +287,8 @@ static int sid_to_id(struct smb_sid *psid, uint sidtype, id = le32_to_cpu(psid->sub_auth[psid->num_subauth - 1]); if (id > 0) { - gid = make_kgid(&init_user_ns, id); - if (gid_valid(gid) && kgid_has_mapping(&init_user_ns, gid)) { + gid = make_kgid(user_ns, id); + if (gid_valid(gid) && kgid_has_mapping(user_ns, gid)) { fattr->cf_gid = gid; rc = 0; } @@ -362,7 +363,8 @@ void free_acl_state(struct posix_acl_state *state) kfree(state->groups); } -static void parse_dacl(struct smb_acl *pdacl, char *end_of_acl, +static void parse_dacl(struct user_namespace *user_ns, + struct smb_acl *pdacl, char *end_of_acl, struct smb_sid *pownersid, struct smb_sid *pgrpsid, struct smb_fattr *fattr) { @@ -474,7 +476,7 @@ static void parse_dacl(struct smb_acl *pdacl, char *end_of_acl, acl_mode = access_flags_to_mode(fattr, ppace[i]->access_req, ppace[i]->type); temp_fattr.cf_uid = INVALID_UID; - ret = sid_to_id(&ppace[i]->sid, SIDOWNER, &temp_fattr); + ret = sid_to_id(user_ns, &ppace[i]->sid, SIDOWNER, &temp_fattr); if (ret || uid_eq(temp_fattr.cf_uid, INVALID_UID)) { pr_err("%s: Error %d mapping Owner SID to uid\n", __func__, ret); @@ -553,7 +555,8 @@ static void parse_dacl(struct smb_acl *pdacl, char *end_of_acl, free_acl_state(&default_acl_state); } -static void set_posix_acl_entries_dacl(struct smb_ace *pndace, +static void set_posix_acl_entries_dacl(struct user_namespace *user_ns, + struct smb_ace *pndace, struct smb_fattr *fattr, u32 *num_aces, u16 *size, u32 nt_aces_num) { @@ -577,14 +580,14 @@ static void set_posix_acl_entries_dacl(struct smb_ace *pndace, uid_t uid; unsigned int sid_type = SIDOWNER; - uid = from_kuid(&init_user_ns, pace->e_uid); + uid = from_kuid(user_ns, pace->e_uid); if (!uid) sid_type = SIDUNIX_USER; id_to_sid(uid, sid_type, sid); } else if (pace->e_tag == ACL_GROUP) { gid_t gid; - gid = from_kgid(&init_user_ns, pace->e_gid); + gid = from_kgid(user_ns, pace->e_gid); id_to_sid(gid, SIDUNIX_GROUP, sid); } else if (pace->e_tag == ACL_OTHER && !nt_aces_num) { smb_copy_sid(sid, &sid_everyone); @@ -643,12 +646,12 @@ posix_default_acl: if (pace->e_tag == ACL_USER) { uid_t uid; - uid = from_kuid(&init_user_ns, pace->e_uid); + uid = from_kuid(user_ns, pace->e_uid); id_to_sid(uid, SIDCREATOR_OWNER, sid); } else if (pace->e_tag == ACL_GROUP) { gid_t gid; - gid = from_kgid(&init_user_ns, pace->e_gid); + gid = from_kgid(user_ns, pace->e_gid); id_to_sid(gid, SIDCREATOR_GROUP, sid); } else { kfree(sid); @@ -666,7 +669,9 @@ posix_default_acl: } } -static void set_ntacl_dacl(struct smb_acl *pndacl, struct smb_acl *nt_dacl, +static void set_ntacl_dacl(struct user_namespace *user_ns, + struct smb_acl *pndacl, + struct smb_acl *nt_dacl, const struct smb_sid *pownersid, const struct smb_sid *pgrpsid, struct smb_fattr *fattr) @@ -687,12 +692,14 @@ static void set_ntacl_dacl(struct smb_acl *pndacl, struct smb_acl *nt_dacl, } } - set_posix_acl_entries_dacl(pndace, fattr, &num_aces, &size, nt_num_aces); + set_posix_acl_entries_dacl(user_ns, pndace, fattr, + &num_aces, &size, nt_num_aces); pndacl->num_aces = cpu_to_le32(num_aces); pndacl->size = cpu_to_le16(le16_to_cpu(pndacl->size) + size); } -static void set_mode_dacl(struct smb_acl *pndacl, struct smb_fattr *fattr) +static void set_mode_dacl(struct user_namespace *user_ns, + struct smb_acl *pndacl, struct smb_fattr *fattr) { struct smb_ace *pace, *pndace; u32 num_aces = 0; @@ -703,12 +710,13 @@ static void set_mode_dacl(struct smb_acl *pndacl, struct smb_fattr *fattr) pace = pndace = (struct smb_ace *)((char *)pndacl + sizeof(struct smb_acl)); if (fattr->cf_acls) { - set_posix_acl_entries_dacl(pndace, fattr, &num_aces, &size, num_aces); + set_posix_acl_entries_dacl(user_ns, pndace, fattr, + &num_aces, &size, num_aces); goto out; } /* owner RID */ - uid = from_kuid(&init_user_ns, fattr->cf_uid); + uid = from_kuid(user_ns, fattr->cf_uid); if (uid) sid = &server_conf.domain_sid; else @@ -725,7 +733,7 @@ static void set_mode_dacl(struct smb_acl *pndacl, struct smb_fattr *fattr) ace_size = fill_ace_for_sid(pace, &sid_unix_groups, ACCESS_ALLOWED, 0, fattr->cf_mode, 0070); pace->sid.sub_auth[pace->sid.num_subauth++] = - cpu_to_le32(from_kgid(&init_user_ns, fattr->cf_gid)); + cpu_to_le32(from_kgid(user_ns, fattr->cf_gid)); pace->size = cpu_to_le16(ace_size + 4); size += le16_to_cpu(pace->size); pace = (struct smb_ace *)((char *)pndace + size); @@ -771,8 +779,8 @@ static int parse_sid(struct smb_sid *psid, char *end_of_acl) } /* Convert CIFS ACL to POSIX form */ -int parse_sec_desc(struct smb_ntsd *pntsd, int acl_len, - struct smb_fattr *fattr) +int parse_sec_desc(struct user_namespace *user_ns, struct smb_ntsd *pntsd, + int acl_len, struct smb_fattr *fattr) { int rc = 0; struct smb_sid *owner_sid_ptr, *group_sid_ptr; @@ -811,7 +819,7 @@ int parse_sec_desc(struct smb_ntsd *pntsd, int acl_len, return rc; } - rc = sid_to_id(owner_sid_ptr, SIDOWNER, fattr); + rc = sid_to_id(user_ns, owner_sid_ptr, SIDOWNER, fattr); if (rc) { pr_err("%s: Error %d mapping Owner SID to uid\n", __func__, rc); @@ -826,7 +834,7 @@ int parse_sec_desc(struct smb_ntsd *pntsd, int acl_len, __func__, rc); return rc; } - rc = sid_to_id(group_sid_ptr, SIDUNIX_GROUP, fattr); + rc = sid_to_id(user_ns, group_sid_ptr, SIDUNIX_GROUP, fattr); if (rc) { pr_err("%s: Error %d mapping Group SID to gid\n", __func__, rc); @@ -841,15 +849,16 @@ int parse_sec_desc(struct smb_ntsd *pntsd, int acl_len, pntsd->type |= cpu_to_le16(DACL_PROTECTED); if (dacloffset) { - parse_dacl(dacl_ptr, end_of_acl, owner_sid_ptr, group_sid_ptr, - fattr); + parse_dacl(user_ns, dacl_ptr, end_of_acl, + owner_sid_ptr, group_sid_ptr, fattr); } return 0; } /* Convert permission bits from mode to equivalent CIFS ACL */ -int build_sec_desc(struct smb_ntsd *pntsd, struct smb_ntsd *ppntsd, +int build_sec_desc(struct user_namespace *user_ns, + struct smb_ntsd *pntsd, struct smb_ntsd *ppntsd, int addition_info, __u32 *secdesclen, struct smb_fattr *fattr) { @@ -866,7 +875,7 @@ int build_sec_desc(struct smb_ntsd *pntsd, struct smb_ntsd *ppntsd, if (!nowner_sid_ptr) return -ENOMEM; - uid = from_kuid(&init_user_ns, fattr->cf_uid); + uid = from_kuid(user_ns, fattr->cf_uid); if (!uid) sid_type = SIDUNIX_USER; id_to_sid(uid, sid_type, nowner_sid_ptr); @@ -877,7 +886,7 @@ int build_sec_desc(struct smb_ntsd *pntsd, struct smb_ntsd *ppntsd, return -ENOMEM; } - gid = from_kgid(&init_user_ns, fattr->cf_gid); + gid = from_kgid(user_ns, fattr->cf_gid); id_to_sid(gid, SIDUNIX_GROUP, ngroup_sid_ptr); offset = sizeof(struct smb_ntsd); @@ -909,7 +918,7 @@ int build_sec_desc(struct smb_ntsd *pntsd, struct smb_ntsd *ppntsd, dacl_ptr->num_aces = 0; if (!ppntsd) { - set_mode_dacl(dacl_ptr, fattr); + set_mode_dacl(user_ns, dacl_ptr, fattr); } else if (!ppntsd->dacloffset) { goto out; } else { @@ -917,8 +926,8 @@ int build_sec_desc(struct smb_ntsd *pntsd, struct smb_ntsd *ppntsd, ppdacl_ptr = (struct smb_acl *)((char *)ppntsd + le32_to_cpu(ppntsd->dacloffset)); - set_ntacl_dacl(dacl_ptr, ppdacl_ptr, nowner_sid_ptr, - ngroup_sid_ptr, fattr); + set_ntacl_dacl(user_ns, dacl_ptr, ppdacl_ptr, + nowner_sid_ptr, ngroup_sid_ptr, fattr); } pntsd->dacloffset = cpu_to_le32(offset); offset += le16_to_cpu(dacl_ptr->size); @@ -956,7 +965,8 @@ int smb_inherit_dacl(struct ksmbd_conn *conn, char *aces_base; bool is_dir = S_ISDIR(d_inode(path->dentry)->i_mode); - acl_len = ksmbd_vfs_get_sd_xattr(conn, parent, &parent_pntsd); + acl_len = ksmbd_vfs_get_sd_xattr(conn, mnt_user_ns(path->mnt), + parent, &parent_pntsd); if (acl_len <= 0) return rc; dacloffset = le32_to_cpu(parent_pntsd->dacloffset); @@ -1087,7 +1097,8 @@ pass: pntsd_size += sizeof(struct smb_acl) + nt_size; } - ksmbd_vfs_set_sd_xattr(conn, path->dentry, pntsd, pntsd_size); + ksmbd_vfs_set_sd_xattr(conn, mnt_user_ns(path->mnt), + path->dentry, pntsd, pntsd_size); kfree(pntsd); rc = 0; } @@ -1128,7 +1139,8 @@ int smb_check_perm_dacl(struct ksmbd_conn *conn, struct path *path, char *end_of_acl; ksmbd_debug(SMB, "check permission using windows acl\n"); - acl_size = ksmbd_vfs_get_sd_xattr(conn, path->dentry, &pntsd); + acl_size = ksmbd_vfs_get_sd_xattr(conn, mnt_user_ns(path->mnt), + path->dentry, &pntsd); if (acl_size <= 0 || !pntsd || !pntsd->dacloffset) { kfree(pntsd); return 0; @@ -1209,9 +1221,11 @@ int smb_check_perm_dacl(struct ksmbd_conn *conn, struct path *path, pa_entry = posix_acls->a_entries; for (i = 0; i < posix_acls->a_count; i++, pa_entry++) { if (pa_entry->e_tag == ACL_USER) - id = from_kuid(&init_user_ns, pa_entry->e_uid); + id = from_kuid(mnt_user_ns(path->mnt), + pa_entry->e_uid); else if (pa_entry->e_tag == ACL_GROUP) - id = from_kgid(&init_user_ns, pa_entry->e_gid); + id = from_kgid(mnt_user_ns(path->mnt), + pa_entry->e_gid); else continue; @@ -1273,7 +1287,7 @@ int set_info_sec(struct ksmbd_conn *conn, struct ksmbd_tree_connect *tcon, fattr.cf_gid = INVALID_GID; fattr.cf_mode = inode->i_mode; - rc = parse_sec_desc(pntsd, ntsd_len, &fattr); + rc = parse_sec_desc(mnt_user_ns(path->mnt), pntsd, ntsd_len, &fattr); if (rc) goto out; @@ -1284,13 +1298,13 @@ int set_info_sec(struct ksmbd_conn *conn, struct ksmbd_tree_connect *tcon, inode->i_gid = fattr.cf_gid; mark_inode_dirty(inode); - ksmbd_vfs_remove_acl_xattrs(path->dentry); + ksmbd_vfs_remove_acl_xattrs(mnt_user_ns(path->mnt), path->dentry); /* Update posix acls */ if (fattr.cf_dacls) { - rc = set_posix_acl(&init_user_ns, inode, ACL_TYPE_ACCESS, - fattr.cf_acls); + rc = set_posix_acl(mnt_user_ns(path->mnt), inode, + ACL_TYPE_ACCESS, fattr.cf_acls); if (S_ISDIR(inode->i_mode) && fattr.cf_dacls) - rc = set_posix_acl(&init_user_ns, inode, + rc = set_posix_acl(mnt_user_ns(path->mnt), inode, ACL_TYPE_DEFAULT, fattr.cf_dacls); } @@ -1300,8 +1314,9 @@ int set_info_sec(struct ksmbd_conn *conn, struct ksmbd_tree_connect *tcon, if (test_share_config_flag(tcon->share_conf, KSMBD_SHARE_FLAG_ACL_XATTR)) { /* Update WinACL in xattr */ - ksmbd_vfs_remove_sd_xattrs(path->dentry); - ksmbd_vfs_set_sd_xattr(conn, path->dentry, pntsd, ntsd_len); + ksmbd_vfs_remove_sd_xattrs(mnt_user_ns(path->mnt), path->dentry); + ksmbd_vfs_set_sd_xattr(conn, mnt_user_ns(path->mnt), + path->dentry, pntsd, ntsd_len); } out: diff --git a/fs/ksmbd/smbacl.h b/fs/ksmbd/smbacl.h index 4ee7bda32e5f..940f686a1d95 100644 --- a/fs/ksmbd/smbacl.h +++ b/fs/ksmbd/smbacl.h @@ -189,11 +189,11 @@ struct posix_acl_state { struct posix_ace_state_array *groups; }; -int parse_sec_desc(struct smb_ntsd *pntsd, int acl_len, - struct smb_fattr *fattr); -int build_sec_desc(struct smb_ntsd *pntsd, struct smb_ntsd *ppntsd, - int addition_info, __u32 *secdesclen, - struct smb_fattr *fattr); +int parse_sec_desc(struct user_namespace *user_ns, struct smb_ntsd *pntsd, + int acl_len, struct smb_fattr *fattr); +int build_sec_desc(struct user_namespace *user_ns, struct smb_ntsd *pntsd, + struct smb_ntsd *ppntsd, int addition_info, + __u32 *secdesclen, struct smb_fattr *fattr); int init_acl_state(struct posix_acl_state *state, int cnt); void free_acl_state(struct posix_acl_state *state); void posix_state_to_acl(struct posix_acl_state *state, diff --git a/fs/ksmbd/vfs.c b/fs/ksmbd/vfs.c index 702166266f91..0f5a4fb8215f 100644 --- a/fs/ksmbd/vfs.c +++ b/fs/ksmbd/vfs.c @@ -95,7 +95,8 @@ out_err: return ret; } -int ksmbd_vfs_may_delete(struct dentry *dentry) +int ksmbd_vfs_may_delete(struct user_namespace *user_ns, + struct dentry *dentry) { struct dentry *parent; int ret; @@ -107,7 +108,7 @@ int ksmbd_vfs_may_delete(struct dentry *dentry) return ret; } |
