1. 30 6月, 2016 3 次提交
  2. 01 5月, 2016 1 次提交
    • M
      ima: add support for creating files using the mknodat syscall · 05d1a717
      Mimi Zohar 提交于
      Commit 3034a146 "ima: pass 'opened' flag to identify newly created files"
      stopped identifying empty files as new files.  However new empty files
      can be created using the mknodat syscall.  On systems with IMA-appraisal
      enabled, these empty files are not labeled with security.ima extended
      attributes properly, preventing them from subsequently being opened in
      order to write the file data contents.  This patch defines a new hook
      named ima_post_path_mknod() to mark these empty files, created using
      mknodat, as new in order to allow the file data contents to be written.
      
      In addition, files with security.ima xattrs containing a file signature
      are considered "immutable" and can not be modified.  The file contents
      need to be written, before signing the file.  This patch relaxes this
      requirement for new files, allowing the file signature to be written
      before the file contents.
      
      Changelog:
      - defer identifying files with signatures stored as security.ima
        (based on Dmitry Rozhkov's comments)
      - removing tests (eg. dentry, dentry->d_inode, inode->i_size == 0)
        (based on Al's review)
      Signed-off-by: NMimi Zohar <zohar@linux.vnet.ibm.com>
      Cc: Al Viro <<viro@zeniv.linux.org.uk>
      Tested-by: NDmitry Rozhkov <dmitry.rozhkov@linux.intel.com>
      05d1a717
  3. 21 2月, 2016 6 次提交
    • M
      ima: measure and appraise the IMA policy itself · 19f8a847
      Mimi Zohar 提交于
      Add support for measuring and appraising the IMA policy itself.
      
      Changelog v4:
      - use braces on both if/else branches, even if single line on one of the
      branches - Dmitry
      - Use the id mapping - Dmitry
      Signed-off-by: NMimi Zohar <zohar@linux.vnet.ibm.com>
      Acked-by: NPetko Manolov <petkan@mip-labs.com>
      Acked-by: NDmitry Kasatkin <dmitry.kasatkin@huawei.com>
      19f8a847
    • M
      ima: support for kexec image and initramfs · d9ddf077
      Mimi Zohar 提交于
      Add IMA policy support for measuring/appraising the kexec image and
      initramfs. Two new IMA policy identifiers KEXEC_KERNEL_CHECK and
      KEXEC_INITRAMFS_CHECK are defined.
      
      Example policy rules:
      measure func=KEXEC_KERNEL_CHECK
      appraise func=KEXEC_KERNEL_CHECK appraise_type=imasig
      measure func=KEXEC_INITRAMFS_CHECK
      appraise func=KEXEC_INITRAMFS_CHECK appraise_type=imasig
      
      Moving the enumeration to the vfs layer simplified the patches, allowing
      the IMA changes, for the most part, to be separated from the other
      changes.  Unfortunately, passing either a kernel_read_file_id or a
      ima_hooks enumeration within IMA is messy.
      
      Option 1: duplicate kernel_read_file enumeration in ima_hooks
      
      enum kernel_read_file_id {
      	...
              READING_KEXEC_IMAGE,
              READING_KEXEC_INITRAMFS,
              READING_MAX_ID
      
      enum ima_hooks {
      	...
      	KEXEC_KERNEL_CHECK
      	KEXEC_INITRAMFS_CHECK
      
      Option 2: define ima_hooks as extension of kernel_read_file
      eg: enum ima_hooks {
              FILE_CHECK = READING_MAX_ID,
              MMAP_CHECK,
      
      In order to pass both kernel_read_file_id and ima_hooks values, we
      would need to specify a struct containing a union.
      
      struct caller_id {
              union {
                      enum ima_hooks func_id;
                      enum kernel_read_file_id read_id;
              };
      };
      
      Option 3: incorportate the ima_hooks enumeration into kernel_read_file_id,
      perhaps changing the enumeration name.
      
      For now, duplicate the new READING_KEXEC_IMAGE/INITRAMFS in the ima_hooks.
      
      Changelog v4:
      - replaced switch statement with a kernel_read_file_id to an ima_hooks
      id mapping array - Dmitry
      - renamed ima_hook tokens KEXEC_CHECK and INITRAMFS_CHECK to
      KEXEC_KERNEL_CHECK and KEXEC_INITRAMFS_CHECK respectively - Dave Young
      Signed-off-by: NMimi Zohar <zohar@linux.vnet.ibm.com>
      Acked-by: NPetko Manolov <petkan@mip-labs.com>
      Acked-by: NDmitry Kasatkin <dmitry.kasatkin@huawei.com>
      Cc: Dave Young <dyoung@redhat.com>
      d9ddf077
    • M
      module: replace copy_module_from_fd with kernel version · a1db7420
      Mimi Zohar 提交于
      Replace copy_module_from_fd() with kernel_read_file_from_fd().
      
      Although none of the upstreamed LSMs define a kernel_module_from_file
      hook, IMA is called, based on policy, to prevent unsigned kernel modules
      from being loaded by the original kernel module syscall and to
      measure/appraise signed kernel modules.
      
      The security function security_kernel_module_from_file() was called prior
      to reading a kernel module.  Preventing unsigned kernel modules from being
      loaded by the original kernel module syscall remains on the pre-read
      kernel_read_file() security hook.  Instead of reading the kernel module
      twice, once for measuring/appraising and again for loading the kernel
      module, the signature validation is moved to the kernel_post_read_file()
      security hook.
      
      This patch removes the security_kernel_module_from_file() hook and security
      call.
      Signed-off-by: NMimi Zohar <zohar@linux.vnet.ibm.com>
      Acked-by: NKees Cook <keescook@chromium.org>
      Acked-by: NLuis R. Rodriguez <mcgrof@kernel.org>
      Cc: Rusty Russell <rusty@rustcorp.com.au>
      a1db7420
    • M
      security: define kernel_read_file hook · 39eeb4fb
      Mimi Zohar 提交于
      The kernel_read_file security hook is called prior to reading the file
      into memory.
      
      Changelog v4+:
      - export security_kernel_read_file()
      Signed-off-by: NMimi Zohar <zohar@linux.vnet.ibm.com>
      Acked-by: NKees Cook <keescook@chromium.org>
      Acked-by: NLuis R. Rodriguez <mcgrof@kernel.org>
      Acked-by: NCasey Schaufler <casey@schaufler-ca.com>
      39eeb4fb
    • M
      firmware: replace call to fw_read_file_contents() with kernel version · e40ba6d5
      Mimi Zohar 提交于
      Replace the fw_read_file_contents with kernel_file_read_from_path().
      
      Although none of the upstreamed LSMs define a kernel_fw_from_file hook,
      IMA is called by the security function to prevent unsigned firmware from
      being loaded and to measure/appraise signed firmware, based on policy.
      
      Instead of reading the firmware twice, once for measuring/appraising the
      firmware and again for reading the firmware contents into memory, the
      kernel_post_read_file() security hook calculates the file hash based on
      the in memory file buffer.  The firmware is read once.
      
      This patch removes the LSM kernel_fw_from_file() hook and security call.
      
      Changelog v4+:
      - revert dropped buf->size assignment - reported by Sergey Senozhatsky
      v3:
      - remove kernel_fw_from_file hook
      - use kernel_file_read_from_path() - requested by Luis
      v2:
      - reordered and squashed firmware patches
      - fix MAX firmware size (Kees Cook)
      Signed-off-by: NMimi Zohar <zohar@linux.vnet.ibm.com>
      Acked-by: NKees Cook <keescook@chromium.org>
      Acked-by: NLuis R. Rodriguez <mcgrof@kernel.org>
      e40ba6d5
    • M
      ima: define a new hook to measure and appraise a file already in memory · cf222217
      Mimi Zohar 提交于
      This patch defines a new IMA hook ima_post_read_file() for measuring
      and appraising files read by the kernel. The caller loads the file into
      memory before calling this function, which calculates the hash followed by
      the normal IMA policy based processing.
      
      Changelog v5:
      - fail ima_post_read_file() if either file or buf is NULL
      v3:
      - rename ima_hash_and_process_file() to ima_post_read_file()
      
      v1:
      - split patch
      Signed-off-by: NMimi Zohar <zohar@linux.vnet.ibm.com>
      Acked-by: NDmitry Kasatkin <dmitry.kasatkin@huawei.com>
      cf222217
  4. 19 2月, 2016 2 次提交
  5. 23 1月, 2016 1 次提交
    • A
      wrappers for ->i_mutex access · 5955102c
      Al Viro 提交于
      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: NAl Viro <viro@zeniv.linux.org.uk>
      5955102c
  6. 22 5月, 2015 1 次提交
    • R
      ima: pass iint to ima_add_violation() · 8d94eb9b
      Roberto Sassu 提交于
      This patch adds the iint associated to the current inode as a new
      parameter of ima_add_violation(). The passed iint is always not NULL
      if a violation is detected. This modification will be used to determine
      the inode for which there is a violation.
      
      Since the 'd' and 'd-ng' template field init() functions were detecting
      a violation from the value of the iint pointer, they now check the new
      field 'violation', added to the 'ima_event_data' structure.
      
      Changelog:
       - v1:
         - modified an old comment (Roberto Sassu)
      Signed-off-by: NRoberto Sassu <rsassu@suse.de>
      Signed-off-by: NMimi Zohar <zohar@linux.vnet.ibm.com>
      8d94eb9b
  7. 08 10月, 2014 2 次提交
  8. 18 9月, 2014 4 次提交
    • R
      ima: detect violations for mmaped files · 1b68bdf9
      Roberto Sassu 提交于
      This patch fixes the detection of the 'open_writers' violation for mmaped
      files.
      
      before) an 'open_writers' violation is detected if the policy contains
              a rule with the criteria: func=FILE_CHECK mask=MAY_READ
      
      after) an 'open_writers' violation is detected if the current event
             matches one of the policy rules.
      
      With the old behaviour, the 'open_writers' violation is not detected
      in the following case:
      
      policy:
      measure func=FILE_MMAP mask=MAY_EXEC
      
      steps:
      1) open a shared library for writing
      2) execute a binary that links that shared library
      3) during the binary execution, modify the shared library and save
         the change
      
      result:
      the 'open_writers' violation measurement is not present in the IMA list.
      
      Only binaries executed are protected from writes. For libraries mapped
      in memory there is the flag MAP_DENYWRITE for this purpose, but according
      to the output of 'man mmap', the mmap flag is ignored.
      
      Since ima_rdwr_violation_check() is now called by process_measurement()
      the information about if the inode must be measured is already provided
      by ima_get_action(). Thus the unnecessary function ima_must_measure()
      has been removed.
      
      Changes in v3 (Dmitry Kasatkin):
      - Violation for MMAP_CHECK function are verified since this patch
      - Changed patch description a bit
      Signed-off-by: NRoberto Sassu <roberto.sassu@polito.it>
      Signed-off-by: NDmitry Kasatkin <d.kasatkin@samsung.com>
      Signed-off-by: NMimi Zohar <zohar@linux.vnet.ibm.com>
      1b68bdf9
    • R
      ima: fix race condition on ima_rdwr_violation_check and process_measurement · f7a859ff
      Roberto Sassu 提交于
      This patch fixes a race condition between two functions that try to access
      the same inode. Since the i_mutex lock is held and released separately
      in the two functions, there may be the possibility that a violation is
      not correctly detected.
      
      Suppose there are two processes, A (reader) and B (writer), if the
      following sequence happens:
      
      A: ima_rdwr_violation_check()
      B: ima_rdwr_violation_check()
      B: process_measurement()
      B: starts writing the inode
      A: process_measurement()
      
      the ToMToU violation (a reader may be accessing a content different from
      that measured, due to a concurrent modification by a writer) will not be
      detected. To avoid this issue, the violation check and the measurement
      must be done atomically.
      
      This patch fixes the problem by moving the violation check inside
      process_measurement() when the i_mutex lock is held. Differently from
      the old code, the violation check is executed also for the MMAP_CHECK
      hook (other than for FILE_CHECK). This allows to detect ToMToU violations
      that are possible because shared libraries can be opened for writing
      while they are in use (according to the output of 'man mmap', the mmap()
      flag MAP_DENYWRITE is ignored).
      
      Changes in v5 (Roberto Sassu):
      * get iint if action is not zero
      * exit process_measurement() after the violation check if action is zero
      * reverse order process_measurement() exit cleanup (Mimi)
      
      Changes in v4 (Dmitry Kasatkin):
      * iint allocation is done before calling ima_rdrw_violation_check()
        (Suggested-by Mimi)
      * do not check for violations if the policy does not contain 'measure'
        rules (done by Roberto Sassu)
      
      Changes in v3 (Dmitry Kasatkin):
      * no violation checking for MMAP_CHECK function in this patch
      * remove use of filename from violation
      * removes checking if ima is enabled from ima_rdrw_violation_check
      * slight style change
      Suggested-by: NDmitry Kasatkin <d.kasatkin@samsung.com>
      Signed-off-by: NRoberto Sassu <roberto.sassu@polito.it>
      Signed-off-by: NDmitry Kasatkin <d.kasatkin@samsung.com>
      Signed-off-by: NMimi Zohar <zohar@linux.vnet.ibm.com>
      f7a859ff
    • R
      ima: added ima_policy_flag variable · a756024e
      Roberto Sassu 提交于
      This patch introduces the new variable 'ima_policy_flag', whose bits
      are set depending on the action of the current policy rules. Only the
      flags IMA_MEASURE, IMA_APPRAISE and IMA_AUDIT are set.
      
      The new variable will be used to improve performance by skipping the
      unnecessary execution of IMA code if the policy does not contain rules
      with the above actions.
      
      Changes in v6 (Roberto Sassu)
      * do not check 'ima_initialized' before calling ima_update_policy_flag()
        in ima_update_policy() (suggested by Dmitry)
      * calling ima_update_policy_flag() moved to init_ima to co-locate with
        ima_initialized (Dmitry)
      * add/revise comments (Mimi)
      
      Changes in v5 (Roberto Sassu)
      * reset IMA_APPRAISE flag in 'ima_policy_flag' if 'ima_appraise' is set
        to zero (reported by Dmitry)
      * update 'ima_policy_flag' only if IMA initialization is successful
        (suggested by Mimi and Dmitry)
      * check 'ima_policy_flag' instead of 'ima_initialized'
        (suggested by Mimi and Dmitry)
      Signed-off-by: NRoberto Sassu <roberto.sassu@polito.it>
      Signed-off-by: NDmitry Kasatkin <d.kasatkin@samsung.com>
      Signed-off-by: NMimi Zohar <zohar@linux.vnet.ibm.com>
      a756024e
    • D
      ima: move keyring initialization to ima_init() · 31b70f66
      Dmitry Kasatkin 提交于
      ima_init() is used as a single place for all initializations.
      Experimental keyring patches used the 'late_initcall' which was
      co-located with the late_initcall(init_ima). When the late_initcall
      for the keyring initialization was abandoned, initialization moved
      to init_ima, though it would be more logical to move it to ima_init,
      where the rest of the initialization is done. This patch moves the
      keyring initialization to ima_init() as a preparatory step for
      loading the keys which will be added to ima_init() in following
      patches.
      Signed-off-by: NDmitry Kasatkin <d.kasatkin@samsung.com>
      Signed-off-by: NMimi Zohar <zohar@linux.vnet.ibm.com>
      31b70f66
  9. 09 9月, 2014 5 次提交
  10. 26 7月, 2014 1 次提交
  11. 17 7月, 2014 3 次提交
  12. 13 6月, 2014 2 次提交
    • D
      ima: check inode integrity cache in violation check · 14503eb9
      Dmitry Kasatkin 提交于
      When IMA did not support ima-appraisal, existance of the S_IMA flag
      clearly indicated that the file was measured. With IMA appraisal S_IMA
      flag indicates that file was measured and/or appraised. Because of
      this, when measurement is not enabled by the policy, violations are
      still reported.
      
      To differentiate between measurement and appraisal policies this
      patch checks the inode integrity cache flags.  The IMA_MEASURED
      flag indicates whether the file was actually measured, while the
      IMA_MEASURE flag indicates whether the file should be measured.
      Unfortunately, the IMA_MEASURED flag is reset to indicate the file
      needs to be re-measured.  Thus, this patch checks the IMA_MEASURE
      flag.
      
      This patch limits the false positive violation reports, but does
      not fix it entirely.  The IMA_MEASURE/IMA_MEASURED flags are
      indications that, at some point in time, the file opened for read
      was in policy, but might not be in policy now (eg. different uid).
      Other changes would be needed to further limit false positive
      violation reports.
      
      Changelog:
      - expanded patch description based on conversation with Roberto (Mimi)
      Signed-off-by: NDmitry Kasatkin <d.kasatkin@samsung.com>
      Signed-off-by: NMimi Zohar <zohar@linux.vnet.ibm.com>
      14503eb9
    • D
      ima: prevent unnecessary policy checking · b882fae2
      Dmitry Kasatkin 提交于
      ima_rdwr_violation_check is called for every file openning.
      The function checks the policy even when violation condition
      is not met. It causes unnecessary policy checking.
      
      This patch does policy checking only if violation condition is met.
      
      Changelog:
      - check writecount is greater than zero (Mimi)
      Signed-off-by: NDmitry Kasatkin <d.kasatkin@samsung.com>
      Signed-off-by: NMimi Zohar <zohar@linux.vnet.ibm.com>
      b882fae2
  13. 04 6月, 2014 1 次提交
    • M
      ima: audit log files opened with O_DIRECT flag · f9b2a735
      Mimi Zohar 提交于
      Files are measured or appraised based on the IMA policy.  When a
      file, in policy, is opened with the O_DIRECT flag, a deadlock
      occurs.
      
      The first attempt at resolving this lockdep temporarily removed the
      O_DIRECT flag and restored it, after calculating the hash.  The
      second attempt introduced the O_DIRECT_HAVELOCK flag. Based on this
      flag, do_blockdev_direct_IO() would skip taking the i_mutex a second
      time.  The third attempt, by Dmitry Kasatkin, resolves the i_mutex
      locking issue, by re-introducing the IMA mutex, but uncovered
      another problem.  Reading a file with O_DIRECT flag set, writes
      directly to userspace pages.  A second patch allocates a user-space
      like memory.  This works for all IMA hooks, except ima_file_free(),
      which is called on __fput() to recalculate the file hash.
      
      Until this last issue is addressed, do not 'collect' the
      measurement for measuring, appraising, or auditing files opened
      with the O_DIRECT flag set.  Based on policy, permit or deny file
      access.  This patch defines a new IMA policy rule option named
      'permit_directio'.  Policy rules could be defined, based on LSM
      or other criteria, to permit specific applications to open files
      with the O_DIRECT flag set.
      
      Changelog v1:
      - permit or deny file access based IMA policy rules
      Signed-off-by: NMimi Zohar <zohar@linux.vnet.ibm.com>
      Acked-by: NDmitry Kasatkin <d.kasatkin@samsung.com>
      Cc: <stable@vger.kernel.org>
      f9b2a735
  14. 08 3月, 2014 2 次提交
  15. 01 11月, 2013 1 次提交
    • M
      ima: extend the measurement list to include the file signature · bcbc9b0c
      Mimi Zohar 提交于
      This patch defines a new template called 'ima-sig', which includes
      the file signature in the template data, in addition to the file's
      digest and pathname.
      
      A template is composed of a set of fields.  Associated with each
      field is an initialization and display function.  This patch defines
      a new template field called 'sig', the initialization function
      ima_eventsig_init(), and the display function ima_show_template_sig().
      
      This patch modifies the .field_init() function definition to include
      the 'security.ima' extended attribute and length.
      
      Changelog:
      - remove unused code (Dmitry Kasatkin)
      - avoid calling ima_write_template_field_data() unnecesarily (Roberto Sassu)
      - rename DATA_FMT_SIG to DATA_FMT_HEX
      - cleanup ima_eventsig_init() based on Roberto's comments
      Signed-off-by: NMimi Zohar <zohar@linux.vnet.ibm.com>
      Signed-off-by: NDmitry Kasatkin <d.kasatkin@samsung.com>
      Signed-off-by: NRoberto Sassu <roberto.sassu@polito.it>
      bcbc9b0c
  16. 27 10月, 2013 2 次提交
    • M
      ima: enable support for larger default filedata hash algorithms · e7a2ad7e
      Mimi Zohar 提交于
      The IMA measurement list contains two hashes - a template data hash
      and a filedata hash.  The template data hash is committed to the TPM,
      which is limited, by the TPM v1.2 specification, to 20 bytes.  The
      filedata hash is defined as 20 bytes as well.
      
      Now that support for variable length measurement list templates was
      added, the filedata hash is not limited to 20 bytes.  This patch adds
      Kconfig support for defining larger default filedata hash algorithms
      and replacing the builtin default with one specified on the kernel
      command line.
      
      <uapi/linux/hash_info.h> contains a list of hash algorithms.  The
      Kconfig default hash algorithm is a subset of this list, but any hash
      algorithm included in the list can be specified at boot, using the
      'ima_hash=' kernel command line option.
      
      Changelog v2:
      - update Kconfig
      
      Changelog:
      - support hashes that are configured
      - use generic HASH_ALGO_ definitions
      - add Kconfig support
      - hash_setup must be called only once (Dmitry)
      - removed trailing whitespaces (Roberto Sassu)
      Signed-off-by: NMimi Zohar <zohar@us.ibm.com>
      Signed-off-by: NRoberto Sassu <roberto.sassu@polito.it>
      e7a2ad7e
    • R
      ima: defer determining the appraisal hash algorithm for 'ima' template · add1c05d
      Roberto Sassu 提交于
      The same hash algorithm should be used for calculating the file
      data hash for the IMA measurement list, as for appraising the file
      data integrity.  (The appraise hash algorithm is stored in the
      'security.ima' extended attribute.)  The exception is when the
      reference file data hash digest, stored in the extended attribute,
      is larger than the one supported by the template.  In this case,
      the file data hash needs to be calculated twice, once for the
      measurement list and, again, for appraisal.
      Signed-off-by: NRoberto Sassu <roberto.sassu@polito.it>
      Signed-off-by: NMimi Zohar <zohar@linux.vnet.ibm.com>
      add1c05d
  17. 26 10月, 2013 3 次提交