Re: memcpy with negative length and destination on heap - exploitable?

From: dullien@gmx.de
Date: 12/26/01


Date: Wed, 26 Dec 2001 07:13:30 -0800
From: dullien@gmx.de
To: 3APA3A <3APA3A@SECURITY.NNOV.RU>

Hey 3APA3A,

3> Theoretically, are there are any situations, then it's possible to
3> exploit this kind of bug:
3> char src[FEW * KB_OF_DATA], * dst;
3> get_user_input(src, sizeof(src));
3> len = src[POSITION]; /* char is signed and can be negative! */
3> dst = malloc(256);
3> memcpy(dst, src + POSITION + 1, len);
3> len is too long then converted to size_t and memcpy will crash... Is
3> it possible to avoid it if destination buffer is on heap? Program is
3> available on all possible platforms :)

Normally, no -- unless of course the application handle's it's own
segfault and issues either a malloc() or a free() on the corrupted
heap.
If it happens on the stack (under NT), you might be able to overwrite
SEH structures before segfaulting and thus gain control.

Auditing ISC code, eh ? ;)

Cheers,
dullien@gmx.de

-- 
Mit freundlichen Grüssen
dullien@gmx.de                            mailto:dullien@gmx.de



Relevant Pages

  • Windows Help Heap Overflow
    ... 3: Bug Impact Rate: Undefined ... There is a heap based buffer overflow in the rendering engine of .hlp files in winhlp32.exe which will allow some ... Therefor I release this Heap Overflow as another ... set ecx -> Top SE handler address ...
    (Bugtraq)
  • Re: Preventing memory leaks with TDD
    ... the stack space of a function after returning from it, or into heap space ... means portably available in the programming language / standard library. ... For writing your tests in a way that they trigger the bug for sure, ... the requirements of 'setName' should state whether or not ...
    (comp.object)
  • Re: writing to freed memory--issues
    ... I was playing around with a toy program, which led to some confusion. ... bug, just trying to understand the behavior. ... Why does the segfault keep occurring ... I figure understanding ...
    (comp.os.linux.development.apps)
  • Re: Debug vs Release...Some questions...Please Help...
    ... It is almost certainly a bug. ... release heap, so heap damage will have different manifestations in each. ... carve away at pieces trying to find which static constructor or DLL has done you in. ...
    (microsoft.public.vc.mfc)
  • RE: Several Application Verifier Bugs and a Feature Request
    ... I click on Dlls and type the name of a dll. ... hpa - Place heap allocations at ends of pages ... I look at the PageHeapTargetDlls registry entry for my .exe. ... For bug #2, under the heaps test, set the Addr property to true. ...
    (microsoft.public.win32.programmer.tools)