Skip to content

Commit e9665f4

Browse files
committed
init: don't special-case logrus fds
We close the logfd before execve so there's no need to special case it. In addition, it turns out that (*os.File).Fd() doesn't handle the case where the file was closed and so it seems suspect to use that kind of check. Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
1 parent 683ad2f commit e9665f4

File tree

2 files changed

+0
-17
lines changed

2 files changed

+0
-17
lines changed

libcontainer/logs/logs.go

-9
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,10 @@ import (
44
"bufio"
55
"encoding/json"
66
"io"
7-
"os"
87

98
"github.com/sirupsen/logrus"
109
)
1110

12-
// IsLogrusFd returns whether the provided fd matches the one that logrus is
13-
// currently outputting to. This should only ever be called by UnsafeCloseFrom
14-
// from `runc init`.
15-
func IsLogrusFd(fd uintptr) bool {
16-
file, ok := logrus.StandardLogger().Out.(*os.File)
17-
return ok && file.Fd() == fd
18-
}
19-
2011
func ForwardLogs(logPipe io.ReadCloser) chan error {
2112
done := make(chan error, 1)
2213
s := bufio.NewScanner(logPipe)

libcontainer/utils/utils_unix.go

-8
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import (
1010
_ "unsafe" // for go:linkname
1111

1212
"golang.org/x/sys/unix"
13-
14-
"github.com/opencontainers/runc/libcontainer/logs"
1513
)
1614

1715
// EnsureProcHandle returns whether or not the given file handle is on procfs.
@@ -102,12 +100,6 @@ func UnsafeCloseFrom(minFd int) error {
102100
// don't have any choice.
103101
return
104102
}
105-
if logs.IsLogrusFd(uintptr(fd)) {
106-
// Do not close the logrus output fd. We cannot exec a pipe, and
107-
// the contents are quite limited (very little attacker control,
108-
// JSON-encoded) making shellcode attacks unlikely.
109-
return
110-
}
111103
// There's nothing we can do about errors from close(2), and the
112104
// only likely error to be seen is EBADF which indicates the fd was
113105
// already closed (in which case, we got what we wanted).

0 commit comments

Comments
 (0)