1 /* Public keys for module signature verification
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 <linux/sched.h>
14 #include <linux/cred.h>
15 #include <linux/err.h>
16 #include <keys/asymmetric-type.h>
17 #include "module-internal.h"
19 struct key
*modsign_keyring
;
21 extern __initdata
const u8 modsign_certificate_list
[];
22 extern __initdata
const u8 modsign_certificate_list_end
[];
23 asm(".section .init.data,\"aw\"\n"
24 "modsign_certificate_list:\n"
25 ".incbin \"signing_key.x509\"\n"
26 ".incbin \"extra_certificates\"\n"
27 "modsign_certificate_list_end:"
31 * We need to make sure ccache doesn't cache the .o file as it doesn't notice
32 * if modsign.pub changes.
34 static __initdata
const char annoy_ccache
[] = __TIME__
"foo";
37 * Load the compiled-in keys
39 static __init
int module_verify_init(void)
41 pr_notice("Initialise module verification\n");
43 modsign_keyring
= key_alloc(&key_type_keyring
, ".module_sign",
44 KUIDT_INIT(0), KGIDT_INIT(0),
46 (KEY_POS_ALL
& ~KEY_POS_SETATTR
) |
47 KEY_USR_VIEW
| KEY_USR_READ
,
48 KEY_ALLOC_NOT_IN_QUOTA
);
49 if (IS_ERR(modsign_keyring
))
50 panic("Can't allocate module signing keyring\n");
52 if (key_instantiate_and_link(modsign_keyring
, NULL
, 0, NULL
, NULL
) < 0)
53 panic("Can't instantiate module signing keyring\n");
59 * Must be initialised before we try and load the keys into the keyring.
61 device_initcall(module_verify_init
);
64 * Load the compiled-in keys
66 static __init
int load_module_signing_keys(void)
72 pr_notice("Loading module verification certificates\n");
74 end
= modsign_certificate_list_end
;
75 p
= modsign_certificate_list
;
77 /* Each cert begins with an ASN.1 SEQUENCE tag and must be more
78 * than 256 bytes in size.
85 plen
= (p
[2] << 8) | p
[3];
90 key
= key_create_or_update(make_key_ref(modsign_keyring
, 1),
95 (KEY_POS_ALL
& ~KEY_POS_SETATTR
) |
97 KEY_ALLOC_NOT_IN_QUOTA
);
99 pr_err("MODSIGN: Problem loading in-kernel X.509 certificate (%ld)\n",
102 pr_notice("MODSIGN: Loaded cert '%s'\n",
103 key_ref_to_ptr(key
)->description
);
110 pr_err("MODSIGN: Problem parsing in-kernel X.509 certificate list\n");
113 late_initcall(load_module_signing_keys
);