Skip to content
Snippets Groups Projects
  1. Feb 04, 2019
    • Kairui Song's avatar
      kexec, KEYS: Make use of platform keyring for signature verify · 278311e4
      Kairui Song authored
      
      This patch allows the kexec_file_load syscall to verify the PE signed
      kernel image signature based on the preboot keys stored in the .platform
      keyring, as fall back, if the signature verification failed due to not
      finding the public key in the secondary or builtin keyrings.
      
      This commit adds a VERIFY_USE_PLATFORM_KEYRING similar to previous
      VERIFY_USE_SECONDARY_KEYRING indicating that verify_pkcs7_signature
      should verify the signature using platform keyring.  Also, decrease
      the error message log level when verification failed with -ENOKEY,
      so that if called tried multiple time with different keyring it
      won't generate extra noises.
      
      Signed-off-by: default avatarKairui Song <kasong@redhat.com>
      Cc: David Howells <dhowells@redhat.com>
      Acked-by: Dave Young <dyoung@redhat.com> (for kexec_file_load part)
      [zohar@linux.ibm.com: tweaked the first paragraph of the patch description,
       and fixed checkpatch warning.]
      Signed-off-by: default avatarMimi Zohar <zohar@linux.ibm.com>
      278311e4
    • Kairui Song's avatar
      integrity, KEYS: add a reference to platform keyring · 219a3e86
      Kairui Song authored
      
      commit 9dc92c45 ("integrity: Define a trusted platform keyring")
      introduced a .platform keyring for storing preboot keys, used for
      verifying kernel image signatures. Currently only IMA-appraisal is able
      to use the keyring to verify kernel images that have their signature
      stored in xattr.
      
      This patch exposes the .platform keyring, making it accessible for
      verifying PE signed kernel images as well.
      
      Suggested-by: default avatarMimi Zohar <zohar@linux.ibm.com>
      Signed-off-by: default avatarKairui Song <kasong@redhat.com>
      Cc: David Howells <dhowells@redhat.com>
      [zohar@linux.ibm.com: fixed checkpatch errors, squashed with patch fix]
      Signed-off-by: default avatarMimi Zohar <zohar@linux.ibm.com>
      219a3e86
  2. Jan 06, 2019
  3. Aug 22, 2018
  4. Aug 16, 2018
  5. Jun 26, 2018
  6. Jun 15, 2018
  7. Feb 21, 2018
  8. Nov 02, 2017
    • Greg Kroah-Hartman's avatar
      License cleanup: add SPDX GPL-2.0 license identifier to files with no license · b2441318
      Greg Kroah-Hartman authored
      
      Many source files in the tree are missing licensing information, which
      makes it harder for compliance tools to determine the correct license.
      
      By default all files without license information are under the default
      license of the kernel, which is GPL version 2.
      
      Update the files which contain no license information with the 'GPL-2.0'
      SPDX license identifier.  The SPDX identifier is a legally binding
      shorthand, which can be used instead of the full boiler plate text.
      
      This patch is based on work done by Thomas Gleixner and Kate Stewart and
      Philippe Ombredanne.
      
      How this work was done:
      
      Patches were generated and checked against linux-4.14-rc6 for a subset of
      the use cases:
       - file had no licensing information it it.
       - file was a */uapi/* one with no licensing information in it,
       - file was a */uapi/* one with existing licensing information,
      
      Further patches will be generated in subsequent months to fix up cases
      where non-standard license headers were used, and references to license
      had to be inferred by heuristics based on keywords.
      
      The analysis to determine which SPDX License Identifier to be applied to
      a file was done in a spreadsheet of side by side results from of the
      output of two independent scanners (ScanCode & Windriver) producing SPDX
      tag:value files created by Philippe Ombredanne.  Philippe prepared the
      base worksheet, and did an initial spot review of a few 1000 files.
      
      The 4.13 kernel was the starting point of the analysis with 60,537 files
      assessed.  Kate Stewart did a file by file comparison of the scanner
      results in the spreadsheet to determine which SPDX license identifier(s)
      to be applied to the file. She confirmed any determination that was not
      immediately clear with lawyers working with the Linux Foundation.
      
      Criteria used to select files for SPDX license identifier tagging was:
       - Files considered eligible had to be source code files.
       - Make and config files were included as candidates if they contained >5
         lines of source
       - File already had some variant of a license header in it (even if <5
         lines).
      
      All documentation files were explicitly excluded.
      
      The following heuristics were used to determine which SPDX license
      identifiers to apply.
      
       - when both scanners couldn't find any license traces, file was
         considered to have no license information in it, and the top level
         COPYING file license applied.
      
         For non */uapi/* files that summary was:
      
         SPDX license identifier                            # files
         ---------------------------------------------------|-------
         GPL-2.0                                              11139
      
         and resulted in the first patch in this series.
      
         If that file was a */uapi/* path one, it was "GPL-2.0 WITH
         Linux-syscall-note" otherwise it was "GPL-2.0".  Results of that was:
      
         SPDX license identifier                            # files
         ---------------------------------------------------|-------
         GPL-2.0 WITH Linux-syscall-note                        930
      
         and resulted in the second patch in this series.
      
       - if a file had some form of licensing information in it, and was one
         of the */uapi/* ones, it was denoted with the Linux-syscall-note if
         any GPL family license was found in the file or had no licensing in
         it (per prior point).  Results summary:
      
         SPDX license identifier                            # files
         ---------------------------------------------------|------
         GPL-2.0 WITH Linux-syscall-note                       270
         GPL-2.0+ WITH Linux-syscall-note                      169
         ((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause)    21
         ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause)    17
         LGPL-2.1+ WITH Linux-syscall-note                      15
         GPL-1.0+ WITH Linux-syscall-note                       14
         ((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause)    5
         LGPL-2.0+ WITH Linux-syscall-note                       4
         LGPL-2.1 WITH Linux-syscall-note                        3
         ((GPL-2.0 WITH Linux-syscall-note) OR MIT)              3
         ((GPL-2.0 WITH Linux-syscall-note) AND MIT)             1
      
         and that resulted in the third patch in this series.
      
       - when the two scanners agreed on the detected license(s), that became
         the concluded license(s).
      
       - when there was disagreement between the two scanners (one detected a
         license but the other didn't, or they both detected different
         licenses) a manual inspection of the file occurred.
      
       - In most cases a manual inspection of the information in the file
         resulted in a clear resolution of the license that should apply (and
         which scanner probably needed to revisit its heuristics).
      
       - When it was not immediately clear, the license identifier was
         confirmed with lawyers working with the Linux Foundation.
      
       - If there was any question as to the appropriate license identifier,
         the file was flagged for further research and to be revisited later
         in time.
      
      In total, over 70 hours of logged manual review was done on the
      spreadsheet to determine the SPDX license identifiers to apply to the
      source files by Kate, Philippe, Thomas and, in some cases, confirmation
      by lawyers working with the Linux Foundation.
      
      Kate also obtained a third independent scan of the 4.13 code base from
      FOSSology, and compared selected files where the other two scanners
      disagreed against that SPDX file, to see if there was new insights.  The
      Windriver scanner is based on an older version of FOSSology in part, so
      they are related.
      
      Thomas did random spot checks in about 500 files from the spreadsheets
      for the uapi headers and agreed with SPDX license identifier in the
      files he inspected. For the non-uapi files Thomas did random spot checks
      in about 15000 files.
      
      In initial set of patches against 4.14-rc6, 3 files were found to have
      copy/paste license identifier errors, and have been fixed to reflect the
      correct identifier.
      
      Additionally Philippe spent 10 hours this week doing a detailed manual
      inspection and review of the 12,461 patched files from the initial patch
      version early this week with:
       - a full scancode scan run, collecting the matched texts, detected
         license ids and scores
       - reviewing anything where there was a license detected (about 500+
         files) to ensure that the applied SPDX license was correct
       - reviewing anything where there was no detection but the patch license
         was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
         SPDX license was correct
      
      This produced a worksheet with 20 files needing minor correction.  This
      worksheet was then exported into 3 different .csv files for the
      different types of files to be modified.
      
      These .csv files were then reviewed by Greg.  Thomas wrote a script to
      parse the csv files and add the proper SPDX tag to the file, in the
      format that the file expected.  This script was further refined by Greg
      based on the output to detect more types of files automatically and to
      distinguish between header and source .c files (which need different
      comment types.)  Finally Greg ran the script using the .csv files to
      generate the patches.
      
      Reviewed-by: default avatarKate Stewart <kstewart@linuxfoundation.org>
      Reviewed-by: default avatarPhilippe Ombredanne <pombredanne@nexb.com>
      Reviewed-by: default avatarThomas Gleixner <tglx@linutronix.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b2441318
  9. Jul 14, 2017
  10. May 09, 2017
  11. Apr 04, 2017
    • Mat Martineau's avatar
      KEYS: Use structure to capture key restriction function and data · 2b6aa412
      Mat Martineau authored
      
      Replace struct key's restrict_link function pointer with a pointer to
      the new struct key_restriction. The structure contains pointers to the
      restriction function as well as relevant data for evaluating the
      restriction.
      
      The garbage collector checks restrict_link->keytype when key types are
      unregistered. Restrictions involving a removed key type are converted
      to use restrict_link_reject so that restrictions cannot be removed by
      unregistering key types.
      
      Signed-off-by: default avatarMat Martineau <mathew.j.martineau@linux.intel.com>
      2b6aa412
  12. Apr 03, 2017
    • Mat Martineau's avatar
      KEYS: Split role of the keyring pointer for keyring restrict functions · aaf66c88
      Mat Martineau authored
      
      The first argument to the restrict_link_func_t functions was a keyring
      pointer. These functions are called by the key subsystem with this
      argument set to the destination keyring, but restrict_link_by_signature
      expects a pointer to the relevant trusted keyring.
      
      Restrict functions may need something other than a single struct key
      pointer to allow or reject key linkage, so the data used to make that
      decision (such as the trust keyring) is moved to a new, fourth
      argument. The first argument is now always the destination keyring.
      
      Signed-off-by: default avatarMat Martineau <mathew.j.martineau@linux.intel.com>
      aaf66c88
    • David Howells's avatar
      KEYS: Add a system blacklist keyring · 734114f8
      David Howells authored
      
      Add the following:
      
       (1) A new system keyring that is used to store information about
           blacklisted certificates and signatures.
      
       (2) A new key type (called 'blacklist') that is used to store a
           blacklisted hash in its description as a hex string.  The key accepts
           no payload.
      
       (3) The ability to configure a list of blacklisted hashes into the kernel
           at build time.  This is done by setting
           CONFIG_SYSTEM_BLACKLIST_HASH_LIST to the filename of a list of hashes
           that are in the form:
      
      	"<hash>", "<hash>", ..., "<hash>"
      
           where each <hash> is a hex string representation of the hash and must
           include all necessary leading zeros to pad the hash to the right size.
      
      The above are enabled with CONFIG_SYSTEM_BLACKLIST_KEYRING.
      
      Once the kernel is booted, the blacklist keyring can be listed:
      
      	root@andromeda ~]# keyctl show %:.blacklist
      	Keyring
      	 723359729 ---lswrv      0     0  keyring: .blacklist
      	 676257228 ---lswrv      0     0   \_ blacklist: 123412341234c55c1dcc601ab8e172917706aa32fb5eaf826813547fdf02dd46
      
      The blacklist cannot currently be modified by userspace, but it will be
      possible to load it, for example, from the UEFI blacklist database.
      
      A later commit will make it possible to load blacklisted asymmetric keys in
      here too.
      
      Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
      734114f8
  13. Apr 11, 2016
    • David Howells's avatar
      certs: Add a secondary system keyring that can be added to dynamically · d3bfe841
      David Howells authored
      
      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: default avatarDavid Howells <dhowells@redhat.com>
      d3bfe841
    • David Howells's avatar
      KEYS: Remove KEY_FLAG_TRUSTED and KEY_ALLOC_TRUSTED · 77f68bac
      David Howells authored
      
      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: default avatarDavid Howells <dhowells@redhat.com>
      77f68bac
    • David Howells's avatar
      KEYS: Move the point of trust determination to __key_link() · a511e1af
      David Howells authored
      
      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: default avatarDavid Howells <dhowells@redhat.com>
      a511e1af
    • David Howells's avatar
      KEYS: Make the system trusted keyring depend on the asymmetric key type · 99716b7c
      David Howells authored
      
      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: default avatarDavid Howells <dhowells@redhat.com>
      99716b7c
    • David Howells's avatar
      KEYS: Add a facility to restrict new links into a keyring · 5ac7eace
      David Howells authored
      
      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: default avatarDavid Howells <dhowells@redhat.com>
      Reviewed-by: default avatarMimi Zohar <zohar@linux.vnet.ibm.com>
      5ac7eace
  14. Apr 06, 2016
    • David Howells's avatar
      PKCS#7: Make trust determination dependent on contents of trust keyring · bda850cd
      David Howells authored
      
      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: default avatarDavid Howells <dhowells@redhat.com>
      bda850cd
    • David Howells's avatar
      KEYS: Generalise system_verify_data() to provide access to internal content · e68503bd
      David Howells authored
      
      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: default avatarDavid Howells <dhowells@redhat.com>
      e68503bd
  15. Feb 29, 2016
  16. Feb 26, 2016
    • Mehmet Kayaalp's avatar
      KEYS: Reserve an extra certificate symbol for inserting without recompiling · c4c36105
      Mehmet Kayaalp authored
      
      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 <vmlinux> -c <certfile>
      
      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: default avatarMehmet Kayaalp <mkayaalp@linux.vnet.ibm.com>
      Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
      Acked-by: default avatarMimi Zohar <zohar@linux.vnet.ibm.com>
      c4c36105
    • Arnd Bergmann's avatar
      modsign: hide openssl output in silent builds · 5d06ee20
      Arnd Bergmann authored
      
      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: default avatarArnd Bergmann <arnd@arndb.de>
      Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
      5d06ee20
  17. Feb 09, 2016
  18. Oct 21, 2015
  19. Aug 14, 2015
    • David Woodhouse's avatar
      modsign: Handle signing key in source tree · 3ee550f1
      David Woodhouse authored
      
      Since commit 1329e8cc ("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: default avatarDavid Woodhouse <David.Woodhouse@intel.com>
      Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
      3ee550f1
    • David Woodhouse's avatar
      modsign: Use if_changed rule for extracting cert from module signing key · 62172c81
      David Woodhouse authored
      
      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: default avatarDavid Woodhouse <David.Woodhouse@intel.com>
      Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
      62172c81
    • David Howells's avatar
      Move certificate handling to its own directory · cfc411e7
      David Howells authored
      
      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: default avatarDavid Howells <dhowells@redhat.com>
      Reviewed-by: default avatarDavid Woodhouse <David.Woodhouse@intel.com>
      cfc411e7
Loading