Skip to content

Commit bcc70e3

Browse files
fvoznikagvisor-bot
authored andcommitted
Make all restored host FDs explicit
This ensures that host FDs are not using some random FD upon restore. All host FDs must be part of the restore FD map that is explicity set, otherwise restore fails. Updates google#1956 PiperOrigin-RevId: 615581166
1 parent 466008a commit bcc70e3

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

pkg/sentry/fsimpl/host/host.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,11 @@ type inode struct {
108108
inodeRefs
109109

110110
// hostFD contains the host fd that this file was originally created from.
111-
// It must be available at time of restore by being set to the same value or
112-
// remapped using restoreKey and vfs.CtxRestoreFilesystemFDMap in the context.
111+
// Upon restore, it must be remapped using restoreKey and vfs.CtxRestoreFilesystemFDMap
112+
// from the restore context.
113113
//
114114
// This field is initialized at creation time and is immutable.
115-
hostFD int
115+
hostFD int `state:"nosave"`
116116

117117
// restoreKey is used to identify the `hostFD` after a restore is performed.
118118
restoreKey vfs.RestoreID

pkg/sentry/fsimpl/host/save_restore.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,10 @@ func (i *inode) beforeSave() {
7373
func (i *inode) afterLoad(ctx context.Context) {
7474
fdmap := vfs.RestoreFilesystemFDMapFromContext(ctx)
7575
fd, ok := fdmap[i.restoreKey]
76-
if ok {
77-
// Remap FD if a new mapping is provided. Otherwise, keep the old FD and
78-
// expect that caller will use the same FDs numbers.
79-
i.hostFD = fd
76+
if !ok {
77+
panic(fmt.Sprintf("no host FD available for %+v, map: %v", i.restoreKey, fdmap))
8078
}
79+
i.hostFD = fd
8180

8281
if i.epollable {
8382
if err := unix.SetNonblock(i.hostFD, true); err != nil {

0 commit comments

Comments
 (0)