Bug 91303 - program using getcontext/setcontext/swapcontext crashes if LD_LIBRARY_PATH contains /lib and application is linked with libpthread
program using getcontext/setcontext/swapcontext crashes if LD_LIBRARY_PATH co...
Status: CLOSED NOTABUG
Product: Red Hat Linux
Classification: Retired
Component: glibc (Show other bugs)
8.0
All Linux
low Severity high
: ---
: ---
Assigned To: Jakub Jelinek
Brian Brock
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2003-05-20 23:44 EDT by Mohammed Abouzour
Modified: 2016-11-24 10:27 EST (History)
1 user (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2003-06-09 23:28:29 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Mohammed Abouzour 2003-05-20 23:44:41 EDT
Description of problem:
If LD_LIBRARY_PATH contain /lib, a program that uses 
getcontext/setcontext/swapcontext function and links with 
libpthread  will crash if it tries to access the errno value.
The crash will happen after the first swapcontext() call. If
LD_LIBRARY_PATH is unset or /lib is not in the list of directories,
program runs correctly.
The following foo.c program reproduces the problem as per the steps below:
#include <stdlib.h>
#include <stdio.h>
#include <ucontext.h>
#include <malloc.h>
 
ucontext_t func, main_func;
 
void MyFunc()
{
    printf( "MyFunc running\n" ); // this will crash 
    printf( "Now func switching back to main_func\n" );
    swapcontext( &func, &main_func );
}
 
int main()
{
    char * ss_sp = (char *)malloc( 16 * 1024 );

    // Get the current execution context
    getcontext( &func );
 
    // Modify the context to a new stack
    func.uc_link = 0;
    func.uc_stack.ss_flags = 0;        
    func.uc_stack.ss_size = (16* 1024);
    func.uc_stack.ss_sp = ss_sp;
 
    printf( "Creating thread context... \n" );
    makecontext( &func, &MyFunc, 0 );
         
    printf( "Switching to thread \n" );
    swapcontext( &main_func, &func );

    free( ss_sp );
 
    printf( "main_func done\n" );
         
    return 0;
}


Version-Release number of selected component (if applicable):


How reproducible:
Every time.

Steps to Reproduce:
1. g++ foo.c -o foo -lpthread
2. export LD_LIBRARY_PATH=/lib
3. ./foo
    
Actual results:
Creating thread context... 
Switching to thread 
Segmentation fault

Expected results:
Creating thread context... 
Switching to thread 
MyFunc running
Now func switching back to main_func
main_func done

Additional info:
Comment 1 Ulrich Drepper 2003-06-09 23:28:29 EDT
That's not a bug.  The thread library in /lib cannot possibly handle setcontext
etc since it does not use a thread register and has to rely on the stack pointer
to lead to the thread decriptor.  Use the thread library in /lib/i686 or on RHL9
in /lib/tls.

Note You need to log in before you can comment on or make changes to this bug.