diff --git a/pkg/sentry/fsimpl/host/host.go b/pkg/sentry/fsimpl/host/host.go index 5087f13c1..c606050a2 100644 --- a/pkg/sentry/fsimpl/host/host.go +++ b/pkg/sentry/fsimpl/host/host.go @@ -108,11 +108,11 @@ type inode struct { inodeRefs // hostFD contains the host fd that this file was originally created from. - // It must be available at time of restore by being set to the same value or - // remapped using restoreKey and vfs.CtxRestoreFilesystemFDMap in the context. + // Upon restore, it must be remapped using restoreKey and vfs.CtxRestoreFilesystemFDMap + // from the restore context. // // This field is initialized at creation time and is immutable. - hostFD int + hostFD int `state:"nosave"` // restoreKey is used to identify the `hostFD` after a restore is performed. restoreKey vfs.RestoreID diff --git a/pkg/sentry/fsimpl/host/save_restore.go b/pkg/sentry/fsimpl/host/save_restore.go index 3cf29b93a..c4845ed78 100644 --- a/pkg/sentry/fsimpl/host/save_restore.go +++ b/pkg/sentry/fsimpl/host/save_restore.go @@ -73,11 +73,10 @@ func (i *inode) beforeSave() { func (i *inode) afterLoad(ctx context.Context) { fdmap := vfs.RestoreFilesystemFDMapFromContext(ctx) fd, ok := fdmap[i.restoreKey] - if ok { - // Remap FD if a new mapping is provided. Otherwise, keep the old FD and - // expect that caller will use the same FDs numbers. - i.hostFD = fd + if !ok { + panic(fmt.Sprintf("no host FD available for %+v, map: %v", i.restoreKey, fdmap)) } + i.hostFD = fd if i.epollable { if err := unix.SetNonblock(i.hostFD, true); err != nil {