FPM: inner prev_execute_data walk in fpm_php_trace_dump() is not depth-bounded

Open Beginner friendly
#26,068 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
74/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
c, php

Research direction

Start with sapi/fpm/fpm/fpm_php_trace.c, especially the inner while (prev) loop at line 126 and the outer callers_limit loop near line 181. Add a bound to the inner walk so cyclic prev_execute_data chains cannot keep the master reading child memory indefinitely. Check the existing FPM trace tests and confirm the walk stops at the bound while normal traces still work.

Written by the indexing model from the issue text.

Description

Description

In fpm_php_trace_dump() (sapi/fpm/fpm/fpm_php_trace.c), the outer frame loop is bounded by callers_limit = request_slowlog_trace_depth (default 20; decremented at sapi/fpm/fpm/fpm_php_trace.c:181).

The inner loop that searches for the nearest user-code frame has no iteration cap:

sapi/fpm/fpm/fpm_php_trace.c:126

while (prev) {
    ...
    if (0 > fpm_trace_get_long(prev + offsetof(zend_execute_data, prev_execute_data), &l)) {
        return -1;
    }
    prev = l;
}

It stops only on a user frame, an invalid pointer, or a ptrace read error. The walk reads the stopped (ptraced) child's memory from the master. A corrupted or cyclic prev_execute_data chain in a worker could spin the inner loop, keeping the master busy reading child memory.

The trigger is narrow — it needs slowlog + request_slowlog_timeout configured and the ability to corrupt VM stack memory in a worker — so this is a robustness nit rather than a security issue. Confirmed by source on PHP-8.6 and PHP-8.3.

Suggested fix

Bound the inner while (prev) loop with a counter (e.g. mirroring the outer callers_limit, or a hard cap), so a cyclic chain cannot hang the master.

PHP Version

PHP-8.6 and PHP-8.3 branch heads (confirmed by source).

Operating System

Linux

Dominant language
C
Stars
41.9k
Forks
8.5k
Avg merge
2d 16h
Merged PRs (30d)
117

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from php/php-src

All issues in php/php-src

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.