ceph-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ceph: Fix multifs mds auth caps issue
@ 2025-07-29 17:02 khiremat
  2025-07-29 18:26 ` Viacheslav Dubeyko
  0 siblings, 1 reply; 11+ messages in thread
From: khiremat @ 2025-07-29 17:02 UTC (permalink / raw)
  To: ceph-devel
  Cc: Slava.Dubeyko, idryomov, amarkuze, pdonnell, vshankar, Kotresh HR

From: Kotresh HR <khiremat@redhat.com>

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 patch fixes the same.

Steps to Reproduce (on vstart cluster):
1. Create two file systems in a cluster, say 'a' and 'b'
2. ceph fs authorize a client.usr / r
3. ceph fs authorize b client.usr / rw
4. ceph auth get client.usr >> ./keyring
5. sudo bin/mount.ceph usr@.a=/ /kmnt_a_usr/
6. touch /kmnt_a_usr/file1 (SHOULD NOT BE ALLOWED)
7. sudo bin/mount.ceph admin@.a=/ /kmnt_a_admin
8. echo "data" > /kmnt_a_admin/admin_file1
9. rm -f /kmnt_a_usr/admin_file1 (SHOULD NOT BE ALLOWED)

URL: https://tracker.ceph.com/issues/72167
Signed-off-by: Kotresh HR <khiremat@redhat.com>
---
 fs/ceph/mds_client.c | 10 ++++++++++
 fs/ceph/mdsmap.c     | 11 ++++++++++-
 fs/ceph/mdsmap.h     |  1 +
 3 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c
index 9eed6d73a508..ba91f3360ff6 100644
--- a/fs/ceph/mds_client.c
+++ b/fs/ceph/mds_client.c
@@ -5640,11 +5640,21 @@ static int ceph_mds_auth_match(struct ceph_mds_client *mdsc,
 	u32 caller_uid = from_kuid(&init_user_ns, cred->fsuid);
 	u32 caller_gid = from_kgid(&init_user_ns, cred->fsgid);
 	struct ceph_client *cl = mdsc->fsc->client;
+	const char *fs_name = mdsc->mdsmap->fs_name;
 	const char *spath = mdsc->fsc->mount_options->server_path;
 	bool gid_matched = false;
 	u32 gid, tlen, len;
 	int i, j;
 
+	if (auth->match.fs_name && strcmp(auth->match.fs_name, fs_name)) {
+		doutc(cl, "fsname check failed fs_name=%s  match.fs_name=%s\n",
+		      fs_name, auth->match.fs_name);
+		return 0;
+	} else {
+		doutc(cl, "fsname check passed fs_name=%s  match.fs_name=%s\n",
+		      fs_name, auth->match.fs_name);
+	}
+
 	doutc(cl, "match.uid %lld\n", auth->match.uid);
 	if (auth->match.uid != MDS_AUTH_UID_ANY) {
 		if (auth->match.uid != caller_uid)
diff --git a/fs/ceph/mdsmap.c b/fs/ceph/mdsmap.c
index 8109aba66e02..f1431ba0b33e 100644
--- a/fs/ceph/mdsmap.c
+++ b/fs/ceph/mdsmap.c
@@ -356,7 +356,15 @@ struct ceph_mdsmap *ceph_mdsmap_decode(struct ceph_mds_client *mdsc, void **p,
 		/* enabled */
 		ceph_decode_8_safe(p, end, m->m_enabled, bad_ext);
 		/* fs_name */
-		ceph_decode_skip_string(p, end, bad_ext);
+	        m->fs_name = ceph_extract_encoded_string(p, end, NULL, GFP_NOFS);
+	        if (IS_ERR(m->fs_name)) {
+			err = PTR_ERR(m->fs_name);
+			m->fs_name = NULL;
+			if (err == -ENOMEM)
+				goto out_err;
+			else
+				goto bad;
+	        }
 	}
 	/* damaged */
 	if (mdsmap_ev >= 9) {
@@ -418,6 +426,7 @@ void ceph_mdsmap_destroy(struct ceph_mdsmap *m)
 		kfree(m->m_info);
 	}
 	kfree(m->m_data_pg_pools);
+	kfree(m->fs_name);
 	kfree(m);
 }
 
diff --git a/fs/ceph/mdsmap.h b/fs/ceph/mdsmap.h
index 1f2171dd01bf..acb0a2a3627a 100644
--- a/fs/ceph/mdsmap.h
+++ b/fs/ceph/mdsmap.h
@@ -45,6 +45,7 @@ struct ceph_mdsmap {
 	bool m_enabled;
 	bool m_damaged;
 	int m_num_laggy;
+	char *fs_name;
 };
 
 static inline struct ceph_entity_addr *
-- 
2.45.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2025-08-20 19:35 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-29 17:02 [PATCH] ceph: Fix multifs mds auth caps issue khiremat
2025-07-29 18:26 ` Viacheslav Dubeyko
     [not found]   ` <CAPgWtC4s6Yhjp0_pnrcU5Cv3ptLe+4uL6+whQK4y398JCcNLnA@mail.gmail.com>
2025-08-01 20:00     ` Viacheslav Dubeyko
     [not found]       ` <CAPgWtC5muDGHsd5A=5bE4OCxYtiKRTLUa1KjU348qnfPDb54_Q@mail.gmail.com>
2025-08-11 21:20         ` Viacheslav Dubeyko
2025-08-12  9:07           ` Kotresh Hiremath Ravishankar
2025-08-12 19:52             ` Viacheslav Dubeyko
2025-08-13  7:28               ` Kotresh Hiremath Ravishankar
2025-08-13 18:22                 ` Viacheslav Dubeyko
2025-08-19 14:01                   ` Kotresh Hiremath Ravishankar
2025-08-19 18:03                     ` Viacheslav Dubeyko
2025-08-20 19:35                       ` Ilya Dryomov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).