Bug 1109263 - (CVE-2014-4043) CVE-2014-4043 glibc: posix_spawn_file_actions_addopen fails to copy the path argument
CVE-2014-4043 glibc: posix_spawn_file_actions_addopen fails to copy the path ...
Status: NEW
Product: Security Response
Classification: Other
Component: vulnerability (Show other bugs)
unspecified
All Linux
low Severity low
: ---
: ---
Assigned To: Red Hat Product Security
impact=low,public=20140611,reported=2...
: Reopened, Security
Depends On: 1109745
Blocks: 1109746
  Show dependency treegraph
 
Reported: 2014-06-13 10:10 EDT by Vasyl Kaigorodov
Modified: 2018-01-29 20:03 EST (History)
8 users (show)

See Also:
Fixed In Version: glibc 2.20
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2014-06-16 07:39:12 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Vasyl Kaigorodov 2014-06-13 10:10:19 EDT
posix_spawn_file_actions_addopen in glibc fails to copy the path argument.
Per the specification (http://pubs.opengroup.org/onlinepubs/000095399/functions/posix_spawn_file_actions_addclose.html) 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:
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=89e435f3559c53084498e9baad22172b64429362
Recommended additional commit for backporting: 
https://sourceware.org/git/?p=glibc.git;a=commit;h=35a5e3e338ae17f3d42c6

External references:

https://sourceware.org/bugzilla/show_bug.cgi?id=17048
Comment 1 Vincent Danen 2014-06-13 12:30:19 EDT
Acknowledgements:

Red Hat would like to thank David Reid, Alex Gaynor, and Glyph Lefkowitz from Rackspace for reporting this issue.
Comment 2 Vasyl Kaigorodov 2014-06-16 06:00:48 EDT
Created glibc tracking bugs for this issue:

Affects: fedora-all [bug 1109745]
Comment 3 Vasyl Kaigorodov 2014-06-16 07:12:53 EDT
Statement:

The Red Hat Security Response Team has rated this issue as having Low security impact. This issue is not currently planned to be addressed in future updates for Red Hat Enterprise Linux 4 and 5. A future update may address this flaw in Red Hat Enterprise Linux 6 or 7. For additional information, refer to the Issue Severity Classification: https://access.redhat.com/security/updates/classification/.

Note You need to log in before you can comment on or make changes to this bug.