Skip to content

Commit 87373a8

Browse files
nixprimegvisor-bot
authored andcommitted
runsc/cmd: fix unintended FD closing in gofer
PiperOrigin-RevId: 823179726
1 parent 8eca122 commit 87373a8

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

runsc/cmd/gofer.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,6 @@ func (g *Gofer) Execute(_ context.Context, f *flag.FlagSet, args ...any) subcomm
193193
defer cleanupUnmounter()
194194
}
195195
}
196-
goferToHostRPC.Close()
197196
if g.applyCaps {
198197
overrides := g.syncFDs.flags()
199198
overrides["apply-caps"] = "false"
@@ -207,6 +206,11 @@ func (g *Gofer) Execute(_ context.Context, f *flag.FlagSet, args ...any) subcomm
207206
panic("unreachable")
208207
}
209208

209+
// This can't happen until after setCapsAndCallSelf(), since otherwise the
210+
// re-executed gofer may reuse goferToHostRPCFD's file descriptor for an
211+
// unrelated file.
212+
goferToHostRPC.Close()
213+
210214
// Start profiling. This will be a noop if no profiling arguments were passed.
211215
profileOpts := profile.MakeOpts(&g.profileFDs, conf.ProfileGCInterval)
212216
g.stopProfiling = profile.Start(profileOpts)

0 commit comments

Comments
 (0)