Mitigate Baron SameEdit (CVE-2021-3156) vulnerability

sles 15.2
tmpfile weakness #34


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 Sles 15.2 tmpfile weakness.

 int do_mkstemp(char *template, mode_t perms)
	RETURN_ERROR_IF(dry_run, 0);
	perms |= S_IWUSR;

#if defined HAVE_SECURE_MKSTEMP && defined HAVE_FCHMOD && (!defined HAVE_OPEN64 || defined HAVE_MKSTEMP64)
		int fd = mkstemp(template);
		if (fd == -1)
			return -1;
		if (fchmod(fd, perms) != 0 && preserve_perms) {
			int errno_save = errno;
			errno = errno_save;
			return -1;
#if defined HAVE_SETMODE && O_BINARY
		setmode(fd, O_BINARY);
		return fd;
	if (!mktemp(template))
		return -1;
	return do_open(template, O_RDWR|O_EXCL|O_CREAT, perms);

int do_stat(const char *fname, STRUCT_STAT *st)
	return stat64(fname, st);
	return stat(fname, st);

int do_lstat(const char *fname, STRUCT_STAT *st)
# ifdef USE_STAT64_FUNCS
	return lstat64(fname, st);
# else
	return lstat(fname, st);
# endif
	return do_stat(fname, st);

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.