Skip to content

Fix FPM log overflow when errno text exceeds the buffer - #25648

Closed
jorgsowa wants to merge 1 commit into
php:PHP-8.4from
jorgsowa:fix-fpm-vzlog-errno-overflow
Closed

jorgsowa wants to merge 1 commit into
php:PHP-8.4from
jorgsowa:fix-fpm-vzlog-errno-overflow

Conversation

@jorgsowa

Copy link
Copy Markdown
Contributor

vzlog() formats log lines into a 2048-byte stack buffer. After appending the errno text for ZLOG_SYSERROR messages, it checked the length returned by snprintf() only against log_limit. With log_limit above 2048, a message nearly filling the buffer made the length exceed it. The newline was then written past the buffer, and the following write() sent stack memory to the log.

Truncate when the buffer size is reached too.

Reproducer:

[global]
log_limit = 4096
[www]
listen = 127.0.0.1:9000
pm = static
pm.max_children = 1
request_slowlog_timeout = 1
slowlog = /aaaa… (1970 × 'a')

ASAN:

==61448==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x00016d21b5ac
WRITE of size 1 at 0x00016d21b5ac thread T0
    #0 vzlog zlog.c:248
    #1 zlog_ex zlog.c:263
    #2 fpm_conf_process_all_pools fpm_conf.c:1064
    #3 fpm_conf_post_process fpm_conf.c:1348
    #4 fpm_conf_init_main fpm_conf.c:1881
    #5 fpm_init fpm.c:58
    #6 main fpm_main.c:1817

  This frame has 1 object(s):
    [32, 2080) 'buf' (line 200) <== Memory access at offset 2092 overflows this variable
SUMMARY: AddressSanitizer: stack-buffer-overflow zlog.c:248 in vzlog

Without ASAN, the log line contains 12 bytes of stack memory after the buffer.

With log_limit above 2048, vzlog() checked the length after appending
errno text only against log_limit. snprintf() returns the would-be
length, so a message nearly filling the 2048-byte stack buffer made the
newline write and the log write go past it. Truncate when the buffer
size is reached too.
@jorgsowa jorgsowa self-assigned this Nov 22, 2026
@jorgsowa
jorgsowa requested a review from bukka as a code owner November 22, 2026 12:48
@jorgsowa jorgsowa closed this in 0ccf33a Nov 25, 2026
arnaud-lb added a commit to pavimus/php-src that referenced this pull request Nov 27, 2026
* PHP-8.4: (91 commits)
  [skip ci] Add NEWS entry for php#25674
  ext/bz2: Fix NULL dereference when compress.bzip2:// open fails in write mode
  ext/dom: Reject DTD declaration nodes in adoptNode()
  Fix iconv_mime_encode() overflowing on a negative line-length (php#25485)
  ext/pgsql: pg_get_notify() result is never === false with opcache enabled
  ext/zlib: fix gzwrite() not reporting write errors
  Fix phpGH-25779: mysqli_fetch_object() crashes with JIT when the constructor keeps a reference and the result is discarded (php#25784)
  Fix stale string metadata in sodium_add() and sodium_increment() (php#25775)
  Sync `session.upload_progress.enabled` default in `php.ini-{development,production}` (php#25743)
  ext/pgsql: fix pg_fetch_object() JIT crash when constructor keeps $this
  Fix hash() and hash_file() hanging on invalid xxh3/xxh128 options (php#25777)
  ext/dom: fix Dom\Notation publicId and systemId property handlers
  Fix FFI::string() reading out of bounds for a negative size
  [ci skip] Update test title
  Fix phpGH-25558: FFI: struct with an enum field passed by value is described to libffi with a void element
  Fix OSS-Fuzz #588264417
  Fix FPM log overflow when errno text exceeds the buffer (phpGH-25648)
  [skip ci] Use USE_TRACKED_ALLOC=1 for Symfony Preloading test
  [skip ci] Fix Symfony test without USE_TRACKED_ALLOC
  [skip ci] Skip assign_dim_undef_op_data_008.phpt when JIT is unavailable
  ...
arnaud-lb added a commit to lazerg/php-src that referenced this pull request Nov 27, 2026
* PHP-8.4: (262 commits)
  ext/pdo_sqlite: crash when a collation callback closes the statement cursor
  Admit NTS requests to OPcache SHM only in RINIT (php#25509)
  ext/pgsql: pg_meta_data() numeric column names not integer keys with opcache
  [skip ci] Add NEWS entry for php#25674
  ext/bz2: Fix NULL dereference when compress.bzip2:// open fails in write mode
  ext/dom: Reject DTD declaration nodes in adoptNode()
  Fix iconv_mime_encode() overflowing on a negative line-length (php#25485)
  ext/pgsql: pg_get_notify() result is never === false with opcache enabled
  ext/zlib: fix gzwrite() not reporting write errors
  Fix phpGH-25779: mysqli_fetch_object() crashes with JIT when the constructor keeps a reference and the result is discarded (php#25784)
  Fix stale string metadata in sodium_add() and sodium_increment() (php#25775)
  Sync `session.upload_progress.enabled` default in `php.ini-{development,production}` (php#25743)
  ext/pgsql: fix pg_fetch_object() JIT crash when constructor keeps $this
  Fix hash() and hash_file() hanging on invalid xxh3/xxh128 options (php#25777)
  ext/dom: fix Dom\Notation publicId and systemId property handlers
  Fix FFI::string() reading out of bounds for a negative size
  [ci skip] Update test title
  Fix phpGH-25558: FFI: struct with an enum field passed by value is described to libffi with a void element
  Fix OSS-Fuzz #588264417
  Fix FPM log overflow when errno text exceeds the buffer (phpGH-25648)
  ...
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