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 <sys/types.h>
#include <sys/ipc.h>
#include <errno.h>

#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

.



Relevant Pages

  • shmat fails problem in RedHat Linux 4
    ... shmtest: Program to exhibit Red Hat Linux 4 shared memory problem. ... The problem DOES NOT occur under Red Hat Linux 3 (kernel version ...
    (linux.redhat.misc)
  • shmat fails problem in RedHat Linux 4
    ... shmtest: Program to exhibit Red Hat Linux 4 shared memory problem. ... The problem DOES NOT occur under Red Hat Linux 3 (kernel version ...
    (alt.os.linux)
  • Re: shmat fails problem in RedHat Linux 4
    ... If we compile the program under Red Hat Linux 7.2, ... Program to exhibit Red Hat Linux 4 shared memory problem. ... The problem DOES NOT occur under Red Hat Linux 3 (kernel version ...
    (linux.redhat.misc)
  • Re: shmat fails problem in RedHat Linux 4
    ... If we compile the program under Red Hat Linux 7.2, ... Program to exhibit Red Hat Linux 4 shared memory problem. ... The problem DOES NOT occur under Red Hat Linux 3 (kernel version ...
    (alt.os.linux)
  • [RHSA-2003:238-01] Updated 2.4 kernel fixes vulnerabilities
    ... The Linux kernel handles the basic functions of the operating system. ... Several security issues have been discovered affecting the Linux kernel: ... If you use Red Hat Linux 7.1, you must have installed quota-3.06-9.71 from ...
    (Bugtraq)