22 Jan, 2021

1 commit

  • Fix W=1 compile warnings (invalid kerneldoc):

    crypto/asymmetric_keys/asymmetric_type.c:160: warning: Function parameter or member 'kid1' not described in 'asymmetric_key_id_same'
    crypto/asymmetric_keys/asymmetric_type.c:160: warning: Function parameter or member 'kid2' not described in 'asymmetric_key_id_same'
    crypto/asymmetric_keys/asymmetric_type.c:160: warning: Excess function parameter 'kid_1' description in 'asymmetric_key_id_same'
    crypto/asymmetric_keys/asymmetric_type.c:160: warning: Excess function parameter 'kid_2' description in 'asymmetric_key_id_same'

    Signed-off-by: Krzysztof Kozlowski
    Signed-off-by: David Howells
    Acked-by: Randy Dunlap
    Reviewed-by: Ben Boeckel
    Reviewed-by: Jarkko Sakkinen

    Krzysztof Kozlowski
     

20 Jun, 2020

1 commit

  • This file is almost compatible with ReST. Just minor changes
    were needed:

    - Adjust document and titles markups;
    - Adjust numbered list markups;
    - Add a comments markup for the Contents section;
    - Add markups for literal blocks.

    Acked-by: Jarkko Sakkinen
    Signed-off-by: Mauro Carvalho Chehab
    Link: https://lore.kernel.org/r/c2275ea94e0507a01b020ab66dfa824d8b1c2545.1592203650.git.mchehab+huawei@kernel.org
    Signed-off-by: Jonathan Corbet

    Mauro Carvalho Chehab
     

09 Jul, 2019

1 commit

  • …/git/dhowells/linux-fs

    Pull keyring namespacing from David Howells:
    "These patches help make keys and keyrings more namespace aware.

    Firstly some miscellaneous patches to make the process easier:

    - Simplify key index_key handling so that the word-sized chunks
    assoc_array requires don't have to be shifted about, making it
    easier to add more bits into the key.

    - Cache the hash value in the key so that we don't have to calculate
    on every key we examine during a search (it involves a bunch of
    multiplications).

    - Allow keying_search() to search non-recursively.

    Then the main patches:

    - Make it so that keyring names are per-user_namespace from the point
    of view of KEYCTL_JOIN_SESSION_KEYRING so that they're not
    accessible cross-user_namespace.

    keyctl_capabilities() shows KEYCTL_CAPS1_NS_KEYRING_NAME for this.

    - Move the user and user-session keyrings to the user_namespace
    rather than the user_struct. This prevents them propagating
    directly across user_namespaces boundaries (ie. the KEY_SPEC_*
    flags will only pick from the current user_namespace).

    - Make it possible to include the target namespace in which the key
    shall operate in the index_key. This will allow the possibility of
    multiple keys with the same description, but different target
    domains to be held in the same keyring.

    keyctl_capabilities() shows KEYCTL_CAPS1_NS_KEY_TAG for this.

    - Make it so that keys are implicitly invalidated by removal of a
    domain tag, causing them to be garbage collected.

    - Institute a network namespace domain tag that allows keys to be
    differentiated by the network namespace in which they operate. New
    keys that are of a type marked 'KEY_TYPE_NET_DOMAIN' are assigned
    the network domain in force when they are created.

    - Make it so that the desired network namespace can be handed down
    into the request_key() mechanism. This allows AFS, NFS, etc. to
    request keys specific to the network namespace of the superblock.

    This also means that the keys in the DNS record cache are
    thenceforth namespaced, provided network filesystems pass the
    appropriate network namespace down into dns_query().

    For DNS, AFS and NFS are good, whilst CIFS and Ceph are not. Other
    cache keyrings, such as idmapper keyrings, also need to set the
    domain tag - for which they need access to the network namespace of
    the superblock"

    * tag 'keys-namespace-20190627' of git://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs:
    keys: Pass the network namespace into request_key mechanism
    keys: Network namespace domain tag
    keys: Garbage collect keys for which the domain has been removed
    keys: Include target namespace in match criteria
    keys: Move the user and user-session keyrings to the user_namespace
    keys: Namespace keyring names
    keys: Add a 'recurse' flag for keyring searches
    keys: Cache the hash value to avoid lots of recalculation
    keys: Simplify key description management

    Linus Torvalds
     

