From 8773800e941bcde45ab87c62437e72127c905a86 Mon Sep 17 00:00:00 2001 From: Kotresh HR Date: Fri, 26 Jul 2024 20:18:04 +0530 Subject: [PATCH] client: Fix leading / issue with mds_check_access The "Client::mds_check_access" expects the target_path without leading '/' as it eventually calls the "MDSCapMatch::match_path" which expects the target_path passed to be with out leading '/' as well. The single leading '/' was being removed. But absolute path constructed did have leading '//', so removing all the leading '/' was necessary. This causes the clients not to be able to access a particular path even though it has a rw permission on the specific path. The patche fixes the leading '//' issue. Fixes: https://tracker.ceph.com/issues/67212 Signed-off-by: Kotresh HR (cherry picked from commit 2e2adb2719c40a87d9fc556f5fa492ef6a2580dc) --- src/client/Client.cc | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/client/Client.cc b/src/client/Client.cc index 26a8428d94f..e6e487f603a 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -6077,6 +6077,11 @@ int Client::mds_check_access(std::string& path, const UserPerm& perms, int mask) } } + // drop any leading / + while (path.length() && path[0] == '/') { + path = path.substr(1); + } + for (auto& s: cap_auths) { ldout(cct, 20) << __func__ << " auth match path " << s.match.path << " r: " << s.readable << " w: " << s.writeable << dendl; @@ -8101,6 +8106,10 @@ bool Client::make_absolute_path_string(const InodeRef& in, std::string& path) return false; } + // Make sure this function returns path with single leading '/' + if (path.length() && path[0] == '/' && path[1] == '/') + path = path.substr(1); + return true; } @@ -8148,8 +8157,6 @@ int Client::_do_setattr(Inode *in, struct ceph_statx *stx, int mask, std::string path; if (make_absolute_path_string(in, path)) { ldout(cct, 20) << " absolute path: " << path << dendl; - if (path.length()) - path = path.substr(1); // drop leading / res = mds_check_access(path, perms, MAY_WRITE); if (res) { goto out; @@ -10514,8 +10521,6 @@ int Client::_open(const InodeRef& in, int flags, mode_t mode, Fh **fhp, std::string path; if (make_absolute_path_string(in, path)) { ldout(cct, 20) << __func__ << " absolute path: " << path << dendl; - if (path.length()) - path = path.substr(1); // drop leading / result = mds_check_access(path, perms, mask); if (result) { return result; -- 2.39.5