FPM: fpm_request_end() releases the scoreboard writer lock without acquiring it (8.6 regression)
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 88/100
Research direction
Read sapi/fpm/fpm/fpm_request.c around fpm_request_end() and compare its scoreboard calls with the begin/commit pairs in the same file. Check the lock behavior in sapi/fpm/fpm/fpm_scoreboard.c; the issue identifies the missing call and its safe placement after fpm_scoreboard_proc_release(proc). Done when request end acquires the writer lock before committing, with the proc == NULL return path unchanged.
Written by the indexing model from the issue text.
Description
Description
In PHP 8.6 the FPM scoreboard write path was split into two halves:
fpm_scoreboard_update_begin()acquiresscoreboard->writer_activeand waits forreader_count == 0.fpm_scoreboard_update_commit()writes the shared counters and then releaseswriter_active(fpm_unlock(scoreboard->writer_active);,sapi/fpm/fpm/fpm_scoreboard.c:218).
Every writer pairs the two calls — e.g. in sapi/fpm/fpm/fpm_request.c at lines 45/58 and 77/102 — except fpm_request_end(), which calls only commit:
sapi/fpm/fpm/fpm_request.c:205
fpm_scoreboard_update_commit(-1, -1, -1, -1, -1, -1, -1, proc->memory, FPM_SCOREBOARD_ACTION_SET, NULL);
with no preceding fpm_scoreboard_update_begin().
Because commit ends by releasing writer_active, at the end of every request fpm_request_end():
- releases a writer lock it never acquired — if another process legitimately holds
writer_activeat that moment, this clears it, letting a second writer and readers run concurrently with it; and - updates the shared counters (
memory_peak,active_max, ...) without first ensuringreader_count == 0, so a concurrent?fullstatus reader (fpm_scoreboard_copy) can read a torn scoreboard.
This is a correctness regression from the 8.6 begin/commit split (8.3 has no such split — it uses a single fpm_scoreboard_update()), not a memory-safety issue: the scoreboard is a fixed shared struct of scalars, so the consequences are limited to garbled status/metrics and a possible writer-lock imbalance.
Suggested fix
Add the matching fpm_scoreboard_update_begin(NULL) immediately before the commit in fpm_request_end() (after fpm_scoreboard_proc_release(proc)), so the writer lock is held across the shared-counter update. Placing begin right before commit (rather than at function entry, as the other sites do) avoids leaking the writer lock on the proc == NULL early-return path. PR to follow.
PHP Version
PHP-8.6 branch at 47abe238897 (PHP 8.6.2-dev (fpm-fcgi), NTS DEBUG).
Operating System
Linux
- Dominant language
- C
- Stars
- 41.9k
- Forks
- 8.5k
- Avg merge
- 2d 16h
- Merged PRs (30d)
- 117
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from php/php-src
-
FPM/FastCGI: FCGI_HASH_FUNC reads var[3] for 3-character names (guarded only by var_len < 3)Possibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
php/php-src#26067 · 4 comments ·
Maintainers usually reply within 1 day
-
Bug Status: Verified
Difficulty 1/5 Under an hour Newbie friendliness 74/100
Maintainers usually reply within 1 day
-
getimagesize(): WebP VP8 dimensions are accepted with an invalid start codePossibly taken @lazerg claimed this 5 days ago. OpenBug Status: Needs Triage
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
Similar issues
-
CF_CFDP_S_SendFileData computes the file checksum from the SB buffer after CFE_SB_TransmitBufferOpen
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
389ds/389-ds-base#8251 ·
Maintainers usually reply within 1 day
-
bug data-types
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
ClickHouse/clickhouse-cpp#645 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
ROCm/hrx-system#3628 ·
Maintainers usually reply within 1 day