1. 04 Apr, 2016 1 commit
    • Jiri Slaby's avatar
      audit: cleanup prune_tree_thread · 0bf676d1
      Jiri Slaby authored
      We can use kthread_run instead of kthread_create+wake_up_process for
      creating the thread.
      We do not need to set the task state to TASK_RUNNING after schedule(),
      the process is in that state already.
      And we do not need to set the state to TASK_INTERRUPTIBLE when not
      doing schedule() as we set the state to TASK_RUNNING immediately
      Signed-off-by: default avatarJiri Slaby <jslaby@suse.cz>
      Cc: Paul Moore <paul@paul-moore.com>
      Cc: Eric Paris <eparis@redhat.com>
      Cc: <linux-audit@redhat.com>
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
  2. 04 Nov, 2015 1 commit
  3. 06 Aug, 2015 1 commit
    • Richard Guy Briggs's avatar
      audit: implement audit by executable · 34d99af5
      Richard Guy Briggs authored
      This adds the ability audit the actions of a not-yet-running process.
      This patch implements the ability to filter on the executable path.  Instead of
      just hard coding the ino and dev of the executable we care about at the moment
      the rule is inserted into the kernel, use the new audit_fsnotify
      infrastructure to manage this dynamically.  This means that if the filename
      does not yet exist but the containing directory does, or if the inode in
      question is unlinked and creat'd (aka updated) the rule will just continue to
      work.  If the containing directory is moved or deleted or the filesystem is
      unmounted, the rule is deleted automatically.  A future enhancement would be to
      have the rule survive across directory disruptions.
      This is a heavily modified version of a patch originally submitted by Eric
      Paris with some ideas from Peter Moody.
      Cc: Peter Moody <peter@hda3.com>
      Cc: Eric Paris <eparis@redhat.com>
      Signed-off-by: default avatarRichard Guy Briggs <rgb@redhat.com>
      [PM: minor whitespace clean to satisfy ./scripts/checkpatch]
      Signed-off-by: default avatarPaul Moore <pmoore@redhat.com>
  4. 15 Apr, 2015 1 commit
  5. 23 Feb, 2015 1 commit
    • Imre Palik's avatar
      audit: move the tree pruning to a dedicated thread · f1aaf262
      Imre Palik authored
      When file auditing is enabled, during a low memory situation, a memory
      allocation with __GFP_FS can lead to pruning the inode cache.  Which can,
      in turn lead to audit_tree_freeing_mark() being called.  This can call
      audit_schedule_prune(), that tries to fork a pruning thread, and
      waits until the thread is created.  But forking needs memory, and the
      memory allocations there are done with __GFP_FS.
      So we are waiting merrily for some __GFP_FS memory allocations to complete,
      while holding some filesystem locks.  This can take a while ...
      This patch creates a single thread for pruning the tree from
      audit_add_tree_rule(), and thus avoids the deadlock that the on-demand
      thread creation can cause.
      Reported-by: default avatarMatt Wilson <msw@amazon.com>
      Cc: Matt Wilson <msw@amazon.com>
      Signed-off-by: default avatarImre Palik <imrep@amazon.de>
      Reviewed-by: default avatarRichard Guy Briggs <rgb@redhat.com>
      Signed-off-by: default avatarPaul Moore <pmoore@redhat.com>
  6. 13 Dec, 2014 1 commit
  7. 11 Nov, 2014 1 commit
    • Miklos Szeredi's avatar
      audit: keep inode pinned · 799b6014
      Miklos Szeredi authored
      Audit rules disappear when an inode they watch is evicted from the cache.
      This is likely not what we want.
      The guilty commit is "fsnotify: allow marks to not pin inodes in core",
      which didn't take into account that audit_tree adds watches with a zero
      Adding any mask should fix this.
      Fixes: 90b1e7a5 ("fsnotify: allow marks to not pin inodes in core")
      Signed-off-by: default avatarMiklos Szeredi <mszeredi@suse.cz>
      Cc: stable@vger.kernel.org # 2.6.36+
      Signed-off-by: default avatarPaul Moore <pmoore@redhat.com>
  8. 10 Oct, 2014 1 commit
  9. 23 Sep, 2014 1 commit
    • Burn Alting's avatar
      audit: invalid op= values for rules · e7df61f4
      Burn Alting authored
      Various audit events dealing with adding, removing and updating rules result in
      invalid values set for the op keys which result in embedded spaces in op=
      The invalid values are
              op="add rule"       set in kernel/auditfilter.c
              op="remove rule"    set in kernel/auditfilter.c
              op="remove rule"    set in kernel/audit_tree.c
              op="updated rules"  set in kernel/audit_watch.c
              op="remove rule"    set in kernel/audit_watch.c
      Replace the space in the above values with an underscore character ('_').
      Coded-by: default avatarBurn Alting <burn@swtf.dyndns.org>
      Signed-off-by: default avatarRichard Guy Briggs <rgb@redhat.com>
  10. 18 Feb, 2014 1 commit
    • Jan Kara's avatar
      inotify: Fix reporting of cookies for inotify events · 45a22f4c
      Jan Kara authored
      My rework of handling of notification events (namely commit 7053aee2
      "fsnotify: do not share events between notification groups") broke
      sending of cookies with inotify events. We didn't propagate the value
      passed to fsnotify() properly and passed 4 uninitialized bytes to
      userspace instead (so it is also an information leak). Sadly I didn't
      notice this during my testing because inotify cookies aren't used very
      much and LTP inotify tests ignore them.
      Fix the problem by passing the cookie value properly.
      Fixes: 7053aee2Reported-by: default avatarVegard Nossum <vegard.nossum@oracle.com>
      Signed-off-by: default avatarJan Kara <jack@suse.cz>
  11. 22 Jan, 2014 3 commits
    • Jan Kara's avatar
      fsnotify: remove pointless NULL initializers · 56b27cf6
      Jan Kara authored
      We usually rely on the fact that struct members not specified in the
      initializer are set to NULL.  So do that with fsnotify function pointers
      as well.
      Signed-off-by: default avatarJan Kara <jack@suse.cz>
      Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
      Cc: Eric Paris <eparis@parisplace.org>
      Cc: Al Viro <viro@zeniv.linux.org.uk>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
    • Jan Kara's avatar
      fsnotify: remove .should_send_event callback · 83c4c4b0
      Jan Kara authored
      After removing event structure creation from the generic layer there is
      no reason for separate .should_send_event and .handle_event callbacks.
      So just remove the first one.
      Signed-off-by: default avatarJan Kara <jack@suse.cz>
      Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
      Cc: Eric Paris <eparis@parisplace.org>
      Cc: Al Viro <viro@zeniv.linux.org.uk>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
    • Jan Kara's avatar
      fsnotify: do not share events between notification groups · 7053aee2
      Jan Kara authored
      Currently fsnotify framework creates one event structure for each
      notification event and links this event into all interested notification
      groups.  This is done so that we save memory when several notification
      groups are interested in the event.  However the need for event
      structure shared between inotify & fanotify bloats the event structure
      so the result is often higher memory consumption.
      Another problem is that fsnotify framework keeps path references with
      outstanding events so that fanotify can return open file descriptors
      with its events.  This has the undesirable effect that filesystem cannot
      be unmounted while there are outstanding events - a regression for
      inotify compared to a situation before it was converted to fsnotify
      framework.  For fanotify this problem is hard to avoid and users of
      fanotify should kind of expect this behavior when they ask for file
      descriptors from notified files.
      This patch changes fsnotify and its users to create separate event
      structure for each group.  This allows for much simpler code (~400 lines
      removed by this patch) and also smaller event structures.  For example
      on 64-bit system original struct fsnotify_event consumes 120 bytes, plus
      additional space for file name, additional 24 bytes for second and each
      subsequent group linking the event, and additional 32 bytes for each
      inotify group for private data.  After the conversion inotify event
      consumes 48 bytes plus space for file name which is considerably less
      memory unless file names are long and there are several groups
      interested in the events (both of which are uncommon).  Fanotify event
      fits in 56 bytes after the conversion (fanotify doesn't care about file
      names so its events don't have to have it allocated).  A win unless
      there are four or more fanotify groups interested in the event.
      The conversion also solves the problem with unmount when only inotify is
      used as we don't have to grab path references for inotify events.
      [hughd@google.com: fanotify: fix corruption preventing startup]
      Signed-off-by: default avatarJan Kara <jack@suse.cz>
      Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
      Cc: Eric Paris <eparis@parisplace.org>
      Cc: Al Viro <viro@zeniv.linux.org.uk>
      Signed-off-by: default avatarHugh Dickins <hughd@google.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
  12. 12 Jun, 2013 1 commit
    • Chen Gang's avatar
      kernel/audit_tree.c:audit_add_tree_rule(): protect `rule' from kill_rules() · 736f3203
      Chen Gang authored
      audit_add_tree_rule() must set 'rule->tree = NULL;' firstly, to protect
      the rule itself freed in kill_rules().
      The reason is when it is killed, the 'rule' itself may have already
      released, we should not access it.  one example: we add a rule to an
      inode, just at the same time the other task is deleting this inode.
      The work flow for adding a rule:
          audit_receive() -> (need audit_cmd_mutex lock)
            audit_receive_skb() ->
              audit_receive_msg() ->
                audit_receive_filter() ->
                  audit_add_rule() ->
                    audit_add_tree_rule() -> (need audit_filter_mutex lock)
                      unlock audit_filter_mutex
                      iterate_mounts() -> (iterate all related inodes)
                        tag_mount() ->
                          tag_trunk() ->
                            create_trunk() -> (assume it is 1st rule)
                              fsnotify_add_mark() ->
                                fsnotify_add_inode_mark() ->  (add mark to inode->i_fsnotify_marks)
                              get_tree(); (each inode will get one)
                      lock audit_filter_mutex
      The work flow for deleting an inode:
          __destroy_inode() ->
           fsnotify_inode_delete() ->
             __fsnotify_inode_delete() ->
              fsnotify_clear_marks_by_inode() ->  (get mark from inode->i_fsnotify_marks)
                fsnotify_destroy_mark() ->
                 fsnotify_destroy_mark_locked() ->
                   audit_tree_freeing_mark() ->
                     evict_chunk() ->
                       tree->goner = 1
                       kill_rules() ->   (assume current->audit_context == NULL)
                         call_rcu() ->   (rule->tree != NULL)
                           audit_free_rule_rcu() ->
                       audit_schedule_prune() ->  (assume current->audit_context == NULL)
                         kthread_run() ->    (need audit_cmd_mutex and audit_filter_mutex lock)
                           prune_one() ->    (delete it from prue_list)
                             put_tree(); (match the original get_tree above)
      Signed-off-by: default avatarChen Gang <gang.chen@asianux.com>
      Cc: Eric Paris <eparis@redhat.com>
      Cc: Al Viro <viro@zeniv.linux.org.uk>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
  13. 29 Apr, 2013 1 commit
  14. 11 Jan, 2013 1 commit
  15. 11 Dec, 2012 1 commit
  16. 15 Aug, 2012 3 commits
    • Miklos Szeredi's avatar
      audit: clean up refcounting in audit-tree · b3e8692b
      Miklos Szeredi authored
      Drop the initial reference by fsnotify_init_mark early instead of
      audit_tree_freeing_mark() at destroy time.
      In the cases we destroy the mark before we drop the initial reference we need to
      get rid of the get_mark that balances the put_mark in audit_tree_freeing_mark().
      Signed-off-by: default avatarMiklos Szeredi <mszeredi@suse.cz>
    • Miklos Szeredi's avatar
      audit: fix refcounting in audit-tree · a2140fc0
      Miklos Szeredi authored
      Refcounting of fsnotify_mark in audit tree is broken.  E.g:
        alloc_chunk                 1
        fsnotify_add_mark           2
        fsnotify_get_mark           3
          audit_tree_freeing_mark   2
        fsnotify_put_mark           1
        fsnotify_put_mark           0
        via destroy_list
          fsnotify_mark_destroy    -1
      This was reported by various people as triggering Oops when stopping auditd.
      We could just remove the put_mark from audit_tree_freeing_mark() but that would
      break freeing via inode destruction.  So this patch simply omits a put_mark
      after calling destroy_mark or adds a get_mark before.
      The additional get_mark is necessary where there's no other put_mark after
      fsnotify_destroy_mark() since it assumes that the caller is holding a reference
      (or the inode is keeping the mark pinned, not the case here AFAICS).
      Signed-off-by: default avatarMiklos Szeredi <mszeredi@suse.cz>
      Reported-by: default avatarValentin Avram <aval13@gmail.com>
      Reported-by: default avatarPeter Moody <pmoody@google.com>
      Acked-by: default avatarEric Paris <eparis@redhat.com>
      CC: stable@vger.kernel.org
    • Miklos Szeredi's avatar
      audit: don't free_chunk() after fsnotify_add_mark() · 0fe33aae
      Miklos Szeredi authored
      Don't do free_chunk() after fsnotify_add_mark().  That one does a delayed unref
      via the destroy list and this results in use-after-free.
      Signed-off-by: default avatarMiklos Szeredi <mszeredi@suse.cz>
      Acked-by: default avatarEric Paris <eparis@redhat.com>
      CC: stable@vger.kernel.org
  17. 14 Jul, 2012 1 commit
    • David Howells's avatar
      VFS: Make clone_mnt()/copy_tree()/collect_mounts() return errors · be34d1a3
      David Howells authored
      copy_tree() can theoretically fail in a case other than ENOMEM, but always
      returns NULL which is interpreted by callers as -ENOMEM.  Change it to return
      an explicit error.
      Also change clone_mnt() for consistency and because union mounts will add new
      error cases.
      Thanks to Andreas Gruenbacher <agruen@suse.de> for a bug fix.
      [AV: folded braino fix by Dan Carpenter]
      Original-author: Valerie Aurora <vaurora@redhat.com>
      Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
      Cc: Valerie Aurora <valerie.aurora@gmail.com>
      Cc: Andreas Gruenbacher <agruen@suse.de>
      Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
  18. 20 Jul, 2011 1 commit
  19. 31 Mar, 2011 1 commit
  20. 30 Oct, 2010 1 commit
  21. 28 Jul, 2010 16 commits