An error occurred fetching the project authors.
  1. 27 Jul, 2020 6 commits
  2. 15 Jul, 2020 2 commits
  3. 13 May, 2020 2 commits
  4. 25 Mar, 2020 7 commits
    • Amir Goldstein's avatar
      fanotify: report name info for FAN_DIR_MODIFY event · 44d705b0
      Amir Goldstein authored
      Report event FAN_DIR_MODIFY with name in a variable length record similar
      to how fid's are reported.  With name info reporting implemented, setting
      FAN_DIR_MODIFY in mark mask is now allowed.
      
      When events are reported with name, the reported fid identifies the
      directory and the name follows the fid. The info record type for this
      event info is FAN_EVENT_INFO_TYPE_DFID_NAME.
      
      For now, all reported events have at most one info record which is
      either FAN_EVENT_INFO_TYPE_FID or FAN_EVENT_INFO_TYPE_DFID_NAME (for
      FAN_DIR_MODIFY).  Later on, events "on child" will report both records.
      
      There are several ways that an application can use this information:
      
      1. When watching a single directory, the name is always relative to
      the watched directory, so application need to fstatat(2) the name
      relative to the watched directory.
      
      2. When watching a set of directories, the application could keep a map
      of dirfd for all watched directories and hash the map by fid obtained
      with name_to_handle_at(2).  When getting a name event, the fid in the
      event info could be used to lookup the base dirfd in the map and then
      call fstatat(2) with that dirfd.
      
      3. When watching a filesystem (FAN_MARK_FILESYSTEM) or a large set of
      directories, the application could use open_by_handle_at(2) with the fid
      in event info to obtain dirfd for the directory where event happened and
      call fstatat(2) with this dirfd.
      
      The last option scales better for a large number of watched directories.
      The first two options may be available in the future also for non
      privileged fanotify watchers, because open_by_handle_at(2) requires
      the CAP_DAC_READ_SEARCH capability.
      
      Link: https://lore.kernel.org/r/20200319151022.31456-15-amir73il@gmail.comSigned-off-by: default avatarAmir Goldstein <amir73il@gmail.com>
      Signed-off-by: default avatarJan Kara <jack@suse.cz>
      44d705b0
    • Amir Goldstein's avatar
      fanotify: record name info for FAN_DIR_MODIFY event · cacfb956
      Amir Goldstein authored
      For FAN_DIR_MODIFY event, allocate a variable size event struct to store
      the dir entry name along side the directory file handle.
      
      At this point, name info reporting is not yet implemented, so trying to
      set FAN_DIR_MODIFY in mark mask will return -EINVAL.
      
      Link: https://lore.kernel.org/r/20200319151022.31456-14-amir73il@gmail.comSigned-off-by: default avatarAmir Goldstein <amir73il@gmail.com>
      Signed-off-by: default avatarJan Kara <jack@suse.cz>
      cacfb956
    • Jan Kara's avatar
      fanotify: Drop fanotify_event_has_fid() · 01affd54
      Jan Kara authored
      When some events have directory id and some object id,
      fanotify_event_has_fid() becomes mostly useless and confusing because we
      usually need to know which type of file handle the event has. So just
      drop the function and use fanotify_event_object_fh() instead.
      Signed-off-by: default avatarJan Kara <jack@suse.cz>
      01affd54
    • Amir Goldstein's avatar
      fanotify: prepare to report both parent and child fid's · d766b553
      Amir Goldstein authored
      For some events, we are going to report both child and parent fid's,
      so pass fsid and file handle as arguments to copy_fid_to_user(),
      which is going to be called with parent and child file handles.
      
      Link: https://lore.kernel.org/r/20200319151022.31456-13-amir73il@gmail.comSigned-off-by: default avatarAmir Goldstein <amir73il@gmail.com>
      Signed-off-by: default avatarJan Kara <jack@suse.cz>
      d766b553
    • Jan Kara's avatar
      fanotify: divorce fanotify_path_event and fanotify_fid_event · 7088f357
      Jan Kara authored
      Breakup the union and make them both inherit from abstract fanotify_event.
      
      fanotify_path_event, fanotify_fid_event and fanotify_perm_event inherit
      from fanotify_event.
      
      type field in abstract fanotify_event determines the concrete event type.
      
      fanotify_path_event, fanotify_fid_event and fanotify_perm_event are
      allocated from separate memcache pools.
      
      Rename fanotify_perm_event casting macro to FANOTIFY_PERM(), so that
      FANOTIFY_PE() and FANOTIFY_FE() can be used as casting macros to
      fanotify_path_event and fanotify_fid_event.
      
      [JK: Cleanup FANOTIFY_PE() and FANOTIFY_FE() to be proper inline
      functions and remove requirement that fanotify_event is the first in
      event structures]
      
      Link: https://lore.kernel.org/r/20200319151022.31456-11-amir73il@gmail.comSuggested-by: default avatarJan Kara <jack@suse.cz>
      Signed-off-by: default avatarAmir Goldstein <amir73il@gmail.com>
      Signed-off-by: default avatarJan Kara <jack@suse.cz>
      7088f357
    • Jan Kara's avatar
      fanotify: Store fanotify handles differently · afc894c7
      Jan Kara authored
      Currently, struct fanotify_fid groups fsid and file handle and is
      unioned together with struct path to save space. Also there is fh_type
      and fh_len directly in struct fanotify_event to avoid padding overhead.
      In the follwing patches, we will be adding more event types and this
      packing makes code difficult to follow. So unpack everything and create
      struct fanotify_fh which groups members logically related to file handle
      to make code easier to follow. In the following patch we will pack
      things again differently to make events smaller.
      Signed-off-by: default avatarJan Kara <jack@suse.cz>
      afc894c7
    • Jan Kara's avatar
      fanotify: Simplify create_fd() · a741c2fe
      Jan Kara authored
      create_fd() is never used with invalid path. Also the only thing it
      needs to know from fanotify_event is the path. Simplify the function to
      take path directly and assume it is correct.
      Signed-off-by: default avatarJan Kara <jack@suse.cz>
      a741c2fe
  5. 23 Oct, 2019 1 commit
  6. 12 Aug, 2019 1 commit
    • Aaron Goidel's avatar
      fanotify, inotify, dnotify, security: add security hook for fs notifications · ac5656d8
      Aaron Goidel authored
      As of now, setting watches on filesystem objects has, at most, applied a
      check for read access to the inode, and in the case of fanotify, requires
      CAP_SYS_ADMIN. No specific security hook or permission check has been
      provided to control the setting of watches. Using any of inotify, dnotify,
      or fanotify, it is possible to observe, not only write-like operations, but
      even read access to a file. Modeling the watch as being merely a read from
      the file is insufficient for the needs of SELinux. This is due to the fact
      that read access should not necessarily imply access to information about
      when another process reads from a file. Furthermore, fanotify watches grant
      more power to an application in the form of permission events. While
      notification events are solely, unidirectional (i.e. they only pass
      information to the receiving application), permission events are blocking.
      Permission events make a request to the receiving application which will
      then reply with a decision as to whether or not that action may be
      completed. This causes the issue of the watching application having the
      ability to exercise control over the triggering process. Without drawing a
      distinction within the permission check, the ability to read would imply
      the greater ability to control an application. Additionally, mount and
      superblock watches apply to all files within the same mount or superblock.
      Read access to one file should not necessarily imply the ability to watch
      all files accessed within a given mount or superblock.
      
      In order to solve these issues, a new LSM hook is implemented and has been
      placed within the system calls for marking filesystem objects with inotify,
      fanotify, and dnotify watches. These calls to the hook are placed at the
      point at which the target path has been resolved and are provided with the
      path struct, the mask of requested notification events, and the type of
      object on which the mark is being set (inode, superblock, or mount). The
      mask and obj_type have already been translated into common FS_* values
      shared by the entirety of the fs notification infrastructure. The path
      struct is passed rather than just the inode so that the mount is available,
      particularly for mount watches. This also allows for use of the hook by
      pathname-based security modules. However, since the hook is intended for
      use even by inode based security modules, it is not placed under the
      CONFIG_SECURITY_PATH conditional. Otherwise, the inode-based security
      modules would need to enable all of the path hooks, even though they do not
      use any of them.
      
      This only provides a hook at the point of setting a watch, and presumes
      that permission to set a particular watch implies the ability to receive
      all notification about that object which match the mask. This is all that
      is required for SELinux. If other security modules require additional hooks
      or infrastructure to control delivery of notification, these can be added
      by them. It does not make sense for us to propose hooks for which we have
      no implementation. The understanding that all notifications received by the
      requesting application are all strictly of a type for which the application
      has been granted permission shows that this implementation is sufficient in
      its coverage.
      
      Security modules wishing to provide complete control over fanotify must
      also implement a security_file_open hook that validates that the access
      requested by the watching application is authorized. Fanotify has the issue
      that it returns a file descriptor with the file mode specified during
      fanotify_init() to the watching process on event. This is already covered
      by the LSM security_file_open hook if the security module implements
      checking of the requested file mode there. Otherwise, a watching process
      can obtain escalated access to a file for which it has not been authorized.
      
      The selinux_path_notify hook implementation works by adding five new file
      permissions: watch, watch_mount, watch_sb, watch_reads, and watch_with_perm
      (descriptions about which will follow), and one new filesystem permission:
      watch (which is applied to superblock checks). The hook then decides which
      subset of these permissions must be held by the requesting application
      based on the contents of the provided mask and the obj_type. The
      selinux_file_open hook already checks the requested file mode and therefore
      ensures that a watching process cannot escalate its access through
      fanotify.
      
      The watch, watch_mount, and watch_sb permissions are the baseline
      permissions for setting a watch on an object and each are a requirement for
      any watch to be set on a file, mount, or superblock respectively. It should
      be noted that having either of the other two permissions (watch_reads and
      watch_with_perm) does not imply the watch, watch_mount, or watch_sb
      permission. Superblock watches further require the filesystem watch
      permission to the superblock. As there is no labeled object in view for
      mounts, there is no specific check for mount watches beyond watch_mount to
      the inode. Such a check could be added in the future, if a suitable labeled
      object existed representing the mount.
      
      The watch_reads permission is required to receive notifications from
      read-exclusive events on filesystem objects. These events include accessing
      a file for the purpose of reading and closing a file which has been opened
      read-only. This distinction has been drawn in order to provide a direct
      indication in the policy for this otherwise not obvious capability. Read
      access to a file should not necessarily imply the ability to observe read
      events on a file.
      
      Finally, watch_with_perm only applies to fanotify masks since it is the
      only way to set a mask which allows for the blocking, permission event.
      This permission is needed for any watch which is of this type. Though
      fanotify requires CAP_SYS_ADMIN, this is insufficient as it gives implicit
      trust to root, which we do not do, and does not support least privilege.
      Signed-off-by: default avatarAaron Goidel <acgoide@tycho.nsa.gov>
      Acked-by: default avatarCasey Schaufler <casey@schaufler-ca.com>
      Acked-by: default avatarJan Kara <jack@suse.cz>
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      ac5656d8
  7. 28 May, 2019 1 commit
  8. 19 Mar, 2019 1 commit
    • Jan Kara's avatar
      fanotify: Allow copying of file handle to userspace · b2d22b6b
      Jan Kara authored
      When file handle is embedded inside fanotify_event and usercopy checks
      are enabled, we get a warning like:
      
      Bad or missing usercopy whitelist? Kernel memory exposure attempt detected
      from SLAB object 'fanotify_event' (offset 40, size 8)!
      WARNING: CPU: 1 PID: 7649 at mm/usercopy.c:78 usercopy_warn+0xeb/0x110
      mm/usercopy.c:78
      
      Annotate handling in fanotify_event properly to mark copying it to
      userspace is fine.
      
      Reported-by: syzbot+2c49971e251e36216d1f@syzkaller.appspotmail.com
      Fixes: a8b13aa2 ("fanotify: enable FAN_REPORT_FID init flag")
      Signed-off-by: default avatarKees Cook <keescook@chromium.org>
      Reviewed-by: default avatarAmir Goldstein <amir73il@gmail.com>
      Signed-off-by: default avatarJan Kara <jack@suse.cz>
      b2d22b6b
  9. 18 Feb, 2019 5 commits
  10. 07 Feb, 2019 8 commits
    • Amir Goldstein's avatar
      fanotify: add support for create/attrib/move/delete events · 235328d1
      Amir Goldstein authored
      Add support for events with data type FSNOTIFY_EVENT_INODE
      (e.g. create/attrib/move/delete) for inode and filesystem mark types.
      
      The "inode" events do not carry enough information (i.e. path) to
      report event->fd, so we do not allow setting a mask for those events
      unless group supports reporting fid.
      
      The "inode" events are not supported on a mount mark, because they do
      not carry enough information (i.e. path) to be filtered by mount point.
      
      The "dirent" events (create/move/delete) report the fid of the parent
      directory where events took place without specifying the filename of the
      child. In the future, fanotify may get support for reporting filename
      information for those events.
      
      Cc: <linux-api@vger.kernel.org>
      Signed-off-by: default avatarAmir Goldstein <amir73il@gmail.com>
      Signed-off-by: default avatarJan Kara <jack@suse.cz>
      235328d1
    • Amir Goldstein's avatar
      fanotify: support events with data type FSNOTIFY_EVENT_INODE · 83b535d2
      Amir Goldstein authored
      When event data type is FSNOTIFY_EVENT_INODE, we don't have a refernece
      to the mount, so we will not be able to open a file descriptor when user
      reads the event. However, if the listener has enabled reporting file
      identifier with the FAN_REPORT_FID init flag, we allow reporting those
      events and we use an identifier inode to encode fid.
      
      The inode to use as identifier when reporting fid depends on the event.
      For dirent modification events, we report the modified directory inode
      and we report the "victim" inode otherwise.
      For example:
      FS_ATTRIB reports the child inode even if reported on a watched parent.
      FS_CREATE reports the modified dir inode and not the created inode.
      
      [JK: Fixup condition in fanotify_group_event_mask()]
      Signed-off-by: default avatarAmir Goldstein <amir73il@gmail.com>
      Signed-off-by: default avatarJan Kara <jack@suse.cz>
      83b535d2
    • Amir Goldstein's avatar
      fanotify: use vfs_get_fsid() helper instead of vfs_statfs() · 73072283
      Amir Goldstein authored
      This is a cleanup that doesn't change any logic.
      Signed-off-by: default avatarAmir Goldstein <amir73il@gmail.com>
      Signed-off-by: default avatarJan Kara <jack@suse.cz>
      73072283
    • Amir Goldstein's avatar
      fanotify: cache fsid in fsnotify_mark_connector · 77115225
      Amir Goldstein authored
      For FAN_REPORT_FID, we need to encode fid with fsid of the filesystem on
      every event. To avoid having to call vfs_statfs() on every event to get
      fsid, we store the fsid in fsnotify_mark_connector on the first time we
      add a mark and on handle event we use the cached fsid.
      
      Subsequent calls to add mark on the same object are expected to pass the
      same fsid, so the call will fail on cached fsid mismatch.
      
      If an event is reported on several mark types (inode, mount, filesystem),
      all connectors should already have the same fsid, so we use the cached
      fsid from the first connector.
      
      [JK: Simplify code flow around fanotify_get_fid()
           make fsid argument of fsnotify_add_mark_locked() unconditional]
      Suggested-by: default avatarJan Kara <jack@suse.cz>
      Signed-off-by: default avatarAmir Goldstein <amir73il@gmail.com>
      Signed-off-by: default avatarJan Kara <jack@suse.cz>
      77115225
    • Amir Goldstein's avatar
      fanotify: enable FAN_REPORT_FID init flag · a8b13aa2
      Amir Goldstein authored
      When setting up an fanotify listener, user may request to get fid
      information in event instead of an open file descriptor.
      
      The fid obtained with event on a watched object contains the file
      handle returned by name_to_handle_at(2) and fsid returned by statfs(2).
      
      Restrict FAN_REPORT_FID to class FAN_CLASS_NOTIF, because we have have
      no good reason to support reporting fid on permission events.
      
      When setting a mark, we need to make sure that the filesystem
      supports encoding file handles with name_to_handle_at(2) and that
      statfs(2) encodes a non-zero fsid.
      
      Cc: <linux-api@vger.kernel.org>
      Signed-off-by: default avatarAmir Goldstein <amir73il@gmail.com>
      Signed-off-by: default avatarJan Kara <jack@suse.cz>
      a8b13aa2
    • Amir Goldstein's avatar
      fanotify: copy event fid info to user · 5e469c83
      Amir Goldstein authored
      If group requested FAN_REPORT_FID and event has file identifier,
      copy that information to user reading the event after event metadata.
      
      fid information is formatted as struct fanotify_event_info_fid
      that includes a generic header struct fanotify_event_info_header,
      so that other info types could be defined in the future using the
      same header.
      
      metadata->event_len includes the length of the fid information.
      
      The fid information includes the filesystem's fsid (see statfs(2))
      followed by an NFS file handle of the file that could be passed as
      an argument to open_by_handle_at(2).
      
      Cc: <linux-api@vger.kernel.org>
      Signed-off-by: default avatarAmir Goldstein <amir73il@gmail.com>
      Signed-off-by: default avatarJan Kara <jack@suse.cz>
      5e469c83
    • Amir Goldstein's avatar
      fanotify: encode file identifier for FAN_REPORT_FID · e9e0c890
      Amir Goldstein authored
      When user requests the flag FAN_REPORT_FID in fanotify_init(),
      a unique file identifier of the event target object will be reported
      with the event.
      
      The file identifier includes the filesystem's fsid (i.e. from statfs(2))
      and an NFS file handle of the file (i.e. from name_to_handle_at(2)).
      
      The file identifier makes holding the path reference and passing a file
      descriptor to user redundant, so those are disabled in a group with
      FAN_REPORT_FID.
      
      Encode fid and store it in event for a group with FAN_REPORT_FID.
      Up to 12 bytes of file handle on 32bit arch (16 bytes on 64bit arch)
      are stored inline in fanotify_event struct. Larger file handles are
      stored in an external allocated buffer.
      
      On failure to encode fid, we print a warning and queue the event
      without the fid information.
      
      [JK: Fold part of later patched into this one to use
      exportfs_encode_inode_fh() right away]
      Signed-off-by: default avatarAmir Goldstein <amir73il@gmail.com>
      Signed-off-by: default avatarJan Kara <jack@suse.cz>
      e9e0c890
    • Amir Goldstein's avatar
      fanotify: open code fill_event_metadata() · bb2f7b45
      Amir Goldstein authored
      The helper is quite trivial and open coding it will make it easier
      to implement copying event fid info to user.
      Signed-off-by: default avatarAmir Goldstein <amir73il@gmail.com>
      Signed-off-by: default avatarJan Kara <jack@suse.cz>
      bb2f7b45
  11. 06 Feb, 2019 2 commits
  12. 11 Dec, 2018 1 commit
  13. 05 Dec, 2018 1 commit
  14. 08 Oct, 2018 1 commit
  15. 04 Oct, 2018 1 commit