27 Jun, 2019

1 commit


24 May, 2019

1 commit

  • Based on 1 normalized pattern(s):

    this program is free software you can redistribute it and or modify
    it under the terms of the gnu general public licence as published by
    the free software foundation either version 2 of the licence or at
    your option any later version

    extracted by the scancode license scanner the SPDX license identifier

    GPL-2.0-or-later

    has been chosen to replace the boilerplate/reference in 114 file(s).

    Signed-off-by: Thomas Gleixner
    Reviewed-by: Allison Randal
    Reviewed-by: Kate Stewart
    Cc: linux-spdx@vger.kernel.org
    Link: https://lkml.kernel.org/r/20190520170857.552531963@linutronix.de
    Signed-off-by: Greg Kroah-Hartman

    Thomas Gleixner
     

26 Oct, 2018

1 commit

  • Provide the missing asymmetric key subops for new key type ops. This
    include query, encrypt, decrypt and create signature. Verify signature
    already exists. Also provided are accessor functions for this:

    int query_asymmetric_key(const struct key *key,
    struct kernel_pkey_query *info);

    int encrypt_blob(struct kernel_pkey_params *params,
    const void *data, void *enc);
    int decrypt_blob(struct kernel_pkey_params *params,
    const void *enc, void *data);
    int create_signature(struct kernel_pkey_params *params,
    const void *data, void *enc);

    The public_key_signature struct gains an encoding field to carry the
    encoding for verify_signature().

    Signed-off-by: David Howells
    Tested-by: Marcel Holtmann
    Reviewed-by: Marcel Holtmann
    Reviewed-by: Denis Kenzior
    Tested-by: Denis Kenzior
    Signed-off-by: James Morris

    David Howells
     

16 Jun, 2018

1 commit

  • As we move stuff around, some doc references are broken. Fix some of
    them via this script:
    ./scripts/documentation-file-ref-check --fix

    Manually checked if the produced result is valid, removing a few
    false-positives.

    Acked-by: Takashi Iwai
    Acked-by: Masami Hiramatsu
    Acked-by: Stephen Boyd
    Acked-by: Charles Keepax
    Acked-by: Mathieu Poirier
    Reviewed-by: Coly Li
    Signed-off-by: Mauro Carvalho Chehab
    Acked-by: Jonathan Corbet

    Mauro Carvalho Chehab
     

18 Oct, 2017

2 commits


05 Apr, 2017

3 commits


12 Apr, 2016

2 commits


06 Apr, 2016

1 commit


21 Oct, 2015

1 commit

  • Merge the type-specific data with the payload data into one four-word chunk
    as it seems pointless to keep them separate.

    Use user_key_payload() for accessing the payloads of overloaded
    user-defined keys.

    Signed-off-by: David Howells
    cc: linux-cifs@vger.kernel.org
    cc: ecryptfs@vger.kernel.org
    cc: linux-ext4@vger.kernel.org
    cc: linux-f2fs-devel@lists.sourceforge.net
    cc: linux-nfs@vger.kernel.org
    cc: ceph-devel@vger.kernel.org
    cc: linux-ima-devel@lists.sourceforge.net

    David Howells
     

13 Aug, 2015

