1 /* Module signature checker
3 * Copyright (C) 2012 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public Licence
8 * as published by the Free Software Foundation; either version
9 * 2 of the Licence, or (at your option) any later version.
12 #include <linux/kernel.h>
13 #include <keys/system_keyring.h>
14 #include <crypto/public_key.h>
15 #include "module-internal.h"
18 * Module signature information block.
20 * The constituents of the signature section are, in order:
27 struct module_signature {
28 u8 algo; /* Public-key crypto algorithm [0] */
29 u8 hash; /* Digest algorithm [0] */
30 u8 id_type; /* Key identifier type [PKEY_ID_PKCS7] */
31 u8 signer_len; /* Length of signer's name [0] */
32 u8 key_id_len; /* Length of key identifier [0] */
34 __be32 sig_len; /* Length of signature data */
38 * Verify the signature on a module.
40 int mod_verify_sig(const void *mod, unsigned long *_modlen)
42 struct module_signature ms;
43 size_t modlen = *_modlen, sig_len;
45 pr_devel("==>%s(,%zu)\n", __func__, modlen);
47 if (modlen <= sizeof(ms))
50 memcpy(&ms, mod + (modlen - sizeof(ms)), sizeof(ms));
53 sig_len = be32_to_cpu(ms.sig_len);
54 if (sig_len >= modlen)
59 if (ms.id_type != PKEY_ID_PKCS7) {
60 pr_err("Module is not signed with expected PKCS#7 message\n");
71 pr_err("PKCS#7 signature info has unexpected non-zero params\n");
75 return system_verify_data(mod, modlen, mod + modlen, sig_len,
76 VERIFYING_MODULE_SIGNATURE);