Bug 1127122 - (CVE-2018-20783) VUL-1: CVE-2018-20783: php5,php7,php53: buffer over-read in PHAR reading functions
(CVE-2018-20783)
VUL-1: CVE-2018-20783: php5,php7,php53: buffer over-read in PHAR reading func...
Status: RESOLVED FIXED
Classification: Novell Products
Product: SUSE Security Incidents
Classification: Novell Products
Component: Incidents
unspecified
Other Other
: P4 - Low : Normal
: ---
Assigned To: Security Team bot
Security Team bot
https://smash.suse.de/issue/217953/
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2019-02-27 08:26 UTC by Robert Frohl
Modified: 2021-09-14 12:48 UTC (History)
2 users (show)

See Also:
Found By: Security Response Team
Services Priority:
Business Priority:
Blocker: ---
Marketing QA Status: ---
IT Deployment: ---


Attachments
php-oob4.phar (50 bytes, application/octet-stream)
2019-05-31 12:37 UTC, Marcus Meissner
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Robert Frohl 2019-02-27 08:26:45 UTC
rh#1680545

In PHP before 5.6.39, 7.x before 7.0.33, 7.1.x before 7.1.25, and 7.2.x before
7.2.13, a buffer over-read in PHAR reading functions may allow an attacker to
read allocated or unallocated memory past the actual data when trying to parse a
.phar file. This is related to phar_parse_pharfile in ext/phar/phar.c.

References:
https://bugzilla.redhat.com/show_bug.cgi?id=1680545
http://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2018-20783
http://people.canonical.com/~ubuntu-security/cve/2018/CVE-2018-20783.html
http://php.net/ChangeLog-5.php
http://php.net/ChangeLog-7.php
https://bugs.php.net/bug.php?id=77143
Comment 1 Robert Frohl 2019-02-27 09:26:30 UTC
affected codestreams:
- SUSE:SLE-11-SP3:Update
- SUSE:SLE-12:Update
- SUSE:SLE-15:Update 

not affected:
- SUSE:SLE-10-SP3:Update
- SUSE:SLE-11:Update
Comment 2 Petr Gajdos 2019-03-07 12:00:38 UTC
BEFORE

15/php7, 12/php7, 12/php5, 11sp3/php53

$ USE_ZEND_ALLOC=0 valgrind  -q php -d phar.readonly=0 -r "var_dump(new Phar('php-oob4.phar',0,'project.phar'));"
==7995== Invalid read of size 4
==7995==    at 0x6F7B28F: memcpy (string3.h:51)
==7995==    by 0x6F7B28F: phar_parse_pharfile (phar.c:971)
==7995==    by 0x6F7B28F: phar_open_from_fp.isra.7 (phar.c:1716)
==7995==    by 0x6F7EF83: phar_create_or_parse_filename (phar.c:1346)
==7995==    by 0x6F7F809: phar_open_or_create_filename (phar.c:1314)
==7995==    by 0x6F84879: zim_Phar___construct (phar_object.c:1167)
==7995==    by 0x40F7FA: ZEND_DO_FCALL_SPEC_HANDLER (zend_vm_execute.h:842)
==7995==    by 0x3D5FAA: execute_ex (zend_vm_execute.h:414)
==7995==    by 0x431FE2: zend_execute (zend_vm_execute.h:458)
==7995==    by 0x385636: zend_eval_stringl (zend_execute_API.c:1135)
==7995==    by 0x3857B8: zend_eval_stringl_ex (zend_execute_API.c:1176)
==7995==    by 0x433A7D: do_cli (php_cli.c:1005)
==7995==    by 0x1DE05A: main (php_cli.c:1344)
==7995==  Address 0x6da7baa is 0 bytes after a block of size 10 alloc'd
==7995==    at 0x4C29110: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==7995==    by 0x6F7B104: phar_parse_pharfile (phar.c:722)
==7995==    by 0x6F7B104: phar_open_from_fp.isra.7 (phar.c:1716)
==7995==    by 0x6F7EF83: phar_create_or_parse_filename (phar.c:1346)
==7995==    by 0x6F7F809: phar_open_or_create_filename (phar.c:1314)
==7995==    by 0x6F84879: zim_Phar___construct (phar_object.c:1167)
==7995==    by 0x40F7FA: ZEND_DO_FCALL_SPEC_HANDLER (zend_vm_execute.h:842)
==7995==    by 0x3D5FAA: execute_ex (zend_vm_execute.h:414)
==7995==    by 0x431FE2: zend_execute (zend_vm_execute.h:458)
==7995==    by 0x385636: zend_eval_stringl (zend_execute_API.c:1135)
==7995==    by 0x3857B8: zend_eval_stringl_ex (zend_execute_API.c:1176)
==7995==    by 0x433A7D: do_cli (php_cli.c:1005)
==7995==    by 0x1DE05A: main (php_cli.c:1344)
==7995== 
PHP Fatal error:  Uncaught UnexpectedValueException: internal corruption of phar "/127122/php-oob4.phar" (buffer overrun) in Command line code:1
Stack trace:
#0 Command line code(1): Phar->__construct('php-oob4.phar', 0, 'project.phar')
#1 {main}
  thrown in Command line code on line 1
