KEMBAR78
Use PERF_FLAG_FD_CLOEXEC with perf_event_open by olivergillespie · Pull Request #1165 · async-profiler/async-profiler · GitHub
Skip to content

Conversation

@olivergillespie
Copy link
Contributor

Use PERF_FLAG_FD_CLOEXEC with perf_event_open

If the profiled process spawns another process with execve, the child process may be signalled before the signal handler is installed, which will terminate the process.

This flag was introduced in kernel 3.14, so we just don't use it at runtime in that case.

We don't really need the flag in the check/supported calls, but since that's what we'll be using for the real call it may be helpful for catching unexpected errors.

Related issues

#1164

How has this been tested?

Confirmed that this fixes the issue on my kernel 5.10 host with LD_PRELOAD=libasyncProfiler.so ASPROF_COMMAND=start cargo --version (when installed via rustup, cargo has an indirection which uses execve and triggers this issue).

I have not yet tested on other kernels, especially building and running on <3.14, since I don't have a 3.14 host at the moment. I can do that next week, if you don't also have convenient access.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

If the profiled process spawns another process with execve,
the child process may be signalled before the signal handler
is installed, which will terminate the process.

This flag was introduced in kernel 3.14, so we just don't use it
at runtime in that case.
@apangin apangin merged commit f5a7c63 into async-profiler:master Mar 10, 2025
10 checks passed
@olivergillespie olivergillespie deleted the cloexec branch March 10, 2025 11:02
krk pushed a commit to krk/async-profiler that referenced this pull request Mar 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants