Skip to content

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

Closed
iliaal wants to merge 1 commit into
masterfrom
sockets-ifindex-overflow
Closed

ext/sockets: bound interface name copy in from_zval_write_ifindex()#104
iliaal wants to merge 1 commit into
masterfrom
sockets-ifindex-overflow

Conversation

@iliaal

@iliaal iliaal commented Jun 21, 2026

Copy link
Copy Markdown
Owner

The SIOCGIFINDEX fallback in from_zval_write_ifindex() checks ZSTR_LEN against sizeof(ifr.ifr_name) but does not return on overflow, then memcpy's ZSTR_LEN+1 bytes into the fixed-size ifr_name stack buffer, so an over-long interface name passed to socket_sendmsg() IPV6_PKTINFO overruns the stack. This regressed in 3e9b530 (php#17311), which replaced the original bounded strlcpy with an unguarded memcpy; PHP-8.4 and PHP-8.5 are unaffected. The fix restores the strlcpy plus else-if guard from the stable branches. The branch is only compiled where if_nametoindex() is unavailable, so it is not built on mainstream Linux/CI and there is no automated test; verified by inspection against the stable-branch code.

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 and PHP-8.5.
@iliaal

iliaal commented Jun 21, 2026

Copy link
Copy Markdown
Owner Author

Submitted upstream as php#22379.

@iliaal iliaal closed this Jun 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant