Skip to content

Commit 673478b

Browse files
mihalicynidryomov
authored andcommitted
ceph: add enable_unsafe_idmap module parameter
This parameter is used to decide if we allow to perform IO on idmapped mount in case when MDS lacks support of CEPHFS_FEATURE_HAS_OWNER_UIDGID feature. In this case we can't properly handle MDS permission checks and if UID/GID-based restrictions are enabled on the MDS side then IO requests which go through an idmapped mount may fail with -EACCESS/-EPERM. Fortunately, for most of users it's not a case and everything should work fine. But we put work "unsafe" in the module parameter name to warn users about possible problems with this feature and encourage update of cephfs MDS. Suggested-by: Stéphane Graber <stgraber@ubuntu.com> Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com> Acked-by: Christian Brauner <brauner@kernel.org> Reviewed-by: Xiubo Li <xiubli@redhat.com> Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
1 parent 5ccd853 commit 673478b

3 files changed

Lines changed: 28 additions & 7 deletions

File tree

fs/ceph/mds_client.c

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2928,6 +2928,8 @@ static struct ceph_msg *create_request_message(struct ceph_mds_session *session,
29282928
int ret;
29292929
bool legacy = !(session->s_con.peer_features & CEPH_FEATURE_FS_BTIME);
29302930
u16 request_head_version = mds_supported_head_version(session);
2931+
kuid_t caller_fsuid = req->r_cred->fsuid;
2932+
kgid_t caller_fsgid = req->r_cred->fsgid;
29312933

29322934
ret = set_request_path_attr(mdsc, req->r_inode, req->r_dentry,
29332935
req->r_parent, req->r_path1, req->r_ino1.ino,
@@ -3025,12 +3027,24 @@ static struct ceph_msg *create_request_message(struct ceph_mds_session *session,
30253027
!test_bit(CEPHFS_FEATURE_HAS_OWNER_UIDGID, &session->s_features)) {
30263028
WARN_ON_ONCE(!IS_CEPH_MDS_OP_NEWINODE(req->r_op));
30273029

3028-
pr_err_ratelimited_client(cl,
3029-
"idmapped mount is used and CEPHFS_FEATURE_HAS_OWNER_UIDGID"
3030-
" is not supported by MDS. Fail request with -EIO.\n");
3030+
if (enable_unsafe_idmap) {
3031+
pr_warn_once_client(cl,
3032+
"idmapped mount is used and CEPHFS_FEATURE_HAS_OWNER_UIDGID"
3033+
" is not supported by MDS. UID/GID-based restrictions may"
3034+
" not work properly.\n");
30313035

3032-
ret = -EIO;
3033-
goto out_err;
3036+
caller_fsuid = from_vfsuid(req->r_mnt_idmap, &init_user_ns,
3037+
VFSUIDT_INIT(req->r_cred->fsuid));
3038+
caller_fsgid = from_vfsgid(req->r_mnt_idmap, &init_user_ns,
3039+
VFSGIDT_INIT(req->r_cred->fsgid));
3040+
} else {
3041+
pr_err_ratelimited_client(cl,
3042+
"idmapped mount is used and CEPHFS_FEATURE_HAS_OWNER_UIDGID"
3043+
" is not supported by MDS. Fail request with -EIO.\n");
3044+
3045+
ret = -EIO;
3046+
goto out_err;
3047+
}
30343048
}
30353049

30363050
/*
@@ -3082,9 +3096,9 @@ static struct ceph_msg *create_request_message(struct ceph_mds_session *session,
30823096
lhead->mdsmap_epoch = cpu_to_le32(mdsc->mdsmap->m_epoch);
30833097
lhead->op = cpu_to_le32(req->r_op);
30843098
lhead->caller_uid = cpu_to_le32(from_kuid(&init_user_ns,
3085-
req->r_cred->fsuid));
3099+
caller_fsuid));
30863100
lhead->caller_gid = cpu_to_le32(from_kgid(&init_user_ns,
3087-
req->r_cred->fsgid));
3101+
caller_fsgid));
30883102
lhead->ino = cpu_to_le64(req->r_deleg_ino);
30893103
lhead->args = req->r_args;
30903104

fs/ceph/mds_client.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,4 +619,6 @@ static inline int ceph_wait_on_async_create(struct inode *inode)
619619
extern int ceph_wait_on_conflict_unlink(struct dentry *dentry);
620620
extern u64 ceph_get_deleg_ino(struct ceph_mds_session *session);
621621
extern int ceph_restore_deleg_ino(struct ceph_mds_session *session, u64 ino);
622+
623+
extern bool enable_unsafe_idmap;
622624
#endif

fs/ceph/super.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1681,6 +1681,11 @@ static const struct kernel_param_ops param_ops_mount_syntax = {
16811681
module_param_cb(mount_syntax_v1, &param_ops_mount_syntax, &mount_support, 0444);
16821682
module_param_cb(mount_syntax_v2, &param_ops_mount_syntax, &mount_support, 0444);
16831683

1684+
bool enable_unsafe_idmap = false;
1685+
module_param(enable_unsafe_idmap, bool, 0644);
1686+
MODULE_PARM_DESC(enable_unsafe_idmap,
1687+
"Allow to use idmapped mounts with MDS without CEPHFS_FEATURE_HAS_OWNER_UIDGID");
1688+
16841689
module_init(init_ceph);
16851690
module_exit(exit_ceph);
16861691

0 commit comments

Comments
 (0)