bsc-performance-tools / extrae

Instrumentation framework to generate execution traces of the most used parallel runtimes.
https://tools.bsc.es/extrae
GNU Lesser General Public License v2.1
63 stars 40 forks source link

Memory corruption in ia32_Initialize #17

Closed devreal closed 6 years ago

devreal commented 6 years ago

I've been chasing a bug that led to corruption of the buffer containing the configuration file name during startup of extrae, leading to something like:

I/O warning : failed to load external entity "�"
Extrae: Detected GOMP version is 4.5
I/O warning : Extrae: Detected and hooked OpenMP runtime: [Intel KMPC] [GNU GOMP]
failed to load external entity "�"

After some debugging I found that the ia32 clock initialization is corrupting the memory and the reason seems to be the following lines in ia32_Initialize:

  char buffer[ 32768 ];
  [...]
  fp = fopen( "/proc/cpuinfo", "r" );
  bytes_read = fread( buffer, 1, sizeof( buffer ), fp );
  fclose( fp );

  if (bytes_read == 0)
    return;

  buffer[ bytes_read ] = '\0';

Note that if fread reads exactly 32k bytes the write access in the last line is out-of-bounds. Indeed the size of /proc/cpuinfo is larger than 32k on our system:

$ aprun -n 1 cat /proc/cpuinfo | wc
   1297    9469   52636

Changing the line to buffer[ bytes_read-1 ] = '\0'; seems to prevent the memory from getting corrupted and leads to successful parsing of the config file.

Also note that the same problem exists in the ia64 and ppc implementations.