-
Notifications
You must be signed in to change notification settings - Fork 0
/
snakeoil.c
54 lines (43 loc) · 1.02 KB
/
snakeoil.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <linux/init.h>
#include <linux/module.h>
#include <linux/reboot.h>
#include <linux/slab.h>
#include <linux/random.h>
static int snakeoil_wipe(struct notifier_block *nb, unsigned long action, void *data)
{
void *ptr = NULL;
void *prev = NULL;
while ((ptr = kmalloc(4096, GFP_KERNEL|__GFP_NORETRY)) != NULL) {
*(void **)ptr = prev;
prev = ptr;
}
while (prev != NULL) {
ptr = *(void **)prev;
get_random_bytes(prev, 4096);
kfree(prev);
prev = ptr;
}
return 0;
}
static struct notifier_block snakeoil_reboot_notifier = {
.notifier_call = snakeoil_wipe,
.next = NULL,
.priority = 0
};
static int __init snakeoil_init(void)
{
int ret = register_reboot_notifier(&snakeoil_reboot_notifier);
if (ret != 0) {
// error handling
return 1;
}
printk(KERN_INFO "snakeoil loaded\n");
return 0;
}
static void __exit snakeoil_exit(void)
{
unregister_reboot_notifier(&snakeoil_reboot_notifier);
printk(KERN_INFO "snakeoil unloaded\n");
}
module_init(snakeoil_init);
module_exit(snakeoil_exit);