26 Sep, 2018

1 commit

  • [ Upstream commit baa2a4fdd525c8c4b0f704d20457195b29437839 ]

    audit_add_watch stores locally krule->watch without taking a reference
    on watch. Then, it calls audit_add_to_parent, and uses the watch stored
    locally.

    Unfortunately, it is possible that audit_add_to_parent updates
    krule->watch.
    When it happens, it also drops a reference of watch which
    could free the watch.

    How to reproduce (with KASAN enabled):

    auditctl -w /etc/passwd -F success=0 -k test_passwd
    auditctl -w /etc/passwd -F success=1 -k test_passwd2

    The second call to auditctl triggers the use-after-free, because
    audit_to_parent updates krule->watch to use a previous existing watch
    and drops the reference to the newly created watch.

    To fix the issue, we grab a reference of watch and we release it at the
    end of the function.

    Signed-off-by: Ronny Chevalier
    Reviewed-by: Richard Guy Briggs
    Signed-off-by: Paul Moore
    Signed-off-by: Sasha Levin
    Signed-off-by: Greg Kroah-Hartman

    Ronny Chevalier
     

17 Aug, 2017

1 commit


16 Aug, 2017

2 commits

  • Although audit_watch_handle_event() can handle FS_UNMOUNT event, it is
    not part of AUDIT_FS_WATCH mask and thus such event never gets to
    audit_watch_handle_event(). Thus fsnotify marks are deleted by fsnotify
    subsystem on unmount without audit being notified about that which leads
    to a strange state of existing audit rules with dead fsnotify marks.

    Add FS_UNMOUNT to the mask of events to be received so that audit can
    clean up its state accordingly.

    Signed-off-by: Jan Kara
    Signed-off-by: Paul Moore

    Jan Kara
     
  • audit_remove_watch_rule() drops watch's reference to parent but then
    continues to work with it. That is not safe as parent can get freed once
    we drop our reference. The following is a trivial reproducer:

    mount -o loop image /mnt
    touch /mnt/file
    auditctl -w /mnt/file -p wax
    umount /mnt
    auditctl -D

    Grab our own reference in audit_remove_watch_rule() earlier to make sure
    mark does not get freed under us.

    CC: stable@vger.kernel.org
    Reported-by: Tony Jones
    Signed-off-by: Jan Kara
    Tested-by: Tony Jones
    Signed-off-by: Paul Moore

    Jan Kara
     

04 May, 2017

1 commit

  • Pull fsnotify updates from Jan Kara:
    "The branch contains mainly a rework of fsnotify infrastructure fixing
    a shortcoming that we have waited for response to fanotify permission
    events with SRCU read lock held and when the process consuming events
    was slow to respond the kernel has stalled.

    It also contains several cleanups of unnecessary indirections in
    fsnotify framework and a bugfix from Amir fixing leakage of kernel
    internal errno to userspace"

    * 'fsnotify' of git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs: (37 commits)
    fanotify: don't expose EOPENSTALE to userspace
    fsnotify: remove a stray unlock
    fsnotify: Move ->free_mark callback to fsnotify_ops
    fsnotify: Add group pointer in fsnotify_init_mark()
    fsnotify: Drop inode_mark.c
    fsnotify: Remove fsnotify_find_{inode|vfsmount}_mark()
    fsnotify: Remove fsnotify_detach_group_marks()
    fsnotify: Rename fsnotify_clear_marks_by_group_flags()
    fsnotify: Inline fsnotify_clear_{inode|vfsmount}_mark_group()
    fsnotify: Remove fsnotify_recalc_{inode|vfsmount}_mask()
    fsnotify: Remove fsnotify_set_mark_{,ignored_}mask_locked()
    fanotify: Release SRCU lock when waiting for userspace response
    fsnotify: Pass fsnotify_iter_info into handle_event handler
    fsnotify: Provide framework for dropping SRCU lock in ->handle_event
    fsnotify: Remove special handling of mark destruction on group shutdown
    fsnotify: Detach mark from object list when last reference is dropped
    fsnotify: Move queueing of mark for destruction into fsnotify_put_mark()
    inotify: Do not drop mark reference under idr_lock
    fsnotify: Free fsnotify_mark_connector when there is no mark attached
    fsnotify: Lock object list with connector lock
    ...

    Linus Torvalds
     

