alpine 3.8
tmpfile weakness #17

4

Weakness Breakdown


Definition:

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:

kbuild/src/kBuild-0.1.9998-pre20131130/src/kmk/main.c

Context:

The highlighted line of code below is the trigger point of this particular Alpine 3.8 tmpfile weakness.

   mib[0] = CTL_HW;
  mib[1] = HW_NCPU;
  if (!sysctl(mib, 2, &cpus, &sz, NULL, 0)
      && cpus >= 1)
    return cpus;
  cpus = -1;
#  endif /* CTL_HW */

  /* no idea / failure, just return 1. */
  return 1;
# endif
}
#endif /* KMK */

#ifdef __MSDOS__
static void
msdos_return_to_initial_directory (void)
{
  if (directory_before_chdir)
    chdir (directory_before_chdir);
}
#endif  /* __MSDOS__ */

#ifndef _MSC_VER /* bird */
char *mktemp (char *template);
#endif
int mkstemp (char *template);

FILE *
open_tmpfile(char **name, const char *template)
{
#ifdef HAVE_FDOPEN
  int fd;
#endif

#if defined HAVE_MKSTEMP || defined HAVE_MKTEMP
# define TEMPLATE_LEN   strlen (template)
#else
# define TEMPLATE_LEN   L_tmpnam
#endif
  *name = xmalloc (TEMPLATE_LEN + 1);
  strcpy (*name, template);

#if defined HAVE_MKSTEMP && defined HAVE_FDOPEN
  /* It's safest to use mkstemp(), if we can.  */
  fd = mkstemp (*name);
  if (fd == -1)
    return 0;
  return fdopen (fd, "w");
#else 

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.