Skip to content

Commit de57e24

Browse files
committed
add missing O_CLOEXEC to open calls
The go std os package to will always make sure to use O_CLOEXEC, however in cases where we directly call unix.Open() we need to pass that flag explicitly. I looked at this as there was a report of a leaked fd on the pasta list, though I am not sure this will address it. But anyway doing this should be rather safe and avoid leaks into other processes. Signed-off-by: Paul Holzinger <pholzing@redhat.com> (cherry picked from commit d20933d) Signed-off-by: Paul Holzinger <pholzing@redhat.com>
1 parent 37fad4d commit de57e24

4 files changed

Lines changed: 4 additions & 4 deletions

File tree

cmd/rootlessport/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ outer:
201201
_ = os.Remove(socketfile)
202202
// workaround to bypass the 108 char socket path limit
203203
// open the fd and use the path to the fd as bind argument
204-
fd, err := unix.Open(socketDir, unix.O_PATH, 0)
204+
fd, err := unix.Open(socketDir, unix.O_PATH|unix.O_CLOEXEC, 0)
205205
if err != nil {
206206
return err
207207
}

libpod/oci_conmon_attach_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
)
1111

1212
func openUnixSocket(path string) (*net.UnixConn, error) {
13-
fd, err := unix.Open(path, unix.O_PATH, 0)
13+
fd, err := unix.Open(path, unix.O_PATH|unix.O_CLOEXEC, 0)
1414
if err != nil {
1515
return nil, err
1616
}

pkg/pidhandle/pidhandle_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func NewPIDHandleFromString(pid int, pidData string) (PIDHandle, error) {
118118
return nil, err
119119
}
120120
defer unix.Close(fd)
121-
pidfd, err := openByHandleAt(fd, fh, 0)
121+
pidfd, err := openByHandleAt(fd, fh, unix.O_CLOEXEC)
122122
if err != nil {
123123
if err == unix.ESTALE {
124124
h.normalHandle.pidData = noSuchProcessID

pkg/specgen/generate/config_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ func addDevice(g *generate.Generator, device string) error {
153153
} else if src == "/dev/fuse" {
154154
// if the user is asking for fuse inside the container
155155
// make sure the module is loaded.
156-
f, err := unix.Open(src, unix.O_RDONLY|unix.O_NONBLOCK, 0)
156+
f, err := unix.Open(src, unix.O_RDONLY|unix.O_NONBLOCK|unix.O_CLOEXEC, 0)
157157
if err == nil {
158158
unix.Close(f)
159159
}

0 commit comments

Comments
 (0)