1. 13 Nov, 2014 1 commit
    • Dmitry Kasatkin's avatar
      evm: check xattr value length and type in evm_inode_setxattr() · b00f3bdc
      Dmitry Kasatkin authored
      commit 3b1deef6
      
       upstream.
      
      evm_inode_setxattr() can be called with no value. The function does not
      check the length so that following command can be used to produce the
      kernel oops: setfattr -n security.evm FOO. This patch fixes it.
      
      Changes in v3:
      * there is no reason to return different error codes for EVM_XATTR_HMAC
        and non EVM_XATTR_HMAC. Remove unnecessary test then.
      
      Changes in v2:
      * testing for validity of xattr type
      
      [ 1106.396921] BUG: unable to handle kernel NULL pointer dereference at           (null)
      [ 1106.398192] IP: [<ffffffff812af7b8>] evm_inode_setxattr+0x2a/0x48
      [ 1106.399244] PGD 29048067 PUD 290d7067 PMD 0
      [ 1106.399953] Oops: 0000 [#1] SMP
      [ 1106.400020] Modules linked in: bridge stp llc evdev serio_raw i2c_piix4 button fuse
      [ 1106.400020] CPU: 0 PID: 3635 Comm: setxattr Not tainted 3.16.0-kds+ #2936
      [ 1106.400020] Hardware name: Bochs Bochs, BIOS Bochs 01/01/2011
      [ 1106.400020] task: ffff8800291a0000 ti: ffff88002917c000 task.ti: ffff88002917c000
      [ 1106.400020] RIP: 0010:[<ffffffff812af7b8>]  [<ffffffff812af7b8>] evm_inode_setxattr+0x2a/0x48
      [ 1106.400020] RSP: 0018:ffff88002917fd50  EFLAGS: 00010246
      [ 1106.400020] RAX: 0000000000000000 RBX: ffff88002917fdf8 RCX: 0000000000000000
      [ 1106.400020] RDX: 0000000000000000 RSI: ffffffff818136d3 RDI: ffff88002917fdf8
      [ 1106.400020] RBP: ffff88002917fd68 R08: 0000000000000000 R09: 00000000003ec1df
      [ 1106.400020] R10: 0000000000000000 R11: 0000000000000000 R12: ffff8800438a0a00
      [ 1106.400020] R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000000
      [ 1106.400020] FS:  00007f7dfa7d7740(0000) GS:ffff88005da00000(0000) knlGS:0000000000000000
      [ 1106.400020] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
      [ 1106.400020] CR2: 0000000000000000 CR3: 000000003763e000 CR4: 00000000000006f0
      [ 1106.400020] Stack:
      [ 1106.400020]  ffff8800438a0a00 ffff88002917fdf8 0000000000000000 ffff88002917fd98
      [ 1106.400020]  ffffffff812a1030 ffff8800438a0a00 ffff88002917fdf8 0000000000000000
      [ 1106.400020]  0000000000000000 ffff88002917fde0 ffffffff8116d08a ffff88002917fdc8
      [ 1106.400020] Call Trace:
      [ 1106.400020]  [<ffffffff812a1030>] security_inode_setxattr+0x5d/0x6a
      [ 1106.400020]  [<ffffffff8116d08a>] vfs_setxattr+0x6b/0x9f
      [ 1106.400020]  [<ffffffff8116d1e0>] setxattr+0x122/0x16c
      [ 1106.400020]  [<ffffffff811687e8>] ? mnt_want_write+0x21/0x45
      [ 1106.400020]  [<ffffffff8114d011>] ? __sb_start_write+0x10f/0x143
      [ 1106.400020]  [<ffffffff811687e8>] ? mnt_want_write+0x21/0x45
      [ 1106.400020]  [<ffffffff811687c0>] ? __mnt_want_write+0x48/0x4f
      [ 1106.400020]  [<ffffffff8116d3e6>] SyS_setxattr+0x6e/0xb0
      [ 1106.400020]  [<ffffffff81529da9>] system_call_fastpath+0x16/0x1b
      [ 1106.400020] Code: c3 0f 1f 44 00 00 55 48 89 e5 41 55 49 89 d5 41 54 49 89 fc 53 48 89 f3 48 c7 c6 d3 36 81 81 48 89 df e8 18 22 04 00 85 c0 75 07 <41> 80 7d 00 02 74 0d 48 89 de 4c 89 e7 e8 5a fe ff ff eb 03 83
      [ 1106.400020] RIP  [<ffffffff812af7b8>] evm_inode_setxattr+0x2a/0x48
      [ 1106.400020]  RSP <ffff88002917fd50>
      [ 1106.400020] CR2: 0000000000000000
      [ 1106.428061] ---[ end trace ae08331628ba3050 ]---
      Reported-by: default avatarJan Kara <jack@suse.cz>
      Signed-off-by: default avatarDmitry Kasatkin <d.kasatkin@samsung.com>
      Signed-off-by: default avatarMimi Zohar <zohar@linux.vnet.ibm.com>
      Signed-off-by: default avatarLuis Henriques <luis.henriques@canonical.com>
      b00f3bdc
  2. 12 Jun, 2014 3 commits
  3. 02 Apr, 2014 1 commit
  4. 07 Mar, 2014 1 commit
  5. 25 Oct, 2013 1 commit
  6. 25 Jul, 2013 1 commit
  7. 20 Jun, 2013 1 commit
  8. 06 Feb, 2013 1 commit
    • Dmitry Kasatkin's avatar
      evm: add file system uuid to EVM hmac · 74de6684
      Dmitry Kasatkin authored
      
      EVM uses the same key for all file systems to calculate the HMAC,
      making it possible to paste inodes from one file system on to another
      one, without EVM being able to detect it.  To prevent such an attack,
      it is necessary to make the EVM HMAC file system specific.
      
      This patch uses the file system UUID, a file system unique identifier,
      to bind the EVM HMAC to the file system. The value inode->i_sb->s_uuid
      is used for the HMAC hash calculation, instead of using it for deriving
      the file system specific key.  Initializing the key for every inode HMAC
      calculation is a bit more expensive operation than adding the uuid to
      the HMAC hash.
      
      Changing the HMAC calculation method or adding additional info to the
      calculation, requires existing EVM labeled file systems to be relabeled.
      This patch adds a Kconfig HMAC version option for backwards compatability.
      
      Changelog v1:
      - squash "hmac version setting"
      Changelog v0:
      - add missing Kconfig depends (Mimi)
      Signed-off-by: default avatarDmitry Kasatkin <dmitry.kasatkin@intel.com>
      Signed-off-by: default avatarMimi Zohar <zohar@linux.vnet.ibm.com>
      74de6684
  9. 16 Jan, 2013 1 commit
  10. 07 Sep, 2012 1 commit
    • Mimi Zohar's avatar
      ima: integrity appraisal extension · 2fe5d6de
      Mimi Zohar authored
      
      IMA currently maintains an integrity measurement list used to assert the
      integrity of the running system to a third party.  The IMA-appraisal
      extension adds local integrity validation and enforcement of the
      measurement against a "good" value stored as an extended attribute
      'security.ima'.  The initial methods for validating 'security.ima' are
      hashed based, which provides file data integrity, and digital signature
      based, which in addition to providing file data integrity, provides
      authenticity.
      
      This patch creates and maintains the 'security.ima' xattr, containing
      the file data hash measurement.  Protection of the xattr is provided by
      EVM, if enabled and configured.
      
      Based on policy, IMA calls evm_verifyxattr() to verify a file's metadata
      integrity and, assuming success, compares the file's current hash value
      with the one stored as an extended attribute in 'security.ima'.
      
      Changelov v4:
      - changed iint cache flags to hex values
      
      Changelog v3:
      - change appraisal default for filesystems without xattr support to fail
      
      Changelog v2:
      - fix audit msg 'res' value
      - removed unused 'ima_appraise=' values
      
      Changelog v1:
      - removed unused iint mutex (Dmitry Kasatkin)
      - setattr hook must not reset appraised (Dmitry Kasatkin)
      - evm_verifyxattr() now differentiates between no 'security.evm' xattr
        (INTEGRITY_NOLABEL) and no EVM 'protected' xattrs included in the
        'security.evm' (INTEGRITY_NOXATTRS).
      - replace hash_status with ima_status (Dmitry Kasatkin)
      - re-initialize slab element ima_status on free (Dmitry Kasatkin)
      - include 'security.ima' in EVM if CONFIG_IMA_APPRAISE, not CONFIG_IMA
      - merged half "ima: ima_must_appraise_or_measure API change" (Dmitry Kasatkin)
      - removed unnecessary error variable in process_measurement() (Dmitry Kasatkin)
      - use ima_inode_post_setattr() stub function, if IMA_APPRAISE not configured
        (moved ima_inode_post_setattr() to ima_appraise.c)
      - make sure ima_collect_measurement() can read file
      
      Changelog:
      - add 'iint' to evm_verifyxattr() call (Dimitry Kasatkin)
      - fix the race condition between chmod, which takes the i_mutex and then
        iint->mutex, and ima_file_free() and process_measurement(), which take
        the locks in the reverse order, by eliminating iint->mutex. (Dmitry Kasatkin)
      - cleanup of ima_appraise_measurement() (Dmitry Kasatkin)
      - changes as a result of the iint not allocated for all regular files, but
        only for those measured/appraised.
      - don't try to appraise new/empty files
      - expanded ima_appraisal description in ima/Kconfig
      - IMA appraise definitions required even if IMA_APPRAISE not enabled
      - add return value to ima_must_appraise() stub
      - unconditionally set status = INTEGRITY_PASS *after* testing status,
        not before.  (Found by Joe Perches)
      Signed-off-by: default avatarMimi Zohar <zohar@us.ibm.com>
      Signed-off-by: default avatarDmitry Kasatkin <dmitry.kasatkin@intel.com>
      2fe5d6de
  11. 09 Nov, 2011 1 commit
  12. 14 Sep, 2011 3 commits
    • Mimi Zohar's avatar
      evm: permit mode bits to be updated · 566be59a
      Mimi Zohar authored
      
      Before permitting 'security.evm' to be updated, 'security.evm' must
      exist and be valid.  In the case that there are no existing EVM protected
      xattrs, it is safe for posix acls to update the mode bits.
      
      To differentiate between no 'security.evm' xattr and no xattrs used to
      calculate 'security.evm', this patch defines INTEGRITY_NOXATTR.
      Signed-off-by: default avatarMimi Zohar <zohar@us.ibm.com>
      566be59a
    • Mimi Zohar's avatar
      evm: posix acls modify i_mode · bf6d0f5d
      Mimi Zohar authored
      
      The posix xattr acls are 'system' prefixed, which normally would not
      affect security.evm.  An interesting side affect of writing posix xattr
      acls is their modifying of the i_mode, which is included in security.evm.
      
      This patch updates security.evm when posix xattr acls are written.
      Signed-off-by: default avatarMimi Zohar <zohar@us.ibm.com>
      bf6d0f5d
    • Mimi Zohar's avatar
      evm: limit verifying current security.evm integrity · a924ce0b
      Mimi Zohar authored
      
      evm_protect_xattr unnecessarily validates the current security.evm
      integrity, before updating non-evm protected extended attributes
      and other file metadata. This patch limits validating the current
      security.evm integrity to evm protected metadata.
      Signed-off-by: default avatarMimi Zohar <zohar@us.ibm.com>
      a924ce0b
  13. 11 Aug, 2011 1 commit
  14. 18 Jul, 2011 10 commits
    • Mimi Zohar's avatar
      evm: add evm_inode_setattr to prevent updating an invalid security.evm · 817b54aa
      Mimi Zohar authored
      
      Permit changing of security.evm only when valid, unless in fixmode.
      Reported-by: default avatarRoberto Sassu <roberto.sassu@polito.it>
      Signed-off-by: default avatarMimi Zohar <zohar@us.ibm.com>
      817b54aa
    • Mimi Zohar's avatar
      evm: permit only valid security.evm xattrs to be updated · 7102ebcd
      Mimi Zohar authored
      
      In addition to requiring CAP_SYS_ADMIN permission to modify/delete
      security.evm, prohibit invalid security.evm xattrs from changing,
      unless in fixmode. This patch prevents inadvertent 'fixing' of
      security.evm to reflect offline modifications.
      
      Changelog v7:
      - rename boot paramater 'evm_mode' to 'evm'
      Reported-by: default avatarRoberto Sassu <roberto.sassu@polito.it>
      Signed-off-by: default avatarMimi Zohar <zohar@us.ibm.com>
      7102ebcd
    • Dmitry Kasatkin's avatar
      evm: replace hmac_status with evm_status · 24e0198e
      Dmitry Kasatkin authored
      
      We will use digital signatures in addtion to hmac.
      Signed-off-by: default avatarDmitry Kasatkin <dmitry.kasatkin@nokia.com>
      Signed-off-by: default avatarMimi Zohar <zohar@us.ibm.com>
      24e0198e
    • Dmitry Kasatkin's avatar
      evm: evm_verify_hmac must not return INTEGRITY_UNKNOWN · 6d38ca01
      Dmitry Kasatkin authored
      
      If EVM is not supported or enabled, evm_verify_hmac() returns
      INTEGRITY_UNKNOWN, which ima_appraise_measurement() ignores and sets
      the appraisal status based solely on the security.ima verification.
      
      evm_verify_hmac() also returns INTEGRITY_UNKNOWN for other failures, such
      as temporary failures like -ENOMEM, resulting in possible attack vectors.
      This patch changes the default return code for temporary/unexpected
      failures, like -ENOMEM, from INTEGRITY_UNKNOWN to INTEGRITY_FAIL, making
      evm_verify_hmac() fail safe.
      
      As a result, failures need to be re-evaluated in order to catch both
      temporary errors, such as the -ENOMEM, as well as errors that have been
      resolved in fix mode.
      Signed-off-by: default avatarDmitry Kasatkin <dmitry.kasatkin@nokia.com>
      Signed-off-by: default avatarMimi Zohar <zohar@us.ibm.com>
      6d38ca01
    • Dmitry Kasatkin's avatar
      evm: additional parameter to pass integrity cache entry 'iint' · 2960e6cb
      Dmitry Kasatkin authored
      
      Additional iint parameter allows to skip lookup in the cache.
      Signed-off-by: default avatarDmitry Kasatkin <dmitry.kasatkin@nokia.com>
      Signed-off-by: default avatarMimi Zohar <zohar@linux.vnet.ibm.com>
      2960e6cb
    • Dmitry Kasatkin's avatar
      evm: crypto hash replaced by shash · d46eb369
      Dmitry Kasatkin authored
      
      Using shash is more efficient, because the algorithm is allocated only
      once. Only the descriptor to store the hash state needs to be allocated
      for every operation.
      
      Changelog v6:
      - check for crypto_shash_setkey failure
      Signed-off-by: default avatarDmitry Kasatkin <dmitry.kasatkin@nokia.com>
      Signed-off-by: default avatarMimi Zohar <zohar@linux.vnet.ibm.com>
      d46eb369
    • Mimi Zohar's avatar
      evm: add evm_inode_init_security to initialize new files · cb723180
      Mimi Zohar authored
      
      Initialize 'security.evm' for new files.
      
      Changelog v7:
      - renamed evm_inode_post_init_security to evm_inode_init_security
      - moved struct xattr definition to earlier patch
      - allocate xattr name
      Changelog v6:
      - Use 'struct evm_ima_xattr_data'
      Signed-off-by: default avatarMimi Zohar <zohar@us.ibm.com>
      cb723180
    • Mimi Zohar's avatar
      security: imbed evm calls in security hooks · 3e1be52d
      Mimi Zohar authored
      
      Imbed the evm calls evm_inode_setxattr(), evm_inode_post_setxattr(),
      evm_inode_removexattr() in the security hooks.  evm_inode_setxattr()
      protects security.evm xattr.  evm_inode_post_setxattr() and
      evm_inode_removexattr() updates the hmac associated with an inode.
      
      (Assumes an LSM module protects the setting/removing of xattr.)
      
      Changelog:
        - Don't define evm_verifyxattr(), unless CONFIG_INTEGRITY is enabled.
        - xattr_name is a 'const', value is 'void *'
      Signed-off-by: default avatarMimi Zohar <zohar@us.ibm.com>
      Acked-by: default avatarSerge Hallyn <serge.hallyn@ubuntu.com>
      3e1be52d
    • Dmitry Kasatkin's avatar
      evm: add support for different security.evm data types · 6be5cc52
      Dmitry Kasatkin authored
      
      EVM protects a file's security extended attributes(xattrs) against integrity
      attacks. The current patchset maintains an HMAC-sha1 value across the security
      xattrs, storing the value as the extended attribute 'security.evm'. We
      anticipate other methods for protecting the security extended attributes.
      This patch reserves the first byte of 'security.evm' as a place holder for
      the type of method.
      
      Changelog v6:
      - move evm_ima_xattr_type definition to security/integrity/integrity.h
      - defined a structure for the EVM xattr called evm_ima_xattr_data
        (based on Serge Hallyn's suggestion)
      - removed unnecessary memset
      Signed-off-by: default avatarDmitry Kasatkin <dmitry.kasatkin@nokia.com>
      Signed-off-by: default avatarMimi Zohar <zohar@us.ibm.com>
      Acked-by: default avatarSerge Hallyn <serge.hallyn@canonical.com>
      6be5cc52
    • Mimi Zohar's avatar
      evm: re-release · 66dbc325
      Mimi Zohar authored
      EVM protects a file's security extended attributes(xattrs) against integrity
      attacks.  This patchset provides the framework and an initial method.  The
      initial method maintains an HMAC-sha1 value across the security extended
      attributes, storing the HMAC value as the extended attribute 'security.evm'.
      Other methods of validating the integrity of a file's metadata will be posted
      separately (eg. EVM-digital-signatures).
      
      While this patchset does authenticate the security xattrs, and
      cryptographically binds them to the inode, coming extensions will bind other
      directory and inode metadata for more complete protection.  To help simplify
      the review and upstreaming process, each extension will be posted separately
      (eg. IMA-appraisal, IMA-appraisal-directory).  For a general overview of the
      proposed Linux integrity subsystem, refer to Dave Safford's whitepaper:
      http://downloads.sf.net/project/linux-ima/linux-ima/Integrity_overview.pdf.
      
      EVM depends on the Kernel Key Retention System to provide it with a
      trusted/encrypted key for the HMAC-sha1 operation. The key is loaded onto the
      root's keyring using keyctl.  Until EVM receives notification that the key has
      been successfully loaded onto the keyring (echo 1 > <securityfs>/evm), EVM can
      not create or validate the 'security.evm' xattr, but returns INTEGRITY_UNKNOWN.
      Loading the key and signaling EVM should be done as early as possible. Normally
      this is done in the initramfs, which has already been measured as part of the
      trusted boot.  For more information on creating and loading existing
      trusted/encrypted keys, refer to Documentation/keys-trusted-encrypted.txt.  A
      sample dracut patch, which loads the trusted/encrypted key and enables EVM, is
      available from http://linux-ima.sourceforge.net/#EVM
      
      .
      
      Based on the LSMs enabled, the set of EVM protected security xattrs is defined
      at compile.  EVM adds the following three calls to the existing security hooks:
      evm_inode_setxattr(), evm_inode_post_setxattr(), and evm_inode_removexattr.  To
      initialize and update the 'security.evm' extended attribute, EVM defines three
      calls: evm_inode_post_init(), evm_inode_post_setattr() and
      evm_inode_post_removexattr() hooks.  To verify the integrity of a security
      xattr, EVM exports evm_verifyxattr().
      
      Changelog v7:
      - Fixed URL in EVM ABI documentation
      
      Changelog v6: (based on Serge Hallyn's review)
      - fix URL in patch description
      - remove evm_hmac_size definition
      - use SHA1_DIGEST_SIZE (removed both MAX_DIGEST_SIZE and evm_hmac_size)
      - moved linux include before other includes
      - test for crypto_hash_setkey failure
      - fail earlier for invalid key
      - clear entire encrypted key, even on failure
      - check xattr name length before comparing xattr names
      
      Changelog:
      - locking based on i_mutex, remove evm_mutex
      - using trusted/encrypted keys for storing the EVM key used in the HMAC-sha1
        operation.
      - replaced crypto hash with shash (Dmitry Kasatkin)
      - support for additional methods of verifying the security xattrs
        (Dmitry Kasatkin)
      - iint not allocated for all regular files, but only for those appraised
      - Use cap_sys_admin in lieu of cap_mac_admin
      - Use __vfs_setxattr_noperm(), without permission checks, from EVM
      Signed-off-by: default avatarMimi Zohar <zohar@us.ibm.com>
      Acked-by: default avatarSerge Hallyn <serge.hallyn@canonical.com>
      66dbc325