centos 7
race weakness #4

5

Weakness Breakdown


Definition:

A race condition exists when parallel code accesses shared data without proper coordination. An attack that uses a race-condition weakness takes advantage of the unsafe data access to manipulate how one of the parallel sections of code reacts. Even though each process runs as intended, the outcome is unexpected. For example, consider a bank service that depends on an encryption key that it reads from a known location. An independent cryptography service is responsible for generating the key and placing it where the bank is expected to read it in a timely manner. If the bank and cryptography services do not coordinate with each other, then the bank may read a blank encryption key before cryptography writes the key to the location. This can effectively turn off all encryption for the bank without either service, or the administrator, knowing that something has gone wrong.

Warning code(s):

This accepts filename arguments; if an attacker can move those files, a race condition results..

File Name:

flac-1.3.0/src/test_libFLAC++/metadata_manip.cpp

Context:

The highlighted line of code below is the trigger point of this particular Centos 7 race weakness.

 	cleanup_tempfile_(tempfile, tempfilename);

	return true;
}

bool get_file_stats_(const char *filename, struct flac_stat_s *stats)
{
	FLAC__ASSERT(0 != filename);
	FLAC__ASSERT(0 != stats);
	return (0 == flac_stat(filename, stats));
}

void set_file_stats_(const char *filename, struct flac_stat_s *stats)
{
	struct utimbuf srctime;

	FLAC__ASSERT(0 != filename);
	FLAC__ASSERT(0 != stats);

	srctime.actime = stats->st_atime;
	srctime.modtime = stats->st_mtime;
	(void)flac_chmod(filename, stats->st_mode);
	(void)flac_utime(filename, &srctime);
#if !defined _MSC_VER && !defined __MINGW32__ && !defined __EMX__
	FLAC_CHECK_RETURN(chown(filename, stats->st_uid, (gid_t)(-1)));
	FLAC_CHECK_RETURN(chown(filename, (uid_t)(-1), stats->st_gid));
#endif
}

#ifdef FLAC__VALGRIND_TESTING
static size_t chain_write_cb_(const void *ptr, size_t size, size_t nmemb, ::FLAC__IOHandle handle)
{
	FILE *stream = (FILE*)handle;
	size_t ret = fwrite(ptr, size, nmemb, stream);
	if(!ferror(stream))
		fflush(stream);
	return ret;
}
#endif

static int chain_seek_cb_(::FLAC__IOHandle handle, FLAC__int64 offset, int whence)
{
	FLAC__off_t o = (FLAC__off_t)offset;
	FLAC__ASSERT(offset == o);
	return fseeko((FILE*)handle, o, whence);
}

static FLAC__int64 chain_tell_cb_(::FLAC__IOHandle handle)
{
	return ftello((FILE*)handle); 

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.