alpine 3.8
tmpfile weakness #4

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:

imake/src/imake-1.0.7/imake.c

Context:

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

 	init();

	lenCrossCompileDir = strlen(CrossCompileDir);
	if (lenCrossCompileDir) {
	    if (lenCrossCompileDir > (PATH_MAX - 20))
	      LogFatal("Cross compile directory path too long %s\n",
		       CrossCompileDir);
	    else
		CrossCompiling = TRUE;
	}

	SetOpts(argc, argv);
	Imakefile = FindImakefile(Imakefile);
	CheckImakefileC(ImakefileC);
	if (Makefile) {
		tmpMakefile = Makefile;
		if ((tmpfd = fopen(tmpMakefile, "w+")) == NULL)
		   LogFatal("Cannot create temporary file %s.", tmpMakefile);
	} else {
#ifdef HAVE_MKSTEMP
		int fd;
#endif
		char *tmpMakefileName = Strdup(tmpMakefileTemplate);
#ifndef HAVE_MKSTEMP
		if (mktemp(tmpMakefileName) == NULL ||
		    (tmpfd = fopen(tmpMakefileName, "w+")) == NULL) {
		   LogFatal("Cannot create temporary file %s.", tmpMakefileName);
		}
#else
		fd = mkstemp(tmpMakefileName);
		if (fd == -1 || (tmpfd = fdopen(fd, "w+")) == NULL) {
		   if (fd != -1) {
		      unlink(tmpMakefileName); close(fd);
		   }
		   LogFatal("Cannot create temporary file %s.", tmpMakefileName);
		}
#endif
		tmpMakefile = tmpMakefileName;
	}
	AddMakeArg("-f");
	AddMakeArg( tmpMakefile );
	sprintf(makeMacro, "MAKE=%s", program);
	AddMakeArg( makeMacro );
	sprintf(makefileMacro, "MAKEFILE=%s", Imakefile);
	AddMakeArg( makefileMacro );

	cleanedImakefile = CleanCppInput(Imakefile);
	cppit(cleanedImakefile, Template, ImakefileC, tmpfd, tmpMakefile);

	if (show) { 

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.