1
2
3
4
5
6
7
8
9#include <linux/security.h>
10#include "common.h"
11
12
13
14
15
16
17
18
19
20static int tomoyo_open(struct inode *inode, struct file *file)
21{
22 const int key = ((u8 *) file->f_path.dentry->d_inode->i_private)
23 - ((u8 *) NULL);
24 return tomoyo_open_control(key, file);
25}
26
27
28
29
30
31
32
33
34
35static int tomoyo_release(struct inode *inode, struct file *file)
36{
37 return tomoyo_close_control(file);
38}
39
40
41
42
43
44
45
46
47
48static unsigned int tomoyo_poll(struct file *file, poll_table *wait)
49{
50 return tomoyo_poll_control(file, wait);
51}
52
53
54
55
56
57
58
59
60
61
62
63static ssize_t tomoyo_read(struct file *file, char __user *buf, size_t count,
64 loff_t *ppos)
65{
66 return tomoyo_read_control(file, buf, count);
67}
68
69
70
71
72
73
74
75
76
77
78
79static ssize_t tomoyo_write(struct file *file, const char __user *buf,
80 size_t count, loff_t *ppos)
81{
82 return tomoyo_write_control(file, buf, count);
83}
84
85
86
87
88
89
90
91
92static const struct file_operations tomoyo_operations = {
93 .open = tomoyo_open,
94 .release = tomoyo_release,
95 .poll = tomoyo_poll,
96 .read = tomoyo_read,
97 .write = tomoyo_write,
98 .llseek = noop_llseek,
99};
100
101
102
103
104
105
106
107
108
109
110
111static void __init tomoyo_create_entry(const char *name, const mode_t mode,
112 struct dentry *parent, const u8 key)
113{
114 securityfs_create_file(name, mode, parent, ((u8 *) NULL) + key,
115 &tomoyo_operations);
116}
117
118
119
120
121
122
123static int __init tomoyo_initerface_init(void)
124{
125 struct dentry *tomoyo_dir;
126
127
128 if (current_cred()->security != &tomoyo_kernel_domain)
129 return 0;
130
131 tomoyo_dir = securityfs_create_dir("tomoyo", NULL);
132 tomoyo_create_entry("query", 0600, tomoyo_dir,
133 TOMOYO_QUERY);
134 tomoyo_create_entry("domain_policy", 0600, tomoyo_dir,
135 TOMOYO_DOMAINPOLICY);
136 tomoyo_create_entry("exception_policy", 0600, tomoyo_dir,
137 TOMOYO_EXCEPTIONPOLICY);
138 tomoyo_create_entry("self_domain", 0400, tomoyo_dir,
139 TOMOYO_SELFDOMAIN);
140 tomoyo_create_entry(".domain_status", 0600, tomoyo_dir,
141 TOMOYO_DOMAIN_STATUS);
142 tomoyo_create_entry(".process_status", 0600, tomoyo_dir,
143 TOMOYO_PROCESS_STATUS);
144 tomoyo_create_entry("meminfo", 0600, tomoyo_dir,
145 TOMOYO_MEMINFO);
146 tomoyo_create_entry("profile", 0600, tomoyo_dir,
147 TOMOYO_PROFILE);
148 tomoyo_create_entry("manager", 0600, tomoyo_dir,
149 TOMOYO_MANAGER);
150 tomoyo_create_entry("version", 0400, tomoyo_dir,
151 TOMOYO_VERSION);
152 return 0;
153}
154
155fs_initcall(tomoyo_initerface_init);
156