12 Apr, 2016

5 commits

  • Add a secondary system keyring that can be added to by root whilst the
    system is running - provided the key being added is vouched for by a key
    built into the kernel or already added to the secondary keyring.

    Rename .system_keyring to .builtin_trusted_keys to distinguish it more
    obviously from the new keyring (called .secondary_trusted_keys).

    The new keyring needs to be enabled with CONFIG_SECONDARY_TRUSTED_KEYRING.

    If the secondary keyring is enabled, a link is created from that to
    .builtin_trusted_keys so that the the latter will automatically be searched
    too if the secondary keyring is searched.

    Signed-off-by: David Howells

    David Howells
     
  • Remove KEY_FLAG_TRUSTED and KEY_ALLOC_TRUSTED as they're no longer
    meaningful. Also we can drop the trusted flag from the preparse structure.

    Given this, we no longer need to pass the key flags through to
    restrict_link().

    Further, we can now get rid of keyring_restrict_trusted_only() also.

    Signed-off-by: David Howells

    David Howells
     
  • Move the point at which a key is determined to be trustworthy to
    __key_link() so that we use the contents of the keyring being linked in to
    to determine whether the key being linked in is trusted or not.

    What is 'trusted' then becomes a matter of what's in the keyring.

    Currently, the test is done when the key is parsed, but given that at that
    point we can only sensibly refer to the contents of the system trusted
    keyring, we can only use that as the basis for working out the
    trustworthiness of a new key.

    With this change, a trusted keyring is a set of keys that once the
    trusted-only flag is set cannot be added to except by verification through
    one of the contained keys.

    Further, adding a key into a trusted keyring, whilst it might grant
    trustworthiness in the context of that keyring, does not automatically
    grant trustworthiness in the context of a second keyring to which it could
    be secondarily linked.

    To accomplish this, the authentication data associated with the key source
    must now be retained. For an X.509 cert, this means the contents of the
    AuthorityKeyIdentifier and the signature data.

    If system keyrings are disabled then restrict_link_by_builtin_trusted()
    resolves to restrict_link_reject(). The integrity digital signature code
    still works correctly with this as it was previously using
    KEY_FLAG_TRUSTED_ONLY, which doesn't permit anything to be added if there
    is no system keyring against which trust can be determined.

    Signed-off-by: David Howells

    David Howells
     
  • Make the system trusted keyring depend on the asymmetric key type as
    there's not a lot of point having it if you can't then load asymmetric keys
    onto it.

    This requires the ASYMMETRIC_KEY_TYPE to be made a bool, not a tristate, as
    the Kconfig language doesn't then correctly force ASYMMETRIC_KEY_TYPE to
    'y' rather than 'm' if SYSTEM_TRUSTED_KEYRING is 'y'.

    Making SYSTEM_TRUSTED_KEYRING *select* ASYMMETRIC_KEY_TYPE instead doesn't
    work as the Kconfig interpreter then wrongly complains about dependency
    loops.

    Signed-off-by: David Howells

    David Howells
     
  • Add a facility whereby proposed new links to be added to a keyring can be
    vetted, permitting them to be rejected if necessary. This can be used to
    block public keys from which the signature cannot be verified or for which
    the signature verification fails. It could also be used to provide
    blacklisting.

    This affects operations like add_key(), KEYCTL_LINK and KEYCTL_INSTANTIATE.

    To this end:

    (1) A function pointer is added to the key struct that, if set, points to
    the vetting function. This is called as:

    int (*restrict_link)(struct key *keyring,
    const struct key_type *key_type,
    unsigned long key_flags,
    const union key_payload *key_payload),

    where 'keyring' will be the keyring being added to, key_type and
    key_payload will describe the key being added and key_flags[*] can be
    AND'ed with KEY_FLAG_TRUSTED.

    [*] This parameter will be removed in a later patch when
    KEY_FLAG_TRUSTED is removed.

    The function should return 0 to allow the link to take place or an
    error (typically -ENOKEY, -ENOPKG or -EKEYREJECTED) to reject the
    link.

    The pointer should not be set directly, but rather should be set
    through keyring_alloc().

    Note that if called during add_key(), preparse is called before this
    method, but a key isn't actually allocated until after this function
    is called.

    (2) KEY_ALLOC_BYPASS_RESTRICTION is added. This can be passed to
    key_create_or_update() or key_instantiate_and_link() to bypass the
    restriction check.

    (3) KEY_FLAG_TRUSTED_ONLY is removed. The entire contents of a keyring
    with this restriction emplaced can be considered 'trustworthy' by
    virtue of being in the keyring when that keyring is consulted.

    (4) key_alloc() and keyring_alloc() take an extra argument that will be
    used to set restrict_link in the new key. This ensures that the
    pointer is set before the key is published, thus preventing a window
    of unrestrictedness. Normally this argument will be NULL.

    (5) As a temporary affair, keyring_restrict_trusted_only() is added. It
    should be passed to keyring_alloc() as the extra argument instead of
    setting KEY_FLAG_TRUSTED_ONLY on a keyring. This will be replaced in
    a later patch with functions that look in the appropriate places for
    authoritative keys.

    Signed-off-by: David Howells
    Reviewed-by: Mimi Zohar

    David Howells
     

