Skip to content

ext/sockets: bound interface name copy in from_zval_write_ifindex()#22379

Open
iliaal wants to merge 1 commit into
php:PHP-8.5from
iliaal:sockets-ifindex-overflow
Open

ext/sockets: bound interface name copy in from_zval_write_ifindex()#22379
iliaal wants to merge 1 commit into
php:PHP-8.5from
iliaal:sockets-ifindex-overflow

Conversation

@iliaal

@iliaal iliaal commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

3e9b530 replaced the bounded strlcpy in from_zval_write_ifindex() with a memcpy of ZSTR_LEN+1 bytes that runs even when the name overflows ifr_name: the length check sets an error but falls through instead of returning, overrunning the stack. PHP-8.5 and master both carry the regression; 8.4 still has the strlcpy and is unaffected. Restore the strlcpy plus else-if guard.

@devnexen

Copy link
Copy Markdown
Member

The SIOCGIFINDEX fallback checks the interface-name length against sizeof(ifr.ifr_name) but does not return on overflow, then memcpy's ZSTR_LEN+1 bytes into the fixed ifr_name buffer, overrunning the stack. This is a master-only regression from 3e9b530, which replaced the original bounded strlcpy with an unguarded memcpy. Restore the strlcpy plus else-if guard that PHP-8.4 and PHP-8.5 still have.

not entirely true, The regression commit 3e9b530 is contained in PHP-8.5 (git branch --contains confirms it), and PHP-8.5:ext/sockets/conversions.c carries the same
unguarded memcpy, so 8.5 is vulnerable too

The SIOCGIFINDEX fallback checked ZSTR_LEN against sizeof(ifr.ifr_name)
but did not return on overflow, then memcpy'd ZSTR_LEN+1 bytes into the
fixed ifr_name buffer, so an over-long interface name overran the stack.
This regressed in 3e9b530, which replaced the original bounded
strlcpy with an unguarded memcpy. Restore the strlcpy plus else-if guard,
matching PHP-8.4.
@iliaal iliaal force-pushed the sockets-ifindex-overflow branch from 08c0e82 to 1904658 Compare June 21, 2026 16:00
@iliaal iliaal changed the base branch from master to PHP-8.5 June 21, 2026 16:00
@iliaal

iliaal commented Jun 21, 2026

Copy link
Copy Markdown
Contributor Author

You're right, 3e9b530 is in 8.5 too and its conversions.c has the same fall-through memcpy. Retargeted to PHP-8.5 as the lowest affected branch; 8.4 still has the strlcpy, so it's unaffected.

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