Blame view
kernel/module_signing.c
2.21 KB
106a4ee25 module: signature... |
1 2 3 4 5 6 7 8 9 10 11 12 |
/* Module signature checker * * Copyright (C) 2012 Red Hat, Inc. All Rights Reserved. * Written by David Howells (dhowells@redhat.com) * * 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. */ #include <linux/kernel.h> |
146aa8b14 KEYS: Merge the t... |
13 |
#include <linux/errno.h> |
89053aa9c MODSIGN: linux/st... |
14 |
#include <linux/string.h> |
a511e1af8 KEYS: Move the po... |
15 |
#include <linux/verification.h> |
3f1e1bea3 MODSIGN: Use PKCS... |
16 |
#include <crypto/public_key.h> |
106a4ee25 module: signature... |
17 |
#include "module-internal.h" |
4e8ae72a7 X.509: Make algo ... |
18 19 20 21 22 |
enum pkey_id_type { PKEY_ID_PGP, /* OpenPGP generated key ID */ PKEY_ID_X509, /* X.509 arbitrary subjectKeyIdentifier */ PKEY_ID_PKCS7, /* Signature in PKCS#7 message */ }; |
106a4ee25 module: signature... |
23 |
/* |
48ba2462a MODSIGN: Implemen... |
24 25 26 27 28 29 30 31 32 33 |
* Module signature information block. * * The constituents of the signature section are, in order: * * - Signer's name * - Key identifier * - Signature data * - Information block */ struct module_signature { |
3f1e1bea3 MODSIGN: Use PKCS... |
34 35 36 37 38 |
u8 algo; /* Public-key crypto algorithm [0] */ u8 hash; /* Digest algorithm [0] */ u8 id_type; /* Key identifier type [PKEY_ID_PKCS7] */ u8 signer_len; /* Length of signer's name [0] */ u8 key_id_len; /* Length of key identifier [0] */ |
12e130b04 MODSIGN: Don't us... |
39 40 |
u8 __pad[3]; __be32 sig_len; /* Length of signature data */ |
48ba2462a MODSIGN: Implemen... |
41 42 43 |
}; /* |
106a4ee25 module: signature... |
44 45 |
* Verify the signature on a module. */ |
caabe2405 MODSIGN: Move the... |
46 |
int mod_verify_sig(const void *mod, unsigned long *_modlen) |
106a4ee25 module: signature... |
47 |
{ |
48ba2462a MODSIGN: Implemen... |
48 |
struct module_signature ms; |
caabe2405 MODSIGN: Move the... |
49 |
size_t modlen = *_modlen, sig_len; |
48ba2462a MODSIGN: Implemen... |
50 |
|
0390c8835 module_signing: f... |
51 52 |
pr_devel("==>%s(,%zu) ", __func__, modlen); |
48ba2462a MODSIGN: Implemen... |
53 |
|
caabe2405 MODSIGN: Move the... |
54 |
if (modlen <= sizeof(ms)) |
48ba2462a MODSIGN: Implemen... |
55 |
return -EBADMSG; |
caabe2405 MODSIGN: Move the... |
56 57 |
memcpy(&ms, mod + (modlen - sizeof(ms)), sizeof(ms)); modlen -= sizeof(ms); |
48ba2462a MODSIGN: Implemen... |
58 59 |
sig_len = be32_to_cpu(ms.sig_len); |
caabe2405 MODSIGN: Move the... |
60 |
if (sig_len >= modlen) |
48ba2462a MODSIGN: Implemen... |
61 |
return -EBADMSG; |
caabe2405 MODSIGN: Move the... |
62 |
modlen -= sig_len; |
caabe2405 MODSIGN: Move the... |
63 |
*_modlen = modlen; |
48ba2462a MODSIGN: Implemen... |
64 |
|
3f1e1bea3 MODSIGN: Use PKCS... |
65 66 67 |
if (ms.id_type != PKEY_ID_PKCS7) { pr_err("Module is not signed with expected PKCS#7 message "); |
48ba2462a MODSIGN: Implemen... |
68 |
return -ENOPKG; |
48ba2462a MODSIGN: Implemen... |
69 |
} |
3f1e1bea3 MODSIGN: Use PKCS... |
70 71 72 73 74 75 76 77 78 79 80 |
if (ms.algo != 0 || ms.hash != 0 || ms.signer_len != 0 || ms.key_id_len != 0 || ms.__pad[0] != 0 || ms.__pad[1] != 0 || ms.__pad[2] != 0) { pr_err("PKCS#7 signature info has unexpected non-zero params "); return -EBADMSG; } |
48ba2462a MODSIGN: Implemen... |
81 |
|
e68503bd6 KEYS: Generalise ... |
82 |
return verify_pkcs7_signature(mod, modlen, mod + modlen, sig_len, |
bda850cd2 PKCS#7: Make trus... |
83 |
NULL, VERIFYING_MODULE_SIGNATURE, |
e68503bd6 KEYS: Generalise ... |
84 |
NULL, NULL); |
106a4ee25 module: signature... |
85 |
} |