$

PATCH

http://git.php.net/?p=php-src.git;a=commit;h=48f0f73f75c0059ba5d9b73cb4e5faeeaea49c47

AFTER

$ USE_ZEND_ALLOC=0 valgrind  -q "php" "-d" "phar.readonly=0" "-r" "var_dump(new Phar('php-oob4.phar',0,'project.phar'));"
PHP Fatal error:  Uncaught exception 'UnexpectedValueException' with message 'internal corruption of phar "/127122/php-oob4.phar" (truncated manifest header)' in Command line code:1
Stack trace:
#0 Command line code(1): Phar->__construct('php-oob4.phar', 0, 'project.phar')
#1 {main}
  thrown in Command line code on line 1
$
Comment 3 Petr Gajdos 2019-03-07 12:01:49 UTC
Will submit for: 15/php7, 12/php72, 12/php7, 12/php5, 11sp3/php53
Comment 4 Petr Gajdos 2019-03-08 08:53:22 UTC
With the testcase I do not see invalid reads, however there are superfluous conditional jumps in memchr. I have asked reporter of upstream bug for the original testcase, however he had not replied until now.

15/php7, 12/php7, 12/php5

$ USE_ZEND_ALLOC=0 valgrind -q php -r "new Phar('a/.b');"
==11330== Conditional jump or move depends on uninitialised value(s)
==11330==    at 0x4C2D94B: memchr (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==11330==    by 0x6F8077E: phar_detect_phar_fname_ext (phar.c:2022)
==11330==    by 0x6F80FAB: phar_split_fname (phar.c:2229)
==11330==    by 0x6F84884: zim_Phar___construct (phar_object.c:1150)
==11330==    by 0x40F7FA: ZEND_DO_FCALL_SPEC_HANDLER (zend_vm_execute.h:842)
==11330==    by 0x3D5FAA: execute_ex (zend_vm_execute.h:414)
==11330==    by 0x431FE2: zend_execute (zend_vm_execute.h:458)
==11330==    by 0x385636: zend_eval_stringl (zend_execute_API.c:1135)
==11330==    by 0x3857B8: zend_eval_stringl_ex (zend_execute_API.c:1176)
==11330==    by 0x433A7D: do_cli (php_cli.c:1005)
==11330==    by 0x1DE05A: main (php_cli.c:1344)
==11330== 
==11330== Conditional jump or move depends on uninitialised value(s)
==11330==    at 0x4C2D94B: memchr (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==11330==    by 0x6F79F97: phar_detect_phar_fname_ext.constprop.8 (phar.c:2022)
==11330==    by 0x6F7F53D: phar_open_or_create_filename (phar.c:1267)
==11330==    by 0x6F848C9: zim_Phar___construct (phar_object.c:1167)
==11330==    by 0x40F7FA: ZEND_DO_FCALL_SPEC_HANDLER (zend_vm_execute.h:842)
==11330==    by 0x3D5FAA: execute_ex (zend_vm_execute.h:414)
==11330==    by 0x431FE2: zend_execute (zend_vm_execute.h:458)
==11330==    by 0x385636: zend_eval_stringl (zend_execute_API.c:1135)
==11330==    by 0x3857B8: zend_eval_stringl_ex (zend_execute_API.c:1176)
==11330==    by 0x433A7D: do_cli (php_cli.c:1005)
==11330==    by 0x1DE05A: main (php_cli.c:1344)
==11330== 
==11330== Conditional jump or move depends on uninitialised value(s)
==11330==    at 0x4C2D94B: memchr (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==11330==    by 0x6F79F97: phar_detect_phar_fname_ext.constprop.8 (phar.c:2022)
==11330==    by 0x6F7F564: phar_open_or_create_filename (phar.c:1272)
==11330==    by 0x6F848C9: zim_Phar___construct (phar_object.c:1167)
==11330==    by 0x40F7FA: ZEND_DO_FCALL_SPEC_HANDLER (zend_vm_execute.h:842)
==11330==    by 0x3D5FAA: execute_ex (zend_vm_execute.h:414)
==11330==    by 0x431FE2: zend_execute (zend_vm_execute.h:458)
==11330==    by 0x385636: zend_eval_stringl (zend_execute_API.c:1135)
==11330==    by 0x3857B8: zend_eval_stringl_ex (zend_execute_API.c:1176)
==11330==    by 0x433A7D: do_cli (php_cli.c:1005)
==11330==    by 0x1DE05A: main (php_cli.c:1344)
==11330==
$

11sp3/php53:

$ USE_ZEND_ALLOC=0 valgrind -q php -r "new Phar('a/.b');"               
==11420== Invalid read of size 1
==11420==    at 0x4C2C288: memchr (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==11420==    by 0x6C80063: phar_detect_phar_fname_ext (phar.c:2044)
==11420==    by 0x6C803CB: phar_split_fname (phar.c:2292)
==11420==    by 0x6C8E788: zim_Phar___construct (phar_object.c:1184)
==11420==    by 0x5D398D: zend_do_fcall_common_helper_SPEC (zend_vm_execute.h:320)
==11420==    by 0x5AF530: execute (zend_vm_execute.h:107)
==11420==    by 0x575134: zend_eval_stringl (zend_execute_API.c:1198)
==11420==    by 0x5752C8: zend_eval_stringl_ex (zend_execute_API.c:1240)
==11420==    by 0x60EEAC: main (php_cli.c:1228)
==11420==  Address 0x6baac65 is 0 bytes after a block of size 5 alloc'd
==11420==    at 0x4C29F09: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==11420==    by 0x564BCF: _estrndup (zend_alloc.c:2503)
==11420==    by 0x580B02: _zval_copy_ctor_func (zend_variables.c:120)
==11420==    by 0x5AFDCE: ZEND_SEND_VAL_SPEC_CONST_HANDLER (zend_variables.h:45)
==11420==    by 0x5AF530: execute (zend_vm_execute.h:107)
==11420==    by 0x575134: zend_eval_stringl (zend_execute_API.c:1198)
==11420==    by 0x5752C8: zend_eval_stringl_ex (zend_execute_API.c:1240)
==11420==    by 0x60EEAC: main (php_cli.c:1228)
==11420== 
==11420== Invalid read of size 1
==11420==    at 0x4C2C288: memchr (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==11420==    by 0x6C80063: phar_detect_phar_fname_ext (phar.c:2044)
==11420==    by 0x6C84E8E: phar_open_or_create_filename (phar.c:1264)
==11420==    by 0x6C8E7EC: zim_Phar___construct (phar_object.c:1201)
==11420==    by 0x5D398D: zend_do_fcall_common_helper_SPEC (zend_vm_execute.h:320)
==11420==    by 0x5AF530: execute (zend_vm_execute.h:107)
==11420==    by 0x575134: zend_eval_stringl (zend_execute_API.c:1198)
==11420==    by 0x5752C8: zend_eval_stringl_ex (zend_execute_API.c:1240)
==11420==    by 0x60EEAC: main (php_cli.c:1228)
==11420==  Address 0x6baac65 is 0 bytes after a block of size 5 alloc'd
==11420==    at 0x4C29F09: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==11420==    by 0x564BCF: _estrndup (zend_alloc.c:2503)
==11420==    by 0x580B02: _zval_copy_ctor_func (zend_variables.c:120)
==11420==    by 0x5AFDCE: ZEND_SEND_VAL_SPEC_CONST_HANDLER (zend_variables.h:45)
==11420==    by 0x5AF530: execute (zend_vm_execute.h:107)
==11420==    by 0x575134: zend_eval_stringl (zend_execute_API.c:1198)
==11420==    by 0x5752C8: zend_eval_stringl_ex (zend_execute_API.c:1240)
==11420==    by 0x60EEAC: main (php_cli.c:1228)
==11420== 
==11420== Invalid read of size 1
==11420==    at 0x4C2C288: memchr (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==11420==    by 0x6C80063: phar_detect_phar_fname_ext (phar.c:2044)
==11420==    by 0x6C84EB3: phar_open_or_create_filename (phar.c:1269)
==11420==    by 0x6C8E7EC: zim_Phar___construct (phar_object.c:1201)
==11420==    by 0x5D398D: zend_do_fcall_common_helper_SPEC (zend_vm_execute.h:320)
==11420==    by 0x5AF530: execute (zend_vm_execute.h:107)
==11420==    by 0x575134: zend_eval_stringl (zend_execute_API.c:1198)
==11420==    by 0x5752C8: zend_eval_stringl_ex (zend_execute_API.c:1240)
==11420==    by 0x60EEAC: main (php_cli.c:1228)
==11420==  Address 0x6baac65 is 0 bytes after a block of size 5 alloc'd
==11420==    at 0x4C29F09: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==11420==    by 0x564BCF: _estrndup (zend_alloc.c:2503)
==11420==    by 0x580B02: _zval_copy_ctor_func (zend_variables.c:120)
==11420==    by 0x5AFDCE: ZEND_SEND_VAL_SPEC_CONST_HANDLER (zend_variables.h:45)
==11420==    by 0x5AF530: execute (zend_vm_execute.h:107)
==11420==    by 0x575134: zend_eval_stringl (zend_execute_API.c:1198)
==11420==    by 0x5752C8: zend_eval_stringl_ex (zend_execute_API.c:1240)
==11420==    by 0x60EEAC: main (php_cli.c:1228)
==11420==
$

For 15/php7 I get additional, unrelated conditional jumps depending on uninitialized values.

PATCH

http://git.php.net/?p=php-src.git;a=commit;h=48f0f73f75c0059ba5d9b73cb4e5faeeaea49c47

AFTER

$ USE_ZEND_ALLOC=0 valgrind -q php -r "new Phar('a/.b');"
PHP Fatal error:  Uncaught UnexpectedValueException: Cannot create phar 'a/.b', file extension (or combination) not recognised or the directory does not exist in Command line code:1
Stack trace:
#0 Command line code(1): Phar->__construct('a/.b')
#1 {main}
  thrown in Command line code on line 1
$
Comment 5 Petr Gajdos 2019-03-08 09:01:15 UTC
Apologize, comment 4 was meant for the other php-phar bug, please disregard it.
Comment 6 Petr Gajdos 2019-03-11 21:04:02 UTC
I believe all fixed.
Comment 11 Swamp Workflow Management 2019-04-05 19:20:04 UTC
SUSE-SU-2019:14013-1: An update that fixes 11 vulnerabilities is now available.

Category: security (moderate)
Bug References: 1126711,1126713,1126821,1126823,1127122,1128722,1128883,1128886,1128887,1128889,1128892
CVE References: CVE-2018-20783,CVE-2019-9020,CVE-2019-9021,CVE-2019-9023,CVE-2019-9024,CVE-2019-9637,CVE-2019-9638,CVE-2019-9639,CVE-2019-9640,CVE-2019-9641,CVE-2019-9675
Sources used:
SUSE Linux Enterprise Software Development Kit 11-SP4 (src):    php53-5.3.17-112.58.1
SUSE Linux Enterprise Server 11-SP4 (src):    php53-5.3.17-112.58.1
SUSE Linux Enterprise Point of Sale 11-SP3 (src):    php53-5.3.17-112.58.1
SUSE Linux Enterprise Debuginfo 11-SP4 (src):    php53-5.3.17-112.58.1

*** NOTE: This information is not intended to be used for external
    communication, because this may only be a partial fix.
    If you have questions please reach out to maintenance coordination.
Comment 12 Swamp Workflow Management 2019-04-18 16:12:38 UTC
SUSE-SU-2019:0985-1: An update that fixes 6 vulnerabilities is now available.

Category: security (moderate)
Bug References: 1126711,1126713,1126821,1126823,1127122,1128722
CVE References: CVE-2018-20783,CVE-2019-9020,CVE-2019-9021,CVE-2019-9023,CVE-2019-9024,CVE-2019-9641
Sources used:
SUSE Linux Enterprise Software Development Kit 12-SP4 (src):    php5-5.5.14-109.51.6
SUSE Linux Enterprise Software Development Kit 12-SP3 (src):    php5-5.5.14-109.51.6
SUSE Linux Enterprise Module for Web Scripting 12 (src):    php5-5.5.14-109.51.6

*** NOTE: This information is not intended to be used for external
    communication, because this may only be a partial fix.
    If you have questions please reach out to maintenance coordination.
Comment 13 Swamp Workflow Management 2019-04-23 15:07:46 UTC
openSUSE-SU-2019:1256-1: An update that fixes 6 vulnerabilities is now available.

Category: security (moderate)
Bug References: 1126711,1126713,1126821,1126823,1127122,1128722
CVE References: CVE-2018-20783,CVE-2019-9020,CVE-2019-9021,CVE-2019-9023,CVE-2019-9024,CVE-2019-9641
Sources used:
openSUSE Leap 42.3 (src):    php5-5.5.14-115.1
Comment 15 Swamp Workflow Management 2019-04-29 13:09:52 UTC
openSUSE-SU-2019:1293-1: An update that solves 11 vulnerabilities and has one errata is now available.

Category: security (moderate)
Bug References: 1126711,1126713,1126821,1126823,1127122,1128722,1128883,1128886,1128887,1128889,1128892,1129032
CVE References: CVE-2018-20783,CVE-2019-9020,CVE-2019-9021,CVE-2019-9023,CVE-2019-9024,CVE-2019-9637,CVE-2019-9638,CVE-2019-9639,CVE-2019-9640,CVE-2019-9641,CVE-2019-9675
Sources used:
openSUSE Leap 42.3 (src):    php7-7.0.7-58.1
Comment 17 Marcus Meissner 2019-05-31 12:37:39 UTC
Created attachment 806536 [details]
php-oob4.phar

QA REPRODUCER:

USE_ZEND_ALLOC=0 valgrind php -d phar.readonly=0 -r "var_dump(new Phar('php-oob4.phar',0,'project.phar'));"

should not report invalid reads from valgrind
Comment 18 Swamp Workflow Management 2019-06-11 22:11:56 UTC
SUSE-SU-2019:1461-1: An update that solves 16 vulnerabilities and has two fixes is now available.

Category: security (moderate)
Bug References: 1118832,1119396,1126711,1126713,1126821,1126823,1126827,1127122,1128722,1128883,1128886,1128887,1128889,1128892,1129032,1132837,1132838,1134322
CVE References: CVE-2018-19935,CVE-2018-20783,CVE-2019-11034,CVE-2019-11035,CVE-2019-11036,CVE-2019-9020,CVE-2019-9021,CVE-2019-9022,CVE-2019-9023,CVE-2019-9024,CVE-2019-9637,CVE-2019-9638,CVE-2019-9639,CVE-2019-9640,CVE-2019-9641,CVE-2019-9675
Sources used:
SUSE Linux Enterprise Module for Web Scripting 15 (src):    php7-7.2.5-4.32.1
SUSE Linux Enterprise Module for Packagehub Subpackages 15 (src):    php7-7.2.5-4.32.1
SUSE Linux Enterprise Module for Open Buildservice Development Tools 15 (src):    php7-7.2.5-4.32.1

NOTE: This line indicates an update has been released for the listed product(s). At times this might be only a partial fix. If you have questions please reach out to maintenance coordination.
Comment 19 Swamp Workflow Management 2019-06-18 16:38:17 UTC
openSUSE-SU-2019:1572-1: An update that solves 16 vulnerabilities and has two fixes is now available.

Category: security (moderate)
Bug References: 1118832,1119396,1126711,1126713,1126821,1126823,1126827,1127122,1128722,1128883,1128886,1128887,1128889,1128892,1129032,1132837,1132838,1134322
CVE References: CVE-2018-19935,CVE-2018-20783,CVE-2019-11034,CVE-2019-11035,CVE-2019-11036,CVE-2019-9020,CVE-2019-9021,CVE-2019-9022,CVE-2019-9023,CVE-2019-9024,CVE-2019-9637,CVE-2019-9638,CVE-2019-9639,CVE-2019-9640,CVE-2019-9641,CVE-2019-9675
Sources used:
openSUSE Leap 15.1 (src):    php7-7.2.5-lp151.6.3.1
Comment 20 Swamp Workflow Management 2019-06-18 16:43:24 UTC
openSUSE-SU-2019:1573-1: An update that solves 16 vulnerabilities and has two fixes is now available.

Category: security (moderate)
Bug References: 1118832,1119396,1126711,1126713,1126821,1126823,1126827,1127122,1128722,1128883,1128886,1128887,1128889,1128892,1129032,1132837,1132838,1134322
CVE References: CVE-2018-19935,CVE-2018-20783,CVE-2019-11034,CVE-2019-11035,CVE-2019-11036,CVE-2019-9020,CVE-2019-9021,CVE-2019-9022,CVE-2019-9023,CVE-2019-9024,CVE-2019-9637,CVE-2019-9638,CVE-2019-9639,CVE-2019-9640,CVE-2019-9641,CVE-2019-9675
Sources used:
openSUSE Leap 15.0 (src):    php7-7.2.5-lp150.2.19.1
Comment 21 Marcus Meissner 2019-10-29 16:35:18 UTC
released
Comment 24 OBSbugzilla Bot 2020-05-12 08:01:03 UTC
This is an autogenerated message for OBS integration:
This bug (1127122) was mentioned in
https://build.opensuse.org/request/show/802846 Factory / php7
Comment 25 OBSbugzilla Bot 2020-05-12 14:00:48 UTC
This is an autogenerated message for OBS integration:
This bug (1127122) was mentioned in
https://build.opensuse.org/request/show/802978 Factory / php7
Comment 26 OBSbugzilla Bot 2020-05-13 08:20:45 UTC
This is an autogenerated message for OBS integration:
This bug (1127122) was mentioned in
https://build.opensuse.org/request/show/804946 Factory / php7
Comment 28 OBSbugzilla Bot 2020-05-13 13:30:17 UTC
This is an autogenerated message for OBS integration:
This bug (1127122) was mentioned in
https://build.opensuse.org/request/show/805287 Factory / php7