public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libc/14552] New: Two security issues in strcoll() function
@ 2012-09-06 16:18 shaun.colley at ioactive dot com
  2012-09-06 16:22 ` [Bug libc/14552] " shaun.colley at ioactive dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: shaun.colley at ioactive dot com @ 2012-09-06 16:18 UTC (permalink / raw)
  To: glibc-bugs

http://sourceware.org/bugzilla/show_bug.cgi?id=14552

             Bug #: 14552
           Summary: Two security issues in strcoll() function
           Product: glibc
           Version: 2.17
            Status: NEW
          Severity: normal
          Priority: P2
         Component: libc
        AssignedTo: unassigned@sourceware.org
        ReportedBy: shaun.colley@ioactive.com
                CC: drepper.fsp@gmail.com
    Classification: Unclassified


There are two problems with the strcoll() interface.


1) alloca() stack overflow

If the malloc() call fails (i.e. OOM conditions), strcoll() will failsafe back
to alloca(), which could result in unbounded alloca() calls and exploitable
conditions if the stack pointer is shifted over the guard area and into the
heap. See vulnerable code below.

       if (idx1arr == NULL)    // [5] memory allocation failed, use alloca()
...
       /* No memory.  Well, go with the stack then.

          XXX Once this implementation is stable we will handle this
          differently.  Instead of precomputing the indeces we will
          do this in time.  This means, though, that this happens for
          every pass again.  */
          goto try_stack;
          use_malloc = 1;
       }
     else
       {
       try_stack:
         idx1arr = (int32_t *) alloca (s1len * sizeof (int32_t));   // [6]
stack pointer shifting
         idx2arr = (int32_t *) alloca (s2len * sizeof (int32_t));
         rule1arr = (unsigned char *) alloca (s1len);
         rule2arr = (unsigned char *) alloca (s2len);


Here's my testcase.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <locale.h>

#define LEN 500000 

int main() {

char *ptr1 = malloc(LEN + 1);
char *ptr2 = malloc(LEN + 1);
char *wasted = NULL;
int i = 0, ret = 0;

if(!ptr1 || !ptr2) {
    printf("memory allocation failed\n");
    return -1;
}

memset(ptr1, 0x61, LEN);
memset(ptr2, 0x61, LEN); 

ptr1[LEN] = 0;
ptr2[LEN] = 0;

printf("strings allocated\n");

char *ptr = setlocale(LC_ALL, "en_US.UTF-8");
if(!ptr) {
    printf("error setting locale\n");
    return -1;
}

/* malloc() big chunks until we're out of memory */
do {    
wasted = malloc(1000000);
printf("%p\n", wasted);
i++;
} while(wasted);

ret = strcoll(ptr1, ptr2);

if(!ret) {
    printf("strings were lexicographically identical\n");
}

else {
    printf("strings were different\n");
}

return 0;
}



2) Integer overflows in the malloc() memory allocation.

int
  STRCOLL (s1, s2, l)
         const STRING_TYPE *s1;
         const STRING_TYPE *s2;
         __locale_t l;
    {

    [ … ]

  /* We need this a few times.  */
     s1len = STRLEN (s1);
     s2len = STRLEN (s2);

    [ … ]

    Please note that the localedef programs makes sure that `position'
    is not used at the first level.  */
    if (! __libc_use_alloca ((s1len + s2len) * (sizeof (int32_t) + 1)))  // [1]
