1 |
/* |
/* |
2 |
* security/ccsecurity/policy_io.c |
* security/ccsecurity/policy_io.c |
3 |
* |
* |
4 |
* Copyright (C) 2005-2009 NTT DATA CORPORATION |
* Copyright (C) 2005-2010 NTT DATA CORPORATION |
5 |
* |
* |
6 |
* Version: 1.7.0-pre 2009/08/08 |
* Version: 1.7.2-pre 2010/03/21 |
7 |
* |
* |
8 |
* This file is applicable to both 2.4.30 and 2.6.11 and later. |
* This file is applicable to both 2.4.30 and 2.6.11 and later. |
9 |
* See README.ccs for ChangeLog. |
* See README.ccs for ChangeLog. |
12 |
|
|
13 |
#include "internal.h" |
#include "internal.h" |
14 |
|
|
15 |
/* Lock for protecting ccs_profile->comment */ |
static struct ccs_profile ccs_default_profile = { |
16 |
static DEFINE_SPINLOCK(ccs_profile_comment_lock); |
.learning = &ccs_default_profile.preference, |
17 |
|
.permissive = &ccs_default_profile.preference, |
18 |
/* String table for functionality that takes 2 modes. */ |
.enforcing = &ccs_default_profile.preference, |
19 |
static const char *ccs_mode_2[2] = { |
.audit = &ccs_default_profile.preference, |
20 |
"disabled", "enabled" |
#ifdef CONFIG_CCSECURITY_AUDIT |
21 |
|
.preference.audit_max_grant_log = CONFIG_CCSECURITY_MAX_GRANT_LOG, |
22 |
|
.preference.audit_max_reject_log = CONFIG_CCSECURITY_MAX_REJECT_LOG, |
23 |
|
#endif |
24 |
|
.preference.audit_task_info = true, |
25 |
|
.preference.audit_path_info = true, |
26 |
|
.preference.enforcing_penalty = 0, |
27 |
|
.preference.enforcing_verbose = true, |
28 |
|
.preference.learning_max_entry = CONFIG_CCSECURITY_MAX_ACCEPT_ENTRY, |
29 |
|
.preference.learning_verbose = false, |
30 |
|
.preference.learning_exec_realpath = true, |
31 |
|
.preference.learning_exec_argv0 = true, |
32 |
|
.preference.learning_symlink_target = true, |
33 |
|
.preference.permissive_verbose = true |
34 |
}; |
}; |
35 |
|
|
36 |
|
/* Profile version. Currently only 20090903 is defined. */ |
37 |
|
static unsigned int ccs_profile_version; |
38 |
|
|
39 |
|
/* Profile table. Memory is allocated as needed. */ |
40 |
|
static struct ccs_profile *ccs_profile_ptr[CCS_MAX_PROFILES]; |
41 |
|
|
42 |
|
/* String table for functionality that takes 4 modes. */ |
43 |
static const char *ccs_mode_4[4] = { |
static const char *ccs_mode_4[4] = { |
44 |
"disabled", "learning", "permissive", "enforcing" |
"disabled", "learning", "permissive", "enforcing" |
45 |
}; |
}; |
46 |
|
|
47 |
static bool ccs_mac_keywords_used[CCS_MAX_MAC_INDEX + |
/* String table for /proc/ccs/profile */ |
|
CCS_MAX_CAPABILITY_INDEX]; |
|
|
|
|
48 |
static const char *ccs_mac_keywords[CCS_MAX_MAC_INDEX + |
static const char *ccs_mac_keywords[CCS_MAX_MAC_INDEX + |
49 |
CCS_MAX_CAPABILITY_INDEX] = { |
CCS_MAX_CAPABILITY_INDEX + |
50 |
[CCS_MAC_EXECUTE] = "execute", |
CCS_MAX_MAC_CATEGORY_INDEX] = { |
51 |
[CCS_MAC_OPEN] = "open", |
[CCS_MAC_FILE_EXECUTE] |
52 |
[CCS_MAC_CREATE] = "create", |
= "file::execute", |
53 |
[CCS_MAC_UNLINK] = "unlink", |
[CCS_MAC_FILE_OPEN] |
54 |
[CCS_MAC_MKDIR] = "mkdir", |
= "file::open", |
55 |
[CCS_MAC_RMDIR] = "rmdir", |
[CCS_MAC_FILE_CREATE] |
56 |
[CCS_MAC_MKFIFO] = "mkfifo", |
= "file::create", |
57 |
[CCS_MAC_MKSOCK] = "mksock", |
[CCS_MAC_FILE_UNLINK] |
58 |
[CCS_MAC_TRUNCATE] = "truncate", |
= "file::unlink", |
59 |
[CCS_MAC_SYMLINK] = "symlink", |
[CCS_MAC_FILE_MKDIR] |
60 |
[CCS_MAC_REWRITE] = "rewrite", |
= "file::mkdir", |
61 |
[CCS_MAC_MKBLOCK] = "mkblock", |
[CCS_MAC_FILE_RMDIR] |
62 |
[CCS_MAC_MKCHAR] = "mkchar", |
= "file::rmdir", |
63 |
[CCS_MAC_LINK] = "link", |
[CCS_MAC_FILE_MKFIFO] |
64 |
[CCS_MAC_RENAME] = "rename", |
= "file::mkfifo", |
65 |
[CCS_MAC_CHMOD] = "chmod", |
[CCS_MAC_FILE_MKSOCK] |
66 |
[CCS_MAC_CHOWN] = "chown", |
= "file::mksock", |
67 |
[CCS_MAC_CHGRP] = "chgrp", |
[CCS_MAC_FILE_TRUNCATE] |
68 |
[CCS_MAC_IOCTL] = "ioctl", |
= "file::truncate", |
69 |
[CCS_MAC_CHROOT] = "chroot", |
[CCS_MAC_FILE_SYMLINK] |
70 |
[CCS_MAC_MOUNT] = "mount", |
= "file::symlink", |
71 |
[CCS_MAC_UMOUNT] = "umount", |
[CCS_MAC_FILE_REWRITE] |
72 |
[CCS_MAC_PIVOT_ROOT] = "pivot_root", |
= "file::rewrite", |
73 |
[CCS_MAC_ENVIRON] = "env", |
[CCS_MAC_FILE_MKBLOCK] |
74 |
[CCS_MAC_NETWORK] = "network", |
= "file::mkblock", |
75 |
[CCS_MAC_SIGNAL] = "signal", |
[CCS_MAC_FILE_MKCHAR] |
76 |
|
= "file::mkchar", |
77 |
|
[CCS_MAC_FILE_LINK] |
78 |
|
= "file::link", |
79 |
|
[CCS_MAC_FILE_RENAME] |
80 |
|
= "file::rename", |
81 |
|
[CCS_MAC_FILE_CHMOD] |
82 |
|
= "file::chmod", |
83 |
|
[CCS_MAC_FILE_CHOWN] |
84 |
|
= "file::chown", |
85 |
|
[CCS_MAC_FILE_CHGRP] |
86 |
|
= "file::chgrp", |
87 |
|
[CCS_MAC_FILE_IOCTL] |
88 |
|
= "file::ioctl", |
89 |
|
[CCS_MAC_FILE_CHROOT] |
90 |
|
= "file::chroot", |
91 |
|
[CCS_MAC_FILE_MOUNT] |
92 |
|
= "file::mount", |
93 |
|
[CCS_MAC_FILE_UMOUNT] |
94 |
|
= "file::umount", |
95 |
|
[CCS_MAC_FILE_PIVOT_ROOT] |
96 |
|
= "file::pivot_root", |
97 |
|
[CCS_MAC_FILE_TRANSIT] |
98 |
|
= "file::transit", |
99 |
|
[CCS_MAC_ENVIRON] |
100 |
|
= "misc::env", |
101 |
|
[CCS_MAC_NETWORK_UDP_BIND] |
102 |
|
= "network::inet_udp_bind", |
103 |
|
[CCS_MAC_NETWORK_UDP_CONNECT] |
104 |
|
= "network::inet_udp_connect", |
105 |
|
[CCS_MAC_NETWORK_TCP_BIND] |
106 |
|
= "network::inet_tcp_bind", |
107 |
|
[CCS_MAC_NETWORK_TCP_LISTEN] |
108 |
|
= "network::inet_tcp_listen", |
109 |
|
[CCS_MAC_NETWORK_TCP_CONNECT] |
110 |
|
= "network::inet_tcp_connect", |
111 |
|
[CCS_MAC_NETWORK_TCP_ACCEPT] |
112 |
|
= "network::inet_tcp_accept", |
113 |
|
[CCS_MAC_NETWORK_RAW_BIND] |
114 |
|
= "network::inet_raw_bind", |
115 |
|
[CCS_MAC_NETWORK_RAW_CONNECT] |
116 |
|
= "network::inet_raw_connect", |
117 |
|
[CCS_MAC_SIGNAL] |
118 |
|
= "ipc::signal", |
119 |
[CCS_MAX_MAC_INDEX + CCS_INET_STREAM_SOCKET_CREATE] |
[CCS_MAX_MAC_INDEX + CCS_INET_STREAM_SOCKET_CREATE] |
120 |
= "inet_tcp_create", |
= "capability::inet_tcp_create", |
121 |
[CCS_MAX_MAC_INDEX + CCS_INET_STREAM_SOCKET_LISTEN] |
[CCS_MAX_MAC_INDEX + CCS_INET_STREAM_SOCKET_LISTEN] |
122 |
= "inet_tcp_listen", |
= "capability::inet_tcp_listen", |
123 |
[CCS_MAX_MAC_INDEX + CCS_INET_STREAM_SOCKET_CONNECT] |
[CCS_MAX_MAC_INDEX + CCS_INET_STREAM_SOCKET_CONNECT] |
124 |
= "inet_tcp_connect", |
= "capability::inet_tcp_connect", |
125 |
[CCS_MAX_MAC_INDEX + CCS_USE_INET_DGRAM_SOCKET] = "use_inet_udp", |
[CCS_MAX_MAC_INDEX + CCS_USE_INET_DGRAM_SOCKET] |
126 |
[CCS_MAX_MAC_INDEX + CCS_USE_INET_RAW_SOCKET] = "use_inet_ip", |
= "capability::use_inet_udp", |
127 |
[CCS_MAX_MAC_INDEX + CCS_USE_ROUTE_SOCKET] = "use_route", |
[CCS_MAX_MAC_INDEX + CCS_USE_INET_RAW_SOCKET] |
128 |
[CCS_MAX_MAC_INDEX + CCS_USE_PACKET_SOCKET] = "use_packet", |
= "capability::use_inet_ip", |
129 |
[CCS_MAX_MAC_INDEX + CCS_SYS_MOUNT] = "SYS_MOUNT", |
[CCS_MAX_MAC_INDEX + CCS_USE_ROUTE_SOCKET] |
130 |
[CCS_MAX_MAC_INDEX + CCS_SYS_UMOUNT] = "SYS_UMOUNT", |
= "capability::use_route", |
131 |
[CCS_MAX_MAC_INDEX + CCS_SYS_REBOOT] = "SYS_REBOOT", |
[CCS_MAX_MAC_INDEX + CCS_USE_PACKET_SOCKET] |
132 |
[CCS_MAX_MAC_INDEX + CCS_SYS_CHROOT] = "SYS_CHROOT", |
= "capability::use_packet", |
133 |
[CCS_MAX_MAC_INDEX + CCS_SYS_KILL] = "SYS_KILL", |
[CCS_MAX_MAC_INDEX + CCS_SYS_MOUNT] |
134 |
[CCS_MAX_MAC_INDEX + CCS_SYS_VHANGUP] = "SYS_VHANGUP", |
= "capability::SYS_MOUNT", |
135 |
[CCS_MAX_MAC_INDEX + CCS_SYS_SETTIME] = "SYS_TIME", |
[CCS_MAX_MAC_INDEX + CCS_SYS_UMOUNT] |
136 |
[CCS_MAX_MAC_INDEX + CCS_SYS_NICE] = "SYS_NICE", |
= "capability::SYS_UMOUNT", |
137 |
[CCS_MAX_MAC_INDEX + CCS_SYS_SETHOSTNAME] = "SYS_SETHOSTNAME", |
[CCS_MAX_MAC_INDEX + CCS_SYS_REBOOT] |
138 |
[CCS_MAX_MAC_INDEX + CCS_USE_KERNEL_MODULE] = "use_kernel_module", |
= "capability::SYS_REBOOT", |
139 |
[CCS_MAX_MAC_INDEX + CCS_CREATE_FIFO] = "create_fifo", |
[CCS_MAX_MAC_INDEX + CCS_SYS_CHROOT] |
140 |
[CCS_MAX_MAC_INDEX + CCS_CREATE_BLOCK_DEV] = "create_block_dev", |
= "capability::SYS_CHROOT", |
141 |
[CCS_MAX_MAC_INDEX + CCS_CREATE_CHAR_DEV] = "create_char_dev", |
[CCS_MAX_MAC_INDEX + CCS_SYS_KILL] |
142 |
[CCS_MAX_MAC_INDEX + CCS_CREATE_UNIX_SOCKET] = "create_unix_socket", |
= "capability::SYS_KILL", |
143 |
[CCS_MAX_MAC_INDEX + CCS_SYS_LINK] = "SYS_LINK", |
[CCS_MAX_MAC_INDEX + CCS_SYS_VHANGUP] |
144 |
[CCS_MAX_MAC_INDEX + CCS_SYS_SYMLINK] = "SYS_SYMLINK", |
= "capability::SYS_VHANGUP", |
145 |
[CCS_MAX_MAC_INDEX + CCS_SYS_RENAME] = "SYS_RENAME", |
[CCS_MAX_MAC_INDEX + CCS_SYS_SETTIME] |
146 |
[CCS_MAX_MAC_INDEX + CCS_SYS_UNLINK] = "SYS_UNLINK", |
= "capability::SYS_TIME", |
147 |
[CCS_MAX_MAC_INDEX + CCS_SYS_CHMOD] = "SYS_CHMOD", |
[CCS_MAX_MAC_INDEX + CCS_SYS_NICE] |
148 |
[CCS_MAX_MAC_INDEX + CCS_SYS_CHOWN] = "SYS_CHOWN", |
= "capability::SYS_NICE", |
149 |
[CCS_MAX_MAC_INDEX + CCS_SYS_IOCTL] = "SYS_IOCTL", |
[CCS_MAX_MAC_INDEX + CCS_SYS_SETHOSTNAME] |
150 |
[CCS_MAX_MAC_INDEX + CCS_SYS_KEXEC_LOAD] = "SYS_KEXEC_LOAD", |
= "capability::SYS_SETHOSTNAME", |
151 |
[CCS_MAX_MAC_INDEX + CCS_SYS_PIVOT_ROOT] = "SYS_PIVOT_ROOT", |
[CCS_MAX_MAC_INDEX + CCS_USE_KERNEL_MODULE] |
152 |
[CCS_MAX_MAC_INDEX + CCS_SYS_PTRACE] = "SYS_PTRACE", |
= "capability::use_kernel_module", |
153 |
[CCS_MAX_MAC_INDEX + CCS_CONCEAL_MOUNT] = "conceal_mount" |
[CCS_MAX_MAC_INDEX + CCS_CREATE_FIFO] |
154 |
}; |
= "capability::create_fifo", |
155 |
|
[CCS_MAX_MAC_INDEX + CCS_CREATE_BLOCK_DEV] |
156 |
/* Table for profile. */ |
= "capability::create_block_dev", |
157 |
static struct { |
[CCS_MAX_MAC_INDEX + CCS_CREATE_CHAR_DEV] |
158 |
const char *keyword; |
= "capability::create_char_dev", |
159 |
unsigned int current_value; |
[CCS_MAX_MAC_INDEX + CCS_CREATE_UNIX_SOCKET] |
160 |
const unsigned int max_value; |
= "capability::create_unix_socket", |
161 |
} ccs_control_array[CCS_MAX_CONTROL_INDEX] = { |
[CCS_MAX_MAC_INDEX + CCS_SYS_LINK] |
162 |
[CCS_AUTOLEARN_EXEC_REALPATH] = { "AUTOLEARN_EXEC_REALPATH", 0, 1 }, |
= "capability::SYS_LINK", |
163 |
[CCS_AUTOLEARN_EXEC_ARGV0] = { "AUTOLEARN_EXEC_ARGV0", 0, 1 }, |
[CCS_MAX_MAC_INDEX + CCS_SYS_SYMLINK] |
164 |
[CCS_MAX_ACCEPT_ENTRY] |
= "capability::SYS_SYMLINK", |
165 |
= { "MAX_ACCEPT_ENTRY", CONFIG_CCSECURITY_MAX_ACCEPT_ENTRY, INT_MAX }, |
[CCS_MAX_MAC_INDEX + CCS_SYS_RENAME] |
166 |
#ifdef CONFIG_CCSECURITY_AUDIT |
= "capability::SYS_RENAME", |
167 |
[CCS_MAX_GRANT_LOG] |
[CCS_MAX_MAC_INDEX + CCS_SYS_UNLINK] |
168 |
= { "MAX_GRANT_LOG", CONFIG_CCSECURITY_MAX_GRANT_LOG, INT_MAX }, |
= "capability::SYS_UNLINK", |
169 |
[CCS_MAX_REJECT_LOG] |
[CCS_MAX_MAC_INDEX + CCS_SYS_CHMOD] |
170 |
= { "MAX_REJECT_LOG", CONFIG_CCSECURITY_MAX_REJECT_LOG, INT_MAX }, |
= "capability::SYS_CHMOD", |
171 |
#endif |
[CCS_MAX_MAC_INDEX + CCS_SYS_CHOWN] |
172 |
[CCS_VERBOSE] = { "PRINT_VIOLATION", 1, 1 }, |
= "capability::SYS_CHOWN", |
173 |
[CCS_SLEEP_PERIOD] = { "SLEEP_PERIOD", 0, 3000 }, /* in 0.1 second */ |
[CCS_MAX_MAC_INDEX + CCS_SYS_IOCTL] |
174 |
|
= "capability::SYS_IOCTL", |
175 |
|
[CCS_MAX_MAC_INDEX + CCS_SYS_KEXEC_LOAD] |
176 |
|
= "capability::SYS_KEXEC_LOAD", |
177 |
|
[CCS_MAX_MAC_INDEX + CCS_SYS_PIVOT_ROOT] |
178 |
|
= "capability::SYS_PIVOT_ROOT", |
179 |
|
[CCS_MAX_MAC_INDEX + CCS_SYS_PTRACE] |
180 |
|
= "capability::SYS_PTRACE", |
181 |
|
[CCS_MAX_MAC_INDEX + CCS_CONCEAL_MOUNT] |
182 |
|
= "capability::conceal_mount", |
183 |
|
[CCS_MAX_MAC_INDEX + CCS_MAX_CAPABILITY_INDEX |
184 |
|
+ CCS_MAC_CATEGORY_FILE] = "file", |
185 |
|
[CCS_MAX_MAC_INDEX + CCS_MAX_CAPABILITY_INDEX |
186 |
|
+ CCS_MAC_CATEGORY_NETWORK] = "network", |
187 |
|
[CCS_MAX_MAC_INDEX + CCS_MAX_CAPABILITY_INDEX |
188 |
|
+ CCS_MAC_CATEGORY_MISC] = "misc", |
189 |
|
[CCS_MAX_MAC_INDEX + CCS_MAX_CAPABILITY_INDEX |
190 |
|
+ CCS_MAC_CATEGORY_IPC] = "ipc", |
191 |
|
[CCS_MAX_MAC_INDEX + CCS_MAX_CAPABILITY_INDEX |
192 |
|
+ CCS_MAC_CATEGORY_CAPABILITY] = "capability", |
193 |
}; |
}; |
194 |
|
|
195 |
/* Permit policy management by non-root user? */ |
/* Permit policy management by non-root user? */ |
205 |
const char *ccs_cap2keyword(const u8 operation) |
const char *ccs_cap2keyword(const u8 operation) |
206 |
{ |
{ |
207 |
return operation < CCS_MAX_CAPABILITY_INDEX |
return operation < CCS_MAX_CAPABILITY_INDEX |
208 |
? ccs_mac_keywords[CCS_MAX_MAC_INDEX + operation] : NULL; |
? ccs_mac_keywords[CCS_MAX_MAC_INDEX + operation] + 12 : NULL; |
209 |
} |
} |
210 |
|
|
211 |
/** |
/** |
212 |
* ccs_quiet_setup - Set CCS_VERBOSE=0 by default. |
* ccs_yesno - Return "yes" or "no". |
|
* |
|
|
* @str: Unused. |
|
213 |
* |
* |
214 |
* Returns 0. |
* @value: Bool value. |
215 |
*/ |
*/ |
216 |
static int __init ccs_quiet_setup(char *str) |
static const char *ccs_yesno(const unsigned int value) |
217 |
{ |
{ |
218 |
ccs_control_array[CCS_VERBOSE].current_value = 0; |
return value ? "yes" : "no"; |
|
return 0; |
|
219 |
} |
} |
220 |
|
|
|
__setup("CCS_QUIET", ccs_quiet_setup); |
|
|
|
|
221 |
/** |
/** |
222 |
* ccs_io_printf - Transactional printf() to "struct ccs_io_buffer" structure. |
* ccs_io_printf - Transactional printf() to "struct ccs_io_buffer" structure. |
223 |
* |
* |
257 |
{ |
{ |
258 |
struct ccs_profile *ptr; |
struct ccs_profile *ptr; |
259 |
struct ccs_profile *entry; |
struct ccs_profile *entry; |
|
int i; |
|
260 |
if (profile >= CCS_MAX_PROFILES) |
if (profile >= CCS_MAX_PROFILES) |
261 |
return NULL; |
return NULL; |
262 |
ptr = ccs_profile_ptr[profile]; |
ptr = ccs_profile_ptr[profile]; |
263 |
if (ptr) |
if (ptr) |
264 |
return ptr; |
return ptr; |
265 |
entry = kzalloc(sizeof(*entry), GFP_KERNEL); |
entry = kzalloc(sizeof(*entry), CCS_GFP_FLAGS); |
266 |
mutex_lock(&ccs_policy_lock); |
mutex_lock(&ccs_policy_lock); |
267 |
ptr = ccs_profile_ptr[profile]; |
ptr = ccs_profile_ptr[profile]; |
268 |
if (!ptr && ccs_memory_ok(entry, sizeof(*entry))) { |
if (!ptr && ccs_memory_ok(entry, sizeof(*entry))) { |
269 |
ptr = entry; |
ptr = entry; |
270 |
for (i = 0; i < CCS_MAX_CONTROL_INDEX; i++) |
ptr->audit = &ccs_default_profile.preference; |
271 |
ptr->value[i] = ccs_control_array[i].current_value; |
ptr->learning = &ccs_default_profile.preference; |
272 |
|
ptr->permissive = &ccs_default_profile.preference; |
273 |
|
ptr->enforcing = &ccs_default_profile.preference; |
274 |
|
ptr->default_config = CCS_CONFIG_DISABLED | |
275 |
|
CCS_CONFIG_WANT_GRANT_LOG | CCS_CONFIG_WANT_REJECT_LOG; |
276 |
|
memset(ptr->config, CCS_CONFIG_USE_DEFAULT, |
277 |
|
sizeof(ptr->config)); |
278 |
mb(); /* Avoid out-of-order execution. */ |
mb(); /* Avoid out-of-order execution. */ |
279 |
ccs_profile_ptr[profile] = ptr; |
ccs_profile_ptr[profile] = ptr; |
280 |
entry = NULL; |
entry = NULL; |
285 |
} |
} |
286 |
|
|
287 |
/** |
/** |
288 |
|
* ccs_check_profile - Check all profiles currently assigned to domains are defined. |
289 |
|
*/ |
290 |
|
static void ccs_check_profile(void) |
291 |
|
{ |
292 |
|
struct ccs_domain_info *domain; |
293 |
|
ccs_policy_loaded = true; |
294 |
|
list_for_each_entry_rcu(domain, &ccs_domain_list, list) { |
295 |
|
const u8 profile = domain->profile; |
296 |
|
if (ccs_profile_ptr[profile]) |
297 |
|
continue; |
298 |
|
panic("Profile %u (used by '%s') not defined.\n", |
299 |
|
profile, domain->domainname->name); |
300 |
|
} |
301 |
|
if (ccs_profile_version != 20090903) |
302 |
|
panic("Profile version %u is not supported.\n", |
303 |
|
ccs_profile_version); |
304 |
|
printk(KERN_INFO "CCSecurity: 1.7.2-pre 2010/03/21\n"); |
305 |
|
printk(KERN_INFO "Mandatory Access Control activated.\n"); |
306 |
|
} |
307 |
|
|
308 |
|
/** |
309 |
|
* ccs_profile - Find a profile. |
310 |
|
* |
311 |
|
* @profile: Profile number to find. |
312 |
|
* |
313 |
|
* Returns pointer to "struct ccs_profile". |
314 |
|
*/ |
315 |
|
struct ccs_profile *ccs_profile(const u8 profile) |
316 |
|
{ |
317 |
|
struct ccs_profile *ptr = ccs_profile_ptr[profile]; |
318 |
|
if (!ccs_policy_loaded) |
319 |
|
return &ccs_default_profile; |
320 |
|
BUG_ON(!ptr); |
321 |
|
return ptr; |
322 |
|
} |
323 |
|
|
324 |
|
/** |
325 |
* ccs_write_profile - Write profile table. |
* ccs_write_profile - Write profile table. |
326 |
* |
* |
327 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
332 |
{ |
{ |
333 |
char *data = head->write_buf; |
char *data = head->write_buf; |
334 |
unsigned int i; |
unsigned int i; |
335 |
unsigned int value; |
int value; |
|
int index = -1; |
|
336 |
int mode; |
int mode; |
337 |
|
u8 config; |
338 |
|
bool use_default = false; |
339 |
char *cp; |
char *cp; |
340 |
struct ccs_profile *ccs_profile; |
struct ccs_profile *profile; |
341 |
|
if (sscanf(data, "PROFILE_VERSION=%u", &ccs_profile_version) == 1) |
342 |
|
return 0; |
343 |
i = simple_strtoul(data, &cp, 10); |
i = simple_strtoul(data, &cp, 10); |
344 |
if (data != cp) { |
if (data == cp) { |
345 |
|
profile = &ccs_default_profile; |
346 |
|
} else { |
347 |
if (*cp != '-') |
if (*cp != '-') |
348 |
return -EINVAL; |
return -EINVAL; |
349 |
data = cp + 1; |
data = cp + 1; |
350 |
|
profile = ccs_find_or_assign_new_profile(i); |
351 |
|
if (!profile) |
352 |
|
return -EINVAL; |
353 |
} |
} |
|
ccs_profile = ccs_find_or_assign_new_profile(i); |
|
|
if (!ccs_profile) |
|
|
return -EINVAL; |
|
354 |
cp = strchr(data, '='); |
cp = strchr(data, '='); |
355 |
if (!cp) |
if (!cp) |
356 |
return -EINVAL; |
return -EINVAL; |
357 |
*cp++ = '\0'; |
*cp++ = '\0'; |
358 |
|
if (profile != &ccs_default_profile) |
359 |
|
use_default = strstr(cp, "use_default") != NULL; |
360 |
|
if (strstr(cp, "verbose=yes")) |
361 |
|
value = 1; |
362 |
|
else if (strstr(cp, "verbose=no")) |
363 |
|
value = 0; |
364 |
|
else |
365 |
|
value = -1; |
366 |
|
if (!strcmp(data, "PREFERENCE::audit")) { |
367 |
|
#ifdef CONFIG_CCSECURITY_AUDIT |
368 |
|
char *cp2; |
369 |
|
#endif |
370 |
|
if (use_default) { |
371 |
|
profile->audit = &ccs_default_profile.preference; |
372 |
|
return 0; |
373 |
|
} |
374 |
|
profile->audit = &profile->preference; |
375 |
|
#ifdef CONFIG_CCSECURITY_AUDIT |
376 |
|
cp2 = strstr(cp, "max_grant_log="); |
377 |
|
if (cp2) |
378 |
|
sscanf(cp2 + 14, "%u", |
379 |
|
&profile->preference.audit_max_grant_log); |
380 |
|
cp2 = strstr(cp, "max_reject_log="); |
381 |
|
if (cp2) |
382 |
|
sscanf(cp2 + 15, "%u", |
383 |
|
&profile->preference.audit_max_reject_log); |
384 |
|
#endif |
385 |
|
if (strstr(cp, "task_info=yes")) |
386 |
|
profile->preference.audit_task_info = true; |
387 |
|
else if (strstr(cp, "task_info=no")) |
388 |
|
profile->preference.audit_task_info = false; |
389 |
|
if (strstr(cp, "path_info=yes")) |
390 |
|
profile->preference.audit_path_info = true; |
391 |
|
else if (strstr(cp, "path_info=no")) |
392 |
|
profile->preference.audit_path_info = false; |
393 |
|
return 0; |
394 |
|
} |
395 |
|
if (!strcmp(data, "PREFERENCE::enforcing")) { |
396 |
|
char *cp2; |
397 |
|
if (use_default) { |
398 |
|
profile->enforcing = &ccs_default_profile.preference; |
399 |
|
return 0; |
400 |
|
} |
401 |
|
profile->enforcing = &profile->preference; |
402 |
|
if (value >= 0) |
403 |
|
profile->preference.enforcing_verbose = value; |
404 |
|
cp2 = strstr(cp, "penalty="); |
405 |
|
if (cp2) |
406 |
|
sscanf(cp2 + 8, "%u", |
407 |
|
&profile->preference.enforcing_penalty); |
408 |
|
return 0; |
409 |
|
} |
410 |
|
if (!strcmp(data, "PREFERENCE::permissive")) { |
411 |
|
if (use_default) { |
412 |
|
profile->permissive = &ccs_default_profile.preference; |
413 |
|
return 0; |
414 |
|
} |
415 |
|
profile->permissive = &profile->preference; |
416 |
|
if (value >= 0) |
417 |
|
profile->preference.permissive_verbose = value; |
418 |
|
return 0; |
419 |
|
} |
420 |
|
if (!strcmp(data, "PREFERENCE::learning")) { |
421 |
|
char *cp2; |
422 |
|
if (use_default) { |
423 |
|
profile->learning = &ccs_default_profile.preference; |
424 |
|
return 0; |
425 |
|
} |
426 |
|
profile->learning = &profile->preference; |
427 |
|
if (value >= 0) |
428 |
|
profile->preference.learning_verbose = value; |
429 |
|
cp2 = strstr(cp, "max_entry="); |
430 |
|
if (cp2) |
431 |
|
sscanf(cp2 + 10, "%u", |
432 |
|
&profile->preference.learning_max_entry); |
433 |
|
if (strstr(cp, "exec.realpath=yes")) |
434 |
|
profile->preference.learning_exec_realpath = true; |
435 |
|
else if (strstr(cp, "exec.realpath=no")) |
436 |
|
profile->preference.learning_exec_realpath = false; |
437 |
|
if (strstr(cp, "exec.argv0=yes")) |
438 |
|
profile->preference.learning_exec_argv0 = true; |
439 |
|
else if (strstr(cp, "exec.argv0=no")) |
440 |
|
profile->preference.learning_exec_argv0 = false; |
441 |
|
if (strstr(cp, "symlink.target=yes")) |
442 |
|
profile->preference.learning_symlink_target = true; |
443 |
|
else if (strstr(cp, "symlink.target=no")) |
444 |
|
profile->preference.learning_symlink_target = false; |
445 |
|
return 0; |
446 |
|
} |
447 |
|
if (profile == &ccs_default_profile) |
448 |
|
return -EINVAL; |
449 |
if (!strcmp(data, "COMMENT")) { |
if (!strcmp(data, "COMMENT")) { |
450 |
const struct ccs_path_info *new_comment = ccs_get_name(cp); |
const struct ccs_path_info *old_comment = profile->comment; |
451 |
const struct ccs_path_info *old_comment; |
profile->comment = ccs_get_name(cp); |
|
/* Protect reader from ccs_put_name(). */ |
|
|
spin_lock(&ccs_profile_comment_lock); |
|
|
old_comment = ccs_profile->comment; |
|
|
ccs_profile->comment = new_comment; |
|
|
spin_unlock(&ccs_profile_comment_lock); |
|
452 |
ccs_put_name(old_comment); |
ccs_put_name(old_comment); |
453 |
return 0; |
return 0; |
454 |
} |
} |
455 |
if (!ccs_str_starts(&data, "MAC::")) |
if (!strcmp(data, "CONFIG")) { |
456 |
goto not_mac; |
i = CCS_MAX_MAC_INDEX + CCS_MAX_CAPABILITY_INDEX |
457 |
if (ccs_str_starts(&data, CCS_KEYWORD_CAPABILITY)) |
+ CCS_MAX_MAC_CATEGORY_INDEX; |
458 |
for (i = 0; i < CCS_MAX_CAPABILITY_INDEX; i++) { |
config = profile->default_config; |
459 |
if (strcmp(data, |
} else if (ccs_str_starts(&data, "CONFIG::")) { |
460 |
ccs_mac_keywords[CCS_MAX_MAC_INDEX + i])) |
config = 0; |
461 |
continue; |
for (i = 0; i < CCS_MAX_MAC_INDEX + CCS_MAX_CAPABILITY_INDEX |
462 |
index = CCS_MAX_MAC_INDEX + i; |
+ CCS_MAX_MAC_CATEGORY_INDEX; i++) { |
|
break; |
|
|
} |
|
|
else |
|
|
for (i = 0; i < CCS_MAX_MAC_INDEX; i++) { |
|
463 |
if (strcmp(data, ccs_mac_keywords[i])) |
if (strcmp(data, ccs_mac_keywords[i])) |
464 |
continue; |
continue; |
465 |
index = i; |
config = profile->config[i]; |
466 |
break; |
break; |
467 |
} |
} |
468 |
if (index < 0) |
if (i == CCS_MAX_MAC_INDEX + CCS_MAX_CAPABILITY_INDEX |
469 |
|
+ CCS_MAX_MAC_CATEGORY_INDEX) |
470 |
|
return -EINVAL; |
471 |
|
} else { |
472 |
return -EINVAL; |
return -EINVAL; |
|
ccs_mac_keywords_used[index] = 1; |
|
|
ccs_profile->no_grant_log[index] = !!strstr(cp, "no_grant_log"); |
|
|
ccs_profile->no_reject_log[index] = !!strstr(cp, "no_reject_log"); |
|
|
for (mode = 0; mode < 4; mode++) |
|
|
if (strstr(cp, ccs_mode_4[mode])) |
|
|
ccs_profile->mac_mode[index] = mode; |
|
|
return 0; |
|
|
not_mac: |
|
|
for (i = 0; i < CCS_MAX_CONTROL_INDEX; i++) { |
|
|
if (strcmp(data, ccs_control_array[i].keyword)) |
|
|
continue; |
|
|
if (sscanf(cp, "%u", &value) != 1) { |
|
|
int j; |
|
|
for (j = 0; j < 2; j++) { |
|
|
if (strcmp(cp, ccs_mode_2[j])) |
|
|
continue; |
|
|
value = j; |
|
|
break; |
|
|
} |
|
|
if (j == 2) |
|
|
return -EINVAL; |
|
|
} else if (value > ccs_control_array[i].max_value) { |
|
|
value = ccs_control_array[i].max_value; |
|
|
} |
|
|
ccs_profile->value[i] = value; |
|
|
return 0; |
|
473 |
} |
} |
474 |
return -EINVAL; |
if (use_default) { |
475 |
} |
config = CCS_CONFIG_USE_DEFAULT; |
476 |
|
} else { |
477 |
static bool ccs_print_mac_mode(struct ccs_io_buffer *head, u8 index) |
for (mode = 3; mode >= 0; mode--) |
478 |
{ |
if (strstr(cp, ccs_mode_4[mode])) |
479 |
const int pos = head->read_avail; |
/* |
480 |
int i; |
* Update lower 3 bits in order to distinguish |
481 |
const struct ccs_profile *ccs_profile = ccs_profile_ptr[index]; |
* 'config' from 'CCS_CONFIG_USE_DEAFULT'. |
482 |
for (i = 0; i < CCS_MAX_MAC_INDEX + CCS_MAX_CAPABILITY_INDEX; i++) { |
*/ |
483 |
if (!ccs_mac_keywords_used[index]) |
config = (config & ~7) | mode; |
484 |
continue; |
#ifdef CONFIG_CCSECURITY_AUDIT |
485 |
if (!ccs_io_printf(head, "%u-MAC::%s%s=%s %s %s\n", index, |
if (config != CCS_CONFIG_USE_DEFAULT) { |
486 |
i >= CCS_MAX_MAC_INDEX ? |
if (strstr(cp, "grant_log=yes")) |
487 |
CCS_KEYWORD_CAPABILITY : "", |
config |= CCS_CONFIG_WANT_GRANT_LOG; |
488 |
ccs_mac_keywords[i], |
else if (strstr(cp, "grant_log=no")) |
489 |
ccs_mode_4[ccs_profile->mac_mode[i]], |
config &= ~CCS_CONFIG_WANT_GRANT_LOG; |
490 |
ccs_profile->no_grant_log[i] ? |
if (strstr(cp, "reject_log=yes")) |
491 |
"no_grant_log" : "", |
config |= CCS_CONFIG_WANT_REJECT_LOG; |
492 |
ccs_profile->no_reject_log[i] ? |
else if (strstr(cp, "reject_log=no")) |
493 |
"no_reject_log" : "")) |
config &= ~CCS_CONFIG_WANT_REJECT_LOG; |
494 |
goto out; |
} |
495 |
|
#endif |
496 |
} |
} |
497 |
return true; |
if (i < CCS_MAX_MAC_INDEX + CCS_MAX_CAPABILITY_INDEX |
498 |
out: |
+ CCS_MAX_MAC_CATEGORY_INDEX) |
499 |
head->read_avail = pos; |
profile->config[i] = config; |
500 |
return false; |
else if (config != CCS_CONFIG_USE_DEFAULT) |
501 |
|
profile->default_config = config; |
502 |
|
return 0; |
503 |
} |
} |
504 |
|
|
505 |
/** |
/** |
506 |
* ccs_read_profile - Read profile table. |
* ccs_read_profile - Read profile table. |
507 |
* |
* |
508 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
|
* |
|
|
* Returns 0. |
|
509 |
*/ |
*/ |
510 |
static int ccs_read_profile(struct ccs_io_buffer *head) |
static void ccs_read_profile(struct ccs_io_buffer *head) |
511 |
{ |
{ |
512 |
static const int ccs_total = CCS_MAX_CONTROL_INDEX + 2; |
int index; |
|
int step; |
|
513 |
if (head->read_eof) |
if (head->read_eof) |
514 |
return 0; |
return; |
515 |
for (step = head->read_step; step < CCS_MAX_PROFILES * ccs_total; |
if (head->read_bit) |
516 |
step++) { |
goto body; |
517 |
const u8 index = step / ccs_total; |
ccs_io_printf(head, "PROFILE_VERSION=%s\n", "20090903"); |
518 |
u8 type = step % ccs_total; |
ccs_io_printf(head, "PREFERENCE::audit={ " |
519 |
const struct ccs_profile *ccs_profile = ccs_profile_ptr[index]; |
#ifdef CONFIG_CCSECURITY_AUDIT |
520 |
head->read_step = step; |
"max_grant_log=%u max_reject_log=%u " |
521 |
if (!ccs_profile) |
#endif |
522 |
continue; |
"task_info=%s path_info=%s }\n", |
523 |
if (!type) { /* Print profile' comment tag. */ |
#ifdef CONFIG_CCSECURITY_AUDIT |
524 |
bool done; |
ccs_default_profile.preference.audit_max_grant_log, |
525 |
spin_lock(&ccs_profile_comment_lock); |
ccs_default_profile.preference.audit_max_reject_log, |
526 |
done = ccs_io_printf(head, "%u-COMMENT=%s\n", |
#endif |
527 |
index, ccs_profile->comment ? |
ccs_yesno(ccs_default_profile.preference. |
528 |
ccs_profile->comment->name : ""); |
audit_task_info), |
529 |
spin_unlock(&ccs_profile_comment_lock); |
ccs_yesno(ccs_default_profile.preference. |
530 |
if (!done) |
audit_path_info)); |
531 |
break; |
ccs_io_printf(head, "PREFERENCE::learning={ verbose=%s max_entry=%u " |
532 |
continue; |
"exec.realpath=%s exec.argv0=%s symlink.target=%s }\n", |
533 |
} else if (type == 1) { |
ccs_yesno(ccs_default_profile.preference. |
534 |
if (!ccs_print_mac_mode(head, index)) |
learning_verbose), |
535 |
break; |
ccs_default_profile.preference.learning_max_entry, |
536 |
|
ccs_yesno(ccs_default_profile.preference. |
537 |
|
learning_exec_realpath), |
538 |
|
ccs_yesno(ccs_default_profile.preference. |
539 |
|
learning_exec_argv0), |
540 |
|
ccs_yesno(ccs_default_profile.preference. |
541 |
|
learning_symlink_target)); |
542 |
|
ccs_io_printf(head, "PREFERENCE::permissive={ verbose=%s }\n", |
543 |
|
ccs_yesno(ccs_default_profile.preference. |
544 |
|
permissive_verbose)); |
545 |
|
ccs_io_printf(head, "PREFERENCE::enforcing={ verbose=%s penalty=%u " |
546 |
|
"}\n", |
547 |
|
ccs_yesno(ccs_default_profile.preference. |
548 |
|
enforcing_verbose), |
549 |
|
ccs_default_profile.preference.enforcing_penalty); |
550 |
|
head->read_bit = 1; |
551 |
|
body: |
552 |
|
for (index = head->read_step; index < CCS_MAX_PROFILES; index++) { |
553 |
|
bool done; |
554 |
|
u8 config; |
555 |
|
int i; |
556 |
|
int pos; |
557 |
|
const struct ccs_profile *profile = ccs_profile_ptr[index]; |
558 |
|
const struct ccs_path_info *comment; |
559 |
|
head->read_step = index; |
560 |
|
if (!profile) |
561 |
continue; |
continue; |
562 |
|
pos = head->read_avail; |
563 |
|
comment = profile->comment; |
564 |
|
done = ccs_io_printf(head, "%u-COMMENT=%s\n", index, |
565 |
|
comment ? comment->name : ""); |
566 |
|
if (!done) |
567 |
|
goto out; |
568 |
|
config = profile->default_config; |
569 |
|
#ifdef CONFIG_CCSECURITY_AUDIT |
570 |
|
if (!ccs_io_printf(head, "%u-CONFIG={ mode=%s grant_log=%s " |
571 |
|
"reject_log=%s }\n", index, |
572 |
|
ccs_mode_4[config & 3], |
573 |
|
ccs_yesno(config & |
574 |
|
CCS_CONFIG_WANT_GRANT_LOG), |
575 |
|
ccs_yesno(config & |
576 |
|
CCS_CONFIG_WANT_REJECT_LOG))) |
577 |
|
goto out; |
578 |
|
#else |
579 |
|
if (!ccs_io_printf(head, "%u-CONFIG={ mode=%s }\n", index, |
580 |
|
ccs_mode_4[config & 3])) |
581 |
|
goto out; |
582 |
|
#endif |
583 |
|
for (i = 0; i < CCS_MAX_MAC_INDEX + CCS_MAX_CAPABILITY_INDEX |
584 |
|
+ CCS_MAX_MAC_CATEGORY_INDEX; i++) { |
585 |
|
#ifdef CONFIG_CCSECURITY_AUDIT |
586 |
|
const char *g; |
587 |
|
const char *r; |
588 |
|
#endif |
589 |
|
config = profile->config[i]; |
590 |
|
if (config == CCS_CONFIG_USE_DEFAULT) |
591 |
|
continue; |
592 |
|
#ifdef CONFIG_CCSECURITY_AUDIT |
593 |
|
g = ccs_yesno(config & CCS_CONFIG_WANT_GRANT_LOG); |
594 |
|
r = ccs_yesno(config & CCS_CONFIG_WANT_REJECT_LOG); |
595 |
|
if (!ccs_io_printf(head, "%u-CONFIG::%s={ mode=%s " |
596 |
|
"grant_log=%s reject_log=%s }\n", |
597 |
|
index, ccs_mac_keywords[i], |
598 |
|
ccs_mode_4[config & 3], g, r)) |
599 |
|
goto out; |
600 |
|
#else |
601 |
|
if (!ccs_io_printf(head, "%u-CONFIG::%s={ mode=%s }\n", |
602 |
|
index, ccs_mac_keywords[i], |
603 |
|
ccs_mode_4[config & 3])) |
604 |
|
goto out; |
605 |
|
#endif |
606 |
} |
} |
607 |
type -= 2; |
if (profile->audit != &ccs_default_profile.preference && |
608 |
{ |
!ccs_io_printf(head, "%u-PREFERENCE::audit={ " |
609 |
const unsigned int value = ccs_profile->value[type]; |
#ifdef CONFIG_CCSECURITY_AUDIT |
610 |
const char *keyword = ccs_control_array[type].keyword; |
"max_grant_log=%u max_reject_log=%u " |
611 |
if (ccs_control_array[type].max_value == 1) { |
#endif |
612 |
if (!ccs_io_printf(head, "%u-%s=%s\n", index, |
"task_info=%s path_info=%s }\n", index, |
613 |
keyword, ccs_mode_2[value])) |
#ifdef CONFIG_CCSECURITY_AUDIT |
614 |
break; |
profile->preference.audit_max_grant_log, |
615 |
} else { |
profile->preference.audit_max_reject_log, |
616 |
if (!ccs_io_printf(head, "%u-%s=%u\n", index, |
#endif |
617 |
keyword, value)) |
ccs_yesno(profile->preference. |
618 |
break; |
audit_task_info), |
619 |
} |
ccs_yesno(profile->preference. |
620 |
} |
audit_path_info))) |
621 |
|
goto out; |
622 |
|
if (profile->learning != &ccs_default_profile.preference && |
623 |
|
!ccs_io_printf(head, "%u-PREFERENCE::learning={ " |
624 |
|
"verbose=%s max_entry=%u exec.realpath=%s " |
625 |
|
"exec.argv0=%s symlink.target=%s }\n", |
626 |
|
index, |
627 |
|
ccs_yesno(profile->preference. |
628 |
|
learning_verbose), |
629 |
|
profile->preference.learning_max_entry, |
630 |
|
ccs_yesno(profile->preference. |
631 |
|
learning_exec_realpath), |
632 |
|
ccs_yesno(profile->preference. |
633 |
|
learning_exec_argv0), |
634 |
|
ccs_yesno(profile->preference. |
635 |
|
learning_symlink_target))) |
636 |
|
goto out; |
637 |
|
if (profile->permissive != &ccs_default_profile.preference && |
638 |
|
!ccs_io_printf(head, "%u-PREFERENCE::permissive={ " |
639 |
|
"verbose=%s }\n", index, |
640 |
|
ccs_yesno(profile->preference. |
641 |
|
permissive_verbose))) |
642 |
|
goto out; |
643 |
|
if (profile->enforcing != &ccs_default_profile.preference && |
644 |
|
!ccs_io_printf(head, "%u-PREFERENCE::enforcing={ " |
645 |
|
"verbose=%s penalty=%u }\n", index, |
646 |
|
ccs_yesno(profile->preference. |
647 |
|
enforcing_verbose), |
648 |
|
profile->preference.enforcing_penalty)) |
649 |
|
goto out; |
650 |
|
continue; |
651 |
|
out: |
652 |
|
head->read_avail = pos; |
653 |
|
break; |
654 |
} |
} |
655 |
if (step == CCS_MAX_PROFILES * ccs_total) |
if (index == CCS_MAX_PROFILES) |
656 |
head->read_eof = true; |
head->read_eof = true; |
|
return 0; |
|
657 |
} |
} |
658 |
|
|
659 |
/* The list for "struct ccs_policy_manager_entry". */ |
/* The list for "struct ccs_policy_manager_entry". */ |
669 |
*/ |
*/ |
670 |
static int ccs_update_manager_entry(const char *manager, const bool is_delete) |
static int ccs_update_manager_entry(const char *manager, const bool is_delete) |
671 |
{ |
{ |
|
struct ccs_policy_manager_entry *entry = NULL; |
|
672 |
struct ccs_policy_manager_entry *ptr; |
struct ccs_policy_manager_entry *ptr; |
673 |
struct ccs_policy_manager_entry e = { }; |
struct ccs_policy_manager_entry e = { }; |
674 |
int error = is_delete ? -ENOENT : -ENOMEM; |
int error = is_delete ? -ENOENT : -ENOMEM; |
683 |
e.manager = ccs_get_name(manager); |
e.manager = ccs_get_name(manager); |
684 |
if (!e.manager) |
if (!e.manager) |
685 |
return -ENOMEM; |
return -ENOMEM; |
|
if (!is_delete) |
|
|
entry = kmalloc(sizeof(e), GFP_KERNEL); |
|
686 |
mutex_lock(&ccs_policy_lock); |
mutex_lock(&ccs_policy_lock); |
687 |
list_for_each_entry_rcu(ptr, &ccs_policy_manager_list, list) { |
list_for_each_entry_rcu(ptr, &ccs_policy_manager_list, list) { |
688 |
if (ptr->manager != e.manager) |
if (ptr->manager != e.manager) |
691 |
error = 0; |
error = 0; |
692 |
break; |
break; |
693 |
} |
} |
694 |
if (!is_delete && error && ccs_commit_ok(entry, &e, sizeof(e))) { |
if (!is_delete && error) { |
695 |
list_add_tail_rcu(&entry->list, &ccs_policy_manager_list); |
struct ccs_policy_manager_entry *entry = |
696 |
entry = NULL; |
ccs_commit_ok(&e, sizeof(e)); |
697 |
error = 0; |
if (entry) { |
698 |
|
list_add_tail_rcu(&entry->list, |
699 |
|
&ccs_policy_manager_list); |
700 |
|
error = 0; |
701 |
|
} |
702 |
} |
} |
703 |
mutex_unlock(&ccs_policy_lock); |
mutex_unlock(&ccs_policy_lock); |
704 |
ccs_put_name(e.manager); |
ccs_put_name(e.manager); |
|
kfree(entry); |
|
705 |
return error; |
return error; |
706 |
} |
} |
707 |
|
|
728 |
* |
* |
729 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
730 |
* |
* |
|
* Returns 0. |
|
|
* |
|
731 |
* Caller holds ccs_read_lock(). |
* Caller holds ccs_read_lock(). |
732 |
*/ |
*/ |
733 |
static int ccs_read_manager_policy(struct ccs_io_buffer *head) |
static void ccs_read_manager_policy(struct ccs_io_buffer *head) |
734 |
{ |
{ |
735 |
struct list_head *pos; |
struct list_head *pos; |
|
ccs_assert_read_lock(); |
|
736 |
if (head->read_eof) |
if (head->read_eof) |
737 |
return 0; |
return; |
738 |
list_for_each_cookie(pos, head->read_var2, &ccs_policy_manager_list) { |
list_for_each_cookie(pos, head->read_var2, &ccs_policy_manager_list) { |
739 |
struct ccs_policy_manager_entry *ptr; |
struct ccs_policy_manager_entry *ptr; |
740 |
ptr = list_entry(pos, struct ccs_policy_manager_entry, list); |
ptr = list_entry(pos, struct ccs_policy_manager_entry, list); |
741 |
if (ptr->is_deleted) |
if (ptr->is_deleted) |
742 |
continue; |
continue; |
743 |
if (!ccs_io_printf(head, "%s\n", ptr->manager->name)) |
if (!ccs_io_printf(head, "%s\n", ptr->manager->name)) |
744 |
return 0; |
return; |
745 |
} |
} |
746 |
head->read_eof = true; |
head->read_eof = true; |
|
return 0; |
|
747 |
} |
} |
748 |
|
|
749 |
/** |
/** |
762 |
const struct ccs_path_info *domainname |
const struct ccs_path_info *domainname |
763 |
= ccs_current_domain()->domainname; |
= ccs_current_domain()->domainname; |
764 |
bool found = false; |
bool found = false; |
|
ccs_assert_read_lock(); |
|
765 |
if (!ccs_policy_loaded) |
if (!ccs_policy_loaded) |
766 |
return true; |
return true; |
767 |
if (task->ccs_flags & CCS_TASK_IS_POLICY_MANAGER) |
if (task->ccs_flags & CCS_TASK_IS_POLICY_MANAGER) |
842 |
{ |
{ |
843 |
unsigned int pid; |
unsigned int pid; |
844 |
struct ccs_domain_info *domain = NULL; |
struct ccs_domain_info *domain = NULL; |
845 |
ccs_assert_read_lock(); |
bool global_pid = false; |
846 |
if (!strcmp(data, "allow_execute")) { |
if (!strcmp(data, "allow_execute")) { |
847 |
head->read_execute_only = true; |
head->read_execute_only = true; |
848 |
return true; |
return true; |
849 |
} |
} |
850 |
if (sscanf(data, "pid=%u", &pid) == 1) { |
if (sscanf(data, "pid=%u", &pid) == 1 || |
851 |
|
(global_pid = true, sscanf(data, "global-pid=%u", &pid) == 1)) { |
852 |
struct task_struct *p; |
struct task_struct *p; |
853 |
read_lock(&tasklist_lock); |
ccs_tasklist_lock(); |
854 |
|
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24) |
855 |
|
if (global_pid) |
856 |
|
p = ccsecurity_exports.find_task_by_pid_ns(pid, |
857 |
|
&init_pid_ns); |
858 |
|
else |
859 |
|
p = ccsecurity_exports.find_task_by_vpid(pid); |
860 |
|
#else |
861 |
p = find_task_by_pid(pid); |
p = find_task_by_pid(pid); |
862 |
|
#endif |
863 |
if (p) |
if (p) |
864 |
domain = ccs_task_domain(p); |
domain = ccs_task_domain(p); |
865 |
read_unlock(&tasklist_lock); |
ccs_tasklist_unlock(); |
866 |
} else if (!strncmp(data, "domain=", 7)) { |
} else if (!strncmp(data, "domain=", 7)) { |
867 |
if (ccs_is_domain_def(data + 7)) |
if (ccs_is_domain_def(data + 7)) |
868 |
domain = ccs_find_domain(data + 7); |
domain = ccs_find_domain(data + 7); |
908 |
return ccs_write_env_policy(data, domain, cond, is_delete); |
return ccs_write_env_policy(data, domain, cond, is_delete); |
909 |
if (ccs_str_starts(&data, CCS_KEYWORD_ALLOW_MOUNT)) |
if (ccs_str_starts(&data, CCS_KEYWORD_ALLOW_MOUNT)) |
910 |
return ccs_write_mount_policy(data, domain, cond, is_delete); |
return ccs_write_mount_policy(data, domain, cond, is_delete); |
|
if (ccs_str_starts(&data, CCS_KEYWORD_ALLOW_UNMOUNT)) |
|
|
return ccs_write_umount_policy(data, domain, cond, is_delete); |
|
|
if (ccs_str_starts(&data, CCS_KEYWORD_ALLOW_CHROOT)) |
|
|
return ccs_write_chroot_policy(data, domain, cond, is_delete); |
|
|
if (ccs_str_starts(&data, CCS_KEYWORD_ALLOW_PIVOT_ROOT)) |
|
|
return ccs_write_pivot_root_policy(data, domain, cond, |
|
|
is_delete); |
|
911 |
return ccs_write_file_policy(data, domain, cond, is_delete); |
return ccs_write_file_policy(data, domain, cond, is_delete); |
912 |
} |
} |
913 |
|
|
953 |
|
|
954 |
if (sscanf(data, CCS_KEYWORD_USE_PROFILE "%u", &profile) == 1 |
if (sscanf(data, CCS_KEYWORD_USE_PROFILE "%u", &profile) == 1 |
955 |
&& profile < CCS_MAX_PROFILES) { |
&& profile < CCS_MAX_PROFILES) { |
956 |
if (ccs_profile_ptr[profile] || !ccs_policy_loaded) |
if (!ccs_policy_loaded || ccs_profile_ptr[(u8) profile]) |
957 |
domain->profile = (u8) profile; |
domain->profile = (u8) profile; |
958 |
return 0; |
return 0; |
959 |
} |
} |
965 |
domain->ignore_global_allow_env = !is_delete; |
domain->ignore_global_allow_env = !is_delete; |
966 |
return 0; |
return 0; |
967 |
} |
} |
968 |
|
if (!strcmp(data, CCS_KEYWORD_QUOTA_EXCEEDED)) { |
969 |
|
domain->quota_warned = !is_delete; |
970 |
|
return 0; |
971 |
|
} |
972 |
|
if (!strcmp(data, CCS_KEYWORD_TRANSITION_FAILED)) { |
973 |
|
domain->domain_transition_failed = !is_delete; |
974 |
|
return 0; |
975 |
|
} |
976 |
cp = ccs_find_condition_part(data); |
cp = ccs_find_condition_part(data); |
977 |
if (cp) { |
if (cp) { |
978 |
cond = ccs_get_condition(cp); |
cond = ccs_get_condition(cp); |
985 |
return error; |
return error; |
986 |
} |
} |
987 |
|
|
988 |
|
/** |
989 |
|
* ccs_print_name_union - Print a ccs_name_union. |
990 |
|
* |
991 |
|
* @head: Pointer to "struct ccs_io_buffer". |
992 |
|
* @ptr: Pointer to "struct ccs_name_union". |
993 |
|
* |
994 |
|
* Returns true on success, false otherwise. |
995 |
|
*/ |
996 |
static bool ccs_print_name_union(struct ccs_io_buffer *head, |
static bool ccs_print_name_union(struct ccs_io_buffer *head, |
997 |
const struct ccs_name_union *ptr) |
const struct ccs_name_union *ptr) |
998 |
{ |
{ |
1005 |
return ccs_io_printf(head, " %s", ptr->filename->name); |
return ccs_io_printf(head, " %s", ptr->filename->name); |
1006 |
} |
} |
1007 |
|
|
1008 |
|
/** |
1009 |
|
* ccs_print_name_union_quoted - Print a ccs_name_union with double quotes. |
1010 |
|
* |
1011 |
|
* @head: Pointer to "struct ccs_io_buffer". |
1012 |
|
* @ptr: Pointer to "struct ccs_name_union". |
1013 |
|
* |
1014 |
|
* Returns true on success, false otherwise. |
1015 |
|
*/ |
1016 |
static bool ccs_print_name_union_quoted(struct ccs_io_buffer *head, |
static bool ccs_print_name_union_quoted(struct ccs_io_buffer *head, |
1017 |
const struct ccs_name_union *ptr) |
const struct ccs_name_union *ptr) |
1018 |
{ |
{ |
1022 |
return ccs_io_printf(head, "\"%s\"", ptr->filename->name); |
return ccs_io_printf(head, "\"%s\"", ptr->filename->name); |
1023 |
} |
} |
1024 |
|
|
1025 |
|
/** |
1026 |
|
* ccs_print_number_union_common - Print a ccs_number_union. |
1027 |
|
* |
1028 |
|
* @head: Pointer to "struct ccs_io_buffer". |
1029 |
|
* @ptr: Pointer to "struct ccs_number_union". |
1030 |
|
* @need_space: True if a space character is needed. |
1031 |
|
* |
1032 |
|
* Returns true on success, false otherwise. |
1033 |
|
*/ |
1034 |
static bool ccs_print_number_union_common(struct ccs_io_buffer *head, |
static bool ccs_print_number_union_common(struct ccs_io_buffer *head, |
1035 |
const struct ccs_number_union *ptr, |
const struct ccs_number_union *ptr, |
1036 |
const bool need_space) |
const bool need_space) |
1074 |
} |
} |
1075 |
} |
} |
1076 |
|
|
1077 |
|
/** |
1078 |
|
* ccs_print_number_union - Print a ccs_number_union. |
1079 |
|
* |
1080 |
|
* @head: Pointer to "struct ccs_io_buffer". |
1081 |
|
* @ptr: Pointer to "struct ccs_number_union". |
1082 |
|
* |
1083 |
|
* Returns true on success, false otherwise. |
1084 |
|
*/ |
1085 |
bool ccs_print_number_union(struct ccs_io_buffer *head, |
bool ccs_print_number_union(struct ccs_io_buffer *head, |
1086 |
const struct ccs_number_union *ptr) |
const struct ccs_number_union *ptr) |
1087 |
{ |
{ |
1088 |
return ccs_print_number_union_common(head, ptr, true); |
return ccs_print_number_union_common(head, ptr, true); |
1089 |
} |
} |
1090 |
|
|
1091 |
|
/** |
1092 |
|
* ccs_print_number_union_nospace - Print a ccs_number_union without a space character. |
1093 |
|
* |
1094 |
|
* @head: Pointer to "struct ccs_io_buffer". |
1095 |
|
* @ptr: Pointer to "struct ccs_number_union". |
1096 |
|
* |
1097 |
|
* Returns true on success, false otherwise. |
1098 |
|
*/ |
1099 |
static bool ccs_print_number_union_nospace(struct ccs_io_buffer *head, |
static bool ccs_print_number_union_nospace(struct ccs_io_buffer *head, |
1100 |
const struct ccs_number_union *ptr) |
const struct ccs_number_union *ptr) |
1101 |
{ |
{ |
1214 |
} |
} |
1215 |
|
|
1216 |
/** |
/** |
1217 |
* ccs_print_path_acl - Print a single path ACL entry. |
* ccs_print_path_acl - Print a path ACL entry. |
1218 |
* |
* |
1219 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1220 |
* @ptr: Pointer to "struct ccs_path_acl". |
* @ptr: Pointer to "struct ccs_path_acl". |
1223 |
* Returns true on success, false otherwise. |
* Returns true on success, false otherwise. |
1224 |
*/ |
*/ |
1225 |
static bool ccs_print_path_acl(struct ccs_io_buffer *head, |
static bool ccs_print_path_acl(struct ccs_io_buffer *head, |
1226 |
struct ccs_path_acl *ptr, |
struct ccs_path_acl *ptr, |
1227 |
const struct ccs_condition *cond) |
const struct ccs_condition *cond) |
1228 |
{ |
{ |
1229 |
int pos; |
int pos; |
1230 |
u8 bit; |
u8 bit; |
1232 |
for (bit = head->read_bit; bit < CCS_MAX_PATH_OPERATION; bit++) { |
for (bit = head->read_bit; bit < CCS_MAX_PATH_OPERATION; bit++) { |
1233 |
if (!(perm & (1 << bit))) |
if (!(perm & (1 << bit))) |
1234 |
continue; |
continue; |
1235 |
if (head->read_execute_only && bit != CCS_TYPE_EXECUTE) |
if (head->read_execute_only && bit != CCS_TYPE_EXECUTE |
1236 |
|
&& bit != CCS_TYPE_TRANSIT) |
1237 |
continue; |
continue; |
1238 |
/* Print "read/write" instead of "read" and "write". */ |
/* Print "read/write" instead of "read" and "write". */ |
1239 |
if ((bit == CCS_TYPE_READ || bit == CCS_TYPE_WRITE) |
if ((bit == CCS_TYPE_READ || bit == CCS_TYPE_WRITE) |
1262 |
* Returns true on success, false otherwise. |
* Returns true on success, false otherwise. |
1263 |
*/ |
*/ |
1264 |
static bool ccs_print_path_number3_acl(struct ccs_io_buffer *head, |
static bool ccs_print_path_number3_acl(struct ccs_io_buffer *head, |
1265 |
struct ccs_path_number3_acl *ptr, |
struct ccs_path_number3_acl *ptr, |
1266 |
const struct ccs_condition *cond) |
const struct ccs_condition *cond) |
1267 |
{ |
{ |
1268 |
int pos; |
int pos; |
1269 |
u8 bit; |
u8 bit; |
1290 |
} |
} |
1291 |
|
|
1292 |
/** |
/** |
1293 |
* ccs_print_path2_acl - Print a double path ACL entry. |
* ccs_print_path2_acl - Print a path2 ACL entry. |
1294 |
* |
* |
1295 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1296 |
* @ptr: Pointer to "struct ccs_path2_acl". |
* @ptr: Pointer to "struct ccs_path2_acl". |
1299 |
* Returns true on success, false otherwise. |
* Returns true on success, false otherwise. |
1300 |
*/ |
*/ |
1301 |
static bool ccs_print_path2_acl(struct ccs_io_buffer *head, |
static bool ccs_print_path2_acl(struct ccs_io_buffer *head, |
1302 |
struct ccs_path2_acl *ptr, |
struct ccs_path2_acl *ptr, |
1303 |
const struct ccs_condition *cond) |
const struct ccs_condition *cond) |
1304 |
{ |
{ |
1305 |
int pos; |
int pos; |
1306 |
u8 bit; |
u8 bit; |
1324 |
} |
} |
1325 |
|
|
1326 |
/** |
/** |
1327 |
* ccs_print_path_number_acl - Print an ioctl/chmod/chown/chgrp ACL entry. |
* ccs_print_path_number_acl - Print a path_number ACL entry. |
1328 |
* |
* |
1329 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1330 |
* @ptr: Pointer to "struct ccs_path_number_acl". |
* @ptr: Pointer to "struct ccs_path_number_acl". |
1566 |
} |
} |
1567 |
|
|
1568 |
/** |
/** |
|
* ccs_print_umount_acl - Print a mount ACL entry. |
|
|
* |
|
|
* @head: Pointer to "struct ccs_io_buffer". |
|
|
* @ptr: Pointer to "struct ccs_umount_acl". |
|
|
* @cond: Pointer to "struct ccs_condition". May be NULL. |
|
|
* |
|
|
* Returns true on success, false otherwise. |
|
|
*/ |
|
|
static bool ccs_print_umount_acl(struct ccs_io_buffer *head, |
|
|
struct ccs_umount_acl *ptr, |
|
|
const struct ccs_condition *cond) |
|
|
{ |
|
|
const int pos = head->read_avail; |
|
|
if (!ccs_io_printf(head, CCS_KEYWORD_ALLOW_UNMOUNT) || |
|
|
!ccs_print_name_union(head, &ptr->dir) || |
|
|
!ccs_print_condition(head, cond)) { |
|
|
head->read_avail = pos; |
|
|
return false; |
|
|
} |
|
|
return true; |
|
|
} |
|
|
|
|
|
/** |
|
|
* ccs_print_chroot_acl - Print a chroot ACL entry. |
|
|
* |
|
|
* @head: Pointer to "struct ccs_io_buffer". |
|
|
* @ptr: Pointer to "struct ccs_chroot_acl". |
|
|
* @cond: Pointer to "struct ccs_condition". May be NULL. |
|
|
* |
|
|
* Returns true on success, false otherwise. |
|
|
*/ |
|
|
static bool ccs_print_chroot_acl(struct ccs_io_buffer *head, |
|
|
struct ccs_chroot_acl *ptr, |
|
|
const struct ccs_condition *cond) |
|
|
{ |
|
|
const int pos = head->read_avail; |
|
|
if (!ccs_io_printf(head, CCS_KEYWORD_ALLOW_CHROOT) || |
|
|
!ccs_print_name_union(head, &ptr->dir) || |
|
|
!ccs_print_condition(head, cond)) { |
|
|
head->read_avail = pos; |
|
|
return false; |
|
|
} |
|
|
return true; |
|
|
} |
|
|
|
|
|
/** |
|
|
* ccs_print_pivot_root_acl - Print a pivot_root ACL entry. |
|
|
* |
|
|
* @head: Pointer to "struct ccs_io_buffer". |
|
|
* @ptr: Pointer to "struct ccs_pivot_root_acl". |
|
|
* @cond: Pointer to "struct ccs_condition". May be NULL. |
|
|
* |
|
|
* Returns true on success, false otherwise. |
|
|
*/ |
|
|
static bool ccs_print_pivot_root_acl(struct ccs_io_buffer *head, |
|
|
struct ccs_pivot_root_acl *ptr, |
|
|
const struct ccs_condition *cond) |
|
|
{ |
|
|
const int pos = head->read_avail; |
|
|
if (!ccs_io_printf(head, CCS_KEYWORD_ALLOW_PIVOT_ROOT) || |
|
|
!ccs_print_name_union(head, &ptr->new_root) || |
|
|
!ccs_print_name_union(head, &ptr->old_root) || |
|
|
!ccs_print_condition(head, cond)) { |
|
|
head->read_avail = pos; |
|
|
return false; |
|
|
} |
|
|
return true; |
|
|
} |
|
|
|
|
|
/** |
|
1569 |
* ccs_print_entry - Print an ACL entry. |
* ccs_print_entry - Print an ACL entry. |
1570 |
* |
* |
1571 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1582 |
return true; |
return true; |
1583 |
if (acl_type == CCS_TYPE_PATH_ACL) { |
if (acl_type == CCS_TYPE_PATH_ACL) { |
1584 |
struct ccs_path_acl *acl |
struct ccs_path_acl *acl |
1585 |
= container_of(ptr, struct ccs_path_acl, |
= container_of(ptr, struct ccs_path_acl, head); |
|
head); |
|
1586 |
return ccs_print_path_acl(head, acl, cond); |
return ccs_print_path_acl(head, acl, cond); |
1587 |
} |
} |
1588 |
if (acl_type == CCS_TYPE_EXECUTE_HANDLER) { |
if (acl_type == CCS_TYPE_EXECUTE_HANDLER) { |
1608 |
} |
} |
1609 |
if (acl_type == CCS_TYPE_PATH2_ACL) { |
if (acl_type == CCS_TYPE_PATH2_ACL) { |
1610 |
struct ccs_path2_acl *acl |
struct ccs_path2_acl *acl |
1611 |
= container_of(ptr, struct ccs_path2_acl, |
= container_of(ptr, struct ccs_path2_acl, head); |
|
head); |
|
1612 |
return ccs_print_path2_acl(head, acl, cond); |
return ccs_print_path2_acl(head, acl, cond); |
1613 |
} |
} |
1614 |
if (acl_type == CCS_TYPE_PATH_NUMBER_ACL) { |
if (acl_type == CCS_TYPE_PATH_NUMBER_ACL) { |
1615 |
struct ccs_path_number_acl *acl |
struct ccs_path_number_acl *acl |
1616 |
= container_of(ptr, struct ccs_path_number_acl, |
= container_of(ptr, struct ccs_path_number_acl, head); |
|
head); |
|
1617 |
return ccs_print_path_number_acl(head, acl, cond); |
return ccs_print_path_number_acl(head, acl, cond); |
1618 |
} |
} |
1619 |
if (acl_type == CCS_TYPE_ENV_ACL) { |
if (acl_type == CCS_TYPE_ENV_ACL) { |
1623 |
} |
} |
1624 |
if (acl_type == CCS_TYPE_CAPABILITY_ACL) { |
if (acl_type == CCS_TYPE_CAPABILITY_ACL) { |
1625 |
struct ccs_capability_acl *acl |
struct ccs_capability_acl *acl |
1626 |
= container_of(ptr, struct ccs_capability_acl, |
= container_of(ptr, struct ccs_capability_acl, head); |
|
head); |
|
1627 |
return ccs_print_capability_acl(head, acl, cond); |
return ccs_print_capability_acl(head, acl, cond); |
1628 |
} |
} |
1629 |
if (acl_type == CCS_TYPE_IP_NETWORK_ACL) { |
if (acl_type == CCS_TYPE_IP_NETWORK_ACL) { |
1630 |
struct ccs_ip_network_acl *acl |
struct ccs_ip_network_acl *acl |
1631 |
= container_of(ptr, struct ccs_ip_network_acl, |
= container_of(ptr, struct ccs_ip_network_acl, head); |
|
head); |
|
1632 |
return ccs_print_network_acl(head, acl, cond); |
return ccs_print_network_acl(head, acl, cond); |
1633 |
} |
} |
1634 |
if (acl_type == CCS_TYPE_SIGNAL_ACL) { |
if (acl_type == CCS_TYPE_SIGNAL_ACL) { |
1641 |
= container_of(ptr, struct ccs_mount_acl, head); |
= container_of(ptr, struct ccs_mount_acl, head); |
1642 |
return ccs_print_mount_acl(head, acl, cond); |
return ccs_print_mount_acl(head, acl, cond); |
1643 |
} |
} |
|
if (acl_type == CCS_TYPE_UMOUNT_ACL) { |
|
|
struct ccs_umount_acl *acl |
|
|
= container_of(ptr, struct ccs_umount_acl, head); |
|
|
return ccs_print_umount_acl(head, acl, cond); |
|
|
} |
|
|
if (acl_type == CCS_TYPE_CHROOT_ACL) { |
|
|
struct ccs_chroot_acl *acl |
|
|
= container_of(ptr, struct ccs_chroot_acl, head); |
|
|
return ccs_print_chroot_acl(head, acl, cond); |
|
|
} |
|
|
if (acl_type == CCS_TYPE_PIVOT_ROOT_ACL) { |
|
|
struct ccs_pivot_root_acl *acl |
|
|
= container_of(ptr, struct ccs_pivot_root_acl, |
|
|
head); |
|
|
return ccs_print_pivot_root_acl(head, acl, cond); |
|
|
} |
|
1644 |
BUG(); /* This must not happen. */ |
BUG(); /* This must not happen. */ |
1645 |
return false; |
return false; |
1646 |
} |
} |
1650 |
* |
* |
1651 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1652 |
* |
* |
|
* Returns 0. |
|
|
* |
|
1653 |
* Caller holds ccs_read_lock(). |
* Caller holds ccs_read_lock(). |
1654 |
*/ |
*/ |
1655 |
static int ccs_read_domain_policy(struct ccs_io_buffer *head) |
static void ccs_read_domain_policy(struct ccs_io_buffer *head) |
1656 |
{ |
{ |
1657 |
struct list_head *dpos; |
struct list_head *dpos; |
1658 |
struct list_head *apos; |
struct list_head *apos; |
|
ccs_assert_read_lock(); |
|
1659 |
if (head->read_eof) |
if (head->read_eof) |
1660 |
return 0; |
return; |
1661 |
if (head->read_step == 0) |
if (head->read_step == 0) |
1662 |
head->read_step = 1; |
head->read_step = 1; |
1663 |
list_for_each_cookie(dpos, head->read_var1, &ccs_domain_list) { |
list_for_each_cookie(dpos, head->read_var1, &ccs_domain_list) { |
1673 |
continue; |
continue; |
1674 |
/* Print domainname and flags. */ |
/* Print domainname and flags. */ |
1675 |
if (domain->quota_warned) |
if (domain->quota_warned) |
1676 |
quota_exceeded = "quota_exceeded\n"; |
quota_exceeded = CCS_KEYWORD_QUOTA_EXCEEDED "\n"; |
1677 |
if (domain->domain_transition_failed) |
if (domain->domain_transition_failed) |
1678 |
transition_failed = "transition_failed\n"; |
transition_failed = CCS_KEYWORD_TRANSITION_FAILED "\n"; |
1679 |
if (domain->ignore_global_allow_read) |
if (domain->ignore_global_allow_read) |
1680 |
ignore_global_allow_read |
ignore_global_allow_read |
1681 |
= CCS_KEYWORD_IGNORE_GLOBAL_ALLOW_READ "\n"; |
= CCS_KEYWORD_IGNORE_GLOBAL_ALLOW_READ "\n"; |
1688 |
transition_failed, |
transition_failed, |
1689 |
ignore_global_allow_read, |
ignore_global_allow_read, |
1690 |
ignore_global_allow_env)) |
ignore_global_allow_env)) |
1691 |
return 0; |
return; |
1692 |
head->read_step = 2; |
head->read_step = 2; |
1693 |
acl_loop: |
acl_loop: |
1694 |
if (head->read_step == 3) |
if (head->read_step == 3) |
1699 |
struct ccs_acl_info *ptr |
struct ccs_acl_info *ptr |
1700 |
= list_entry(apos, struct ccs_acl_info, list); |
= list_entry(apos, struct ccs_acl_info, list); |
1701 |
if (!ccs_print_entry(head, ptr)) |
if (!ccs_print_entry(head, ptr)) |
1702 |
return 0; |
return; |
1703 |
} |
} |
1704 |
head->read_step = 3; |
head->read_step = 3; |
1705 |
tail_mark: |
tail_mark: |
1706 |
if (!ccs_io_printf(head, "\n")) |
if (!ccs_io_printf(head, "\n")) |
1707 |
return 0; |
return; |
1708 |
head->read_step = 1; |
head->read_step = 1; |
1709 |
if (head->read_single_domain) |
if (head->read_single_domain) |
1710 |
break; |
break; |
1711 |
} |
} |
1712 |
head->read_eof = true; |
head->read_eof = true; |
|
return 0; |
|
1713 |
} |
} |
1714 |
|
|
1715 |
/** |
/** |
1722 |
* This is equivalent to doing |
* This is equivalent to doing |
1723 |
* |
* |
1724 |
* ( echo "select " $domainname; echo "use_profile " $profile ) | |
* ( echo "select " $domainname; echo "use_profile " $profile ) | |
1725 |
* /usr/lib/ccs/loadpolicy -d |
* /usr/sbin/ccs-loadpolicy -d |
1726 |
* |
* |
1727 |
* Caller holds ccs_read_lock(). |
* Caller holds ccs_read_lock(). |
1728 |
*/ |
*/ |
1732 |
char *cp = strchr(data, ' '); |
char *cp = strchr(data, ' '); |
1733 |
struct ccs_domain_info *domain; |
struct ccs_domain_info *domain; |
1734 |
unsigned int profile; |
unsigned int profile; |
|
ccs_assert_read_lock(); |
|
1735 |
if (!cp) |
if (!cp) |
1736 |
return -EINVAL; |
return -EINVAL; |
1737 |
*cp = '\0'; |
*cp = '\0'; |
1739 |
if (profile >= CCS_MAX_PROFILES) |
if (profile >= CCS_MAX_PROFILES) |
1740 |
return -EINVAL; |
return -EINVAL; |
1741 |
domain = ccs_find_domain(cp + 1); |
domain = ccs_find_domain(cp + 1); |
1742 |
if (domain && (ccs_profile_ptr[profile] || !ccs_policy_loaded)) |
if (domain && (!ccs_policy_loaded || ccs_profile_ptr[(u8) profile])) |
1743 |
domain->profile = (u8) profile; |
domain->profile = (u8) profile; |
1744 |
return 0; |
return 0; |
1745 |
} |
} |
1749 |
* |
* |
1750 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1751 |
* |
* |
|
* Returns list of profile number and domainname pairs. |
|
|
* |
|
1752 |
* This is equivalent to doing |
* This is equivalent to doing |
1753 |
* |
* |
1754 |
* grep -A 1 '^<kernel>' /proc/ccs/domain_policy | |
* grep -A 1 '^<kernel>' /proc/ccs/domain_policy | |
1758 |
* |
* |
1759 |
* Caller holds ccs_read_lock(). |
* Caller holds ccs_read_lock(). |
1760 |
*/ |
*/ |
1761 |
static int ccs_read_domain_profile(struct ccs_io_buffer *head) |
static void ccs_read_domain_profile(struct ccs_io_buffer *head) |
1762 |
{ |
{ |
1763 |
struct list_head *pos; |
struct list_head *pos; |
|
ccs_assert_read_lock(); |
|
1764 |
if (head->read_eof) |
if (head->read_eof) |
1765 |
return 0; |
return; |
1766 |
list_for_each_cookie(pos, head->read_var1, &ccs_domain_list) { |
list_for_each_cookie(pos, head->read_var1, &ccs_domain_list) { |
1767 |
struct ccs_domain_info *domain; |
struct ccs_domain_info *domain; |
1768 |
domain = list_entry(pos, struct ccs_domain_info, list); |
domain = list_entry(pos, struct ccs_domain_info, list); |
1770 |
continue; |
continue; |
1771 |
if (!ccs_io_printf(head, "%u %s\n", domain->profile, |
if (!ccs_io_printf(head, "%u %s\n", domain->profile, |
1772 |
domain->domainname->name)) |
domain->domainname->name)) |
1773 |
return 0; |
return; |
1774 |
} |
} |
1775 |
head->read_eof = true; |
head->read_eof = true; |
|
return 0; |
|
1776 |
} |
} |
1777 |
|
|
1778 |
/** |
/** |
1799 |
* |
* |
1800 |
* Caller holds ccs_read_lock(). |
* Caller holds ccs_read_lock(). |
1801 |
*/ |
*/ |
1802 |
static int ccs_read_pid(struct ccs_io_buffer *head) |
static void ccs_read_pid(struct ccs_io_buffer *head) |
1803 |
{ |
{ |
1804 |
char *buf = head->write_buf; |
char *buf = head->write_buf; |
1805 |
bool task_info = false; |
bool task_info = false; |
1806 |
|
bool global_pid = false; |
1807 |
unsigned int pid; |
unsigned int pid; |
1808 |
struct task_struct *p; |
struct task_struct *p; |
1809 |
struct ccs_domain_info *domain = NULL; |
struct ccs_domain_info *domain = NULL; |
1810 |
u32 ccs_flags = 0; |
u32 ccs_flags = 0; |
|
ccs_assert_read_lock(); |
|
1811 |
/* Accessing write_buf is safe because head->io_sem is held. */ |
/* Accessing write_buf is safe because head->io_sem is held. */ |
1812 |
if (!buf) |
if (!buf) { |
1813 |
goto done; /* Do nothing if open(O_RDONLY). */ |
head->read_eof = true; |
1814 |
|
return; /* Do nothing if open(O_RDONLY). */ |
1815 |
|
} |
1816 |
if (head->read_avail || head->read_eof) |
if (head->read_avail || head->read_eof) |
1817 |
goto done; |
return; |
1818 |
head->read_eof = true; |
head->read_eof = true; |
1819 |
if (ccs_str_starts(&buf, "info ")) |
if (ccs_str_starts(&buf, "info ")) |
1820 |
task_info = true; |
task_info = true; |
1821 |
|
if (ccs_str_starts(&buf, "global-pid ")) |
1822 |
|
global_pid = true; |
1823 |
pid = (unsigned int) simple_strtoul(buf, NULL, 10); |
pid = (unsigned int) simple_strtoul(buf, NULL, 10); |
1824 |
read_lock(&tasklist_lock); |
ccs_tasklist_lock(); |
1825 |
|
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24) |
1826 |
|
if (global_pid) |
1827 |
|
p = ccsecurity_exports.find_task_by_pid_ns(pid, &init_pid_ns); |
1828 |
|
else |
1829 |
|
p = ccsecurity_exports.find_task_by_vpid(pid); |
1830 |
|
#else |
1831 |
p = find_task_by_pid(pid); |
p = find_task_by_pid(pid); |
1832 |
|
#endif |
1833 |
if (p) { |
if (p) { |
1834 |
domain = ccs_task_domain(p); |
domain = ccs_task_domain(p); |
1835 |
ccs_flags = p->ccs_flags; |
ccs_flags = p->ccs_flags; |
1836 |
} |
} |
1837 |
read_unlock(&tasklist_lock); |
ccs_tasklist_unlock(); |
1838 |
if (!domain) |
if (!domain) |
1839 |
goto done; |
return; |
1840 |
if (!task_info) |
if (!task_info) |
1841 |
ccs_io_printf(head, "%u %u %s", pid, domain->profile, |
ccs_io_printf(head, "%u %u %s", pid, domain->profile, |
1842 |
domain->domainname->name); |
domain->domainname->name); |
1843 |
else |
else |
1844 |
ccs_io_printf(head, "%u manager=%s execute_handler=%s " |
ccs_io_printf(head, "%u manager=%s execute_handler=%s " |
1845 |
"state[0]=%u state[1]=%u state[2]=%u", pid, |
"state[0]=%u state[1]=%u state[2]=%u", pid, |
1846 |
ccs_flags & CCS_TASK_IS_POLICY_MANAGER ? |
ccs_yesno(ccs_flags & |
1847 |
"yes" : "no", |
CCS_TASK_IS_POLICY_MANAGER), |
1848 |
ccs_flags & CCS_TASK_IS_EXECUTE_HANDLER ? |
ccs_yesno(ccs_flags & |
1849 |
"yes" : "no", |
CCS_TASK_IS_EXECUTE_HANDLER), |
1850 |
(u8) (ccs_flags >> 24), |
(u8) (ccs_flags >> 24), |
1851 |
(u8) (ccs_flags >> 16), |
(u8) (ccs_flags >> 16), |
1852 |
(u8) (ccs_flags >> 8)); |
(u8) (ccs_flags >> 8)); |
|
done: |
|
|
return 0; |
|
1853 |
} |
} |
1854 |
|
|
1855 |
/** |
/** |
1899 |
* |
* |
1900 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1901 |
* |
* |
|
* Returns 0 on success, -EINVAL otherwise. |
|
|
* |
|
1902 |
* Caller holds ccs_read_lock(). |
* Caller holds ccs_read_lock(). |
1903 |
*/ |
*/ |
1904 |
static int ccs_read_exception_policy(struct ccs_io_buffer *head) |
static void ccs_read_exception_policy(struct ccs_io_buffer *head) |
1905 |
{ |
{ |
1906 |
ccs_assert_read_lock(); |
if (head->read_eof) |
1907 |
if (!head->read_eof) { |
return; |
1908 |
switch (head->read_step) { |
switch (head->read_step) { |
1909 |
case 0: |
case 0: |
1910 |
head->read_var2 = NULL; |
head->read_var2 = NULL; |
1911 |
head->read_step = 1; |
head->read_step = 1; |
1912 |
case 1: |
case 1: |
1913 |
if (!ccs_read_domain_keeper_policy(head)) |
if (!ccs_read_domain_keeper_policy(head)) |
|
break; |
|
|
head->read_var2 = NULL; |
|
|
head->read_step = 2; |
|
|
case 2: |
|
|
if (!ccs_read_globally_readable_policy(head)) |
|
|
break; |
|
|
head->read_var2 = NULL; |
|
|
head->read_step = 3; |
|
|
case 3: |
|
|
if (!ccs_read_globally_usable_env_policy(head)) |
|
|
break; |
|
|
head->read_var2 = NULL; |
|
|
head->read_step = 4; |
|
|
case 4: |
|
|
if (!ccs_read_domain_initializer_policy(head)) |
|
|
break; |
|
|
head->read_var2 = NULL; |
|
|
head->read_step = 6; |
|
|
case 6: |
|
|
if (!ccs_read_aggregator_policy(head)) |
|
|
break; |
|
|
head->read_var2 = NULL; |
|
|
head->read_step = 7; |
|
|
case 7: |
|
|
if (!ccs_read_file_pattern(head)) |
|
|
break; |
|
|
head->read_var2 = NULL; |
|
|
head->read_step = 8; |
|
|
case 8: |
|
|
if (!ccs_read_no_rewrite_policy(head)) |
|
|
break; |
|
|
head->read_var2 = NULL; |
|
|
head->read_step = 9; |
|
|
case 9: |
|
|
if (!ccs_read_path_group_policy(head)) |
|
|
break; |
|
|
head->read_var1 = NULL; |
|
|
head->read_var2 = NULL; |
|
|
head->read_step = 10; |
|
|
case 10: |
|
|
if (!ccs_read_number_group_policy(head)) |
|
|
break; |
|
|
head->read_var1 = NULL; |
|
|
head->read_var2 = NULL; |
|
|
head->read_step = 11; |
|
|
case 11: |
|
|
if (!ccs_read_address_group_policy(head)) |
|
|
break; |
|
|
head->read_var2 = NULL; |
|
|
head->read_step = 12; |
|
|
case 12: |
|
|
if (!ccs_read_reserved_port_policy(head)) |
|
|
break; |
|
|
head->read_eof = true; |
|
1914 |
break; |
break; |
1915 |
default: |
head->read_var2 = NULL; |
1916 |
return -EINVAL; |
head->read_step = 2; |
1917 |
} |
case 2: |
1918 |
|
if (!ccs_read_globally_readable_policy(head)) |
1919 |
|
break; |
1920 |
|
head->read_var2 = NULL; |
1921 |
|
head->read_step = 3; |
1922 |
|
case 3: |
1923 |
|
if (!ccs_read_globally_usable_env_policy(head)) |
1924 |
|
break; |
1925 |
|
head->read_var2 = NULL; |
1926 |
|
head->read_step = 4; |
1927 |
|
case 4: |
1928 |
|
if (!ccs_read_domain_initializer_policy(head)) |
1929 |
|
break; |
1930 |
|
head->read_var2 = NULL; |
1931 |
|
head->read_step = 6; |
1932 |
|
case 6: |
1933 |
|
if (!ccs_read_aggregator_policy(head)) |
1934 |
|
break; |
1935 |
|
head->read_var2 = NULL; |
1936 |
|
head->read_step = 7; |
1937 |
|
case 7: |
1938 |
|
if (!ccs_read_file_pattern(head)) |
1939 |
|
break; |
1940 |
|
head->read_var2 = NULL; |
1941 |
|
head->read_step = 8; |
1942 |
|
case 8: |
1943 |
|
if (!ccs_read_no_rewrite_policy(head)) |
1944 |
|
break; |
1945 |
|
head->read_var2 = NULL; |
1946 |
|
head->read_step = 9; |
1947 |
|
case 9: |
1948 |
|
if (!ccs_read_path_group_policy(head)) |
1949 |
|
break; |
1950 |
|
head->read_var1 = NULL; |
1951 |
|
head->read_var2 = NULL; |
1952 |
|
head->read_step = 10; |
1953 |
|
case 10: |
1954 |
|
if (!ccs_read_number_group_policy(head)) |
1955 |
|
break; |
1956 |
|
head->read_var1 = NULL; |
1957 |
|
head->read_var2 = NULL; |
1958 |
|
head->read_step = 11; |
1959 |
|
case 11: |
1960 |
|
if (!ccs_read_address_group_policy(head)) |
1961 |
|
break; |
1962 |
|
head->read_var2 = NULL; |
1963 |
|
head->read_step = 12; |
1964 |
|
case 12: |
1965 |
|
if (!ccs_read_reserved_port_policy(head)) |
1966 |
|
break; |
1967 |
|
head->read_eof = true; |
1968 |
} |
} |
|
return 0; |
|
1969 |
} |
} |
1970 |
|
|
1971 |
/** |
/** |
1993 |
while (offset < PAGE_SIZE) { |
while (offset < PAGE_SIZE) { |
1994 |
const char *kaddr = ee->dump.data; |
const char *kaddr = ee->dump.data; |
1995 |
const unsigned char c = kaddr[offset++]; |
const unsigned char c = kaddr[offset++]; |
1996 |
if (c && arg_len < CCS_MAX_PATHNAME_LEN - 10) { |
if (c && arg_len < CCS_EXEC_TMPSIZE - 10) { |
1997 |
if (c == '\\') { |
if (c == '\\') { |
1998 |
arg_ptr[arg_len++] = '\\'; |
arg_ptr[arg_len++] = '\\'; |
1999 |
arg_ptr[arg_len++] = '\\'; |
arg_ptr[arg_len++] = '\\'; |
|
} else if (c == '/') { |
|
|
arg_len = 0; |
|
2000 |
} else if (c > ' ' && c < 127) { |
} else if (c > ' ' && c < 127) { |
2001 |
arg_ptr[arg_len++] = c; |
arg_ptr[arg_len++] = c; |
2002 |
} else { |
} else { |
2021 |
return false; |
return false; |
2022 |
} |
} |
2023 |
|
|
2024 |
|
/** |
2025 |
|
* ccs_get_execute_condition - Get condition part for execute requests. |
2026 |
|
* |
2027 |
|
* @ee: Pointer to "struct ccs_execve_entry". |
2028 |
|
* |
2029 |
|
* Returns pointer to "struct ccs_condition" on success, NULL otherwise. |
2030 |
|
*/ |
2031 |
static struct ccs_condition *ccs_get_execute_condition(struct ccs_execve_entry |
static struct ccs_condition *ccs_get_execute_condition(struct ccs_execve_entry |
2032 |
*ee) |
*ee) |
2033 |
{ |
{ |
2036 |
int len = 256; |
int len = 256; |
2037 |
char *realpath = NULL; |
char *realpath = NULL; |
2038 |
char *argv0 = NULL; |
char *argv0 = NULL; |
2039 |
if (ccs_flags(NULL, CCS_AUTOLEARN_EXEC_REALPATH)) { |
const struct ccs_profile *profile = ccs_profile(ee->r.domain->profile); |
2040 |
|
if (profile->learning->learning_exec_realpath) { |
2041 |
struct file *file = ee->bprm->file; |
struct file *file = ee->bprm->file; |
2042 |
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 20) |
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 20) |
2043 |
struct path path = { file->f_vfsmnt, file->f_dentry }; |
struct path path = { file->f_vfsmnt, file->f_dentry }; |
2048 |
if (realpath) |
if (realpath) |
2049 |
len += strlen(realpath) + 17; |
len += strlen(realpath) + 17; |
2050 |
} |
} |
2051 |
if (ccs_flags(NULL, CCS_AUTOLEARN_EXEC_REALPATH)) { |
if (profile->learning->learning_exec_argv0) { |
2052 |
if (ccs_get_argv0(ee)) { |
if (ccs_get_argv0(ee)) { |
2053 |
argv0 = ee->tmp; |
argv0 = ee->tmp; |
2054 |
len += strlen(argv0) + 16; |
len += strlen(argv0) + 16; |
2055 |
} |
} |
2056 |
} |
} |
2057 |
buf = kmalloc(len, GFP_KERNEL); |
buf = kmalloc(len, CCS_GFP_FLAGS); |
2058 |
if (!buf) |
if (!buf) { |
2059 |
|
kfree(realpath); |
2060 |
return NULL; |
return NULL; |
2061 |
|
} |
2062 |
snprintf(buf, len - 1, "if"); |
snprintf(buf, len - 1, "if"); |
2063 |
if (current->ccs_flags & CCS_TASK_IS_EXECUTE_HANDLER) { |
if (current->ccs_flags & CCS_TASK_IS_EXECUTE_HANDLER) { |
2064 |
const int pos = strlen(buf); |
const int pos = strlen(buf); |
2081 |
return cond; |
return cond; |
2082 |
} |
} |
2083 |
|
|
2084 |
|
/** |
2085 |
|
* ccs_get_symlink_condition - Get condition part for symlink requests. |
2086 |
|
* |
2087 |
|
* @r: Pointer to "struct ccs_request_info". |
2088 |
|
* |
2089 |
|
* Returns pointer to "struct ccs_condition" on success, NULL otherwise. |
2090 |
|
*/ |
2091 |
|
static struct ccs_condition *ccs_get_symlink_condition(struct ccs_request_info |
2092 |
|
*r) |
2093 |
|
{ |
2094 |
|
struct ccs_condition *cond; |
2095 |
|
char *buf; |
2096 |
|
int len = 256; |
2097 |
|
const char *symlink = NULL; |
2098 |
|
const struct ccs_profile *profile = ccs_profile(r->profile); |
2099 |
|
if (profile->learning->learning_symlink_target) { |
2100 |
|
symlink = r->obj->symlink_target->name; |
2101 |
|
len += strlen(symlink) + 18; |
2102 |
|
} |
2103 |
|
buf = kmalloc(len, CCS_GFP_FLAGS); |
2104 |
|
if (!buf) |
2105 |
|
return NULL; |
2106 |
|
snprintf(buf, len - 1, "if"); |
2107 |
|
if (current->ccs_flags & CCS_TASK_IS_EXECUTE_HANDLER) { |
2108 |
|
const int pos = strlen(buf); |
2109 |
|
snprintf(buf + pos, len - pos - 1, |
2110 |
|
" task.type=execute_handler"); |
2111 |
|
} |
2112 |
|
if (symlink) { |
2113 |
|
const int pos = strlen(buf); |
2114 |
|
snprintf(buf + pos, len - pos - 1, " symlink.target=\"%s\"", |
2115 |
|
symlink); |
2116 |
|
} |
2117 |
|
cond = ccs_get_condition(buf); |
2118 |
|
kfree(buf); |
2119 |
|
return cond; |
2120 |
|
} |
2121 |
|
|
2122 |
/* Wait queue for ccs_query_list. */ |
/* Wait queue for ccs_query_list. */ |
2123 |
static DECLARE_WAIT_QUEUE_HEAD(ccs_query_wait); |
static DECLARE_WAIT_QUEUE_HEAD(ccs_query_wait); |
2124 |
|
|
2148 |
* @fmt: The printf()'s format string, followed by parameters. |
* @fmt: The printf()'s format string, followed by parameters. |
2149 |
* |
* |
2150 |
* Returns 0 if the supervisor decided to permit the access request which |
* Returns 0 if the supervisor decided to permit the access request which |
2151 |
* violated the policy in enforcing mode, 1 if the supervisor decided to |
* violated the policy in enforcing mode, CCS_RETRY_REQUEST if the supervisor |
2152 |
* retry the access request which violated the policy in enforcing mode, |
* decided to retry the access request which violated the policy in enforcing |
2153 |
* 0 if it is not in enforcing mode, -EPERM otherwise. |
* mode, 0 if it is not in enforcing mode, -EPERM otherwise. |
2154 |
*/ |
*/ |
2155 |
int ccs_supervisor(struct ccs_request_info *r, const char *fmt, ...) |
int ccs_supervisor(struct ccs_request_info *r, const char *fmt, ...) |
2156 |
{ |
{ |
2167 |
switch (r->mode) { |
switch (r->mode) { |
2168 |
char *buffer; |
char *buffer; |
2169 |
struct ccs_condition *cond; |
struct ccs_condition *cond; |
2170 |
case 1: |
case CCS_CONFIG_LEARNING: |
2171 |
if (!ccs_domain_quota_ok(r)) |
if (!ccs_domain_quota_ok(r)) |
2172 |
return 0; |
return 0; |
2173 |
va_start(args, fmt); |
va_start(args, fmt); |
2174 |
len = vsnprintf((char *) &pos, sizeof(pos) - 1, fmt, args) + 4; |
len = vsnprintf((char *) &pos, sizeof(pos) - 1, fmt, args) + 4; |
2175 |
va_end(args); |
va_end(args); |
2176 |
buffer = kmalloc(len, GFP_KERNEL); |
buffer = kmalloc(len, CCS_GFP_FLAGS); |
2177 |
if (!buffer) |
if (!buffer) |
2178 |
return 0; |
return 0; |
2179 |
va_start(args, fmt); |
va_start(args, fmt); |
2182 |
ccs_normalize_line(buffer); |
ccs_normalize_line(buffer); |
2183 |
if (r->ee && !strncmp(buffer, "allow_execute ", 14)) |
if (r->ee && !strncmp(buffer, "allow_execute ", 14)) |
2184 |
cond = ccs_get_execute_condition(r->ee); |
cond = ccs_get_execute_condition(r->ee); |
2185 |
|
else if (r->obj && r->obj->symlink_target) |
2186 |
|
cond = ccs_get_symlink_condition(r); |
2187 |
else if ((current->ccs_flags & CCS_TASK_IS_EXECUTE_HANDLER)) { |
else if ((current->ccs_flags & CCS_TASK_IS_EXECUTE_HANDLER)) { |
2188 |
char str[] = "if task.type=execute_handler"; |
char str[] = "if task.type=execute_handler"; |
2189 |
cond = ccs_get_condition(str); |
cond = ccs_get_condition(str); |
2193 |
ccs_put_condition(cond); |
ccs_put_condition(cond); |
2194 |
kfree(buffer); |
kfree(buffer); |
2195 |
/* fall through */ |
/* fall through */ |
2196 |
case 2: |
case CCS_CONFIG_PERMISSIVE: |
2197 |
return 0; |
return 0; |
2198 |
} |
} |
2199 |
if (!atomic_read(&ccs_query_observers)) { |
if (!atomic_read(&ccs_query_observers)) { |
2200 |
int i; |
int i; |
2201 |
if (current->ccs_flags & CCS_DONT_SLEEP_ON_ENFORCE_ERROR) |
if (current->ccs_flags & CCS_DONT_SLEEP_ON_ENFORCE_ERROR) |
2202 |
return -EPERM; |
return -EPERM; |
2203 |
for (i = 0; i < ccs_flags(r->domain, CCS_SLEEP_PERIOD); |
for (i = 0; i < ccs_profile(r->domain->profile)->enforcing-> |
2204 |
i++) { |
enforcing_penalty; i++) { |
2205 |
set_current_state(TASK_INTERRUPTIBLE); |
set_current_state(TASK_INTERRUPTIBLE); |
2206 |
schedule_timeout(HZ / 10); |
schedule_timeout(HZ / 10); |
2207 |
} |
} |
2213 |
header = ccs_init_audit_log(&len, r); |
header = ccs_init_audit_log(&len, r); |
2214 |
if (!header) |
if (!header) |
2215 |
goto out; |
goto out; |
2216 |
ccs_query_entry = kzalloc(sizeof(*ccs_query_entry), GFP_KERNEL); |
ccs_query_entry = kzalloc(sizeof(*ccs_query_entry), CCS_GFP_FLAGS); |
2217 |
if (!ccs_query_entry) |
if (!ccs_query_entry) |
2218 |
goto out; |
goto out; |
2219 |
len = ccs_round2(len); |
len = ccs_round2(len); |
2220 |
ccs_query_entry->query = kzalloc(len, GFP_KERNEL); |
ccs_query_entry->query = kzalloc(len, CCS_GFP_FLAGS); |
2221 |
if (!ccs_query_entry->query) |
if (!ccs_query_entry->query) |
2222 |
goto out; |
goto out; |
2223 |
INIT_LIST_HEAD(&ccs_query_entry->list); |
INIT_LIST_HEAD(&ccs_query_entry->list); |
2259 |
spin_unlock(&ccs_query_list_lock); |
spin_unlock(&ccs_query_list_lock); |
2260 |
switch (ccs_query_entry->answer) { |
switch (ccs_query_entry->answer) { |
2261 |
case 3: /* Asked to retry by administrator. */ |
case 3: /* Asked to retry by administrator. */ |
2262 |
error = 1; |
error = CCS_RETRY_REQUEST; |
2263 |
r->retry++; |
r->retry++; |
2264 |
break; |
break; |
2265 |
case 1: |
case 1: |
2320 |
* ccs_read_query - Read access requests which violated policy in enforcing mode. |
* ccs_read_query - Read access requests which violated policy in enforcing mode. |
2321 |
* |
* |
2322 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
|
* |
|
|
* Returns 0. |
|
2323 |
*/ |
*/ |
2324 |
static int ccs_read_query(struct ccs_io_buffer *head) |
static void ccs_read_query(struct ccs_io_buffer *head) |
2325 |
{ |
{ |
2326 |
struct list_head *tmp; |
struct list_head *tmp; |
2327 |
int pos = 0; |
int pos = 0; |
2328 |
int len = 0; |
int len = 0; |
2329 |
char *buf; |
char *buf; |
2330 |
if (head->read_avail) |
if (head->read_avail) |
2331 |
return 0; |
return; |
2332 |
if (head->read_buf) { |
if (head->read_buf) { |
2333 |
kfree(head->read_buf); |
kfree(head->read_buf); |
2334 |
head->read_buf = NULL; |
head->read_buf = NULL; |
2348 |
spin_unlock(&ccs_query_list_lock); |
spin_unlock(&ccs_query_list_lock); |
2349 |
if (!len) { |
if (!len) { |
2350 |
head->read_step = 0; |
head->read_step = 0; |
2351 |
return 0; |
return; |
2352 |
} |
} |
2353 |
buf = kzalloc(len, GFP_KERNEL); |
buf = kzalloc(len, CCS_GFP_FLAGS); |
2354 |
if (!buf) |
if (!buf) |
2355 |
return 0; |
return; |
2356 |
pos = 0; |
pos = 0; |
2357 |
spin_lock(&ccs_query_list_lock); |
spin_lock(&ccs_query_list_lock); |
2358 |
list_for_each(tmp, &ccs_query_list) { |
list_for_each(tmp, &ccs_query_list) { |
2379 |
} else { |
} else { |
2380 |
kfree(buf); |
kfree(buf); |
2381 |
} |
} |
|
return 0; |
|
2382 |
} |
} |
2383 |
|
|
2384 |
/** |
/** |
2421 |
* ccs_read_version: Get version. |
* ccs_read_version: Get version. |
2422 |
* |
* |
2423 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
|
* |
|
|
* Returns version information. |
|
2424 |
*/ |
*/ |
2425 |
static int ccs_read_version(struct ccs_io_buffer *head) |
static void ccs_read_version(struct ccs_io_buffer *head) |
2426 |
{ |
{ |
2427 |
if (!head->read_eof) { |
if (head->read_eof) |
2428 |
ccs_io_printf(head, "1.7.0-pre"); |
return; |
2429 |
head->read_eof = true; |
ccs_io_printf(head, "1.7.1"); |
2430 |
} |
head->read_eof = true; |
|
return 0; |
|
2431 |
} |
} |
2432 |
|
|
2433 |
/** |
/** |
2434 |
* ccs_read_self_domain - Get the current process's domainname. |
* ccs_read_self_domain - Get the current process's domainname. |
2435 |
* |
* |
2436 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
|
* |
|
|
* Returns the current process's domainname. |
|
2437 |
*/ |
*/ |
2438 |
static int ccs_read_self_domain(struct ccs_io_buffer *head) |
static void ccs_read_self_domain(struct ccs_io_buffer *head) |
2439 |
{ |
{ |
2440 |
if (!head->read_eof) { |
if (head->read_eof) |
2441 |
/* |
return; |
2442 |
* ccs_current_domain()->domainname != NULL |
/* |
2443 |
* because every process belongs to a domain and |
* ccs_current_domain()->domainname != NULL because every process |
2444 |
* the domain's name cannot be NULL. |
* belongs to a domain and the domain's name cannot be NULL. |
2445 |
*/ |
*/ |
2446 |
ccs_io_printf(head, "%s", |
ccs_io_printf(head, "%s", ccs_current_domain()->domainname->name); |
2447 |
ccs_current_domain()->domainname->name); |
head->read_eof = true; |
|
head->read_eof = true; |
|
|
} |
|
|
return 0; |
|
2448 |
} |
} |
2449 |
|
|
2450 |
/** |
/** |
2457 |
*/ |
*/ |
2458 |
int ccs_open_control(const u8 type, struct file *file) |
int ccs_open_control(const u8 type, struct file *file) |
2459 |
{ |
{ |
2460 |
struct ccs_io_buffer *head = kzalloc(sizeof(*head), GFP_KERNEL); |
struct ccs_io_buffer *head = kzalloc(sizeof(*head), CCS_GFP_FLAGS); |
2461 |
if (!head) |
if (!head) |
2462 |
return -ENOMEM; |
return -ENOMEM; |
2463 |
mutex_init(&head->io_sem); |
mutex_init(&head->io_sem); |
2473 |
break; |
break; |
2474 |
#ifdef CONFIG_CCSECURITY_AUDIT |
#ifdef CONFIG_CCSECURITY_AUDIT |
2475 |
case CCS_GRANTLOG: /* /proc/ccs/grant_log */ |
case CCS_GRANTLOG: /* /proc/ccs/grant_log */ |
|
head->poll = ccs_poll_grant_log; |
|
|
head->read = ccs_read_grant_log; |
|
|
break; |
|
2476 |
case CCS_REJECTLOG: /* /proc/ccs/reject_log */ |
case CCS_REJECTLOG: /* /proc/ccs/reject_log */ |
2477 |
head->poll = ccs_poll_reject_log; |
head->poll = ccs_poll_audit_log; |
2478 |
head->read = ccs_read_reject_log; |
head->read = ccs_read_audit_log; |
2479 |
break; |
break; |
2480 |
#endif |
#endif |
2481 |
case CCS_SELFDOMAIN: /* /proc/ccs/self_domain */ |
case CCS_SELFDOMAIN: /* /proc/ccs/self_domain */ |
2530 |
/* Don't allocate read_buf for poll() access. */ |
/* Don't allocate read_buf for poll() access. */ |
2531 |
if (!head->readbuf_size) |
if (!head->readbuf_size) |
2532 |
head->readbuf_size = 4096; |
head->readbuf_size = 4096; |
2533 |
head->read_buf = kzalloc(head->readbuf_size, GFP_KERNEL); |
head->read_buf = kzalloc(head->readbuf_size, CCS_GFP_FLAGS); |
2534 |
if (!head->read_buf) { |
if (!head->read_buf) { |
2535 |
kfree(head); |
kfree(head); |
2536 |
return -ENOMEM; |
return -ENOMEM; |
2544 |
head->write = NULL; |
head->write = NULL; |
2545 |
} else if (head->write) { |
} else if (head->write) { |
2546 |
head->writebuf_size = 4096; |
head->writebuf_size = 4096; |
2547 |
head->write_buf = kzalloc(head->writebuf_size, GFP_KERNEL); |
head->write_buf = kzalloc(head->writebuf_size, CCS_GFP_FLAGS); |
2548 |
if (!head->write_buf) { |
if (!head->write_buf) { |
2549 |
kfree(head->read_buf); |
kfree(head->read_buf); |
2550 |
kfree(head); |
kfree(head); |
2552 |
} |
} |
2553 |
} |
} |
2554 |
if (type != CCS_QUERY && |
if (type != CCS_QUERY && |
2555 |
type != CCS_GRANTLOG && type != CCS_REJECTLOG) |
type != CCS_GRANTLOG && type != CCS_REJECTLOG) { |
2556 |
head->reader_idx = ccs_read_lock(); |
spin_lock(&ccs_io_buffer_list_lock); |
2557 |
|
list_add(&head->list, &ccs_io_buffer_list); |
2558 |
|
spin_unlock(&ccs_io_buffer_list_lock); |
2559 |
|
} |
2560 |
file->private_data = head; |
file->private_data = head; |
2561 |
/* |
/* |
2562 |
* Call the handler now if the file is /proc/ccs/self_domain |
* Call the handler now if the file is /proc/ccs/self_domain |
2582 |
* @wait: Pointer to "poll_table". |
* @wait: Pointer to "poll_table". |
2583 |
* |
* |
2584 |
* Waits for read readiness. |
* Waits for read readiness. |
2585 |
* /proc/ccs/query is handled by /usr/lib/ccs/ccs-queryd and |
* /proc/ccs/query is handled by /usr/sbin/ccs-queryd and |
2586 |
* /proc/ccs/grant_log and /proc/ccs/reject_log are handled by |
* /proc/ccs/grant_log and /proc/ccs/reject_log are handled by |
2587 |
* /usr/lib/ccs/ccs-auditd. |
* /usr/sbin/ccs-auditd . |
2588 |
*/ |
*/ |
2589 |
int ccs_poll_control(struct file *file, poll_table *wait) |
int ccs_poll_control(struct file *file, poll_table *wait) |
2590 |
{ |
{ |
2609 |
int len = 0; |
int len = 0; |
2610 |
struct ccs_io_buffer *head = file->private_data; |
struct ccs_io_buffer *head = file->private_data; |
2611 |
char *cp; |
char *cp; |
2612 |
|
int idx; |
2613 |
if (!head->read) |
if (!head->read) |
2614 |
return -ENOSYS; |
return -ENOSYS; |
2615 |
if (!access_ok(VERIFY_WRITE, buffer, buffer_len)) |
if (!access_ok(VERIFY_WRITE, buffer, buffer_len)) |
2616 |
return -EFAULT; |
return -EFAULT; |
2617 |
if (mutex_lock_interruptible(&head->io_sem)) |
if (mutex_lock_interruptible(&head->io_sem)) |
2618 |
return -EINTR; |
return -EINTR; |
2619 |
retry: |
idx = ccs_read_lock(); |
2620 |
/* Call the policy handler. */ |
while (1) { |
2621 |
len = head->read(head); |
/* Call the policy handler. */ |
2622 |
if (len < 0) |
head->read(head); |
2623 |
goto out; |
/* Write to buffer. */ |
2624 |
/* Write to buffer. */ |
len = head->read_avail; |
2625 |
len = head->read_avail; |
if (len || head->poll || head->read_eof) |
2626 |
if (!len && !head->poll && !head->read_eof) { |
break; |
2627 |
const int len = head->readbuf_size * 2; |
len = head->readbuf_size * 2; |
2628 |
cp = kzalloc(len, GFP_KERNEL); |
cp = kzalloc(len, CCS_GFP_FLAGS); |
2629 |
if (cp) { |
if (!cp) { |
2630 |
kfree(head->read_buf); |
len = -ENOMEM; |
2631 |
head->read_buf = cp; |
goto out; |
|
head->readbuf_size = len; |
|
|
goto retry; |
|
2632 |
} |
} |
2633 |
|
kfree(head->read_buf); |
2634 |
|
head->read_buf = cp; |
2635 |
|
head->readbuf_size = len; |
2636 |
} |
} |
2637 |
if (len > buffer_len) |
if (len > buffer_len) |
2638 |
len = buffer_len; |
len = buffer_len; |
2647 |
head->read_avail -= len; |
head->read_avail -= len; |
2648 |
memmove(cp, cp + len, head->read_avail); |
memmove(cp, cp + len, head->read_avail); |
2649 |
out: |
out: |
2650 |
|
ccs_read_unlock(idx); |
2651 |
mutex_unlock(&head->io_sem); |
mutex_unlock(&head->io_sem); |
2652 |
return len; |
return len; |
2653 |
} |
} |
2668 |
int error = buffer_len; |
int error = buffer_len; |
2669 |
int avail_len = buffer_len; |
int avail_len = buffer_len; |
2670 |
char *cp0 = head->write_buf; |
char *cp0 = head->write_buf; |
2671 |
|
int idx; |
2672 |
if (!head->write) |
if (!head->write) |
2673 |
return -ENOSYS; |
return -ENOSYS; |
2674 |
if (!access_ok(VERIFY_READ, buffer, buffer_len)) |
if (!access_ok(VERIFY_READ, buffer, buffer_len)) |
2680 |
return -EPERM; |
return -EPERM; |
2681 |
if (mutex_lock_interruptible(&head->io_sem)) |
if (mutex_lock_interruptible(&head->io_sem)) |
2682 |
return -EINTR; |
return -EINTR; |
2683 |
|
idx = ccs_read_lock(); |
2684 |
/* Read a line and dispatch it to the policy handler. */ |
/* Read a line and dispatch it to the policy handler. */ |
2685 |
while (avail_len > 0) { |
while (avail_len > 0) { |
2686 |
char c; |
char c; |
2687 |
if (head->write_avail >= head->writebuf_size - 1) { |
if (head->write_avail >= head->writebuf_size - 1) { |
2688 |
const int len = head->writebuf_size * 2; |
const int len = head->writebuf_size * 2; |
2689 |
char *cp = kzalloc(len, GFP_KERNEL); |
char *cp = kzalloc(len, CCS_GFP_FLAGS); |
2690 |
if (!cp) { |
if (!cp) { |
2691 |
error = -ENOMEM; |
error = -ENOMEM; |
2692 |
break; |
break; |
2711 |
ccs_normalize_line(cp0); |
ccs_normalize_line(cp0); |
2712 |
head->write(head); |
head->write(head); |
2713 |
} |
} |
2714 |
|
ccs_read_unlock(idx); |
2715 |
mutex_unlock(&head->io_sem); |
mutex_unlock(&head->io_sem); |
2716 |
return error; |
return error; |
2717 |
} |
} |
2734 |
if (type == CCS_QUERY) |
if (type == CCS_QUERY) |
2735 |
atomic_dec(&ccs_query_observers); |
atomic_dec(&ccs_query_observers); |
2736 |
if (type != CCS_QUERY && |
if (type != CCS_QUERY && |
2737 |
type != CCS_GRANTLOG && type != CCS_REJECTLOG) |
type != CCS_GRANTLOG && type != CCS_REJECTLOG) { |
2738 |
ccs_read_unlock(head->reader_idx); |
spin_lock(&ccs_io_buffer_list_lock); |
2739 |
|
list_del(&head->list); |
2740 |
|
spin_unlock(&ccs_io_buffer_list_lock); |
2741 |
|
} |
2742 |
/* Release memory used for policy I/O. */ |
/* Release memory used for policy I/O. */ |
2743 |
kfree(head->read_buf); |
kfree(head->read_buf); |
2744 |
head->read_buf = NULL; |
head->read_buf = NULL; |
2747 |
kfree(head); |
kfree(head); |
2748 |
head = NULL; |
head = NULL; |
2749 |
file->private_data = NULL; |
file->private_data = NULL; |
2750 |
if (is_write) |
if (is_write) { |
2751 |
ccs_run_gc(); |
ccs_need_gc = 1; |
2752 |
|
wake_up(&ccs_gc_queue); |
2753 |
|
} |
2754 |
return 0; |
return 0; |
2755 |
} |
} |
2756 |
|
|
2757 |
|
void __init ccs_policy_io_init(void) |
2758 |
|
{ |
2759 |
|
ccsecurity_ops.check_profile = ccs_check_profile; |
2760 |
|
} |