1. 25 3月, 2018 8 次提交
    • P
      ima: Fallback to the builtin hash algorithm · ab60368a
      Petr Vorel 提交于
      IMA requires having it's hash algorithm be compiled-in due to it's
      early use.  The default IMA algorithm is protected by Kconfig to be
      compiled-in.
      
      The ima_hash kernel parameter allows to choose the hash algorithm. When
      the specified algorithm is not available or available as a module, IMA
      initialization fails, which leads to a kernel panic (mknodat syscall calls
      ima_post_path_mknod()).  Therefore as fallback we force IMA to use
      the default builtin Kconfig hash algorithm.
      
      Fixed crash:
      
      $ grep CONFIG_CRYPTO_MD4 .config
      CONFIG_CRYPTO_MD4=m
      
      [    0.000000] Command line: BOOT_IMAGE=/boot/vmlinuz-4.12.14-2.3-default root=UUID=74ae8202-9ca7-4e39-813b-22287ec52f7a video=1024x768-16 plymouth.ignore-serial-consoles console=ttyS0 console=tty resume=/dev/disk/by-path/pci-0000:00:07.0-part3 splash=silent showopts ima_hash=md4
      ...
      [    1.545190] ima: Can not allocate md4 (reason: -2)
      ...
      [    2.610120] BUG: unable to handle kernel NULL pointer dereference at           (null)
      [    2.611903] IP: ima_match_policy+0x23/0x390
      [    2.612967] PGD 0 P4D 0
      [    2.613080] Oops: 0000 [#1] SMP
      [    2.613080] Modules linked in: autofs4
      [    2.613080] Supported: Yes
      [    2.613080] CPU: 0 PID: 1 Comm: systemd Not tainted 4.12.14-2.3-default #1
      [    2.613080] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.0.0-prebuilt.qemu-project.org 04/01/2014
      [    2.613080] task: ffff88003e2d0040 task.stack: ffffc90000190000
      [    2.613080] RIP: 0010:ima_match_policy+0x23/0x390
      [    2.613080] RSP: 0018:ffffc90000193e88 EFLAGS: 00010296
      [    2.613080] RAX: 0000000000000000 RBX: 000000000000000c RCX: 0000000000000004
      [    2.613080] RDX: 0000000000000010 RSI: 0000000000000001 RDI: ffff880037071728
      [    2.613080] RBP: 0000000000008000 R08: 0000000000000000 R09: 0000000000000000
      [    2.613080] R10: 0000000000000008 R11: 61c8864680b583eb R12: 00005580ff10086f
      [    2.613080] R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000008000
      [    2.613080] FS:  00007f5c1da08940(0000) GS:ffff88003fc00000(0000) knlGS:0000000000000000
      [    2.613080] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
      [    2.613080] CR2: 0000000000000000 CR3: 0000000037002000 CR4: 00000000003406f0
      [    2.613080] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
      [    2.613080] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
      [    2.613080] Call Trace:
      [    2.613080]  ? shmem_mknod+0xbf/0xd0
      [    2.613080]  ima_post_path_mknod+0x1c/0x40
      [    2.613080]  SyS_mknod+0x210/0x220
      [    2.613080]  entry_SYSCALL_64_fastpath+0x1a/0xa5
      [    2.613080] RIP: 0033:0x7f5c1bfde570
      [    2.613080] RSP: 002b:00007ffde1c90dc8 EFLAGS: 00000246 ORIG_RAX: 0000000000000085
      [    2.613080] RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00007f5c1bfde570
      [    2.613080] RDX: 0000000000000000 RSI: 0000000000008000 RDI: 00005580ff10086f
      [    2.613080] RBP: 00007ffde1c91040 R08: 00005580ff10086f R09: 0000000000000000
      [    2.613080] R10: 0000000000104000 R11: 0000000000000246 R12: 00005580ffb99660
      [    2.613080] R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000002
      [    2.613080] Code: 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 41 57 41 56 44 8d 14 09 41 55 41 54 55 53 44 89 d3 09 cb 48 83 ec 38 48 8b 05 c5 03 29 01 <4c> 8b 20 4c 39 e0 0f 84 d7 01 00 00 4c 89 44 24 08 89 54 24 20
      [    2.613080] RIP: ima_match_policy+0x23/0x390 RSP: ffffc90000193e88
      [    2.613080] CR2: 0000000000000000
      [    2.613080] ---[ end trace 9a9f0a8a73079f6a ]---
      [    2.673052] Kernel panic - not syncing: Attempted to kill init! exitcode=0x00000009
      [    2.673052]
      [    2.675337] Kernel Offset: disabled
      [    2.676405] ---[ end Kernel panic - not syncing: Attempted to kill init! exitcode=0x00000009
      Signed-off-by: NPetr Vorel <pvorel@suse.cz>
      Signed-off-by: NMimi Zohar <zohar@linux.vnet.ibm.com>
      ab60368a
    • M
      ima: Add smackfs to the default appraise/measure list · 1c070b18
      Martin Townsend 提交于
      This is required to use SMACK and IMA/EVM together. Add it to the
      default nomeasure/noappraise list like other pseudo filesystems.
      Signed-off-by: NMartin Townsend <mtownsend1973@gmail.com>
      Acked-by: NCasey Schaufler <casey@schaufler-ca.com>
      Signed-off-by: NMimi Zohar <zohar@linux.vnet.ibm.com>
      1c070b18
    • S
      evm: check for remount ro in progress before writing · 70946c4a
      Sascha Hauer 提交于
      EVM might update the evm xattr while the VFS performs a remount to
      readonly mode. This is not properly checked for, additionally check
      the s_readonly_remount superblock flag before writing.
      
      The bug can for example be observed with UBIFS. UBIFS checks the free
      space on the device before and after a remount. With EVM enabled the
      free space sometimes differs between both checks.
      Signed-off-by: NSascha Hauer <s.hauer@pengutronix.de>
      Signed-off-by: NMimi Zohar <zohar@linux.vnet.ibm.com>
      70946c4a
    • T
      ima: Improvements in ima_appraise_measurement() · f5e51fa3
      Thiago Jung Bauermann 提交于
      Replace nested ifs in the EVM xattr verification logic with a switch
      statement, making the code easier to understand.
      
      Also, add comments to the if statements in the out section and constify the
      cause variable.
      Signed-off-by: NMimi Zohar <zohar@linux.vnet.ibm.com>
      Signed-off-by: NThiago Jung Bauermann <bauerman@linux.vnet.ibm.com>
      Acked-by: NSerge Hallyn <serge@hallyn.com>
      f5e51fa3
    • T
      ima: Simplify ima_eventsig_init() · 1775cb87
      Thiago Jung Bauermann 提交于
      The "goto out" statement doesn't have any purpose since there's no cleanup
      to be done when returning early, so remove it. This also makes the rc
      variable unnecessary so remove it as well.
      
      Also, the xattr_len and fmt variables are redundant so remove them as well.
      Signed-off-by: NThiago Jung Bauermann <bauerman@linux.vnet.ibm.com>
      Acked-by: NSerge Hallyn <serge@hallyn.com>
      Signed-off-by: NMimi Zohar <zohar@linux.vnet.ibm.com>
      1775cb87
    • T
      integrity: Remove unused macro IMA_ACTION_RULE_FLAGS · 11c60f23
      Thiago Jung Bauermann 提交于
      This macro isn't used anymore since commit 0d73a552 ("ima: re-introduce
      own integrity cache lock"), so remove it.
      Signed-off-by: NThiago Jung Bauermann <bauerman@linux.vnet.ibm.com>
      Acked-by: NSerge Hallyn <serge@hallyn.com>
      Signed-off-by: NMimi Zohar <zohar@linux.vnet.ibm.com>
      11c60f23
    • T
      ima: drop vla in ima_audit_measurement() · e456ef88
      Tycho Andersen 提交于
      In keeping with the directive to get rid of VLAs [1], let's drop the VLA
      from ima_audit_measurement(). We need to adjust the return type of
      ima_audit_measurement, because now this function can fail if an allocation
      fails.
      
      [1]: https://lkml.org/lkml/2018/3/7/621
      
      v2: just use audit_log_format instead of doing a second allocation
      v3: ignore failures in ima_audit_measurement()
      Signed-off-by: NTycho Andersen <tycho@tycho.ws>
      Signed-off-by: NMimi Zohar <zohar@linux.vnet.ibm.com>
      e456ef88
    • J
      ima: Fix Kconfig to select TPM 2.0 CRB interface · fac37c62
      Jiandi An 提交于
      TPM_CRB driver provides TPM CRB 2.0 support.  If it is built as a
      module, the TPM chip is registered after IMA init.  tpm_pcr_read() in
      IMA fails and displays the following message even though eventually
      there is a TPM chip on the system.
      
      ima: No TPM chip found, activating TPM-bypass! (rc=-19)
      
      Fix IMA Kconfig to select TPM_CRB so TPM_CRB driver is built in the kernel
      and initializes before IMA.
      Signed-off-by: NJiandi An <anjiandi@codeaurora.org>
      Signed-off-by: NMimi Zohar <zohar@linux.vnet.ibm.com>
      fac37c62
  2. 23 3月, 2018 7 次提交
  3. 23 2月, 2018 1 次提交
  4. 02 2月, 2018 1 次提交
  5. 01 2月, 2018 1 次提交
  6. 29 1月, 2018 1 次提交
  7. 19 1月, 2018 1 次提交
  8. 08 1月, 2018 1 次提交
  9. 18 12月, 2017 6 次提交
    • S
      ima: Use i_version only when filesystem supports it · a2a2c3c8
      Sascha Hauer 提交于
      i_version is only supported by a filesystem when the SB_I_VERSION
      flag is set. This patch tests for the SB_I_VERSION flag before using
      i_version. If we can't use i_version to detect a file change then we
      must assume the file has changed in the last_writer path and remeasure
      it.
      
      On filesystems without i_version support IMA used to measure a file
      only once and didn't detect any changes to a file. With this patch
      IMA now works properly on these filesystems.
      Signed-off-by: NSascha Hauer <s.hauer@pengutronix.de>
      Reviewed-by: NJeff Layton <jlayton@redhat.com>
      Signed-off-by: NMimi Zohar <zohar@linux.vnet.ibm.com>
      a2a2c3c8
    • J
      integrity: remove unneeded initializations in integrity_iint_cache entries · 02c324a5
      Jeff Layton 提交于
      The init_once routine memsets the whole object to 0, and then
      explicitly sets some of the fields to 0 again. Just remove the explicit
      initializations.
      Signed-off-by: NJeff Layton <jlayton@redhat.com>
      Signed-off-by: NMimi Zohar <zohar@linux.vnet.ibm.com>
      02c324a5
    • B
      ima: log message to module appraisal error · 9c655be0
      Bruno E. O. Meneguele 提交于
      Simple but useful message log to the user in case of module appraise is
      forced and fails due to the lack of file descriptor, that might be
      caused by kmod calls to compressed modules.
      Signed-off-by: NBruno E. O. Meneguele <brdeoliv@redhat.com>
      Signed-off-by: NMimi Zohar <zohar@linux.vnet.ibm.com>
      9c655be0
    • R
      ima: pass filename to ima_rdwr_violation_check() · 4e8581ee
      Roberto Sassu 提交于
      ima_rdwr_violation_check() retrieves the full path of a measured file by
      calling ima_d_path(). If process_measurement() calls this function, it
      reuses the pointer and passes it to the functions to measure/appraise/audit
      an accessed file.
      
      After commit bc15ed66 ("ima: fix ima_d_path() possible race with
      rename"), ima_d_path() first tries to retrieve the full path by calling
      d_absolute_path() and, if there is an error, copies the dentry name to the
      buffer passed as argument.
      
      However, ima_rdwr_violation_check() passes to ima_d_path() the pointer of a
      local variable. process_measurement() might be reusing the pointer to an
      area in the stack which may have been already overwritten after
      ima_rdwr_violation_check() returned.
      
      Correct this issue by passing to ima_rdwr_violation_check() the pointer of
      a buffer declared in process_measurement().
      
      Fixes: bc15ed66 ("ima: fix ima_d_path() possible race with rename")
      Signed-off-by: NRoberto Sassu <roberto.sassu@huawei.com>
      Signed-off-by: NMimi Zohar <zohar@linux.vnet.ibm.com>
      4e8581ee
    • J
      ima: Fix line continuation format · 72bf83b0
      Joe Perches 提交于
      Line continuations with excess spacing causes unexpected output.
      
      Based on commit 6f76b6fc ("CodingStyle: Document the exception of
      not splitting user-visible strings, for grepping") recommendation.
      Signed-off-by: NJoe Perches <joe@perches.com>
      Signed-off-by: NMimi Zohar <zohar@linux.vnet.ibm.com>
      72bf83b0
    • M
      ima: support new "hash" and "dont_hash" policy actions · da1b0029
      Mimi Zohar 提交于
      The builtin ima_appraise_tcb policy, which is specified on the boot
      command line, can be replaced with a custom policy, normally early in
      the boot process.  Custom policies can be more restrictive in some ways,
      like requiring file signatures, but can be less restrictive in other
      ways, like not appraising mutable files.  With a less restrictive policy
      in place, files in the builtin policy might not be hashed and labeled
      with a security.ima hash.  On reboot, files which should be labeled in
      the ima_appraise_tcb are not labeled, possibly preventing the system
      from booting properly.
      
      To resolve this problem, this patch extends the existing IMA policy
      actions "measure", "dont_measure", "appraise", "dont_appraise", and
      "audit" with "hash" and "dont_hash".  The new "hash" action will write
      the file hash as security.ima, but without requiring the file to be
      appraised as well.
      
      For example, the builtin ima_appraise_tcb policy includes the rule,
      "appraise fowner=0".  Adding the "hash fowner=0" rule to a custom
      policy, will cause the needed file hashes to be calculated and written
      as security.ima xattrs.
      Signed-off-by: NMimi Zohar <zohar@linux.vnet.ibm.com>
      Signed-off-by: NStefan Berger <stefanb@linux.vnet.ibm.com>
      da1b0029
  10. 13 12月, 2017 1 次提交
  11. 12 12月, 2017 4 次提交
    • D
      ima: re-introduce own integrity cache lock · 0d73a552
      Dmitry Kasatkin 提交于
      Before IMA appraisal was introduced, IMA was using own integrity cache
      lock along with i_mutex. process_measurement and ima_file_free took
      the iint->mutex first and then the i_mutex, while setxattr, chmod and
      chown took the locks in reverse order. To resolve the potential deadlock,
      i_mutex was moved to protect entire IMA functionality and the redundant
      iint->mutex was eliminated.
      
      Solution was based on the assumption that filesystem code does not take
      i_mutex further. But when file is opened with O_DIRECT flag, direct-io
      implementation takes i_mutex and produces deadlock. Furthermore, certain
      other filesystem operations, such as llseek, also take i_mutex.
      
      More recently some filesystems have replaced their filesystem specific
      lock with the global i_rwsem to read a file.  As a result, when IMA
      attempts to calculate the file hash, reading the file attempts to take
      the i_rwsem again.
      
      To resolve O_DIRECT related deadlock problem, this patch re-introduces
      iint->mutex. But to eliminate the original chmod() related deadlock
      problem, this patch eliminates the requirement for chmod hooks to take
      the iint->mutex by introducing additional atomic iint->attr_flags to
      indicate calling of the hooks. The allowed locking order is to take
      the iint->mutex first and then the i_rwsem.
      
      Original flags were cleared in chmod(), setxattr() or removwxattr()
      hooks and tested when file was closed or opened again. New atomic flags
      are set or cleared in those hooks and tested to clear iint->flags on
      close or on open.
      
      Atomic flags are following:
      * IMA_CHANGE_ATTR - indicates that chATTR() was called (chmod, chown,
        chgrp) and file attributes have changed. On file open, it causes IMA
        to clear iint->flags to re-evaluate policy and perform IMA functions
        again.
      * IMA_CHANGE_XATTR - indicates that setxattr or removexattr was called
        and extended attributes have changed. On file open, it causes IMA to
        clear iint->flags IMA_DONE_MASK to re-appraise.
      * IMA_UPDATE_XATTR - indicates that security.ima needs to be updated.
        It is cleared if file policy changes and no update is needed.
      * IMA_DIGSIG - indicates that file security.ima has signature and file
        security.ima must not update to file has on file close.
      * IMA_MUST_MEASURE - indicates the file is in the measurement policy.
      
      Fixes: Commit 65523218 ("xfs: remove i_iolock and use i_rwsem in
      the VFS inode instead")
      Signed-off-by: NDmitry Kasatkin <dmitry.kasatkin@huawei.com>
      Signed-off-by: NMimi Zohar <zohar@linux.vnet.ibm.com>
      0d73a552
    • M
      EVM: Add support for portable signature format · 50b97748
      Matthew Garrett 提交于
      The EVM signature includes the inode number and (optionally) the
      filesystem UUID, making it impractical to ship EVM signatures in
      packages. This patch adds a new portable format intended to allow
      distributions to include EVM signatures. It is identical to the existing
      format but hardcodes the inode and generation numbers to 0 and does not
      include the filesystem UUID even if the kernel is configured to do so.
      
      Removing the inode means that the metadata and signature from one file
      could be copied to another file without invalidating it. This is avoided
      by ensuring that an IMA xattr is present during EVM validation.
      
      Portable signatures are intended to be immutable - ie, they will never
      be transformed into HMACs.
      
      Based on earlier work by Dmitry Kasatkin and Mikhail Kurinnoi.
      Signed-off-by: NMatthew Garrett <mjg59@google.com>
      Cc: Dmitry Kasatkin <dmitry.kasatkin@huawei.com>
      Cc: Mikhail Kurinnoi <viewizard@viewizard.com>
      Signed-off-by: NMimi Zohar <zohar@linux.vnet.ibm.com>
      50b97748
    • M
      EVM: Allow userland to permit modification of EVM-protected metadata · ae1ba167
      Matthew Garrett 提交于
      When EVM is enabled it forbids modification of metadata protected by
      EVM unless there is already a valid EVM signature. If any modification
      is made, the kernel will then generate a new EVM HMAC. However, this
      does not map well on use cases which use only asymmetric EVM signatures,
      as in this scenario the kernel is unable to generate new signatures.
      
      This patch extends the /sys/kernel/security/evm interface to allow
      userland to request that modification of these xattrs be permitted. This
      is only permitted if no keys have already been loaded. In this
      configuration, modifying the metadata will invalidate the EVM appraisal
      on the file in question. This allows packaging systems to write out new
      files, set the relevant extended attributes and then move them into
      place.
      
      There's also some refactoring of the use of evm_initialized in order to
      avoid heading down codepaths that assume there's a key available.
      Signed-off-by: NMatthew Garrett <mjg59@google.com>
      Signed-off-by: NMimi Zohar <zohar@linux.vnet.ibm.com>
      ae1ba167
    • M
      ima: relax requiring a file signature for new files with zero length · b7e27bc1
      Mimi Zohar 提交于
      Custom policies can require file signatures based on LSM labels.  These
      files are normally created and only afterwards labeled, requiring them
      to be signed.
      
      Instead of requiring file signatures based on LSM labels, entire
      filesystems could require file signatures.  In this case, we need the
      ability of writing new files without requiring file signatures.
      
      The definition of a "new" file was originally defined as any file with
      a length of zero.  Subsequent patches redefined a "new" file to be based
      on the FILE_CREATE open flag.  By combining the open flag with a file
      size of zero, this patch relaxes the file signature requirement.
      
      Fixes: 1ac202e9 ima: accept previously set IMA_NEW_FILE
      Signed-off-by: NMimi Zohar <zohar@linux.vnet.ibm.com>
      b7e27bc1
  12. 20 11月, 2017 1 次提交
    • R
      ima: do not update security.ima if appraisal status is not INTEGRITY_PASS · 020aae3e
      Roberto Sassu 提交于
      Commit b65a9cfc ("Untangling ima mess, part 2: deal with counters")
      moved the call of ima_file_check() from may_open() to do_filp_open() at a
      point where the file descriptor is already opened.
      
      This breaks the assumption made by IMA that file descriptors being closed
      belong to files whose access was granted by ima_file_check(). The
      consequence is that security.ima and security.evm are updated with good
      values, regardless of the current appraisal status.
      
      For example, if a file does not have security.ima, IMA will create it after
      opening the file for writing, even if access is denied. Access to the file
      will be allowed afterwards.
      
      Avoid this issue by checking the appraisal status before updating
      security.ima.
      
      Cc: stable@vger.kernel.org
      Signed-off-by: NRoberto Sassu <roberto.sassu@huawei.com>
      Signed-off-by: NMimi Zohar <zohar@linux.vnet.ibm.com>
      Signed-off-by: NJames Morris <james.l.morris@oracle.com>
      020aae3e
  13. 09 11月, 2017 7 次提交