Skip to content

Commit 446ea62

Browse files
committed
Fix phpGH-19520: php_admin_value[extension] in FPM unsafely runs RINIT
This redifines start_now param to start_mode in php_dl / php_load_extension to allow selection of start hooks to run. And for php-fpm it uses just starting of module.
1 parent 314daba commit 446ea62

File tree

4 files changed

+15
-10
lines changed

4 files changed

+15
-10
lines changed

ext/standard/dl.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ PHPAPI PHP_FUNCTION(dl)
6666
zend_rc_debug = false;
6767
#endif
6868

69-
php_dl(filename, MODULE_TEMPORARY, return_value, 0);
69+
php_dl(filename, MODULE_TEMPORARY, return_value, PHP_DL_START_NONE);
7070
if (Z_TYPE_P(return_value) == IS_TRUE) {
7171
EG(full_tables_cleanup) = 1;
7272
}
@@ -107,7 +107,7 @@ PHPAPI void *php_load_shlib(const char *path, char **errp)
107107
/* }}} */
108108

109109
/* {{{ php_load_extension */
110-
PHPAPI int php_load_extension(const char *filename, int type, int start_now)
110+
PHPAPI int php_load_extension(const char *filename, int type, int start_mode)
111111
{
112112
void *handle;
113113
char *libpath;
@@ -238,12 +238,13 @@ PHPAPI int php_load_extension(const char *filename, int type, int start_now)
238238

239239
module_entry->handle = handle;
240240

241-
if ((type == MODULE_TEMPORARY || start_now) && zend_startup_module_ex(module_entry) == FAILURE) {
241+
if ((type == MODULE_TEMPORARY || start_mode == PHP_DL_START_MODULE || start_mode == PHP_DL_START_REQUEST) &&
242+
zend_startup_module_ex(module_entry) == FAILURE) {
242243
DL_UNLOAD(handle);
243244
return FAILURE;
244245
}
245246

246-
if ((type == MODULE_TEMPORARY || start_now) && module_entry->request_startup_func) {
247+
if ((type == MODULE_TEMPORARY || (start_mode == PHP_DL_START_REQUEST)) && module_entry->request_startup_func) {
247248
if (module_entry->request_startup_func(type, module_entry->module_number) == FAILURE) {
248249
php_error_docref(NULL, error_type, "Unable to initialize module '%s'", module_entry->name);
249250
DL_UNLOAD(handle);
@@ -278,10 +279,10 @@ PHPAPI int php_load_extension(const char *filename, int type, int start_now)
278279
#endif
279280

280281
/* {{{ php_dl */
281-
PHPAPI void php_dl(const char *file, int type, zval *return_value, int start_now)
282+
PHPAPI void php_dl(const char *file, int type, zval *return_value, int start_mode)
282283
{
283284
/* Load extension */
284-
if (php_load_extension(file, type, start_now) == FAILURE) {
285+
if (php_load_extension(file, type, start_mode) == FAILURE) {
285286
RETVAL_FALSE;
286287
} else {
287288
RETVAL_TRUE;

ext/standard/dl.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,12 @@
1919
#ifndef DL_H
2020
#define DL_H
2121

22-
PHPAPI int php_load_extension(const char *filename, int type, int start_now);
23-
PHPAPI void php_dl(const char *file, int type, zval *return_value, int start_now);
22+
#define PHP_DL_START_NONE 0
23+
#define PHP_DL_START_REQUEST 1
24+
#define PHP_DL_START_MODULE 2
25+
26+
PHPAPI int php_load_extension(const char *filename, int type, int start_mode);
27+
PHPAPI void php_dl(const char *file, int type, zval *return_value, int start_mode);
2428
PHPAPI void *php_load_shlib(const char *path, char **errp);
2529

2630
/* dynamic loading functions */

main/php_ini.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ static void php_ini_parser_cb(zval *arg1, zval *arg2, zval *arg3, int callback_t
313313
static void php_load_php_extension_cb(void *arg)
314314
{
315315
#ifdef HAVE_LIBDL
316-
php_load_extension(*((char **) arg), MODULE_PERSISTENT, 0);
316+
php_load_extension(*((char **) arg), MODULE_PERSISTENT, PHP_DL_START_NONE);
317317
#endif
318318
}
319319
/* }}} */

sapi/fpm/fpm/fpm_php.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ int fpm_php_apply_defines_ex(struct key_value_s *kv, int mode) /* {{{ */
7575
zend_rc_debug = false;
7676
#endif
7777

78-
php_dl(value, MODULE_PERSISTENT, &zv, 1);
78+
php_dl(value, MODULE_PERSISTENT, &zv, PHP_DL_START_MODULE);
7979

8080
#if ZEND_RC_DEBUG
8181
zend_rc_debug = orig_rc_debug;

0 commit comments

Comments
 (0)