First published: Fri Jun 13 2014(Updated: )
posix_spawn_file_actions_addopen in glibc fails to copy the path argument. Per the specification (<a href="http://pubs.opengroup.org/onlinepubs/000095399/functions/posix_spawn_file_actions_addclose.html">http://pubs.opengroup.org/onlinepubs/000095399/functions/posix_spawn_file_actions_addclose.html</a>) it is supposed to. The result of not copying is that programs can easily trigger use-after-free bugs, or other situations where the path is mutated. The following program demonstrates this issue: #include <string.h> #include <assert.h> #include <fcntl.h> #include <unistd.h> #include <sys/types.h> #include <sys/wait.h> #include <stdlib.h> #include <spawn.h> #include <stdio.h> extern char *const *environ; int main() { int res; posix_spawn_file_actions_t fa; posix_spawn_file_actions_init(&fa); char *orig_path = "/tmp/afddsa"; char *path = malloc(strlen(orig_path) + 1); strcpy(path, orig_path); path[strlen(orig_path)] = '\0'; res = posix_spawn_file_actions_addopen( &fa, 1, path, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR); assert(res == 0); memset(path, 0, strlen(orig_path)); free(path); char *argv[] = {"/bin/echo", NULL}; pid_t pid; res = posix_spawn( &pid, "/bin/echo", &fa, NULL, argv, environ ); assert(res == 0); int status; wait4(pid, &status, 0, NULL); printf("%d\n", WEXITSTATUS(status)); } This bug was jointly discovered by David Reid, Alex Gaynor, and Glyph Lefkowitz. Issue is fixed in glibc 2.20: <a href="https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=89e435f3559c53084498e9baad22172b64429362">https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=89e435f3559c53084498e9baad22172b64429362</a> Recommended additional commit for backporting: <a href="https://sourceware.org/git/?p=glibc.git;a=commit;h=35a5e3e338ae17f3d42c6">https://sourceware.org/git/?p=glibc.git;a=commit;h=35a5e3e338ae17f3d42c6</a> External references: <a href="https://sourceware.org/bugzilla/show_bug.cgi?id=17048">https://sourceware.org/bugzilla/show_bug.cgi?id=17048</a>
Credit: cve@mitre.org
Affected Software | Affected Version | How to fix |
---|---|---|
redhat/glibc | <2.20 | 2.20 |
GNU glibc | <=2.19 | |
openSUSE openSUSE | =13.1 |
Sign up to SecAlerts for real-time vulnerability data matched to your software, aggregated from hundreds of sources.