Mitigate Baron SameEdit (CVE-2021-3156) vulnerability

fedora 23
race weakness #14


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 23 race weakness.

  * permissions are also set automatically by these functions. So
 * pty_set_owner() is only needed when the device needs to be owned by some
 * user other than the real user. 
int pty_set_owner(const char *slavename, uid_t uid)
    mode_t mode = S_IRUSR | S_IWUSR | S_IWGRP;
    struct stat status[1];
    int gid;

    if (stat(slavename, status) == -1)
        return -1;

    if ((gid = groupname2gid("tty")) == -1) {
        gid = uid2gid(uid);
        mode |= S_IWOTH;

    if (status->st_uid != uid || status->st_gid != (unsigned int) gid)
        if (chown(slavename, uid, gid) == -1)
            if (errno != EROFS || status->st_uid != uid)
                return -1;

    if ((status->st_mode & (S_IRWXU | S_IRWXG | S_IRWXO)) != mode)
        if (chmod(slavename, mode) == -1)
            if (errno != EROFS || (status->st_mode & (S_IRGRP | S_IROTH)))
                return -1;

    return 0;

/* pty_make_controlling_tty: Makes the slave pty the controlling terminal. 
 * slavefd contains the descriptor for the slave side of a pseudo terminal. 
 * slavename: the device name of the slave side of the pseudo terminal
 * Returns  : 0 on success or -1 on error.
 * NOTE: The descriptor of the resulting controlling terminal will be stored 
 * in slavefd. 
int pty_make_controlling_tty(int *slavefd, const char *slavename)
    int fd;

    void (*old) (int);
#endif /* USE_VHANGUP */

    if (!slavefd || *slavefd < 0 || !slavename)
        return set_errno(EINVAL); 

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.