Skip to content
Snippets Groups Projects
  1. Jan 03, 2025
  2. Dec 24, 2024
    • Breno Leitao's avatar
      ima: kexec: silence RCU list traversal warning · 68af44a7
      Breno Leitao authored
      
      The ima_measurements list is append-only and doesn't require
      rcu_read_lock() protection. However, lockdep issues a warning when
      traversing RCU lists without the read lock:
      
        security/integrity/ima/ima_kexec.c:40 RCU-list traversed in non-reader section!!
      
      Fix this by using the variant of list_for_each_entry_rcu() with the last
      argument set to true. This tells the RCU subsystem that traversing this
      append-only list without the read lock is intentional and safe.
      
      This change silences the lockdep warning while maintaining the correct
      semantics for the append-only list traversal.
      
      Signed-off-by: default avatarBreno Leitao <leitao@debian.org>
      Signed-off-by: default avatarMimi Zohar <zohar@linux.ibm.com>
      68af44a7
  3. Dec 11, 2024
    • Stefan Berger's avatar
      ima: Suspend PCR extends and log appends when rebooting · 254ef954
      Stefan Berger authored
      
      To avoid the following types of error messages due to a failure by the TPM
      driver to use the TPM, suspend TPM PCR extensions and the appending of
      entries to the IMA log once IMA's reboot notifier has been called. This
      avoids trying to use the TPM after the TPM subsystem has been shut down.
      
      [111707.685315][    T1] ima: Error Communicating to TPM chip, result: -19
      [111707.685960][    T1] ima: Error Communicating to TPM chip, result: -19
      
      Synchronization with the ima_extend_list_mutex to set
      ima_measurements_suspended ensures that the TPM subsystem is not shut down
      when IMA holds the mutex while appending to the log and extending the PCR.
      The alternative of reading the system_state variable would not provide this
      guarantee.
      
      This error could be observed on a ppc64 machine running SuSE Linux where
      processes are still accessing files after devices have been shut down.
      
      Suspending the IMA log and PCR extensions shortly before reboot does not
      seem to open a significant measurement gap since neither TPM quoting would
      work for attestation nor that new log entries could be written to anywhere
      after devices have been shut down. However, there's a time window between
      the invocation of the reboot notifier and the shutdown of devices. This
      includes all subsequently invoked reboot notifiers as well as
      kernel_restart_prepare() where __usermodehelper_disable() waits for all
      running_helpers to exit. During this time window IMA could now miss log
      entries even though attestation would still work. The reboot of the system
      shortly after may make this small gap insignificant.
      
      Signed-off-by: default avatarTushar Sugandhi <tusharsu@linux.microsoft.com>
      Signed-off-by: default avatarStefan Berger <stefanb@linux.ibm.com>
      Reviewed-by: default avatarJarkko Sakkinen <jarkko@kernel.org>
      Signed-off-by: default avatarMimi Zohar <zohar@linux.ibm.com>
      254ef954
  4. Nov 27, 2024
  5. Nov 03, 2024
  6. Oct 11, 2024
    • Casey Schaufler's avatar
      lsm: create new security_cred_getlsmprop LSM hook · b0654ca4
      Casey Schaufler authored
      
      Create a new LSM hook security_cred_getlsmprop() which, like
      security_cred_getsecid(), fetches LSM specific attributes from the
      cred structure.  The associated data elements in the audit sub-system
      are changed from a secid to a lsm_prop to accommodate multiple possible
      LSM audit users.
      
      Cc: linux-integrity@vger.kernel.org
      Cc: audit@vger.kernel.org
      Cc: selinux@vger.kernel.org
      Signed-off-by: default avatarCasey Schaufler <casey@schaufler-ca.com>
      [PM: subj line tweak]
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      b0654ca4
    • Casey Schaufler's avatar
      lsm: use lsm_prop in security_inode_getsecid · 07f9d2c1
      Casey Schaufler authored
      
      Change the security_inode_getsecid() interface to fill in a
      lsm_prop structure instead of a u32 secid. This allows for its
      callers to gather data from all registered LSMs. Data is provided
      for IMA and audit. Change the name to security_inode_getlsmprop().
      
      Cc: linux-integrity@vger.kernel.org
      Cc: selinux@vger.kernel.org
      Signed-off-by: default avatarCasey Schaufler <casey@schaufler-ca.com>
      [PM: subj line tweak]
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      07f9d2c1
    • Casey Schaufler's avatar
      lsm: use lsm_prop in security_current_getsecid · 37f670aa
      Casey Schaufler authored
      
      Change the security_current_getsecid_subj() and
      security_task_getsecid_obj() interfaces to fill in a lsm_prop structure
      instead of a u32 secid.  Audit interfaces will need to collect all
      possible security data for possible reporting.
      
      Cc: linux-integrity@vger.kernel.org
      Cc: audit@vger.kernel.org
      Cc: selinux@vger.kernel.org
      Signed-off-by: default avatarCasey Schaufler <casey@schaufler-ca.com>
      [PM: subject line tweak]
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      37f670aa
    • Casey Schaufler's avatar
      lsm: use lsm_prop in security_audit_rule_match · 870b7fdc
      Casey Schaufler authored
      
      Change the secid parameter of security_audit_rule_match
      to a lsm_prop structure pointer. Pass the entry from the
      lsm_prop structure for the approprite slot to the LSM hook.
      
      Change the users of security_audit_rule_match to use the
      lsm_prop instead of a u32. The scaffolding function lsmprop_init()
      fills the structure with the value of the old secid, ensuring that
      it is available to the appropriate module hook. The sources of
      the secid, security_task_getsecid() and security_inode_getsecid(),
      will be converted to use the lsm_prop structure later in the series.
      At that point the use of lsmprop_init() is dropped.
      
      Signed-off-by: default avatarCasey Schaufler <casey@schaufler-ca.com>
      [PM: subject line tweak]
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      870b7fdc
  7. Oct 10, 2024
  8. Oct 05, 2024
    • Lukas Wunner's avatar
      crypto: rsassa-pkcs1 - Migrate to sig_alg backend · 1e562dea
      Lukas Wunner authored
      
      A sig_alg backend has just been introduced with the intent of moving all
      asymmetric sign/verify algorithms to it one by one.
      
      Migrate the sign/verify operations from rsa-pkcs1pad.c to a separate
      rsassa-pkcs1.c which uses the new backend.
      
      Consequently there are now two templates which build on the "rsa"
      akcipher_alg:
      
      * The existing "pkcs1pad" template, which is instantiated as an
        akcipher_instance and retains the encrypt/decrypt operations of
        RSAES-PKCS1-v1_5 (RFC 8017 sec 7.2).
      
      * The new "pkcs1" template, which is instantiated as a sig_instance
        and contains the sign/verify operations of RSASSA-PKCS1-v1_5
        (RFC 8017 sec 8.2).
      
      In a separate step, rsa-pkcs1pad.c could optionally be renamed to
      rsaes-pkcs1.c for clarity.  Additional "oaep" and "pss" templates
      could be added for RSAES-OAEP and RSASSA-PSS.
      
      Note that it's currently allowed to allocate a "pkcs1pad(rsa)" transform
      without specifying a hash algorithm.  That makes sense if the transform
      is only used for encrypt/decrypt and continues to be supported.  But for
      sign/verify, such transforms previously did not insert the Full Hash
      Prefix into the padding.  The resulting message encoding was incompliant
      with EMSA-PKCS1-v1_5 (RFC 8017 sec 9.2) and therefore nonsensical.
      
      From here on in, it is no longer allowed to allocate a transform without
      specifying a hash algorithm if the transform is used for sign/verify
      operations.  This simplifies the code because the insertion of the Full
      Hash Prefix is no longer optional, so various "if (digest_info)" clauses
      can be removed.
      
      There has been a previous attempt to forbid transform allocation without
      specifying a hash algorithm, namely by commit c0d20d22 ("crypto:
      rsa-pkcs1pad - Require hash to be present").  It had to be rolled back
      with commit b3a8c8a5 ("crypto: rsa-pkcs1pad: Allow hash to be
      optional [ver #2]"), presumably because it broke allocation of a
      transform which was solely used for encrypt/decrypt, not sign/verify.
      Avoid such breakage by allowing transform allocation for encrypt/decrypt
      with and without specifying a hash algorithm (and simply ignoring the
      hash algorithm in the former case).
      
      So again, specifying a hash algorithm is now mandatory for sign/verify,
      but optional and ignored for encrypt/decrypt.
      
      The new sig_alg API uses kernel buffers instead of sglists, which
      avoids the overhead of copying signature and digest from sglists back
      into kernel buffers.  rsassa-pkcs1.c is thus simplified quite a bit.
      
      sig_alg is always synchronous, whereas the underlying "rsa" akcipher_alg
      may be asynchronous.  So await the result of the akcipher_alg, similar
      to crypto_akcipher_sync_{en,de}crypt().
      
      As part of the migration, rename "rsa_digest_info" to "hash_prefix" to
      adhere to the spec language in RFC 9580.  Otherwise keep the code
      unmodified wherever possible to ease reviewing and bisecting.  Leave
      several simplification and hardening opportunities to separate commits.
      
      rsassa-pkcs1.c uses modern __free() syntax for allocation of buffers
      which need to be freed by kfree_sensitive(), hence a DEFINE_FREE()
      clause for kfree_sensitive() is introduced herein as a byproduct.
      
      Signed-off-by: default avatarLukas Wunner <lukas@wunner.de>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      1e562dea
  9. Aug 13, 2024
    • Al Viro's avatar
      introduce fd_file(), convert all accessors to it. · 1da91ea8
      Al Viro authored
      
      	For any changes of struct fd representation we need to
      turn existing accesses to fields into calls of wrappers.
      Accesses to struct fd::flags are very few (3 in linux/file.h,
      1 in net/socket.c, 3 in fs/overlayfs/file.c and 3 more in
      explicit initializers).
      	Those can be dealt with in the commit converting to
      new layout; accesses to struct fd::file are too many for that.
      	This commit converts (almost) all of f.file to
      fd_file(f).  It's not entirely mechanical ('file' is used as
      a member name more than just in struct fd) and it does not
      even attempt to distinguish the uses in pointer context from
      those in boolean context; the latter will be eventually turned
      into a separate helper (fd_empty()).
      
      	NOTE: mass conversion to fd_empty(), tempting as it
      might be, is a bad idea; better do that piecewise in commit
      that convert from fdget...() to CLASS(...).
      
      [conflicts in fs/fhandle.c, kernel/bpf/syscall.c, mm/memcontrol.c
      caught by git; fs/stat.c one got caught by git grep]
      [fs/xattr.c conflict]
      
      Reviewed-by: default avatarChristian Brauner <brauner@kernel.org>
      Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
      1da91ea8
  10. Aug 12, 2024
  11. Jul 31, 2024
  12. Jun 13, 2024
    • GUO Zihua's avatar
      ima: Avoid blocking in RCU read-side critical section · 9a95c5bf
      GUO Zihua authored
      
      A panic happens in ima_match_policy:
      
      BUG: unable to handle kernel NULL pointer dereference at 0000000000000010
      PGD 42f873067 P4D 0
      Oops: 0000 [#1] SMP NOPTI
      CPU: 5 PID: 1286325 Comm: kubeletmonit.sh
      Kdump: loaded Tainted: P
      Hardware name: QEMU Standard PC (i440FX + PIIX, 1996),
                     BIOS 0.0.0 02/06/2015
      RIP: 0010:ima_match_policy+0x84/0x450
      Code: 49 89 fc 41 89 cf 31 ed 89 44 24 14 eb 1c 44 39
            7b 18 74 26 41 83 ff 05 74 20 48 8b 1b 48 3b 1d
            f2 b9 f4 00 0f 84 9c 01 00 00 <44> 85 73 10 74 ea
            44 8b 6b 14 41 f6 c5 01 75 d4 41 f6 c5 02 74 0f
      RSP: 0018:ff71570009e07a80 EFLAGS: 00010207
      RAX: 0000000000000000 RBX: 0000000000000000 RCX: 0000000000000200
      RDX: ffffffffad8dc7c0 RSI: 0000000024924925 RDI: ff3e27850dea2000
      RBP: 0000000000000000 R08: 0000000000000000 R09: ffffffffabfce739
      R10: ff3e27810cc42400 R11: 0000000000000000 R12: ff3e2781825ef970
      R13: 00000000ff3e2785 R14: 000000000000000c R15: 0000000000000001
      FS:  00007f5195b51740(0000)
      GS:ff3e278b12d40000(0000) knlGS:0000000000000000
      CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
      CR2: 0000000000000010 CR3: 0000000626d24002 CR4: 0000000000361ee0
      DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
      DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
      Call Trace:
       ima_get_action+0x22/0x30
       process_measurement+0xb0/0x830
       ? page_add_file_rmap+0x15/0x170
       ? alloc_set_pte+0x269/0x4c0
       ? prep_new_page+0x81/0x140
       ? simple_xattr_get+0x75/0xa0
       ? selinux_file_open+0x9d/0xf0
       ima_file_check+0x64/0x90
       path_openat+0x571/0x1720
       do_filp_open+0x9b/0x110
       ? page_counter_try_charge+0x57/0xc0
       ? files_cgroup_alloc_fd+0x38/0x60
       ? __alloc_fd+0xd4/0x250
       ? do_sys_open+0x1bd/0x250
       do_sys_open+0x1bd/0x250
       do_syscall_64+0x5d/0x1d0
       entry_SYSCALL_64_after_hwframe+0x65/0xca
      
      Commit c7423dbd ("ima: Handle -ESTALE returned by
      ima_filter_rule_match()") introduced call to ima_lsm_copy_rule within a
      RCU read-side critical section which contains kmalloc with GFP_KERNEL.
      This implies a possible sleep and violates limitations of RCU read-side
      critical sections on non-PREEMPT systems.
      
      Sleeping within RCU read-side critical section might cause
      synchronize_rcu() returning early and break RCU protection, allowing a
      UAF to happen.
      
      The root cause of this issue could be described as follows:
      |	Thread A	|	Thread B	|
      |			|ima_match_policy	|
      |			|  rcu_read_lock	|
      |ima_lsm_update_rule	|			|
      |  synchronize_rcu	|			|
      |			|    kmalloc(GFP_KERNEL)|
      |			|      sleep		|
      ==> synchronize_rcu returns early
      |  kfree(entry)		|			|
      |			|    entry = entry->next|
      ==> UAF happens and entry now becomes NULL (or could be anything).
      |			|    entry->action	|
      ==> Accessing entry might cause panic.
      
      To fix this issue, we are converting all kmalloc that is called within
      RCU read-side critical section to use GFP_ATOMIC.
      
      Fixes: c7423dbd ("ima: Handle -ESTALE returned by ima_filter_rule_match()")
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarGUO Zihua <guozihua@huawei.com>
      Acked-by: default avatarJohn Johansen <john.johansen@canonical.com>
      Reviewed-by: default avatarMimi Zohar <zohar@linux.ibm.com>
      Reviewed-by: default avatarCasey Schaufler <casey@schaufler-ca.com>
      [PM: fixed missing comment, long lines, !CONFIG_IMA_LSM_RULES case]
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      9a95c5bf
  13. Jun 07, 2024
    • Herbert Xu's avatar
      crypto: sm2 - Remove sm2 algorithm · 46b3ff73
      Herbert Xu authored
      
      The SM2 algorithm has a single user in the kernel.  However, it's
      never been integrated properly with that user: asymmetric_keys.
      
      The crux of the issue is that the way it computes its digest with
      sm3 does not fit into the architecture of asymmetric_keys.  As no
      solution has been proposed, remove this algorithm.
      
      It can be resubmitted when it is integrated properly into the
      asymmetric_keys subsystem.
      
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      46b3ff73
  14. Jun 03, 2024
    • Enrico Bravi's avatar
      ima: fix wrong zero-assignment during securityfs dentry remove · fbf06cee
      Enrico Bravi authored
      
      In case of error during ima_fs_init() all the dentry already created
      are removed. {ascii, binary}_securityfs_measurement_lists are freed
      calling for each array the remove_securityfs_measurement_lists(). This
      function, at the end, assigns to zero the securityfs_measurement_list_count.
      This causes during the second call of remove_securityfs_measurement_lists()
      to leave the dentry of the array pending, not removing them correctly,
      because the securityfs_measurement_list_count is already zero.
      
      Move the securityfs_measurement_list_count = 0 after the two
      remove_securityfs_measurement_lists() calls to correctly remove all the
      dentry already allocated.
      
      Fixes: 9fa8e762 ("ima: add crypto agility support for template-hash algorithm")
      Signed-off-by: default avatarEnrico Bravi <enrico.bravi@polito.it>
      Reviewed-by: default avatarRoberto Sassu <roberto.sassu@huawei.com>
      Signed-off-by: default avatarMimi Zohar <zohar@linux.ibm.com>
      fbf06cee
  15. Apr 12, 2024
    • Enrico Bravi's avatar
      ima: add crypto agility support for template-hash algorithm · 9fa8e762
      Enrico Bravi authored
      
      The template hash showed by the ascii_runtime_measurements and
      binary_runtime_measurements is the one calculated using sha1 and there is
      no possibility to change this value, despite the fact that the template
      hash is calculated using the hash algorithms corresponding to all the PCR
      banks configured in the TPM.
      
      Add the support to retrieve the ima log with the template data hash
      calculated with a specific hash algorithm.
      Add a new file in the securityfs ima directory for each hash algo
      configured in a PCR bank of the TPM. Each new file has the name with
      the following structure:
      
              {binary, ascii}_runtime_measurements_<hash_algo_name>
      
      Legacy files are kept, to avoid breaking existing applications, but as
      symbolic links which point to {binary, ascii}_runtime_measurements_sha1
      files. These two files are created even if a TPM chip is not detected or
      the sha1 bank is not configured in the TPM.
      
      As example, in the case a TPM chip is present and sha256 is the only
      configured PCR bank, the listing of the securityfs ima directory is the
      following:
      
      lr--r--r-- [...] ascii_runtime_measurements -> ascii_runtime_measurements_sha1
      -r--r----- [...] ascii_runtime_measurements_sha1
      -r--r----- [...] ascii_runtime_measurements_sha256
      lr--r--r-- [...] binary_runtime_measurements -> binary_runtime_measurements_sha1
      -r--r----- [...] binary_runtime_measurements_sha1
      -r--r----- [...] binary_runtime_measurements_sha256
      --w------- [...] policy
      -r--r----- [...] runtime_measurements_count
      -r--r----- [...] violations
      
      Signed-off-by: default avatarEnrico Bravi <enrico.bravi@polito.it>
      Signed-off-by: default avatarSilvia Sisinni <silvia.sisinni@polito.it>
      Reviewed-by: default avatarRoberto Sassu <roberto.sassu@huawei.com>
      Signed-off-by: default avatarMimi Zohar <zohar@linux.ibm.com>
      9fa8e762
  16. Apr 09, 2024
  17. Apr 08, 2024
    • Gustavo A. R. Silva's avatar
      integrity: Avoid -Wflex-array-member-not-at-end warnings · 38aa3f5a
      Gustavo A. R. Silva authored
      -Wflex-array-member-not-at-end is coming in GCC-14, and we are getting
      ready to enable it globally.
      
      There is currently an object (`hdr)` in `struct ima_max_digest_data`
      that contains a flexible structure (`struct ima_digest_data`):
      
       struct ima_max_digest_data {
              struct ima_digest_data hdr;
              u8 digest[HASH_MAX_DIGESTSIZE];
       } __packed;
      
      So, in order to avoid ending up with a flexible-array member in the
      middle of a struct, we use the `__struct_group()` helper to separate
      the flexible array from the rest of the members in the flexible
      structure:
      
      struct ima_digest_data {
              __struct_group(ima_digest_data_hdr, hdr, __packed,
      
              ... the rest of the members
      
              );
              u8 digest[];
      } __packed;
      
      And similarly for `struct evm_ima_xattr_data`.
      
      With the change described above, we can now declare an object of the
      type of the tagged `struct ima_digest_data_hdr`, without embedding the
      flexible array in the middle of another struct:
      
       struct ima_max_digest_data {
              struct ima_digest_data_hdr hdr;
              u8 digest[HASH_MAX_DIGESTSIZE];
       } __packed;
      
      And similarly for `struct evm_digest` and `struct evm_xattr`.
      
      We also use `container_of()` whenever we need to retrieve a pointer to
      the flexible structure.
      
      So, with these changes, fix the following warnings:
      
      security/integrity/evm/evm.h:64:32: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
      security/integrity/evm/../integrity.h:40:35: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
      security/integrity/evm/../integrity.h:68:32: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
      security/integrity/ima/../integrity.h:40:35: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
      security/integrity/ima/../integrity.h:68:32: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
      security/integrity/integrity.h:40:35: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
      security/integrity/integrity.h:68:32: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
      security/integrity/platform_certs/../integrity.h:40:35: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
      security/integrity/platform_certs/../integrity.h:68:32: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
      
      Link: https://github.com/KSPP/linux/issues/202
      
      
      Signed-off-by: default avatarGustavo A. R. Silva <gustavoars@kernel.org>
      Signed-off-by: default avatarMimi Zohar <zohar@linux.ibm.com>
      38aa3f5a
    • Mimi Zohar's avatar
      ima: define an init_module critical data record · cc293c84
      Mimi Zohar authored
      
      The init_module syscall loads an ELF image into kernel space without
      measuring the buffer containing the ELF image.  To close this kernel
      module integrity gap, define a new critical-data record which includes
      the hash of the ELF image.
      
      Instead of including the buffer data in the IMA measurement list,
      include the hash of the buffer data to avoid large IMA measurement
      list records.  The buffer data hash would be the same value as the
      finit_module syscall file hash.
      
      To enable measuring the init_module buffer and other critical data from
      boot, define "ima_policy=critical_data" on the boot command line.  Since
      builtin policies are not persistent, a custom IMA policy must include
      the rule as well: measure func=CRITICAL_DATA label=modules
      
      To verify the template data hash value, first convert the buffer data
      hash to binary:
      grep "init_module" \
      	/sys/kernel/security/integrity/ima/ascii_runtime_measurements | \
      	tail -1 | cut -d' ' -f 6 | xxd -r -p | sha256sum
      
      Reported-by: default avatarKen Goldman <kgold@linux.ibm.com>
      Reviewed-by: default avatarJarkko Sakkinen <jarkko@kernel.org>
      Signed-off-by: default avatarMimi Zohar <zohar@linux.ibm.com>
      cc293c84
    • Stefan Berger's avatar
      ima: Fix use-after-free on a dentry's dname.name · be84f32b
      Stefan Berger authored
      ->d_name.name can change on rename and the earlier value can be freed;
      there are conditions sufficient to stabilize it (->d_lock on dentry,
      ->d_lock on its parent, ->i_rwsem exclusive on the parent's inode,
      rename_lock), but none of those are met at any of the sites. Take a stable
      snapshot of the name instead.
      
      Link: https://lore.kernel.org/all/20240202182732.GE2087318@ZenIV/
      
      
      Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
      Signed-off-by: default avatarStefan Berger <stefanb@linux.ibm.com>
      Signed-off-by: default avatarMimi Zohar <zohar@linux.ibm.com>
      be84f32b
  18. Feb 16, 2024
    • Coiby Xu's avatar
      integrity: eliminate unnecessary "Problem loading X.509 certificate" msg · 85445b96
      Coiby Xu authored
      
      Currently when the kernel fails to add a cert to the .machine keyring,
      it will throw an error immediately in the function integrity_add_key.
      
      Since the kernel will try adding to the .platform keyring next or throw
      an error (in the caller of integrity_add_key i.e. add_to_machine_keyring),
      so there is no need to throw an error immediately in integrity_add_key.
      
      Reported-by: default avatar <itrymybest80@protonmail.com>
      Closes: https://bugzilla.redhat.com/show_bug.cgi?id=2239331
      
      
      Fixes: d1996776 ("integrity: Introduce a Linux keyring called machine")
      Reviewed-by: default avatarEric Snowberg <eric.snowberg@oracle.com>
      Signed-off-by: default avatarCoiby Xu <coxu@redhat.com>
      Signed-off-by: default avatarMimi Zohar <zohar@linux.ibm.com>
      85445b96
    • Roberto Sassu's avatar
      integrity: Remove LSM · b6c0dec9
      Roberto Sassu authored
      
      Since now IMA and EVM use their own integrity metadata, it is safe to
      remove the 'integrity' LSM, with its management of integrity metadata.
      
      Keep the iint.c file only for loading IMA and EVM keys at boot, and for
      creating the integrity directory in securityfs (we need to keep it for
      retrocompatibility reasons).
      
      Signed-off-by: default avatarRoberto Sassu <roberto.sassu@huawei.com>
      Reviewed-by: default avatarCasey Schaufler <casey@schaufler-ca.com>
      Reviewed-by: default avatarStefan Berger <stefanb@linux.ibm.com>
      Reviewed-by: default avatarMimi Zohar <zohar@linux.ibm.com>
      Acked-by: default avatarMimi Zohar <zohar@linux.ibm.com>
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      b6c0dec9
    • Roberto Sassu's avatar
      ima: Make it independent from 'integrity' LSM · 4de2f084
      Roberto Sassu authored
      
      Make the 'ima' LSM independent from the 'integrity' LSM by introducing IMA
      own integrity metadata (ima_iint_cache structure, with IMA-specific fields
      from the integrity_iint_cache structure), and by managing it directly from
      the 'ima' LSM.
      
      Create ima_iint.c and introduce the same integrity metadata management
      functions found in iint.c (renamed with ima_). However, instead of putting
      metadata in an rbtree, reserve space from IMA in the inode security blob
      for a pointer, and introduce the ima_inode_set_iint()/ima_inode_get_iint()
      primitives to store/retrieve that pointer. This improves search time from
      logarithmic to constant.
      
      Consequently, don't include the inode pointer as field in the
      ima_iint_cache structure, since the association with the inode is clear.
      Since the inode field is missing in ima_iint_cache, pass the extra inode
      parameter to ima_get_verity_digest().
      
      Prefer storing the pointer instead of the entire ima_iint_cache structure,
      to avoid too much memory pressure. Use the same mechanism as before, a
      cache named ima_iint_cache (renamed from iint_cache), to quickly allocate
      a new ima_iint_cache structure when requested by the IMA policy.
      
      Create the new ima_iint_cache in ima_iintcache_init(),
      called by init_ima_lsm(), during the initialization of the 'ima' LSM. And,
      register ima_inode_free_security() to free the ima_iint_cache structure, if
      exists.
      
      Replace integrity_iint_cache with ima_iint_cache in various places of the
      IMA code. Also, replace integrity_inode_get() and integrity_iint_find(),
      respectively with ima_inode_get() and ima_iint_find().
      
      Finally, move the remaining IMA-specific flags
      to security/integrity/ima/ima.h, since they are now unnecessary in the
      common integrity layer.
      
      Signed-off-by: default avatarRoberto Sassu <roberto.sassu@huawei.com>
      Reviewed-by: default avatarCasey Schaufler <casey@schaufler-ca.com>
      Reviewed-by: default avatarStefan Berger <stefanb@linux.ibm.com>
      Reviewed-by: default avatarMimi Zohar <zohar@linux.ibm.com>
      Acked-by: default avatarMimi Zohar <zohar@linux.ibm.com>
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      4de2f084
    • Roberto Sassu's avatar
      evm: Make it independent from 'integrity' LSM · 75a323e6
      Roberto Sassu authored
      
      Define a new structure for EVM-specific metadata, called evm_iint_cache,
      and embed it in the inode security blob. Introduce evm_iint_inode() to
      retrieve metadata, and register evm_inode_alloc_security() for the
      inode_alloc_security LSM hook, to initialize the structure (before
      splitting metadata, this task was done by iint_init_always()).
      
      Keep the non-NULL checks after calling evm_iint_inode() except in
      evm_inode_alloc_security(), to take into account inodes for which
      security_inode_alloc() was not called. When using shared metadata,
      obtaining a NULL pointer from integrity_iint_find() meant that the file
      wasn't in the IMA policy. Now, because IMA and EVM use disjoint metadata,
      the EVM status has to be stored for every inode regardless of the IMA
      policy.
      
      Given that from now on EVM relies on its own metadata, remove the iint
      parameter from evm_verifyxattr(). Also, directly retrieve the iint in
      evm_verify_hmac(), called by both evm_verifyxattr() and
      evm_verify_current_integrity(), since now there is no performance penalty
      in retrieving EVM metadata (constant time).
      
      Replicate the management of the IMA_NEW_FILE flag, by introducing
      evm_post_path_mknod() and evm_file_release() to respectively set and clear
      the newly introduced flag EVM_NEW_FILE, at the same time IMA does. Like for
      IMA, select CONFIG_SECURITY_PATH when EVM is enabled, to ensure that files
      are marked as new.
      
      Unlike ima_post_path_mknod(), evm_post_path_mknod() cannot check if a file
      must be appraised. Thus, it marks all affected files. Also, it does not
      clear EVM_NEW_FILE depending on i_version, but that is not a problem
      because IMA_NEW_FILE is always cleared when set in ima_check_last_writer().
      
      Move the EVM-specific flag EVM_IMMUTABLE_DIGSIG to
      security/integrity/evm/evm.h, since that definition is now unnecessary in
      the common integrity layer.
      
      Finally, switch to the LSM reservation mechanism for the EVM xattr, and
      consequently decrement by one the number of xattrs to allocate in
      security_inode_init_security().
      
      Signed-off-by: default avatarRoberto Sassu <roberto.sassu@huawei.com>
      Reviewed-by: default avatarCasey Schaufler <casey@schaufler-ca.com>
      Reviewed-by: default avatarStefan Berger <stefanb@linux.ibm.com>
      Reviewed-by: default avatarMimi Zohar <zohar@linux.ibm.com>
      Acked-by: default avatarMimi Zohar <zohar@linux.ibm.com>
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      75a323e6
    • Roberto Sassu's avatar
      evm: Move to LSM infrastructure · 92383111
      Roberto Sassu authored
      
      As for IMA, move hardcoded EVM function calls from various places in the
      kernel to the LSM infrastructure, by introducing a new LSM named 'evm'
      (last and always enabled like 'ima'). The order in the Makefile ensures
      that 'evm' hooks are executed after 'ima' ones.
      
      Make EVM functions as static (except for evm_inode_init_security(), which
      is exported), and register them as hook implementations in init_evm_lsm().
      Also move the inline functions evm_inode_remove_acl(),
      evm_inode_post_remove_acl(), and evm_inode_post_set_acl() from the public
      evm.h header to evm_main.c.
      
      Unlike before (see commit to move IMA to the LSM infrastructure),
      evm_inode_post_setattr(), evm_inode_post_set_acl(),
      evm_inode_post_remove_acl(), and evm_inode_post_removexattr() are not
      executed for private inodes.
      
      Finally, add the LSM_ID_EVM case in lsm_list_modules_test.c
      
      Signed-off-by: default avatarRoberto Sassu <roberto.sassu@huawei.com>
      Reviewed-by: default avatarCasey Schaufler <casey@schaufler-ca.com>
      Acked-by: default avatarChristian Brauner <brauner@kernel.org>
      Reviewed-by: default avatarStefan Berger <stefanb@linux.ibm.com>
      Reviewed-by: default avatarMimi Zohar <zohar@linux.ibm.com>
      Acked-by: default avatarMimi Zohar <zohar@linux.ibm.com>
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      92383111
    • Roberto Sassu's avatar
      ima: Move IMA-Appraisal to LSM infrastructure · 84594c9e
      Roberto Sassu authored
      
      A few additional IMA hooks are needed to reset the cached appraisal
      status, causing the file's integrity to be re-evaluated on next access.
      Register these IMA-appraisal only functions separately from the rest of IMA
      functions, as appraisal is a separate feature not necessarily enabled in
      the kernel configuration.
      
      Reuse the same approach as for other IMA functions, move hardcoded calls
      from various places in the kernel to the LSM infrastructure. Declare the
      functions as static and register them as hook implementations in
      init_ima_appraise_lsm(), called by init_ima_lsm().
      
      Also move the inline function ima_inode_remove_acl() from the public ima.h
      header to ima_appraise.c.
      
      Signed-off-by: default avatarRoberto Sassu <roberto.sassu@huawei.com>
      Reviewed-by: default avatarStefan Berger <stefanb@linux.ibm.com>
      Reviewed-by: default avatarMimi Zohar <zohar@linux.ibm.com>
      Reviewed-by: default avatarCasey Schaufler <casey@schaufler-ca.com>
      Acked-by: default avatarChristian Brauner <brauner@kernel.org>
      Acked-by: default avatarMimi Zohar <zohar@linux.ibm.com>
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      84594c9e
Loading