Skip to content

Commit 139c55f

Browse files
kotreshhrSasha Levin
authored andcommitted
ceph: fix multifs mds auth caps issue
[ Upstream commit 22c73d5 ] The mds auth caps check should also validate the fsname along with the associated caps. Not doing so would result in applying the mds auth caps of one fs on to the other fs in a multifs ceph cluster. The bug causes multiple issues w.r.t user authentication, following is one such example. Steps to Reproduce (on vstart cluster): 1. Create two file systems in a cluster, say 'fsname1' and 'fsname2' 2. Authorize read only permission to the user 'client.usr' on fs 'fsname1' $ceph fs authorize fsname1 client.usr / r 3. Authorize read and write permission to the same user 'client.usr' on fs 'fsname2' $ceph fs authorize fsname2 client.usr / rw 4. Update the keyring $ceph auth get client.usr >> ./keyring With above permssions for the user 'client.usr', following is the expectation. a. The 'client.usr' should be able to only read the contents and not allowed to create or delete files on file system 'fsname1'. b. The 'client.usr' should be able to read/write on file system 'fsname2'. But, with this bug, the 'client.usr' is allowed to read/write on file system 'fsname1'. See below. 5. Mount the file system 'fsname1' with the user 'client.usr' $sudo bin/mount.ceph usr@.fsname1=/ /kmnt_fsname1_usr/ 6. Try creating a file on file system 'fsname1' with user 'client.usr'. This should fail but passes with this bug. $touch /kmnt_fsname1_usr/file1 7. Mount the file system 'fsname1' with the user 'client.admin' and create a file. $sudo bin/mount.ceph admin@.fsname1=/ /kmnt_fsname1_admin $echo "data" > /kmnt_fsname1_admin/admin_file1 8. Try removing an existing file on file system 'fsname1' with the user 'client.usr'. This shoudn't succeed but succeeds with the bug. $rm -f /kmnt_fsname1_usr/admin_file1 For more information, please take a look at the corresponding mds/fuse patch and tests added by looking into the tracker mentioned below. v2: Fix a possible null dereference in doutc v3: Don't store fsname from mdsmap, validate against ceph_mount_options's fsname and use it v4: Code refactor, better warning message and fix possible compiler warning [ Slava.Dubeyko: "fsname check failed" -> "fsname mismatch" ] Link: https://tracker.ceph.com/issues/72167 Signed-off-by: Kotresh HR <khiremat@redhat.com> Reviewed-by: Viacheslav Dubeyko <Slava.Dubeyko@ibm.com> Signed-off-by: Ilya Dryomov <idryomov@gmail.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent f6e98c5 commit 139c55f

File tree

4 files changed

+35
-15
lines changed

4 files changed

+35
-15
lines changed

fs/ceph/mds_client.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5649,11 +5649,19 @@ static int ceph_mds_auth_match(struct ceph_mds_client *mdsc,
56495649
u32 caller_uid = from_kuid(&init_user_ns, cred->fsuid);
56505650
u32 caller_gid = from_kgid(&init_user_ns, cred->fsgid);
56515651
struct ceph_client *cl = mdsc->fsc->client;
5652+
const char *fs_name = mdsc->fsc->mount_options->mds_namespace;
56525653
const char *spath = mdsc->fsc->mount_options->server_path;
56535654
bool gid_matched = false;
56545655
u32 gid, tlen, len;
56555656
int i, j;
56565657

5658+
doutc(cl, "fsname check fs_name=%s match.fs_name=%s\n",
5659+
fs_name, auth->match.fs_name ? auth->match.fs_name : "");
5660+
if (auth->match.fs_name && strcmp(auth->match.fs_name, fs_name)) {
5661+
/* fsname mismatch, try next one */
5662+
return 0;
5663+
}
5664+
56575665
doutc(cl, "match.uid %lld\n", auth->match.uid);
56585666
if (auth->match.uid != MDS_AUTH_UID_ANY) {
56595667
if (auth->match.uid != caller_uid)

fs/ceph/mdsmap.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,10 +353,22 @@ struct ceph_mdsmap *ceph_mdsmap_decode(struct ceph_mds_client *mdsc, void **p,
353353
__decode_and_drop_type(p, end, u8, bad_ext);
354354
}
355355
if (mdsmap_ev >= 8) {
356+
u32 fsname_len;
356357
/* enabled */
357358
ceph_decode_8_safe(p, end, m->m_enabled, bad_ext);
358359
/* fs_name */
359-
ceph_decode_skip_string(p, end, bad_ext);
360+
ceph_decode_32_safe(p, end, fsname_len, bad_ext);
361+
362+
/* validate fsname against mds_namespace */
363+
if (!namespace_equals(mdsc->fsc->mount_options, *p,
364+
fsname_len)) {
365+
pr_warn_client(cl, "fsname %*pE doesn't match mds_namespace %s\n",
366+
(int)fsname_len, (char *)*p,
367+
mdsc->fsc->mount_options->mds_namespace);
368+
goto bad;
369+
}
370+
/* skip fsname after validation */
371+
ceph_decode_skip_n(p, end, fsname_len, bad);
360372
}
361373
/* damaged */
362374
if (mdsmap_ev >= 9) {

fs/ceph/super.c

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -246,20 +246,6 @@ static void canonicalize_path(char *path)
246246
path[j] = '\0';
247247
}
248248

249-
/*
250-
* Check if the mds namespace in ceph_mount_options matches
251-
* the passed in namespace string. First time match (when
252-
* ->mds_namespace is NULL) is treated specially, since
253-
* ->mds_namespace needs to be initialized by the caller.
254-
*/
255-
static int namespace_equals(struct ceph_mount_options *fsopt,
256-
const char *namespace, size_t len)
257-
{
258-
return !(fsopt->mds_namespace &&
259-
(strlen(fsopt->mds_namespace) != len ||
260-
strncmp(fsopt->mds_namespace, namespace, len)));
261-
}
262-
263249
static int ceph_parse_old_source(const char *dev_name, const char *dev_name_end,
264250
struct fs_context *fc)
265251
{

fs/ceph/super.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,20 @@ struct ceph_mount_options {
104104
struct fscrypt_dummy_policy dummy_enc_policy;
105105
};
106106

107+
/*
108+
* Check if the mds namespace in ceph_mount_options matches
109+
* the passed in namespace string. First time match (when
110+
* ->mds_namespace is NULL) is treated specially, since
111+
* ->mds_namespace needs to be initialized by the caller.
112+
*/
113+
static inline int namespace_equals(struct ceph_mount_options *fsopt,
114+
const char *namespace, size_t len)
115+
{
116+
return !(fsopt->mds_namespace &&
117+
(strlen(fsopt->mds_namespace) != len ||
118+
strncmp(fsopt->mds_namespace, namespace, len)));
119+
}
120+
107121
/* mount state */
108122
enum {
109123
CEPH_MOUNT_MOUNTING,

0 commit comments

Comments
 (0)