session_destroy() / session_abort() from __serialize() causes NULL dereference in ps_files_open
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 25/100
Hướng nghiên cứu
Start from the ASAN stack: ps_files_open() (ext/session/mod_files.c:157) dereferences a ps_files that a re-entrant call already closed; read ps_files_write() (231) and ps_write_files() (561) up to php_session_save_current_state() (ext/session/session.c:561). Reproduce with the Boom script under an ASAN build, one op per process (destroy, abort, write_close). Done means the reproducer runs clean under ASAN once maintainers pick between re-checking handler state and rejecting re-entrancy during php_session_encode().
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Description
Summary
Calling session_destroy(), session_abort(), or session_write_close() from
inside a session object's __serialize() re-enters the session module while it
is still encoding $_SESSION. For the files handler this ends in a NULL
dereference in ps_files_open() (ext/session/mod_files.c:157), because
PS(mod_data) has already been closed by the re-entrant call while
php_session_save_current_state() still calls s_write() afterwards.
On Windows the process exits with 0xC0000005 (STATUS_ACCESS_VIOLATION); on
Linux the ASAN build reports a SEGV in ps_files_open.
Affected
- PHP 8.6.0 NTS x64/x86 (Windows), PHP 8.5.13, PHP 8.4.28
- PHP 8.6.0 NTS DEBUG + ASAN/UBSAN (Linux, WSL)
session.serialize_handler=php(also reproduced withphp_binaryand
php_serializein the harness)
Reproducer
<?php
class Boom {
public $a = 1;
public function __serialize(): array {
session_destroy(); // or session_abort(); or session_write_close();
return ['a' => $this->a];
}
}
session_start();
$_SESSION['s'] = new Boom();
session_write_close(); // crash here, or at RSHUTDOWN without this line
Run with a writable session.save_path, session.use_cookies=0:
php -d session.save_path=/tmp/sessdir -d session.use_cookies=0 \
-d session.serialize_handler=php repro.php
Minimal harness used for matrix testing (one op per process):
python harnesses/run_one.py --php bin/php86-x64/php.exe --ini env/ini/php86-x64.ini \
--script parallel/chats/chat-02-session/harness/mini2.php \
--arg destroy --arg php --arg 0 --arg /tmp/sessdir --arg c2ro000000000000000000004 \
--log parallel/chats/chat-02-session/crashes/sess-reentry.jsonl --tag reenter-destroy
Control: --arg none exits 0.
Expected / actual
- Expected: either the re-entrant call is rejected with a warning/Error, or it
completes without corrupting module state.__serialize()is documented as
user code that runs during serialization, so re-entrancy is reachable. - Actual: SEGV / access violation at shutdown; no diagnostic.
ASAN trace (PHP 8.6.0 DEBUG + ASAN/UBSAN, Linux)
ext/session/mod_files.c:157:10: runtime error: member access within null pointer of type 'struct ps_files'
AddressSanitizer: SEGV on unknown address 0x000000000024 ... in ps_files_open
#0 ps_files_open ext/session/mod_files.c:157
#1 ps_files_write ext/session/mod_files.c:231
#2 ps_write_files ext/session/mod_files.c:561
#3 php_session_save_current_state ext/session/session.c:561
#4 php_session_flush ext/session/session.c:1840
#5 zif_session_write_close ext/session/session.c:2835
session_abort() with a user save handler also shows the semantic bug without
a crash: H_CLOSE is followed by H_WRITE len=31 (write after abort). The
$_SESSION UAF claim is source-based; ASAN did not observe it in these runs.
Suggested fix
At minimum, make php_session_save_current_state() re-check the handler/data
after php_session_encode() returns, and make ps_files_open() tolerate a
NULL ps_files (return FAILURE instead of dereferencing). A stricter fix is
to reject session API re-entrancy while PS(in_save_handler)/encoding is
active (fatal Error or warning), which matches the module's existing
re-entrancy guards elsewhere.
Notes
- This report is intentionally separate from the security advisories; the
trigger requires application code to call the session API from__serialize(). - Raw logs:
work/wsl/asan-sess-destroy.log,asan-sess-abort.log,
asan-sess-writeclose.log; Windows matrix:parallel/chats/chat-02-session/crashes/sess-reentry.jsonl. - Reporter: Leenulk Jantarangsee ([email protected])
PHP Version
PHP 8.6.0 (cli) (built: Nov 19 2026 15:17:27) (ZTS)
Copyright © The PHP Group and Contributors
Built by Ubuntu
Zend Engine v4.6.0, Copyright © Zend by Perforce
with Zend OPcache v8.6.0, Copyright ©, by Zend by Perforce
Operating System
Windows 11 / Ubuntu 26.04 (WSL)
- Ngôn ngữ chính
- C
- Star
- 41.8k
- Fork
- 8.6k
- Merge trung bình
- 2 ngày 15 giờ
- Pull request đã merge (30 ngày)
- 125
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của php/php-src
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
ext/openssl: 8.2.31+/8.3.31+ fail to build against OpenSSL 1.0.2 (ASN1_STRING_get0_data in xp_ssl.c)Đang mởExtension: openssl Status: Needs Triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 79/100
php/php-src#25402 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Bug Status: Needs Triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
php/php-src#25397 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
SNMP accepts malformed remote portsCó thể đã có người làm @somethingwithproof đã nhận 21 ngày trước. Đang mở
Độ khó 2/5 Nửa ngày Mức phù hợp với người mới 62/100
php/php-src#25137 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Bug Status: Needs Triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
Maintainer thường phản hồi trong vòng 1 ngày
Issue tương tự
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
ZIP/ZIPS decode dereferences NULL when the cached libdeflate decompressor can't be allocated (3.5 regression)Có thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
AcademySoftwareFoundation/openexr#2884 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
python-pillow/Pillow#10590 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
status: needs-triage type: bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
openwrt/packages#31407 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày