]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librgw: treat empty root path as "/" on mount 43968/head
authorMatt Benjamin <mbenjamin@redhat.com>
Tue, 2 Nov 2021 13:47:31 +0000 (09:47 -0400)
committerCory Snyder <csnyder@iland.com>
Tue, 16 Nov 2021 15:26:38 +0000 (10:26 -0500)
This prevents an invalid access (and possible crash) when path is
given as "" in ganesha.conf.

Fixes: https://tracker.ceph.com/issues/53030
Signed-off-by: Matt Benjamin <mbenjamin@redhat.com>
(cherry picked from commit 8cee384cb25b29e532f49a67cc7edd2ff3cd2927)

src/rgw/rgw_file.cc
src/rgw/rgw_file.h
src/test/librgw_file_nfsns.cc

index b9b2b3cbd703471fe5d20577a3f8a376137a8d1b..c364475368a5523670203a8c1183a35e24a22497 100644 (file)
@@ -2061,10 +2061,21 @@ int rgw_mount2(librgw_t rgw, const char *uid, const char *acc_key,
 {
   int rc = 0;
 
-  /* stash access data for "mount" */
-  RGWLibFS* new_fs = new RGWLibFS(static_cast<CephContext*>(rgw), uid, acc_key,
-                                 sec_key, root);
-  ceph_assert(new_fs);
+  /* if the config has no value for path/root, choose "/" */
+  RGWLibFS* new_fs{nullptr};
+  if(root &&
+     (!strcmp(root, ""))) {
+    /* stash access data for "mount" */
+    new_fs = new RGWLibFS(
+      static_cast<CephContext*>(rgw), uid, acc_key, sec_key, "/");
+  }
+  else {
+    /* stash access data for "mount" */
+    new_fs = new RGWLibFS(
+      static_cast<CephContext*>(rgw), uid, acc_key, sec_key, root);
+  }
+
+  ceph_assert(new_fs); /* should we be using ceph_assert? */
 
   const DoutPrefix dp(rgwlib.get_store()->ctx(), dout_subsys, "rgw mount2: ");
   rc = new_fs->authorize(&dp, rgwlib.get_store());
index 60845d9d896b5c984c719e4a39fae8104690890c..d716f533999762d27ef3ba6d07ef67dd6a8fb497 100644 (file)
@@ -371,6 +371,10 @@ namespace rgw {
       fh.fh_private = this;
     }
 
+    const std::string& get_name() const {
+      return name;
+    }
+
     const fh_key& get_key() const {
       return fhk;
     }
@@ -1293,6 +1297,8 @@ namespace rgw {
 
     struct rgw_fs* get_fs() { return &fs; }
 
+    RGWFileHandle& get_fh() { return root_fh; }
+
     uint64_t get_fsid() { return root_fh.state.dev; }
 
     RGWUserInfo* get_user() { return &user; }
index b2a8fd27b06ed1fb9e9e3043746c0c13fd74357d..5483dce389a85f05a9fbddac455aef10987763b9 100644 (file)
@@ -187,6 +187,21 @@ TEST(LibRGW, INIT) {
   ASSERT_NE(rgw_h, nullptr);
 }
 
+TEST(LibRGW, MOUNT_NOROOT) {
+  /* do a mount at root="" and verify that it's root is "/" */
+  struct rgw_fs *fs = nullptr;
+  int ret = rgw_mount2(rgw_h, userid.c_str(), access_key.c_str(),
+                       secret_key.c_str(), "", &fs, RGW_MOUNT_FLAG_NONE);
+  ASSERT_EQ(ret, 0);
+  ASSERT_NE(fs, nullptr);
+
+  auto& root_fh = static_cast<RGWLibFS*>(fs->fs_private)->get_fh();
+  ASSERT_EQ(root_fh.get_name(), "/");
+
+  ret = rgw_umount(fs, RGW_UMOUNT_FLAG_NONE);
+  ASSERT_EQ(ret, 0);
+}
+
 TEST(LibRGW, MOUNT) {
   int ret = rgw_mount2(rgw_h, userid.c_str(), access_key.c_str(),
                        secret_key.c_str(), "/", &fs, RGW_MOUNT_FLAG_NONE);