1. 23 7月, 2012 1 次提交
  2. 14 7月, 2012 1 次提交
  3. 31 5月, 2012 1 次提交
  4. 24 3月, 2012 1 次提交
  5. 15 1月, 2012 1 次提交
  6. 04 1月, 2012 1 次提交
  7. 27 7月, 2011 1 次提交
  8. 06 4月, 2011 1 次提交
    • E
      inotify: fix double free/corruption of stuct user · d0de4dc5
      Eric Paris 提交于
      On an error path in inotify_init1 a normal user can trigger a double
      free of struct user.  This is a regression introduced by a2ae4cc9
      ("inotify: stop kernel memory leak on file creation failure").
      
      We fix this by making sure that if a group exists the user reference is
      dropped when the group is cleaned up.  We should not explictly drop the
      reference on error and also drop the reference when the group is cleaned
      up.
      
      The new lifetime rules are that an inotify group lives from
      inotify_new_group to the last fsnotify_put_group.  Since the struct user
      and inotify_devs are directly tied to this lifetime they are only
      changed/updated in those two locations.  We get rid of all special
      casing of struct user or user->inotify_devs.
      Signed-off-by: NEric Paris <eparis@redhat.com>
      Cc: stable@kernel.org (2.6.37 and up)
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      d0de4dc5
  9. 31 3月, 2011 1 次提交
  10. 25 3月, 2011 3 次提交
    • D
      fs: rename inode_lock to inode_hash_lock · 67a23c49
      Dave Chinner 提交于
      All that remains of the inode_lock is protecting the inode hash list
      manipulation and traversals. Rename the inode_lock to
      inode_hash_lock to reflect it's actual function.
      Signed-off-by: NDave Chinner <dchinner@redhat.com>
      Signed-off-by: NAl Viro <viro@zeniv.linux.org.uk>
      67a23c49
    • D
      fs: move i_sb_list out from under inode_lock · 55fa6091
      Dave Chinner 提交于
      Protect the per-sb inode list with a new global lock
      inode_sb_list_lock and use it to protect the list manipulations and
      traversals. This lock replaces the inode_lock as the inodes on the
      list can be validity checked while holding the inode->i_lock and
      hence the inode_lock is no longer needed to protect the list.
      Signed-off-by: NDave Chinner <dchinner@redhat.com>
      Signed-off-by: NAl Viro <viro@zeniv.linux.org.uk>
      55fa6091
    • D
      fs: protect inode->i_state with inode->i_lock · 250df6ed
      Dave Chinner 提交于
      Protect inode state transitions and validity checks with the
      inode->i_lock. This enables us to make inode state transitions
      independently of the inode_lock and is the first step to peeling
      away the inode_lock from the code.
      
      This requires that __iget() is done atomically with i_state checks
      during list traversals so that we don't race with another thread
      marking the inode I_FREEING between the state check and grabbing the
      reference.
      
      Also remove the unlock_new_inode() memory barrier optimisation
      required to avoid taking the inode_lock when clearing I_NEW.
      Simplify the code by simply taking the inode->i_lock around the
      state change and wakeup. Because the wakeup is no longer tricky,
      remove the wake_up_inode() function and open code the wakeup where
      necessary.
      Signed-off-by: NDave Chinner <dchinner@redhat.com>
      Signed-off-by: NAl Viro <viro@zeniv.linux.org.uk>
      250df6ed
  11. 01 3月, 2011 1 次提交
  12. 07 1月, 2011 4 次提交
    • N
      fs: dcache per-inode inode alias locking · 873feea0
      Nick Piggin 提交于
      dcache_inode_lock can be replaced with per-inode locking. Use existing
      inode->i_lock for this. This is slightly non-trivial because we sometimes
      need to find the inode from the dentry, which requires d_inode to be
      stabilised (either with refcount or d_lock).
      Signed-off-by: NNick Piggin <npiggin@kernel.dk>
      873feea0
    • N
      fs: dcache remove dcache_lock · b5c84bf6
      Nick Piggin 提交于
      dcache_lock no longer protects anything. remove it.
      Signed-off-by: NNick Piggin <npiggin@kernel.dk>
      b5c84bf6
    • N
      fs: scale inode alias list · b23fb0a6
      Nick Piggin 提交于
      Add a new lock, dcache_inode_lock, to protect the inode's i_dentry list
      from concurrent modification. d_alias is also protected by d_lock.
      Signed-off-by: NNick Piggin <npiggin@kernel.dk>
      b23fb0a6
    • N
      fs: dcache scale subdirs · 2fd6b7f5
      Nick Piggin 提交于
      Protect d_subdirs and d_child with d_lock, except in filesystems that aren't
      using dcache_lock for these anyway (eg. using i_mutex).
      
      Note: if we change the locking rule in future so that ->d_child protection is
      provided only with ->d_parent->d_lock, it may allow us to reduce some locking.
      But it would be an exception to an otherwise regular locking scheme, so we'd
      have to see some good results. Probably not worthwhile.
      Signed-off-by: NNick Piggin <npiggin@kernel.dk>
      2fd6b7f5
  13. 16 12月, 2010 1 次提交
  14. 08 12月, 2010 7 次提交
    • L
      fanotify: Dont try to open a file descriptor for the overflow event · fdbf3cee
      Lino Sanfilippo 提交于
      We should not try to open a file descriptor for the overflow event since this
      will always fail.
      Signed-off-by: NLino Sanfilippo <LinoSanfilippo@gmx.de>
      Signed-off-by: NEric Paris <eparis@redhat.com>
      fdbf3cee
    • E
      fanotify: do not leak user reference on allocation failure · 26379198
      Eric Paris 提交于
      If fanotify_init is unable to allocate a new fsnotify group it will
      return but will not drop its reference on the associated user struct.
      Drop that reference on error.
      Reported-by: NVegard Nossum <vegard.nossum@gmail.com>
      Signed-off-by: NEric Paris <eparis@redhat.com>
      26379198
    • E
      inotify: stop kernel memory leak on file creation failure · a2ae4cc9
      Eric Paris 提交于
      If inotify_init is unable to allocate a new file for the new inotify
      group we leak the new group.  This patch drops the reference on the
      group on file allocation failure.
      Reported-by: NVegard Nossum <vegard.nossum@gmail.com>
      cc: stable@kernel.org
      Signed-off-by: NEric Paris <eparis@redhat.com>
      a2ae4cc9
    • L
      fanotify: on group destroy allow all waiters to bypass permission check · 09e5f14e
      Lino Sanfilippo 提交于
      When fanotify_release() is called, there may still be processes waiting for
      access permission. Currently only processes for which an event has already been
      queued into the groups access list will be woken up.  Processes for which no
      event has been queued will continue to sleep and thus cause a deadlock when
      fsnotify_put_group() is called.
      Furthermore there is a race allowing further processes to be waiting on the
      access wait queue after wake_up (if they arrive before clear_marks_by_group()
      is called).
      This patch corrects this by setting a flag to inform processes that the group
      is about to be destroyed and thus not to wait for access permission.
      
      [additional changelog from eparis]
      Lets think about the 4 relevant code paths from the PoV of the
      'operator' 'listener' 'responder' and 'closer'.  Where operator is the
      process doing an action (like open/read) which could require permission.
      Listener is the task (or in this case thread) slated with reading from
      the fanotify file descriptor.  The 'responder' is the thread responsible
      for responding to access requests.  'Closer' is the thread attempting to
      close the fanotify file descriptor.
      
      The 'operator' is going to end up in:
      fanotify_handle_event()
        get_response_from_access()
          (THIS BLOCKS WAITING ON USERSPACE)
      
      The 'listener' interesting code path
      fanotify_read()
        copy_event_to_user()
          prepare_for_access_response()
            (THIS CREATES AN fanotify_response_event)
      
      The 'responder' code path:
      fanotify_write()
        process_access_response()
          (REMOVE A fanotify_response_event, SET RESPONSE, WAKE UP 'operator')
      
      The 'closer':
      fanotify_release()
        (SUPPOSED TO CLEAN UP THE REST OF THIS MESS)
      
      What we have today is that in the closer we remove all of the
      fanotify_response_events and set a bit so no more response events are
      ever created in prepare_for_access_response().
      
      The bug is that we never wake all of the operators up and tell them to
      move along.  You fix that in fanotify_get_response_from_access().  You
      also fix other operators which haven't gotten there yet.  So I agree
      that's a good fix.
      [/additional changelog from eparis]
      
      [remove additional changes to minimize patch size]
      [move initialization so it was inside CONFIG_FANOTIFY_PERMISSION]
      Signed-off-by: NLino Sanfilippo <LinoSanfilippo@gmx.de>
      Signed-off-by: NEric Paris <eparis@redhat.com>
      09e5f14e
    • L
      fanotify: Dont allow a mask of 0 if setting or removing a mark · 1734dee4
      Lino Sanfilippo 提交于
      In mark_remove_from_mask() we destroy marks that have their event mask cleared.
      Thus we should not allow the creation of those marks in the first place.
      With this patch we check if the mask given from user is 0 in case of FAN_MARK_ADD.
      If so we return an error. Same for FAN_MARK_REMOVE since this does not have any
      effect.
      Signed-off-by: NLino Sanfilippo <LinoSanfilippo@gmx.de>
      Signed-off-by: NEric Paris <eparis@redhat.com>
      1734dee4
    • L
      fanotify: correct broken ref counting in case adding a mark failed · fa218ab9
      Lino Sanfilippo 提交于
      If adding a mount or inode mark failed fanotify_free_mark() is called explicitly.
      But at this time the mark has already been put into the destroy list of the
      fsnotify_mark kernel thread. If the thread is too slow it will try to decrease
      the reference of a mark, that has already been freed by fanotify_free_mark().
      (If its fast enough it will only decrease the marks ref counter from 2 to 1 - note
      that the counter has been increased to 2 in add_mark() - which has practically no
      effect.)
      
      This patch fixes the ref counting by not calling free_mark() explicitly, but
      decreasing the ref counter and rely on the fsnotify_mark thread to cleanup in
      case adding the mark has failed.
      Signed-off-by: NLino Sanfilippo <LinoSanfilippo@gmx.de>
      Signed-off-by: NEric Paris <eparis@redhat.com>
      fa218ab9
    • E
      fanotify: deny permissions when no event was sent · ecf6f5e7
      Eric Paris 提交于
      If no event was sent to userspace we cannot expect userspace to respond to
      permissions requests.  Today such requests just hang forever. This patch will
      deny any permissions event which was unable to be sent to userspace.
      Reported-by: NTvrtko Ursulin <tvrtko.ursulin@sophos.com>
      Signed-off-by: NEric Paris <eparis@redhat.com>
      ecf6f5e7
  15. 02 11月, 2010 1 次提交
  16. 31 10月, 2010 1 次提交
  17. 29 10月, 2010 13 次提交
    • A
      fs/notify/fanotify/fanotify_user.c: fix warnings · 19ba54f4
      Andrew Morton 提交于
      fs/notify/fanotify/fanotify_user.c: In function 'fanotify_release':
      fs/notify/fanotify/fanotify_user.c:375: warning: unused variable 'lre'
      fs/notify/fanotify/fanotify_user.c:375: warning: unused variable 're'
      
      this is really ugly.
      
      Cc: Eric Paris <eparis@redhat.com>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NEric Paris <eparis@redhat.com>
      19ba54f4
    • E
      fanotify: do not recalculate the mask if the ignored mask changed · 192ca4d1
      Eric Paris 提交于
      If fanotify sets a new bit in the ignored mask it will cause the generic
      fsnotify layer to recalculate the real mask.  This is stupid since we
      didn't change that part.
      Signed-off-by: NEric Paris <eparis@redhat.com>
      192ca4d1
    • E
      fanotify: ignore events on directories unless specifically requested · 8fcd6528
      Eric Paris 提交于
      fanotify has a very limited number of events it sends on directories.  The
      usefulness of these events is yet to be seen and still we send them.  This
      is particularly painful for mount marks where one might receive many of
      these useless events.  As such this patch will drop events on IS_DIR()
      inodes unless they were explictly requested with FAN_ON_DIR.
      
      This means that a mark on a directory without FAN_EVENT_ON_CHILD or
      FAN_ON_DIR is meaningless and will result in no events ever (although it
      will still be allowed since detecting it is hard)
      Signed-off-by: NEric Paris <eparis@redhat.com>
      8fcd6528
    • E
      fsnotify: rename FS_IN_ISDIR to FS_ISDIR · b29866aa
      Eric Paris 提交于
      The _IN_ in the naming is reserved for flags only used by inotify.  Since I
      am about to use this flag for fanotify rename it to be generic like the
      rest.
      Signed-off-by: NEric Paris <eparis@redhat.com>
      b29866aa
    • E
      fanotify: do not send events for irregular files · e1c048ba
      Eric Paris 提交于
      fanotify_should_send_event has a test to see if an object is a file or
      directory and does not send an event otherwise.  The problem is that the
      test is actually checking if the object with a mark is a file or directory,
      not if the object the event happened on is a file or directory.  We should
      check the latter.
      Signed-off-by: NEric Paris <eparis@redhat.com>
      e1c048ba
    • E
      fanotify: limit number of listeners per user · 4afeff85
      Eric Paris 提交于
      fanotify currently has no limit on the number of listeners a given user can
      have open.  This patch limits the total number of listeners per user to
      128.  This is the same as the inotify default limit.
      Signed-off-by: NEric Paris <eparis@redhat.com>
      4afeff85
    • E
      fanotify: allow userspace to override max marks · ac7e22dc
      Eric Paris 提交于
      Some fanotify groups, especially those like AV scanners, will need to place
      lots of marks, particularly ignore marks.  Since ignore marks do not pin
      inodes in cache and are cleared if the inode is removed from core (usually
      under memory pressure) we expose an interface for listeners, with
      CAP_SYS_ADMIN, to override the maximum number of marks and be allowed to
      set and 'unlimited' number of marks.  Programs which make use of this
      feature will be able to OOM a machine.
      Signed-off-by: NEric Paris <eparis@redhat.com>
      ac7e22dc
    • E
      fanotify: limit the number of marks in a single fanotify group · e7099d8a
      Eric Paris 提交于
      There is currently no limit on the number of marks a given fanotify group
      can have.  Since fanotify is gated on CAP_SYS_ADMIN this was not seen as
      a serious DoS threat.  This patch implements a default of 8192, the same as
      inotify to work towards removing the CAP_SYS_ADMIN gating and eliminating
      the default DoS'able status.
      Signed-off-by: NEric Paris <eparis@redhat.com>
      e7099d8a
    • E
      fanotify: allow userspace to override max queue depth · 5dd03f55
      Eric Paris 提交于
      fanotify has a defualt max queue depth.  This patch allows processes which
      explicitly request it to have an 'unlimited' queue depth.  These processes
      need to be very careful to make sure they cannot fall far enough behind
      that they OOM the box.  Thus this flag is gated on CAP_SYS_ADMIN.
      Signed-off-by: NEric Paris <eparis@redhat.com>
      5dd03f55
    • E
      fsnotify: implement a default maximum queue depth · 2529a0df
      Eric Paris 提交于
      Currently fanotify has no maximum queue depth.  Since fanotify is
      CAP_SYS_ADMIN only this does not pose a normal user DoS issue, but it
      certianly is possible that an fanotify listener which can't keep up could
      OOM the box.  This patch implements a default 16k depth.  This is the same
      default depth used by inotify, but given fanotify's better queue merging in
      many situations this queue will contain many additional useful events by
      comparison.
      Signed-off-by: NEric Paris <eparis@redhat.com>
      2529a0df
    • E
      fanotify: ignore fanotify ignore marks if open writers · 5322a59f
      Eric Paris 提交于
      fanotify will clear ignore marks if a task changes the contents of an
      inode.  The problem is with the races around when userspace finishes
      checking a file and when that result is actually attached to the inode.
      This race was described as such:
      
      Consider the following scenario with hostile processes A and B, and
      victim process C:
      1. Process A opens new file for writing. File check request is generated.
      2. File check is performed in userspace. Check result is "file has no malware".
      3. The "permit" response is delivered to kernel space.
      4. File ignored mark set.
      5. Process A writes dummy bytes to the file. File ignored flags are cleared.
      6. Process B opens the same file for reading. File check request is generated.
      7. File check is performed in userspace. Check result is "file has no malware".
      8. Process A writes malware bytes to the file. There is no cached response yet.
      9. The "permit" response is delivered to kernel space and is cached in fanotify.
      10. File ignored mark set.
      11. Now any process C will be permitted to open the malware file.
      There is a race between steps 8 and 10
      
      While fanotify makes no strong guarantees about systems with hostile
      processes there is no reason we cannot harden against this race.  We do
      that by simply ignoring any ignore marks if the inode has open writers (aka
      i_writecount > 0).  (We actually do not ignore ignore marks if the
      FAN_MARK_SURV_MODIFY flag is set)
      Reported-by: NVasily Novikov <vasily.novikov@kaspersky.com>
      Signed-off-by: NEric Paris <eparis@redhat.com>
      5322a59f
    • E
      fsnotify: call fsnotify_parent in perm events · 52420392
      Eric Paris 提交于
      fsnotify perm events do not call fsnotify parent.  That means you cannot
      register a perm event on a directory and enforce permissions on all inodes in
      that directory.  This patch fixes that situation.
      Signed-off-by: NEric Paris <eparis@redhat.com>
      52420392
    • E
      fsnotify: correctly handle return codes from listeners · ff8bcbd0
      Eric Paris 提交于
      When fsnotify groups return errors they are ignored.  For permissions
      events these should be passed back up the stack, but for most events these
      should continue to be ignored.
      Signed-off-by: NEric Paris <eparis@redhat.com>
      ff8bcbd0