*/
static int smb2_set_ea(struct smb2_ea_info *eabuf, struct path *path)
{
+ struct user_namespace *user_ns = mnt_user_ns(path->mnt);
char *attr_name = NULL, *value;
int rc = 0;
int next = 0;
value = (char *)&eabuf->name + eabuf->EaNameLength + 1;
if (!eabuf->EaValueLength) {
- rc = ksmbd_vfs_casexattr_len(mnt_user_ns(path->mnt),
+ rc = ksmbd_vfs_casexattr_len(user_ns,
path->dentry,
attr_name,
XATTR_USER_PREFIX_LEN +
/* delete the EA only when it exits */
if (rc > 0) {
- rc = ksmbd_vfs_remove_xattr(mnt_user_ns(path->mnt),
+ rc = ksmbd_vfs_remove_xattr(user_ns,
path->dentry,
attr_name);
/* if the EA doesn't exist, just do nothing. */
rc = 0;
} else {
- rc = ksmbd_vfs_setxattr(mnt_user_ns(path->mnt),
+ rc = ksmbd_vfs_setxattr(user_ns,
path->dentry, attr_name, value,
le16_to_cpu(eabuf->EaValueLength), 0);
if (rc < 0) {
struct ksmbd_file *fp,
char *stream_name, int s_type)
{
+ struct user_namespace *user_ns = mnt_user_ns(path->mnt);
size_t xattr_stream_size;
char *xattr_stream_name;
int rc;
fp->stream.size = xattr_stream_size;
/* Check if there is stream prefix in xattr space */
- rc = ksmbd_vfs_casexattr_len(mnt_user_ns(path->mnt),
+ rc = ksmbd_vfs_casexattr_len(user_ns,
path->dentry,
xattr_stream_name,
xattr_stream_size);
return -EBADF;
}
- rc = ksmbd_vfs_setxattr(mnt_user_ns(path->mnt),
- path->dentry, xattr_stream_name, NULL, 0, 0);
+ rc = ksmbd_vfs_setxattr(user_ns, path->dentry,
+ xattr_stream_name, NULL, 0, 0);
if (rc < 0)
pr_err("Failed to store XATTR stream name :%d\n", rc);
return 0;
static int smb2_remove_smb_xattrs(struct path *path)
{
+ struct user_namespace *user_ns = mnt_user_ns(path->mnt);
char *name, *xattr_list = NULL;
ssize_t xattr_list_len;
int err = 0;
strncmp(&name[XATTR_USER_PREFIX_LEN], STREAM_PREFIX, STREAM_PREFIX_LEN))
continue;
- err = ksmbd_vfs_remove_xattr(mnt_user_ns(path->mnt),
- path->dentry, name);
+ err = ksmbd_vfs_remove_xattr(user_ns, path->dentry, name);
if (err)
ksmbd_debug(SMB, "remove xattr failed : %s\n", name);
}
struct ksmbd_share_config *share = tcon->share_conf;
struct ksmbd_file *fp = NULL;
struct file *filp = NULL;
+ struct user_namespace *user_ns = NULL;
struct kstat stat;
struct create_context *context;
struct lease_ctx_info *lc = NULL;
rc = 0;
} else {
file_present = true;
- generic_fillattr(mnt_user_ns(path.mnt), d_inode(path.dentry), &stat);
+ user_ns = mnt_user_ns(path.mnt);
+ generic_fillattr(user_ns, d_inode(path.dentry), &stat);
}
if (stream_name) {
if (req->CreateOptions & FILE_DIRECTORY_FILE_LE) {
if (!file_present) {
daccess = cpu_to_le32(GENERIC_ALL_FLAGS);
} else {
- rc = ksmbd_vfs_query_maximal_access(mnt_user_ns(path.mnt),
+ rc = ksmbd_vfs_query_maximal_access(user_ns,
path.dentry,
&daccess);
if (rc)
goto err_out;
created = true;
+ user_ns = mnt_user_ns(path.mnt);
if (ea_buf) {
rc = smb2_set_ea(&ea_buf->ea, &path);
if (rc == -EOPNOTSUPP)
* is already granted.
*/
if (daccess & ~(FILE_READ_ATTRIBUTES_LE | FILE_READ_CONTROL_LE)) {
- rc = inode_permission(mnt_user_ns(path.mnt),
+ rc = inode_permission(user_ns,
d_inode(path.dentry),
may_flags);
if (rc)
if ((daccess & FILE_DELETE_LE) ||
(req->CreateOptions & FILE_DELETE_ON_CLOSE_LE)) {
- rc = ksmbd_vfs_may_delete(mnt_user_ns(path.mnt),
+ rc = ksmbd_vfs_may_delete(user_ns,
path.dentry);
if (rc)
goto err_out;
int posix_acl_rc;
struct inode *inode = d_inode(path.dentry);
- posix_acl_rc = ksmbd_vfs_inherit_posix_acl(mnt_user_ns(path.mnt),
+ posix_acl_rc = ksmbd_vfs_inherit_posix_acl(user_ns,
inode,
d_inode(path.dentry->d_parent));
if (posix_acl_rc)
rc = smb2_create_sd_buffer(work, req, &path);
if (rc) {
if (posix_acl_rc)
- ksmbd_vfs_set_init_posix_acl(mnt_user_ns(path.mnt),
+ ksmbd_vfs_set_init_posix_acl(user_ns,
inode);
if (test_share_config_flag(work->tcon->share_conf,
if (!pntsd)
goto err_out;
- rc = build_sec_desc(mnt_user_ns(path.mnt),
+ rc = build_sec_desc(user_ns,
pntsd, NULL,
OWNER_SECINFO |
GROUP_SECINFO |
posix_acl_release(fattr.cf_dacls);
rc = ksmbd_vfs_set_sd_xattr(conn,
- mnt_user_ns(path.mnt),
+ user_ns,
path.dentry,
pntsd,
pntsd_size);
rc = ksmbd_vfs_getattr(&path, &stat);
if (rc) {
- generic_fillattr(mnt_user_ns(path.mnt), d_inode(path.dentry), &stat);
+ generic_fillattr(user_ns, d_inode(path.dentry), &stat);
rc = 0;
}
memcpy(fp->client_guid, conn->ClientGUID, SMB2_CLIENT_GUID_SIZE);
- generic_fillattr(file_mnt_user_ns(fp->filp), file_inode(fp->filp),
+ generic_fillattr(user_ns, file_inode(fp->filp),
&stat);
rsp->StructureSize = cpu_to_le16(89);
struct create_context *mxac_ccontext;
if (maximal_access == 0)
- ksmbd_vfs_query_maximal_access(mnt_user_ns(path.mnt),
+ ksmbd_vfs_query_maximal_access(user_ns,
path.dentry,
&maximal_access);
mxac_ccontext = (struct create_context *)(rsp->Buffer +
static int process_query_dir_entries(struct smb2_query_dir_private *priv)
{
+ struct user_namespace *user_ns = file_mnt_user_ns(priv->dir_fp->filp);
struct kstat kstat;
struct ksmbd_kstat ksmbd_kstat;
int rc;
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),
+ user_ns,
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),
+ user_ns,
&ksmbd_kstat);
dput(dent);
if (rc)
ssize_t buf_free_len, alignment_bytes, next_offset, rsp_data_cnt = 0;
struct smb2_ea_info_req *ea_req = NULL;
struct path *path;
+ struct user_namespace *user_ns = file_mnt_user_ns(fp->filp);
if (!(fp->daccess & FILE_READ_EA_LE)) {
pr_err("Not permitted to read ext attr : 0x%x\n",
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(mnt_user_ns(path->mnt),
- path->dentry, name, &buf);
+ value_len = ksmbd_vfs_getxattr(user_ns, path->dentry,
+ name, &buf);
if (value_len <= 0) {
rc = -ENOENT;
rsp->hdr.Status = STATUS_INVALID_HANDLE;
struct smb2_query_info_rsp *rsp, void *rsp_org)
{
struct ksmbd_file *fp;
+ struct user_namespace *user_ns;
struct smb_ntsd *pntsd = (struct smb_ntsd *)rsp->Buffer, *ppntsd = NULL;
struct smb_fattr fattr = {{0}};
struct inode *inode;
if (!fp)
return -ENOENT;
+ user_ns = file_mnt_user_ns(fp->filp);
inode = file_inode(fp->filp);
ksmbd_acls_fattr(&fattr, inode);
if (test_share_config_flag(work->tcon->share_conf,
KSMBD_SHARE_FLAG_ACL_XATTR))
- ksmbd_vfs_get_sd_xattr(work->conn, file_mnt_user_ns(fp->filp),
+ ksmbd_vfs_get_sd_xattr(work->conn, user_ns,
fp->filp->f_path.dentry, &ppntsd);
- rc = build_sec_desc(file_mnt_user_ns(fp->filp),
- pntsd, ppntsd, addition_info, &secdesclen, &fattr);
+ rc = build_sec_desc(user_ns, pntsd, ppntsd, addition_info,
+ &secdesclen, &fattr);
posix_acl_release(fattr.cf_acls);
posix_acl_release(fattr.cf_dacls);
kfree(ppntsd);
struct iattr temp_attrs;
struct file *filp;
struct inode *inode;
+ struct user_namespace *user_ns;
int rc;
if (!(fp->daccess & FILE_WRITE_ATTRIBUTES_LE))
attrs.ia_valid = 0;
filp = fp->filp;
inode = file_inode(filp);
+ user_ns = file_mnt_user_ns(filp);
if (file_info->CreationTime)
fp->create_time = le64_to_cpu(file_info->CreationTime);
da.flags = XATTR_DOSINFO_ATTRIB | XATTR_DOSINFO_CREATE_TIME |
XATTR_DOSINFO_ITIME;
- rc = ksmbd_vfs_set_dos_attrib_xattr(file_mnt_user_ns(filp),
+ rc = ksmbd_vfs_set_dos_attrib_xattr(user_ns,
filp->f_path.dentry, &da);
if (rc)
ksmbd_debug(SMB,
if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
return -EACCES;
- rc = setattr_prepare(file_mnt_user_ns(filp), dentry, &attrs);
+ rc = setattr_prepare(user_ns, dentry, &attrs);
if (rc)
return -EINVAL;
inode_lock(inode);
- setattr_copy(file_mnt_user_ns(filp), inode, &attrs);
+ setattr_copy(user_ns, inode, &attrs);
attrs.ia_valid &= ~ATTR_CTIME;
- rc = notify_change(file_mnt_user_ns(filp), dentry, &attrs, NULL);
+ rc = notify_change(user_ns, dentry, &attrs, NULL);
inode_unlock(inode);
}
return 0;
struct file_sparse *sparse)
{
struct ksmbd_file *fp;
+ struct user_namespace *user_ns;
int ret = 0;
__le32 old_fattr;
fp = ksmbd_lookup_fd_fast(work, id);
if (!fp)
return -ENOENT;
+ user_ns = file_mnt_user_ns(fp->filp);
old_fattr = fp->f_ci->m_fattr;
if (sparse->SetSparse)
KSMBD_SHARE_FLAG_STORE_DOS_ATTRS)) {
struct xattr_dos_attrib da;
- ret = ksmbd_vfs_get_dos_attrib_xattr(file_mnt_user_ns(fp->filp),
+ ret = ksmbd_vfs_get_dos_attrib_xattr(user_ns,
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(file_mnt_user_ns(fp->filp),
+ ret = ksmbd_vfs_set_dos_attrib_xattr(user_ns,
fp->filp->f_path.dentry, &da);
if (ret)
fp->f_ci->m_fattr = old_fattr;
struct smb_ntsd *parent_pntsd = NULL;
struct smb_sid owner_sid, group_sid;
struct dentry *parent = path->dentry->d_parent;
+ struct user_namespace *user_ns = mnt_user_ns(path->mnt);
int inherited_flags = 0, flags = 0, i, ace_cnt = 0, nt_size = 0;
int rc = -ENOENT, num_aces, dacloffset, pntsd_type, acl_len;
char *aces_base;
bool is_dir = S_ISDIR(d_inode(path->dentry)->i_mode);
- acl_len = ksmbd_vfs_get_sd_xattr(conn, mnt_user_ns(path->mnt),
+ acl_len = ksmbd_vfs_get_sd_xattr(conn, user_ns,
parent, &parent_pntsd);
if (acl_len <= 0)
return rc;
pntsd_size += sizeof(struct smb_acl) + nt_size;
}
- ksmbd_vfs_set_sd_xattr(conn, mnt_user_ns(path->mnt),
+ ksmbd_vfs_set_sd_xattr(conn, user_ns,
path->dentry, pntsd, pntsd_size);
kfree(pntsd);
rc = 0;
int smb_check_perm_dacl(struct ksmbd_conn *conn, struct path *path,
__le32 *pdaccess, int uid)
{
+ struct user_namespace *user_ns = mnt_user_ns(path->mnt);
struct smb_ntsd *pntsd = NULL;
struct smb_acl *pdacl;
struct posix_acl *posix_acls;
char *end_of_acl;
ksmbd_debug(SMB, "check permission using windows acl\n");
- acl_size = ksmbd_vfs_get_sd_xattr(conn, mnt_user_ns(path->mnt),
+ acl_size = ksmbd_vfs_get_sd_xattr(conn, user_ns,
path->dentry, &pntsd);
if (acl_size <= 0 || !pntsd || !pntsd->dacloffset) {
kfree(pntsd);
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(mnt_user_ns(path->mnt),
+ id = from_kuid(user_ns,
pa_entry->e_uid);
else if (pa_entry->e_tag == ACL_GROUP)
- id = from_kgid(mnt_user_ns(path->mnt),
+ id = from_kgid(user_ns,
pa_entry->e_gid);
else
continue;
int rc;
struct smb_fattr fattr = {{0}};
struct inode *inode = d_inode(path->dentry);
+ struct user_namespace *user_ns = mnt_user_ns(path->mnt);
fattr.cf_uid = INVALID_UID;
fattr.cf_gid = INVALID_GID;
fattr.cf_mode = inode->i_mode;
- rc = parse_sec_desc(mnt_user_ns(path->mnt), pntsd, ntsd_len, &fattr);
+ rc = parse_sec_desc(user_ns, pntsd, ntsd_len, &fattr);
if (rc)
goto out;
inode->i_gid = fattr.cf_gid;
mark_inode_dirty(inode);
- ksmbd_vfs_remove_acl_xattrs(mnt_user_ns(path->mnt), path->dentry);
+ ksmbd_vfs_remove_acl_xattrs(user_ns, path->dentry);
/* Update posix acls */
if (fattr.cf_dacls) {
- rc = set_posix_acl(mnt_user_ns(path->mnt), inode,
+ rc = set_posix_acl(user_ns, inode,
ACL_TYPE_ACCESS, fattr.cf_acls);
if (S_ISDIR(inode->i_mode) && fattr.cf_dacls)
- rc = set_posix_acl(mnt_user_ns(path->mnt), inode,
+ rc = set_posix_acl(user_ns, inode,
ACL_TYPE_DEFAULT, fattr.cf_dacls);
}
if (test_share_config_flag(tcon->share_conf, KSMBD_SHARE_FLAG_ACL_XATTR)) {
/* Update WinACL in xattr */
- ksmbd_vfs_remove_sd_xattrs(mnt_user_ns(path->mnt), path->dentry);
- ksmbd_vfs_set_sd_xattr(conn, mnt_user_ns(path->mnt),
+ ksmbd_vfs_remove_sd_xattrs(user_ns, path->dentry);
+ ksmbd_vfs_set_sd_xattr(conn, user_ns,
path->dentry, pntsd, ntsd_len);
}