]> err.no Git - systemd/commitdiff
util: never follow symlinks in rm_rf_children()
authorMichal Schmidt <mschmidt@redhat.com>
Fri, 2 Mar 2012 09:39:10 +0000 (10:39 +0100)
committerTollef Fog Heen <tfheen@err.no>
Mon, 2 Apr 2012 18:45:54 +0000 (20:45 +0200)
The function checks if the entry is a directory before recursing, but
there is a window between the check and the open, during which the
directory could be replaced with a symlink.

CVE-2012-1174
https://bugzilla.redhat.com/show_bug.cgi?id=803358

src/util.c

index 20cbc2b0db4a2b77d1b2146cf3f687265732298a..dfc1dc6b85a94a7dec0bf01cc2b74dfc08938c9f 100644 (file)
@@ -3593,7 +3593,8 @@ static int rm_rf_children(int fd, bool only_dirs, bool honour_sticky) {
                 if (is_dir) {
                         int subdir_fd;
 
-                        if ((subdir_fd = openat(fd, de->d_name, O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC)) < 0) {
+                        subdir_fd = openat(fd, de->d_name, O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC|O_NOFOLLOW);
+                        if (subdir_fd < 0) {
                                 if (ret == 0 && errno != ENOENT)
                                         ret = -errno;
                                 continue;