centos 6
tmpfile weakness #44


Weakness Breakdown


A temporary file weakness occurs when a temporary file that is created and used by a high-privilege process is accidentally shared with a low-privilege process, on account of it being temporary and generated after all security controls have been applied. This allows the low-privilege process to read data from the high-privilege process (information leakage), or worse, influence the high-privilege process by modifying the shared temporary file.

Warning code(s):

Temporary file race condition.

File Name:



The highlighted line of code below is the trigger point of this particular Centos 6 tmpfile weakness.

 static void *
tf_accept (void *arg)
  struct sockaddr_un sun;
  /* To test a non-blocking accept call we make the call file by using
     a datagrame socket.  */
  int pf = arg == NULL ? SOCK_STREAM : SOCK_DGRAM;

  tempfd = socket (AF_UNIX, pf, 0);
  if (tempfd == -1)
      printf ("%s: socket call failed\n", __FUNCTION__);
      exit (1);

  int tries = 0;
      if (++tries > 10)
	  printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__);

      strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-1-XXXXXX");
      if (mktemp (sun.sun_path) == NULL)
	  printf ("%s: cannot generate temp file name\n", __FUNCTION__);
	  exit (1);

      sun.sun_family = AF_UNIX;
  while (bind (tempfd, (struct sockaddr *) &sun,
	       offsetof (struct sockaddr_un, sun_path)
	       + strlen (sun.sun_path) + 1) != 0);

  unlink (sun.sun_path);

  listen (tempfd, 5);

  socklen_t len = sizeof (sun);

  int r = pthread_barrier_wait (&b2);
      printf ("%s: barrier_wait failed\n", __FUNCTION__);
      exit (1);

  if (arg != NULL) 

The registered trademark Linux® is used pursuant to a sublicense from the Linux Foundation, the exclusive licensee of Linus Torvalds, owner of the mark on a world­wide basis.