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.
avfs/src/avfs-1.0.6/src/oper.c
The highlighted line of code below is the trigger point of this particular Alpine 3.9 race weakness.
newlink = malloc(dotdots * 3 + strlen(l) + 2);
if (!newlink) {
av_log(AVLOG_ERROR, "transform_symlink: memory allocation failed");
exit(1);
}
for (s = newlink, i = 0; i < dotdots; i++, s += 3)
strcpy(s, "../");
if (l[0])
strcpy(s, l);
else if (!dotdots)
strcpy(s, ".");
else
s[0] = '\0';
*linkp = newlink;
}
int av_readlink(ventry *ve, char **bufp)
{
int res;
struct avfs *avfs = ve->mnt->avfs;
AVFS_LOCK(avfs);
res = avfs->readlink(ve, bufp);
AVFS_UNLOCK(avfs);
if(res == 0) {
if(*bufp[0] == '/' && av_get_symlink_rewrite() == 1) {
char *rel_link = NULL;
char *path = NULL;
int res2;
res2 = av_generate_path(ve, &path);
if(res2 == 0) {
transform_symlink(path, *bufp, &rel_link);
if(rel_link != NULL) {
free(*bufp);
*bufp = rel_link;
}
av_free(path);
}
}
}
return res;
}
int av_unlink(ventry *ve)