alpine 3.6
tmpfile weakness #38


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.

void mess_up_dir_parent_dup(ocfs2_filesys *fs, enum fsck_type type,
			    uint64_t blkno)
	errcode_t ret;
	uint64_t parent1, parent2, tmp_blkno;
	char random_name[OCFS2_MAX_FILENAME_LEN];

	/* create 2 direcotories */
	create_directory(fs, blkno, &parent1);
	create_directory(fs, blkno, &parent2);

	/* create a directory under parent1, tmp_blkno indicates its inode. */
	create_directory(fs, parent1, &tmp_blkno);

	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_link(fs, parent2, random_name, tmp_blkno, OCFS2_FT_DIR);
        if (ret)
		FSWRK_COM_FATAL(progname, ret);
	fprintf(stdout, "DIR_PARENT_DUP: "

		"Create a directory #%"PRIu64
		" which has two parents: #%"PRIu64" and #%"PRIu64".\n",
		tmp_blkno, parent1, parent2);


void mess_up_dir_inode(ocfs2_filesys *fs, enum fsck_type type, uint64_t blkno)
	errcode_t ret;
	char *buf = NULL;
	struct ocfs2_dinode *di;
	struct ocfs2_extent_list *el;
	uint64_t tmp_blkno;

	create_directory(fs, blkno, &tmp_blkno);

	ret = ocfs2_malloc_block(fs->fs_io, &buf); 

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.