From 8cee384cb25b29e532f49a67cc7edd2ff3cd2927 Mon Sep 17 00:00:00 2001 From: Matt Benjamin Date: Tue, 2 Nov 2021 09:47:31 -0400 Subject: [PATCH] librgw: treat empty root path as "/" on mount 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 --- src/rgw/rgw_file.cc | 19 +++++++++++++++---- src/rgw/rgw_file.h | 6 ++++++ src/test/librgw_file_nfsns.cc | 15 +++++++++++++++ 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/rgw/rgw_file.cc b/src/rgw/rgw_file.cc index 48474c9fecc08..8fe95b964a60e 100644 --- a/src/rgw/rgw_file.cc +++ b/src/rgw/rgw_file.cc @@ -2043,10 +2043,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(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(rgw), uid, acc_key, sec_key, "/"); + } + else { + /* stash access data for "mount" */ + new_fs = new RGWLibFS( + static_cast(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()); diff --git a/src/rgw/rgw_file.h b/src/rgw/rgw_file.h index b5ab94986dcd6..6e909f3ee172f 100644 --- a/src/rgw/rgw_file.h +++ b/src/rgw/rgw_file.h @@ -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; } @@ -1291,6 +1295,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->get_info(); } diff --git a/src/test/librgw_file_nfsns.cc b/src/test/librgw_file_nfsns.cc index c1e9c35c58b58..3adcc2d3ec6c6 100644 --- a/src/test/librgw_file_nfsns.cc +++ b/src/test/librgw_file_nfsns.cc @@ -189,6 +189,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(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); -- 2.39.5