1. 12 11月, 2019 2 次提交
    • N
      ima: Check against blacklisted hashes for files with modsig · 273df864
      Nayna Jain 提交于
      Asymmetric private keys are used to sign multiple files. The kernel
      currently supports checking against blacklisted keys. However, if the
      public key is blacklisted, any file signed by the blacklisted key will
      automatically fail signature verification. Blacklisting the public key
      is not fine enough granularity, as we might want to only blacklist a
      particular file.
      
      This patch adds support for checking against the blacklisted hash of
      the file, without the appended signature, based on the IMA policy. It
      defines a new policy option "appraise_flag=check_blacklist".
      
      In addition to the blacklisted binary hashes stored in the firmware
      "dbx" variable, the Linux kernel may be configured to load blacklisted
      binary hashes onto the .blacklist keyring as well. The following
      example shows how to blacklist a specific kernel module hash.
      
        $ sha256sum kernel/kheaders.ko
        77fa889b35a05338ec52e51591c1b89d4c8d1c99a21251d7c22b1a8642a6bad3
        kernel/kheaders.ko
      
        $ grep BLACKLIST .config
        CONFIG_SYSTEM_BLACKLIST_KEYRING=y
        CONFIG_SYSTEM_BLACKLIST_HASH_LIST="blacklist-hash-list"
      
        $ cat certs/blacklist-hash-list
        "bin:77fa889b35a05338ec52e51591c1b89d4c8d1c99a21251d7c22b1a8642a6bad3"
      
      Update the IMA custom measurement and appraisal policy
      rules (/etc/ima-policy):
      
        measure func=MODULE_CHECK template=ima-modsig
        appraise func=MODULE_CHECK appraise_flag=check_blacklist
        appraise_type=imasig|modsig
      
      After building, installing, and rebooting the kernel:
      
         545660333 ---lswrv      0     0   \_ blacklist:
        bin:77fa889b35a05338ec52e51591c1b89d4c8d1c99a21251d7c22b1a8642a6bad3
      
        measure func=MODULE_CHECK template=ima-modsig
        appraise func=MODULE_CHECK appraise_flag=check_blacklist
        appraise_type=imasig|modsig
      
        modprobe: ERROR: could not insert 'kheaders': Permission denied
      
        10 0c9834db5a0182c1fb0cdc5d3adcf11a11fd83dd ima-sig
        sha256:3bc6ed4f0b4d6e31bc1dbc9ef844605abc7afdc6d81a57d77a1ec9407997c40
        2 /usr/lib/modules/5.4.0-rc3+/kernel/kernel/kheaders.ko
      
        10 82aad2bcc3fa8ed94762356b5c14838f3bcfa6a0 ima-modsig
        sha256:3bc6ed4f0b4d6e31bc1dbc9ef844605abc7afdc6d81a57d77a1ec9407997c40
        2 /usr/lib/modules/5.4.0rc3+/kernel/kernel/kheaders.ko  sha256:77fa889b3
        5a05338ec52e51591c1b89d4c8d1c99a21251d7c22b1a8642a6bad3
        3082029a06092a864886f70d010702a082028b30820287020101310d300b0609608648
        016503040201300b06092a864886f70d01070131820264....
      
        10 25b72217cc1152b44b134ce2cd68f12dfb71acb3 ima-buf
        sha256:8b58427fedcf8f4b20bc8dc007f2e232bf7285d7b93a66476321f9c2a3aa132
        b blacklisted-hash
        77fa889b35a05338ec52e51591c1b89d4c8d1c99a21251d7c22b1a8642a6bad3
      Signed-off-by: NNayna Jain <nayna@linux.ibm.com>
      [zohar@linux.ibm.com: updated patch description]
      Signed-off-by: NMimi Zohar <zohar@linux.ibm.com>
      Signed-off-by: NMichael Ellerman <mpe@ellerman.id.au>
      Link: https://lore.kernel.org/r/1572492694-6520-8-git-send-email-zohar@linux.ibm.com
      273df864
    • N
      ima: Make process_buffer_measurement() generic · e14555e3
      Nayna Jain 提交于
      process_buffer_measurement() is limited to measuring the kexec boot
      command line. This patch makes process_buffer_measurement() more
      generic, allowing it to measure other types of buffer data (e.g.
      blacklisted binary hashes or key hashes).
      
      process_buffer_measurement() may be called directly from an IMA hook
      or as an auxiliary measurement record. In both cases the buffer
      measurement is based on policy. This patch modifies the function to
      conditionally retrieve the policy defined PCR and template for the IMA
      hook case.
      Signed-off-by: NNayna Jain <nayna@linux.ibm.com>
      [zohar@linux.ibm.com: added comment in process_buffer_measurement()]
      Signed-off-by: NMimi Zohar <zohar@linux.ibm.com>
      Signed-off-by: NMichael Ellerman <mpe@ellerman.id.au>
      Link: https://lore.kernel.org/r/1572492694-6520-6-git-send-email-zohar@linux.ibm.com
      e14555e3
  2. 05 10月, 2019 2 次提交
  3. 25 9月, 2019 1 次提交
  4. 18 9月, 2019 1 次提交
  5. 10 9月, 2019 1 次提交
  6. 06 9月, 2019 1 次提交
    • H
      keys: Fix missing null pointer check in request_key_auth_describe() · d41a3eff
      Hillf Danton 提交于
      If a request_key authentication token key gets revoked, there's a window in
      which request_key_auth_describe() can see it with a NULL payload - but it
      makes no check for this and something like the following oops may occur:
      
      	BUG: Kernel NULL pointer dereference at 0x00000038
      	Faulting instruction address: 0xc0000000004ddf30
      	Oops: Kernel access of bad area, sig: 11 [#1]
      	...
      	NIP [...] request_key_auth_describe+0x90/0xd0
      	LR [...] request_key_auth_describe+0x54/0xd0
      	Call Trace:
      	[...] request_key_auth_describe+0x54/0xd0 (unreliable)
      	[...] proc_keys_show+0x308/0x4c0
      	[...] seq_read+0x3d0/0x540
      	[...] proc_reg_read+0x90/0x110
      	[...] __vfs_read+0x3c/0x70
      	[...] vfs_read+0xb4/0x1b0
      	[...] ksys_read+0x7c/0x130
      	[...] system_call+0x5c/0x70
      
      Fix this by checking for a NULL pointer when describing such a key.
      
      Also make the read routine check for a NULL pointer to be on the safe side.
      
      [DH: Modified to not take already-held rcu lock and modified to also check
       in the read routine]
      
      Fixes: 04c567d9 ("[PATCH] Keys: Fix race between two instantiators of a key")
      Reported-by: NSachin Sant <sachinp@linux.vnet.ibm.com>
      Signed-off-by: NHillf Danton <hdanton@sina.com>
      Signed-off-by: NDavid Howells <dhowells@redhat.com>
      Tested-by: NSachin Sant <sachinp@linux.vnet.ibm.com>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      d41a3eff
  7. 05 9月, 2019 5 次提交
  8. 31 8月, 2019 1 次提交
  9. 30 8月, 2019 2 次提交
    • G
      ima: ima_api: Use struct_size() in kzalloc() · 2a7f0e53
      Gustavo A. R. Silva 提交于
      One of the more common cases of allocation size calculations is finding
      the size of a structure that has a zero-sized array at the end, along
      with memory for some number of elements for that array. For example:
      
      struct ima_template_entry {
      	...
              struct ima_field_data template_data[0]; /* template related data */
      };
      
      instance = kzalloc(sizeof(struct ima_template_entry) + count * sizeof(struct ima_field_data), GFP_NOFS);
      
      Instead of leaving these open-coded and prone to type mistakes, we can
      now use the new struct_size() helper:
      
      instance = kzalloc(struct_size(instance, entry, count), GFP_NOFS);
      
      This code was detected with the help of Coccinelle.
      Signed-off-by: NGustavo A. R. Silva <gustavo@embeddedor.com>
      Signed-off-by: NMimi Zohar <zohar@linux.ibm.com>
      2a7f0e53
    • G
      ima: use struct_size() in kzalloc() · fa5b5717
      Gustavo A. R. Silva 提交于
      One of the more common cases of allocation size calculations is finding
      the size of a structure that has a zero-sized array at the end, along
      with memory for some number of elements for that array. For example:
      
      struct foo {
         int stuff;
         struct boo entry[];
      };
      
      instance = kzalloc(sizeof(struct foo) + count * sizeof(struct boo), GFP_KERNEL);
      
      Instead of leaving these open-coded and prone to type mistakes, we can
      now use the new struct_size() helper:
      
      instance = kzalloc(struct_size(instance, entry, count), GFP_KERNEL);
      
      This code was detected with the help of Coccinelle.
      Signed-off-by: NGustavo A. R. Silva <gustavo@embeddedor.com>
      Signed-off-by: NMimi Zohar <zohar@linux.ibm.com>
      fa5b5717
  10. 29 8月, 2019 1 次提交
  11. 28 8月, 2019 1 次提交
    • O
      selinux: avoid atomic_t usage in sidtab · 116f21bb
      Ondrej Mosnacek 提交于
      As noted in Documentation/atomic_t.txt, if we don't need the RMW atomic
      operations, we should only use READ_ONCE()/WRITE_ONCE() +
      smp_rmb()/smp_wmb() where necessary (or the combined variants
      smp_load_acquire()/smp_store_release()).
      
      This patch converts the sidtab code to use regular u32 for the counter
      and reverse lookup cache and use the appropriate operations instead of
      atomic_get()/atomic_set(). Note that when reading/updating the reverse
      lookup cache we don't need memory barriers as it doesn't need to be
      consistent or accurate. We can now also replace some atomic ops with
      regular loads (when under spinlock) and stores (for conversion target
      fields that are always accessed under the master table's spinlock).
      
      We can now also bump SIDTAB_MAX to U32_MAX as we can use the full u32
      range again.
      Suggested-by: NJann Horn <jannh@google.com>
      Signed-off-by: NOndrej Mosnacek <omosnace@redhat.com>
      Reviewed-by: NJann Horn <jannh@google.com>
      Signed-off-by: NPaul Moore <paul@paul-moore.com>
      116f21bb
  12. 20 8月, 2019 22 次提交