From: Kotresh HR Date: Fri, 26 Jul 2024 14:48:04 +0000 (+0530) Subject: client: Fix leading / issue with mds_check_access X-Git-Tag: v18.2.5~145^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=9a0d72c4294b94dcc17a72e38eb573b702ac1b48;p=ceph.git 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) --- diff --git a/src/client/Client.cc b/src/client/Client.cc index a84e69f38f2fd..0d295d203f551 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -5910,6 +5910,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; @@ -8006,6 +8011,10 @@ bool Client::make_absolute_path_string(Inode *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; } @@ -8053,8 +8062,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; @@ -10300,8 +10307,6 @@ int Client::_open(Inode *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;