Skip to content

Commit d33e6b1

Browse files
nixpanicmergify[bot]
authored andcommitted
rbd: validate IOContext before getting the list of trashed images
`ensureImageCleanup()` can cause a panic when an image was deleted, but the journal still contained a reference. By opening the IOContext before using, an error may be returned instead of a panic when using a `nil` or freed IOContext. Signed-off-by: Niels de Vos <[email protected]>
1 parent 9267210 commit d33e6b1

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

internal/rbd/controllerserver.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -881,9 +881,9 @@ func (cs *ControllerServer) checkErrAndUndoReserve(
881881
}
882882

883883
if errors.Is(err, ErrImageNotFound) {
884-
err = rbdVol.ensureImageCleanup(ctx)
885-
if err != nil {
886-
return nil, status.Error(codes.Internal, err.Error())
884+
notFoundErr := rbdVol.ensureImageCleanup(ctx)
885+
if notFoundErr != nil {
886+
return nil, status.Errorf(codes.Internal, "failed to cleanup image %q: %v", rbdVol, notFoundErr)
887887
}
888888
} else {
889889
// All errors other than ErrImageNotFound should return an error back to the caller
@@ -1538,11 +1538,6 @@ func cleanUpImageAndSnapReservation(ctx context.Context, rbdSnap *rbdSnapshot, c
15381538
}
15391539
defer rbdVol.Destroy(ctx)
15401540

1541-
err = rbdVol.openIoctx()
1542-
if err != nil {
1543-
return status.Error(codes.Internal, err.Error())
1544-
}
1545-
15461541
// cleanup the image from trash if the error is image not found.
15471542
err = rbdVol.ensureImageCleanup(ctx)
15481543
if err != nil {

internal/rbd/rbd_util.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,11 @@ func isCephMgrSupported(ctx context.Context, clusterID string, err error) bool {
621621
// ensureImageCleanup finds image in trash and if found removes it
622622
// from trash.
623623
func (ri *rbdImage) ensureImageCleanup(ctx context.Context) error {
624+
err := ri.openIoctx()
625+
if err != nil {
626+
return err
627+
}
628+
624629
trashInfoList, err := librbd.GetTrashList(ri.ioctx)
625630
if err != nil {
626631
log.ErrorLog(ctx, "failed to list images in trash: %v", err)

0 commit comments

Comments
 (0)