Virt-Handler VMI Lifecycle Endpoints β Nil-Pointer Panic#
virt-handler exposes a REST API for in-node VMI operations. The LifecycleHandler struct (package pkg/virt-handler/rest) handles these requests and holds a reference to a node-local vmiStore (cache.Store). Every action handler β PauseHandler, UnpauseHandler, FreezeHandler, UnfreezeHandler, ResetHandler, SoftRebootHandler, and the guest-info/user/filesystem/SEV/backup handlers β routes through the shared helper getVMILauncherClient.
The Panic: Root Cause#
getVMILauncherClient first calls getVMI, which performs a key lookup (namespace/name) against the node-local vmiStore and never reads the request body. When the VMI is absent from this node's store, getVMI returns:
nilfor the*v1.VirtualMachineInstancehttp.StatusNotFoundas the status code- a non-nil error
getVMILauncherClient then immediately logs the error with :
log.Log.Object(vmi).Reason(err).Error(failedRetrieveVMI)
vmi is nil at this point. log.Log.Object() calls obj.GetObjectMeta() on its argument to extract name, namespace, UID, and kind for structured logging. Because v1.VirtualMachineInstance embeds metav1.ObjectMeta by value, the promoted GetObjectMeta() method is on *ObjectMeta. Calling it via a nil *VirtualMachineInstance pointer dereferences the nil β producing:
panic: runtime error: invalid memory address or nil pointer dereference
in kubevirt.io.(*VirtualMachineInstance).GetObjectMeta.
Affected Handlers#
Every handler that calls getVMILauncherClient is affected when the requested VMI is absent from the local store. This includes PauseHandler, UnpauseHandler, FreezeHandler, UnfreezeHandler, ResetHandler, SoftRebootHandler, GetGuestInfo, GetUsers, GetFilesystems, and the SEV handlers .
Handlers that decode a body (FreezeHandler, SEVInjectLaunchSecretHandler, BackupHandler, RedefineCheckpointHandler) reach their body-decode step after getVMILauncherClient returns a non-nil vmi β so those body-decode paths are safe, but they still panic on the not-found path .
Security Context#
This was reported as finding INFO-11 in the Quarkslab/OSTIF security audit of KubeVirt . Any caller with a valid virt-handler client certificate can trigger the panic with a single request to a VMI name not present on that node. Repeated requests can degrade the handler's HTTP server. The audit's curl reproducer used an empty body, but the body is irrelevant β the panic fires purely from the nil-VMI logging line in getVMILauncherClient .
As of commit 635f26f3, no fix has been merged .
Fix Direction#
The bug is a single-line issue in getVMILauncherClient. The logging call must not pass vmi to log.Log.Object() when vmi is nil. The corrected pattern is to log the key and error without object context before writing the error response β e.g., use log.Log.Reason(err).Error(...) and include the namespace/name key separately.
No changes to the individual action handlers or to getVMI are required.
Key Files#
| File | Purpose |
|---|---|
pkg/virt-handler/rest/lifecycle.go | All lifecycle handlers and getVMILauncherClient |
pkg/virt-handler/rest/common.go | getVMI β local-store lookup, returns nil on miss |
staging/src/kubevirt.io/client-go/log/log.go | FilteredLogger.Object() β dereferences the nil |
vendor/k8s.io/apimachinery/pkg/apis/meta/v1/meta.go | (*ObjectMeta).GetObjectMeta() β the promoted method that panics |