1 commit

  • A PKCS#7 or CMS message can have per-signature authenticated attributes
    that are digested as a lump and signed by the authorising key for that
    signature. If such attributes exist, the content digest isn't itself
    signed, but rather it is included in a special authattr which then
    contributes to the signature.

    Further, we already require the master message content type to be
    pkcs7_signedData - but there's also a separate content type for the data
    itself within the SignedData object and this must be repeated inside the
    authattrs for each signer [RFC2315 9.2, RFC5652 11.1].

    We should really validate the authattrs if they exist or forbid them
    entirely as appropriate. To this end:

    (1) Alter the PKCS#7 parser to reject any message that has more than one
    signature where at least one signature has authattrs and at least one
    that does not.

    (2) Validate authattrs if they are present and strongly restrict them.
    Only the following authattrs are permitted and all others are
    rejected:

    (a) contentType. This is checked to be an OID that matches the
    content type in the SignedData object.

    (b) messageDigest. This must match the crypto digest of the data.

    (c) signingTime. If present, we check that this is a valid, parseable
    UTCTime or GeneralTime and that the date it encodes fits within
    the validity window of the matching X.509 cert.

    (d) S/MIME capabilities. We don't check the contents.

    (e) Authenticode SP Opus Info. We don't check the contents.

    (f) Authenticode Statement Type. We don't check the contents.

    The message is rejected if (a) or (b) are missing. If the message is
    an Authenticode type, the message is rejected if (e) is missing; if
    not Authenticode, the message is rejected if (d) - (f) are present.

    The S/MIME capabilities authattr (d) unfortunately has to be allowed
    to support kernels already signed by the pesign program. This only
    affects kexec. sign-file suppresses them (CMS_NOSMIMECAP).

    The message is also rejected if an authattr is given more than once or
    if it contains more than one element in its set of values.

    (3) Add a parameter to pkcs7_verify() to select one of the following
    restrictions and pass in the appropriate option from the callers:

    (*) VERIFYING_MODULE_SIGNATURE

    This requires that the SignedData content type be pkcs7-data and
    forbids authattrs. sign-file sets CMS_NOATTR. We could be more
    flexible and permit authattrs optionally, but only permit minimal
    content.

    (*) VERIFYING_FIRMWARE_SIGNATURE

    This requires that the SignedData content type be pkcs7-data and
    requires authattrs. In future, this will require an attribute
    holding the target firmware name in addition to the minimal set.

    (*) VERIFYING_UNSPECIFIED_SIGNATURE

    This requires that the SignedData content type be pkcs7-data but
    allows either no authattrs or only permits the minimal set.

    (*) VERIFYING_KEXEC_PE_SIGNATURE

    This only supports the Authenticode SPC_INDIRECT_DATA content type
    and requires at least an SpcSpOpusInfo authattr in addition to the
    minimal set. It also permits an SPC_STATEMENT_TYPE authattr (and
    an S/MIME capabilities authattr because the pesign program doesn't
    remove these).

    (*) VERIFYING_KEY_SIGNATURE
    (*) VERIFYING_KEY_SELF_SIGNATURE

    These are invalid in this context but are included for later use
    when limiting the use of X.509 certs.

    (4) The pkcs7_test key type is given a module parameter to select between
    the above options for testing purposes. For example:

    echo 1 >/sys/module/pkcs7_test_key/parameters/usage
    keyctl padd pkcs7_test foo @s
    Signed-off-by: David Howells
    Reviewed-by: Marcel Holtmann
    Reviewed-by: David Woodhouse

    David Howells
     

22 May, 2015

1 commit

  • The call to asymmetric_key_hex_to_key_id() from ca_keys_setup()
    silently fails with -ENOMEM. Instead of dynamically allocating
    memory from a __setup function, this patch defines a variable
    and calls __asymmetric_key_hex_to_key_id(), a new helper function,
    directly.

    This bug was introduced by 'commit 46963b774d44 ("KEYS: Overhaul
    key identification when searching for asymmetric keys")'.

    Changelog:
    - for clarification, rename hexlen to asciihexlen in
    asymmetric_key_hex_to_key_id()
    - add size argument to __asymmetric_key_hex_to_key_id() - David Howells
    - inline __asymmetric_key_hex_to_key_id() - David Howells
    - remove duplicate strlen() calls

    Acked-by: David Howells
    Signed-off-by: Mimi Zohar
    Cc: stable@vger.kernel.org # 3.18

    Mimi Zohar
     

07 Oct, 2014

1 commit


06 Oct, 2014

1 commit


03 Oct, 2014

