summaryrefstree
path: root/kernel/security/sdp/cache_cleanup.c
blob: 80a0f2a1e329f126dfb0efa8a0f2eb6da39a4195 (plain)
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
 *
 * Sensitive Data Protection
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

#include <sdp/common.h>
#include <sdp/cache_cleanup.h>

#ifdef CONFIG_SDP
#if SDP_CACHE_CLEANUP_DEBUG
static void sdp_page_dump(unsigned char *buf, int len, const char *str)
{
	unsigned int i;
	char s[512];

	s[0] = 0;
	for (i = 0; i < len && i < 32; ++i) {
		char tmp[8];

		sprintf(tmp, " %02x", buf[i]);
		strcat(s, tmp);
	}

	if (len > 32) {
		char tmp[8];

		sprintf(tmp, " ...");
		strcat(s, tmp);
	}

	printk("%s [%s len=%d]\n", s, str, len);
}
#else
static void sdp_page_dump(unsigned char *buf, int len, const char *str)
{
	return;
}
#endif
#endif

void sdp_page_cleanup(struct page *page)
{
#ifdef CONFIG_SDP
	if (page && page->mapping) {
		if (mapping_sensitive(page->mapping)) {
			void *d;

#if SDP_CACHE_CLEANUP_DEBUG
			printk("%s : deleting [%s] sensitive page.\n",
			__func__, page->mapping->host->i_sb->s_type->name);
			//dump_stack();
#endif
			d = kmap_atomic(page);
			if (d) {
				sdp_page_dump((unsigned char *)d, PAGE_SIZE, "freeing");
				clear_page(d);
				sdp_page_dump((unsigned char *)d, PAGE_SIZE, "freed");
				kunmap_atomic(d);
			}
		}
	}
#endif
}