diff options
author | Ondrej Kos <okos@redhat.com> | 2013-01-29 14:15:48 +0100 |
---|---|---|
committer | Jakub Hrozek <jhrozek@redhat.com> | 2013-01-29 16:18:18 +0100 |
commit | cfcfa9bd014a7717821c98262a11772c8e79c13e (patch) | |
tree | 3a17519433808dd5f43373da2796123075cd1d83 /src/tools/tools_util.c | |
parent | 2b0c414b919ec75be2bcfcca850ef309760816d3 (diff) | |
download | sssd-cfcfa9bd014a7717821c98262a11772c8e79c13e.tar.gz sssd-cfcfa9bd014a7717821c98262a11772c8e79c13e.tar.xz sssd-cfcfa9bd014a7717821c98262a11772c8e79c13e.zip |
TOOLS: Use file descriptor to avoid races when creating a home directory
When creating a home directory, the destination tree can be modified in
various ways while it is being constructed because directory
permissions
are set before populating the directory. This can lead to file creation
and permission changes outside the target directory tree, using hard
links.
This security problem was assigned CVE-2013-0219
https://fedorahosted.org/sssd/ticket/1782
Diffstat (limited to 'src/tools/tools_util.c')
-rw-r--r-- | src/tools/tools_util.c | 28 |
1 files changed, 1 insertions, 27 deletions
diff --git a/src/tools/tools_util.c b/src/tools/tools_util.c index 004489533..bf6464244 100644 --- a/src/tools/tools_util.c +++ b/src/tools/tools_util.c @@ -472,33 +472,7 @@ int create_homedir(const char *skeldir, selinux_file_context(homedir); - ret = mkdir(homedir, 0); - if (ret != 0) { - ret = errno; - DEBUG(1, ("Cannot create user's home directory: [%d][%s].\n", - ret, strerror(ret))); - goto done; - } - - ret = chown(homedir, uid, gid); - if (ret != 0) { - ret = errno; - DEBUG(1, ("Cannot chown user's home directory: [%d][%s].\n", - ret, strerror(ret))); - goto done; - } - - ret = chmod(homedir, 0777 & ~default_umask); - if (ret != 0) { - ret = errno; - DEBUG(1, ("Cannot chmod user's home directory: [%d][%s].\n", - ret, strerror(ret))); - goto done; - } - - reset_selinux_file_context(); - - ret = copy_tree(skeldir, homedir, uid, gid); + ret = copy_tree(skeldir, homedir, 0777 & ~default_umask, uid, gid); if (ret != EOK) { DEBUG(1, ("Cannot populate user's home directory: [%d][%s].\n", ret, strerror(ret))); |