fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / kernel / module-verify.c
1 /* module-verify.c: module verifier
2  *
3  * Written by David Howells (dhowells@redhat.com)
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version
8  * 2 of the License, or (at your option) any later version.
9  */
10
11 #include <linux/kernel.h>
12 #include <linux/module.h>
13 #include <linux/slab.h>
14 #include "module-verify.h"
15
16 /*
17  * verify a module's integrity
18  * - check the ELF is viable
19  * - return 1 if the module has a correct signature
20  * - return 0 if the module has no signature or one we don't have a key for
21  * - return -ve on error
22  */
23 int module_verify(const Elf_Ehdr *hdr, size_t size)
24 {
25         struct module_verify_data mvdata;
26         int ret;
27
28         memset(&mvdata, 0, sizeof(mvdata));
29         mvdata.buffer   = hdr;
30         mvdata.hdr      = hdr;
31         mvdata.size     = size;
32
33         ret = module_verify_elf(&mvdata);
34         if (ret < 0) {
35                 if (ret == -ELIBBAD)
36                         printk("Module failed ELF checks\n");
37                 goto error;
38         }
39
40         ret = module_verify_signature(&mvdata);
41
42 error:
43         kfree(mvdata.secsizes);
44         kfree(mvdata.canonlist);
45         return ret;
46 }