VulnWatch by ve1ve2
low 3.3 EPSS 0.48%

GHSA-865w-9rf3-2wh5 / CVE-2024-9026: [PHP-FPM] Logs from childrens may be altered

Source:
PHP releases (GitHub php/php-src tags)
Published:
Fetched:
Updated:
Affects:
php php-src

https://github.com/php/php-src/security/advisories/GHSA-865w-9rf3-2wh5 ↗

repo-advisoryCWE-117securityrepo:php/php-srcstack

[PHP-FPM] Logs from childrens may be altered ### Summary In PHP-FPM, when configured to catch workers output through `catch_workers_output = yes` configuration, it may be possible to pollute the final log with up to 4 characters from the `FPM_STDIO_CMD_FLUSH` macro, or remove up to 4 characters from the logs. Additionally, If PHP-FPM is configured to use a syslog, it seems that much more characters can be excluded from the logs, even though it has not been tested. Note that this issue was found and reported as part of Quarkslab security audit on PHP-SRC with the OSTIF and PHP Foundation. ### Details The method `static void fpm_stdio_child_said` defined in `sapi/fpm/fpm/fpm_stdio.c` is responsible for parsing and writing the logs out from workers input. The interesting part is the following : ``` C while (1) { stdio_read: in_buf = read(fd, buf, sizeof(buf) - 1); if (in_buf <= 0) { /* no data */ if (in_buf == 0 || !PHP_IS_TRANSIENT_ERROR(errno)) { /* pipe is closed or error */ read_fail = (in_buf < 0) ? in_buf : 1; } break; } start = 0; if (cmd_pos > 0) { if ((sizeof(FPM_STDIO_CMD_FLUSH) - cmd_pos) <= in_buf && !memcmp(buf, &FPM_STDIO_CMD_FLUSH[cmd_pos], sizeof(FPM_STDIO_CMD_FLUSH) - cmd_pos)) { zlog_stream_finish(log_stream); start = cmd_pos; } else { zlog_stream_str(log_stream, &FPM_STDIO_CMD_FLUSH[0], cmd_pos); } cmd_pos = 0; } for (pos = start; pos < in_buf; pos++) { switch (buf[pos]) { case '\n': zlog_stream_str(log_stream, buf + start, pos - start); zlog_stream_finish(log_stream); start = pos + 1; break; case '\0': if (pos + sizeof(FPM_STDIO_CMD_FLUSH) <= in_buf) { if (!memcmp(buf + pos, FPM_STDIO_CMD_FLUSH, sizeof(FPM_STDIO_CMD_FLUSH))) { zlog_stream_str(log_stream, buf + start, pos - start); zlog_stream_finish(log_stream); start = pos + sizeof(FPM_STDIO_CMD_FLUSH); pos = start - 1; } } else if (!memcmp(buf + pos, FPM_STDIO_CMD_FLUSH, in_buf - pos)) { cmd_pos = in_buf - pos; zlog_stream_str(log_stream, buf + start, pos - start); goto stdio_read; } break; } } if (start < pos) { zlog_stream_str(log_stream, buf + start, pos - start); } } ``` For each characters of `buf`, it is checked whether it is `\n` or `\0`. `\n` is used to indicate that the current line of log is terminated and can be written. `\0` is used to detect the `FPM_STDIO_CMD_FLUSH` macro characters sequence, defined as `\0fscf\0` and used to flush logs. It acts the same as `\n`. If a `\0` character is encountered, and if the end of the buffer is reached before the full comparison with `FPM_STDIO_CMD_FLUSH` can be achieved, then the comparison is done with what is currently available: ``` C } else if (!memcmp(buf + pos, FPM_STDIO_CMD_FLUSH, in_buf - pos)) { cmd_pos = in_buf - pos; zlog_stream_str(log_stream, buf + start, pos - start); goto stdio_read; } ``` Patched: 8.1.30, 8.2.24, 8.3.12

Linked vulnerabilities (2)

CVE-2024-9026 low 3.3 EPSS 0.48% (p42) NVDCVE.orgGHSA
CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:N/I:L/A:N

php8.2 - security update

CWE: CWE-117Aliases: CVE-2024-8925, CVE-2024-8926, CVE-2024-8927, GHSA-865w-9rf3-2wh5
CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:N/I:L/A:N

[PHP-FPM] Logs from childrens may be altered

CWE: CWE-117Aliases: CVE-2024-9026