Statement on glibc/iconv Vulnerability


EDIT 2024-04-25: Clarified when a PHP application is vulnerable to this bug.
Recently, a bug in glibc version 2.39 and older (CVE-2024-2961) was uncovered
where a buffer overflow in character set conversions to
the ISO-2022-CN-EXT character set can result in remote code execution.

This specific buffer overflow in glibc is exploitable through PHP,
which exposes the iconv functionality of glibc to do character set
conversions via the iconv extension.
Although the bug is exploitable in the context of the PHP
Engine, the bug is not in PHP. It is also not directly exploitable
remotely.

The bug is exploitable, if and only if,
the PHP application calls iconv functions
or filters
with user-supplied character sets.

Applications are not vulnerable if:

  • Glibc security updates from the distribution have been installed.
  • Or the iconv extension is not loaded.
  • Or the vulnerable character set has been removed from gconv-modules-extra.conf.
  • Or the application passes only specifically allowed character sets to iconv.

Moreover, when using a user-supplied character set,
it is good practice for applications to accept only
specific charsets that have been explicitly allowed by the application.
One example of how this can be done is by using an allow-list and the
array_search() function
to check the encoding before passing it to iconv.
For example: array_search($charset, $allowed_list, true)

There are numerous reports online with titles like "Mitigating the
iconv Vulnerability for PHP (CVE-2024-2961)" or "PHP Under Attack". These
titles are misleading as this is not a bug in PHP itself.

If your PHP application is vulnerable, we first recommend to check if your Linux distribution
has already published patched variants of glibc.
Debian,
CentOS, and others, have already done so, and please upgrade as soon as possible.

Once an update is available in glibc, updating that package on your
Linux machine will be enough to alleviate the issue. You do not need to
update PHP, as glibc is a dynamically linked library.

If your Linux distribution has not published a patched version of glibc,
there is no fix for this issue. However, there exists a workaround described in
GLIBC
Vulnerability on Servers Serving PHP
which explains a way on how to remove
the problematic character set from glibc. Perform this procedure for every
gconv-modules-extra.conf file that is available on your system.

PHP users on Windows are not affected.

Therefore, a new version of PHP will not be released for this vulnerability.