daemon: persist teardown fallbacks and reject unsafe import paths
Preserve cleanup after daemon restarts and harden OCI and tar imports against filenames that debugfs cannot encode safely. Mirror tap, loop, and dm teardown identity onto VM.Runtime, teach cleanup and reconcile to fall back to those persisted fields when handles.json is missing or corrupt, and clear the recovery state on stop, error, and delete paths. Reject debugfs-hostile entry names during flattening and in ApplyOwnership itself, then add regression coverage for corrupt handles.json recovery and unsafe import paths. Verified with targeted go tests, make lint-go, make lint-shell, and make build.
This commit is contained in:
parent
86a56fedb3
commit
d743a8ba4b
15 changed files with 272 additions and 81 deletions
|
|
@ -80,7 +80,7 @@ func (s *VMService) startVMLocked(ctx context.Context, vm model.VMRecord, image
|
|||
vm.State = model.VMStateError
|
||||
vm.Runtime.State = model.VMStateError
|
||||
vm.Runtime.LastError = runErr.Error()
|
||||
vm.Runtime.TapDevice = ""
|
||||
clearRuntimeTeardownState(&vm)
|
||||
s.clearVMHandles(vm)
|
||||
if s.store != nil {
|
||||
_ = s.store.UpsertVM(context.Background(), vm)
|
||||
|
|
@ -113,7 +113,7 @@ func (s *VMService) stopVMLocked(ctx context.Context, current model.VMRecord) (v
|
|||
}
|
||||
vm.State = model.VMStateStopped
|
||||
vm.Runtime.State = model.VMStateStopped
|
||||
vm.Runtime.TapDevice = ""
|
||||
clearRuntimeTeardownState(&vm)
|
||||
s.clearVMHandles(vm)
|
||||
if err := s.store.UpsertVM(ctx, vm); err != nil {
|
||||
return model.VMRecord{}, err
|
||||
|
|
@ -138,7 +138,7 @@ func (s *VMService) stopVMLocked(ctx context.Context, current model.VMRecord) (v
|
|||
}
|
||||
vm.State = model.VMStateStopped
|
||||
vm.Runtime.State = model.VMStateStopped
|
||||
vm.Runtime.TapDevice = ""
|
||||
clearRuntimeTeardownState(&vm)
|
||||
s.clearVMHandles(vm)
|
||||
system.TouchNow(&vm)
|
||||
if err := s.store.UpsertVM(ctx, vm); err != nil {
|
||||
|
|
@ -170,7 +170,7 @@ func (s *VMService) killVMLocked(ctx context.Context, current model.VMRecord, si
|
|||
}
|
||||
vm.State = model.VMStateStopped
|
||||
vm.Runtime.State = model.VMStateStopped
|
||||
vm.Runtime.TapDevice = ""
|
||||
clearRuntimeTeardownState(&vm)
|
||||
s.clearVMHandles(vm)
|
||||
if err := s.store.UpsertVM(ctx, vm); err != nil {
|
||||
return model.VMRecord{}, err
|
||||
|
|
@ -200,7 +200,7 @@ func (s *VMService) killVMLocked(ctx context.Context, current model.VMRecord, si
|
|||
}
|
||||
vm.State = model.VMStateStopped
|
||||
vm.Runtime.State = model.VMStateStopped
|
||||
vm.Runtime.TapDevice = ""
|
||||
clearRuntimeTeardownState(&vm)
|
||||
s.clearVMHandles(vm)
|
||||
system.TouchNow(&vm)
|
||||
if err := s.store.UpsertVM(ctx, vm); err != nil {
|
||||
|
|
@ -262,6 +262,7 @@ func (s *VMService) deleteVMLocked(ctx context.Context, current model.VMRecord)
|
|||
if err := s.cleanupRuntime(ctx, vm, false); err != nil {
|
||||
return model.VMRecord{}, err
|
||||
}
|
||||
clearRuntimeTeardownState(&vm)
|
||||
op.stage("delete_store_record")
|
||||
if err := s.store.DeleteVM(ctx, vm.ID); err != nil {
|
||||
return model.VMRecord{}, err
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue