Forum | Documentation | Website | Blog

Skip to content
Snippets Groups Projects
  1. Mar 08, 2022
  2. Mar 02, 2022
    • Nicolai Stange's avatar
      crypto: dh - constify struct dh's pointer members · 215bebc8
      Nicolai Stange authored
      
      struct dh contains several pointer members corresponding to DH parameters:
      ->key, ->p and ->g. A subsequent commit will introduce "dh" wrapping
      templates of the form "ffdhe2048(dh)", "ffdhe3072(dh)" and so on in order
      to provide built-in support for the well-known safe-prime ffdhe group
      parameters specified in RFC 7919. These templates will need to set the
      group parameter related members of the (serialized) struct dh instance
      passed to the inner "dh" kpp_alg instance, i.e. ->p and ->g, to some
      constant, static storage arrays.
      
      Turn the struct dh pointer members' types into "pointer to const" in
      preparation for this.
      
      Signed-off-by: default avatarNicolai Stange <nstange@suse.de>
      Reviewed-by: default avatarHannes Reinecke <hare@suse.de>
      Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
      215bebc8
    • Paul Moore's avatar
      selinux: shorten the policy capability enum names · cdbec3ed
      Paul Moore authored
      
      The SELinux policy capability enum names are rather long and follow
      the "POLICYDB_CAPABILITY_XXX format".  While the "POLICYDB_" prefix
      is helpful in tying the enums to other SELinux policy constants,
      macros, etc. there is no reason why we need to spell out
      "CAPABILITY" completely.  Shorten "CAPABILITY" to "CAP" in order to
      make things a bit shorter and cleaner.
      
      Moving forward, the SELinux policy capability enum names should
      follow the "POLICYDB_CAP_XXX" format.
      
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      cdbec3ed
  3. Feb 28, 2022
  4. Feb 25, 2022
  5. Feb 22, 2022
    • Randy Dunlap's avatar
      EVM: fix the evm= __setup handler return value · f2544f5e
      Randy Dunlap authored
      __setup() handlers should return 1 if the parameter is handled.
      Returning 0 causes the entire string to be added to init's
      environment strings (limited to 32 strings), unnecessarily polluting it.
      
      Using the documented string "evm=fix" causes an Unknown parameter message:
        Unknown kernel command line parameters
        "BOOT_IMAGE=/boot/bzImage-517rc5 evm=fix", will be passed to user space.
      
      and that string is added to init's environment string space:
        Run /sbin/init as init process
          with arguments:
           /sbin/init
          with environment:
           HOME=/
           TERM=linux
           BOOT_IMAGE=/boot/bzImage-517rc5
           evm=fix
      
      With this change, using "evm=fix" acts as expected and an invalid
      option ("evm=evm") causes a warning to be printed:
        evm: invalid "evm" mode
      but init's environment is not polluted with this string, as expected.
      
      Fixes: 7102ebcd
      
       ("evm: permit only valid security.evm xattrs to be updated")
      Signed-off-by: default avatarRandy Dunlap <rdunlap@infradead.org>
      Reported-by: default avatarIgor Zhbanov <i.zhbanov@omprussia.ru>
      Link: lore.kernel.org/r/64644a2f-4a20-bab3-1e15-3b2cdd0defe3@omprussia.ru
      Signed-off-by: default avatarMimi Zohar <zohar@linux.ibm.com>
      f2544f5e
    • Ondrej Mosnacek's avatar
      selinux: fix misuse of mutex_is_locked() · ce2fc710
      Ondrej Mosnacek authored
      mutex_is_locked() tests whether the mutex is locked *by any task*, while
      here we want to test if it is held *by the current task*. To avoid
      false/missed WARNINGs, use lockdep_assert_is_held() and
      lockdep_assert_is_not_held() instead, which do the right thing (though
      they are a no-op if CONFIG_LOCKDEP=n).
      
      Cc: stable@vger.kernel.org
      Fixes: 2554a48f
      
       ("selinux: measure state and policy capabilities")
      Signed-off-by: default avatarOndrej Mosnacek <omosnace@redhat.com>
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      ce2fc710
  6. Feb 21, 2022
    • Yael Tzur's avatar
      KEYS: encrypted: Instantiate key with user-provided decrypted data · cd3bc044
      Yael Tzur authored
      
      For availability and performance reasons master keys often need to be
      released outside of a Key Management Service (KMS) to clients. It
      would be beneficial to provide a mechanism where the
      wrapping/unwrapping of data encryption keys (DEKs) is not dependent
      on a remote call at runtime yet security is not (or only minimally)
      compromised. Master keys could be securely stored in the Kernel and
      be used to wrap/unwrap keys from Userspace.
      
      The encrypted.c class supports instantiation of encrypted keys with
      either an already-encrypted key material, or by generating new key
      material based on random numbers. This patch defines a new datablob
      format: [<format>] <master-key name> <decrypted data length>
      <decrypted data> that allows to inject and encrypt user-provided
      decrypted data. The decrypted data must be hex-ascii encoded.
      
      Signed-off-by: default avatarYael Tzur <yaelt@google.com>
      Reviewed-by: default avatarMimi Zohar <zohar@linux.ibm.com>
      Reviewed-by: default avatarSumit Garg <sumit.garg@linaro.org>
      Reviewed-by: default avatarJarkko Sakkinen <jarkko@kernel.org>
      Signed-off-by: default avatarMimi Zohar <zohar@linux.ibm.com>
      cd3bc044
  7. Feb 18, 2022
  8. Feb 15, 2022
    • Ondrej Mosnacek's avatar
      security: implement sctp_assoc_established hook in selinux · 3eb8eaf2
      Ondrej Mosnacek authored
      Do this by extracting the peer labeling per-association logic from
      selinux_sctp_assoc_request() into a new helper
      selinux_sctp_process_new_assoc() and use this helper in both
      selinux_sctp_assoc_request() and selinux_sctp_assoc_established(). This
      ensures that the peer labeling behavior as documented in
      Documentation/security/SCTP.rst is applied both on the client and server
      side:
      """
      An SCTP socket will only have one peer label assigned to it. This will be
      assigned during the establishment of the first association. Any further
      associations on this socket will have their packet peer label compared to
      the sockets peer label, and only if they are different will the
      ``association`` permission be validated. This is validated by checking the
      socket peer sid against the received packets peer sid to determine whether
      the association should be allowed or denied.
      """
      
      At the same time, it also ensures that the peer label of the association
      is set to the correct value, such that if it is peeled off into a new
      socket, the socket's peer label  will then be set to the association's
      peer label, same as it already works on the server side.
      
      While selinux_inet_conn_established() (which we are replacing by
      selinux_sctp_assoc_established() for SCTP) only deals with assigning a
      peer label to the connection (socket), in case of SCTP we need to also
      copy the (local) socket label to the association, so that
      selinux_sctp_sk_clone() can then pick it up for the new socket in case
      of SCTP peeloff.
      
      Careful readers will notice that the selinux_sctp_process_new_assoc()
      helper also includes the "IPv4 packet received over an IPv6 socket"
      check, even though it hadn't been in selinux_sctp_assoc_request()
      before. While such check is not necessary in
      selinux_inet_conn_request() (because struct request_sock's family field
      is already set according to the skb's family), here it is needed, as we
      don't have request_sock and we take the initial family from the socket.
      In selinux_sctp_assoc_established() it is similarly needed as well (and
      also selinux_inet_conn_established() already has it).
      
      Fixes: 72e89f50
      
       ("security: Add support for SCTP security hooks")
      Reported-by: default avatarPrashanth Prahlad <pprahlad@redhat.com>
      Based-on-patch-by: default avatarXin Long <lucien.xin@gmail.com>
      Reviewed-by: default avatarXin Long <lucien.xin@gmail.com>
      Tested-by: default avatarRichard Haines <richard_c_haines@btinternet.com>
      Signed-off-by: default avatarOndrej Mosnacek <omosnace@redhat.com>
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      3eb8eaf2
    • Ondrej Mosnacek's avatar
      security: add sctp_assoc_established hook · 5e50f5d4
      Ondrej Mosnacek authored
      security_sctp_assoc_established() is added to replace
      security_inet_conn_established() called in
      sctp_sf_do_5_1E_ca(), so that asoc can be accessed in security
      subsystem and save the peer secid to asoc->peer_secid.
      
      Fixes: 72e89f50
      
       ("security: Add support for SCTP security hooks")
      Reported-by: default avatarPrashanth Prahlad <pprahlad@redhat.com>
      Based-on-patch-by: default avatarXin Long <lucien.xin@gmail.com>
      Reviewed-by: default avatarXin Long <lucien.xin@gmail.com>
      Tested-by: default avatarRichard Haines <richard_c_haines@btinternet.com>
      Signed-off-by: default avatarOndrej Mosnacek <omosnace@redhat.com>
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      5e50f5d4
    • Mimi Zohar's avatar
      ima: define ima_max_digest_data struct without a flexible array variable · 8c54135e
      Mimi Zohar authored
      
      To support larger hash digests in the 'iint' cache, instead of defining
      the 'digest' field as the maximum digest size, the 'digest' field was
      defined as a flexible array variable.  The "ima_digest_data" struct was
      wrapped inside a local structure with the maximum digest size.  But
      before adding the record to the iint cache, memory for the exact digest
      size was dynamically allocated.
      
      The original reason for defining the 'digest' field as a flexible array
      variable is still valid for the 'iint' cache use case.  Instead of
      wrapping the 'ima_digest_data' struct in a local structure define
      'ima_max_digest_data' struct.
      
      Reviewed-by: default avatarStefan Berger <stefanb@linux.ibm.com>
      Signed-off-by: default avatarMimi Zohar <zohar@linux.ibm.com>
      8c54135e
    • Mimi Zohar's avatar
      ima: rename IMA_ACTION_FLAGS to IMA_NONACTION_FLAGS · aae6ccbd
      Mimi Zohar authored
      
      Simple policy rule options, such as fowner, uid, or euid, can be checked
      immediately, while other policy rule options, such as requiring a file
      signature, need to be deferred.
      
      The 'flags' field in the integrity_iint_cache struct contains the policy
      action', 'subaction', and non action/subaction.
      
      action: measure/measured, appraise/appraised, (collect)/collected,
              audit/audited
      subaction: appraise status for each hook (e.g. file, mmap, bprm, read,
              creds)
      non action/subaction: deferred policy rule options and state
      
      Rename the IMA_ACTION_FLAGS to IMA_NONACTION_FLAGS.
      
      Reviewed-by: default avatarStefan Berger <stefanb@linux.ibm.com>
      Signed-off-by: default avatarMimi Zohar <zohar@linux.ibm.com>
      aae6ccbd
    • Stefan Berger's avatar
      ima: Return error code obtained from securityfs functions · e4e071ba
      Stefan Berger authored
      
      If an error occurs when creating a securityfs file, return the exact
      error code to the caller.
      
      Signed-off-by: default avatarStefan Berger <stefanb@linux.ibm.com>
      Signed-off-by: default avatarMimi Zohar <zohar@linux.ibm.com>
      e4e071ba
    • Austin Kim's avatar
      ima: Fix trivial typos in the comments · 65603435
      Austin Kim authored
      
      There are a few minor typos in the comments. Fix these.
      
      Signed-off-by: default avatarAustin Kim <austindh.kim@gmail.com>
      Signed-off-by: default avatarMimi Zohar <zohar@linux.ibm.com>
      65603435
  9. Feb 06, 2022
  10. Feb 04, 2022
    • Ondrej Mosnacek's avatar
      selinux: parse contexts for mount options early · 70f4169a
      Ondrej Mosnacek authored
      Commit b8b87fd9
      
       ("selinux: Fix selinux_sb_mnt_opts_compat()")
      started to parse mount options into SIDs in selinux_add_opt() if policy
      has already been loaded. Since it's extremely unlikely that anyone would
      depend on the ability to set SELinux contexts on fs_context before
      loading the policy and then mounting that context after simplify the
      logic by always parsing the options early.
      
      Note that the multi-step mounting is only possible with the new
      fscontext mount API and wasn't possible before its introduction.
      
      Signed-off-by: default avatarOndrej Mosnacek <omosnace@redhat.com>
      Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
      70f4169a
  11. Feb 02, 2022
  12. Feb 01, 2022
  13. Jan 28, 2022
    • Vivek Goyal's avatar
      security, lsm: dentry_init_security() Handle multi LSM registration · 7f5056b9
      Vivek Goyal authored
      
      A ceph user has reported that ceph is crashing with kernel NULL pointer
      dereference. Following is the backtrace.
      
      /proc/version: Linux version 5.16.2-arch1-1 (linux@archlinux) (gcc (GCC)
      11.1.0, GNU ld (GNU Binutils) 2.36.1) #1 SMP PREEMPT Thu, 20 Jan 2022
      16:18:29 +0000
      distro / arch: Arch Linux / x86_64
      SELinux is not enabled
      ceph cluster version: 16.2.7 (dd0603118f56ab514f133c8d2e3adfc983942503)
      
      relevant dmesg output:
      [   30.947129] BUG: kernel NULL pointer dereference, address:
      0000000000000000
      [   30.947206] #PF: supervisor read access in kernel mode
      [   30.947258] #PF: error_code(0x0000) - not-present page
      [   30.947310] PGD 0 P4D 0
      [   30.947342] Oops: 0000 [#1] PREEMPT SMP PTI
      [   30.947388] CPU: 5 PID: 778 Comm: touch Not tainted 5.16.2-arch1-1 #1
      86fbf2c313cc37a553d65deb81d98e9dcc2a3659
      [   30.947486] Hardware name: Gigabyte Technology Co., Ltd. B365M
      DS3H/B365M DS3H, BIOS F5 08/13/2019
      [   30.947569] RIP: 0010:strlen+0x0/0x20
      [   30.947616] Code: b6 07 38 d0 74 16 48 83 c7 01 84 c0 74 05 48 39 f7 75
      ec 31 c0 31 d2 89 d6 89 d7 c3 48 89 f8 31 d2 89 d6 89 d7 c3 0
      f 1f 40 00 <80> 3f 00 74 12 48 89 f8 48 83 c0 01 80 38 00 75 f7 48 29 f8 31
      ff
      [   30.947782] RSP: 0018:ffffa4ed80ffbbb8 EFLAGS: 00010246
      [   30.947836] RAX: 0000000000000000 RBX: ffffa4ed80ffbc60 RCX:
      0000000000000000
      [   30.947904] RDX: 0000000000000000 RSI: 0000000000000000 RDI:
      0000000000000000
      [   30.947971] RBP: ffff94b0d15c0ae0 R08: 0000000000000000 R09:
      0000000000000000
      [   30.948040] R10: 0000000000000000 R11: 0000000000000000 R12:
      0000000000000000
      [   30.948106] R13: 0000000000000001 R14: ffffa4ed80ffbc60 R15:
      0000000000000000
      [   30.948174] FS:  00007fc7520f0740(0000) GS:ffff94b7ced40000(0000)
      knlGS:0000000000000000
      [   30.948252] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
      [   30.948308] CR2: 0000000000000000 CR3: 0000000104a40001 CR4:
      00000000003706e0
      [   30.948376] Call Trace:
      [   30.948404]  <TASK>
      [   30.948431]  ceph_security_init_secctx+0x7b/0x240 [ceph
      49f9c4b9bf5be8760f19f1747e26da33920bce4b]
      [   30.948582]  ceph_atomic_open+0x51e/0x8a0 [ceph
      49f9c4b9bf5be8760f19f1747e26da33920bce4b]
      [   30.948708]  ? get_cached_acl+0x4d/0xa0
      [   30.948759]  path_openat+0x60d/0x1030
      [   30.948809]  do_filp_open+0xa5/0x150
      [   30.948859]  do_sys_openat2+0xc4/0x190
      [   30.948904]  __x64_sys_openat+0x53/0xa0
      [   30.948948]  do_syscall_64+0x5c/0x90
      [   30.948989]  ? exc_page_fault+0x72/0x180
      [   30.949034]  entry_SYSCALL_64_after_hwframe+0x44/0xae
      [   30.949091] RIP: 0033:0x7fc7521e25bb
      [   30.950849] Code: 25 00 00 41 00 3d 00 00 41 00 74 4b 64 8b 04 25 18 00
      00 00 85 c0 75 67 44 89 e2 48 89 ee bf 9c ff ff ff b8 01 01 0
      0 00 0f 05 <48> 3d 00 f0 ff ff 0f 87 91 00 00 00 48 8b 54 24 28 64 48 2b 14
      25
      
      Core of the problem is that ceph checks for return code from
      security_dentry_init_security() and if return code is 0, it assumes
      everything is fine and continues to call strlen(name), which crashes.
      
      Typically SELinux LSM returns 0 and sets name to "security.selinux" and
      it is not a problem. Or if selinux is not compiled in or disabled, it
      returns -EOPNOTSUP and ceph deals with it.
      
      But somehow in this configuration, 0 is being returned and "name" is
      not being initialized and that's creating the problem.
      
      Our suspicion is that BPF LSM is registering a hook for
      dentry_init_security() and returns hook default of 0.
      
      LSM_HOOK(int, 0, dentry_init_security, struct dentry *dentry,...)
      
      I have not been able to reproduce it just by doing CONFIG_BPF_LSM=y.
      Stephen has tested the patch though and confirms it solves the problem
      for him.
      
      dentry_init_security() is written in such a way that it expects only one
      LSM to register the hook. Atleast that's the expectation with current code.
      
      If another LSM returns a hook and returns default, it will simply return
      0 as of now and that will break ceph.
      
      Hence, suggestion is that change semantics of this hook a bit. If there
      are no LSMs or no LSM is taking ownership and initializing security context,
      then return -EOPNOTSUP. Also allow at max one LSM to initialize security
      context. This hook can't deal with multiple LSMs trying to init security
      context. This patch implements this new behavior.
      
      Reported-by: default avatarStephen Muth <smuth4@gmail.com>
      Tested-by: default avatarStephen Muth <smuth4@gmail.com>
      Suggested-by: default avatarCasey Schaufler <casey@schaufler-ca.com>
      Acked-by: default avatarCasey Schaufler <casey@schaufler-ca.com>
      Reviewed-by: default avatarSerge Hallyn <serge@hallyn.com>
      Cc: Jeff Layton <jlayton@kernel.org>
      Cc: Christian Brauner <brauner@kernel.org>
      Cc: Paul Moore <paul@paul-moore.com>
      Cc: <stable@vger.kernel.org> # 5.16.0
      Signed-off-by: default avatarVivek Goyal <vgoyal@redhat.com>
      Reviewed-by: default avatarJeff Layton <jlayton@kernel.org>
      Acked-by: default avatarPaul Moore <paul@paul-moore.com>
      Acked-by: default avatarChristian Brauner <brauner@kernel.org>
      Signed-off-by: default avatarJames Morris <jmorris@namei.org>
      7f5056b9
  14. Jan 27, 2022
  15. Jan 26, 2022