02 May, 2017

2 commits


10 Apr, 2017

4 commits

  • Pointer to ->free_mark callback unnecessarily occupies one long in each
    fsnotify_mark although they are the same for all marks from one
    notification group. Move the callback pointer to fsnotify_ops.

    Reviewed-by: Miklos Szeredi
    Reviewed-by: Amir Goldstein
    Signed-off-by: Jan Kara

    Jan Kara
     
  • Currently we initialize mark->group only in fsnotify_add_mark_lock().
    However we will need to access fsnotify_ops of corresponding group from
    fsnotify_put_mark() so we need mark->group initialized earlier. Do that
    in fsnotify_init_mark() which has a consequence that once
    fsnotify_init_mark() is called on a mark, the mark has to be destroyed
    by fsnotify_put_mark().

    Reviewed-by: Miklos Szeredi
    Reviewed-by: Amir Goldstein
    Signed-off-by: Jan Kara

    Jan Kara
     
  • These are very thin wrappers, just remove them. Drop
    fs/notify/vfsmount_mark.c as it is empty now.

    Reviewed-by: Miklos Szeredi
    Reviewed-by: Amir Goldstein
    Signed-off-by: Jan Kara

    Jan Kara
     
  • Pass fsnotify_iter_info into ->handle_event() handler so that it can
    release and reacquire SRCU lock via fsnotify_prepare_user_wait() and
    fsnotify_finish_user_wait() functions. These functions also make sure
    current marks are appropriately pinned so that iteration protected by
    srcu in fsnotify() stays safe.

    Reviewed-by: Miklos Szeredi
    Reviewed-by: Amir Goldstein
    Signed-off-by: Jan Kara

    Jan Kara
     

18 Dec, 2016

1 commit

  • Pull more vfs updates from Al Viro:
    "In this pile:

    - autofs-namespace series
    - dedupe stuff
    - more struct path constification"

    * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs: (40 commits)
    ocfs2: implement the VFS clone_range, copy_range, and dedupe_range features
    ocfs2: charge quota for reflinked blocks
    ocfs2: fix bad pointer cast
    ocfs2: always unlock when completing dio writes
    ocfs2: don't eat io errors during _dio_end_io_write
    ocfs2: budget for extent tree splits when adding refcount flag
    ocfs2: prohibit refcounted swapfiles
    ocfs2: add newlines to some error messages
    ocfs2: convert inode refcount test to a helper
    simple_write_end(): don't zero in short copy into uptodate
    exofs: don't mess with simple_write_{begin,end}
    9p: saner ->write_end() on failing copy into non-uptodate page
    fix gfs2_stuffed_write_end() on short copies
    fix ceph_write_end()
    nfs_write_end(): fix handling of short copies
    vfs: refactor clone/dedupe_file_range common functions
    fs: try to clone files first in vfs_copy_file_range
    vfs: misc struct path constification
    namespace.c: constify struct path passed to a bunch of primitives
    quota: constify struct path in quota_on
    ...

    Linus Torvalds
     

17 Dec, 2016

