Mitigate Baron SameEdit (CVE-2021-3156) vulnerability

rhel 7
race weakness #474

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:

socat-1.7.3.2/sycls.c

Context:

The highlighted line of code below is the trigger point of this particular Red Hat Enterprise Linux 7 race weakness.

 
int Readlink(const char *path, char *buf, size_t bufsiz) {
   int retval, _errno;
   Debug3("readlink(\"%s\", %p, "F_Zu")", path, buf, bufsiz);
   retval = readlink(path, buf, bufsiz);
   _errno = errno;
   Debug1("readlink() -> %d", retval);
   errno = _errno;
   return retval;
}

int Chown(const char *path, uid_t owner, gid_t group) {
   int retval, _errno;
   Debug3("chown(\"%s\", "F_uid", "F_gid")", path, owner, group);
   retval = chown(path, owner, group);
   _errno = errno;
   Debug1("chown()  -> %d", retval);
   errno = _errno;
   return retval;
}

int Chmod(const char *path, mode_t mode) {
   int retval, _errno;
   Debug2("chmod(\"%s\", 0%o)", path, mode);
   retval = chmod(path, mode);
   _errno = errno;
   Debug1("chmod()  -> %d", retval);
   errno = _errno;
   return retval;
}

#endif /* WITH_SYCLS */

#if HAVE_POLL
/* we only show the first struct pollfd; hope this is enough for most cases. */
int Poll(struct pollfd *ufds, unsigned int nfds, int timeout) {
   int _errno, result;
   if (!diag_in_handler) diag_flush();
#if WITH_SYCLS
   if (nfds == 4) {
      Debug10("poll({%d,0x%02hx,}{%d,0x%02hx,}{%d,0x%02hx,}{%d,0x%02hx,}, %u, %d)",
	      ufds[0].fd, ufds[0].events, ufds[1].fd, ufds[1].events,
	      ufds[2].fd, ufds[2].events, ufds[3].fd, ufds[3].events,
	      nfds, timeout);
   } else {
      Debug4("poll({%d,0x%02hx,}, , %u, %d)", ufds[0].fd, ufds[0].events, nfds, timeout);
   }
#endif /* WITH_SYCLS */
   result = poll(ufds, nfds, timeout);
   _errno = errno; 

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.