Home / exploits PHP 5.3.6 Null Pointer Dereference
Posted on 19 August 2011
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 [ PHP 5.3.6 multiple null pointer dereference ] Author: Maksymilian Arciemowicz http://securityreason.com/ http://securityreason.net/ http://cxib.net/ Date: - - Dis.: 20.07.2011 - - Pub.: 19.08.2011 Affected Software (verified): PHP 5.3.6 and prior Fixed: PHP 5.3.7 Original URL: http://securityreason.com/achievement_securityalert/101 - --- 0.Description --- PHP is a general-purpose scripting language originally designed for web development to produce dynamic web pages. For this purpose, PHP code is embedded into the HTML source document and interpreted by a web server with a PHP processor module, which generates the web page document. It also has evolved to include a command-line interface capability and can be used in standalone graphical applications. - --- 1. PHP 5.3.6 multiple null pointer dereference --- Some time ago we have reported list with possible NULL pointer dereferences in php 5.3.6. If user may change size of malloc, it's possible to get NULL pointer dereferences. I haven't enought time to check security impacts for all these bugs. To demonstrate these flaws, we may use default memory limit in OpenBSD [512MB]. We should allocate a lot of memory like 510MB (still 2MB free). If some string is longer than 2MB (example 4MB), and php try copy this string using malloc/strlen etc then malloc return NULL. Then program is counting with possible NULL pointer dereference or buffer overflow sympthons. Example: http://cwe.mitre.org/data/definitions/690.html where CWE-690 give CWE-476 NULL pointer dereference good example for CWE-690 is tz->location.comments = malloc(comments_len + 1); memcpy(tz->location.comments, *tzf, comments_len); This code may provide to null pointer dereference or simple crash with nulling memory with memset() in.str = malloc((e - s) + YYMAXFILL); memset(in.str, 0, (e - s) + YYMAXFILL); memcpy(in.str, s, (e - s)); Program received signal SIGSEGV, Segmentation fault. 0xbba7581c in memset () from /usr/lib/libc.so.12 (gdb) x/i $eip 0xbba7581c <memset+44>: rep stos %eax,%es:(%edi) (gdb) x/x $eax 0x0: Cannot access memory at address 0x0 (gdb) x/x $edi 0x0: Cannot access memory at address 0x0 In this case, memset() overwrite the memory with 0x0 char. If attacker can put something else that 0x0, it would have security impact. There are more interesting places, where user may try change size of malloc. See bellow - -id0-start--------- http://svn.php.net/viewvc/php/php-src/branches/PHP_5_3/ext/curl/interface.c?view=markup 820 if (!CRYPTO_get_id_callback()) { 821 int i, c = CRYPTO_num_locks(); 822 823 php_curl_openssl_tsl = malloc(c * sizeof(MUTEX_T)); 824 825 for (i = 0; i < c; ++i) { 826 php_curl_openssl_tsl[i] = tsrm_mutex_alloc(); 827 } 828 829 CRYPTO_set_id_callback(php_curl_ssl_id); 830 CRYPTO_set_locking_callback(php_curl_ssl_lock); 831 } - -id0-end--------- - -id1-start--------- http://svn.php.net/viewvc/php/php-src/branches/PHP_5_3/ext/date/lib/parse_date.c?view=markup http://svn.php.net/viewvc/php/php-src/branches/PHP_5_3/ext/date/lib/parse_iso_intervals.c?view=markup multiple malloc/calloc/realloc 323 uchar *buf = (uchar*) malloc(((s->lim - s->bot) + BSIZE)*sizeof(uchar)); 324 memcpy(buf, s->tok, s->lim - s->tok); 496 str = calloc(1, end - begin + 1); 497 memcpy(str, begin, end - begin); 346 s->errors->warning_messages = realloc(s->errors->warning_messages, s->errors->warning_count * sizeof(timelib_error_message)); 347 s->errors->warning_messages[s->errors->warning_count - 1].position = s->tok ? s->tok - s->str : 0; 348 s->errors->warning_messages[s->errors->warning_count - 1].character = s->tok ? *s->tok : 0; 349 s->errors->warning_messages[s->errors->warning_count - 1].message = strdup(error); - -id1-end--------- - -id2-start--------- http://svn.php.net/viewvc/php/php-src/branches/PHP_5_3/ext/date/lib/parse_tz.c?view=markup 210 tz->location.comments = malloc(comments_len + 1); 211 memcpy(tz->location.comments, *tzf, comments_len); 212 tz->location.comments[comments_len] = '