1 commit

  • Pull vfs updates from Al Viro:

    - more ->d_init() stuff (work.dcache)

    - pathname resolution cleanups (work.namei)

    - a few missing iov_iter primitives - copy_from_iter_full() and
    friends. Either copy the full requested amount, advance the iterator
    and return true, or fail, return false and do _not_ advance the
    iterator. Quite a few open-coded callers converted (and became more
    readable and harder to fuck up that way) (work.iov_iter)

    - several assorted patches, the big one being logfs removal

    * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs:
    logfs: remove from tree
    vfs: fix put_compat_statfs64() does not handle errors
    namei: fold should_follow_link() with the step into not-followed link
    namei: pass both WALK_GET and WALK_MORE to should_follow_link()
    namei: invert WALK_PUT logics
    namei: shift interpretation of LOOKUP_FOLLOW inside should_follow_link()
    namei: saner calling conventions for mountpoint_last()
    namei.c: get rid of user_path_parent()
    switch getfrag callbacks to ..._full() primitives
    make skb_add_data,{_nocache}() and skb_copy_to_page_nocache() advance only on success
    [iov_iter] new primitives - copy_from_iter_full() and friends
    don't open-code file_inode()
    ceph: switch to use of ->d_init()
    ceph: unify dentry_operations instances
    lustre: switch to use of ->d_init()

    Linus Torvalds
     

06 Dec, 2016

1 commit


05 Dec, 2016

1 commit


21 Nov, 2016

1 commit

  • The AUDIT_CONFIG_CHANGE events sometimes use a op= field. The current
    code logs the value of the field with quotes. This field is documented
    to not be encoded, so it should not have quotes.

    Signed-off-by: Steve Grubb
    Reviewed-by: Richard Guy Briggs
    [PM: reformatted commit description to make checkpatch.pl happy]
    Signed-off-by: Paul Moore

    Steve Grubb
     

02 Sep, 2016

1 commit


01 Sep, 2016

1 commit

  • Prior to the change the function would blindly deference mm, exe_file
    and exe_file->f_inode, each of which could have been NULL or freed.

    Use get_task_exe_file to safely obtain stable exe_file.

    Signed-off-by: Mateusz Guzik
    Acked-by: Konstantin Khlebnikov
    Acked-by: Richard Guy Briggs
    Cc: # 4.3.x
    Signed-off-by: Paul Moore

    Mateusz Guzik
     

11 Apr, 2016

1 commit


20 Mar, 2016

1 commit

  • Pull audit updates from Paul Moore:
    "A small set of patches for audit this time; just three in total and
    one is a spelling fix.

    The two patches with actual content are designed to help prevent new
    instances of auditd from displacing an existing, functioning auditd
    and to generate a log of the attempt. Not to worry, dead/stuck auditd
    instances can still be replaced by a new instance without problem.

    Nothing controversial, and everything passes our regression suite"

    * 'stable-4.6' of git://git.infradead.org/users/pcmoore/audit:
    audit: Fix typo in comment
    audit: log failed attempts to change audit_pid configuration
    audit: stop an old auditd being starved out by a new auditd

    Linus Torvalds
     

09 Feb, 2016

1 commit


23 Jan, 2016

1 commit

  • parallel to mutex_{lock,unlock,trylock,is_locked,lock_nested},
    inode_foo(inode) being mutex_foo(&inode->i_mutex).

    Please, use those for access to ->i_mutex; over the coming cycle
    ->i_mutex will become rwsem, with ->lookup() done with it held
    only shared.

    Signed-off-by: Al Viro

    Al Viro
     

09 Sep, 2015

1 commit

  • Pull audit update from Paul Moore:
    "This is one of the larger audit patchsets in recent history,
    consisting of eight patches and almost 400 lines of changes.

    The bulk of the patchset is the new "audit by executable"
    functionality which allows admins to set an audit watch based on the
    executable on disk. Prior to this, admins could only track an
    application by PID, which has some obvious limitations.

    Beyond the new functionality we also have some refcnt fixes and a few
    minor cleanups"

    * 'upstream' of git://git.infradead.org/users/pcmoore/audit:
    fixup: audit: implement audit by executable
    audit: implement audit by executable
    audit: clean simple fsnotify implementation
    audit: use macros for unset inode and device values
    audit: make audit_del_rule() more robust
    audit: fix uninitialized variable in audit_add_rule()
    audit: eliminate unnecessary extra layer of watch parent references
    audit: eliminate unnecessary extra layer of watch references

    Linus Torvalds
     

