Skip to content

Commit ee73091

Browse files
committed
libcontainer: mark all non-stdio fds O_CLOEXEC before spawning init
Given the core issue in GHSA-xr7r-f8xq-vfvv was that we were unknowingly leaking file descriptors to "runc init", it seems prudent to make sure we proactively prevent this in the future. The solution is to simply mark all non-stdio file descriptors as O_CLOEXEC before we spawn "runc init". For libcontainer library users, this could result in unrelated files being marked as O_CLOEXEC -- however (for the same reason we are doing this for runc), for security reasons those files should've been marked as O_CLOEXEC anyway. Fixes: GHSA-xr7r-f8xq-vfvv CVE-2024-21626 Signed-off-by: Aleksa Sarai <[email protected]>
1 parent 89c93dd commit ee73091

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

libcontainer/container_linux.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,15 @@ func (c *Container) start(process *Process) (retErr error) {
332332
}()
333333
}
334334

335+
// Before starting "runc init", mark all non-stdio open files as O_CLOEXEC
336+
// to make sure we don't leak any files into "runc init". Any files to be
337+
// passed to "runc init" through ExtraFiles will get dup2'd by the Go
338+
// runtime and thus their O_CLOEXEC flag will be cleared. This is some
339+
// additional protection against attacks like CVE-2024-21626, by making
340+
// sure we never leak files to "runc init" we didn't intend to.
341+
if err := utils.CloseExecFrom(3); err != nil {
342+
return fmt.Errorf("unable to mark non-stdio fds as cloexec: %w", err)
343+
}
335344
if err := parent.start(); err != nil {
336345
return fmt.Errorf("unable to start container process: %w", err)
337346
}

0 commit comments

Comments
 (0)