1 commit

  • If hexlen is odd then function returns an error.
    Use IS_ERR to check for error, otherwise invalid pointer
    is used and kernel gives oops:

    [ 132.816522] BUG: unable to handle kernel paging request at
    ffffffffffffffea
    [ 132.819902] IP: [] asymmetric_key_id_same+0x14/0x36
    [ 132.820302] PGD 1a12067 PUD 1a14067 PMD 0
    [ 132.820302] Oops: 0000 [#1] SMP
    [ 132.820302] Modules linked in: bridge(E) stp(E) llc(E) evdev(E)
    serio_raw(E) i2c_piix4(E) button(E) fuse(E)
    [ 132.820302] CPU: 0 PID: 2993 Comm: cat Tainted: G E
    3.16.0-kds+ #2847
    [ 132.820302] Hardware name: Bochs Bochs, BIOS Bochs 01/01/2011
    [ 132.820302] task: ffff88004249a430 ti: ffff880056640000 task.ti:
    ffff880056640000
    [ 132.820302] RIP: 0010:[] []
    asymmetric_key_id_same+0x14/0x36
    [ 132.820302] RSP: 0018:ffff880056643930 EFLAGS: 00010246
    [ 132.820302] RAX: 0000000000000000 RBX: ffffffffffffffea RCX:
    ffff880056643ae0
    [ 132.820302] RDX: 000000000000005e RSI: ffffffffffffffea RDI:
    ffff88005bac9300
    [ 132.820302] RBP: ffff880056643948 R08: 0000000000000003 R09:
    00000007504aa01a
    [ 132.820302] R10: 0000000000000000 R11: 0000000000000000 R12:
    ffff88005d68ca40
    [ 132.820302] R13: 0000000000000101 R14: 0000000000000000 R15:
    ffff88005bac5280
    [ 132.820302] FS: 00007f67a153c740(0000) GS:ffff88005da00000(0000)
    knlGS:0000000000000000
    [ 132.820302] CS: 0010 DS: 0000 ES: 0000 CR0: 000000008005003b
    [ 132.820302] CR2: ffffffffffffffea CR3: 000000002e663000 CR4:
    00000000000006f0
    [ 132.820302] Stack:
    [ 132.820302] ffffffff812bfc66 ffff880056643ae0 ffff88005bac5280
    ffff880056643958
    [ 132.820302] ffffffff812bfc9d ffff880056643980 ffffffff812971d9
    ffff88005ce930c1
    [ 132.820302] ffff88005ce930c0 0000000000000000 ffff8800566439c8
    ffffffff812fb753
    [ 132.820302] Call Trace:
    [ 132.820302] [] ? asymmetric_match_key_ids+0x24/0x42
    [ 132.820302] [] asymmetric_key_cmp+0x19/0x1b
    [ 132.820302] [] keyring_search_iterator+0x74/0xd7
    [ 132.820302] [] assoc_array_subtree_iterate+0x67/0xd2
    [ 132.820302] [] ? key_default_cmp+0x20/0x20
    [ 132.820302] [] assoc_array_iterate+0x19/0x1e
    [ 132.820302] [] search_nested_keyrings+0xf6/0x2b6
    [ 132.820302] [] ? sched_clock_cpu+0x91/0xa2
    [ 132.820302] [] ? mark_held_locks+0x58/0x6e
    [ 132.820302] [] ? current_kernel_time+0x77/0xb8
    [ 132.820302] [] keyring_search_aux+0xe1/0x14c
    [ 132.820302] [] ? keyring_search_aux+0x6c/0x14c
    [ 132.820302] [] keyring_search+0x8f/0xb6
    [ 132.820302] [] ? asymmetric_match_key_ids+0x42/0x42
    [ 132.820302] [] ? key_default_cmp+0x20/0x20
    [ 132.820302] [] asymmetric_verify+0xa4/0x214
    [ 132.820302] [] integrity_digsig_verify+0xb1/0xe2
    [ 132.820302] [] ? evm_verifyxattr+0x6a/0x7a
    [ 132.820302] [] ima_appraise_measurement+0x160/0x370
    [ 132.820302] [] ? d_absolute_path+0x5b/0x7a
    [ 132.820302] [] process_measurement+0x322/0x404

    Reported-by: Dmitry Kasatkin
    Signed-off-by: Dmitry Kasatkin
    Signed-off-by: David Howells

    Dmitry Kasatkin
     

22 Sep, 2014

1 commit

  • As it stands, the code to generate an asymmetric key ID prechecks the hex
    string it is given whilst determining the length, before it allocates the
    buffer for hex2bin() to translate into - which mean that checking the result of
    hex2bin() is redundant.

    Unfortunately, hex2bin() is marked as __must_check, which means that the
    following warning may be generated if the return value isn't checked:

    crypto/asymmetric_keys/asymmetric_type.c: In function
    asymmetric_key_hex_to_key_id:
    crypto/asymmetric_keys/asymmetric_type.c:110: warning: ignoring return
    value of hex2bin, declared with attribute warn_unused_result

    The warning can't be avoided by casting the result to void.

    Instead, use strlen() to check the length of the string and ignore the fact
    that the string might not be entirely valid hex until after the allocation has
    been done - in which case we can use the result of hex2bin() for this.

    Signed-off-by: David Howells

    David Howells
     

17 Sep, 2014

6 commits

  • Make use of the new match string preparsing to overhaul key identification
    when searching for asymmetric keys. The following changes are made:

    (1) Use the previously created asymmetric_key_id struct to hold the following
    key IDs derived from the X.509 certificate or PKCS#7 message:

    id: serial number + issuer
    skid: subjKeyId + subject
    authority: authKeyId + issuer

    (2) Replace the hex fingerprint attached to key->type_data[1] with an
    asymmetric_key_ids struct containing the id and the skid (if present).

    (3) Make the asymmetric_type match data preparse select one of two searches:

    (a) An iterative search for the key ID given if prefixed with "id:". The
    prefix is expected to be followed by a hex string giving the ID to
    search for. The criterion key ID is checked against all key IDs
    recorded on the key.

    (b) A direct search if the key ID is not prefixed with "id:". This will
    look for an exact match on the key description.

    (4) Make x509_request_asymmetric_key() take a key ID. This is then converted
    into "id:" and passed into keyring_search() where match preparsing
    will turn it back into a binary ID.

    (5) X.509 certificate verification then takes the authority key ID and looks
    up a key that matches it to find the public key for the certificate
    signature.

    (6) PKCS#7 certificate verification then takes the id key ID and looks up a
    key that matches it to find the public key for the signed information
    block signature.

    Additional changes:

    (1) Multiple subjKeyId and authKeyId values on an X.509 certificate cause the
    cert to be rejected with -EBADMSG.

    (2) The 'fingerprint' ID is gone. This was primarily intended to convey PGP
    public key fingerprints. If PGP is supported in future, this should
    generate a key ID that carries the fingerprint.

    (3) Th ca_keyid= kernel command line option is now converted to a key ID and
    used to match the authority key ID. Possibly this should only match the
    actual authKeyId part and not the issuer as well.

    Signed-off-by: David Howells
    Acked-by: Vivek Goyal

    David Howells
     
  • Implement the first step in using binary key IDs for asymmetric keys rather
    than hex string keys.

    The previously added match data preparsing will be able to convert hex
    criterion strings into binary which can then be compared more rapidly.

    Further, we actually want more then one ID string per public key. The problem
    is that X.509 certs refer to other X.509 certs by matching Issuer + AuthKeyId
    to Subject + SubjKeyId, but PKCS#7 messages match against X.509 Issuer +
    SerialNumber.

    This patch just provides facilities for a later patch to make use of.

    Signed-off-by: David Howells
    Acked-by: Vivek Goyal

    David Howells
     
  • Make the key matching functions pointed to by key_match_data::cmp return bool
    rather than int.

    Signed-off-by: David Howells
    Acked-by: Vivek Goyal

    David Howells
     
  • A previous patch added a ->match_preparse() method to the key type. This is
    allowed to override the function called by the iteration algorithm.
    Therefore, we can just set a default that simply checks for an exact match of
    the key description with the original criterion data and allow match_preparse
    to override it as needed.

    The key_type::match op is then redundant and can be removed, as can the
    user_match() function.

    Signed-off-by: David Howells
    Acked-by: Vivek Goyal

    David Howells
     
  • Remove key_type::def_lookup_type as it's no longer used. The information now
    defaults to KEYRING_SEARCH_LOOKUP_DIRECT but may be overridden by
    type->match_preparse().

    Signed-off-by: David Howells
    Acked-by: Vivek Goyal

    David Howells
     
  • Preparse the match data. This provides several advantages:

    (1) The preparser can reject invalid criteria up front.

    (2) The preparser can convert the criteria to binary data if necessary (the
    asymmetric key type really wants to do binary comparison of the key IDs).

    (3) The preparser can set the type of search to be performed. This means
    that it's not then a one-off setting in the key type.

    (4) The preparser can set an appropriate comparator function.

    Signed-off-by: David Howells
    Acked-by: Vivek Goyal

    David Howells
     

23 Jul, 2014

2 commits


19 Jul, 2014

1 commit

  • Provide a generic instantiation function for key types that use the preparse
    hook. This makes it easier to prereserve key quota before keyrings get locked
    to retain the new key.

    Signed-off-by: David Howells
    Acked-by: Steve Dickson
    Acked-by: Jeff Layton
    Reviewed-by: Sage Weil

    David Howells
     

17 Jul, 2014

2 commits

  • Instead of allowing public keys, with certificates signed by any
    key on the system trusted keyring, to be added to a trusted keyring,
    this patch further restricts the certificates to those signed by a
    particular key on the system keyring.

    This patch defines a new kernel parameter 'ca_keys' to identify the
    specific key which must be used for trust validation of certificates.

    Simplified Mimi's "KEYS: define an owner trusted keyring" patch.

    Changelog:
    - support for builtin x509 public keys only
    - export "asymmetric_keyid_match"
    - remove ifndefs MODULE
    - rename kernel boot parameter from keys_ownerid to ca_keys

    Signed-off-by: Dmitry Kasatkin
    Signed-off-by: Mimi Zohar

    Dmitry Kasatkin
     
  • To avoid code duplication this patch refactors asymmetric_key_match(),
    making partial ID string match a separate function.

    This patch also implicitly fixes a bug in the code. asymmetric_key_match()
    allows to match the key by its subtype. But subtype matching could be
    undone if asymmetric_key_id(key) would return NULL. This patch first
    checks for matching spec and then for its value.

    Signed-off-by: Dmitry Kasatkin
    Signed-off-by: Mimi Zohar

    Dmitry Kasatkin
     

26 Sep, 2013

1 commit

  • The keyring expansion patches introduces a new search method by which
    key_search() attempts to walk directly to the key that has exactly the same
    description as the requested one.

    However, this causes inexact matching of asymmetric keys to fail. The
    solution to this is to select iterative rather than direct search as the
    default search type for asymmetric keys.

    As an example, the kernel might have a key like this:

    Magrathea: Glacier signing key: 6a2a0f82bad7e396665f465e4e3e1f9bd24b1226

    and:

    keyctl search asymmetric id:d24b1226

    should find the key, despite that not being its exact description.

    Signed-off-by: David Howells

    David Howells
     

08 Oct, 2012

2 commits

  • The instantiation data passed to the asymmetric key type are expected to be
    formatted in some way, and there are several possible standard ways to format
    the data.

    The two obvious standards are OpenPGP keys and X.509 certificates. The latter
    is especially useful when dealing with UEFI, and the former might be useful
    when dealing with, say, eCryptfs.

    Further, it might be desirable to provide formatted blobs that indicate
    hardware is to be accessed to retrieve the keys or that the keys live
    unretrievably in a hardware store, but that the keys can be used by means of
    the hardware.

    From userspace, the keys can be loaded using the keyctl command, for example,
    an X.509 binary certificate:

    keyctl padd asymmetric foo @s
    Signed-off-by: Rusty Russell

    David Howells
     
  • Create a key type that can be used to represent an asymmetric key type for use
    in appropriate cryptographic operations, such as encryption, decryption,
    signature generation and signature verification.

    The key type is "asymmetric" and can provide access to a variety of
    cryptographic algorithms.

    Possibly, this would be better as "public_key" - but that has the disadvantage
    that "public key" is an overloaded term.

    Signed-off-by: David Howells
    Signed-off-by: Rusty Russell

    David Howells