After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 758588 - (CVE-2016-1838) Heap-based buffer overread in xmlParserPrintFileContextInternal
(CVE-2016-1838)
Heap-based buffer overread in xmlParserPrintFileContextInternal
Status: RESOLVED FIXED
Product: libxml2
Classification: Platform
Component: general
git master
Other All
: Normal normal
: ---
Assigned To: Daniel Veillard
libxml QA maintainers
https://bugs.chromium.org/p/project-z...
: 758589 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2015-11-24 11:52 UTC by Mateusz Jurczyk
Modified: 2016-05-28 00:04 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Reproducer. (10.00 KB, text/plain)
2015-11-24 11:52 UTC, Mateusz Jurczyk
  Details
Proposed Patch v1 (1.20 KB, patch)
2016-02-14 02:00 UTC, David Kilzer
none Details | Review
Proposed Patch v2 (33.85 KB, patch)
2016-02-26 00:09 UTC, David Kilzer
none Details | Review

Description Mateusz Jurczyk 2015-11-24 11:52:39 UTC
Created attachment 316157 [details]
Reproducer.

Hi,

The following crash due to a heap-based out-of-bounds memory read can be observed in an ASAN build of latest stable libxml2 (2.9.3, released 4 days ago), by feeding a malformed file to xmllint ("$ ./xmllint /path/to/file"):

=================================================================
==4210==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x6290000051ff at pc 0x000000533c8f bp 0x7ffdb38c4830 sp 0x7ffdb38c4828
READ of size 1 at 0x6290000051ff thread T0
    #0 0x533c8e in xmlParserPrintFileContextInternal libxml2-2.9.3/error.c:192:6
    #1 0x54088a in xmlReportError libxml2-2.9.3/error.c:406:9
    #2 0x53884f in __xmlRaiseError libxml2-2.9.3/error.c:633:2
    #3 0x56f0ec in xmlFatalErr libxml2-2.9.3/parser.c:540:5
    #4 0x569c98 in xmlGROW libxml2-2.9.3/parser.c:2077:9
    #5 0x62bcb3 in xmlParseEndTag2 libxml2-2.9.3/parser.c:9846:5
    #6 0x61d620 in xmlParseElement libxml2-2.9.3/parser.c:10238:2
    #7 0x63be9b in xmlParseDocument libxml2-2.9.3/parser.c:10912:2
    #8 0x672b74 in xmlDoRead libxml2-2.9.3/parser.c:15390:5
    #9 0x673041 in xmlReadFile libxml2-2.9.3/parser.c:15452:13
    #10 0x4f5b60 in parseAndPrintFile libxml2-2.9.3/xmllint.c:2401:9
    #11 0x4ebe8f in main libxml2-2.9.3/xmllint.c:3759:7

0x6290000051ff is located 1 bytes to the left of 16384-byte region [0x629000005200,0x629000009200)
allocated by thread T0 here:
    #0 0x4b8b68 in malloc llvm/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:40
    #1 0x7f4df5219729  (/lib/x86_64-linux-gnu/libz.so.1+0xf729)

SUMMARY: AddressSanitizer: heap-buffer-overflow libxml2-2.9.3/error.c:192:6 in xmlParserPrintFileContextInternal
Shadow bytes around the buggy address:
  0x0c527fff89e0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c527fff89f0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c527fff8a00: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c527fff8a10: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c527fff8a20: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
=>0x0c527fff8a30: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa[fa]
  0x0c527fff8a40: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c527fff8a50: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c527fff8a60: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c527fff8a70: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c527fff8a80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07 
  Heap left redzone:       fa
  Heap right redzone:      fb
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack partial redzone:   f4
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
==4210==ABORTING
Comment 1 Mateusz Jurczyk 2015-11-24 19:18:25 UTC
Note, this bug is reported under the Google Project Zero framework, and is filed at https://code.google.com/p/google-security-research/issues/detail?id=639 on our side.

It is subject to a 90 day disclosure deadline. If 90 days elapse without a broadly available patch, then the bug report will automatically become visible to the public.
Comment 2 Mateusz Jurczyk 2015-11-27 16:00:51 UTC
Just realized this bug entry is already open to the public. Please disregard the deadline disclaimer.
Comment 3 David Kilzer 2016-02-14 02:00:53 UTC
Created attachment 321093 [details] [review]
Proposed Patch v1

This patch adds a bounds check that fixes the crash under ASan with this test case, and the test case attached to Bug 758589.
Comment 4 David Kilzer 2016-02-24 00:38:38 UTC
Review of attachment 321093 [details] [review]:

::: parser.c
@@ +9826,3 @@
     SKIP(2);
 
+    size_t curEnd = ctxt->input->end - ctxt->input->cur;

A better name for 'curEnd' is 'curLength' here.
Comment 5 David Kilzer 2016-02-26 00:09:53 UTC
Created attachment 322426 [details] [review]
Proposed Patch v2

Changes from v1:
- Rename curEnd to curLength.
- Add regression test using attached test case.
Comment 6 Daniel Veillard 2016-05-23 04:37:32 UTC
*** Bug 758589 has been marked as a duplicate of this bug. ***