[Full-Disclosure] (unsigned)-1 and large VM

From: Georgi Guninski (full-disclosure@lists.netsys.com)
Date: 08/28/02


From: full-disclosure@lists.netsys.com (Georgi Guninski)
Date: Wed, 28 Aug 2002 18:10:28 +0300

Potential vulnerability on 64 bit if a lot of virtual memory is present

Can't test this personally, but may turn exploitable.

The following code is somewhat common in some apps:
(a little modified from apache)
-----------------------
1 char *strdup (const char *str)
2 {
3 char *dup;
4 unsigned int len; // int len; also works
5 len=strlen(str);
6 if (!(dup = (char *) malloc(len + 1)))
7 return NULL;
8 dup = strcpy(dup, str);
9
10 return dup;
11}
-----------------------

Consider the following scenario:
str is large - 4GB-1.
strlen(str) returns (unsigned)-1 so len=(unsigned)-1;
on line 6 maloc(-1+1)==malloc(0) has chance of succeeding and on line
8 strcpy definitely screws some of the heap unless it segfaults.

Some difficulties include:
1. One should be able to supply in VM string of size (unsigned)-1 which is
4GB-1.
2. malloc(0) should succeed (works on linux and windoze)
3. strcpy should not segfault (probably possible if dup < str)
4. misc problems with the heap

Can someone with a lot of VM (4+GB) confirm or deny creating a string with
size (unsigned)-1 is possible?

Georgi Guninski
http://www.guninski.com



Relevant Pages

  • Re: Postscript questions
    ... use a test string for the name of such a procedure. ... string dup 1 packedarray cvx /s. ... exch def pop % for assembled numeric ...
    (comp.lang.postscript)
  • Re: Problems with TIB again, I think
    ... parse dup>r ... swap cmove (move string to one cell after here) ... r> allot align (get count and allocate mem for string, ...
    (comp.lang.forth)
  • Re: test for empty stack
    ... But DUP SIZE in returning 0. ... and still leave that null string on the stack in case you did. ... I wanted to trap the error of no input ...
    (comp.sys.hp48)
  • Re: String doesnt auto dup on modification
    ... 'cancel' instead of 'save' then you may want to keep the old string ... destructive method on the string, ... I've got the set_buffer doing a dup. ... So you would be typing away in the field. ...
    (comp.lang.ruby)
  • Postscript problems
    ... The file below has comments documenting these problems. ... /bd {bind def} bind def ... dup eq {(FS: General function not supported ... % now have X multiplier, string of proper length, file token, bool on L ...
    (comp.lang.postscript)