projects/linux·commit f4f27d00

Merge branch 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security

f4f27d00 · Linus Torvalds <[email protected]> · 2016-05-19 09:21:36 -07:00

Pull security subsystem updates from James Morris:
 "Highlights:

   - A new LSM, "LoadPin", from Kees Cook is added, which allows forcing
     of modules and firmware to be loaded from a specific device (this
     is from ChromeOS, where the device as a whole is verified
     cryptographically via dm-verity).

     This is disabled by default but can be configured to be enabled by
     default (don't do this if you don't know what you're doing).

   - Keys: allow authentication data to be stored in an asymmetric key.
     Lots of general fixes and updates.

   - SELinux: add restrictions for loading of kernel modules via
     finit_module().  Distinguish non-init user namespace capability
     checks.  Apply execstack check on thread stacks"

* 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security: (48 commits)
  LSM: LoadPin: provide enablement CONFIG
  Yama: use atomic allocations when reporting
  seccomp: Fix comment typo
  ima: add support for creating files using the mknodat syscall
  ima: fix ima_inode_post_setattr
  vfs: forbid write access when reading a file into memory
  fs: fix over-zealous use of "const"
  selinux: apply execstack check on thread stacks
  selinux: distinguish non-init user namespace capability checks
  LSM: LoadPin for kernel file loading restrictions
  fs: define a string representation of the kernel_read_file_id enumeration
  Yama: consolidate error reporting
  string_helpers: add kstrdup_quotable_file
  string_helpers: add kstrdup_quotable_cmdline
  string_helpers: add kstrdup_quotable
  selinux: check ss_initialized before revalidating an inode label
  selinux: delay inode label lookup as long as possible
  selinux: don't revalidate an inode's label when explicitly setting it
  selinux: Change bool variable name to index.
  KEYS: Add KEYCTL_DH_COMPUTE command
  ...
Commit
f4f27d0028aabce57e44c16c2fdefccd6310d2f3
Parents
2600a46e · b937190c

Merge commit. Changes below are compared with the first parent: 2600a46e.

Changes

82 files changed · +1915 −807

FileStatusAddDelContent
Documentation/security/LoadPin.txtadded+17−0View file
Documentation/security/keys.txtmodified+52−0View file
MAINTAINERSmodified+6−0View file
arch/x86/kernel/kexec-bzimage64.cmodified+4−14View file
certs/Kconfigmodified+9−0View file
certs/system_keyring.cmodified+113−26View file
crypto/asymmetric_keys/Kconfigmodified+3−3View file
crypto/asymmetric_keys/Makefilemodified+4−1View file
crypto/asymmetric_keys/asymmetric_keys.hmodified+2−0View file
crypto/asymmetric_keys/asymmetric_type.cmodified+94−2View file
crypto/asymmetric_keys/mscode_parser.cmodified+7−14View file
crypto/asymmetric_keys/pkcs7_key_type.cmodified+28−44View file
crypto/asymmetric_keys/pkcs7_parser.cmodified+33−25View file
crypto/asymmetric_keys/pkcs7_parser.hmodified+4−7View file
crypto/asymmetric_keys/pkcs7_trust.cmodified+14−29View file
crypto/asymmetric_keys/pkcs7_verify.cmodified+46−61View file
crypto/asymmetric_keys/public_key.cmodified+14−6View file
crypto/asymmetric_keys/restrict.cadded+108−0View file
crypto/asymmetric_keys/signature.cmodified+18−0View file
crypto/asymmetric_keys/verify_pefile.cmodified+9−31View file
crypto/asymmetric_keys/verify_pefile.hmodified+2−3View file
crypto/asymmetric_keys/x509_cert_parser.cmodified+31−21View file
crypto/asymmetric_keys/x509_parser.hmodified+5−7View file
crypto/asymmetric_keys/x509_public_key.cmodified+82−215View file
fs/cifs/cifsacl.cmodified+1−1View file
fs/exec.cmodified+21−8View file
fs/namei.cmodified+2−0View file
fs/nfs/nfs4idmap.cmodified+1−1View file
include/crypto/pkcs7.hmodified+3−3View file
include/crypto/public_key.hmodified+12−21View file
include/keys/asymmetric-subtype.hmodified+1−1View file
include/keys/asymmetric-type.hmodified+10−3View file
include/keys/system_keyring.hmodified+15−26View file
include/linux/fs.hmodified+25−6View file
include/linux/ima.hmodified+6−0View file
include/linux/key-type.hmodified+0−1View file
include/linux/key.hmodified+33−11View file
include/linux/lsm_hooks.hmodified+5−1View file
include/linux/string_helpers.hmodified+6−0View file
include/linux/verification.hadded+49−0View file
include/linux/verify_pefile.hdeleted+0−22View before deletion
include/uapi/linux/keyctl.hmodified+10−0View file
kernel/module_signing.cmodified+4−3View file
kernel/seccomp.cmodified+1−1View file
lib/string_helpers.cmodified+92−0View file
net/dns_resolver/dns_key.cmodified+1−1View file
net/netlabel/netlabel_kapi.cmodified+1−1View file
net/rxrpc/ar-key.cmodified+2−2View file
security/Kconfigmodified+1−0View file
security/Makefilemodified+2−0View file
security/integrity/Kconfigmodified+0−1View file
security/integrity/digsig.cmodified+11−4View file
security/integrity/ima/Kconfigmodified+23−13View file
security/integrity/ima/Makefilemodified+1−1View file
security/integrity/ima/ima_appraise.cmodified+6−1View file
security/integrity/ima/ima_main.cmodified+24−1View file
security/integrity/ima/ima_mok.cmodified+7−16View file
security/integrity/integrity.hmodified+1−0View file
security/keys/Kconfigmodified+15−0View file
security/keys/Makefilemodified+1−0View file
security/keys/big_key.cmodified+180−18View file
security/keys/compat.cmodified+4−0View file
security/keys/dh.cadded+160−0View file
security/keys/internal.hmodified+12−0View file
security/keys/key.cmodified+32−10View file
security/keys/keyctl.cmodified+5−0View file
security/keys/keyring.cmodified+39−7View file
security/keys/persistent.cmodified+2−2View file
security/keys/process_keys.cmodified+10−6View file
security/keys/request_key.cmodified+2−2View file
security/keys/request_key_auth.cmodified+1−1View file
security/keys/user_defined.cmodified+11−31View file
security/loadpin/Kconfigadded+19−0View file
security/loadpin/Makefileadded+1−0View file
security/loadpin/loadpin.cadded+190−0View file
security/security.cmodified+1−1View file
security/selinux/hooks.cmodified+102−42View file
security/selinux/include/classmap.hmodified+19−11View file
security/selinux/include/conditional.hmodified+1−1View file
security/selinux/include/objsec.hmodified+2−3View file
security/selinux/ss/services.cmodified+3−3View file
security/yama/yama_lsm.cmodified+21−10View file

Only the first 600 diff lines are shown. Download the complete patch.

Documentation/security/LoadPin.txt

View file
diff --git a/Documentation/security/LoadPin.txt b/Documentation/security/LoadPin.txt
new file mode 100644
index 0000000..e11877f
--- /dev/null
+++ b/Documentation/security/LoadPin.txt
@@ -0,0 +1,17 @@
+LoadPin is a Linux Security Module that ensures all kernel-loaded files
+(modules, firmware, etc) all originate from the same filesystem, with
+the expectation that such a filesystem is backed by a read-only device
+such as dm-verity or CDROM. This allows systems that have a verified
+and/or unchangeable filesystem to enforce module and firmware loading
+restrictions without needing to sign the files individually.
+
+The LSM is selectable at build-time with CONFIG_SECURITY_LOADPIN, and
+can be controlled at boot-time with the kernel command line option
+"loadpin.enabled". By default, it is enabled, but can be disabled at
+boot ("loadpin.enabled=0").
+
+LoadPin starts pinning when it sees the first file loaded. If the
+block device backing the filesystem is not read-only, a sysctl is
+created to toggle pinning: /proc/sys/kernel/loadpin/enabled. (Having
+a mutable filesystem means pinning is mutable too, but having the
+sysctl allows for easy testing on systems with a mutable filesystem.)

Documentation/security/keys.txt

View file
diff --git a/Documentation/security/keys.txt b/Documentation/security/keys.txt
index 8c18387..20d0571 100644
--- a/Documentation/security/keys.txt
+++ b/Documentation/security/keys.txt
@@ -823,6 +823,36 @@ The keyctl syscall functions are:
A process must have search permission on the key for this function to be
successful.
+ (*) Compute a Diffie-Hellman shared secret or public key
+
+ long keyctl(KEYCTL_DH_COMPUTE, struct keyctl_dh_params *params,
+ char *buffer, size_t buflen);
+
+ The params struct contains serial numbers for three keys:
+
+ - The prime, p, known to both parties
+ - The local private key
+ - The base integer, which is either a shared generator or the
+ remote public key
+
+ The value computed is:
+
+ result = base ^ private (mod prime)
+
+ If the base is the shared generator, the result is the local
+ public key. If the base is the remote public key, the result is
+ the shared secret.
+
+ The buffer length must be at least the length of the prime, or zero.
+
+ If the buffer length is nonzero, the length of the result is
+ returned when it is successfully calculated and copied in to the
+ buffer. When the buffer length is zero, the minimum required
+ buffer length is returned.
+
+ This function will return error EOPNOTSUPP if the key type is not
+ supported, error ENOKEY if the key could not be found, or error
+ EACCES if the key is not readable by the caller.
===============
KERNEL SERVICES
@@ -999,6 +1029,10 @@ payload contents" for more information.
struct key *keyring_alloc(const char *description, uid_t uid, gid_t gid,
const struct cred *cred,
key_perm_t perm,
+ int (*restrict_link)(struct key *,
+ const struct key_type *,
+ unsigned long,
+ const union key_payload *),
unsigned long flags,
struct key *dest);
@@ -1010,6 +1044,24 @@ payload contents" for more information.
KEY_ALLOC_NOT_IN_QUOTA in flags if the keyring shouldn't be accounted
towards the user's quota). Error ENOMEM can also be returned.
+ If restrict_link not NULL, it should point to a function that will be
+ called each time an attempt is made to link a key into the new keyring.
+ This function is called to check whether a key may be added into the keying
+ or not. Callers of key_create_or_update() within the kernel can pass
+ KEY_ALLOC_BYPASS_RESTRICTION to suppress the check. An example of using
+ this is to manage rings of cryptographic keys that are set up when the
+ kernel boots where userspace is also permitted to add keys - provided they
+ can be verified by a key the kernel already has.
+
+ When called, the restriction function will be passed the keyring being
+ added to, the key flags value and the type and payload of the key being
+ added. Note that when a new key is being created, this is called between
+ payload preparsing and actual key creation. The function should return 0
+ to allow the link or an error to reject it.
+
+ A convenience function, restrict_link_reject, exists to always return
+ -EPERM to in this case.
+
(*) To check the validity of a key, this function can be called:

MAINTAINERS

View file
diff --git a/MAINTAINERS b/MAINTAINERS
index add406a..71bcef4 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -10025,6 +10025,12 @@ T: git git://git.kernel.org/pub/scm/linux/kernel/git/jj/apparmor-dev.git
S: Supported
F: security/apparmor/
+LOADPIN SECURITY MODULE
+M: Kees Cook <[email protected]>
+T: git git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git lsm/loadpin
+S: Supported
+F: security/loadpin/
+
YAMA SECURITY MODULE
M: Kees Cook <[email protected]>
T: git git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git yama/tip

arch/x86/kernel/kexec-bzimage64.c

View file
diff --git a/arch/x86/kernel/kexec-bzimage64.c b/arch/x86/kernel/kexec-bzimage64.c
index 2af478e..f2356bd 100644
--- a/arch/x86/kernel/kexec-bzimage64.c
+++ b/arch/x86/kernel/kexec-bzimage64.c
@@ -19,8 +19,7 @@
#include <linux/kernel.h>
#include <linux/mm.h>
#include <linux/efi.h>
-#include <linux/verify_pefile.h>
-#include <keys/system_keyring.h>
+#include <linux/verification.h>
#include <asm/bootparam.h>
#include <asm/setup.h>
@@ -529,18 +528,9 @@ static int bzImage64_cleanup(void *loader_data)
#ifdef CONFIG_KEXEC_BZIMAGE_VERIFY_SIG
static int bzImage64_verify_sig(const char *kernel, unsigned long kernel_len)
{
- bool trusted;
- int ret;
-
- ret = verify_pefile_signature(kernel, kernel_len,
- system_trusted_keyring,
- VERIFYING_KEXEC_PE_SIGNATURE,
- &trusted);
- if (ret < 0)
- return ret;
- if (!trusted)
- return -EKEYREJECTED;
- return 0;
+ return verify_pefile_signature(kernel, kernel_len,
+ NULL,
+ VERIFYING_KEXEC_PE_SIGNATURE);
}
#endif

certs/Kconfig

View file
diff --git a/certs/Kconfig b/certs/Kconfig
index f0f8a44..fc5955f 100644
--- a/certs/Kconfig
+++ b/certs/Kconfig
@@ -17,6 +17,7 @@ config MODULE_SIG_KEY
config SYSTEM_TRUSTED_KEYRING
bool "Provide system-wide ring of trusted keys"
depends on KEYS
+ depends on ASYMMETRIC_KEY_TYPE
help
Provide a system keyring to which trusted keys can be added. Keys in
the keyring are considered to be trusted. Keys may be added at will
@@ -55,4 +56,12 @@ config SYSTEM_EXTRA_CERTIFICATE_SIZE
This is the number of bytes reserved in the kernel image for a
certificate to be inserted.
+config SECONDARY_TRUSTED_KEYRING
+ bool "Provide a keyring to which extra trustable keys may be added"
+ depends on SYSTEM_TRUSTED_KEYRING
+ help
+ If set, provide a keyring to which extra keys may be added, provided
+ those keys are not blacklisted and are vouched for by a key built
+ into the kernel or already in the secondary trusted keyring.
+
endmenu

certs/system_keyring.c

View file
diff --git a/certs/system_keyring.c b/certs/system_keyring.c
index f418032..50979d6 100644
--- a/certs/system_keyring.c
+++ b/certs/system_keyring.c
@@ -18,29 +18,88 @@
#include <keys/system_keyring.h>
#include <crypto/pkcs7.h>
-struct key *system_trusted_keyring;
-EXPORT_SYMBOL_GPL(system_trusted_keyring);
+static struct key *builtin_trusted_keys;
+#ifdef CONFIG_SECONDARY_TRUSTED_KEYRING
+static struct key *secondary_trusted_keys;
+#endif
extern __initconst const u8 system_certificate_list[];
extern __initconst const unsigned long system_certificate_list_size;
+/**
+ * restrict_link_to_builtin_trusted - Restrict keyring addition by built in CA
+ *
+ * Restrict the addition of keys into a keyring based on the key-to-be-added
+ * being vouched for by a key in the built in system keyring.
+ */
+int restrict_link_by_builtin_trusted(struct key *keyring,
+ const struct key_type *type,
+ const union key_payload *payload)
+{
+ return restrict_link_by_signature(builtin_trusted_keys, type, payload);
+}
+
+#ifdef CONFIG_SECONDARY_TRUSTED_KEYRING
+/**
+ * restrict_link_by_builtin_and_secondary_trusted - Restrict keyring
+ * addition by both builtin and secondary keyrings
+ *
+ * Restrict the addition of keys into a keyring based on the key-to-be-added
+ * being vouched for by a key in either the built-in or the secondary system
+ * keyrings.
+ */
+int restrict_link_by_builtin_and_secondary_trusted(
+ struct key *keyring,
+ const struct key_type *type,
+ const union key_payload *payload)
+{
+ /* If we have a secondary trusted keyring, then that contains a link
+ * through to the builtin keyring and the search will follow that link.
+ */
+ if (type == &key_type_keyring &&
+ keyring == secondary_trusted_keys &&
+ payload == &builtin_trusted_keys->payload)
+ /* Allow the builtin keyring to be added to the secondary */
+ return 0;
+
+ return restrict_link_by_signature(secondary_trusted_keys, type, payload);
+}
+#endif
+
/*
- * Load the compiled-in keys
+ * Create the trusted keyrings
*/
static __init int system_trusted_keyring_init(void)
{
- pr_notice("Initialise system trusted keyring\n");
+ pr_notice("Initialise system trusted keyrings\n");
- system_trusted_keyring =
- keyring_alloc(".system_keyring",
+ builtin_trusted_keys =
+ keyring_alloc(".builtin_trusted_keys",
KUIDT_INIT(0), KGIDT_INIT(0), current_cred(),
((KEY_POS_ALL & ~KEY_POS_SETATTR) |
KEY_USR_VIEW | KEY_USR_READ | KEY_USR_SEARCH),
- KEY_ALLOC_NOT_IN_QUOTA, NULL);
- if (IS_ERR(system_trusted_keyring))
- panic("Can't allocate system trusted keyring\n");
+ KEY_ALLOC_NOT_IN_QUOTA,
+ NULL, NULL);
+ if (IS_ERR(builtin_trusted_keys))
+ panic("Can't allocate builtin trusted keyring\n");
+
+#ifdef CONFIG_SECONDARY_TRUSTED_KEYRING
+ secondary_trusted_keys =
+ keyring_alloc(".secondary_trusted_keys",
+ KUIDT_INIT(0), KGIDT_INIT(0), current_cred(),
+ ((KEY_POS_ALL & ~KEY_POS_SETATTR) |
+ KEY_USR_VIEW | KEY_USR_READ | KEY_USR_SEARCH |
+ KEY_USR_WRITE),
+ KEY_ALLOC_NOT_IN_QUOTA,
+ restrict_link_by_builtin_and_secondary_trusted,
+ NULL);
+ if (IS_ERR(secondary_trusted_keys))
+ panic("Can't allocate secondary trusted keyring\n");
+
+ if (key_link(secondary_trusted_keys, builtin_trusted_keys) < 0)
+ panic("Can't link trusted keyrings\n");
+#endif
- set_bit(KEY_FLAG_TRUSTED_ONLY, &system_trusted_keyring->flags);
return 0;
}
@@ -76,7 +135,7 @@ static __init int load_system_certificate_list(void)
if (plen > end - p)
goto dodgy_cert;
- key = key_create_or_update(make_key_ref(system_trusted_keyring, 1),
+ key = key_create_or_update(make_key_ref(builtin_trusted_keys, 1),
"asymmetric",
NULL,
p,
@@ -84,8 +143,8 @@ static __init int load_system_certificate_list(void)
((KEY_POS_ALL & ~KEY_POS_SETATTR) |
KEY_USR_VIEW | KEY_USR_READ),
KEY_ALLOC_NOT_IN_QUOTA |
- KEY_ALLOC_TRUSTED |
- KEY_ALLOC_BUILT_IN);
+ KEY_ALLOC_BUILT_IN |
+ KEY_ALLOC_BYPASS_RESTRICTION);
if (IS_ERR(key)) {
pr_err("Problem loading in-kernel X.509 certificate (%ld)\n",
PTR_ERR(key));
@@ -108,19 +167,27 @@ late_initcall(load_system_certificate_list);
#ifdef CONFIG_SYSTEM_DATA_VERIFICATION
/**
- * Verify a PKCS#7-based signature on system data.
- * @data: The data to be verified.
+ * verify_pkcs7_signature - Verify a PKCS#7-based signature on system data.
+ * @data: The data to be verified (NULL if expecting internal data).
* @len: Size of @data.
* @raw_pkcs7: The PKCS#7 message that is the signature.
* @pkcs7_len: The size of @raw_pkcs7.
+ * @trusted_keys: Trusted keys to use (NULL for builtin trusted keys only,
+ * (void *)1UL for all trusted keys).
* @usage: The use to which the key is being put.
+ * @view_content: Callback to gain access to content.
+ * @ctx: Context for callback.
*/
-int system_verify_data(const void *data, unsigned long len,
- const void *raw_pkcs7, size_t pkcs7_len,
- enum key_being_used_for usage)
+int verify_pkcs7_signature(const void *data, size_t len,
+ const void *raw_pkcs7, size_t pkcs7_len,
+ struct key *trusted_keys,
+ enum key_being_used_for usage,
+ int (*view_content)(void *ctx,
+ const void *data, size_t len,
+ size_t asn1hdrlen),
+ void *ctx)
{
struct pkcs7_message *pkcs7;
- bool trusted;
int ret;
pkcs7 = pkcs7_parse_message(raw_pkcs7, pkcs7_len);
@@ -128,7 +195,7 @@ int system_verify_data(const void *data, unsigned long len,
return PTR_ERR(pkcs7);
/* The data should be detached - so we need to supply it. */
- if (pkcs7_supply_detached_data(pkcs7, data, len) < 0) {
+ if (data && pkcs7_supply_detached_data(pkcs7, data, len) < 0) {
pr_err("PKCS#7 signature with non-detached data\n");
ret = -EBADMSG;
goto error;
@@ -138,13 +205,33 @@ int system_verify_data(const void *data, unsigned long len,
if (ret < 0)
goto error;
- ret = pkcs7_validate_trust(pkcs7, system_trusted_keyring, &trusted);
- if (ret < 0)
+ if (!trusted_keys) {
+ trusted_keys = builtin_trusted_keys;
+ } else if (trusted_keys == (void *)1UL) {
+#ifdef CONFIG_SECONDARY_TRUSTED_KEYRING
+ trusted_keys = secondary_trusted_keys;
+#else
+ trusted_keys = builtin_trusted_keys;
+#endif
+ }
+ ret = pkcs7_validate_trust(pkcs7, trusted_keys);
+ if (ret < 0) {
+ if (ret == -ENOKEY)
+ pr_err("PKCS#7 signature not signed with a trusted key\n");
goto error;
+ }
+
+ if (view_content) {
+ size_t asn1hdrlen;
+
+ ret = pkcs7_get_content_data(pkcs7, &data, &len, &asn1hdrlen);
+ if (ret < 0) {
+ if (ret == -ENODATA)
+ pr_devel("PKCS#7 message does not contain data\n");
+ goto error;
+ }
- if (!trusted) {
- pr_err("PKCS#7 signature not signed with a trusted key\n");
- ret = -ENOKEY;
+ ret = view_content(ctx, data, len, asn1hdrlen);
}
error:
@@ -152,6 +239,6 @@ error:
pr_devel("<==%s() = %d\n", __func__, ret);
return ret;
}
-EXPORT_SYMBOL_GPL(system_verify_data);
+EXPORT_SYMBOL_GPL(verify_pkcs7_signature);
#endif /* CONFIG_SYSTEM_DATA_VERIFICATION */

crypto/asymmetric_keys/Kconfig

View file
diff --git a/crypto/asymmetric_keys/Kconfig b/crypto/asymmetric_keys/Kconfig
index 91a7e04..e28e912 100644
--- a/crypto/asymmetric_keys/Kconfig
+++ b/crypto/asymmetric_keys/Kconfig
@@ -1,5 +1,5 @@
menuconfig ASYMMETRIC_KEY_TYPE
- tristate "Asymmetric (public-key cryptographic) key type"
+ bool "Asymmetric (public-key cryptographic) key type"
depends on KEYS
help
This option provides support for a key type that holds the data for
@@ -40,8 +40,7 @@ config PKCS7_MESSAGE_PARSER
config PKCS7_TEST_KEY
tristate "PKCS#7 testing key type"
- depends on PKCS7_MESSAGE_PARSER
- select SYSTEM_TRUSTED_KEYRING
+ depends on SYSTEM_DATA_VERIFICATION
help
This option provides a type of key that can be loaded up from a
PKCS#7 message - provided the message is signed by a trusted key. If
@@ -54,6 +53,7 @@ config PKCS7_TEST_KEY
config SIGNED_PE_FILE_VERIFICATION
bool "Support for PE file signature verification"
depends on PKCS7_MESSAGE_PARSER=y
+ depends on SYSTEM_DATA_VERIFICATION
select ASN1
select OID_REGISTRY
help

crypto/asymmetric_keys/Makefile

View file
diff --git a/crypto/asymmetric_keys/Makefile b/crypto/asymmetric_keys/Makefile
index f904862..6516855 100644
--- a/crypto/asymmetric_keys/Makefile
+++ b/crypto/asymmetric_keys/Makefile
@@ -4,7 +4,10 @@
obj-$(CONFIG_ASYMMETRIC_KEY_TYPE) += asymmetric_keys.o
-asymmetric_keys-y := asymmetric_type.o signature.o
+asymmetric_keys-y := \
+ asymmetric_type.o \
+ restrict.o \
+ signature.o
obj-$(CONFIG_ASYMMETRIC_PUBLIC_KEY_SUBTYPE) += public_key.o

crypto/asymmetric_keys/asymmetric_keys.h

View file
diff --git a/crypto/asymmetric_keys/asymmetric_keys.h b/crypto/asymmetric_keys/asymmetric_keys.h
index 1d450b5..ca8e9ac 100644
--- a/crypto/asymmetric_keys/asymmetric_keys.h
+++ b/crypto/asymmetric_keys/asymmetric_keys.h
@@ -9,6 +9,8 @@
* 2 of the Licence, or (at your option) any later version.
*/
+#include <keys/asymmetric-type.h>
+
extern struct asymmetric_key_id *asymmetric_key_hex_to_key_id(const char *id);
extern int __asymmetric_key_hex_to_key_id(const char *id,

crypto/asymmetric_keys/asymmetric_type.c

View file
diff --git a/crypto/asymmetric_keys/asymmetric_type.c b/crypto/asymmetric_keys/asymmetric_type.c
index 9f2165b..6600181 100644
--- a/crypto/asymmetric_keys/asymmetric_type.c
+++ b/crypto/asymmetric_keys/asymmetric_type.c
@@ -35,6 +35,95 @@ static LIST_HEAD(asymmetric_key_parsers);
static DECLARE_RWSEM(asymmetric_key_parsers_sem);
/**
+ * find_asymmetric_key - Find a key by ID.
+ * @keyring: The keys to search.
+ * @id_0: The first ID to look for or NULL.
+ * @id_1: The second ID to look for or NULL.
+ * @partial: Use partial match if true, exact if false.
+ *
+ * Find a key in the given keyring by identifier. The preferred identifier is
+ * the id_0 and the fallback identifier is the id_1. If both are given, the
+ * lookup is by the former, but the latter must also match.
+ */
+struct key *find_asymmetric_key(struct key *keyring,
+ const struct asymmetric_key_id *id_0,
+ const struct asymmetric_key_id *id_1,
+ bool partial)
+{
+ struct key *key;
+ key_ref_t ref;
+ const char *lookup;
+ char *req, *p;
+ int len;
+
+ if (id_0) {
+ lookup = id_0->data;
+ len = id_0->len;
+ } else {
+ lookup = id_1->data;
+ len = id_1->len;
+ }
+
+ /* Construct an identifier "id:<keyid>". */
+ p = req = kmalloc(2 + 1 + len * 2 + 1, GFP_KERNEL);
+ if (!req)
+ return ERR_PTR(-ENOMEM);
+
+ if (partial) {
+ *p++ = 'i';
+ *p++ = 'd';
+ } else {
+ *p++ = 'e';
+ *p++ = 'x';
+ }
+ *p++ = ':';
+ p = bin2hex(p, lookup, len);
+ *p = 0;
+
+ pr_debug("Look up: \"%s\"\n", req);
+
+ ref = keyring_search(make_key_ref(keyring, 1),
+ &key_type_asymmetric, req);
+ if (IS_ERR(ref))
+ pr_debug("Request for key '%s' err %ld\n", req, PTR_ERR(ref));
+ kfree(req);
+
+ if (IS_ERR(ref)) {
+ switch (PTR_ERR(ref)) {
+ /* Hide some search errors */
+ case -EACCES:
+ case -ENOTDIR:
+ case -EAGAIN:
+ return ERR_PTR(-ENOKEY);
+ default:
+ return ERR_CAST(ref);
+ }
+ }
+
+ key = key_ref_to_ptr(ref);
+ if (id_0 && id_1) {
+ const struct asymmetric_key_ids *kids = asymmetric_key_ids(key);
+
+ if (!kids->id[0]) {
+ pr_debug("First ID matches, but second is missing\n");
+ goto reject;
+ }
+ if (!asymmetric_key_id_same(id_1, kids->id[1])) {
+ pr_debug("First ID matches, but second does not\n");
+ goto reject;
+ }
+ }
+
+ pr_devel("<==%s() = 0 [%x]\n", __func__, key_serial(key));
+ return key;
+
+reject:
+ key_put(key);
+ return ERR_PTR(-EKEYREJECTED);
+}
+EXPORT_SYMBOL_GPL(find_asymmetric_key);
+
+/**
* asymmetric_key_generate_id: Construct an asymmetric key ID
* @val_1: First binary blob
* @len_1: Length of first binary blob
@@ -331,7 +420,8 @@ static void asymmetric_key_free_preparse(struct key_preparsed_payload *prep)
pr_devel("==>%s()\n", __func__);
if (subtype) {
- subtype->destroy(prep->payload.data[asym_crypto]);
+ subtype->destroy(prep->payload.data[asym_crypto],
+ prep->payload.data[asym_auth]);
module_put(subtype->owner);
}
asymmetric_key_free_kids(kids);
@@ -346,13 +436,15 @@ static void asymmetric_key_destroy(struct key *key)
struct asymmetric_key_subtype *subtype = asymmetric_key_subtype(key);
struct asymmetric_key_ids *kids = key->payload.data[asym_key_ids];
void *data = key->payload.data[asym_crypto];
+ void *auth = key->payload.data[asym_auth];
key->payload.data[asym_crypto] = NULL;
key->payload.data[asym_subtype] = NULL;
key->payload.data[asym_key_ids] = NULL;
+ key->payload.data[asym_auth] = NULL;
if (subtype) {
- subtype->destroy(data);
+ subtype->destroy(data, auth);
module_put(subtype->owner);
}

crypto/asymmetric_keys/mscode_parser.c

View file
diff --git a/crypto/asymmetric_keys/mscode_parser.c b/crypto/asymmetric_keys/mscode_parser.c
index 3242cbf..6a76d5c 100644
--- a/crypto/asymmetric_keys/mscode_parser.c
+++ b/crypto/asymmetric_keys/mscode_parser.c
@@ -21,19 +21,13 @@
/*
* Parse a Microsoft Individual Code Signing blob
*/
-int mscode_parse(struct pefile_context *ctx)
+int mscode_parse(void *_ctx, const void *content_data, size_t data_len,
+ size_t asn1hdrlen)
{
- const void *content_data;
- size_t data_len;
- int ret;
-
- ret = pkcs7_get_content_data(ctx->pkcs7, &content_data, &data_len, 1);
-
- if (ret) {
- pr_debug("PKCS#7 message does not contain data\n");
- return ret;
- }
+ struct pefile_context *ctx = _ctx;

This diff is incomplete. Download the complete patch.

crypto/asymmetric_keys/pkcs7_key_type.c

View file

This diff is incomplete. Download the complete patch.

crypto/asymmetric_keys/pkcs7_parser.c

View file

This diff is incomplete. Download the complete patch.

crypto/asymmetric_keys/pkcs7_parser.h

View file

This diff is incomplete. Download the complete patch.

crypto/asymmetric_keys/pkcs7_trust.c

View file

This diff is incomplete. Download the complete patch.

crypto/asymmetric_keys/pkcs7_verify.c

View file

This diff is incomplete. Download the complete patch.

crypto/asymmetric_keys/public_key.c

View file

This diff is incomplete. Download the complete patch.

crypto/asymmetric_keys/restrict.c

View file

This diff is incomplete. Download the complete patch.

crypto/asymmetric_keys/signature.c

View file

This diff is incomplete. Download the complete patch.

crypto/asymmetric_keys/verify_pefile.c

View file

This diff is incomplete. Download the complete patch.

crypto/asymmetric_keys/verify_pefile.h

View file

This diff is incomplete. Download the complete patch.

crypto/asymmetric_keys/x509_cert_parser.c

View file

This diff is incomplete. Download the complete patch.

crypto/asymmetric_keys/x509_parser.h

View file

This diff is incomplete. Download the complete patch.

crypto/asymmetric_keys/x509_public_key.c

View file

This diff is incomplete. Download the complete patch.

fs/cifs/cifsacl.c

View file

This diff is incomplete. Download the complete patch.

fs/exec.c

View file

This diff is incomplete. Download the complete patch.

fs/namei.c

View file

This diff is incomplete. Download the complete patch.

fs/nfs/nfs4idmap.c

View file

This diff is incomplete. Download the complete patch.

include/crypto/pkcs7.h

View file

This diff is incomplete. Download the complete patch.

include/crypto/public_key.h

View file

This diff is incomplete. Download the complete patch.

include/keys/asymmetric-subtype.h

View file

This diff is incomplete. Download the complete patch.

include/keys/asymmetric-type.h

View file

This diff is incomplete. Download the complete patch.

include/keys/system_keyring.h

View file

This diff is incomplete. Download the complete patch.

include/linux/fs.h

View file

This diff is incomplete. Download the complete patch.

include/linux/ima.h

View file

This diff is incomplete. Download the complete patch.

include/linux/key-type.h

View file

This diff is incomplete. Download the complete patch.

include/linux/key.h

View file

This diff is incomplete. Download the complete patch.

include/linux/lsm_hooks.h

View file

This diff is incomplete. Download the complete patch.

include/linux/string_helpers.h

View file

This diff is incomplete. Download the complete patch.

include/linux/verification.h

View file

This diff is incomplete. Download the complete patch.

include/linux/verify_pefile.h

View before deletion

This diff is incomplete. Download the complete patch.

include/uapi/linux/keyctl.h

View file

This diff is incomplete. Download the complete patch.

kernel/module_signing.c

View file

This diff is incomplete. Download the complete patch.

kernel/seccomp.c

View file

This diff is incomplete. Download the complete patch.

lib/string_helpers.c

View file

This diff is incomplete. Download the complete patch.

net/dns_resolver/dns_key.c

View file

This diff is incomplete. Download the complete patch.

net/netlabel/netlabel_kapi.c

View file

This diff is incomplete. Download the complete patch.

net/rxrpc/ar-key.c

View file

This diff is incomplete. Download the complete patch.

security/Kconfig

View file

This diff is incomplete. Download the complete patch.

security/Makefile

View file

This diff is incomplete. Download the complete patch.

security/integrity/Kconfig

View file

This diff is incomplete. Download the complete patch.

security/integrity/digsig.c

View file

This diff is incomplete. Download the complete patch.

security/integrity/ima/Kconfig

View file

This diff is incomplete. Download the complete patch.

security/integrity/ima/Makefile

View file

This diff is incomplete. Download the complete patch.

security/integrity/ima/ima_appraise.c

View file

This diff is incomplete. Download the complete patch.

security/integrity/ima/ima_main.c

View file

This diff is incomplete. Download the complete patch.

security/integrity/ima/ima_mok.c

View file

This diff is incomplete. Download the complete patch.

security/integrity/integrity.h

View file

This diff is incomplete. Download the complete patch.

security/keys/Kconfig

View file

This diff is incomplete. Download the complete patch.

security/keys/Makefile

View file

This diff is incomplete. Download the complete patch.

security/keys/big_key.c

View file

This diff is incomplete. Download the complete patch.

security/keys/compat.c

View file

This diff is incomplete. Download the complete patch.

security/keys/dh.c

View file

This diff is incomplete. Download the complete patch.

security/keys/internal.h

View file

This diff is incomplete. Download the complete patch.

security/keys/key.c

View file

This diff is incomplete. Download the complete patch.

security/keys/keyctl.c

View file

This diff is incomplete. Download the complete patch.

security/keys/keyring.c

View file

This diff is incomplete. Download the complete patch.

security/keys/persistent.c

View file

This diff is incomplete. Download the complete patch.

security/keys/process_keys.c

View file

This diff is incomplete. Download the complete patch.

security/keys/request_key.c

View file

This diff is incomplete. Download the complete patch.

security/keys/request_key_auth.c

View file

This diff is incomplete. Download the complete patch.

security/keys/user_defined.c

View file

This diff is incomplete. Download the complete patch.

security/loadpin/Kconfig

View file

This diff is incomplete. Download the complete patch.

security/loadpin/Makefile

View file

This diff is incomplete. Download the complete patch.

security/loadpin/loadpin.c

View file

This diff is incomplete. Download the complete patch.

security/security.c

View file

This diff is incomplete. Download the complete patch.

security/selinux/hooks.c

View file

This diff is incomplete. Download the complete patch.

security/selinux/include/classmap.h

View file

This diff is incomplete. Download the complete patch.

security/selinux/include/conditional.h

View file

This diff is incomplete. Download the complete patch.

security/selinux/include/objsec.h

View file

This diff is incomplete. Download the complete patch.

security/selinux/ss/services.c

View file

This diff is incomplete. Download the complete patch.

security/yama/yama_lsm.c

View file

This diff is incomplete. Download the complete patch.