tracing/kprobes: Support soft-mode disabling
[linux-2.6.git] / kernel / modsign_pubkey.c
blob2b6e69909c394440b015e771ff0f3f4eab1a1a28
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[];
25 * We need to make sure ccache doesn't cache the .o file as it doesn't notice
26 * if modsign.pub changes.
28 static __initdata const char annoy_ccache[] = __TIME__ "foo";
31 * Load the compiled-in keys
33 static __init int module_verify_init(void)
35 pr_notice("Initialise module verification\n");
37 modsign_keyring = keyring_alloc(".module_sign",
38 KUIDT_INIT(0), KGIDT_INIT(0),
39 current_cred(),
40 ((KEY_POS_ALL & ~KEY_POS_SETATTR) |
41 KEY_USR_VIEW | KEY_USR_READ),
42 KEY_ALLOC_NOT_IN_QUOTA, NULL);
43 if (IS_ERR(modsign_keyring))
44 panic("Can't allocate module signing keyring\n");
46 return 0;
50 * Must be initialised before we try and load the keys into the keyring.
52 device_initcall(module_verify_init);
55 * Load the compiled-in keys
57 static __init int load_module_signing_keys(void)
59 key_ref_t key;
60 const u8 *p, *end;
61 size_t plen;
63 pr_notice("Loading module verification certificates\n");
65 end = modsign_certificate_list_end;
66 p = modsign_certificate_list;
67 while (p < end) {
68 /* Each cert begins with an ASN.1 SEQUENCE tag and must be more
69 * than 256 bytes in size.
71 if (end - p < 4)
72 goto dodgy_cert;
73 if (p[0] != 0x30 &&
74 p[1] != 0x82)
75 goto dodgy_cert;
76 plen = (p[2] << 8) | p[3];
77 plen += 4;
78 if (plen > end - p)
79 goto dodgy_cert;
81 key = key_create_or_update(make_key_ref(modsign_keyring, 1),
82 "asymmetric",
83 NULL,
85 plen,
86 (KEY_POS_ALL & ~KEY_POS_SETATTR) |
87 KEY_USR_VIEW,
88 KEY_ALLOC_NOT_IN_QUOTA);
89 if (IS_ERR(key))
90 pr_err("MODSIGN: Problem loading in-kernel X.509 certificate (%ld)\n",
91 PTR_ERR(key));
92 else
93 pr_notice("MODSIGN: Loaded cert '%s'\n",
94 key_ref_to_ptr(key)->description);
95 p += plen;
98 return 0;
100 dodgy_cert:
101 pr_err("MODSIGN: Problem parsing in-kernel X.509 certificate list\n");
102 return 0;
104 late_initcall(load_module_signing_keys);