Skip to content

Commit d8edada

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 <[email protected]>
1 parent ee73091 commit d8edada

File tree

2 files changed

+0
-17
lines changed

2 files changed

+0
-17
lines changed

libcontainer/logs/logs.go

Lines changed: 0 additions & 9 deletions
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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ import (
1616
securejoin "github.com/cyphar/filepath-securejoin"
1717
"github.com/sirupsen/logrus"
1818
"golang.org/x/sys/unix"
19-
20-
"github.com/opencontainers/runc/libcontainer/logs"
2119
)
2220

2321
// EnsureProcHandle returns whether or not the given file handle is on procfs.
@@ -142,12 +140,6 @@ func UnsafeCloseFrom(minFd int) error {
142140
// don't have any choice.
143141
return
144142
}
145-
if logs.IsLogrusFd(uintptr(fd)) {
146-
// Do not close the logrus output fd. We cannot exec a pipe, and
147-
// the contents are quite limited (very little attacker control,
148-
// JSON-encoded) making shellcode attacks unlikely.
149-
return
150-
}
151143
// There's nothing we can do about errors from close(2), and the
152144
// only likely error to be seen is EBADF which indicates the fd was
153145
// already closed (in which case, we got what we wanted).

0 commit comments

Comments
 (0)