Skip to content
Snippets Groups Projects
  1. Feb 13, 2023
  2. Dec 08, 2022
  3. Nov 25, 2022
    • Al Viro's avatar
      use less confusing names for iov_iter direction initializers · de4eda9d
      Al Viro authored
      
      READ/WRITE proved to be actively confusing - the meanings are
      "data destination, as used with read(2)" and "data source, as
      used with write(2)", but people keep interpreting those as
      "we read data from it" and "we write data to it", i.e. exactly
      the wrong way.
      
      Call them ITER_DEST and ITER_SOURCE - at least that is harder
      to misinterpret...
      
      Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
      de4eda9d
  4. Oct 19, 2022
    • Nikolaus Voss's avatar
      KEYS: encrypted: fix key instantiation with user-provided data · 5adedd42
      Nikolaus Voss authored
      Commit cd3bc044 ("KEYS: encrypted: Instantiate key with
      user-provided decrypted data") added key instantiation with user
      provided decrypted data.  The user data is hex-ascii-encoded but was
      just memcpy'ed to the binary buffer. Fix this to use hex2bin instead.
      
      Old keys created from user provided decrypted data saved with "keyctl
      pipe" are still valid, however if the key is recreated from decrypted
      data the old key must be converted to the correct format. This can be
      done with a small shell script, e.g.:
      
      BROKENKEY=abcdefABCDEF1234567890aaaaaaaaaa
      NEWKEY=$(echo -ne $BROKENKEY | xxd -p -c32)
      keyctl add user masterkey "$(cat masterkey.bin)" @u
      keyctl add encrypted testkey "new user:masterkey 32 $NEWKEY" @u
      
      However, NEWKEY is still broken: If for BROKENKEY 32 bytes were
      specified, a brute force attacker knowing the key properties would only
      need to try at most 2^(16*8) keys, as if the key was only 16 bytes long.
      
      The security issue is a result of the combination of limiting the input
      range to hex-ascii and using memcpy() instead of hex2bin(). It could
      have been fixed either by allowing binary input or using hex2bin() (and
      doubling the ascii input key length). This patch implements the latter.
      
      The corresponding test for the Linux Test Project ltp has also been
      fixed (see link below).
      
      Fixes: cd3bc044 ("KEYS: encrypted: Instantiate key with user-provided decrypted data")
      Cc: stable@kernel.org
      Link: https://lore.kernel.org/ltp/20221006081709.92303897@mail.steuer-voss.de/
      
      
      Reviewed-by: default avatarMimi Zohar <zohar@linux.ibm.com>
      Signed-off-by: default avatarNikolaus Voss <nikolaus.voss@haag-streit.com>
      Signed-off-by: default avatarMimi Zohar <zohar@linux.ibm.com>
      5adedd42
  5. Oct 04, 2022
  6. Sep 22, 2022
  7. Jun 08, 2022
    • David Safford's avatar
      KEYS: trusted: tpm2: Fix migratable logic · dda53843
      David Safford authored
      
      When creating (sealing) a new trusted key, migratable
      trusted keys have the FIXED_TPM and FIXED_PARENT attributes
      set, and non-migratable keys don't. This is backwards, and
      also causes creation to fail when creating a migratable key
      under a migratable parent. (The TPM thinks you are trying to
      seal a non-migratable blob under a migratable parent.)
      
      The following simple patch fixes the logic, and has been
      tested for all four combinations of migratable and non-migratable
      trusted keys and parent storage keys. With this logic, you will
      get a proper failure if you try to create a non-migratable
      trusted key under a migratable parent storage key, and all other
      combinations work correctly.
      
      Cc: stable@vger.kernel.org # v5.13+
      Fixes: e5fb5d2c ("security: keys: trusted: Make sealed key properly interoperable")
      Signed-off-by: default avatarDavid Safford <david.safford@gmail.com>
      Reviewed-by: default avatarAhmad Fatoum <a.fatoum@pengutronix.de>
      Reviewed-by: default avatarJarkko Sakkinen <jarkko@kernel.org>
      Signed-off-by: default avatarJarkko Sakkinen <jarkko@kernel.org>
      dda53843
  8. May 23, 2022
  9. May 17, 2022
    • Kees Cook's avatar
      big_keys: Use struct for internal payload · c1298a3a
      Kees Cook authored
      
      The randstruct GCC plugin gets upset when it sees struct path (which is
      randomized) being assigned from a "void *" (which it cannot type-check).
      
      There's no need for these casts, as the entire internal payload use is
      following a normal struct layout. Convert the enum-based void * offset
      dereferencing to the new big_key_payload struct. No meaningful machine
      code changes result after this change, and source readability is improved.
      
      Drop the randstruct exception now that there is no "confusing" cross-type
      assignment.
      
      Cc: David Howells <dhowells@redhat.com>
      Cc: Eric Biggers <ebiggers@kernel.org>
      Cc: Christoph Hellwig <hch@infradead.org>
      Cc: Jarkko Sakkinen <jarkko@kernel.org>
      Cc: James Morris <jmorris@namei.org>
      Cc: "Serge E. Hallyn" <serge@hallyn.com>
      Cc: linux-hardening@vger.kernel.org
      Cc: keyrings@vger.kernel.org
      Cc: linux-security-module@vger.kernel.org
      Signed-off-by: default avatarKees Cook <keescook@chromium.org>
      c1298a3a
  10. Mar 08, 2022
  11. 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
  12. Feb 22, 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
  13. Feb 16, 2022
  14. Nov 26, 2021
  15. Oct 20, 2021
    • Eric W. Biederman's avatar
      ucounts: Move get_ucounts from cred_alloc_blank to key_change_session_keyring · 5ebcbe34
      Eric W. Biederman authored
      Setting cred->ucounts in cred_alloc_blank does not make sense.  The
      uid and user_ns are deliberately not set in cred_alloc_blank but
      instead the setting is delayed until key_change_session_keyring.
      
      So move dealing with ucounts into key_change_session_keyring as well.
      
      Unfortunately that movement of get_ucounts adds a new failure mode to
      key_change_session_keyring.  I do not see anything stopping the parent
      process from calling setuid and changing the relevant part of it's
      cred while keyctl_session_to_parent is running making it fundamentally
      necessary to call get_ucounts in key_change_session_keyring.  Which
      means that the new failure mode cannot be avoided.
      
      A failure of key_change_session_keyring results in a single threaded
      parent keeping it's existing credentials.  Which results in the parent
      process not being able to access the session keyring and whichever
      keys are in the new keyring.
      
      Further get_ucounts is only expected to fail if the number of bits in
      the refernece count for the structure is too few.
      
      Since the code has no other way to report the failure of get_ucounts
      and because such failures are not expected to be common add a WARN_ONCE
      to report this problem to userspace.
      
      Between the WARN_ONCE and the parent process not having access to
      the keys in the new session keyring I expect any failure of get_ucounts
      will be noticed and reported and we can find another way to handle this
      condition.  (Possibly by just making ucounts->count an atomic_long_t).
      
      Cc: stable@vger.kernel.org
      Fixes: 905ae01c ("Add a reference to ucounts for each cred")
      Link: https://lkml.kernel.org/r/7k0ias0uf.fsf_-_@disp2133
      
      
      Tested-by: default avatarYu Zhao <yuzhao@google.com>
      Reviewed-by: default avatarAlexey Gladkov <legion@kernel.org>
      Signed-off-by: default avatar"Eric W. Biederman" <ebiederm@xmission.com>
      5ebcbe34
  16. May 12, 2021
  17. Apr 22, 2021
  18. Apr 14, 2021
    • Colin Ian King's avatar
      KEYS: trusted: Fix missing null return from kzalloc call · aec00aa0
      Colin Ian King authored
      
      The kzalloc call can return null with the GFP_KERNEL flag so
      add a null check and exit via a new error exit label. Use the
      same exit error label for another error path too.
      
      Addresses-Coverity: ("Dereference null return value")
      Fixes: 830027e2cb55 ("KEYS: trusted: Add generic trusted keys framework")
      Signed-off-by: default avatarColin Ian King <colin.king@canonical.com>
      Reviewed-by: default avatarSumit Garg <sumit.garg@linaro.org>
      Reviewed-by: default avatarJarkko Sakkinen <jarkko@kernel.org>
      Signed-off-by: default avatarJarkko Sakkinen <jarkko@kernel.org>
      aec00aa0
    • Sumit Garg's avatar
      KEYS: trusted: Introduce TEE based Trusted Keys · 0a95ebc9
      Sumit Garg authored
      
      Add support for TEE based trusted keys where TEE provides the functionality
      to seal and unseal trusted keys using hardware unique key.
      
      Refer to Documentation/staging/tee.rst for detailed information about TEE.
      
      Signed-off-by: default avatarSumit Garg <sumit.garg@linaro.org>
      Tested-by: default avatarJarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
      Reviewed-by: default avatarJarkko Sakkinen <jarkko@kernel.org>
      Signed-off-by: default avatarJarkko Sakkinen <jarkko@kernel.org>
      0a95ebc9
    • Sumit Garg's avatar
      KEYS: trusted: Add generic trusted keys framework · 5d0682be
      Sumit Garg authored
      
      Current trusted keys framework is tightly coupled to use TPM device as
      an underlying implementation which makes it difficult for implementations
      like Trusted Execution Environment (TEE) etc. to provide trusted keys
      support in case platform doesn't posses a TPM device.
      
      Add a generic trusted keys framework where underlying implementations
      can be easily plugged in. Create struct trusted_key_ops to achieve this,
      which contains necessary functions of a backend.
      
      Also, define a module parameter in order to select a particular trust
      source in case a platform support multiple trust sources. In case its
      not specified then implementation itetrates through trust sources list
      starting with TPM and assign the first trust source as a backend which
      has initiazed successfully during iteration.
      
      Note that current implementation only supports a single trust source at
      runtime which is either selectable at compile time or during boot via
      aforementioned module parameter.
      
      Suggested-by: default avatarJarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
      Signed-off-by: default avatarSumit Garg <sumit.garg@linaro.org>
      Reviewed-by: default avatarJarkko Sakkinen <jarkko@kernel.org>
      Signed-off-by: default avatarJarkko Sakkinen <jarkko@kernel.org>
      5d0682be
    • James Bottomley's avatar
      security: keys: trusted: Make sealed key properly interoperable · e5fb5d2c
      James Bottomley authored
      
      The current implementation appends a migratable flag to the end of a
      key, meaning the format isn't exactly interoperable because the using
      party needs to know to strip this extra byte.  However, all other
      consumers of TPM sealed blobs expect the unseal to return exactly the
      key.  Since TPM2 keys have a key property flag that corresponds to
      migratable, use that flag instead and make the actual key the only
      sealed quantity.  This is secure because the key properties are bound
      to a hash in the private part, so if they're altered the key won't
      load.
      
      Backwards compatibility is implemented by detecting whether we're
      loading a new format key or not and correctly setting migratable from
      the last byte of old format keys.
      
      Signed-off-by: default avatarJames Bottomley <James.Bottomley@HansenPartnership.com>
      Reviewed-by: default avatarJarkko Sakkinen <jarkko@kernel.org>
      Tested-by: default avatarJarkko Sakkinen <jarkko@kernel.org>
      Signed-off-by: default avatarJarkko Sakkinen <jarkko@kernel.org>
      e5fb5d2c
    • James Bottomley's avatar
      security: keys: trusted: use ASN.1 TPM2 key format for the blobs · f2219745
      James Bottomley authored
      
      Modify the TPM2 key format blob output to export and import in the
      ASN.1 form for TPM2 sealed object keys.  For compatibility with prior
      trusted keys, the importer will also accept two TPM2B quantities
      representing the public and private parts of the key.  However, the
      export via keyctl pipe will only output the ASN.1 format.
      
      The benefit of the ASN.1 format is that it's a standard and thus the
      exported key can be used by userspace tools (openssl_tpm2_engine,
      openconnect and tpm2-tss-engine).  The format includes policy
      specifications, thus it gets us out of having to construct policy
      handles in userspace and the format includes the parent meaning you
      don't have to keep passing it in each time.
      
      This patch only implements basic handling for the ASN.1 format, so
      keys with passwords but no policy.
      
      Signed-off-by: default avatarJames Bottomley <James.Bottomley@HansenPartnership.com>
      Tested-by: default avatarJarkko Sakkinen <jarkko@kernel.org>
      Signed-off-by: default avatarJarkko Sakkinen <jarkko@kernel.org>
      f2219745
    • James Bottomley's avatar
      security: keys: trusted: fix TPM2 authorizations · de66514d
      James Bottomley authored
      
      In TPM 1.2 an authorization was a 20 byte number.  The spec actually
      recommended you to hash variable length passwords and use the sha1
      hash as the authorization.  Because the spec doesn't require this
      hashing, the current authorization for trusted keys is a 40 digit hex
      number.  For TPM 2.0 the spec allows the passing in of variable length
      passwords and passphrases directly, so we should allow that in trusted
      keys for ease of use.  Update the 'blobauth' parameter to take this
      into account, so we can now use plain text passwords for the keys.
      
      so before
      
      keyctl add trusted kmk "new 32 blobauth=f572d396fae9206628714fb2ce00f72e94f2258fkeyhandle=81000001" @u
      
      after we will accept both the old hex sha1 form as well as a new
      directly supplied password:
      
      keyctl add trusted kmk "new 32 blobauth=hello keyhandle=81000001" @u
      
      Since a sha1 hex code must be exactly 40 bytes long and a direct
      password must be 20 or less, we use the length as the discriminator
      for which form is input.
      
      Note this is both and enhancement and a potential bug fix.  The TPM
      2.0 spec requires us to strip leading zeros, meaning empyty
      authorization is a zero length HMAC whereas we're currently passing in
      20 bytes of zeros.  A lot of TPMs simply accept this as OK, but the
      Microsoft TPM emulator rejects it with TPM_RC_BAD_AUTH, so this patch
      makes the Microsoft TPM emulator work with trusted keys.
      
      Fixes: 0fe54803 ("keys, trusted: seal/unseal with TPM 2.0 chips")
      Signed-off-by: default avatarJames Bottomley <James.Bottomley@HansenPartnership.com>
      Reviewed-by: default avatarJarkko Sakkinen <jarkko@kernel.org>
      Tested-by: default avatarJarkko Sakkinen <jarkko@kernel.org>
      Signed-off-by: default avatarJarkko Sakkinen <jarkko@kernel.org>
      de66514d
  19. Feb 16, 2021
    • Jarkko Sakkinen's avatar
      KEYS: trusted: Reserve TPM for seal and unseal operations · 8c657a05
      Jarkko Sakkinen authored
      
      When TPM 2.0 trusted keys code was moved to the trusted keys subsystem,
      the operations were unwrapped from tpm_try_get_ops() and tpm_put_ops(),
      which are used to take temporarily the ownership of the TPM chip. The
      ownership is only taken inside tpm_send(), but this is not sufficient,
      as in the key load TPM2_CC_LOAD, TPM2_CC_UNSEAL and TPM2_FLUSH_CONTEXT
      need to be done as a one single atom.
      
      Take the TPM chip ownership before sending anything with
      tpm_try_get_ops() and tpm_put_ops(), and use tpm_transmit_cmd() to send
      TPM commands instead of tpm_send(), reverting back to the old behaviour.
      
      Fixes: 2e19e101 ("KEYS: trusted: Move TPM2 trusted keys code")
      Reported-by: default avatar"James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>
      Cc: stable@vger.kernel.org
      Cc: David Howells <dhowells@redhat.com>
      Cc: Mimi Zohar <zohar@linux.ibm.com>
      Cc: Sumit Garg <sumit.garg@linaro.org>
      Acked-by Sumit Garg <sumit.garg@linaro.org>
      Tested-by: default avatarMimi Zohar <zohar@linux.ibm.com>
      Signed-off-by: default avatarJarkko Sakkinen <jarkko@kernel.org>
      8c657a05
    • Jarkko Sakkinen's avatar
      KEYS: trusted: Fix migratable=1 failing · 8da7520c
      Jarkko Sakkinen authored
      
      Consider the following transcript:
      
      $ keyctl add trusted kmk "new 32 blobauth=helloworld keyhandle=80000000 migratable=1" @u
      add_key: Invalid argument
      
      The documentation has the following description:
      
        migratable=   0|1 indicating permission to reseal to new PCR values,
                      default 1 (resealing allowed)
      
      The consequence is that "migratable=1" should succeed. Fix this by
      allowing this condition to pass instead of return -EINVAL.
      
      [*] Documentation/security/keys/trusted-encrypted.rst
      
      Cc: stable@vger.kernel.org
      Cc: "James E.J. Bottomley" <jejb@linux.ibm.com>
      Cc: Mimi Zohar <zohar@linux.ibm.com>
      Cc: David Howells <dhowells@redhat.com>
      Fixes: d00a1c72 ("keys: add new trusted key-type")
      Signed-off-by: default avatarJarkko Sakkinen <jarkko@kernel.org>
      8da7520c
    • Jarkko Sakkinen's avatar
      KEYS: trusted: Fix incorrect handling of tpm_get_random() · 5df16caa
      Jarkko Sakkinen authored
      
      When tpm_get_random() was introduced, it defined the following API for the
      return value:
      
      1. A positive value tells how many bytes of random data was generated.
      2. A negative value on error.
      
      However, in the call sites the API was used incorrectly, i.e. as it would
      only return negative values and otherwise zero. Returning he positive read
      counts to the user space does not make any possible sense.
      
      Fix this by returning -EIO when tpm_get_random() returns a positive value.
      
      Fixes: 41ab999c ("tpm: Move tpm_get_random api into the TPM device driver")
      Cc: stable@vger.kernel.org
      Cc: Mimi Zohar <zohar@linux.ibm.com>
      Cc: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>
      Cc: David Howells <dhowells@redhat.com>
      Cc: Kent Yoder <key@linux.vnet.ibm.com>
      Signed-off-by: default avatarJarkko Sakkinen <jarkko@kernel.org>
      Reviewed-by: default avatarMimi Zohar <zohar@linux.ibm.com>
      5df16caa
  20. Jan 21, 2021
Loading