Skip to content

Commit 61baa87

Browse files
committed
librbd: clear ctx before initiating close in Image::{aio_,}close()
Image::aio_close() must clear ctx before initiating close. Otherwise the provided callback may see a non-NULL ctx and attempt to close the image again from Image destructor, leading to an invalid memory access as ImageCtx and ImageState are both freed immediately after the image is closed (i.e. before AioCompletion is completed and the callback is executed). The same adjustment is made to Image::close() just for consistency. Fixes: https://tracker.ceph.com/issues/69619 Signed-off-by: Ilya Dryomov <[email protected]>
1 parent a02b9b4 commit 61baa87

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/librbd/librbd.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1704,8 +1704,8 @@ namespace librbd {
17041704
ImageCtx *ictx = (ImageCtx *)ctx;
17051705
tracepoint(librbd, close_image_enter, ictx, ictx->name.c_str(), ictx->id.c_str());
17061706

1707+
ctx = NULL; // before initiating close
17071708
r = ictx->state->close();
1708-
ctx = NULL;
17091709

17101710
tracepoint(librbd, close_image_exit, r);
17111711
}
@@ -1721,9 +1721,9 @@ namespace librbd {
17211721
ImageCtx *ictx = (ImageCtx *)ctx;
17221722
tracepoint(librbd, aio_close_image_enter, ictx, ictx->name.c_str(), ictx->id.c_str(), c->pc);
17231723

1724+
ctx = NULL; // before initiating close
17241725
ictx->state->close(new C_AioCompletion(ictx, librbd::io::AIO_TYPE_CLOSE,
17251726
get_aio_completion(c)));
1726-
ctx = NULL;
17271727

17281728
tracepoint(librbd, aio_close_image_exit, 0);
17291729
return 0;

0 commit comments

Comments
 (0)