Fix: concurrent exec(2) file descriptor leak
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 9 Mar 2022 16:54:33 +0000 (11:54 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 10 Mar 2022 14:35:05 +0000 (09:35 -0500)
commita6a2e9741597a5310a76d5a11d31f22c5dde9483
treea1b715ec63081517b3fe2517a9b3f53be44b874b
parent037040cb622ad9aabb2fdeb719b3cc167559bf2e
Fix: concurrent exec(2) file descriptor leak

If exec(2) is executed by the application concurrently with LTTng-UST
listener threads between the creation of a file descriptor with
socket(2), recvmsg(2), or pipe(2) and call to fcntl(3) FD_CLOEXEC, those
file descriptors will stay open after the exec, which is not intended.

As a consequence, shared memory files for ring buffers can stay present
on the file system for long-running traced processes.

Use:

- pipe2(2) O_CLOEXEC (supported since Linux 2.6.27, and by FreeBSD),
- socket(2) SOCK_CLOEXEC (supported since Linux 2.6.27, and by FreeBSD),
- recvmsg(2) MSG_CMSG_CLOEXEC (supported since Linux 2.6.23 and by FreeBSD),

rather than fcntl(2) FD_CLOEXEC to make sure the file descriptors are
closed on exec immediately upon their creation.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: Id2167cf99d7cb8a8425fc0dc13745f023a504562
src/common/ringbuffer/shm.c
src/common/ustcomm.c
This page took 0.02591 seconds and 4 git commands to generate.