if arithmetic is greater 65536, use malloc() instead of alloca()
     {
       idx1arr = (int32_t *) malloc ((s1len + s2len) * (sizeof (int32_t) + 1));
 // [2] attempt to get memory using malloc()


If s1 and s2 point to long strongs, the arithmetic in the malloc() argument may
give an integer overflow, and result in subsequent heap corruption.


Cheers,

Shaun

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


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

* [Bug libc/14552] Two security issues in strcoll() function
  2012-09-06 16:18 [Bug libc/14552] New: Two security issues in strcoll() function shaun.colley at ioactive dot com
@ 2012-09-06 16:22 ` shaun.colley at ioactive dot com
  2012-09-06 16:54 ` jsm28 at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: shaun.colley at ioactive dot com @ 2012-09-06 16:22 UTC (permalink / raw)
  To: glibc-bugs

http://sourceware.org/bugzilla/show_bug.cgi?id=14552

--- Comment #1 from Shaun Colley <shaun.colley at ioactive dot com> 2012-09-06 16:22:41 UTC ---
I've pasted the more complete fragment of code for the unbounded alloca() issue
below.

 /* We need this a few times.  */
     s1len = STRLEN (s1);
     s2len = STRLEN (s2);

    [ … ]

    Please note that the localedef programs makes sure that `position'
    is not used at the first level.  */
    if (! __libc_use_alloca ((s1len + s2len) * (sizeof (int32_t) + 1)))  // [1]
if arithmetic is greater 65536, use malloc() instead of alloca()
     {
       idx1arr = (int32_t *) malloc ((s1len + s2len) * (sizeof (int32_t) + 1)); 
       idx2arr = &idx1arr[s1len];   
       rule1arr = (unsigned char *) &idx2arr[s2len];
       rule2arr = &rule1arr[s1len];  

        if (idx1arr == NULL)
       /* No memory.  Well, go with the stack then.

          XXX Once this implementation is stable we will handle this
          differently.  Instead of precomputing the indeces we will
          do this in time.  This means, though, that this happens for
          every pass again.  */
          goto try_stack;
          use_malloc = 1;
       }
     else
       {
       try_stack:
         idx1arr = (int32_t *) alloca (s1len * sizeof (int32_t));   
         idx2arr = (int32_t *) alloca (s2len * sizeof (int32_t));
         rule1arr = (unsigned char *) alloca (s1len);
         rule2arr = (unsigned char *) alloca (s2len);
       }

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


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

* [Bug libc/14552] Two security issues in strcoll() function
  2012-09-06 16:18 [Bug libc/14552] New: Two security issues in strcoll() function shaun.colley at ioactive dot com
  2012-09-06 16:22 ` [Bug libc/14552] " shaun.colley at ioactive dot com
@ 2012-09-06 16:54 ` jsm28 at gcc dot gnu.org
  2014-06-17  4:45 ` fweimer at redhat dot com
  2015-02-24 11:35 ` fweimer at redhat dot com
  3 siblings, 0 replies; 5+ messages in thread
From: jsm28 at gcc dot gnu.org @ 2012-09-06 16:54 UTC (permalink / raw)
  To: glibc-bugs

http://sourceware.org/bugzilla/show_bug.cgi?id=14552

Joseph Myers <jsm28 at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |DUPLICATE

--- Comment #2 from Joseph Myers <jsm28 at gcc dot gnu.org> 2012-09-06 16:54:00 UTC ---
Duplicate of 14547, please add the extra details there.

*** This bug has been marked as a duplicate of bug 14547 ***

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


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

* [Bug libc/14552] Two security issues in strcoll() function
  2012-09-06 16:18 [Bug libc/14552] New: Two security issues in strcoll() function shaun.colley at ioactive dot com
  2012-09-06 16:22 ` [Bug libc/14552] " shaun.colley at ioactive dot com
  2012-09-06 16:54 ` jsm28 at gcc dot gnu.org
@ 2014-06-17  4:45 ` fweimer at redhat dot com
  2015-02-24 11:35 ` fweimer at redhat dot com
  3 siblings, 0 replies; 5+ messages in thread
From: fweimer at redhat dot com @ 2014-06-17  4:45 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=14552

Florian Weimer <fweimer at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |fweimer at redhat dot com
              Flags|                            |security-

--- Comment #3 from Florian Weimer <fweimer at redhat dot com> ---
This was assigned CVE-2012-4412 and CVE-2012-4424. See bug 14547 for details.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


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

* [Bug libc/14552] Two security issues in strcoll() function
  2012-09-06 16:18 [Bug libc/14552] New: Two security issues in strcoll() function shaun.colley at ioactive dot com
                   ` (2 preceding siblings ...)
  2014-06-17  4:45 ` fweimer at redhat dot com
@ 2015-02-24 11:35 ` fweimer at redhat dot com
  3 siblings, 0 replies; 5+ messages in thread
From: fweimer at redhat dot com @ 2015-02-24 11:35 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=14552

Florian Weimer <fweimer at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
              Alias|                            |CVE-2012-4424

--- Comment #4 from Florian Weimer <fweimer at redhat dot com> ---
Reusing this bug as the holder for one of the CVE aliases.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


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

end of thread, other threads:[~2015-02-24 11:35 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-09-06 16:18 [Bug libc/14552] New: Two security issues in strcoll() function shaun.colley at ioactive dot com
2012-09-06 16:22 ` [Bug libc/14552] " shaun.colley at ioactive dot com
2012-09-06 16:54 ` jsm28 at gcc dot gnu.org
2014-06-17  4:45 ` fweimer at redhat dot com
2015-02-24 11:35 ` fweimer 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).