13 Aug, 2015

1 commit

  • The Intel build-bot detected a sparse warning with with a patch I posted a
    couple of days ago that was accepted in the audit/next tree:

    Subject: [linux-next:master 6689/6751] kernel/audit_watch.c:543:36: sparse: dereference of noderef expression
    Date: Friday, August 07, 2015, 06:57:55 PM
    From: kbuild test robot
    tree: git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git master
    head: e6455bc5b91f41f842f30465c9193320f0568707
    commit: 2e3a8aeb63e5335d4f837d453787c71bcb479796 [6689/6751] Merge remote- tracking branch 'audit/next'
    sparse warnings: (new ones prefixed by >>)
    >> kernel/audit_watch.c:543:36: sparse: dereference of noderef expression
    kernel/audit_watch.c:544:28: sparse: dereference of noderef expression

    34d99af5 Richard Guy Briggs 2015-08-05 541 int audit_exe_compare(struct task_struct *tsk, struct audit_fsnotify_mark *mark)
    34d99af5 Richard Guy Briggs 2015-08-05 542 {
    34d99af5 Richard Guy Briggs 2015-08-05 @543 unsigned long ino = tsk->mm- >exe_file->f_inode->i_ino;
    34d99af5 Richard Guy Briggs 2015-08-05 544 dev_t dev = tsk->mm->exe_file- >f_inode->i_sb->s_dev;

    :::::: The code at line 543 was first introduced by commit
    :::::: 34d99af52ad40bd498ba66970579a5bc1fb1a3bc audit: implement audit by executable

    tsk->mm->exe_file requires RCU access. The warning was reproduceable by adding
    "C=1 CF=-D__CHECK_ENDIAN__" to the build command, and verified eliminated with
    this patch.

    Signed-off-by: Richard Guy Briggs
    Signed-off-by: Paul Moore

    Richard Guy Briggs
     

07 Aug, 2015

2 commits

  • 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
    Cc: Eric Paris
    Signed-off-by: Richard Guy Briggs
    [PM: minor whitespace clean to satisfy ./scripts/checkpatch]
    Signed-off-by: Paul Moore

    Richard Guy Briggs
     
  • Clean up a number of places were casted magic numbers are used to represent
    unset inode and device numbers in preparation for the audit by executable path
    patch set.

    Signed-off-by: Richard Guy Briggs
    [PM: enclosed the _UNSET macros in parentheses for ./scripts/checkpatch]
    Signed-off-by: Paul Moore

    Richard Guy Briggs
     

05 Aug, 2015

2 commits

  • The audit watch parent count was imbalanced, adding an unnecessary layer of
    watch parent references. Decrement the additional parent reference when a
    watch is reused, already having a reference to the parent.

    audit_find_parent() gets a reference to the parent, if the parent is
    already known. This additional parental reference is not needed if the
    watch is subsequently found by audit_add_to_parent(), and consumed if
    the watch does not already exist, so we need to put the parent if the
    watch is found, and do nothing if this new watch is added to the parent.

    If the parent wasn't already known, it is created with a refcount of 1
    and added to the audit_watch_group, then incremented by one to be
    subsequently consumed by the newly created watch in
    audit_add_to_parent().

    The rule points to the watch, not to the parent, so the rule's refcount
    gets bumped, not the parent's.

    See LKML, 2015-07-16

    Signed-off-by: Richard Guy Briggs
    Signed-off-by: Paul Moore

    Richard Guy Briggs
     
  • The audit watch count was imbalanced, adding an unnecessary layer of watch
    references. Only add the second reference when it is added to a parent.

    Signed-off-by: Richard Guy Briggs
    Signed-off-by: Paul Moore

    Richard Guy Briggs
     

16 Apr, 2015

1 commit


24 Sep, 2014

1 commit

  • 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=
    values.

    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: Burn Alting
    Signed-off-by: Richard Guy Briggs

    Burn Alting
     

18 Feb, 2014

1 commit

  • My rework of handling of notification events (namely commit 7053aee26a35
    "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: 7053aee26a3548ebaba046ae2e52396ccf56ac6c
    Reported-by: Vegard Nossum
    Signed-off-by: Jan Kara

    Jan Kara
     

22 Jan, 2014

3 commits

  • 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: Jan Kara
    Reviewed-by: Christoph Hellwig
    Cc: Eric Paris
    Cc: Al Viro
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Jan Kara
     
  • 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: Jan Kara
    Reviewed-by: Christoph Hellwig
    Cc: Eric Paris
    Cc: Al Viro
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Jan Kara
     
  • 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: Jan Kara
    Reviewed-by: Christoph Hellwig
    Cc: Eric Paris
    Cc: Al Viro
    Signed-off-by: Hugh Dickins
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Jan Kara
     

12 Jan, 2013

1 commit

  • It's possible for audit_log_start() to return NULL. Handle it in the
    various callers.

    Signed-off-by: Kees Cook
    Cc: Al Viro
    Cc: Eric Paris
    Cc: Jeff Layton
    Cc: "Eric W. Biederman"
    Cc: Julien Tinnes
    Cc: Will Drewry
    Cc: Steve Grubb
    Cc: Andrea Arcangeli
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Kees Cook
     

21 Dec, 2012

1 commit

  • Pull filesystem notification updates from Eric Paris:
    "This pull mostly is about locking changes in the fsnotify system. By
    switching the group lock from a spin_lock() to a mutex() we can now
    hold the lock across things like iput(). This fixes a problem
    involving unmounting a fs and having inodes be busy, first pointed out
    by FAT, but reproducible with tmpfs.

    This also restores signal driven I/O for inotify, which has been
    broken since about 2.6.32."

    Ugh. I *hate* the timing of this. It was rebased after the merge
    window opened, and then left to sit with the pull request coming the day
    before the merge window closes. That's just crap. But apparently the
    patches themselves have been around for over a year, just gathering
    dust, so now it's suddenly critical.

    Fixed up semantic conflict in fs/notify/fdinfo.c as per Stephen
    Rothwell's fixes from -next.

    * 'for-next' of git://git.infradead.org/users/eparis/notify:
    inotify: automatically restart syscalls
    inotify: dont skip removal of watch descriptor if creation of ignored event failed
    fanotify: dont merge permission events
    fsnotify: make fasync generic for both inotify and fanotify
    fsnotify: change locking order
    fsnotify: dont put marks on temporary list when clearing marks by group
    fsnotify: introduce locked versions of fsnotify_add_mark() and fsnotify_remove_mark()
    fsnotify: pass group to fsnotify_destroy_mark()
    fsnotify: use a mutex instead of a spinlock to protect a groups mark list
    fanotify: add an extra flag to mark_remove_from_mask that indicates wheather a mark should be destroyed
    fsnotify: take groups mark_lock before mark lock
    fsnotify: use reference counting for groups
    fsnotify: introduce fsnotify_get_group()
    inotify, fanotify: replace fsnotify_put_group() with fsnotify_destroy_group()

    Linus Torvalds
     

12 Dec, 2012

1 commit


12 Oct, 2012

2 commits


18 Sep, 2012

1 commit

  • Always store audit loginuids in type kuid_t.

    Print loginuids by converting them into uids in the appropriate user
    namespace, and then printing the resulting uid.

    Modify audit_get_loginuid to return a kuid_t.

    Modify audit_set_loginuid to take a kuid_t.

    Modify /proc//loginuid on read to convert the loginuid into the
    user namespace of the opener of the file.

    Modify /proc//loginud on write to convert the loginuid
    rom the user namespace of the opener of the file.

    Cc: Al Viro
    Cc: Eric Paris
    Cc: Paul Moore ?
    Cc: David Miller
    Signed-off-by: Eric W. Biederman

    Eric W. Biederman