From 31c027df7c89f561bdb3d84e6eb6ec7a7ea69511 Mon Sep 17 00:00:00 2001 From: Josh Seba Date: Thu, 24 Aug 2023 10:47:41 -0700 Subject: [PATCH] Keep spec-file FD alive past point of exec as nobody The Go runtime can run GC at any point once it falls into the branch of `setupRoot && !rootless && !applyCaps`, so `specFile` becomes eligible for closing. This results in the occasional crash on re-exec where the FD was recycled for the proc-mount-sync-fd pipe created in that branch and causes the seek back to 0 to re-read the spec to fail with an ESPIPE error. --- runsc/cmd/boot.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/runsc/cmd/boot.go b/runsc/cmd/boot.go index 3b08f329a..5a6248bf5 100644 --- a/runsc/cmd/boot.go +++ b/runsc/cmd/boot.go @@ -293,6 +293,11 @@ func (b *Boot) Execute(_ context.Context, f *flag.FlagSet, args ...any) subcomma // because the ReadSpecFromFile function seeks to the beginning // of the file before reading. util.Fatalf("callSelfAsNobody(%v): %v", args, callSelfAsNobody(args)) + + // This prevents the specFile finalizer from running and closed + // the specFD, which we have passed to ourselves when + // re-execing. + runtime.KeepAlive(specFile) panic("unreachable") } }