]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
librbd: fix use-after-free on ictx in list_descendants()
authorWang ShuaiChao <wangshuaich@chinatelecom.cn>
Tue, 7 Sep 2021 08:43:11 +0000 (16:43 +0800)
committerIlya Dryomov <idryomov@gmail.com>
Tue, 7 Sep 2021 19:03:12 +0000 (21:03 +0200)
Ictx is deleted when "ictx->state->open()" and "ictx->state->close()"
fail, and then "lderr(ictx->cct)" crashes.

Fixes: https://tracker.ceph.com/issues/52522
Signed-off-by: Wang ShuaiChao <wangshuaich@chinatelecom.cn>
src/librbd/api/Image.cc

index eab7efdb2647d2cc2e452b2f6c442707946be024..4be9e111b87441b21351666c8546794d70c768b2 100644 (file)
@@ -311,12 +311,13 @@ int Image<I>::list_descendants(
     std::vector<librbd::linked_image_spec_t> *images) {
   ImageCtx *ictx = new librbd::ImageCtx("", image_id, nullptr,
                                         io_ctx, true);
+  CephContext *cct = ictx->cct;
   int r = ictx->state->open(OPEN_FLAG_SKIP_OPEN_PARENT);
   if (r < 0) {
     if (r == -ENOENT) {
       return 0;
     }
-    lderr(ictx->cct) << "failed to open descendant " << image_id
+    lderr(cct) << "failed to open descendant " << image_id
                      << " from pool " << io_ctx.get_pool_name() << ":"
                      << cpp_strerror(r) << dendl;
     return r;
@@ -326,7 +327,7 @@ int Image<I>::list_descendants(
 
   int r1 = ictx->state->close();
   if (r1 < 0) {
-    lderr(ictx->cct) << "error when closing descendant " << image_id
+    lderr(cct) << "error when closing descendant " << image_id
                      << " from pool " << io_ctx.get_pool_name() << ":"
                      << cpp_strerror(r) << dendl;
   }