30 Dec, 2020

1 commit

  • commit 950cc0d2bef078e1f6459900ca4d4b2a2e0e3c37 upstream.

    The handle_inode_event() interface was added as (quoting comment):
    "a simple variant of handle_event() for groups that only have inode
    marks and don't have ignore mask".

    In other words, all backends except fanotify. The inotify backend
    also falls under this category, but because it required extra arguments
    it was left out of the initial pass of backends conversion to the
    simple interface.

    This results in code duplication between the generic helper
    fsnotify_handle_event() and the inotify_handle_event() callback
    which also happen to be buggy code.

    Generalize the handle_inode_event() arguments and add the check for
    FS_EXCL_UNLINK flag to the generic helper, so inotify backend could
    be converted to use the simple interface.

    Link: https://lore.kernel.org/r/20201202120713.702387-2-amir73il@gmail.com
    CC: stable@vger.kernel.org
    Fixes: b9a1b9772509 ("fsnotify: create method handle_inode_event() in fsnotify_operations")
    Signed-off-by: Amir Goldstein
    Signed-off-by: Jan Kara
    Signed-off-by: Greg Kroah-Hartman

    Amir Goldstein
     

28 Jul, 2020

3 commits

  • The method handle_event() grew a lot of complexity due to the design of
    fanotify and merging of ignore masks.

    Most backends do not care about this complex functionality, so we can hide
    this complexity from them.

    Introduce a method handle_inode_event() that serves those backends and
    passes a single inode mark and less arguments.

    This change converts all backends except fanotify and inotify to use the
    simplified handle_inode_event() method. In pricipal, inotify could have
    also used the new method, but that would require passing more arguments
    on the simple helper (data, data_type, cookie), so we leave it with the
    handle_event() method.

    Link: https://lore.kernel.org/r/20200722125849.17418-9-amir73il@gmail.com
    Suggested-by: Jan Kara
    Signed-off-by: Amir Goldstein
    Signed-off-by: Jan Kara

    Amir Goldstein
     
  • The audit group marks mask does not contain any events possible on
    a child so setting the flag FS_EVENT_ON_CHILD in the mask is counter
    productive.

    It may lead to the undesired outcome of setting the dentry flag
    DCACHE_FSNOTIFY_PARENT_WATCHED on a directory inode even though it is
    not watching children, because the audit mark contribute the flag
    FS_EVENT_ON_CHILD to the inode's fsnotify_mask and another mark could
    be contributing an event that is possible on child to the inode's mask.

    Furthermore in the following patches we want to use FS_EVENT_ON_CHILD
    for non-dir inodes for other purposes so stop using the flag.

    Link: https://lore.kernel.org/r/20200722125849.17418-4-amir73il@gmail.com
    Signed-off-by: Amir Goldstein
    Signed-off-by: Jan Kara

    Amir Goldstein
     
  • The 'inode' argument to handle_event(), sometimes referred to as
    'to_tell' is somewhat obsolete.
    It is a remnant from the times when a group could only have an inode mark
    associated with an event.

    We now pass an iter_info array to the callback, with all marks associated
    with an event.

    Most backends ignore this argument, with two exceptions:
    1. dnotify uses it for sanity check that event is on directory
    2. fanotify uses it to report fid of directory on directory entry
    modification events

    Remove the 'inode' argument and add a 'dir' argument.
    The callback function signature is deliberately changed, because
    the meaning of the argument has changed and the arguments have
    been documented.

    The 'dir' argument is set to when 'file_name' is specified and it is
    referring to the directory that the 'file_name' entry belongs to.

    Signed-off-by: Amir Goldstein
    Signed-off-by: Jan Kara

    Amir Goldstein
     

06 Apr, 2020

1 commit

  • Pull fsnotify updates from Jan Kara:
    "This implements the fanotify FAN_DIR_MODIFY event.

    This event reports the name in a directory under which a change
    happened and together with the directory filehandle and fstatat()
    allows reliable and efficient implementation of directory
    synchronization"

    * tag 'fsnotify_for_v5.7-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs:
    fanotify: Fix the checks in fanotify_fsid_equal
    fanotify: report name info for FAN_DIR_MODIFY event
    fanotify: record name info for FAN_DIR_MODIFY event
    fanotify: Drop fanotify_event_has_fid()
    fanotify: prepare to report both parent and child fid's
    fanotify: send FAN_DIR_MODIFY event flavor with dir inode and name
    fanotify: divorce fanotify_path_event and fanotify_fid_event
    fanotify: Store fanotify handles differently
    fanotify: Simplify create_fd()
    fanotify: fix merging marks masks with FAN_ONDIR
    fanotify: merge duplicate events on parent and child
    fsnotify: replace inode pointer with an object id
    fsnotify: simplify arguments passing to fsnotify_parent()
    fsnotify: use helpers to access data by data_type
    fsnotify: funnel all dirent events through fsnotify_name()
    fsnotify: factor helpers fsnotify_dentry() and fsnotify_file()
    fsnotify: tidy up FS_ and FAN_ constants

    Linus Torvalds
     

24 Mar, 2020

1 commit


10 Feb, 2020

1 commit

  • Common Criteria calls out for any action that modifies the audit trail to
    be recorded. That usually is interpreted to mean insertion or removal of
    rules. It is not required to log modification of the inode information
    since the watch is still in effect. Additionally, if the rule is a never
    rule and the underlying file is one they do not want events for, they
    get an event for this bookkeeping update against their wishes.

    Since no device/inode info is logged at insertion and no device/inode
    information is logged on update, there is nothing meaningful being
    communicated to the admin by the CONFIG_CHANGE updated_rules event. One
    can assume that the rule was not "modified" because it is still watching
    the intended target. If the device or inode cannot be resolved, then
    audit_panic is called which is sufficient.

    The correct resolution is to drop logging config_update events since
    the watch is still in effect but just on another unknown inode.

    Signed-off-by: Steve Grubb
    Signed-off-by: Paul Moore

    Steve Grubb
     

