Mitigate Baron SameEdit (CVE-2021-3156) vulnerability

fedora 25
race weakness #507


Weakness Breakdown


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:



The highlighted line of code below is the trigger point of this particular Fedora 25 race weakness.

 		return -1;

	if (param->server)	{
		if (param->type == COMM_TYPE_LOCAL) {

			/* Bind a name to the socket. */
			memset(&lname, 0, sizeof(struct sockaddr_un));
			lname.sun_family = AF_LOCAL;
			strncpy (lname.sun_path, param->name, sizeof (lname.sun_path) - 1);
			lname.sun_path[sizeof (lname.sun_path) - 1] = '\0';

			/* The size of the address is
			the offset of the start of the filename,
			plus its length,
			plus one for the terminating null byte.
			Alternatively you can just do:
			size = SUN_LEN (&name);
			size = (offsetof (struct sockaddr_un, sun_path)	+ strlen (lname.sun_path) + 1);

			if (bind (sock, (struct sockaddr *) &lname, size) < 0)
				return -1;

			chmod(param->name, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
		} else {
			/* Give the socket a name. */
			memset(&iname, 0, sizeof(struct sockaddr_in));
			iname.sin_family = AF_INET;
			iname.sin_port = htons (param->port);
			iname.sin_addr.s_addr = htonl(INADDR_ANY);
			if (bind(sock, (struct sockaddr *) &iname, sizeof (iname)) < 0)
				return -1;

	return sock;

int connect_comm(int conn_num, comm_param *param)
	struct sockaddr_un lname;
	struct sockaddr_in iname;
	struct hostent *hostinfo;
	size_t size;
	int attempt;
	int max_attempt;
	int not_connected;

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.