[前][次][番号順一覧][スレッド一覧]

ruby-changes:18871

From: shyouhei <ko1@a...>
Date: Fri, 18 Feb 2011 19:42:57 +0900 (JST)
Subject: [ruby-changes:18871] Ruby:r30896 (trunk): * lib/fileutils.rb (FileUtils::remove_entry_secure): there is a

shyouhei	2011-02-18 19:42:50 +0900 (Fri, 18 Feb 2011)

  New Revision: 30896

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=30896

  Log:
    * lib/fileutils.rb (FileUtils::remove_entry_secure): there is a
      race condition in the case where the given path is a directory,
      and some other user can move that directory, and create a
      symlink while this method is executing.
      Reported by: Nicholas Jefferson <nicholas at pythonic.com.au>

  Modified files:
    trunk/ChangeLog
    trunk/lib/fileutils.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 30895)
+++ ChangeLog	(revision 30896)
@@ -1,3 +1,11 @@
+Fri Feb 18 19:31:31 2011  Shugo Maeda  <shugo@r...>
+
+	* lib/fileutils.rb (FileUtils::remove_entry_secure): there is a
+	  race condition in the case where the given path is a directory,
+	  and some other user can move that directory, and create a
+	  symlink while this method is executing.
+	  Reported by: Nicholas Jefferson <nicholas at pythonic.com.au>
+
 Fri Feb 18 00:28:39 2011  CHIKANAGA Tomoyuki  <nagachika00@g...>
 
 	* compile.c (get_exception_sym2type): guard temporary object from GC.
Index: lib/fileutils.rb
===================================================================
--- lib/fileutils.rb	(revision 30895)
+++ lib/fileutils.rb	(revision 30896)
@@ -667,10 +667,10 @@
   # removing directories.  This requires the current process is the
   # owner of the removing whole directory tree, or is the super user (root).
   #
-  # WARNING: You must ensure that *ALL* parent directories are not
-  # world writable.  Otherwise this method does not work.
-  # Only exception is temporary directory like /tmp and /var/tmp,
-  # whose permission is 1777.
+  # WARNING: You must ensure that *ALL* parent directories cannot be
+  # moved by other untrusted users.  For example, parent directories
+  # should not be owned by untrusted users, and should not be world
+  # writable except when the sticky bit set.
   #
   # WARNING: Only the owner of the removing directory tree, or Unix super
   # user (root) should invoke this method.  Otherwise this method does not
@@ -713,6 +713,11 @@
       end
       f.chown euid, -1
       f.chmod 0700
+      unless fu_stat_identical_entry?(st, File.lstat(fullpath))
+        # TOC-to-TOU attack?
+        File.unlink fullpath
+        return
+      end
     }
     # ---- tree root is frozen ----
     root = Entry_.new(path)

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]