FPM/FastCGI: FCGI_HASH_FUNC reads var[3] for 3-character names (guarded only by var_len < 3)
メンテナーはふだん 1 日以内に返信
評価
調査の方向性
main/fastcgi.hにあるFCGI_HASH_FUNCの定義と、1019行目付近のmain/fastcgi.cにあるFastCGIパラメーター解析の呼び出しを読んでください。ハッシュ関数が長さ3の名前をどのように扱うかを確認し、既存のFastCGIテストを調べて、このケースをカバーするのに適した場所を探してください。ハッシュが3文字の名前の範囲を超えて読み取らなくなり、関連するテストが通れば完了です。
索引モデルが issue の本文から書いたものです。
説明
Description
main/fastcgi.h:
#define FCGI_HASH_FUNC(var, var_len) \
(UNEXPECTED(var_len < 3) ? (unsigned int)var_len : \
(((unsigned int)var[3]) << 2) + \
(((unsigned int)var[var_len-2]) << 4) + \
(((unsigned int)var[var_len-1]) << 2) + \
var_len)
The guard is var_len < 3, but the body reads var[3]. For a name of length exactly 3, the valid indices are 0..2, so var[3] is one byte past the name.
In FastCGI param parsing (main/fastcgi.c:1019) name and value are contiguous in the param buffer:
fcgi_hash_set(&req->env, FCGI_HASH_FUNC(p, name_len), (char*)p, name_len, (char*)p + name_len, val_len);
so for a 3-char name var[3] reads the first byte of the value (or the record terminator) — inside the allocation. A true 1-byte out-of-bounds read is only conceivable for a crafted record whose 3-char name sits exactly at the end of the content buffer with an empty value; even then the byte is only fed into a hash and never returned, and the whole surface is behind the FastCGI socket.
So this is a minor correctness nit / optional hardening, not a security issue. Confirmed by source on PHP-8.6 and PHP-8.3 (main/fastcgi.h).
Suggested fix
Guard the var[3] access — e.g. change the condition to var_len < 4 so that 3-char names take the (unsigned int)var_len fast path. This only changes internal hash values (recomputed each run) and removes the past-the-name read.
PHP Version
PHP-8.6 and PHP-8.3 branch heads (confirmed by source).
Operating System
Linux
- 主要言語
- C
- スター
- 41.9k
- フォーク
- 8.5k
- 平均マージ
- 2日 16時間
- マージ済み PR(30日)
- 117
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
php/php-src のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
php/php-src#26067 · コメント 4 件 ·
メンテナーはふだん 1 日以内に返信
-
FPM: fpm_request_end() releases the scoreboard writer lock without acquiring it (8.6 regression)オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
メンテナーはふだん 1 日以内に返信
-
Bug Status: Verified
難易度 1/5 1時間未満 初心者へのやさしさ 74/100
メンテナーはふだん 1 日以内に返信
-
getimagesize(): WebP VP8 dimensions are accepted with an invalid start code対応中かも @lazerg が 5 日前に担当しました。 オープンBug Status: Needs Triage
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
似ている issue
-
CF_CFDP_S_SendFileData computes the file checksum from the SB buffer after CFE_SB_TransmitBufferオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
needs triage
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
389ds/389-ds-base#8251 ·
メンテナーはふだん 1 日以内に返信
-
bug data-types
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
ClickHouse/clickhouse-cpp#645 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
ROCm/hrx-system#3628 ·
メンテナーはふだん 1 日以内に返信