alpine 3.7
race weakness #8

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:

augeas/src/augeas-1.9.0/tests/test-save.c

Context:

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

 }

/* Test that we handle failure to save a file because we lack permission on
 * the target file is handled gracefully.
 *
 * As reported in https://github.com/hercules-team/augeas/issues/178, this
 * used to lead to a SEGV
 */
static void testSaveNoPermission(CuTest *tc) {
    if (getuid() == 0) {
        puts("pending (testSaveNoPermission): can't test permissions under root account");
        return;
    }

    int r;
    char *path = NULL;
    const char *v;

    r = asprintf(&path, "%s/etc/hosts", root);
    CuAssertPositive(tc, r);

    r = aug_set(aug, "/files/etc/hosts/1/alias[1]", "othername");
    CuAssertRetSuccess(tc, r);

    r = chmod(path, 0);
    CuAssertRetSuccess(tc, r);

    r = aug_save(aug);
    CuAssertIntEquals(tc, -1, r);

    r = aug_get(aug, "/augeas/files/etc/hosts/error", &v);
    CuAssertIntEquals(tc, 1, r);
    CuAssertStrEquals(tc, "replace_from_missing", v);
    free(path);
}

int main(void) {
    char *output = NULL;
    CuSuite* suite = CuSuiteNew();

    abs_top_srcdir = getenv("abs_top_srcdir");
    if (abs_top_srcdir == NULL)
        die("env var abs_top_srcdir must be set");

    abs_top_builddir = getenv("abs_top_builddir");
    if (abs_top_builddir == NULL)
        die("env var abs_top_builddir must be set");

    if (asprintf(&src_root, "%s/tests/root", abs_top_srcdir) < 0) {
        die("failed to set src_root"); 

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.