1. 28 7月, 2010 21 次提交
  2. 14 5月, 2010 2 次提交
    • E
      inotify: race use after free/double free in inotify inode marks · e0873344
      Eric Paris 提交于
      There is a race in the inotify add/rm watch code.  A task can find and
      remove a mark which doesn't have all of it's references.  This can
      result in a use after free/double free situation.
      
      Task A					Task B
      ------------				-----------
      inotify_new_watch()
       allocate a mark (refcnt == 1)
       add it to the idr
      					inotify_rm_watch()
      					 inotify_remove_from_idr()
      					  fsnotify_put_mark()
      					      refcnt hits 0, free
       take reference because we are on idr
       [at this point it is a use after free]
       [time goes on]
       refcnt may hit 0 again, double free
      
      The fix is to take the reference BEFORE the object can be found in the
      idr.
      Signed-off-by: NEric Paris <eparis@redhat.com>
      Cc: <stable@kernel.org>
      e0873344
    • E
      inotify: clean up the inotify_add_watch out path · 3dbc6fb6
      Eric Paris 提交于
      inotify_add_watch explictly frees the unused inode mark, but it can just
      use the generic code.  Just do that.
      Signed-off-by: NEric Paris <eparis@redhat.com>
      3dbc6fb6
  3. 19 2月, 2010 1 次提交
  4. 16 1月, 2010 1 次提交
    • E
      inotify: do not reuse watch descriptors · 9e572cc9
      Eric Paris 提交于
      Since commit 7e790dd5 ("inotify: fix
      error paths in inotify_update_watch") inotify changed the manor in which
      it gave watch descriptors back to userspace.  Previous to this commit
      inotify acted like the following:
      
        inotify_add_watch(X, Y, Z) = 1
        inotify_rm_watch(X, 1);
        inotify_add_watch(X, Y, Z) = 2
      
      but after this patch inotify would return watch descriptors like so:
      
        inotify_add_watch(X, Y, Z) = 1
        inotify_rm_watch(X, 1);
        inotify_add_watch(X, Y, Z) = 1
      
      which I saw as equivalent to opening an fd where
      
        open(file) = 1;
        close(1);
        open(file) = 1;
      
      seemed perfectly reasonable.  The issue is that quite a bit of userspace
      apparently relies on the behavior in which watch descriptors will not be
      quickly reused.  KDE relies on it, I know some selinux packages rely on
      it, and I have heard complaints from other random sources such as debian
      bug 558981.
      
      Although the man page implies what we do is ok, we broke userspace so
      this patch almost reverts us to the old behavior.  It is still slightly
      racey and I have patches that would fix that, but they are rather large
      and this will fix it for all real world cases.  The race is as follows:
      
       - task1 creates a watch and blocks in idr_new_watch() before it updates
         the hint.
       - task2 creates a watch and updates the hint.
       - task1 updates the hint with it's older wd
       - task removes the watch created by task2
       - task adds a new watch and will reuse the wd originally given to task2
      
      it requires moving some locking around the hint (last_wd) but this should
      solve it for the real world and be -stable safe.
      
      As a side effect this patch papers over a bug in the lib/idr code which
      is causing a large number WARN's to pop on people's system and many
      reports in kerneloops.org.  I'm working on the root cause of that idr
      bug seperately but this should make inotify immune to that issue.
      Signed-off-by: NEric Paris <eparis@redhat.com>
      Cc: stable@kernel.org
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      9e572cc9
  5. 17 12月, 2009 2 次提交
  6. 04 12月, 2009 1 次提交
  7. 19 11月, 2009 1 次提交
  8. 12 11月, 2009 1 次提交
  9. 29 8月, 2009 1 次提交
  10. 28 8月, 2009 2 次提交
  11. 27 8月, 2009 3 次提交
  12. 18 8月, 2009 2 次提交
    • E
      inotify: start watch descriptor count at 1 · 08e53fcb
      Eric Paris 提交于
      The inotify_add_watch man page specifies that inotify_add_watch() will
      return a non-negative integer.  However, historically the inotify
      watches started at 1, not at 0.
      
      Turns out that the inotifywait program provided by the inotify-tools
      package doesn't properly handle a 0 watch descriptor.  In 7e790dd5 we
      changed from starting at 1 to starting at 0.  This patch starts at 1,
      just like in previous kernels, but also just like in previous kernels
      it's possible for it to wrap back to 0.  This preserves the kernel
      functionality exactly like it was before the patch (neither method broke
      the spec)
      Signed-off-by: NEric Paris <eparis@redhat.com>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      08e53fcb
    • E
      notify: unused event private race · eef3a116
      Eric Paris 提交于
      inotify decides if private data it passed to get added to an event was
      used by checking list_empty().  But it's possible that the event may
      have been dequeued and the private event removed so it would look empty.
      
      The fix is to use the return code from fsnotify_add_notify_event rather
      than looking at the list.
      Signed-off-by: NEric Paris <eparis@redhat.com>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      eef3a116
  13. 22 7月, 2009 2 次提交
    • E
      inotify: use GFP_NOFS under potential memory pressure · f44aebcc
      Eric Paris 提交于
      inotify can have a watchs removed under filesystem reclaim.
      
      =================================
      [ INFO: inconsistent lock state ]
      2.6.31-rc2 #16
      ---------------------------------
      inconsistent {IN-RECLAIM_FS-W} -> {RECLAIM_FS-ON-W} usage.
      khubd/217 [HC0[0]:SC0[0]:HE1:SE1] takes:
       (iprune_mutex){+.+.?.}, at: [<c10ba899>] invalidate_inodes+0x20/0xe3
      {IN-RECLAIM_FS-W} state was registered at:
        [<c10536ab>] __lock_acquire+0x2c9/0xac4
        [<c1053f45>] lock_acquire+0x9f/0xc2
        [<c1308872>] __mutex_lock_common+0x2d/0x323
        [<c1308c00>] mutex_lock_nested+0x2e/0x36
        [<c10ba6ff>] shrink_icache_memory+0x38/0x1b2
        [<c108bfb6>] shrink_slab+0xe2/0x13c
        [<c108c3e1>] kswapd+0x3d1/0x55d
        [<c10449b5>] kthread+0x66/0x6b
        [<c1003fdf>] kernel_thread_helper+0x7/0x10
        [<ffffffff>] 0xffffffff
      
      Two things are needed to fix this.  First we need a method to tell
      fsnotify_create_event() to use GFP_NOFS and second we need to stop using
      one global IN_IGNORED event and allocate them one at a time.  This solves
      current issues with multiple IN_IGNORED on a queue having tail drop
      problems and simplifies the allocations since we don't have to worry about
      two tasks opperating on the IGNORED event concurrently.
      Signed-off-by: NEric Paris <eparis@redhat.com>
      f44aebcc
    • E
      inotify: fix error paths in inotify_update_watch · 7e790dd5
      Eric Paris 提交于
      inotify_update_watch could leave things in a horrid state on a number of
      error paths.  We could try to remove idr entries that didn't exist, we
      could send an IN_IGNORED to userspace for watches that don't exist, and a
      bit of other stupidity.  Clean these up by doing the idr addition before we
      put the mark on the inode since we can clean that up on error and getting
      off the inode's mark list is hard.
      Signed-off-by: NEric Paris <eparis@redhat.com>
      7e790dd5