bugGNU patch - Bugs: bug #45990, out of bounds read with malformed...

 
 

bug #45990: out of bounds read with malformed patch in pch_write_line

Submitter:  Hanno Boeck <hanno>
Submitted:  Thu 17 Sep 2015 05:14:13 PM UTC
   
 
Category:  None Severity:  3 - Normal
Item Group:  None Status:  Fixed
Privacy:  Public Assigned to:  None
Open/Closed:  Closed
* Mandatory Fields

Add a New Comment Rich Markup
   

Tue 09 Aug 2016 10:14:58 PM UTC, comment #2: 

Applied, thanks.

Andreas Gruenbacher <agruen>
Group administrator
Tue 09 Aug 2016 07:13:13 AM UTC, comment #1: 

I'm attaching a patch to fix this.

What happens is that there's an attempt to access
p_line[line][p_len[line] - 1]
in the function pch_write_line().

However in case p_len[line] is zero this will lead to an array access with offset -1, which is obviously invalid. The patch will add a check whether p_len[line] is larger than zero.

Please apply.

(file #38154)

Hanno Boeck <hanno>
Thu 17 Sep 2015 05:14:13 PM UTC, original submission:  

The attached file will cause an out of bounds read in patch. Can be seen with address sanitizer or valgrind.

This was found with american fuzzy lop. I have already reported this privately to the gnu patch developers many months ago, but never got a reply.

Address Sanitizer stack trace:
==6761==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60200000ef6f at pc 0x000000501d1b bp 0x7ffebdd66310 sp 0x7ffebdd66308
READ of size 1 at 0x60200000ef6f thread T0
    #0 0x501d1a in pch_write_line /tmp/patch/src/pch.c:2279:24
    #1 0x4e520f in abort_hunk_unified /tmp/patch/src/patch.c:1301:4
    #2 0x4e520f in abort_hunk /tmp/patch/src/patch.c:1395
    #3 0x4e520f in main /tmp/patch/src/patch.c:471
    #4 0x7fe379f467af in __libc_start_main /var/tmp/portage/sys-libs/glibc-2.21-r1/work/glibc-2.21/csu/libc-start.c:289
    #5 0x419558 in _start (/tmp/patch/src/patch+0x419558)

0x60200000ef6f is located 1 bytes to the left of 1-byte region [0x60200000ef70,0x60200000ef71)
allocated by thread T0 here:
    #0 0x4af7f8 in __interceptor_malloc (/tmp/patch/src/patch+0x4af7f8)
    #1 0x5141bf in savebuf /tmp/patch/src/util.c:861:8
    #2 0x4e273d in main /tmp/patch/src/patch.c:390:25
    #3 0x7fe379f467af in __libc_start_main /var/tmp/portage/sys-libs/glibc-2.21-r1/work/glibc-2.21/csu/libc-start.c:289

Hanno Boeck <hanno>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #38154:  patch-fix-heap-oob.patch added by hanno (455B - text/x-patch - Patch to fix heap oob)
file #34911:  patch-heapoverflow-pch_write_line.diff added by hanno (20B - text/x-patch - fuzzed patch causing oob)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by agruen (Posted a comment)
  • -email is unavailable- added by hanno (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2016-08-09 agruen StatusNone Fixed
        Open/ClosedOpen Closed
    2016-08-09 hanno Attached File- Added patch-fix-heap-oob.patch, #38154
    2015-09-17 hanno Attached File- Added patch-heapoverflow-pch_write_line.diff, #34911

    Back to the top

    Powered by Savane 3.13-3230.
    Corresponding source code