alpine 3.6
tmpfile weakness #37


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 Alpine 3.6 tmpfile weakness.

	if (cinode)
		ocfs2_free_cached_inode(fs, cinode);

static void create_symlink(ocfs2_filesys *fs,
				 uint64_t blkno, uint64_t *retblkno)
	errcode_t ret;
	uint64_t tmp_blkno;
	uint32_t clusters = 1;
	char random_name[OCFS2_MAX_FILENAME_LEN];

	memset(random_name, 0, sizeof(random_name));
	sprintf(random_name, "testXXXXXX");

	/* Don't use mkstemp since it will create a file 
	 * in the working directory which is no use.
	 * Use mktemp instead Although there is a compiling warning.
	 * mktemp fails to work in some implementations follow BSD 4.3,
	 * but currently ocfs2 will only support linux,
	 * so it will not affect us.
	if (!mktemp(random_name))
		FSWRK_COM_FATAL(progname, errno);

	ret = ocfs2_check_directory(fs, blkno);
	if (ret)
		FSWRK_COM_FATAL(progname, ret);

	ret = ocfs2_new_inode(fs, &tmp_blkno, S_IFLNK | 0755);
	if (ret)
		FSWRK_COM_FATAL(progname, ret);

	ret = ocfs2_link(fs, blkno, random_name, tmp_blkno, OCFS2_FT_SYMLINK);
	if (ret)
		FSWRK_COM_FATAL(progname, ret);

	ret = ocfs2_extend_allocation(fs, tmp_blkno, clusters);
	if (ret)
		FSWRK_COM_FATAL(progname, ret);

	add_symlink(fs, tmp_blkno);

	*retblkno = tmp_blkno;

static void corrupt_symlink_file(ocfs2_filesys *fs, uint64_t blkno, 

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.