Bug 3457 - popen fails in sighandler after double free or corruption
Summary: popen fails in sighandler after double free or corruption
Status: RESOLVED INVALID
Alias: None
Product: glibc
Classification: Unclassified
Component: libc (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Ulrich Drepper
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-11-03 23:56 UTC by schaudhu
Modified: 2016-05-08 14:13 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:
fweimer: security-


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description schaudhu 2006-11-03 23:56:15 UTC
Please examine the following atomic example:

#include <iostream>
#include <signal.h>
#include <sys/signal.h>

using std::cout;
using std::endl;

void handler( int sig, siginfo_t *info, void *ctx )
{
    cout << "Got " << sig << " signal." << endl;
    popen( "/bin/ps", "r" );

    cout << "Finished." << endl;
}

int main()
{
    struct sigaction action;

    action.sa_sigaction = &handler;
    sigfillset( &action.sa_mask );
    action.sa_flags = SA_RESETHAND | SA_SIGINFO | SA_ONSTACK;

    sigaction( SIGABRT, &action, NULL );
    sigaction( SIGQUIT, &action, NULL );
    sigaction( SIGILL, &action, NULL );
    sigaction( SIGTRAP, &action, NULL );
    sigaction( SIGABRT, &action, NULL );
    sigaction( SIGFPE, &action, NULL );
    sigaction( SIGBUS, &action, NULL );
    sigaction( SIGSEGV, &action, NULL );
    sigaction( SIGSYS, &action, NULL );
    sigaction( SIGXCPU, &action, NULL );
    sigaction( SIGXFSZ, &action, NULL );

    void *p = ::malloc( 1 );
    ::free( p );
    ::free( p );

    return 0;
}

With older versions of glibc, this produces:

Got 11 signal.
Finished.
Segmentation fault (core dumped)


With newer versions of glibc, this HANGS after producing:

*** glibc detected *** double free or corruption (fasttop): 0x0804a008 ***
Got 6 signal.


The only way to terminate it is to forcibly kill the process.  Using system() 
instead of popen() works okay.  Can someone please investigate?

Thanks!
Comment 1 Ulrich Drepper 2006-11-04 00:02:55 UTC
You cannot use any non-async safe function in a signal handler.  The small list
of functions which is allowed is listed in section 2.4.3 of the XSH volume of POSIX.