11 Nov, 2019

1 commit


31 May, 2019

1 commit

  • Based on 1 normalized pattern(s):

    this program is free software you can redistribute it and or modify
    it under the terms of the gnu general public license as published by
    the free software foundation either version 2 of the license or at
    your option any later version this program is distributed in the
    hope that it will be useful but without any warranty without even
    the implied warranty of merchantability or fitness for a particular
    purpose see the gnu general public license for more details you
    should have received a copy of the gnu general public license along
    with this program if not write to the free software foundation inc
    59 temple place suite 330 boston ma 02111 1307 usa

    extracted by the scancode license scanner the SPDX license identifier

    GPL-2.0-or-later

    has been chosen to replace the boilerplate/reference in 1334 file(s).

    Signed-off-by: Thomas Gleixner
    Reviewed-by: Allison Randal
    Reviewed-by: Richard Fontana
    Cc: linux-spdx@vger.kernel.org
    Link: https://lkml.kernel.org/r/20190527070033.113240726@linutronix.de
    Signed-off-by: Greg Kroah-Hartman

    Thomas Gleixner
     

29 Apr, 2019

1 commit


27 Apr, 2019

2 commits


19 Jan, 2019

1 commit

  • Tie syscall information to all CONFIG_CHANGE calls since they are all a
    result of user actions.

    Exclude user records from syscall context:
    Since the function audit_log_common_recv_msg() is shared by a number of
    AUDIT_CONFIG_CHANGE and the entire range of AUDIT_USER_* record types,
    and since the AUDIT_CONFIG_CHANGE message type has been converted to a
    syscall accompanied record type, special-case the AUDIT_USER_* range of
    messages so they remain standalone records.

    See: https://github.com/linux-audit/audit-kernel/issues/59
    See: https://github.com/linux-audit/audit-kernel/issues/50

    Signed-off-by: Richard Guy Briggs
    [PM: fix line lengths in kernel/audit.c]
    Signed-off-by: Paul Moore

    Richard Guy Briggs
     

27 Nov, 2018

1 commit


20 Nov, 2018

1 commit

  • There are still a couple of places (mark and watch config changes) that
    open code auid and ses fields in sequence in records instead of using
    the audit_log_session_info() helper. Use the helper. Adjust the helper
    to accommodate being the first fields. Passes audit-testsuite.

    Signed-off-by: Richard Guy Briggs
    [PM: fixed misspellings in the description]
    Signed-off-by: Paul Moore

    Richard Guy Briggs
     

18 Jul, 2018

1 commit

  • 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

    Ronny Chevalier
     

28 Jun, 2018

1 commit

  • Check the audit_enabled flag and bail immediately. This does not change
    the functionality, but brings the code format in line with similar
    checks in audit_tree_log_remove_rule(), audit_mark_log_rule_change(),
    and elsewhere in the audit code.

    See: https://github.com/linux-audit/audit-kernel/issues/50

    Signed-off-by: Richard Guy Briggs
    [PM: tweaked subject line]
    Signed-off-by: Paul Moore

    Richard Guy Briggs
     

17 Jun, 2018

1 commit

  • Pull fsnotify updates from Jan Kara:
    "fsnotify cleanups unifying handling of different watch types.

    This is the shortened fsnotify series from Amir with the last five
    patches pulled out. Amir has modified those patches to not change
    struct inode but obviously it's too late for those to go into this
    merge window"

    * tag 'fsnotify_for_v4.18-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs:
    fsnotify: add fsnotify_add_inode_mark() wrappers
    fanotify: generalize fanotify_should_send_event()
    fsnotify: generalize send_to_group()
    fsnotify: generalize iteration of marks by object type
    fsnotify: introduce marks iteration helpers
    fsnotify: remove redundant arguments to handle_event()
    fsnotify: use type id to identify connector object type

    Linus Torvalds
     

18 May, 2018

2 commits

  • Before changing the arguments of the functions fsnotify_add_mark()
    and fsnotify_add_mark_locked(), convert most callers to use a wrapper.

    Signed-off-by: Amir Goldstein
    Signed-off-by: Jan Kara

    Amir Goldstein
     
  • inode_mark and vfsmount_mark arguments are passed to handle_event()
    operation as function arguments as well as on iter_info struct.
    The difference is that iter_info struct may contain marks that should
    not be handled and are represented as NULL arguments to inode_mark or
    vfsmount_mark.

    Instead of passing the inode_mark and vfsmount_mark arguments, add
    a report_mask member to iter_info struct to indicate which marks should
    be handled, versus marks that should only be kept alive during user
    wait.

    This change is going to be used for passing more mark types
    with handle_event() (i.e. super block marks).

    Signed-off-by: Amir Goldstein
    Signed-off-by: Jan Kara

    Amir Goldstein
     

15 May, 2018

1 commit

  • Recognizing that the audit context is an internal audit value, use an
    access function to retrieve the audit context pointer for the task
    rather than reaching directly into the task struct to get it.

    Signed-off-by: Richard Guy Briggs
    [PM: merge fuzz in auditsc.c and selinuxfs.c, checkpatch.pl fixes]
    Signed-off-by: Paul Moore

    Richard Guy Briggs
     

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