-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
David Howells
authored and
Rusty Russell
committed
Oct 10, 2012
1 parent
7887104
commit db9ff19
Showing
4 changed files
with
125 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
--- | ||
refs/heads/master: d441108c6f77541bb66fcd5b3389415b4c232008 | ||
refs/heads/master: 631cc66eb9eaa7296e303197ff1eb0f55e32b61d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/* Public keys for module signature verification | ||
* | ||
* 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> | ||
#include <linux/sched.h> | ||
#include <linux/cred.h> | ||
#include <linux/err.h> | ||
#include <keys/asymmetric-type.h> | ||
#include "module-internal.h" | ||
|
||
struct key *modsign_keyring; | ||
|
||
extern __initdata const u8 modsign_certificate_list[]; | ||
extern __initdata const u8 modsign_certificate_list_end[]; | ||
asm(".section .init.data,\"aw\"\n" | ||
"modsign_certificate_list:\n" | ||
".incbin \"signing_key.x509\"\n" | ||
".incbin \"extra_certificates\"\n" | ||
"modsign_certificate_list_end:" | ||
); | ||
|
||
/* | ||
* We need to make sure ccache doesn't cache the .o file as it doesn't notice | ||
* if modsign.pub changes. | ||
*/ | ||
static __initdata const char annoy_ccache[] = __TIME__ "foo"; | ||
|
||
/* | ||
* Load the compiled-in keys | ||
*/ | ||
static __init int module_verify_init(void) | ||
{ | ||
pr_notice("Initialise module verification\n"); | ||
|
||
modsign_keyring = key_alloc(&key_type_keyring, ".module_sign", | ||
KUIDT_INIT(0), KGIDT_INIT(0), | ||
current_cred(), | ||
(KEY_POS_ALL & ~KEY_POS_SETATTR) | | ||
KEY_USR_VIEW | KEY_USR_READ, | ||
KEY_ALLOC_NOT_IN_QUOTA); | ||
if (IS_ERR(modsign_keyring)) | ||
panic("Can't allocate module signing keyring\n"); | ||
|
||
if (key_instantiate_and_link(modsign_keyring, NULL, 0, NULL, NULL) < 0) | ||
panic("Can't instantiate module signing keyring\n"); | ||
|
||
return 0; | ||
} | ||
|
||
/* | ||
* Must be initialised before we try and load the keys into the keyring. | ||
*/ | ||
device_initcall(module_verify_init); | ||
|
||
/* | ||
* Load the compiled-in keys | ||
*/ | ||
static __init int load_module_signing_keys(void) | ||
{ | ||
key_ref_t key; | ||
const u8 *p, *end; | ||
size_t plen; | ||
|
||
pr_notice("Loading module verification certificates\n"); | ||
|
||
end = modsign_certificate_list_end; | ||
p = modsign_certificate_list; | ||
while (p < end) { | ||
/* Each cert begins with an ASN.1 SEQUENCE tag and must be more | ||
* than 256 bytes in size. | ||
*/ | ||
if (end - p < 4) | ||
goto dodgy_cert; | ||
if (p[0] != 0x30 && | ||
p[1] != 0x82) | ||
goto dodgy_cert; | ||
plen = (p[2] << 8) | p[3]; | ||
plen += 4; | ||
if (plen > end - p) | ||
goto dodgy_cert; | ||
|
||
key = key_create_or_update(make_key_ref(modsign_keyring, 1), | ||
"asymmetric", | ||
NULL, | ||
p, | ||
plen, | ||
(KEY_POS_ALL & ~KEY_POS_SETATTR) | | ||
KEY_USR_VIEW, | ||
KEY_ALLOC_NOT_IN_QUOTA); | ||
if (IS_ERR(key)) | ||
pr_err("MODSIGN: Problem loading in-kernel X.509 certificate (%ld)\n", | ||
PTR_ERR(key)); | ||
else | ||
pr_notice("MODSIGN: Loaded cert '%s'\n", | ||
key_ref_to_ptr(key)->description); | ||
p += plen; | ||
} | ||
|
||
return 0; | ||
|
||
dodgy_cert: | ||
pr_err("MODSIGN: Problem parsing in-kernel X.509 certificate list\n"); | ||
return 0; | ||
} | ||
late_initcall(load_module_signing_keys); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters