shmat fails problem in RedHat Linux 4 - Security

This is a discussion on shmat fails problem in RedHat Linux 4 - Security ; /* shmtest: Program to exhibit Red Hat Linux 4 shared memory problem. To exhibit the problem: Run it once as follows to initialize shared memory: % shmtest init Then run it repeatedly as follows to test access to shared memory: ...

+ Reply to Thread
Results 1 to 5 of 5

Thread: shmat fails problem in RedHat Linux 4

  1. shmat fails problem in RedHat Linux 4

    /*

    shmtest: Program to exhibit Red Hat Linux 4 shared memory problem.

    To exhibit the problem:

    Run it once as follows to initialize shared memory:
    % shmtest init

    Then run it repeatedly as follows to test access to shared memory:
    % shmtest

    It will sometimes print SUCCESS and sometimes print FAILURE. Why?

    Reproducibility:

    The problem is reproducible under Red Hat Linux 4, with kernel
    version 2.6, both the EL version and the SMP version,
    under both the Red Hat Linux Enterprise ES version and the Red Hat
    Linux Advanced Server AS version.

    The problem occurs with a "default" Red Hat Linux installation as
    well as a "complete" installation, with or without patches to the
    latest Red Hat Linux 4 version, and with the SELinux component
    either enabled or disabled.

    The problem DOES NOT occur under Red Hat Linux 3 (kernel version
    2.4),
    SuSE Linux (kernel version 2.6), nor Debian Linux (kernel version
    2.6).

    */

    #include
    #include
    #include

    #define KEY1 1111
    #define KEY2 2222
    #define SIZE1 1000
    #define SIZE2 1000

    int shmid1, shmid2 ;
    char *shmptr1, *shmptr2 ;

    main(int argc, char *argv[]) {

    errno = 0 ;

    /* Initialization: create 2 shared memory partitions. */
    if ( argc > 1 ) {

    shmid1 = shmget(KEY1, 1000, IPC_CREAT|0666) ;
    if ( shmid1 < 0 ) exit(1) ;

    shmptr1 = (char *)shmat(shmid1, 0, 0666) ;
    if ( (long)shmptr1 == -1 ) exit(2) ;

    shmid2 = shmget(KEY2, 1000, IPC_CREAT|0666) ;
    if ( shmid2 < 0 ) exit(3) ;

    shmptr2 = (char *)shmat(shmid2, 0, 0666) ;
    if ( (long)shmptr2 == -1 ) exit(4) ;

    /* Save address of 2nd partition in 1st partition. */
    *(char **)shmptr1 = shmptr2 ;

    printf("Shared memory initialized.\n") ;
    exit(0) ;
    }

    /* Test: locate and access shared memory partitions. */
    shmid1 = shmget(KEY1, SIZE1, 0666) ;
    if ( shmid1 < 0 ) exit(5) ;

    shmptr1 = (char *)shmat(shmid1, 0, 0666) ;
    if ( (long)shmptr1 == -1 ) exit(6) ;

    /* Fetch address of 2nd partition from 1st partition. */
    shmptr2 = *(char **)shmptr1 ;

    shmid2 = shmget(KEY2, SIZE2, 0666) ;
    if ( shmid2 < 0 ) exit(7) ;

    shmptr2 = (char *)shmat(shmid2, shmptr2, 0666) ;
    if ( (long)shmptr2 == -1 ) {
    printf ("FAILURE, errno = %d\n", errno) ;
    exit(8) ; }

    printf("SUCCESS\n") ;
    exit(0) ;

    }

    Thanks for any insight...

    Rock


  2. Re: shmat fails problem in RedHat Linux 4

    wrote in message
    news:1141925860.070155.99970@v46g2000cwv.googlegro ups.com

    > shmtest: Program to exhibit Red Hat Linux 4 shared memory problem.
    > To exhibit the problem:
    > Run it once as follows to initialize shared memory:
    > % shmtest init
    > Then run it repeatedly as follows to test access to shared memory:
    > % shmtest
    > It will sometimes print SUCCESS and sometimes print FAILURE. Why?


    strace -o /tmp/strace.output ./shmtest

    Examine the /tmp/strace.output file after the init, and after the SUCCESS
    and FAILURE modes.


  3. Re: shmat fails problem in RedHat Linux 4


    ynotssor wrote:
    > wrote in message
    > news:1141925860.070155.99970@v46g2000cwv.googlegro ups.com
    >
    > > shmtest: Program to exhibit Red Hat Linux 4 shared memory problem.
    > > To exhibit the problem:
    > > Run it once as follows to initialize shared memory:
    > > % shmtest init
    > > Then run it repeatedly as follows to test access to shared memory:
    > > % shmtest
    > > It will sometimes print SUCCESS and sometimes print FAILURE. Why?

    >
    > strace -o /tmp/strace.output ./shmtest
    >
    > Examine the /tmp/strace.output file after the init, and after the SUCCESS
    > and FAILURE modes.


    Hi, Thanks. Using strace is exactly what we did to isolate the
    problem and make the demonstration program. Whether you trace or not,
    Unix sometimes says OK and
    sometimes says NO to the exact same system call, and there's no clue
    why.

    Any ideas?


  4. Re: shmat fails problem in RedHat Linux 4

    In comp.os.linux.security rockkon@verizon.net:
    > /*


    > shmtest: Program to exhibit Red Hat Linux 4 shared memory problem.


    > To exhibit the problem:


    > Run it once as follows to initialize shared memory:
    > % shmtest init


    > Then run it repeatedly as follows to test access to shared memory:
    > % shmtest


    > It will sometimes print SUCCESS and sometimes print FAILURE. Why?


    > Reproducibility:


    > The problem is reproducible under Red Hat Linux 4, with kernel
    > version 2.6, both the EL version and the SMP version,
    > under both the Red Hat Linux Enterprise ES version and the Red Hat
    > Linux Advanced Server AS version.


    > The problem occurs with a "default" Red Hat Linux installation as
    > well as a "complete" installation, with or without patches to the
    > latest Red Hat Linux 4 version, and with the SELinux component
    > either enabled or disabled.


    > The problem DOES NOT occur under Red Hat Linux 3 (kernel version
    > 2.4),
    > SuSE Linux (kernel version 2.6), nor Debian Linux (kernel version
    > 2.6).


    You have installed all patches available for RHEL 4, including
    kernel, preferable via up2date?

    You have selinux enabled and could try disabling it and see if
    this improves things.

    [..]

    Good luck

    --
    Michael Heiming (X-PGP-Sig > GPG-Key ID: EDD27B94)
    mail: echo zvpunry@urvzvat.qr | perl -pe 'y/a-z/n-za-m/'
    #bofh excuse 89: Electromagnetic energy loss

  5. Re: shmat fails problem in RedHat Linux 4


    Michael Heiming wrote:
    > In comp.os.linux.security rockkon@verizon.net:
    > > /*

    >
    > You have installed all patches available for RHEL 4, including
    > kernel, preferable via up2date?
    >
    > You have selinux enabled and could try disabling it and see if
    > this improves things.
    >
    > [..]
    >
    > Good luck
    >


    Hi Michael,

    Thanks. We think we found the problem, we think... There is a
    difference in the new gcc compiler. If we compile the program under ES
    4 it works without fail. If we compile the program under Red Hat Linux
    7.2, the random problem appears.

    Rock


+ Reply to Thread