public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libc/214] New: sbrk() doesn't detect brk() failures. Malloc doesn't handle sbrk() failures
@ 2004-06-10 19:38 dlstevens at us dot ibm dot com
  2004-06-18 17:35 ` [Bug libc/214] " dlstevens at us dot ibm dot com
                   ` (16 more replies)
  0 siblings, 17 replies; 18+ messages in thread
From: dlstevens at us dot ibm dot com @ 2004-06-10 19:38 UTC (permalink / raw)
  To: glibc-bugs

On Linux systems, the "brk" system call returns 0 for success, but returns the
old end-of-data-segment when the RLIMIT_DATA soft limit is exceeded
(kernel 2.6.x).

"sbrk" in glibc has the following code:

       if (__brk (oldbrk + increment) < 0)
             return (void *) -1;
       return oldbrk;

On Linux systems, sbrk() returns the same value whether or not the allocation
exceeded the soft limit.

For Linux systems, this test should be:

        if (__brk (oldbrk + increment) != 0)
              return (void *) -1;
        return oldbrk;

I retested with a modified Linux kernel where brk() returns -1 for the failure
case and this led to another bug in malloc() [not yet filed or investigated].
Apparently, malloc() does not properly check for sbrk() failures in all cases,
so the retest resulted in a segmentation violation within the malloc code,
instead of malloc() returning NULL as expected.


Reproduce (sbrk issue) by:
     get current VmData size by reading /proc/self/status.
     use setrlimit() to set RLIMIT_DATA/rlim_cur to that value
     do an sbrk() of more than a page

Reproduce (malloc issue) by:
     same, but do enough malloc()'s to exhaust MMAPs; when it
     falls back to sbrk(), it gets a segmentation violation

-- 
           Summary: sbrk() doesn't detect brk() failures. Malloc doesn't
                    handle sbrk() failures
           Product: glibc
           Version: 2.3.2
            Status: NEW
          Severity: normal
          Priority: P2
         Component: libc
        AssignedTo: gotom at debian dot or dot jp
        ReportedBy: dlstevens at us dot ibm dot com
                CC: glibc-bugs at sources dot redhat dot com


http://sources.redhat.com/bugzilla/show_bug.cgi?id=214

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2006-04-01 20:21 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-06-10 19:38 [Bug libc/214] New: sbrk() doesn't detect brk() failures. Malloc doesn't handle sbrk() failures dlstevens at us dot ibm dot com
2004-06-18 17:35 ` [Bug libc/214] " dlstevens at us dot ibm dot com
2004-09-26 21:29 ` drepper at redhat dot com
2006-03-03 22:01 ` rsa at us dot ibm dot com
2006-03-06 21:37 ` rsa at us dot ibm dot com
2006-03-08 19:21 ` rsa at us dot ibm dot com
2006-03-10 20:33 ` rsa at us dot ibm dot com
2006-03-10 22:18 ` rsa at us dot ibm dot com
2006-03-13 16:24 ` rsa at us dot ibm dot com
2006-03-14 18:34 ` rsa at us dot ibm dot com
2006-03-14 19:59 ` dlstevens at us dot ibm dot com
2006-03-15 20:18 ` rsa at us dot ibm dot com
2006-03-15 21:21 ` dlstevens at us dot ibm dot com
2006-03-16  0:29 ` rsa at us dot ibm dot com
2006-03-20 19:59 ` rsa at us dot ibm dot com
2006-03-20 20:27 ` dlstevens at us dot ibm dot com
2006-03-21 23:56 ` dlstevens at us dot ibm dot com
2006-04-01 20:21 ` drepper at redhat dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).