You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Another issue is that the implementation of putenv with ZTS may have a bug. Please take a look.
The environ is a global array, if multiple threads concurrently execute putenv with the same key, the pe.previous_value pointer may point to a memory address that has already been freed.
The putenv C function does not copy the string that is passed in; instead, it directly stores the pointer in environ.
Thread 1:
RINITputenv(env1)
pe.previous_value=NULL// ... more code
I understood the deadlock problem and made a PR for it.
I didn't understand the race condition. I don't understand how freeing putenv_string can cause a UAF on previous_value. I also note that grabbing and resetting previous_value happens under the lock.
Since the putenv_entry structure is managed by BG(), in the case of ZTS, each thread should have its own value. Therefore, I don't think it will become a UAF.
Did that actually happen? If so, I may have missed something.
Activity
cmb69 commentedon Jan 8, 2025
Needs to be fixed for PHP-8.3+.
matyhtf commentedon Jan 8, 2025
Hi cmb69, thanks for your reply.
Another issue is that the implementation of
putenvwithZTSmay have a bug. Please take a look.The
environis a global array, if multiple threads concurrently executeputenvwith the same key, thepe.previous_valuepointer may point to a memory address that has already been freed.The putenv C function does not copy the string that is passed in; instead, it directly stores the pointer in
environ.Thread 1:
Thread 2:
env1 and env2 have the same key
Thread 1:
Thread 2:
[-]The lock is not released when putenv fails.[/-][+]Potential deadlock when putenv fails[/+]Fix phpGH-17403: Potential deadlock when putenv fails
ndossche commentedon Apr 20, 2025
I understood the deadlock problem and made a PR for it.
I didn't understand the race condition. I don't understand how freeing
putenv_stringcan cause a UAF onprevious_value. I also note that grabbing and resettingprevious_valuehappens under the lock.SakiTakamachi commentedon Apr 24, 2025
Since the
putenv_entrystructure is managed byBG(), in the case of ZTS, each thread should have its own value. Therefore, I don't think it will become a UAF.Did that actually happen? If so, I may have missed something.
php-src/ext/standard/basic_functions.c
Line 403 in 54e662c
Fix GH-17403: Potential deadlock when putenv fails
Merge branch 'PHP-8.3' into PHP-8.4
Merge branch 'PHP-8.4'