06 Apr, 2016

2 commits

  • Make the determination of the trustworthiness of a key dependent on whether
    a key that can verify it is present in the supplied ring of trusted keys
    rather than whether or not the verifying key has KEY_FLAG_TRUSTED set.

    verify_pkcs7_signature() will return -ENOKEY if the PKCS#7 message trust
    chain cannot be verified.

    Signed-off-by: David Howells

    David Howells
     
  • Generalise system_verify_data() to provide access to internal content
    through a callback. This allows all the PKCS#7 stuff to be hidden inside
    this function and removed from the PE file parser and the PKCS#7 test key.

    If external content is not required, NULL should be passed as data to the
    function. If the callback is not required, that can be set to NULL.

    The function is now called verify_pkcs7_signature() to contrast with
    verify_pefile_signature() and the definitions of both have been moved into
    linux/verification.h along with the key_being_used_for enum.

    Signed-off-by: David Howells

    David Howells
     

29 Feb, 2016

1 commit


26 Feb, 2016

2 commits

  • Place a system_extra_cert buffer of configurable size, right after the
    system_certificate_list, so that inserted keys can be readily processed by
    the existing mechanism. Added script takes a key file and a kernel image
    and inserts its contents to the reserved area. The
    system_certificate_list_size is also adjusted accordingly.

    Call the script as:

    scripts/insert-sys-cert -b -c

    If vmlinux has no symbol table, supply System.map file with -s flag.
    Subsequent runs replace the previously inserted key, instead of appending
    the new one.

    Signed-off-by: Mehmet Kayaalp
    Signed-off-by: David Howells
    Acked-by: Mimi Zohar

    Mehmet Kayaalp
     
  • When a user calls 'make -s', we can assume they don't want to
    see any output except for warnings and errors, but instead
    they see this for a warning free build:

    ###
    ### Now generating an X.509 key pair to be used for signing modules.
    ###
    ### If this takes a long time, you might wish to run rngd in the
    ### background to keep the supply of entropy topped up. It
    ### needs to be run as root, and uses a hardware random
    ### number generator if one is available.
    ###
    Generating a 4096 bit RSA private key
    .................................................................................................................................................................................................................................++
    ..............................................................................................................................++
    writing new private key to 'certs/signing_key.pem'
    -----
    ###
    ### Key pair generated.
    ###

    The output can confuse simple build testing scripts that just check
    for an empty build log.

    This patch silences all the output:
    - "echo" is changed to "@$(kecho)", which is dropped when "-s" gets
    passed
    - the openssl command itself is only printed with V=1, using the
    $(Q) macro
    - The output of openssl gets redirected to /dev/null on "-s" builds.

    Signed-off-by: Arnd Bergmann
    Signed-off-by: David Howells

    Arnd Bergmann
     

10 Feb, 2016

1 commit


21 Oct, 2015

1 commit

  • Currently we see this in "git status" if we build in the source dir:

    Untracked files:
    (use "git add ..." to include in what will be committed)

    certs/x509_certificate_list

    It looks like it used to live in kernel/ so we squash that .gitignore
    entry at the same time. I didn't bother to dig through git history to
    see when it moved, since it is just a minor annoyance at most.

    Cc: David Woodhouse
    Cc: keyrings@linux-nfs.org
    Signed-off-by: Paul Gortmaker
    Signed-off-by: David Howells

    Paul Gortmaker
     

14 Aug, 2015

3 commits

  • Since commit 1329e8cc69 ("modsign: Extract signing cert from
    CONFIG_MODULE_SIG_KEY if needed"), the build system has carefully coped
    with the signing key being specified as a relative path in either the
    source or or the build trees.

    However, the actual signing of modules has not worked if the filename
    is relative to the source tree.

    Fix that by moving the config_filename helper into scripts/Kbuild.include
    so that it can be used from elsewhere, and then using it in the top-level
    Makefile to find the signing key file.

    Kill the intermediate $(MODPUBKEY) and $(MODSECKEY) variables too, while
    we're at it. There's no need for them.

    Signed-off-by: David Woodhouse
    Signed-off-by: David Howells

    David Woodhouse
     
  • We couldn't use if_changed for this before, because it didn't live in
    the kernel/ directory so we couldn't add it to $(targets). It was easier
    just to leave it as it was.

    Now it's in the certs/ directory we can use if_changed, the same as we
    do for the trusted certificate list.

    Aside from making things consistent, this means we don't need to depend
    explicitly on the include/config/module/sig/key.h file. And we also get
    to automatically do the right thing and re-extract the cert if the user
    does odd things like using a relative filename and then playing silly
    buggers with adding/removing that file in both the source and object
    trees. We always favour the one in the object tree if it exists, and
    now we'll correctly re-extract the cert when it changes. Previously we'd
    *only* re-extract the cert if the config option changed, even if the
    actual file we're using did change.

    Signed-off-by: David Woodhouse
    Signed-off-by: David Howells

    David Woodhouse
     
  • Move certificate handling out of the kernel/ directory and into a certs/
    directory to get all the weird stuff in one place and move the generated
    signing keys into this directory.

    Signed-off-by: David Howells
    Reviewed-by: David Woodhouse

    David Howells