alpine 3.8
race weakness #30

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 or change the link content, a race condition results. Also, it does not terminate with ASCII NUL..

File Name:

kbuild/src/kBuild-0.1.9998-pre20131130/src/kmk/kbuild.c

Context:

The highlighted line of code below is the trigger point of this particular Alpine 3.8 race weakness.

 #endif
        g_pszInitialCwd = xstrdup(szTmp);
    else
        fatal(NILF, _("getcwd failed"));

    /*
     * Determin the executable name.
     */
    rc = -1;
#if defined(__APPLE__)
    {
        const char *pszImageName = _dyld_get_image_name(0);
        if (pszImageName)
        {
            size_t cchImageName = strlen(pszImageName);
            if (cchImageName < GET_PATH_MAX)
            {
                memcpy(szTmp, pszImageName, cchImageName + 1);
                rc = 0;
            }
        }
    }

#elif defined(__FreeBSD__)
    rc = readlink("/proc/curproc/file", szTmp, GET_PATH_MAX - 1);
    if (rc < 0 || rc == GET_PATH_MAX - 1)
    {
        rc = -1;
# if 0 /* doesn't work because l_name isn't always absolute, it's just argv0 from exec or something. */
        /* /proc is optional, try rtdl. */
        void *hExe = dlopen(NULL, 0);
        rc = -1;
        if (hExe)
        {
            struct link_map const *pLinkMap = 0;
            if (dlinfo(hExe, RTLD_DI_LINKMAP, &pLinkMap) == 0)
            {
                const char *pszImageName = pLinkMap->l_name;
                size_t cchImageName = strlen(pszImageName);
                if (cchImageName < GET_PATH_MAX)
                {
                    memcpy(szTmp, pszImageName, cchImageName + 1);
                    rc = 0;
                }
            }

        }
# endif
    }
    else 

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.