3 |
* |
* |
4 |
* Copyright (C) 2005-2009 NTT DATA CORPORATION |
* Copyright (C) 2005-2009 NTT DATA CORPORATION |
5 |
* |
* |
6 |
* Version: 1.7.0-pre 2009/08/08 |
* Version: 1.7.1-pre 2009/10/16 |
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 |
|
.enforcing = &ccs_default_profile.preference, |
19 |
|
.audit = &ccs_default_profile.preference, |
20 |
|
#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 table. Memory is allocated as needed. */ |
37 |
|
static struct ccs_profile *ccs_profile_ptr[CCS_MAX_PROFILES]; |
38 |
|
|
39 |
static bool ccs_profile_entry_used[CCS_MAX_CONTROL_INDEX + |
/* Lock for protecting "struct ccs_profile"->comment */ |
40 |
CCS_MAX_CAPABILITY_INDEX + 1]; |
static DEFINE_SPINLOCK(ccs_profile_comment_lock); |
41 |
|
|
42 |
/* String table for functionality that takes 4 modes. */ |
/* 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 |
}; |
}; |
|
/* String table for functionality that takes 2 modes. */ |
|
|
static const char *ccs_mode_2[4] = { |
|
|
"disabled", "enabled", "enabled", "enabled" |
|
|
}; |
|
46 |
|
|
47 |
/* Table for profile. */ |
/* String table for /proc/ccs/profile */ |
48 |
static struct { |
static const char *ccs_mac_keywords[CCS_MAX_MAC_INDEX + |
49 |
const char *keyword; |
CCS_MAX_CAPABILITY_INDEX + |
50 |
unsigned int current_value; |
CCS_MAX_MAC_CATEGORY_INDEX] = { |
51 |
const unsigned int max_value; |
[CCS_MAC_FILE_EXECUTE] |
52 |
} ccs_control_array[CCS_MAX_CONTROL_INDEX] = { |
= "file::execute", |
53 |
[CCS_MAC_FOR_FILE] = { "MAC_FOR_FILE", 0, 3 }, |
[CCS_MAC_FILE_OPEN] |
54 |
[CCS_AUTOLEARN_EXEC_REALPATH] = { "AUTOLEARN_EXEC_REALPATH", 0, 1 }, |
= "file::open", |
55 |
[CCS_AUTOLEARN_EXEC_ARGV0] = { "AUTOLEARN_EXEC_ARGV0", 0, 1 }, |
[CCS_MAC_FILE_CREATE] |
56 |
[CCS_MAC_FOR_IOCTL] = { "MAC_FOR_IOCTL", 0, 3 }, |
= "file::create", |
57 |
[CCS_MAC_FOR_FILEATTR] = { "MAC_FOR_FILEATTR", 0, 3 }, |
[CCS_MAC_FILE_UNLINK] |
58 |
[CCS_MAC_FOR_ENV] = { "MAC_FOR_ENV", 0, 3 }, |
= "file::unlink", |
59 |
[CCS_MAC_FOR_NETWORK] = { "MAC_FOR_NETWORK", 0, 3 }, |
[CCS_MAC_FILE_MKDIR] |
60 |
[CCS_MAC_FOR_SIGNAL] = { "MAC_FOR_SIGNAL", 0, 3 }, |
= "file::mkdir", |
61 |
[CCS_MAC_FOR_NAMESPACE] = { "MAC_FOR_NAMESPACE", 0, 3 }, |
[CCS_MAC_FILE_RMDIR] |
62 |
[CCS_RESTRICT_AUTOBIND] = { "RESTRICT_AUTOBIND", 0, 1 }, |
= "file::rmdir", |
63 |
[CCS_MAX_ACCEPT_ENTRY] |
[CCS_MAC_FILE_MKFIFO] |
64 |
= { "MAX_ACCEPT_ENTRY", CONFIG_CCSECURITY_MAX_ACCEPT_ENTRY, INT_MAX }, |
= "file::mkfifo", |
65 |
#ifdef CONFIG_CCSECURITY_AUDIT |
[CCS_MAC_FILE_MKSOCK] |
66 |
[CCS_MAX_GRANT_LOG] |
= "file::mksock", |
67 |
= { "MAX_GRANT_LOG", CONFIG_CCSECURITY_MAX_GRANT_LOG, INT_MAX }, |
[CCS_MAC_FILE_TRUNCATE] |
68 |
[CCS_MAX_REJECT_LOG] |
= "file::truncate", |
69 |
= { "MAX_REJECT_LOG", CONFIG_CCSECURITY_MAX_REJECT_LOG, INT_MAX }, |
[CCS_MAC_FILE_SYMLINK] |
70 |
#endif |
= "file::symlink", |
71 |
[CCS_VERBOSE] = { "TOMOYO_VERBOSE", 1, 1 }, |
[CCS_MAC_FILE_REWRITE] |
72 |
[CCS_SLEEP_PERIOD] |
= "file::rewrite", |
73 |
= { "SLEEP_PERIOD", 0, 3000 }, /* in 0.1 second */ |
[CCS_MAC_FILE_MKBLOCK] |
74 |
|
= "file::mkblock", |
75 |
|
[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_ENVIRON] |
98 |
|
= "misc::env", |
99 |
|
[CCS_MAC_NETWORK_UDP_BIND] |
100 |
|
= "network::inet_udp_bind", |
101 |
|
[CCS_MAC_NETWORK_UDP_CONNECT] |
102 |
|
= "network::inet_udp_connect", |
103 |
|
[CCS_MAC_NETWORK_TCP_BIND] |
104 |
|
= "network::inet_tcp_bind", |
105 |
|
[CCS_MAC_NETWORK_TCP_LISTEN] |
106 |
|
= "network::inet_tcp_listen", |
107 |
|
[CCS_MAC_NETWORK_TCP_CONNECT] |
108 |
|
= "network::inet_tcp_connect", |
109 |
|
[CCS_MAC_NETWORK_TCP_ACCEPT] |
110 |
|
= "network::inet_tcp_accept", |
111 |
|
[CCS_MAC_NETWORK_RAW_BIND] |
112 |
|
= "network::inet_raw_bind", |
113 |
|
[CCS_MAC_NETWORK_RAW_CONNECT] |
114 |
|
= "network::inet_raw_connect", |
115 |
|
[CCS_MAC_SIGNAL] |
116 |
|
= "ipc::signal", |
117 |
|
[CCS_MAX_MAC_INDEX + CCS_INET_STREAM_SOCKET_CREATE] |
118 |
|
= "capability::inet_tcp_create", |
119 |
|
[CCS_MAX_MAC_INDEX + CCS_INET_STREAM_SOCKET_LISTEN] |
120 |
|
= "capability::inet_tcp_listen", |
121 |
|
[CCS_MAX_MAC_INDEX + CCS_INET_STREAM_SOCKET_CONNECT] |
122 |
|
= "capability::inet_tcp_connect", |
123 |
|
[CCS_MAX_MAC_INDEX + CCS_USE_INET_DGRAM_SOCKET] |
124 |
|
= "capability::use_inet_udp", |
125 |
|
[CCS_MAX_MAC_INDEX + CCS_USE_INET_RAW_SOCKET] |
126 |
|
= "capability::use_inet_ip", |
127 |
|
[CCS_MAX_MAC_INDEX + CCS_USE_ROUTE_SOCKET] |
128 |
|
= "capability::use_route", |
129 |
|
[CCS_MAX_MAC_INDEX + CCS_USE_PACKET_SOCKET] |
130 |
|
= "capability::use_packet", |
131 |
|
[CCS_MAX_MAC_INDEX + CCS_SYS_MOUNT] |
132 |
|
= "capability::SYS_MOUNT", |
133 |
|
[CCS_MAX_MAC_INDEX + CCS_SYS_UMOUNT] |
134 |
|
= "capability::SYS_UMOUNT", |
135 |
|
[CCS_MAX_MAC_INDEX + CCS_SYS_REBOOT] |
136 |
|
= "capability::SYS_REBOOT", |
137 |
|
[CCS_MAX_MAC_INDEX + CCS_SYS_CHROOT] |
138 |
|
= "capability::SYS_CHROOT", |
139 |
|
[CCS_MAX_MAC_INDEX + CCS_SYS_KILL] |
140 |
|
= "capability::SYS_KILL", |
141 |
|
[CCS_MAX_MAC_INDEX + CCS_SYS_VHANGUP] |
142 |
|
= "capability::SYS_VHANGUP", |
143 |
|
[CCS_MAX_MAC_INDEX + CCS_SYS_SETTIME] |
144 |
|
= "capability::SYS_TIME", |
145 |
|
[CCS_MAX_MAC_INDEX + CCS_SYS_NICE] |
146 |
|
= "capability::SYS_NICE", |
147 |
|
[CCS_MAX_MAC_INDEX + CCS_SYS_SETHOSTNAME] |
148 |
|
= "capability::SYS_SETHOSTNAME", |
149 |
|
[CCS_MAX_MAC_INDEX + CCS_USE_KERNEL_MODULE] |
150 |
|
= "capability::use_kernel_module", |
151 |
|
[CCS_MAX_MAC_INDEX + CCS_CREATE_FIFO] |
152 |
|
= "capability::create_fifo", |
153 |
|
[CCS_MAX_MAC_INDEX + CCS_CREATE_BLOCK_DEV] |
154 |
|
= "capability::create_block_dev", |
155 |
|
[CCS_MAX_MAC_INDEX + CCS_CREATE_CHAR_DEV] |
156 |
|
= "capability::create_char_dev", |
157 |
|
[CCS_MAX_MAC_INDEX + CCS_CREATE_UNIX_SOCKET] |
158 |
|
= "capability::create_unix_socket", |
159 |
|
[CCS_MAX_MAC_INDEX + CCS_SYS_LINK] |
160 |
|
= "capability::SYS_LINK", |
161 |
|
[CCS_MAX_MAC_INDEX + CCS_SYS_SYMLINK] |
162 |
|
= "capability::SYS_SYMLINK", |
163 |
|
[CCS_MAX_MAC_INDEX + CCS_SYS_RENAME] |
164 |
|
= "capability::SYS_RENAME", |
165 |
|
[CCS_MAX_MAC_INDEX + CCS_SYS_UNLINK] |
166 |
|
= "capability::SYS_UNLINK", |
167 |
|
[CCS_MAX_MAC_INDEX + CCS_SYS_CHMOD] |
168 |
|
= "capability::SYS_CHMOD", |
169 |
|
[CCS_MAX_MAC_INDEX + CCS_SYS_CHOWN] |
170 |
|
= "capability::SYS_CHOWN", |
171 |
|
[CCS_MAX_MAC_INDEX + CCS_SYS_IOCTL] |
172 |
|
= "capability::SYS_IOCTL", |
173 |
|
[CCS_MAX_MAC_INDEX + CCS_SYS_KEXEC_LOAD] |
174 |
|
= "capability::SYS_KEXEC_LOAD", |
175 |
|
[CCS_MAX_MAC_INDEX + CCS_SYS_PIVOT_ROOT] |
176 |
|
= "capability::SYS_PIVOT_ROOT", |
177 |
|
[CCS_MAX_MAC_INDEX + CCS_SYS_PTRACE] |
178 |
|
= "capability::SYS_PTRACE", |
179 |
|
[CCS_MAX_MAC_INDEX + CCS_CONCEAL_MOUNT] |
180 |
|
= "capability::conceal_mount", |
181 |
|
[CCS_MAX_MAC_INDEX + CCS_MAX_CAPABILITY_INDEX |
182 |
|
+ CCS_MAC_CATEGORY_FILE] = "file", |
183 |
|
[CCS_MAX_MAC_INDEX + CCS_MAX_CAPABILITY_INDEX |
184 |
|
+ CCS_MAC_CATEGORY_NETWORK] = "network", |
185 |
|
[CCS_MAX_MAC_INDEX + CCS_MAX_CAPABILITY_INDEX |
186 |
|
+ CCS_MAC_CATEGORY_MISC] = "misc", |
187 |
|
[CCS_MAX_MAC_INDEX + CCS_MAX_CAPABILITY_INDEX |
188 |
|
+ CCS_MAC_CATEGORY_IPC] = "ipc", |
189 |
|
[CCS_MAX_MAC_INDEX + CCS_MAX_CAPABILITY_INDEX |
190 |
|
+ CCS_MAC_CATEGORY_CAPABILITY] = "capability", |
191 |
}; |
}; |
192 |
|
|
193 |
/* Permit policy management by non-root user? */ |
/* Permit policy management by non-root user? */ |
194 |
static bool ccs_manage_by_non_root; |
static bool ccs_manage_by_non_root; |
195 |
|
|
196 |
/** |
/** |
197 |
* ccs_quiet_setup - Set CCS_VERBOSE=0 by default. |
* ccs_cap2keyword - Convert capability operation to capability name. |
198 |
* |
* |
199 |
* @str: Unused. |
* @operation: The capability index. |
200 |
* |
* |
201 |
* Returns 0. |
* Returns the name of the specified capability's name. |
202 |
*/ |
*/ |
203 |
static int __init ccs_quiet_setup(char *str) |
const char *ccs_cap2keyword(const u8 operation) |
204 |
{ |
{ |
205 |
ccs_control_array[CCS_VERBOSE].current_value = 0; |
return operation < CCS_MAX_CAPABILITY_INDEX |
206 |
return 0; |
? ccs_mac_keywords[CCS_MAX_MAC_INDEX + operation] + 12 : NULL; |
207 |
} |
} |
208 |
|
|
209 |
__setup("CCS_QUIET", ccs_quiet_setup); |
/** |
210 |
|
* ccs_yesno - Return "yes" or "no". |
211 |
|
* |
212 |
|
* @value: Bool value. |
213 |
|
*/ |
214 |
|
static const char *ccs_yesno(const unsigned int value) |
215 |
|
{ |
216 |
|
return value ? "yes" : "no"; |
217 |
|
} |
218 |
|
|
219 |
/** |
/** |
220 |
* ccs_io_printf - Transactional printf() to "struct ccs_io_buffer" structure. |
* ccs_io_printf - Transactional printf() to "struct ccs_io_buffer" structure. |
255 |
{ |
{ |
256 |
struct ccs_profile *ptr; |
struct ccs_profile *ptr; |
257 |
struct ccs_profile *entry; |
struct ccs_profile *entry; |
|
int i; |
|
258 |
if (profile >= CCS_MAX_PROFILES) |
if (profile >= CCS_MAX_PROFILES) |
259 |
return NULL; |
return NULL; |
260 |
ptr = ccs_profile_ptr[profile]; |
ptr = ccs_profile_ptr[profile]; |
265 |
ptr = ccs_profile_ptr[profile]; |
ptr = ccs_profile_ptr[profile]; |
266 |
if (!ptr && ccs_memory_ok(entry, sizeof(*entry))) { |
if (!ptr && ccs_memory_ok(entry, sizeof(*entry))) { |
267 |
ptr = entry; |
ptr = entry; |
268 |
for (i = 0; i < CCS_MAX_CONTROL_INDEX; i++) |
ptr->audit = &ccs_default_profile.preference; |
269 |
ptr->value[i] = ccs_control_array[i].current_value; |
ptr->learning = &ccs_default_profile.preference; |
270 |
/* |
ptr->permissive = &ccs_default_profile.preference; |
271 |
* Needn't to initialize "ptr->capability_value" |
ptr->enforcing = &ccs_default_profile.preference; |
272 |
* because they are always 0. |
ptr->default_config = CCS_CONFIG_DISABLED | |
273 |
*/ |
CCS_CONFIG_WANT_GRANT_LOG | CCS_CONFIG_WANT_REJECT_LOG; |
274 |
|
memset(ptr->config, CCS_CONFIG_USE_DEFAULT, |
275 |
|
sizeof(ptr->config)); |
276 |
mb(); /* Avoid out-of-order execution. */ |
mb(); /* Avoid out-of-order execution. */ |
277 |
ccs_profile_ptr[profile] = ptr; |
ccs_profile_ptr[profile] = ptr; |
278 |
entry = NULL; |
entry = NULL; |
283 |
} |
} |
284 |
|
|
285 |
/** |
/** |
286 |
|
* ccs_check_profile - Check all profiles currently assigned to domains are defined. |
287 |
|
*/ |
288 |
|
void ccs_check_profile(void) |
289 |
|
{ |
290 |
|
struct ccs_domain_info *domain; |
291 |
|
ccs_policy_loaded = true; |
292 |
|
list_for_each_entry_rcu(domain, &ccs_domain_list, list) { |
293 |
|
const u8 profile = domain->profile; |
294 |
|
if (ccs_profile_ptr[profile]) |
295 |
|
continue; |
296 |
|
panic("Profile %u (used by '%s') not defined.\n", |
297 |
|
profile, domain->domainname->name); |
298 |
|
} |
299 |
|
} |
300 |
|
|
301 |
|
/** |
302 |
|
* ccs_profile - Find a profile. |
303 |
|
* |
304 |
|
* @profile: Profile number to find. |
305 |
|
* |
306 |
|
* Returns pointer to "struct ccs_profile". |
307 |
|
*/ |
308 |
|
struct ccs_profile *ccs_profile(const u8 profile) |
309 |
|
{ |
310 |
|
struct ccs_profile *ptr = ccs_profile_ptr[profile]; |
311 |
|
if (!ccs_policy_loaded) |
312 |
|
return &ccs_default_profile; |
313 |
|
BUG_ON(!ptr); |
314 |
|
return ptr; |
315 |
|
} |
316 |
|
|
317 |
|
/** |
318 |
* ccs_write_profile - Write profile table. |
* ccs_write_profile - Write profile table. |
319 |
* |
* |
320 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
325 |
{ |
{ |
326 |
char *data = head->write_buf; |
char *data = head->write_buf; |
327 |
unsigned int i; |
unsigned int i; |
328 |
unsigned int value; |
int value; |
329 |
|
int mode; |
330 |
|
u8 config; |
331 |
|
bool use_default = false; |
332 |
char *cp; |
char *cp; |
333 |
struct ccs_profile *ccs_profile; |
struct ccs_profile *profile; |
334 |
i = simple_strtoul(data, &cp, 10); |
i = simple_strtoul(data, &cp, 10); |
335 |
if (data != cp) { |
if (data == cp) { |
336 |
|
profile = &ccs_default_profile; |
337 |
|
} else { |
338 |
if (*cp != '-') |
if (*cp != '-') |
339 |
return -EINVAL; |
return -EINVAL; |
340 |
data = cp + 1; |
data = cp + 1; |
341 |
|
profile = ccs_find_or_assign_new_profile(i); |
342 |
|
if (!profile) |
343 |
|
return -EINVAL; |
344 |
} |
} |
|
ccs_profile = ccs_find_or_assign_new_profile(i); |
|
|
if (!ccs_profile) |
|
|
return -EINVAL; |
|
345 |
cp = strchr(data, '='); |
cp = strchr(data, '='); |
346 |
if (!cp) |
if (!cp) |
347 |
return -EINVAL; |
return -EINVAL; |
348 |
*cp = '\0'; |
*cp++ = '\0'; |
349 |
|
if (profile != &ccs_default_profile) |
350 |
|
use_default = strstr(cp, "use_default") != NULL; |
351 |
|
if (strstr(cp, "verbose=yes")) |
352 |
|
value = 1; |
353 |
|
else if (strstr(cp, "verbose=no")) |
354 |
|
value = 0; |
355 |
|
else |
356 |
|
value = -1; |
357 |
|
if (!strcmp(data, "PREFERENCE::audit")) { |
358 |
|
#ifdef CONFIG_CCSECURITY_AUDIT |
359 |
|
char *cp2; |
360 |
|
#endif |
361 |
|
if (use_default) { |
362 |
|
profile->audit = &ccs_default_profile.preference; |
363 |
|
return 0; |
364 |
|
} |
365 |
|
profile->audit = &profile->preference; |
366 |
|
#ifdef CONFIG_CCSECURITY_AUDIT |
367 |
|
cp2 = strstr(cp, "max_grant_log="); |
368 |
|
if (cp2) |
369 |
|
sscanf(cp2 + 14, "%u", |
370 |
|
&profile->preference.audit_max_grant_log); |
371 |
|
cp2 = strstr(cp, "max_reject_log="); |
372 |
|
if (cp2) |
373 |
|
sscanf(cp2 + 15, "%u", |
374 |
|
&profile->preference.audit_max_reject_log); |
375 |
|
#endif |
376 |
|
if (strstr(cp, "task_info=yes")) |
377 |
|
profile->preference.audit_task_info = true; |
378 |
|
else if (strstr(cp, "task_info=no")) |
379 |
|
profile->preference.audit_task_info = false; |
380 |
|
if (strstr(cp, "path_info=yes")) |
381 |
|
profile->preference.audit_path_info = true; |
382 |
|
else if (strstr(cp, "path_info=no")) |
383 |
|
profile->preference.audit_path_info = false; |
384 |
|
return 0; |
385 |
|
} |
386 |
|
if (!strcmp(data, "PREFERENCE::enforcing")) { |
387 |
|
char *cp2; |
388 |
|
if (use_default) { |
389 |
|
profile->enforcing = &ccs_default_profile.preference; |
390 |
|
return 0; |
391 |
|
} |
392 |
|
profile->enforcing = &profile->preference; |
393 |
|
if (value >= 0) |
394 |
|
profile->preference.enforcing_verbose = value; |
395 |
|
cp2 = strstr(cp, "penalty="); |
396 |
|
if (cp2) |
397 |
|
sscanf(cp2 + 8, "%u", |
398 |
|
&profile->preference.enforcing_penalty); |
399 |
|
return 0; |
400 |
|
} |
401 |
|
if (!strcmp(data, "PREFERENCE::permissive")) { |
402 |
|
if (use_default) { |
403 |
|
profile->permissive = &ccs_default_profile.preference; |
404 |
|
return 0; |
405 |
|
} |
406 |
|
profile->permissive = &profile->preference; |
407 |
|
if (value >= 0) |
408 |
|
profile->preference.permissive_verbose = value; |
409 |
|
return 0; |
410 |
|
} |
411 |
|
if (!strcmp(data, "PREFERENCE::learning")) { |
412 |
|
char *cp2; |
413 |
|
if (use_default) { |
414 |
|
profile->learning = &ccs_default_profile.preference; |
415 |
|
return 0; |
416 |
|
} |
417 |
|
profile->learning = &profile->preference; |
418 |
|
if (value >= 0) |
419 |
|
profile->preference.learning_verbose = value; |
420 |
|
cp2 = strstr(cp, "max_entry="); |
421 |
|
if (cp2) |
422 |
|
sscanf(cp2 + 10, "%u", |
423 |
|
&profile->preference.learning_max_entry); |
424 |
|
if (strstr(cp, "exec.realpath=yes")) |
425 |
|
profile->preference.learning_exec_realpath = true; |
426 |
|
else if (strstr(cp, "exec.realpath=no")) |
427 |
|
profile->preference.learning_exec_realpath = false; |
428 |
|
if (strstr(cp, "exec.argv0=yes")) |
429 |
|
profile->preference.learning_exec_argv0 = true; |
430 |
|
else if (strstr(cp, "exec.argv0=no")) |
431 |
|
profile->preference.learning_exec_argv0 = false; |
432 |
|
if (strstr(cp, "symlink.target=yes")) |
433 |
|
profile->preference.learning_symlink_target = true; |
434 |
|
else if (strstr(cp, "symlink.target=no")) |
435 |
|
profile->preference.learning_symlink_target = false; |
436 |
|
return 0; |
437 |
|
} |
438 |
|
if (profile == &ccs_default_profile) |
439 |
|
return -EINVAL; |
440 |
if (!strcmp(data, "COMMENT")) { |
if (!strcmp(data, "COMMENT")) { |
441 |
const struct ccs_path_info *new_comment |
const struct ccs_path_info *new_comment = ccs_get_name(cp); |
|
= ccs_get_name(cp + 1); |
|
442 |
const struct ccs_path_info *old_comment; |
const struct ccs_path_info *old_comment; |
443 |
/* Protect reader from ccs_put_name(). */ |
/* Protect reader from ccs_put_name(). */ |
|
/***** CRITICAL SECTION START *****/ |
|
444 |
spin_lock(&ccs_profile_comment_lock); |
spin_lock(&ccs_profile_comment_lock); |
445 |
old_comment = ccs_profile->comment; |
old_comment = profile->comment; |
446 |
ccs_profile->comment = new_comment; |
profile->comment = new_comment; |
447 |
spin_unlock(&ccs_profile_comment_lock); |
spin_unlock(&ccs_profile_comment_lock); |
|
/***** CRITICAL SECTION END *****/ |
|
448 |
ccs_put_name(old_comment); |
ccs_put_name(old_comment); |
|
ccs_profile_entry_used[0] = true; |
|
449 |
return 0; |
return 0; |
450 |
} |
} |
451 |
if (ccs_str_starts(&data, CCS_KEYWORD_MAC_FOR_CAPABILITY)) { |
if (!strcmp(data, "CONFIG")) { |
452 |
if (sscanf(cp + 1, "%u", &value) != 1) { |
i = CCS_MAX_MAC_INDEX + CCS_MAX_CAPABILITY_INDEX |
453 |
for (i = 0; i < 4; i++) { |
+ CCS_MAX_MAC_CATEGORY_INDEX; |
454 |
if (strcmp(cp + 1, ccs_mode_4[i])) |
config = profile->default_config; |
455 |
continue; |
} else if (ccs_str_starts(&data, "CONFIG::")) { |
456 |
value = i; |
config = 0; |
457 |
break; |
for (i = 0; i < CCS_MAX_MAC_INDEX + CCS_MAX_CAPABILITY_INDEX |
458 |
} |
+ CCS_MAX_MAC_CATEGORY_INDEX; i++) { |
459 |
if (i == 4) |
if (strcmp(data, ccs_mac_keywords[i])) |
|
return -EINVAL; |
|
|
} |
|
|
if (value > 3) |
|
|
value = 3; |
|
|
for (i = 0; i < CCS_MAX_CAPABILITY_INDEX; i++) { |
|
|
if (strcmp(data, ccs_capability_control_keyword[i])) |
|
460 |
continue; |
continue; |
461 |
ccs_profile->capability_value[i] = value; |
config = profile->config[i]; |
462 |
ccs_profile_entry_used[i + 1 + CCS_MAX_CONTROL_INDEX] |
break; |
|
= true; |
|
|
return 0; |
|
463 |
} |
} |
464 |
|
if (i == CCS_MAX_MAC_INDEX + CCS_MAX_CAPABILITY_INDEX |
465 |
|
+ CCS_MAX_MAC_CATEGORY_INDEX) |
466 |
|
return -EINVAL; |
467 |
|
} else { |
468 |
return -EINVAL; |
return -EINVAL; |
469 |
} |
} |
470 |
for (i = 0; i < CCS_MAX_CONTROL_INDEX; i++) { |
if (use_default) { |
471 |
if (strcmp(data, ccs_control_array[i].keyword)) |
config = CCS_CONFIG_USE_DEFAULT; |
472 |
continue; |
} else { |
473 |
if (sscanf(cp + 1, "%u", &value) != 1) { |
for (mode = 3; mode >= 0; mode--) |
474 |
int j; |
if (strstr(cp, ccs_mode_4[mode])) |
475 |
const char **modes; |
/* |
476 |
switch (i) { |
* Update lower 3 bits in order to distinguish |
477 |
case CCS_AUTOLEARN_EXEC_REALPATH: |
* 'config' from 'CCS_CONFIG_USE_DEAFULT'. |
478 |
case CCS_AUTOLEARN_EXEC_ARGV0: |
*/ |
479 |
case CCS_RESTRICT_AUTOBIND: |
config = (config & ~7) | mode; |
480 |
case CCS_VERBOSE: |
#ifdef CONFIG_CCSECURITY_AUDIT |
481 |
modes = ccs_mode_2; |
if (config != CCS_CONFIG_USE_DEFAULT) { |
482 |
break; |
if (strstr(cp, "grant_log=yes")) |
483 |
default: |
config |= CCS_CONFIG_WANT_GRANT_LOG; |
484 |
modes = ccs_mode_4; |
else if (strstr(cp, "grant_log=no")) |
485 |
break; |
config &= ~CCS_CONFIG_WANT_GRANT_LOG; |
486 |
} |
if (strstr(cp, "reject_log=yes")) |
487 |
for (j = 0; j < 4; j++) { |
config |= CCS_CONFIG_WANT_REJECT_LOG; |
488 |
if (strcmp(cp + 1, modes[j])) |
else if (strstr(cp, "reject_log=no")) |
489 |
continue; |
config &= ~CCS_CONFIG_WANT_REJECT_LOG; |
|
value = j; |
|
|
break; |
|
|
} |
|
|
if (j == 4) |
|
|
return -EINVAL; |
|
|
} else if (value > ccs_control_array[i].max_value) { |
|
|
value = ccs_control_array[i].max_value; |
|
490 |
} |
} |
491 |
ccs_profile->value[i] = value; |
#endif |
|
ccs_profile_entry_used[i + 1] = true; |
|
|
return 0; |
|
492 |
} |
} |
493 |
return -EINVAL; |
if (i < CCS_MAX_MAC_INDEX + CCS_MAX_CAPABILITY_INDEX |
494 |
|
+ CCS_MAX_MAC_CATEGORY_INDEX) |
495 |
|
profile->config[i] = config; |
496 |
|
else if (config != CCS_CONFIG_USE_DEFAULT) |
497 |
|
profile->default_config = config; |
498 |
|
return 0; |
499 |
} |
} |
500 |
|
|
501 |
/** |
/** |
502 |
* ccs_read_profile - Read profile table. |
* ccs_read_profile - Read profile table. |
503 |
* |
* |
504 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
|
* |
|
|
* Returns 0. |
|
505 |
*/ |
*/ |
506 |
static int ccs_read_profile(struct ccs_io_buffer *head) |
static void ccs_read_profile(struct ccs_io_buffer *head) |
507 |
{ |
{ |
508 |
static const int ccs_total |
int index; |
|
= CCS_MAX_CONTROL_INDEX + CCS_MAX_CAPABILITY_INDEX + 1; |
|
|
int step; |
|
509 |
if (head->read_eof) |
if (head->read_eof) |
510 |
return 0; |
return; |
511 |
for (step = head->read_step; step < CCS_MAX_PROFILES * ccs_total; |
if (head->read_bit) |
512 |
step++) { |
goto body; |
513 |
const u8 index = step / ccs_total; |
ccs_io_printf(head, "PROFILE_VERSION=%s\n", "20090903"); |
514 |
u8 type = step % ccs_total; |
ccs_io_printf(head, "PREFERENCE::audit={ " |
515 |
const struct ccs_profile *ccs_profile = ccs_profile_ptr[index]; |
#ifdef CONFIG_CCSECURITY_AUDIT |
516 |
head->read_step = step; |
"max_grant_log=%u max_reject_log=%u " |
517 |
if (!ccs_profile) |
#endif |
518 |
continue; |
"task_info=%s path_info=%s }\n", |
519 |
if (!ccs_profile_entry_used[type]) |
#ifdef CONFIG_CCSECURITY_AUDIT |
520 |
continue; |
ccs_default_profile.preference.audit_max_grant_log, |
521 |
if (!type) { /* Print profile' comment tag. */ |
ccs_default_profile.preference.audit_max_reject_log, |
522 |
bool done; |
#endif |
523 |
/***** CRITICAL SECTION START *****/ |
ccs_yesno(ccs_default_profile.preference. |
524 |
spin_lock(&ccs_profile_comment_lock); |
audit_task_info), |
525 |
done = ccs_io_printf(head, "%u-COMMENT=%s\n", |
ccs_yesno(ccs_default_profile.preference. |
526 |
index, ccs_profile->comment ? |
audit_path_info)); |
527 |
ccs_profile->comment->name : ""); |
ccs_io_printf(head, "PREFERENCE::learning={ verbose=%s max_entry=%u " |
528 |
spin_unlock(&ccs_profile_comment_lock); |
"exec.realpath=%s exec.argv0=%s symlink.target=%s }\n", |
529 |
/***** CRITICAL SECTION END *****/ |
ccs_yesno(ccs_default_profile.preference. |
530 |
if (!done) |
learning_verbose), |
531 |
break; |
ccs_default_profile.preference.learning_max_entry, |
532 |
|
ccs_yesno(ccs_default_profile.preference. |
533 |
|
learning_exec_realpath), |
534 |
|
ccs_yesno(ccs_default_profile.preference. |
535 |
|
learning_exec_argv0), |
536 |
|
ccs_yesno(ccs_default_profile.preference. |
537 |
|
learning_symlink_target)); |
538 |
|
ccs_io_printf(head, "PREFERENCE::permissive={ verbose=%s }\n", |
539 |
|
ccs_yesno(ccs_default_profile.preference. |
540 |
|
permissive_verbose)); |
541 |
|
ccs_io_printf(head, "PREFERENCE::enforcing={ verbose=%s penalty=%u " |
542 |
|
"}\n", |
543 |
|
ccs_yesno(ccs_default_profile.preference. |
544 |
|
enforcing_verbose), |
545 |
|
ccs_default_profile.preference.enforcing_penalty); |
546 |
|
head->read_bit = 1; |
547 |
|
body: |
548 |
|
for (index = head->read_step; index < CCS_MAX_PROFILES; index++) { |
549 |
|
bool done; |
550 |
|
u8 config; |
551 |
|
int i; |
552 |
|
int pos; |
553 |
|
const struct ccs_profile *profile = ccs_profile_ptr[index]; |
554 |
|
head->read_step = index; |
555 |
|
if (!profile) |
556 |
continue; |
continue; |
557 |
|
pos = head->read_avail; |
558 |
|
spin_lock(&ccs_profile_comment_lock); |
559 |
|
done = ccs_io_printf(head, "%u-COMMENT=%s\n", index, |
560 |
|
profile->comment ? profile->comment->name |
561 |
|
: ""); |
562 |
|
spin_unlock(&ccs_profile_comment_lock); |
563 |
|
if (!done) |
564 |
|
goto out; |
565 |
|
config = profile->default_config; |
566 |
|
#ifdef CONFIG_CCSECURITY_AUDIT |
567 |
|
if (!ccs_io_printf(head, "%u-CONFIG={ mode=%s grant_log=%s " |
568 |
|
"reject_log=%s }\n", index, |
569 |
|
ccs_mode_4[config & 3], |
570 |
|
ccs_yesno(config & |
571 |
|
CCS_CONFIG_WANT_GRANT_LOG), |
572 |
|
ccs_yesno(config & |
573 |
|
CCS_CONFIG_WANT_REJECT_LOG))) |
574 |
|
goto out; |
575 |
|
#else |
576 |
|
if (!ccs_io_printf(head, "%u-CONFIG={ mode=%s }\n", index, |
577 |
|
ccs_mode_4[config & 3])) |
578 |
|
goto out; |
579 |
|
#endif |
580 |
|
for (i = 0; i < CCS_MAX_MAC_INDEX + CCS_MAX_CAPABILITY_INDEX |
581 |
|
+ CCS_MAX_MAC_CATEGORY_INDEX; i++) { |
582 |
|
#ifdef CONFIG_CCSECURITY_AUDIT |
583 |
|
const char *g; |
584 |
|
const char *r; |
585 |
|
#endif |
586 |
|
config = profile->config[i]; |
587 |
|
if (config == CCS_CONFIG_USE_DEFAULT) |
588 |
|
continue; |
589 |
|
#ifdef CONFIG_CCSECURITY_AUDIT |
590 |
|
g = ccs_yesno(config & CCS_CONFIG_WANT_GRANT_LOG); |
591 |
|
r = ccs_yesno(config & CCS_CONFIG_WANT_REJECT_LOG); |
592 |
|
if (!ccs_io_printf(head, "%u-CONFIG::%s={ mode=%s " |
593 |
|
"grant_log=%s reject_log=%s }\n", |
594 |
|
index, ccs_mac_keywords[i], |
595 |
|
ccs_mode_4[config & 3], g, r)) |
596 |
|
goto out; |
597 |
|
#else |
598 |
|
if (!ccs_io_printf(head, "%u-CONFIG::%s={ mode=%s }\n", |
599 |
|
index, ccs_mac_keywords[i], |
600 |
|
ccs_mode_4[config & 3])) |
601 |
|
goto out; |
602 |
|
#endif |
603 |
} |
} |
604 |
type--; |
if (profile->audit != &ccs_default_profile.preference && |
605 |
if (type >= CCS_MAX_CONTROL_INDEX) { |
!ccs_io_printf(head, "%u-PREFERENCE::audit={ " |
606 |
const int i = type - CCS_MAX_CONTROL_INDEX; |
#ifdef CONFIG_CCSECURITY_AUDIT |
607 |
const u8 value = ccs_profile->capability_value[i]; |
"max_grant_log=%u max_reject_log=%u " |
608 |
if (!ccs_io_printf(head, |
#endif |
609 |
"%u-" CCS_KEYWORD_MAC_FOR_CAPABILITY |
"task_info=%s path_info=%s }\n", index, |
610 |
"%s=%s\n", index, |
#ifdef CONFIG_CCSECURITY_AUDIT |
611 |
ccs_capability_control_keyword[i], |
profile->preference.audit_max_grant_log, |
612 |
ccs_mode_4[value])) |
profile->preference.audit_max_reject_log, |
613 |
break; |
#endif |
614 |
} else { |
ccs_yesno(profile->preference. |
615 |
const unsigned int value = ccs_profile->value[type]; |
audit_task_info), |
616 |
const char **modes = NULL; |
ccs_yesno(profile->preference. |
617 |
const char *keyword = ccs_control_array[type].keyword; |
audit_path_info))) |
618 |
switch (ccs_control_array[type].max_value) { |
goto out; |
619 |
case 3: |
if (profile->learning != &ccs_default_profile.preference && |
620 |
modes = ccs_mode_4; |
!ccs_io_printf(head, "%u-PREFERENCE::learning={ " |
621 |
break; |
"verbose=%s max_entry=%u exec.realpath=%s " |
622 |
case 1: |
"exec.argv0=%s symlink.target=%s }\n", |
623 |
modes = ccs_mode_2; |
index, |
624 |
break; |
ccs_yesno(profile->preference. |
625 |
} |
learning_verbose), |
626 |
if (modes) { |
profile->preference.learning_max_entry, |
627 |
if (!ccs_io_printf(head, "%u-%s=%s\n", index, |
ccs_yesno(profile->preference. |
628 |
keyword, modes[value])) |
learning_exec_realpath), |
629 |
break; |
ccs_yesno(profile->preference. |
630 |
} else { |
learning_exec_argv0), |
631 |
if (!ccs_io_printf(head, "%u-%s=%u\n", index, |
ccs_yesno(profile->preference. |
632 |
keyword, value)) |
learning_symlink_target))) |
633 |
break; |
goto out; |
634 |
} |
if (profile->permissive != &ccs_default_profile.preference && |
635 |
} |
!ccs_io_printf(head, "%u-PREFERENCE::permissive={ " |
636 |
|
"verbose=%s }\n", index, |
637 |
|
ccs_yesno(profile->preference. |
638 |
|
permissive_verbose))) |
639 |
|
goto out; |
640 |
|
if (profile->enforcing != &ccs_default_profile.preference && |
641 |
|
!ccs_io_printf(head, "%u-PREFERENCE::enforcing={ " |
642 |
|
"verbose=%s penalty=%u }\n", index, |
643 |
|
ccs_yesno(profile->preference. |
644 |
|
enforcing_verbose), |
645 |
|
profile->preference.enforcing_penalty)) |
646 |
|
goto out; |
647 |
|
continue; |
648 |
|
out: |
649 |
|
head->read_avail = pos; |
650 |
|
break; |
651 |
} |
} |
652 |
if (step == CCS_MAX_PROFILES * ccs_total) |
if (index == CCS_MAX_PROFILES) |
653 |
head->read_eof = true; |
head->read_eof = true; |
|
return 0; |
|
654 |
} |
} |
655 |
|
|
656 |
/* The list for "struct ccs_policy_manager_entry". */ |
/* The list for "struct ccs_policy_manager_entry". */ |
725 |
* |
* |
726 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
727 |
* |
* |
|
* Returns 0. |
|
|
* |
|
728 |
* Caller holds ccs_read_lock(). |
* Caller holds ccs_read_lock(). |
729 |
*/ |
*/ |
730 |
static int ccs_read_manager_policy(struct ccs_io_buffer *head) |
static void ccs_read_manager_policy(struct ccs_io_buffer *head) |
731 |
{ |
{ |
732 |
struct list_head *pos; |
struct list_head *pos; |
|
ccs_check_read_lock(); |
|
733 |
if (head->read_eof) |
if (head->read_eof) |
734 |
return 0; |
return; |
735 |
list_for_each_cookie(pos, head->read_var2, &ccs_policy_manager_list) { |
list_for_each_cookie(pos, head->read_var2, &ccs_policy_manager_list) { |
736 |
struct ccs_policy_manager_entry *ptr; |
struct ccs_policy_manager_entry *ptr; |
737 |
ptr = list_entry(pos, struct ccs_policy_manager_entry, list); |
ptr = list_entry(pos, struct ccs_policy_manager_entry, list); |
738 |
if (ptr->is_deleted) |
if (ptr->is_deleted) |
739 |
continue; |
continue; |
740 |
if (!ccs_io_printf(head, "%s\n", ptr->manager->name)) |
if (!ccs_io_printf(head, "%s\n", ptr->manager->name)) |
741 |
return 0; |
return; |
742 |
} |
} |
743 |
head->read_eof = true; |
head->read_eof = true; |
|
return 0; |
|
744 |
} |
} |
745 |
|
|
746 |
/** |
/** |
759 |
const struct ccs_path_info *domainname |
const struct ccs_path_info *domainname |
760 |
= ccs_current_domain()->domainname; |
= ccs_current_domain()->domainname; |
761 |
bool found = false; |
bool found = false; |
|
ccs_check_read_lock(); |
|
762 |
if (!ccs_policy_loaded) |
if (!ccs_policy_loaded) |
763 |
return true; |
return true; |
764 |
if (task->ccs_flags & CCS_TASK_IS_POLICY_MANAGER) |
if (task->ccs_flags & CCS_TASK_IS_POLICY_MANAGER) |
839 |
{ |
{ |
840 |
unsigned int pid; |
unsigned int pid; |
841 |
struct ccs_domain_info *domain = NULL; |
struct ccs_domain_info *domain = NULL; |
842 |
ccs_check_read_lock(); |
bool global_pid = false; |
843 |
if (!strcmp(data, "allow_execute")) { |
if (!strcmp(data, "allow_execute")) { |
844 |
head->read_execute_only = true; |
head->read_execute_only = true; |
845 |
return true; |
return true; |
846 |
} |
} |
847 |
if (sscanf(data, "pid=%u", &pid) == 1) { |
if (sscanf(data, "pid=%u", &pid) == 1 || |
848 |
|
(global_pid = true, sscanf(data, "global-pid=%u", &pid) == 1)) { |
849 |
struct task_struct *p; |
struct task_struct *p; |
|
/***** CRITICAL SECTION START *****/ |
|
850 |
read_lock(&tasklist_lock); |
read_lock(&tasklist_lock); |
851 |
|
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24) |
852 |
|
if (global_pid) |
853 |
|
p = find_task_by_pid_ns(pid, &init_pid_ns); |
854 |
|
else |
855 |
|
p = find_task_by_vpid(pid); |
856 |
|
#else |
857 |
p = find_task_by_pid(pid); |
p = find_task_by_pid(pid); |
858 |
|
#endif |
859 |
if (p) |
if (p) |
860 |
domain = ccs_task_domain(p); |
domain = ccs_task_domain(p); |
861 |
read_unlock(&tasklist_lock); |
read_unlock(&tasklist_lock); |
|
/***** CRITICAL SECTION END *****/ |
|
862 |
} else if (!strncmp(data, "domain=", 7)) { |
} else if (!strncmp(data, "domain=", 7)) { |
863 |
if (ccs_is_domain_def(data + 7)) |
if (ccs_is_domain_def(data + 7)) |
864 |
domain = ccs_find_domain(data + 7); |
domain = ccs_find_domain(data + 7); |
904 |
return ccs_write_env_policy(data, domain, cond, is_delete); |
return ccs_write_env_policy(data, domain, cond, is_delete); |
905 |
if (ccs_str_starts(&data, CCS_KEYWORD_ALLOW_MOUNT)) |
if (ccs_str_starts(&data, CCS_KEYWORD_ALLOW_MOUNT)) |
906 |
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); |
|
907 |
return ccs_write_file_policy(data, domain, cond, is_delete); |
return ccs_write_file_policy(data, domain, cond, is_delete); |
908 |
} |
} |
909 |
|
|
949 |
|
|
950 |
if (sscanf(data, CCS_KEYWORD_USE_PROFILE "%u", &profile) == 1 |
if (sscanf(data, CCS_KEYWORD_USE_PROFILE "%u", &profile) == 1 |
951 |
&& profile < CCS_MAX_PROFILES) { |
&& profile < CCS_MAX_PROFILES) { |
952 |
if (ccs_profile_ptr[profile] || !ccs_policy_loaded) |
if (!ccs_policy_loaded || ccs_profile_ptr[(u8) profile]) |
953 |
domain->profile = (u8) profile; |
domain->profile = (u8) profile; |
954 |
return 0; |
return 0; |
955 |
} |
} |
973 |
return error; |
return error; |
974 |
} |
} |
975 |
|
|
976 |
|
/** |
977 |
|
* ccs_print_name_union - Print a ccs_name_union. |
978 |
|
* |
979 |
|
* @head: Pointer to "struct ccs_io_buffer". |
980 |
|
* @ptr: Pointer to "struct ccs_name_union". |
981 |
|
* |
982 |
|
* Returns true on success, false otherwise. |
983 |
|
*/ |
984 |
static bool ccs_print_name_union(struct ccs_io_buffer *head, |
static bool ccs_print_name_union(struct ccs_io_buffer *head, |
985 |
const struct ccs_name_union *ptr) |
const struct ccs_name_union *ptr) |
986 |
{ |
{ |
993 |
return ccs_io_printf(head, " %s", ptr->filename->name); |
return ccs_io_printf(head, " %s", ptr->filename->name); |
994 |
} |
} |
995 |
|
|
996 |
|
/** |
997 |
|
* ccs_print_name_union_quoted - Print a ccs_name_union with double quotes. |
998 |
|
* |
999 |
|
* @head: Pointer to "struct ccs_io_buffer". |
1000 |
|
* @ptr: Pointer to "struct ccs_name_union". |
1001 |
|
* |
1002 |
|
* Returns true on success, false otherwise. |
1003 |
|
*/ |
1004 |
static bool ccs_print_name_union_quoted(struct ccs_io_buffer *head, |
static bool ccs_print_name_union_quoted(struct ccs_io_buffer *head, |
1005 |
const struct ccs_name_union *ptr) |
const struct ccs_name_union *ptr) |
1006 |
{ |
{ |
1010 |
return ccs_io_printf(head, "\"%s\"", ptr->filename->name); |
return ccs_io_printf(head, "\"%s\"", ptr->filename->name); |
1011 |
} |
} |
1012 |
|
|
1013 |
|
/** |
1014 |
|
* ccs_print_number_union_common - Print a ccs_number_union. |
1015 |
|
* |
1016 |
|
* @head: Pointer to "struct ccs_io_buffer". |
1017 |
|
* @ptr: Pointer to "struct ccs_number_union". |
1018 |
|
* @need_space: True if a space character is needed. |
1019 |
|
* |
1020 |
|
* Returns true on success, false otherwise. |
1021 |
|
*/ |
1022 |
static bool ccs_print_number_union_common(struct ccs_io_buffer *head, |
static bool ccs_print_number_union_common(struct ccs_io_buffer *head, |
1023 |
const struct ccs_number_union *ptr, |
const struct ccs_number_union *ptr, |
1024 |
const bool need_space) |
const bool need_space) |
1062 |
} |
} |
1063 |
} |
} |
1064 |
|
|
1065 |
|
/** |
1066 |
|
* ccs_print_number_union - Print a ccs_number_union. |
1067 |
|
* |
1068 |
|
* @head: Pointer to "struct ccs_io_buffer". |
1069 |
|
* @ptr: Pointer to "struct ccs_number_union". |
1070 |
|
* |
1071 |
|
* Returns true on success, false otherwise. |
1072 |
|
*/ |
1073 |
bool ccs_print_number_union(struct ccs_io_buffer *head, |
bool ccs_print_number_union(struct ccs_io_buffer *head, |
1074 |
const struct ccs_number_union *ptr) |
const struct ccs_number_union *ptr) |
1075 |
{ |
{ |
1076 |
return ccs_print_number_union_common(head, ptr, true); |
return ccs_print_number_union_common(head, ptr, true); |
1077 |
} |
} |
1078 |
|
|
1079 |
|
/** |
1080 |
|
* ccs_print_number_union_nospace - Print a ccs_number_union without a space character. |
1081 |
|
* |
1082 |
|
* @head: Pointer to "struct ccs_io_buffer". |
1083 |
|
* @ptr: Pointer to "struct ccs_number_union". |
1084 |
|
* |
1085 |
|
* Returns true on success, false otherwise. |
1086 |
|
*/ |
1087 |
static bool ccs_print_number_union_nospace(struct ccs_io_buffer *head, |
static bool ccs_print_number_union_nospace(struct ccs_io_buffer *head, |
1088 |
const struct ccs_number_union *ptr) |
const struct ccs_number_union *ptr) |
1089 |
{ |
{ |
1202 |
} |
} |
1203 |
|
|
1204 |
/** |
/** |
1205 |
* ccs_print_single_path_acl - Print a single path ACL entry. |
* ccs_print_path_acl - Print a path ACL entry. |
1206 |
* |
* |
1207 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1208 |
* @ptr: Pointer to "struct ccs_single_path_acl_record". |
* @ptr: Pointer to "struct ccs_path_acl". |
1209 |
* @cond: Pointer to "struct ccs_condition". May be NULL. |
* @cond: Pointer to "struct ccs_condition". May be NULL. |
1210 |
* |
* |
1211 |
* Returns true on success, false otherwise. |
* Returns true on success, false otherwise. |
1212 |
*/ |
*/ |
1213 |
static bool ccs_print_single_path_acl(struct ccs_io_buffer *head, |
static bool ccs_print_path_acl(struct ccs_io_buffer *head, |
1214 |
struct ccs_single_path_acl_record *ptr, |
struct ccs_path_acl *ptr, |
1215 |
const struct ccs_condition *cond) |
const struct ccs_condition *cond) |
1216 |
{ |
{ |
1217 |
int pos; |
int pos; |
1218 |
u8 bit; |
u8 bit; |
1219 |
const u16 perm = ptr->perm; |
const u16 perm = ptr->perm; |
1220 |
for (bit = head->read_bit; bit < CCS_MAX_SINGLE_PATH_OPERATION; bit++) { |
for (bit = head->read_bit; bit < CCS_MAX_PATH_OPERATION; bit++) { |
|
const char *msg; |
|
1221 |
if (!(perm & (1 << bit))) |
if (!(perm & (1 << bit))) |
1222 |
continue; |
continue; |
1223 |
if (head->read_execute_only && bit != CCS_TYPE_EXECUTE_ACL) |
if (head->read_execute_only && bit != CCS_TYPE_EXECUTE) |
1224 |
continue; |
continue; |
1225 |
/* Print "read/write" instead of "read" and "write". */ |
/* Print "read/write" instead of "read" and "write". */ |
1226 |
if ((bit == CCS_TYPE_READ_ACL || bit == CCS_TYPE_WRITE_ACL) |
if ((bit == CCS_TYPE_READ || bit == CCS_TYPE_WRITE) |
1227 |
&& (perm & (1 << CCS_TYPE_READ_WRITE_ACL))) |
&& (perm & (1 << CCS_TYPE_READ_WRITE))) |
1228 |
continue; |
continue; |
|
msg = ccs_sp2keyword(bit); |
|
1229 |
pos = head->read_avail; |
pos = head->read_avail; |
1230 |
if (!ccs_io_printf(head, "allow_%s", msg) || |
if (!ccs_io_printf(head, "allow_%s", ccs_path2keyword(bit)) || |
1231 |
!ccs_print_name_union(head, &ptr->name) || |
!ccs_print_name_union(head, &ptr->name) || |
1232 |
!ccs_print_condition(head, cond)) { |
!ccs_print_condition(head, cond)) { |
1233 |
head->read_bit = bit; |
head->read_bit = bit; |
1240 |
} |
} |
1241 |
|
|
1242 |
/** |
/** |
1243 |
* ccs_print_mkdev_acl - Print a mkdev ACL entry. |
* ccs_print_path_number3_acl - Print a path_number3 ACL entry. |
1244 |
* |
* |
1245 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1246 |
* @ptr: Pointer to "struct ccs_mkdev_acl_record". |
* @ptr: Pointer to "struct ccs_path_number3_acl". |
1247 |
* @cond: Pointer to "struct ccs_condition". May be NULL. |
* @cond: Pointer to "struct ccs_condition". May be NULL. |
1248 |
* |
* |
1249 |
* Returns true on success, false otherwise. |
* Returns true on success, false otherwise. |
1250 |
*/ |
*/ |
1251 |
static bool ccs_print_mkdev_acl(struct ccs_io_buffer *head, |
static bool ccs_print_path_number3_acl(struct ccs_io_buffer *head, |
1252 |
struct ccs_mkdev_acl_record *ptr, |
struct ccs_path_number3_acl *ptr, |
1253 |
const struct ccs_condition *cond) |
const struct ccs_condition *cond) |
1254 |
{ |
{ |
1255 |
int pos; |
int pos; |
1256 |
u8 bit; |
u8 bit; |
1257 |
const u16 perm = ptr->perm; |
const u16 perm = ptr->perm; |
1258 |
for (bit = head->read_bit; bit < CCS_MAX_MKDEV_OPERATION; bit++) { |
for (bit = head->read_bit; bit < CCS_MAX_PATH_NUMBER3_OPERATION; |
1259 |
const char *msg; |
bit++) { |
1260 |
if (!(perm & (1 << bit))) |
if (!(perm & (1 << bit))) |
1261 |
continue; |
continue; |
|
msg = ccs_mkdev2keyword(bit); |
|
1262 |
pos = head->read_avail; |
pos = head->read_avail; |
1263 |
if (!ccs_io_printf(head, "allow_%s", msg) || |
if (!ccs_io_printf(head, "allow_%s", |
1264 |
|
ccs_path_number32keyword(bit)) || |
1265 |
!ccs_print_name_union(head, &ptr->name) || |
!ccs_print_name_union(head, &ptr->name) || |
1266 |
|
!ccs_print_number_union(head, &ptr->mode) || |
1267 |
!ccs_print_number_union(head, &ptr->major) || |
!ccs_print_number_union(head, &ptr->major) || |
1268 |
!ccs_print_number_union(head, &ptr->minor) || |
!ccs_print_number_union(head, &ptr->minor) || |
1269 |
!ccs_print_condition(head, cond)) { |
!ccs_print_condition(head, cond)) { |
1277 |
} |
} |
1278 |
|
|
1279 |
/** |
/** |
1280 |
* ccs_print_double_path_acl - Print a double path ACL entry. |
* ccs_print_path2_acl - Print a path2 ACL entry. |
1281 |
* |
* |
1282 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1283 |
* @ptr: Pointer to "struct ccs_double_path_acl_record". |
* @ptr: Pointer to "struct ccs_path2_acl". |
1284 |
* @cond: Pointer to "struct ccs_condition". May be NULL. |
* @cond: Pointer to "struct ccs_condition". May be NULL. |
1285 |
* |
* |
1286 |
* Returns true on success, false otherwise. |
* Returns true on success, false otherwise. |
1287 |
*/ |
*/ |
1288 |
static bool ccs_print_double_path_acl(struct ccs_io_buffer *head, |
static bool ccs_print_path2_acl(struct ccs_io_buffer *head, |
1289 |
struct ccs_double_path_acl_record *ptr, |
struct ccs_path2_acl *ptr, |
1290 |
const struct ccs_condition *cond) |
const struct ccs_condition *cond) |
1291 |
{ |
{ |
1292 |
int pos; |
int pos; |
1293 |
u8 bit; |
u8 bit; |
1294 |
const u8 perm = ptr->perm; |
const u8 perm = ptr->perm; |
1295 |
for (bit = head->read_bit; bit < CCS_MAX_DOUBLE_PATH_OPERATION; bit++) { |
for (bit = head->read_bit; bit < CCS_MAX_PATH2_OPERATION; bit++) { |
|
const char *msg; |
|
1296 |
if (!(perm & (1 << bit))) |
if (!(perm & (1 << bit))) |
1297 |
continue; |
continue; |
|
msg = ccs_dp2keyword(bit); |
|
1298 |
pos = head->read_avail; |
pos = head->read_avail; |
1299 |
if (!ccs_io_printf(head, "allow_%s", msg) || |
if (!ccs_io_printf(head, "allow_%s", |
1300 |
|
ccs_path22keyword(bit)) || |
1301 |
!ccs_print_name_union(head, &ptr->name1) || |
!ccs_print_name_union(head, &ptr->name1) || |
1302 |
!ccs_print_name_union(head, &ptr->name2) || |
!ccs_print_name_union(head, &ptr->name2) || |
1303 |
!ccs_print_condition(head, cond)) { |
!ccs_print_condition(head, cond)) { |
1311 |
} |
} |
1312 |
|
|
1313 |
/** |
/** |
1314 |
* ccs_print_path_number_acl - Print an ioctl/chmod/chown/chgrp ACL entry. |
* ccs_print_path_number_acl - Print a path_number ACL entry. |
1315 |
* |
* |
1316 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1317 |
* @ptr: Pointer to "struct ccs_path_number_acl_record". |
* @ptr: Pointer to "struct ccs_path_number_acl". |
1318 |
* @cond: Pointer to "struct ccs_condition". May be NULL. |
* @cond: Pointer to "struct ccs_condition". May be NULL. |
1319 |
* |
* |
1320 |
* Returns true on success, false otherwise. |
* Returns true on success, false otherwise. |
1321 |
*/ |
*/ |
1322 |
static bool ccs_print_path_number_acl(struct ccs_io_buffer *head, |
static bool ccs_print_path_number_acl(struct ccs_io_buffer *head, |
1323 |
struct ccs_path_number_acl_record *ptr, |
struct ccs_path_number_acl *ptr, |
1324 |
const struct ccs_condition *cond) |
const struct ccs_condition *cond) |
1325 |
{ |
{ |
1326 |
int pos; |
int pos; |
1327 |
u8 bit; |
u8 bit; |
1328 |
const u8 perm = ptr->perm; |
const u8 perm = ptr->perm; |
1329 |
for (bit = head->read_bit; bit < CCS_MAX_PATH_NUMBER_OPERATION; bit++) { |
for (bit = head->read_bit; bit < CCS_MAX_PATH_NUMBER_OPERATION; |
1330 |
const char *msg; |
bit++) { |
1331 |
if (!(perm & (1 << bit))) |
if (!(perm & (1 << bit))) |
1332 |
continue; |
continue; |
|
msg = ccs_path_number2keyword(bit); |
|
1333 |
pos = head->read_avail; |
pos = head->read_avail; |
1334 |
if (!ccs_io_printf(head, "allow_%s", msg) || |
if (!ccs_io_printf(head, "allow_%s", |
1335 |
|
ccs_path_number2keyword(bit)) || |
1336 |
!ccs_print_name_union(head, &ptr->name) || |
!ccs_print_name_union(head, &ptr->name) || |
1337 |
!ccs_print_number_union(head, &ptr->number) || |
!ccs_print_number_union(head, &ptr->number) || |
1338 |
!ccs_print_condition(head, cond)) { |
!ccs_print_condition(head, cond)) { |
1349 |
* ccs_print_env_acl - Print an evironment variable name's ACL entry. |
* ccs_print_env_acl - Print an evironment variable name's ACL entry. |
1350 |
* |
* |
1351 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1352 |
* @ptr: Pointer to "struct ccs_env_acl_record". |
* @ptr: Pointer to "struct ccs_env_acl". |
1353 |
* @cond: Pointer to "struct ccs_condition". May be NULL. |
* @cond: Pointer to "struct ccs_condition". May be NULL. |
1354 |
* |
* |
1355 |
* Returns true on success, false otherwise. |
* Returns true on success, false otherwise. |
1356 |
*/ |
*/ |
1357 |
static bool ccs_print_env_acl(struct ccs_io_buffer *head, |
static bool ccs_print_env_acl(struct ccs_io_buffer *head, |
1358 |
struct ccs_env_acl_record *ptr, |
struct ccs_env_acl *ptr, |
1359 |
const struct ccs_condition *cond) |
const struct ccs_condition *cond) |
1360 |
{ |
{ |
1361 |
const int pos = head->read_avail; |
const int pos = head->read_avail; |
1371 |
* ccs_print_capability_acl - Print a capability ACL entry. |
* ccs_print_capability_acl - Print a capability ACL entry. |
1372 |
* |
* |
1373 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1374 |
* @ptr: Pointer to "struct ccs_capability_acl_record". |
* @ptr: Pointer to "struct ccs_capability_acl". |
1375 |
* @cond: Pointer to "struct ccs_condition". May be NULL. |
* @cond: Pointer to "struct ccs_condition". May be NULL. |
1376 |
* |
* |
1377 |
* Returns true on success, false otherwise. |
* Returns true on success, false otherwise. |
1378 |
*/ |
*/ |
1379 |
static bool ccs_print_capability_acl(struct ccs_io_buffer *head, |
static bool ccs_print_capability_acl(struct ccs_io_buffer *head, |
1380 |
struct ccs_capability_acl_record *ptr, |
struct ccs_capability_acl *ptr, |
1381 |
const struct ccs_condition *cond) |
const struct ccs_condition *cond) |
1382 |
{ |
{ |
1383 |
const int pos = head->read_avail; |
const int pos = head->read_avail; |
1394 |
* ccs_print_ipv4_entry - Print IPv4 address of a network ACL entry. |
* ccs_print_ipv4_entry - Print IPv4 address of a network ACL entry. |
1395 |
* |
* |
1396 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1397 |
* @ptr: Pointer to "struct ccs_ip_network_acl_record". |
* @ptr: Pointer to "struct ccs_ip_network_acl". |
1398 |
* |
* |
1399 |
* Returns true on success, false otherwise. |
* Returns true on success, false otherwise. |
1400 |
*/ |
*/ |
1401 |
static bool ccs_print_ipv4_entry(struct ccs_io_buffer *head, |
static bool ccs_print_ipv4_entry(struct ccs_io_buffer *head, |
1402 |
struct ccs_ip_network_acl_record *ptr) |
struct ccs_ip_network_acl *ptr) |
1403 |
{ |
{ |
1404 |
const u32 min_address = ptr->address.ipv4.min; |
const u32 min_address = ptr->address.ipv4.min; |
1405 |
const u32 max_address = ptr->address.ipv4.max; |
const u32 max_address = ptr->address.ipv4.max; |
1415 |
* ccs_print_ipv6_entry - Print IPv6 address of a network ACL entry. |
* ccs_print_ipv6_entry - Print IPv6 address of a network ACL entry. |
1416 |
* |
* |
1417 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1418 |
* @ptr: Pointer to "struct ccs_ip_network_acl_record". |
* @ptr: Pointer to "struct ccs_ip_network_acl". |
1419 |
* |
* |
1420 |
* Returns true on success, false otherwise. |
* Returns true on success, false otherwise. |
1421 |
*/ |
*/ |
1422 |
static bool ccs_print_ipv6_entry(struct ccs_io_buffer *head, |
static bool ccs_print_ipv6_entry(struct ccs_io_buffer *head, |
1423 |
struct ccs_ip_network_acl_record *ptr) |
struct ccs_ip_network_acl *ptr) |
1424 |
{ |
{ |
1425 |
char buf[64]; |
char buf[64]; |
1426 |
const struct in6_addr *min_address = ptr->address.ipv6.min; |
const struct in6_addr *min_address = ptr->address.ipv6.min; |
1440 |
* ccs_print_network_acl - Print a network ACL entry. |
* ccs_print_network_acl - Print a network ACL entry. |
1441 |
* |
* |
1442 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1443 |
* @ptr: Pointer to "struct ccs_ip_network_acl_record". |
* @ptr: Pointer to "struct ccs_ip_network_acl". |
1444 |
* @cond: Pointer to "struct ccs_condition". May be NULL. |
* @cond: Pointer to "struct ccs_condition". May be NULL. |
1445 |
* |
* |
1446 |
* Returns true on success, false otherwise. |
* Returns true on success, false otherwise. |
1447 |
*/ |
*/ |
1448 |
static bool ccs_print_network_acl(struct ccs_io_buffer *head, |
static bool ccs_print_network_acl(struct ccs_io_buffer *head, |
1449 |
struct ccs_ip_network_acl_record *ptr, |
struct ccs_ip_network_acl *ptr, |
1450 |
const struct ccs_condition *cond) |
const struct ccs_condition *cond) |
1451 |
{ |
{ |
1452 |
const int pos = head->read_avail; |
int pos; |
1453 |
if (!ccs_io_printf(head, CCS_KEYWORD_ALLOW_NETWORK "%s ", |
u8 bit; |
1454 |
ccs_net2keyword(ptr->operation_type))) |
const u16 perm = ptr->perm; |
1455 |
goto out; |
for (bit = head->read_bit; bit < CCS_MAX_NETWORK_OPERATION; bit++) { |
1456 |
switch (ptr->record_type) { |
if (!(perm & (1 << bit))) |
1457 |
case CCS_IP_RECORD_TYPE_ADDRESS_GROUP: |
continue; |
1458 |
if (!ccs_io_printf(head, "@%s", |
pos = head->read_avail; |
1459 |
ptr->address.group->group_name->name)) |
if (!ccs_io_printf(head, CCS_KEYWORD_ALLOW_NETWORK "%s ", |
1460 |
goto out; |
ccs_net2keyword(bit))) |
|
break; |
|
|
case CCS_IP_RECORD_TYPE_IPv4: |
|
|
if (!ccs_print_ipv4_entry(head, ptr)) |
|
1461 |
goto out; |
goto out; |
1462 |
break; |
switch (ptr->address_type) { |
1463 |
case CCS_IP_RECORD_TYPE_IPv6: |
case CCS_IP_ADDRESS_TYPE_ADDRESS_GROUP: |
1464 |
if (!ccs_print_ipv6_entry(head, ptr)) |
if (!ccs_io_printf(head, "@%s", ptr->address.group-> |
1465 |
|
group_name->name)) |
1466 |
|
goto out; |
1467 |
|
break; |
1468 |
|
case CCS_IP_ADDRESS_TYPE_IPv4: |
1469 |
|
if (!ccs_print_ipv4_entry(head, ptr)) |
1470 |
|
goto out; |
1471 |
|
break; |
1472 |
|
case CCS_IP_ADDRESS_TYPE_IPv6: |
1473 |
|
if (!ccs_print_ipv6_entry(head, ptr)) |
1474 |
|
goto out; |
1475 |
|
break; |
1476 |
|
} |
1477 |
|
if (!ccs_print_number_union(head, &ptr->port) || |
1478 |
|
!ccs_print_condition(head, cond)) |
1479 |
goto out; |
goto out; |
|
break; |
|
1480 |
} |
} |
1481 |
if (!ccs_print_number_union(head, &ptr->port) || |
head->read_bit = 0; |
|
!ccs_print_condition(head, cond)) |
|
|
goto out; |
|
1482 |
return true; |
return true; |
1483 |
out: |
out: |
1484 |
|
head->read_bit = bit; |
1485 |
head->read_avail = pos; |
head->read_avail = pos; |
1486 |
return false; |
return false; |
1487 |
} |
} |
1490 |
* ccs_print_signal_acl - Print a signal ACL entry. |
* ccs_print_signal_acl - Print a signal ACL entry. |
1491 |
* |
* |
1492 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1493 |
* @ptr: Pointer to "struct signale_acl_record". |
* @ptr: Pointer to "struct signale_acl". |
1494 |
* @cond: Pointer to "struct ccs_condition". May be NULL. |
* @cond: Pointer to "struct ccs_condition". May be NULL. |
1495 |
* |
* |
1496 |
* Returns true on success, false otherwise. |
* Returns true on success, false otherwise. |
1497 |
*/ |
*/ |
1498 |
static bool ccs_print_signal_acl(struct ccs_io_buffer *head, |
static bool ccs_print_signal_acl(struct ccs_io_buffer *head, |
1499 |
struct ccs_signal_acl_record *ptr, |
struct ccs_signal_acl *ptr, |
1500 |
const struct ccs_condition *cond) |
const struct ccs_condition *cond) |
1501 |
{ |
{ |
1502 |
const int pos = head->read_avail; |
const int pos = head->read_avail; |
1530 |
* ccs_print_mount_acl - Print a mount ACL entry. |
* ccs_print_mount_acl - Print a mount ACL entry. |
1531 |
* |
* |
1532 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1533 |
* @ptr: Pointer to "struct ccs_mount_acl_record". |
* @ptr: Pointer to "struct ccs_mount_acl". |
1534 |
* @cond: Pointer to "struct ccs_condition". May be NULL. |
* @cond: Pointer to "struct ccs_condition". May be NULL. |
1535 |
* |
* |
1536 |
* Returns true on success, false otherwise. |
* Returns true on success, false otherwise. |
1537 |
*/ |
*/ |
1538 |
static bool ccs_print_mount_acl(struct ccs_io_buffer *head, |
static bool ccs_print_mount_acl(struct ccs_io_buffer *head, |
1539 |
struct ccs_mount_acl_record *ptr, |
struct ccs_mount_acl *ptr, |
1540 |
const struct ccs_condition *cond) |
const struct ccs_condition *cond) |
1541 |
{ |
{ |
1542 |
const int pos = head->read_avail; |
const int pos = head->read_avail; |
1553 |
} |
} |
1554 |
|
|
1555 |
/** |
/** |
|
* ccs_print_umount_acl - Print a mount ACL entry. |
|
|
* |
|
|
* @head: Pointer to "struct ccs_io_buffer". |
|
|
* @ptr: Pointer to "struct ccs_umount_acl_record". |
|
|
* @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_record *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_record". |
|
|
* @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_record *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_record". |
|
|
* @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_record *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; |
|
|
} |
|
|
|
|
|
/** |
|
1556 |
* ccs_print_entry - Print an ACL entry. |
* ccs_print_entry - Print an ACL entry. |
1557 |
* |
* |
1558 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1567 |
const u8 acl_type = ptr->type; |
const u8 acl_type = ptr->type; |
1568 |
if (ptr->is_deleted) |
if (ptr->is_deleted) |
1569 |
return true; |
return true; |
1570 |
if (acl_type == CCS_TYPE_SINGLE_PATH_ACL) { |
if (acl_type == CCS_TYPE_PATH_ACL) { |
1571 |
struct ccs_single_path_acl_record *acl |
struct ccs_path_acl *acl |
1572 |
= container_of(ptr, struct ccs_single_path_acl_record, |
= container_of(ptr, struct ccs_path_acl, head); |
1573 |
head); |
return ccs_print_path_acl(head, acl, cond); |
|
return ccs_print_single_path_acl(head, acl, cond); |
|
1574 |
} |
} |
1575 |
if (acl_type == CCS_TYPE_EXECUTE_HANDLER) { |
if (acl_type == CCS_TYPE_EXECUTE_HANDLER) { |
1576 |
struct ccs_execute_handler_record *acl |
struct ccs_execute_handler_record *acl |
1588 |
} |
} |
1589 |
if (head->read_execute_only) |
if (head->read_execute_only) |
1590 |
return true; |
return true; |
1591 |
if (acl_type == CCS_TYPE_MKDEV_ACL) { |
if (acl_type == CCS_TYPE_PATH_NUMBER3_ACL) { |
1592 |
struct ccs_mkdev_acl_record *acl |
struct ccs_path_number3_acl *acl |
1593 |
= container_of(ptr, struct ccs_mkdev_acl_record, head); |
= container_of(ptr, struct ccs_path_number3_acl, head); |
1594 |
return ccs_print_mkdev_acl(head, acl, cond); |
return ccs_print_path_number3_acl(head, acl, cond); |
1595 |
} |
} |
1596 |
if (acl_type == CCS_TYPE_DOUBLE_PATH_ACL) { |
if (acl_type == CCS_TYPE_PATH2_ACL) { |
1597 |
struct ccs_double_path_acl_record *acl |
struct ccs_path2_acl *acl |
1598 |
= container_of(ptr, struct ccs_double_path_acl_record, |
= container_of(ptr, struct ccs_path2_acl, head); |
1599 |
head); |
return ccs_print_path2_acl(head, acl, cond); |
|
return ccs_print_double_path_acl(head, acl, cond); |
|
1600 |
} |
} |
1601 |
if (acl_type == CCS_TYPE_PATH_NUMBER_ACL) { |
if (acl_type == CCS_TYPE_PATH_NUMBER_ACL) { |
1602 |
struct ccs_path_number_acl_record *acl |
struct ccs_path_number_acl *acl |
1603 |
= container_of(ptr, struct ccs_path_number_acl_record, |
= container_of(ptr, struct ccs_path_number_acl, head); |
|
head); |
|
1604 |
return ccs_print_path_number_acl(head, acl, cond); |
return ccs_print_path_number_acl(head, acl, cond); |
1605 |
} |
} |
1606 |
if (acl_type == CCS_TYPE_ENV_ACL) { |
if (acl_type == CCS_TYPE_ENV_ACL) { |
1607 |
struct ccs_env_acl_record *acl |
struct ccs_env_acl *acl |
1608 |
= container_of(ptr, struct ccs_env_acl_record, head); |
= container_of(ptr, struct ccs_env_acl, head); |
1609 |
return ccs_print_env_acl(head, acl, cond); |
return ccs_print_env_acl(head, acl, cond); |
1610 |
} |
} |
1611 |
if (acl_type == CCS_TYPE_CAPABILITY_ACL) { |
if (acl_type == CCS_TYPE_CAPABILITY_ACL) { |
1612 |
struct ccs_capability_acl_record *acl |
struct ccs_capability_acl *acl |
1613 |
= container_of(ptr, struct ccs_capability_acl_record, |
= container_of(ptr, struct ccs_capability_acl, head); |
|
head); |
|
1614 |
return ccs_print_capability_acl(head, acl, cond); |
return ccs_print_capability_acl(head, acl, cond); |
1615 |
} |
} |
1616 |
if (acl_type == CCS_TYPE_IP_NETWORK_ACL) { |
if (acl_type == CCS_TYPE_IP_NETWORK_ACL) { |
1617 |
struct ccs_ip_network_acl_record *acl |
struct ccs_ip_network_acl *acl |
1618 |
= container_of(ptr, struct ccs_ip_network_acl_record, |
= container_of(ptr, struct ccs_ip_network_acl, head); |
|
head); |
|
1619 |
return ccs_print_network_acl(head, acl, cond); |
return ccs_print_network_acl(head, acl, cond); |
1620 |
} |
} |
1621 |
if (acl_type == CCS_TYPE_SIGNAL_ACL) { |
if (acl_type == CCS_TYPE_SIGNAL_ACL) { |
1622 |
struct ccs_signal_acl_record *acl |
struct ccs_signal_acl *acl |
1623 |
= container_of(ptr, struct ccs_signal_acl_record, head); |
= container_of(ptr, struct ccs_signal_acl, head); |
1624 |
return ccs_print_signal_acl(head, acl, cond); |
return ccs_print_signal_acl(head, acl, cond); |
1625 |
} |
} |
1626 |
if (acl_type == CCS_TYPE_MOUNT_ACL) { |
if (acl_type == CCS_TYPE_MOUNT_ACL) { |
1627 |
struct ccs_mount_acl_record *acl |
struct ccs_mount_acl *acl |
1628 |
= container_of(ptr, struct ccs_mount_acl_record, head); |
= container_of(ptr, struct ccs_mount_acl, head); |
1629 |
return ccs_print_mount_acl(head, acl, cond); |
return ccs_print_mount_acl(head, acl, cond); |
1630 |
} |
} |
|
if (acl_type == CCS_TYPE_UMOUNT_ACL) { |
|
|
struct ccs_umount_acl_record *acl |
|
|
= container_of(ptr, struct ccs_umount_acl_record, head); |
|
|
return ccs_print_umount_acl(head, acl, cond); |
|
|
} |
|
|
if (acl_type == CCS_TYPE_CHROOT_ACL) { |
|
|
struct ccs_chroot_acl_record *acl |
|
|
= container_of(ptr, struct ccs_chroot_acl_record, head); |
|
|
return ccs_print_chroot_acl(head, acl, cond); |
|
|
} |
|
|
if (acl_type == CCS_TYPE_PIVOT_ROOT_ACL) { |
|
|
struct ccs_pivot_root_acl_record *acl |
|
|
= container_of(ptr, struct ccs_pivot_root_acl_record, |
|
|
head); |
|
|
return ccs_print_pivot_root_acl(head, acl, cond); |
|
|
} |
|
1631 |
BUG(); /* This must not happen. */ |
BUG(); /* This must not happen. */ |
1632 |
return false; |
return false; |
1633 |
} |
} |
1637 |
* |
* |
1638 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1639 |
* |
* |
|
* Returns 0. |
|
|
* |
|
1640 |
* Caller holds ccs_read_lock(). |
* Caller holds ccs_read_lock(). |
1641 |
*/ |
*/ |
1642 |
static int ccs_read_domain_policy(struct ccs_io_buffer *head) |
static void ccs_read_domain_policy(struct ccs_io_buffer *head) |
1643 |
{ |
{ |
1644 |
struct list_head *dpos; |
struct list_head *dpos; |
1645 |
struct list_head *apos; |
struct list_head *apos; |
|
ccs_check_read_lock(); |
|
1646 |
if (head->read_eof) |
if (head->read_eof) |
1647 |
return 0; |
return; |
1648 |
if (head->read_step == 0) |
if (head->read_step == 0) |
1649 |
head->read_step = 1; |
head->read_step = 1; |
1650 |
list_for_each_cookie(dpos, head->read_var1, &ccs_domain_list) { |
list_for_each_cookie(dpos, head->read_var1, &ccs_domain_list) { |
1675 |
transition_failed, |
transition_failed, |
1676 |
ignore_global_allow_read, |
ignore_global_allow_read, |
1677 |
ignore_global_allow_env)) |
ignore_global_allow_env)) |
1678 |
return 0; |
return; |
1679 |
head->read_step = 2; |
head->read_step = 2; |
1680 |
acl_loop: |
acl_loop: |
1681 |
if (head->read_step == 3) |
if (head->read_step == 3) |
1686 |
struct ccs_acl_info *ptr |
struct ccs_acl_info *ptr |
1687 |
= list_entry(apos, struct ccs_acl_info, list); |
= list_entry(apos, struct ccs_acl_info, list); |
1688 |
if (!ccs_print_entry(head, ptr)) |
if (!ccs_print_entry(head, ptr)) |
1689 |
return 0; |
return; |
1690 |
} |
} |
1691 |
head->read_step = 3; |
head->read_step = 3; |
1692 |
tail_mark: |
tail_mark: |
1693 |
if (!ccs_io_printf(head, "\n")) |
if (!ccs_io_printf(head, "\n")) |
1694 |
return 0; |
return; |
1695 |
head->read_step = 1; |
head->read_step = 1; |
1696 |
if (head->read_single_domain) |
if (head->read_single_domain) |
1697 |
break; |
break; |
1698 |
} |
} |
1699 |
head->read_eof = true; |
head->read_eof = true; |
|
return 0; |
|
1700 |
} |
} |
1701 |
|
|
1702 |
/** |
/** |
1709 |
* This is equivalent to doing |
* This is equivalent to doing |
1710 |
* |
* |
1711 |
* ( echo "select " $domainname; echo "use_profile " $profile ) | |
* ( echo "select " $domainname; echo "use_profile " $profile ) | |
1712 |
* /usr/lib/ccs/loadpolicy -d |
* /usr/sbin/ccs-loadpolicy -d |
1713 |
* |
* |
1714 |
* Caller holds ccs_read_lock(). |
* Caller holds ccs_read_lock(). |
1715 |
*/ |
*/ |
1719 |
char *cp = strchr(data, ' '); |
char *cp = strchr(data, ' '); |
1720 |
struct ccs_domain_info *domain; |
struct ccs_domain_info *domain; |
1721 |
unsigned int profile; |
unsigned int profile; |
|
ccs_check_read_lock(); |
|
1722 |
if (!cp) |
if (!cp) |
1723 |
return -EINVAL; |
return -EINVAL; |
1724 |
*cp = '\0'; |
*cp = '\0'; |
1726 |
if (profile >= CCS_MAX_PROFILES) |
if (profile >= CCS_MAX_PROFILES) |
1727 |
return -EINVAL; |
return -EINVAL; |
1728 |
domain = ccs_find_domain(cp + 1); |
domain = ccs_find_domain(cp + 1); |
1729 |
if (domain && (ccs_profile_ptr[profile] || !ccs_policy_loaded)) |
if (domain && (!ccs_policy_loaded || ccs_profile_ptr[(u8) profile])) |
1730 |
domain->profile = (u8) profile; |
domain->profile = (u8) profile; |
1731 |
return 0; |
return 0; |
1732 |
} |
} |
1736 |
* |
* |
1737 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1738 |
* |
* |
|
* Returns list of profile number and domainname pairs. |
|
|
* |
|
1739 |
* This is equivalent to doing |
* This is equivalent to doing |
1740 |
* |
* |
1741 |
* grep -A 1 '^<kernel>' /proc/ccs/domain_policy | |
* grep -A 1 '^<kernel>' /proc/ccs/domain_policy | |
1745 |
* |
* |
1746 |
* Caller holds ccs_read_lock(). |
* Caller holds ccs_read_lock(). |
1747 |
*/ |
*/ |
1748 |
static int ccs_read_domain_profile(struct ccs_io_buffer *head) |
static void ccs_read_domain_profile(struct ccs_io_buffer *head) |
1749 |
{ |
{ |
1750 |
struct list_head *pos; |
struct list_head *pos; |
|
ccs_check_read_lock(); |
|
1751 |
if (head->read_eof) |
if (head->read_eof) |
1752 |
return 0; |
return; |
1753 |
list_for_each_cookie(pos, head->read_var1, &ccs_domain_list) { |
list_for_each_cookie(pos, head->read_var1, &ccs_domain_list) { |
1754 |
struct ccs_domain_info *domain; |
struct ccs_domain_info *domain; |
1755 |
domain = list_entry(pos, struct ccs_domain_info, list); |
domain = list_entry(pos, struct ccs_domain_info, list); |
1757 |
continue; |
continue; |
1758 |
if (!ccs_io_printf(head, "%u %s\n", domain->profile, |
if (!ccs_io_printf(head, "%u %s\n", domain->profile, |
1759 |
domain->domainname->name)) |
domain->domainname->name)) |
1760 |
return 0; |
return; |
1761 |
} |
} |
1762 |
head->read_eof = true; |
head->read_eof = true; |
|
return 0; |
|
1763 |
} |
} |
1764 |
|
|
1765 |
/** |
/** |
1786 |
* |
* |
1787 |
* Caller holds ccs_read_lock(). |
* Caller holds ccs_read_lock(). |
1788 |
*/ |
*/ |
1789 |
static int ccs_read_pid(struct ccs_io_buffer *head) |
static void ccs_read_pid(struct ccs_io_buffer *head) |
1790 |
{ |
{ |
1791 |
char *buf = head->write_buf; |
char *buf = head->write_buf; |
1792 |
bool task_info = false; |
bool task_info = false; |
1793 |
|
bool global_pid = false; |
1794 |
unsigned int pid; |
unsigned int pid; |
1795 |
struct task_struct *p; |
struct task_struct *p; |
1796 |
struct ccs_domain_info *domain = NULL; |
struct ccs_domain_info *domain = NULL; |
1797 |
u32 ccs_flags = 0; |
u32 ccs_flags = 0; |
|
ccs_check_read_lock(); |
|
1798 |
/* Accessing write_buf is safe because head->io_sem is held. */ |
/* Accessing write_buf is safe because head->io_sem is held. */ |
1799 |
if (!buf) |
if (!buf) |
1800 |
goto done; /* Do nothing if open(O_RDONLY). */ |
return; /* Do nothing if open(O_RDONLY). */ |
1801 |
if (head->read_avail || head->read_eof) |
if (head->read_avail || head->read_eof) |
1802 |
goto done; |
return; |
1803 |
head->read_eof = true; |
head->read_eof = true; |
1804 |
if (ccs_str_starts(&buf, "info ")) |
if (ccs_str_starts(&buf, "info ")) |
1805 |
task_info = true; |
task_info = true; |
1806 |
|
if (ccs_str_starts(&buf, "global-pid ")) |
1807 |
|
global_pid = true; |
1808 |
pid = (unsigned int) simple_strtoul(buf, NULL, 10); |
pid = (unsigned int) simple_strtoul(buf, NULL, 10); |
|
/***** CRITICAL SECTION START *****/ |
|
1809 |
read_lock(&tasklist_lock); |
read_lock(&tasklist_lock); |
1810 |
|
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24) |
1811 |
|
if (global_pid) |
1812 |
|
p = find_task_by_pid_ns(pid, &init_pid_ns); |
1813 |
|
else |
1814 |
|
p = find_task_by_vpid(pid); |
1815 |
|
#else |
1816 |
p = find_task_by_pid(pid); |
p = find_task_by_pid(pid); |
1817 |
|
#endif |
1818 |
if (p) { |
if (p) { |
1819 |
domain = ccs_task_domain(p); |
domain = ccs_task_domain(p); |
1820 |
ccs_flags = p->ccs_flags; |
ccs_flags = p->ccs_flags; |
1821 |
} |
} |
1822 |
read_unlock(&tasklist_lock); |
read_unlock(&tasklist_lock); |
|
/***** CRITICAL SECTION END *****/ |
|
1823 |
if (!domain) |
if (!domain) |
1824 |
goto done; |
return; |
1825 |
if (!task_info) |
if (!task_info) |
1826 |
ccs_io_printf(head, "%u %u %s", pid, domain->profile, |
ccs_io_printf(head, "%u %u %s", pid, domain->profile, |
1827 |
domain->domainname->name); |
domain->domainname->name); |
1828 |
else |
else |
1829 |
ccs_io_printf(head, "%u manager=%s execute_handler=%s " |
ccs_io_printf(head, "%u manager=%s execute_handler=%s " |
1830 |
"state[0]=%u state[1]=%u state[2]=%u", pid, |
"state[0]=%u state[1]=%u state[2]=%u", pid, |
1831 |
ccs_flags & CCS_TASK_IS_POLICY_MANAGER ? |
ccs_yesno(ccs_flags & |
1832 |
"yes" : "no", |
CCS_TASK_IS_POLICY_MANAGER), |
1833 |
ccs_flags & CCS_TASK_IS_EXECUTE_HANDLER ? |
ccs_yesno(ccs_flags & |
1834 |
"yes" : "no", |
CCS_TASK_IS_EXECUTE_HANDLER), |
1835 |
(u8) (ccs_flags >> 24), |
(u8) (ccs_flags >> 24), |
1836 |
(u8) (ccs_flags >> 16), |
(u8) (ccs_flags >> 16), |
1837 |
(u8) (ccs_flags >> 8)); |
(u8) (ccs_flags >> 8)); |
|
done: |
|
|
return 0; |
|
1838 |
} |
} |
1839 |
|
|
1840 |
/** |
/** |
1884 |
* |
* |
1885 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1886 |
* |
* |
|
* Returns 0 on success, -EINVAL otherwise. |
|
|
* |
|
1887 |
* Caller holds ccs_read_lock(). |
* Caller holds ccs_read_lock(). |
1888 |
*/ |
*/ |
1889 |
static int ccs_read_exception_policy(struct ccs_io_buffer *head) |
static void ccs_read_exception_policy(struct ccs_io_buffer *head) |
1890 |
{ |
{ |
1891 |
ccs_check_read_lock(); |
if (head->read_eof) |
1892 |
if (!head->read_eof) { |
return; |
1893 |
switch (head->read_step) { |
switch (head->read_step) { |
1894 |
case 0: |
case 0: |
1895 |
head->read_var2 = NULL; |
head->read_var2 = NULL; |
1896 |
head->read_step = 1; |
head->read_step = 1; |
1897 |
case 1: |
case 1: |
1898 |
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; |
|
1899 |
break; |
break; |
1900 |
default: |
head->read_var2 = NULL; |
1901 |
return -EINVAL; |
head->read_step = 2; |
1902 |
} |
case 2: |
1903 |
|
if (!ccs_read_globally_readable_policy(head)) |
1904 |
|
break; |
1905 |
|
head->read_var2 = NULL; |
1906 |
|
head->read_step = 3; |
1907 |
|
case 3: |
1908 |
|
if (!ccs_read_globally_usable_env_policy(head)) |
1909 |
|
break; |
1910 |
|
head->read_var2 = NULL; |
1911 |
|
head->read_step = 4; |
1912 |
|
case 4: |
1913 |
|
if (!ccs_read_domain_initializer_policy(head)) |
1914 |
|
break; |
1915 |
|
head->read_var2 = NULL; |
1916 |
|
head->read_step = 6; |
1917 |
|
case 6: |
1918 |
|
if (!ccs_read_aggregator_policy(head)) |
1919 |
|
break; |
1920 |
|
head->read_var2 = NULL; |
1921 |
|
head->read_step = 7; |
1922 |
|
case 7: |
1923 |
|
if (!ccs_read_file_pattern(head)) |
1924 |
|
break; |
1925 |
|
head->read_var2 = NULL; |
1926 |
|
head->read_step = 8; |
1927 |
|
case 8: |
1928 |
|
if (!ccs_read_no_rewrite_policy(head)) |
1929 |
|
break; |
1930 |
|
head->read_var2 = NULL; |
1931 |
|
head->read_step = 9; |
1932 |
|
case 9: |
1933 |
|
if (!ccs_read_path_group_policy(head)) |
1934 |
|
break; |
1935 |
|
head->read_var1 = NULL; |
1936 |
|
head->read_var2 = NULL; |
1937 |
|
head->read_step = 10; |
1938 |
|
case 10: |
1939 |
|
if (!ccs_read_number_group_policy(head)) |
1940 |
|
break; |
1941 |
|
head->read_var1 = NULL; |
1942 |
|
head->read_var2 = NULL; |
1943 |
|
head->read_step = 11; |
1944 |
|
case 11: |
1945 |
|
if (!ccs_read_address_group_policy(head)) |
1946 |
|
break; |
1947 |
|
head->read_var2 = NULL; |
1948 |
|
head->read_step = 12; |
1949 |
|
case 12: |
1950 |
|
if (!ccs_read_reserved_port_policy(head)) |
1951 |
|
break; |
1952 |
|
head->read_eof = true; |
1953 |
} |
} |
|
return 0; |
|
1954 |
} |
} |
1955 |
|
|
1956 |
/** |
/** |
1978 |
while (offset < PAGE_SIZE) { |
while (offset < PAGE_SIZE) { |
1979 |
const char *kaddr = ee->dump.data; |
const char *kaddr = ee->dump.data; |
1980 |
const unsigned char c = kaddr[offset++]; |
const unsigned char c = kaddr[offset++]; |
1981 |
if (c && arg_len < CCS_MAX_PATHNAME_LEN - 10) { |
if (c && arg_len < CCS_EXEC_TMPSIZE - 10) { |
1982 |
if (c == '\\') { |
if (c == '\\') { |
1983 |
arg_ptr[arg_len++] = '\\'; |
arg_ptr[arg_len++] = '\\'; |
1984 |
arg_ptr[arg_len++] = '\\'; |
arg_ptr[arg_len++] = '\\'; |
|
} else if (c == '/') { |
|
|
arg_len = 0; |
|
1985 |
} else if (c > ' ' && c < 127) { |
} else if (c > ' ' && c < 127) { |
1986 |
arg_ptr[arg_len++] = c; |
arg_ptr[arg_len++] = c; |
1987 |
} else { |
} else { |
2006 |
return false; |
return false; |
2007 |
} |
} |
2008 |
|
|
2009 |
|
/** |
2010 |
|
* ccs_get_execute_condition - Get condition part for execute requests. |
2011 |
|
* |
2012 |
|
* @ee: Pointer to "struct ccs_execve_entry". |
2013 |
|
* |
2014 |
|
* Returns pointer to "struct ccs_condition" on success, NULL otherwise. |
2015 |
|
*/ |
2016 |
static struct ccs_condition *ccs_get_execute_condition(struct ccs_execve_entry |
static struct ccs_condition *ccs_get_execute_condition(struct ccs_execve_entry |
2017 |
*ee) |
*ee) |
2018 |
{ |
{ |
2021 |
int len = 256; |
int len = 256; |
2022 |
char *realpath = NULL; |
char *realpath = NULL; |
2023 |
char *argv0 = NULL; |
char *argv0 = NULL; |
2024 |
if (ccs_check_flags(NULL, CCS_AUTOLEARN_EXEC_REALPATH)) { |
const struct ccs_profile *profile = ccs_profile(ee->r.domain->profile); |
2025 |
|
if (profile->learning->learning_exec_realpath) { |
2026 |
struct file *file = ee->bprm->file; |
struct file *file = ee->bprm->file; |
2027 |
realpath = ccs_realpath_from_dentry(file->f_dentry, |
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 20) |
2028 |
file->f_vfsmnt); |
struct path path = { file->f_vfsmnt, file->f_dentry }; |
2029 |
|
realpath = ccs_realpath_from_path(&path); |
2030 |
|
#else |
2031 |
|
realpath = ccs_realpath_from_path(&file->f_path); |
2032 |
|
#endif |
2033 |
if (realpath) |
if (realpath) |
2034 |
len += strlen(realpath) + 17; |
len += strlen(realpath) + 17; |
2035 |
} |
} |
2036 |
if (ccs_check_flags(NULL, CCS_AUTOLEARN_EXEC_REALPATH)) { |
if (profile->learning->learning_exec_argv0) { |
2037 |
if (ccs_get_argv0(ee)) { |
if (ccs_get_argv0(ee)) { |
2038 |
argv0 = ee->tmp; |
argv0 = ee->tmp; |
2039 |
len += strlen(argv0) + 16; |
len += strlen(argv0) + 16; |
2040 |
} |
} |
2041 |
} |
} |
2042 |
buf = kmalloc(len, GFP_KERNEL); |
buf = kmalloc(len, GFP_KERNEL); |
2043 |
if (!buf) |
if (!buf) { |
2044 |
|
kfree(realpath); |
2045 |
return NULL; |
return NULL; |
2046 |
|
} |
2047 |
snprintf(buf, len - 1, "if"); |
snprintf(buf, len - 1, "if"); |
2048 |
if (current->ccs_flags & CCS_TASK_IS_EXECUTE_HANDLER) { |
if (current->ccs_flags & CCS_TASK_IS_EXECUTE_HANDLER) { |
2049 |
const int pos = strlen(buf); |
const int pos = strlen(buf); |
2066 |
return cond; |
return cond; |
2067 |
} |
} |
2068 |
|
|
2069 |
|
/** |
2070 |
|
* ccs_get_symlink_condition - Get condition part for symlink requests. |
2071 |
|
* |
2072 |
|
* @r: Pointer to "struct ccs_request_info". |
2073 |
|
* |
2074 |
|
* Returns pointer to "struct ccs_condition" on success, NULL otherwise. |
2075 |
|
*/ |
2076 |
|
static struct ccs_condition *ccs_get_symlink_condition(struct ccs_request_info |
2077 |
|
*r) |
2078 |
|
{ |
2079 |
|
struct ccs_condition *cond; |
2080 |
|
char *buf; |
2081 |
|
int len = 256; |
2082 |
|
const char *symlink = NULL; |
2083 |
|
const struct ccs_profile *profile = ccs_profile(r->profile); |
2084 |
|
if (profile->learning->learning_symlink_target) { |
2085 |
|
symlink = r->obj->symlink_target->name; |
2086 |
|
len += strlen(symlink) + 18; |
2087 |
|
} |
2088 |
|
buf = kmalloc(len, GFP_KERNEL); |
2089 |
|
if (!buf) |
2090 |
|
return NULL; |
2091 |
|
snprintf(buf, len - 1, "if"); |
2092 |
|
if (current->ccs_flags & CCS_TASK_IS_EXECUTE_HANDLER) { |
2093 |
|
const int pos = strlen(buf); |
2094 |
|
snprintf(buf + pos, len - pos - 1, |
2095 |
|
" task.type=execute_handler"); |
2096 |
|
} |
2097 |
|
if (symlink) { |
2098 |
|
const int pos = strlen(buf); |
2099 |
|
snprintf(buf + pos, len - pos - 1, " symlink.target=\"%s\"", |
2100 |
|
symlink); |
2101 |
|
} |
2102 |
|
cond = ccs_get_condition(buf); |
2103 |
|
kfree(buf); |
2104 |
|
return cond; |
2105 |
|
} |
2106 |
|
|
2107 |
/* Wait queue for ccs_query_list. */ |
/* Wait queue for ccs_query_list. */ |
2108 |
static DECLARE_WAIT_QUEUE_HEAD(ccs_query_wait); |
static DECLARE_WAIT_QUEUE_HEAD(ccs_query_wait); |
2109 |
|
|
2127 |
static atomic_t ccs_query_observers = ATOMIC_INIT(0); |
static atomic_t ccs_query_observers = ATOMIC_INIT(0); |
2128 |
|
|
2129 |
/** |
/** |
2130 |
* ccs_check_supervisor - Ask for the supervisor's decision. |
* ccs_supervisor - Ask for the supervisor's decision. |
2131 |
* |
* |
2132 |
* @r: Pointer to "struct ccs_request_info". |
* @r: Pointer to "struct ccs_request_info". |
2133 |
* @fmt: The printf()'s format string, followed by parameters. |
* @fmt: The printf()'s format string, followed by parameters. |
2137 |
* retry the access request which violated the policy in enforcing mode, |
* retry the access request which violated the policy in enforcing mode, |
2138 |
* 0 if it is not in enforcing mode, -EPERM otherwise. |
* 0 if it is not in enforcing mode, -EPERM otherwise. |
2139 |
*/ |
*/ |
2140 |
int ccs_check_supervisor(struct ccs_request_info *r, const char *fmt, ...) |
int ccs_supervisor(struct ccs_request_info *r, const char *fmt, ...) |
2141 |
{ |
{ |
2142 |
va_list args; |
va_list args; |
2143 |
int error = -EPERM; |
int error = -EPERM; |
2152 |
switch (r->mode) { |
switch (r->mode) { |
2153 |
char *buffer; |
char *buffer; |
2154 |
struct ccs_condition *cond; |
struct ccs_condition *cond; |
2155 |
case 1: |
case CCS_CONFIG_LEARNING: |
2156 |
if (!ccs_domain_quota_ok(r)) |
if (!ccs_domain_quota_ok(r)) |
2157 |
return 0; |
return 0; |
2158 |
va_start(args, fmt); |
va_start(args, fmt); |
2167 |
ccs_normalize_line(buffer); |
ccs_normalize_line(buffer); |
2168 |
if (r->ee && !strncmp(buffer, "allow_execute ", 14)) |
if (r->ee && !strncmp(buffer, "allow_execute ", 14)) |
2169 |
cond = ccs_get_execute_condition(r->ee); |
cond = ccs_get_execute_condition(r->ee); |
2170 |
|
else if (r->obj && r->obj->symlink_target) |
2171 |
|
cond = ccs_get_symlink_condition(r); |
2172 |
else if ((current->ccs_flags & CCS_TASK_IS_EXECUTE_HANDLER)) { |
else if ((current->ccs_flags & CCS_TASK_IS_EXECUTE_HANDLER)) { |
2173 |
char str[] = "if task.type=execute_handler"; |
char str[] = "if task.type=execute_handler"; |
2174 |
cond = ccs_get_condition(str); |
cond = ccs_get_condition(str); |
2178 |
ccs_put_condition(cond); |
ccs_put_condition(cond); |
2179 |
kfree(buffer); |
kfree(buffer); |
2180 |
/* fall through */ |
/* fall through */ |
2181 |
case 2: |
case CCS_CONFIG_PERMISSIVE: |
2182 |
return 0; |
return 0; |
2183 |
} |
} |
2184 |
if (!atomic_read(&ccs_query_observers)) { |
if (!atomic_read(&ccs_query_observers)) { |
2185 |
int i; |
int i; |
2186 |
if (current->ccs_flags & CCS_DONT_SLEEP_ON_ENFORCE_ERROR) |
if (current->ccs_flags & CCS_DONT_SLEEP_ON_ENFORCE_ERROR) |
2187 |
return -EPERM; |
return -EPERM; |
2188 |
for (i = 0; i < ccs_check_flags(r->domain, CCS_SLEEP_PERIOD); |
for (i = 0; i < ccs_profile(r->domain->profile)->enforcing-> |
2189 |
i++) { |
enforcing_penalty; i++) { |
2190 |
set_current_state(TASK_INTERRUPTIBLE); |
set_current_state(TASK_INTERRUPTIBLE); |
2191 |
schedule_timeout(HZ / 10); |
schedule_timeout(HZ / 10); |
2192 |
} |
} |
2206 |
if (!ccs_query_entry->query) |
if (!ccs_query_entry->query) |
2207 |
goto out; |
goto out; |
2208 |
INIT_LIST_HEAD(&ccs_query_entry->list); |
INIT_LIST_HEAD(&ccs_query_entry->list); |
|
/***** CRITICAL SECTION START *****/ |
|
2209 |
spin_lock(&ccs_query_list_lock); |
spin_lock(&ccs_query_list_lock); |
2210 |
if (ccs_quota_for_query && ccs_query_memory_size + len + |
if (ccs_quota_for_query && ccs_query_memory_size + len + |
2211 |
sizeof(*ccs_query_entry) >= ccs_quota_for_query) { |
sizeof(*ccs_query_entry) >= ccs_quota_for_query) { |
2215 |
ccs_query_entry->serial = ccs_serial++; |
ccs_query_entry->serial = ccs_serial++; |
2216 |
} |
} |
2217 |
spin_unlock(&ccs_query_list_lock); |
spin_unlock(&ccs_query_list_lock); |
|
/***** CRITICAL SECTION END *****/ |
|
2218 |
if (quota_exceeded) |
if (quota_exceeded) |
2219 |
goto out; |
goto out; |
2220 |
pos = snprintf(ccs_query_entry->query, len - 1, "Q%u-%hu\n%s", |
pos = snprintf(ccs_query_entry->query, len - 1, "Q%u-%hu\n%s", |
2225 |
vsnprintf(ccs_query_entry->query + pos, len - 1 - pos, fmt, args); |
vsnprintf(ccs_query_entry->query + pos, len - 1 - pos, fmt, args); |
2226 |
ccs_query_entry->query_len = strlen(ccs_query_entry->query) + 1; |
ccs_query_entry->query_len = strlen(ccs_query_entry->query) + 1; |
2227 |
va_end(args); |
va_end(args); |
|
/***** CRITICAL SECTION START *****/ |
|
2228 |
spin_lock(&ccs_query_list_lock); |
spin_lock(&ccs_query_list_lock); |
2229 |
list_add_tail(&ccs_query_entry->list, &ccs_query_list); |
list_add_tail(&ccs_query_entry->list, &ccs_query_list); |
2230 |
spin_unlock(&ccs_query_list_lock); |
spin_unlock(&ccs_query_list_lock); |
|
/***** CRITICAL SECTION END *****/ |
|
2231 |
/* Give 10 seconds for supervisor's opinion. */ |
/* Give 10 seconds for supervisor's opinion. */ |
2232 |
for (ccs_query_entry->timer = 0; |
for (ccs_query_entry->timer = 0; |
2233 |
atomic_read(&ccs_query_observers) && ccs_query_entry->timer < 100; |
atomic_read(&ccs_query_observers) && ccs_query_entry->timer < 100; |
2238 |
if (ccs_query_entry->answer) |
if (ccs_query_entry->answer) |
2239 |
break; |
break; |
2240 |
} |
} |
|
/***** CRITICAL SECTION START *****/ |
|
2241 |
spin_lock(&ccs_query_list_lock); |
spin_lock(&ccs_query_list_lock); |
2242 |
list_del(&ccs_query_entry->list); |
list_del(&ccs_query_entry->list); |
2243 |
ccs_query_memory_size -= len + sizeof(*ccs_query_entry); |
ccs_query_memory_size -= len + sizeof(*ccs_query_entry); |
2244 |
spin_unlock(&ccs_query_list_lock); |
spin_unlock(&ccs_query_list_lock); |
|
/***** CRITICAL SECTION END *****/ |
|
2245 |
switch (ccs_query_entry->answer) { |
switch (ccs_query_entry->answer) { |
2246 |
case 3: /* Asked to retry by administrator. */ |
case 3: /* Asked to retry by administrator. */ |
2247 |
error = 1; |
error = 1; |
2282 |
bool found = false; |
bool found = false; |
2283 |
u8 i; |
u8 i; |
2284 |
for (i = 0; i < 2; i++) { |
for (i = 0; i < 2; i++) { |
|
/***** CRITICAL SECTION START *****/ |
|
2285 |
spin_lock(&ccs_query_list_lock); |
spin_lock(&ccs_query_list_lock); |
2286 |
list_for_each(tmp, &ccs_query_list) { |
list_for_each(tmp, &ccs_query_list) { |
2287 |
struct ccs_query_entry *ptr |
struct ccs_query_entry *ptr |
2292 |
break; |
break; |
2293 |
} |
} |
2294 |
spin_unlock(&ccs_query_list_lock); |
spin_unlock(&ccs_query_list_lock); |
|
/***** CRITICAL SECTION END *****/ |
|
2295 |
if (found) |
if (found) |
2296 |
return POLLIN | POLLRDNORM; |
return POLLIN | POLLRDNORM; |
2297 |
if (i) |
if (i) |
2305 |
* ccs_read_query - Read access requests which violated policy in enforcing mode. |
* ccs_read_query - Read access requests which violated policy in enforcing mode. |
2306 |
* |
* |
2307 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
|
* |
|
|
* Returns 0. |
|
2308 |
*/ |
*/ |
2309 |
static int ccs_read_query(struct ccs_io_buffer *head) |
static void ccs_read_query(struct ccs_io_buffer *head) |
2310 |
{ |
{ |
2311 |
struct list_head *tmp; |
struct list_head *tmp; |
2312 |
int pos = 0; |
int pos = 0; |
2313 |
int len = 0; |
int len = 0; |
2314 |
char *buf; |
char *buf; |
2315 |
if (head->read_avail) |
if (head->read_avail) |
2316 |
return 0; |
return; |
2317 |
if (head->read_buf) { |
if (head->read_buf) { |
2318 |
kfree(head->read_buf); |
kfree(head->read_buf); |
2319 |
head->read_buf = NULL; |
head->read_buf = NULL; |
2320 |
head->readbuf_size = 0; |
head->readbuf_size = 0; |
2321 |
} |
} |
|
/***** CRITICAL SECTION START *****/ |
|
2322 |
spin_lock(&ccs_query_list_lock); |
spin_lock(&ccs_query_list_lock); |
2323 |
list_for_each(tmp, &ccs_query_list) { |
list_for_each(tmp, &ccs_query_list) { |
2324 |
struct ccs_query_entry *ptr |
struct ccs_query_entry *ptr |
2331 |
break; |
break; |
2332 |
} |
} |
2333 |
spin_unlock(&ccs_query_list_lock); |
spin_unlock(&ccs_query_list_lock); |
|
/***** CRITICAL SECTION END *****/ |
|
2334 |
if (!len) { |
if (!len) { |
2335 |
head->read_step = 0; |
head->read_step = 0; |
2336 |
return 0; |
return; |
2337 |
} |
} |
2338 |
buf = kzalloc(len, GFP_KERNEL); |
buf = kzalloc(len, GFP_KERNEL); |
2339 |
if (!buf) |
if (!buf) |
2340 |
return 0; |
return; |
2341 |
pos = 0; |
pos = 0; |
|
/***** CRITICAL SECTION START *****/ |
|
2342 |
spin_lock(&ccs_query_list_lock); |
spin_lock(&ccs_query_list_lock); |
2343 |
list_for_each(tmp, &ccs_query_list) { |
list_for_each(tmp, &ccs_query_list) { |
2344 |
struct ccs_query_entry *ptr |
struct ccs_query_entry *ptr |
2356 |
break; |
break; |
2357 |
} |
} |
2358 |
spin_unlock(&ccs_query_list_lock); |
spin_unlock(&ccs_query_list_lock); |
|
/***** CRITICAL SECTION END *****/ |
|
2359 |
if (buf[0]) { |
if (buf[0]) { |
2360 |
head->read_avail = len; |
head->read_avail = len; |
2361 |
head->readbuf_size = head->read_avail; |
head->readbuf_size = head->read_avail; |
2364 |
} else { |
} else { |
2365 |
kfree(buf); |
kfree(buf); |
2366 |
} |
} |
|
return 0; |
|
2367 |
} |
} |
2368 |
|
|
2369 |
/** |
/** |
2379 |
struct list_head *tmp; |
struct list_head *tmp; |
2380 |
unsigned int serial; |
unsigned int serial; |
2381 |
unsigned int answer; |
unsigned int answer; |
|
/***** CRITICAL SECTION START *****/ |
|
2382 |
spin_lock(&ccs_query_list_lock); |
spin_lock(&ccs_query_list_lock); |
2383 |
list_for_each(tmp, &ccs_query_list) { |
list_for_each(tmp, &ccs_query_list) { |
2384 |
struct ccs_query_entry *ptr |
struct ccs_query_entry *ptr |
2386 |
ptr->timer = 0; |
ptr->timer = 0; |
2387 |
} |
} |
2388 |
spin_unlock(&ccs_query_list_lock); |
spin_unlock(&ccs_query_list_lock); |
|
/***** CRITICAL SECTION END *****/ |
|
2389 |
if (sscanf(data, "A%u=%u", &serial, &answer) != 2) |
if (sscanf(data, "A%u=%u", &serial, &answer) != 2) |
2390 |
return -EINVAL; |
return -EINVAL; |
|
/***** CRITICAL SECTION START *****/ |
|
2391 |
spin_lock(&ccs_query_list_lock); |
spin_lock(&ccs_query_list_lock); |
2392 |
list_for_each(tmp, &ccs_query_list) { |
list_for_each(tmp, &ccs_query_list) { |
2393 |
struct ccs_query_entry *ptr |
struct ccs_query_entry *ptr |
2399 |
break; |
break; |
2400 |
} |
} |
2401 |
spin_unlock(&ccs_query_list_lock); |
spin_unlock(&ccs_query_list_lock); |
|
/***** CRITICAL SECTION END *****/ |
|
2402 |
return 0; |
return 0; |
2403 |
} |
} |
2404 |
|
|
2406 |
* ccs_read_version: Get version. |
* ccs_read_version: Get version. |
2407 |
* |
* |
2408 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
|
* |
|
|
* Returns version information. |
|
2409 |
*/ |
*/ |
2410 |
static int ccs_read_version(struct ccs_io_buffer *head) |
static void ccs_read_version(struct ccs_io_buffer *head) |
2411 |
{ |
{ |
2412 |
if (!head->read_eof) { |
if (head->read_eof) |
2413 |
ccs_io_printf(head, "1.7.0-pre"); |
return; |
2414 |
head->read_eof = true; |
ccs_io_printf(head, "1.7.1-pre"); |
2415 |
} |
head->read_eof = true; |
|
return 0; |
|
2416 |
} |
} |
2417 |
|
|
2418 |
/** |
/** |
2419 |
* ccs_read_self_domain - Get the current process's domainname. |
* ccs_read_self_domain - Get the current process's domainname. |
2420 |
* |
* |
2421 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
|
* |
|
|
* Returns the current process's domainname. |
|
2422 |
*/ |
*/ |
2423 |
static int ccs_read_self_domain(struct ccs_io_buffer *head) |
static void ccs_read_self_domain(struct ccs_io_buffer *head) |
2424 |
{ |
{ |
2425 |
if (!head->read_eof) { |
if (head->read_eof) |
2426 |
/* |
return; |
2427 |
* ccs_current_domain()->domainname != NULL |
/* |
2428 |
* because every process belongs to a domain and |
* ccs_current_domain()->domainname != NULL because every process |
2429 |
* the domain's name cannot be NULL. |
* belongs to a domain and the domain's name cannot be NULL. |
2430 |
*/ |
*/ |
2431 |
ccs_io_printf(head, "%s", |
ccs_io_printf(head, "%s", ccs_current_domain()->domainname->name); |
2432 |
ccs_current_domain()->domainname->name); |
head->read_eof = true; |
|
head->read_eof = true; |
|
|
} |
|
|
return 0; |
|
2433 |
} |
} |
2434 |
|
|
2435 |
/** |
/** |
2514 |
*/ |
*/ |
2515 |
head->read = NULL; |
head->read = NULL; |
2516 |
head->poll = NULL; |
head->poll = NULL; |
2517 |
} else if (type != CCS_QUERY && |
} else if (!head->poll) { |
2518 |
type != CCS_GRANTLOG && type != CCS_REJECTLOG) { |
/* Don't allocate read_buf for poll() access. */ |
|
/* |
|
|
* Don't allocate buffer for reading if the file is one of |
|
|
* /proc/ccs/grant_log , /proc/ccs/reject_log , /proc/ccs/query. |
|
|
*/ |
|
2519 |
if (!head->readbuf_size) |
if (!head->readbuf_size) |
2520 |
head->readbuf_size = 4096 * 2; |
head->readbuf_size = 4096; |
2521 |
head->read_buf = kzalloc(head->readbuf_size, GFP_KERNEL); |
head->read_buf = kzalloc(head->readbuf_size, GFP_KERNEL); |
2522 |
if (!head->read_buf) { |
if (!head->read_buf) { |
2523 |
kfree(head); |
kfree(head); |
2531 |
*/ |
*/ |
2532 |
head->write = NULL; |
head->write = NULL; |
2533 |
} else if (head->write) { |
} else if (head->write) { |
2534 |
head->writebuf_size = 4096 * 2; |
head->writebuf_size = 4096; |
2535 |
head->write_buf = kzalloc(head->writebuf_size, GFP_KERNEL); |
head->write_buf = kzalloc(head->writebuf_size, GFP_KERNEL); |
2536 |
if (!head->write_buf) { |
if (!head->write_buf) { |
2537 |
kfree(head->read_buf); |
kfree(head->read_buf); |
2552 |
ccs_read_control(file, NULL, 0); |
ccs_read_control(file, NULL, 0); |
2553 |
/* |
/* |
2554 |
* If the file is /proc/ccs/query , increment the observer counter. |
* If the file is /proc/ccs/query , increment the observer counter. |
2555 |
* The obserber counter is used by ccs_check_supervisor() to see if |
* The obserber counter is used by ccs_supervisor() to see if |
2556 |
* there is some process monitoring /proc/ccs/query. |
* there is some process monitoring /proc/ccs/query. |
2557 |
*/ |
*/ |
2558 |
else if (type == CCS_QUERY) |
else if (type == CCS_QUERY) |
2567 |
* @wait: Pointer to "poll_table". |
* @wait: Pointer to "poll_table". |
2568 |
* |
* |
2569 |
* Waits for read readiness. |
* Waits for read readiness. |
2570 |
* /proc/ccs/query is handled by /usr/lib/ccs/ccs-queryd and |
* /proc/ccs/query is handled by /usr/sbin/ccs-queryd and |
2571 |
* /proc/ccs/grant_log and /proc/ccs/reject_log are handled by |
* /proc/ccs/grant_log and /proc/ccs/reject_log are handled by |
2572 |
* /usr/lib/ccs/ccs-auditd. |
* /usr/sbin/ccs-auditd . |
2573 |
*/ |
*/ |
2574 |
int ccs_poll_control(struct file *file, poll_table *wait) |
int ccs_poll_control(struct file *file, poll_table *wait) |
2575 |
{ |
{ |
2600 |
return -EFAULT; |
return -EFAULT; |
2601 |
if (mutex_lock_interruptible(&head->io_sem)) |
if (mutex_lock_interruptible(&head->io_sem)) |
2602 |
return -EINTR; |
return -EINTR; |
2603 |
/* Call the policy handler. */ |
while (1) { |
2604 |
len = head->read(head); |
/* Call the policy handler. */ |
2605 |
if (len < 0) |
head->read(head); |
2606 |
goto out; |
/* Write to buffer. */ |
2607 |
/* Write to buffer. */ |
len = head->read_avail; |
2608 |
len = head->read_avail; |
if (len || head->poll || head->read_eof) |
2609 |
|
break; |
2610 |
|
len = head->readbuf_size * 2; |
2611 |
|
cp = kzalloc(len, GFP_KERNEL); |
2612 |
|
if (!cp) { |
2613 |
|
len = -ENOMEM; |
2614 |
|
goto out; |
2615 |
|
} |
2616 |
|
kfree(head->read_buf); |
2617 |
|
head->read_buf = cp; |
2618 |
|
head->readbuf_size = len; |
2619 |
|
} |
2620 |
if (len > buffer_len) |
if (len > buffer_len) |
2621 |
len = buffer_len; |
len = buffer_len; |
2622 |
if (!len) |
if (!len) |
2665 |
while (avail_len > 0) { |
while (avail_len > 0) { |
2666 |
char c; |
char c; |
2667 |
if (head->write_avail >= head->writebuf_size - 1) { |
if (head->write_avail >= head->writebuf_size - 1) { |
2668 |
error = -ENOMEM; |
const int len = head->writebuf_size * 2; |
2669 |
break; |
char *cp = kzalloc(len, GFP_KERNEL); |
2670 |
} else if (get_user(c, buffer)) { |
if (!cp) { |
2671 |
|
error = -ENOMEM; |
2672 |
|
break; |
2673 |
|
} |
2674 |
|
memmove(cp, cp0, head->write_avail); |
2675 |
|
kfree(cp0); |
2676 |
|
head->write_buf = cp; |
2677 |
|
cp0 = cp; |
2678 |
|
head->writebuf_size = len; |
2679 |
|
} |
2680 |
|
if (get_user(c, buffer)) { |
2681 |
error = -EFAULT; |
error = -EFAULT; |
2682 |
break; |
break; |
2683 |
} |
} |