]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
client: Fix leading / issue with mds_check_access 58982/head
authorKotresh HR <khiremat@redhat.com>
Fri, 26 Jul 2024 14:48:04 +0000 (20:18 +0530)
committerKotresh HR <khiremat@redhat.com>
Wed, 11 Sep 2024 09:16:03 +0000 (14:46 +0530)
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 <khiremat@redhat.com>
(cherry picked from commit 2e2adb2719c40a87d9fc556f5fa492ef6a2580dc)

src/client/Client.cc

index a84e69f38f2fdcca7691a0c805b6d27a0398a924..0d295d203f551afd5e0861d1d9264bafabcfbf8b 100644 (file)
@@ -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;