Skip to content

Conversation

@ndossche
Copy link
Member

Commit a211956 fixed a leak by adding a TSRM destructor for the JIT globals in ZTS mode. In case the main thread shuts down the TSRM, it will call all the destructors. The JIT globals destructor will be invoked, but will always access the main thread globals using JIT_G. This means that instead of freeing the JIT globals in the different threads, the one in the main thread is freed repeatedly over and over, crashing PHP. Fix it by always passing the pointer instead of relying on JIT_G.

This can be triggered reliably even when opcache is on. The JIT does not need to be enabled, because the JIT globals are always constructed. To reproduce this locally, I used an Apache worker/event MPM, and send a lot of requests using ApacheBench. Eventually you'll see the segfaults in the error_log file. You can also crash it by stopping the Apache server. Other SAPIs might be affected as well.

This bug exists only in 8.1.17RC1, 8.2.4RC1 and master.
Discovered while working on #10737

Commit a211956 fixed a leak by adding a TSRM destructor for the
JIT globals in ZTS mode. In case the main thread shuts down the TSRM, it
will call all the destructors. The JIT globals destructor will be
invoked, but will always access the main thread globals using JIT_G.
This means that instead of freeing the JIT globals in the different
threads, the one in the main thread is freed repeatedly over and over,
crashing PHP. Fix it by always passing the pointer instead of relying on
JIT_G.
Copy link
Member

@dstogov dstogov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks right

@ndossche ndossche closed this in b3e28e2 Mar 13, 2023
saundefined pushed a commit that referenced this pull request Mar 13, 2023
Commit a211956 fixed a leak by adding a TSRM destructor for the
JIT globals in ZTS mode. In case the main thread shuts down the TSRM, it
will call all the destructors. The JIT globals destructor will be
invoked, but will always access the main thread globals using JIT_G.
This means that instead of freeing the JIT globals in the different
threads, the one in the main thread is freed repeatedly over and over,
crashing PHP. Fix it by always passing the pointer instead of relying on
JIT_G.

Closes GH-10835.

(cherry picked from commit b3e28e2)
patrickallaert pushed a commit that referenced this pull request Mar 14, 2023
Commit a211956 fixed a leak by adding a TSRM destructor for the
JIT globals in ZTS mode. In case the main thread shuts down the TSRM, it
will call all the destructors. The JIT globals destructor will be
invoked, but will always access the main thread globals using JIT_G.
This means that instead of freeing the JIT globals in the different
threads, the one in the main thread is freed repeatedly over and over,
crashing PHP. Fix it by always passing the pointer instead of relying on
JIT_G.

Closes GH-10835.

(cherry picked from commit b3e28e2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants