3 |
* |
* |
4 |
* Copyright (C) 2005-2010 NTT DATA CORPORATION |
* Copyright (C) 2005-2010 NTT DATA CORPORATION |
5 |
* |
* |
6 |
* Version: 1.7.2 2010/04/01 |
* Version: 1.8.0-pre 2010/08/01 |
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. |
13 |
#include "internal.h" |
#include "internal.h" |
14 |
|
|
15 |
static struct ccs_profile ccs_default_profile = { |
static struct ccs_profile ccs_default_profile = { |
|
.learning = &ccs_default_profile.preference, |
|
|
.permissive = &ccs_default_profile.preference, |
|
|
.enforcing = &ccs_default_profile.preference, |
|
|
.audit = &ccs_default_profile.preference, |
|
16 |
#ifdef CONFIG_CCSECURITY_AUDIT |
#ifdef CONFIG_CCSECURITY_AUDIT |
17 |
.preference.audit_max_grant_log = CONFIG_CCSECURITY_MAX_GRANT_LOG, |
.preference.audit_max_grant_log = CONFIG_CCSECURITY_MAX_GRANT_LOG, |
18 |
.preference.audit_max_reject_log = CONFIG_CCSECURITY_MAX_REJECT_LOG, |
.preference.audit_max_reject_log = CONFIG_CCSECURITY_MAX_REJECT_LOG, |
20 |
.preference.audit_task_info = true, |
.preference.audit_task_info = true, |
21 |
.preference.audit_path_info = true, |
.preference.audit_path_info = true, |
22 |
.preference.enforcing_penalty = 0, |
.preference.enforcing_penalty = 0, |
|
.preference.enforcing_verbose = true, |
|
23 |
.preference.learning_max_entry = CONFIG_CCSECURITY_MAX_ACCEPT_ENTRY, |
.preference.learning_max_entry = CONFIG_CCSECURITY_MAX_ACCEPT_ENTRY, |
|
.preference.learning_verbose = false, |
|
24 |
.preference.learning_exec_realpath = true, |
.preference.learning_exec_realpath = true, |
25 |
.preference.learning_exec_argv0 = true, |
.preference.learning_exec_argv0 = true, |
26 |
.preference.learning_symlink_target = true, |
.preference.learning_symlink_target = true, |
|
.preference.permissive_verbose = true |
|
27 |
}; |
}; |
28 |
|
|
29 |
/* Profile version. Currently only 20090903 is defined. */ |
/* Profile version. Currently only 20090903 is defined. */ |
33 |
static struct ccs_profile *ccs_profile_ptr[CCS_MAX_PROFILES]; |
static struct ccs_profile *ccs_profile_ptr[CCS_MAX_PROFILES]; |
34 |
|
|
35 |
/* String table for functionality that takes 4 modes. */ |
/* String table for functionality that takes 4 modes. */ |
36 |
static const char *ccs_mode_4[4] = { |
const char *ccs_mode[CCS_CONFIG_MAX_MODE] = { |
37 |
"disabled", "learning", "permissive", "enforcing" |
[CCS_CONFIG_DISABLED] = "disabled", |
38 |
|
[CCS_CONFIG_LEARNING] = "learning", |
39 |
|
[CCS_CONFIG_PERMISSIVE] = "permissive", |
40 |
|
[CCS_CONFIG_ENFORCING] = "enforcing" |
41 |
}; |
}; |
42 |
|
|
43 |
/* String table for /proc/ccs/profile */ |
/* String table for /proc/ccs/profile */ |
64 |
= "file::truncate", |
= "file::truncate", |
65 |
[CCS_MAC_FILE_SYMLINK] |
[CCS_MAC_FILE_SYMLINK] |
66 |
= "file::symlink", |
= "file::symlink", |
|
[CCS_MAC_FILE_REWRITE] |
|
|
= "file::rewrite", |
|
67 |
[CCS_MAC_FILE_MKBLOCK] |
[CCS_MAC_FILE_MKBLOCK] |
68 |
= "file::mkblock", |
= "file::mkblock", |
69 |
[CCS_MAC_FILE_MKCHAR] |
[CCS_MAC_FILE_MKCHAR] |
92 |
= "file::transit", |
= "file::transit", |
93 |
[CCS_MAC_ENVIRON] |
[CCS_MAC_ENVIRON] |
94 |
= "misc::env", |
= "misc::env", |
|
[CCS_MAC_NETWORK_UDP_BIND] |
|
|
= "network::inet_udp_bind", |
|
|
[CCS_MAC_NETWORK_UDP_CONNECT] |
|
|
= "network::inet_udp_connect", |
|
95 |
[CCS_MAC_NETWORK_TCP_BIND] |
[CCS_MAC_NETWORK_TCP_BIND] |
96 |
= "network::inet_tcp_bind", |
= "network::inet_tcp_bind", |
97 |
[CCS_MAC_NETWORK_TCP_LISTEN] |
[CCS_MAC_NETWORK_TCP_LISTEN] |
100 |
= "network::inet_tcp_connect", |
= "network::inet_tcp_connect", |
101 |
[CCS_MAC_NETWORK_TCP_ACCEPT] |
[CCS_MAC_NETWORK_TCP_ACCEPT] |
102 |
= "network::inet_tcp_accept", |
= "network::inet_tcp_accept", |
103 |
|
[CCS_MAC_NETWORK_UDP_BIND] |
104 |
|
= "network::inet_udp_bind", |
105 |
|
[CCS_MAC_NETWORK_UDP_SEND] |
106 |
|
= "network::inet_udp_send", |
107 |
|
[CCS_MAC_NETWORK_UDP_RECV] |
108 |
|
= "network::inet_udp_recv", |
109 |
[CCS_MAC_NETWORK_RAW_BIND] |
[CCS_MAC_NETWORK_RAW_BIND] |
110 |
= "network::inet_raw_bind", |
= "network::inet_raw_bind", |
111 |
[CCS_MAC_NETWORK_RAW_CONNECT] |
[CCS_MAC_NETWORK_RAW_SEND] |
112 |
= "network::inet_raw_connect", |
= "network::inet_raw_send", |
113 |
|
[CCS_MAC_NETWORK_RAW_RECV] |
114 |
|
= "network::inet_raw_recv", |
115 |
[CCS_MAC_SIGNAL] |
[CCS_MAC_SIGNAL] |
116 |
= "ipc::signal", |
= "ipc::signal", |
|
[CCS_MAX_MAC_INDEX + CCS_INET_STREAM_SOCKET_CREATE] |
|
|
= "capability::inet_tcp_create", |
|
|
[CCS_MAX_MAC_INDEX + CCS_INET_STREAM_SOCKET_LISTEN] |
|
|
= "capability::inet_tcp_listen", |
|
|
[CCS_MAX_MAC_INDEX + CCS_INET_STREAM_SOCKET_CONNECT] |
|
|
= "capability::inet_tcp_connect", |
|
|
[CCS_MAX_MAC_INDEX + CCS_USE_INET_DGRAM_SOCKET] |
|
|
= "capability::use_inet_udp", |
|
|
[CCS_MAX_MAC_INDEX + CCS_USE_INET_RAW_SOCKET] |
|
|
= "capability::use_inet_ip", |
|
117 |
[CCS_MAX_MAC_INDEX + CCS_USE_ROUTE_SOCKET] |
[CCS_MAX_MAC_INDEX + CCS_USE_ROUTE_SOCKET] |
118 |
= "capability::use_route", |
= "capability::use_route", |
119 |
[CCS_MAX_MAC_INDEX + CCS_USE_PACKET_SOCKET] |
[CCS_MAX_MAC_INDEX + CCS_USE_PACKET_SOCKET] |
120 |
= "capability::use_packet", |
= "capability::use_packet", |
|
[CCS_MAX_MAC_INDEX + CCS_SYS_MOUNT] |
|
|
= "capability::SYS_MOUNT", |
|
|
[CCS_MAX_MAC_INDEX + CCS_SYS_UMOUNT] |
|
|
= "capability::SYS_UMOUNT", |
|
121 |
[CCS_MAX_MAC_INDEX + CCS_SYS_REBOOT] |
[CCS_MAX_MAC_INDEX + CCS_SYS_REBOOT] |
122 |
= "capability::SYS_REBOOT", |
= "capability::SYS_REBOOT", |
|
[CCS_MAX_MAC_INDEX + CCS_SYS_CHROOT] |
|
|
= "capability::SYS_CHROOT", |
|
|
[CCS_MAX_MAC_INDEX + CCS_SYS_KILL] |
|
|
= "capability::SYS_KILL", |
|
123 |
[CCS_MAX_MAC_INDEX + CCS_SYS_VHANGUP] |
[CCS_MAX_MAC_INDEX + CCS_SYS_VHANGUP] |
124 |
= "capability::SYS_VHANGUP", |
= "capability::SYS_VHANGUP", |
125 |
[CCS_MAX_MAC_INDEX + CCS_SYS_SETTIME] |
[CCS_MAX_MAC_INDEX + CCS_SYS_SETTIME] |
130 |
= "capability::SYS_SETHOSTNAME", |
= "capability::SYS_SETHOSTNAME", |
131 |
[CCS_MAX_MAC_INDEX + CCS_USE_KERNEL_MODULE] |
[CCS_MAX_MAC_INDEX + CCS_USE_KERNEL_MODULE] |
132 |
= "capability::use_kernel_module", |
= "capability::use_kernel_module", |
|
[CCS_MAX_MAC_INDEX + CCS_CREATE_FIFO] |
|
|
= "capability::create_fifo", |
|
|
[CCS_MAX_MAC_INDEX + CCS_CREATE_BLOCK_DEV] |
|
|
= "capability::create_block_dev", |
|
|
[CCS_MAX_MAC_INDEX + CCS_CREATE_CHAR_DEV] |
|
|
= "capability::create_char_dev", |
|
|
[CCS_MAX_MAC_INDEX + CCS_CREATE_UNIX_SOCKET] |
|
|
= "capability::create_unix_socket", |
|
|
[CCS_MAX_MAC_INDEX + CCS_SYS_LINK] |
|
|
= "capability::SYS_LINK", |
|
|
[CCS_MAX_MAC_INDEX + CCS_SYS_SYMLINK] |
|
|
= "capability::SYS_SYMLINK", |
|
|
[CCS_MAX_MAC_INDEX + CCS_SYS_RENAME] |
|
|
= "capability::SYS_RENAME", |
|
|
[CCS_MAX_MAC_INDEX + CCS_SYS_UNLINK] |
|
|
= "capability::SYS_UNLINK", |
|
|
[CCS_MAX_MAC_INDEX + CCS_SYS_CHMOD] |
|
|
= "capability::SYS_CHMOD", |
|
|
[CCS_MAX_MAC_INDEX + CCS_SYS_CHOWN] |
|
|
= "capability::SYS_CHOWN", |
|
|
[CCS_MAX_MAC_INDEX + CCS_SYS_IOCTL] |
|
|
= "capability::SYS_IOCTL", |
|
133 |
[CCS_MAX_MAC_INDEX + CCS_SYS_KEXEC_LOAD] |
[CCS_MAX_MAC_INDEX + CCS_SYS_KEXEC_LOAD] |
134 |
= "capability::SYS_KEXEC_LOAD", |
= "capability::SYS_KEXEC_LOAD", |
|
[CCS_MAX_MAC_INDEX + CCS_SYS_PIVOT_ROOT] |
|
|
= "capability::SYS_PIVOT_ROOT", |
|
135 |
[CCS_MAX_MAC_INDEX + CCS_SYS_PTRACE] |
[CCS_MAX_MAC_INDEX + CCS_SYS_PTRACE] |
136 |
= "capability::SYS_PTRACE", |
= "capability::SYS_PTRACE", |
|
[CCS_MAX_MAC_INDEX + CCS_CONCEAL_MOUNT] |
|
|
= "capability::conceal_mount", |
|
137 |
[CCS_MAX_MAC_INDEX + CCS_MAX_CAPABILITY_INDEX |
[CCS_MAX_MAC_INDEX + CCS_MAX_CAPABILITY_INDEX |
138 |
+ CCS_MAC_CATEGORY_FILE] = "file", |
+ CCS_MAC_CATEGORY_FILE] = "file", |
139 |
[CCS_MAX_MAC_INDEX + CCS_MAX_CAPABILITY_INDEX |
[CCS_MAX_MAC_INDEX + CCS_MAX_CAPABILITY_INDEX |
172 |
return value ? "yes" : "no"; |
return value ? "yes" : "no"; |
173 |
} |
} |
174 |
|
|
175 |
|
static void ccs_addprintf(char *buffer, int len, const char *fmt, ...) |
176 |
|
{ |
177 |
|
va_list args; |
178 |
|
const int pos = strlen(buffer); |
179 |
|
va_start(args, fmt); |
180 |
|
vsnprintf(buffer + pos, len - pos - 1, fmt, args); |
181 |
|
va_end(args); |
182 |
|
} |
183 |
|
|
184 |
/** |
/** |
185 |
* ccs_io_printf - Transactional printf() to "struct ccs_io_buffer" structure. |
* ccs_flush - Flush queued string to userspace's buffer. |
186 |
* |
* |
187 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
|
* @fmt: The printf()'s format string, followed by parameters. |
|
188 |
* |
* |
189 |
* Returns true on success, false otherwise. |
* Returns true if all data was flushed, false otherwise. |
190 |
|
*/ |
191 |
|
static bool ccs_flush(struct ccs_io_buffer *head) |
192 |
|
{ |
193 |
|
while (head->r.w_pos) { |
194 |
|
const char *w = head->r.w[0]; |
195 |
|
int len = strlen(w); |
196 |
|
if (len) { |
197 |
|
if (len > head->read_user_buf_avail) |
198 |
|
len = head->read_user_buf_avail; |
199 |
|
if (!len) |
200 |
|
return false; |
201 |
|
if (copy_to_user(head->read_user_buf, w, len)) |
202 |
|
return false; |
203 |
|
head->read_user_buf_avail -= len; |
204 |
|
head->read_user_buf += len; |
205 |
|
w += len; |
206 |
|
} |
207 |
|
if (*w) { |
208 |
|
head->r.w[0] = w; |
209 |
|
return false; |
210 |
|
} |
211 |
|
/* Add '\0' for audit logs and query. */ |
212 |
|
if (head->poll) { |
213 |
|
if (!head->read_user_buf_avail || |
214 |
|
copy_to_user(head->read_user_buf, "", 1)) |
215 |
|
return false; |
216 |
|
head->read_user_buf_avail--; |
217 |
|
head->read_user_buf++; |
218 |
|
} |
219 |
|
head->r.w_pos--; |
220 |
|
for (len = 0; len < head->r.w_pos; len++) |
221 |
|
head->r.w[len] = head->r.w[len + 1]; |
222 |
|
} |
223 |
|
head->r.avail = 0; |
224 |
|
return true; |
225 |
|
} |
226 |
|
|
227 |
|
/** |
228 |
|
* ccs_set_string - Queue string to "struct ccs_io_buffer" structure. |
229 |
|
* |
230 |
|
* @head: Pointer to "struct ccs_io_buffer". |
231 |
|
* @string: String to print. |
232 |
* |
* |
233 |
* The snprintf() will truncate, but ccs_io_printf() won't. |
* Note that @string has to be kept valid until @head is kfree()d. |
234 |
|
* This means that char[] allocated on stack memory cannot be passed to |
235 |
|
* this function. Use ccs_io_printf() for char[] allocated on stack memory. |
236 |
|
*/ |
237 |
|
static void ccs_set_string(struct ccs_io_buffer *head, const char *string) |
238 |
|
{ |
239 |
|
if (head->r.w_pos < CCS_MAX_IO_READ_QUEUE) { |
240 |
|
head->r.w[head->r.w_pos++] = string; |
241 |
|
ccs_flush(head); |
242 |
|
} else |
243 |
|
printk(KERN_WARNING "Too many words in a line.\n"); |
244 |
|
} |
245 |
|
|
246 |
|
/** |
247 |
|
* ccs_io_printf - printf() to "struct ccs_io_buffer" structure. |
248 |
|
* |
249 |
|
* @head: Pointer to "struct ccs_io_buffer". |
250 |
|
* @fmt: The printf()'s format string, followed by parameters. |
251 |
*/ |
*/ |
252 |
bool ccs_io_printf(struct ccs_io_buffer *head, const char *fmt, ...) |
void ccs_io_printf(struct ccs_io_buffer *head, const char *fmt, ...) |
253 |
{ |
{ |
254 |
va_list args; |
va_list args; |
255 |
int len; |
int len; |
256 |
int pos = head->read_avail; |
int pos = head->r.avail; |
257 |
int size = head->readbuf_size - pos; |
int size = head->readbuf_size - pos; |
258 |
if (size <= 0) |
if (size <= 0) |
259 |
return false; |
return; |
260 |
va_start(args, fmt); |
va_start(args, fmt); |
261 |
len = vsnprintf(head->read_buf + pos, size, fmt, args); |
len = vsnprintf(head->read_buf + pos, size, fmt, args) + 1; |
262 |
va_end(args); |
va_end(args); |
263 |
if (pos + len >= head->readbuf_size) |
if (pos + len >= head->readbuf_size) { |
264 |
return false; |
printk(KERN_WARNING "Too many words in a line.\n"); |
265 |
head->read_avail += len; |
return; |
266 |
return true; |
} |
267 |
|
head->r.avail += len; |
268 |
|
ccs_set_string(head, head->read_buf + pos); |
269 |
|
} |
270 |
|
|
271 |
|
static void ccs_set_space(struct ccs_io_buffer *head) |
272 |
|
{ |
273 |
|
ccs_set_string(head, " "); |
274 |
|
} |
275 |
|
|
276 |
|
static bool ccs_set_lf(struct ccs_io_buffer *head) |
277 |
|
{ |
278 |
|
ccs_set_string(head, "\n"); |
279 |
|
return !head->r.w_pos; |
280 |
} |
} |
281 |
|
|
282 |
/** |
/** |
283 |
* ccs_find_or_assign_new_profile - Create a new profile. |
* ccs_assign_profile - Create a new profile. |
284 |
* |
* |
285 |
* @profile: Profile number to create. |
* @profile: Profile number to create. |
286 |
* |
* |
287 |
* Returns pointer to "struct ccs_profile" on success, NULL otherwise. |
* Returns pointer to "struct ccs_profile" on success, NULL otherwise. |
288 |
*/ |
*/ |
289 |
static struct ccs_profile *ccs_find_or_assign_new_profile(const unsigned int |
static struct ccs_profile *ccs_assign_profile(const unsigned int profile) |
|
profile) |
|
290 |
{ |
{ |
291 |
struct ccs_profile *ptr; |
struct ccs_profile *ptr; |
292 |
struct ccs_profile *entry; |
struct ccs_profile *entry; |
301 |
ptr = ccs_profile_ptr[profile]; |
ptr = ccs_profile_ptr[profile]; |
302 |
if (!ptr && ccs_memory_ok(entry, sizeof(*entry))) { |
if (!ptr && ccs_memory_ok(entry, sizeof(*entry))) { |
303 |
ptr = entry; |
ptr = entry; |
|
ptr->audit = &ccs_default_profile.preference; |
|
|
ptr->learning = &ccs_default_profile.preference; |
|
|
ptr->permissive = &ccs_default_profile.preference; |
|
|
ptr->enforcing = &ccs_default_profile.preference; |
|
304 |
ptr->default_config = CCS_CONFIG_DISABLED | |
ptr->default_config = CCS_CONFIG_DISABLED | |
305 |
|
CCS_CONFIG_VERBOSE | |
306 |
CCS_CONFIG_WANT_GRANT_LOG | CCS_CONFIG_WANT_REJECT_LOG; |
CCS_CONFIG_WANT_GRANT_LOG | CCS_CONFIG_WANT_REJECT_LOG; |
307 |
memset(ptr->config, CCS_CONFIG_USE_DEFAULT, |
memset(ptr->config, CCS_CONFIG_USE_DEFAULT, |
308 |
sizeof(ptr->config)); |
sizeof(ptr->config)); |
335 |
if (ccs_profile_version != 20090903) |
if (ccs_profile_version != 20090903) |
336 |
panic("Profile version %u is not supported.\n", |
panic("Profile version %u is not supported.\n", |
337 |
ccs_profile_version); |
ccs_profile_version); |
338 |
printk(KERN_INFO "CCSecurity: 1.7.2 2010/04/01\n"); |
printk(KERN_INFO "CCSecurity: 1.8.0-pre 2010/08/01\n"); |
339 |
printk(KERN_INFO "Mandatory Access Control activated.\n"); |
printk(KERN_INFO "Mandatory Access Control activated.\n"); |
340 |
} |
} |
341 |
|
|
355 |
return ptr; |
return ptr; |
356 |
} |
} |
357 |
|
|
358 |
/** |
static s8 ccs_find_yesno(const char *string, const char *find) |
|
* ccs_write_profile - Write profile table. |
|
|
* |
|
|
* @head: Pointer to "struct ccs_io_buffer". |
|
|
* |
|
|
* Returns 0 on success, negative value otherwise. |
|
|
*/ |
|
|
static int ccs_write_profile(struct ccs_io_buffer *head) |
|
359 |
{ |
{ |
360 |
char *data = head->write_buf; |
const char *cp = strstr(string, find); |
361 |
unsigned int i; |
if (cp) { |
362 |
int value; |
cp += strlen(find); |
363 |
int mode; |
if (!strncmp(cp, "=yes", 4)) |
364 |
u8 config; |
return 1; |
365 |
bool use_default = false; |
else if (!strncmp(cp, "=no", 3)) |
|
char *cp; |
|
|
struct ccs_profile *profile; |
|
|
if (sscanf(data, "PROFILE_VERSION=%u", &ccs_profile_version) == 1) |
|
|
return 0; |
|
|
i = simple_strtoul(data, &cp, 10); |
|
|
if (data == cp) { |
|
|
profile = &ccs_default_profile; |
|
|
} else { |
|
|
if (*cp != '-') |
|
|
return -EINVAL; |
|
|
data = cp + 1; |
|
|
profile = ccs_find_or_assign_new_profile(i); |
|
|
if (!profile) |
|
|
return -EINVAL; |
|
|
} |
|
|
cp = strchr(data, '='); |
|
|
if (!cp) |
|
|
return -EINVAL; |
|
|
*cp++ = '\0'; |
|
|
if (profile != &ccs_default_profile) |
|
|
use_default = strstr(cp, "use_default") != NULL; |
|
|
if (strstr(cp, "verbose=yes")) |
|
|
value = 1; |
|
|
else if (strstr(cp, "verbose=no")) |
|
|
value = 0; |
|
|
else |
|
|
value = -1; |
|
|
if (!strcmp(data, CCS_KEYWORD_PREFERENCE_AUDIT)) { |
|
|
#ifdef CONFIG_CCSECURITY_AUDIT |
|
|
char *cp2; |
|
|
#endif |
|
|
if (use_default) { |
|
|
profile->audit = &ccs_default_profile.preference; |
|
366 |
return 0; |
return 0; |
|
} |
|
|
profile->audit = &profile->preference; |
|
|
#ifdef CONFIG_CCSECURITY_AUDIT |
|
|
cp2 = strstr(cp, "max_grant_log="); |
|
|
if (cp2) |
|
|
sscanf(cp2 + 14, "%u", |
|
|
&profile->preference.audit_max_grant_log); |
|
|
cp2 = strstr(cp, "max_reject_log="); |
|
|
if (cp2) |
|
|
sscanf(cp2 + 15, "%u", |
|
|
&profile->preference.audit_max_reject_log); |
|
|
#endif |
|
|
if (strstr(cp, "task_info=yes")) |
|
|
profile->preference.audit_task_info = true; |
|
|
else if (strstr(cp, "task_info=no")) |
|
|
profile->preference.audit_task_info = false; |
|
|
if (strstr(cp, "path_info=yes")) |
|
|
profile->preference.audit_path_info = true; |
|
|
else if (strstr(cp, "path_info=no")) |
|
|
profile->preference.audit_path_info = false; |
|
|
return 0; |
|
367 |
} |
} |
368 |
if (!strcmp(data, CCS_KEYWORD_PREFERENCE_ENFORCING)) { |
return -1; |
369 |
char *cp2; |
} |
370 |
if (use_default) { |
|
371 |
profile->enforcing = &ccs_default_profile.preference; |
static void ccs_set_bool(bool *b, const char *string, const char *find) |
372 |
return 0; |
{ |
373 |
} |
switch (ccs_find_yesno(string, find)) { |
374 |
profile->enforcing = &profile->preference; |
case 1: |
375 |
if (value >= 0) |
*b = true; |
376 |
profile->preference.enforcing_verbose = value; |
break; |
377 |
cp2 = strstr(cp, "penalty="); |
case 0: |
378 |
if (cp2) |
*b = false; |
379 |
sscanf(cp2 + 8, "%u", |
break; |
|
&profile->preference.enforcing_penalty); |
|
|
return 0; |
|
380 |
} |
} |
381 |
if (!strcmp(data, CCS_KEYWORD_PREFERENCE_PERMISSIVE)) { |
} |
382 |
if (use_default) { |
|
383 |
profile->permissive = &ccs_default_profile.preference; |
static void ccs_set_uint(unsigned int *i, const char *string, const char *find) |
384 |
return 0; |
{ |
385 |
} |
const char *cp = strstr(string, find); |
386 |
profile->permissive = &profile->preference; |
if (cp) |
387 |
if (value >= 0) |
sscanf(cp + strlen(find), "=%u", i); |
388 |
profile->preference.permissive_verbose = value; |
} |
389 |
return 0; |
|
390 |
|
static void ccs_set_pref(const char *name, const char *value, |
391 |
|
struct ccs_profile *profile) |
392 |
|
{ |
393 |
|
if (!strcmp(name, "audit")) { |
394 |
|
#ifdef CONFIG_CCSECURITY_AUDIT |
395 |
|
ccs_set_uint(&profile->preference.audit_max_grant_log, value, |
396 |
|
"max_grant_log"); |
397 |
|
ccs_set_uint(&profile->preference.audit_max_reject_log, value, |
398 |
|
"max_reject_log"); |
399 |
|
#endif |
400 |
|
ccs_set_bool(&profile->preference.audit_task_info, value, |
401 |
|
"task_info"); |
402 |
|
ccs_set_bool(&profile->preference.audit_path_info, value, |
403 |
|
"path_info"); |
404 |
|
return; |
405 |
} |
} |
406 |
if (!strcmp(data, CCS_KEYWORD_PREFERENCE_LEARNING)) { |
if (!strcmp(name, "enforcing")) { |
407 |
char *cp2; |
ccs_set_uint(&profile->preference.enforcing_penalty, value, |
408 |
if (use_default) { |
"penalty"); |
409 |
profile->learning = &ccs_default_profile.preference; |
return; |
|
return 0; |
|
|
} |
|
|
profile->learning = &profile->preference; |
|
|
if (value >= 0) |
|
|
profile->preference.learning_verbose = value; |
|
|
cp2 = strstr(cp, "max_entry="); |
|
|
if (cp2) |
|
|
sscanf(cp2 + 10, "%u", |
|
|
&profile->preference.learning_max_entry); |
|
|
if (strstr(cp, "exec.realpath=yes")) |
|
|
profile->preference.learning_exec_realpath = true; |
|
|
else if (strstr(cp, "exec.realpath=no")) |
|
|
profile->preference.learning_exec_realpath = false; |
|
|
if (strstr(cp, "exec.argv0=yes")) |
|
|
profile->preference.learning_exec_argv0 = true; |
|
|
else if (strstr(cp, "exec.argv0=no")) |
|
|
profile->preference.learning_exec_argv0 = false; |
|
|
if (strstr(cp, "symlink.target=yes")) |
|
|
profile->preference.learning_symlink_target = true; |
|
|
else if (strstr(cp, "symlink.target=no")) |
|
|
profile->preference.learning_symlink_target = false; |
|
|
return 0; |
|
410 |
} |
} |
411 |
if (profile == &ccs_default_profile) |
if (!strcmp(name, "learning")) { |
412 |
return -EINVAL; |
ccs_set_uint(&profile->preference.learning_max_entry, value, |
413 |
if (!strcmp(data, "COMMENT")) { |
"max_entry"); |
414 |
const struct ccs_path_info *old_comment = profile->comment; |
ccs_set_bool(&profile->preference.learning_exec_realpath, |
415 |
profile->comment = ccs_get_name(cp); |
value, "exec.realpath"); |
416 |
ccs_put_name(old_comment); |
ccs_set_bool(&profile->preference.learning_exec_argv0, value, |
417 |
return 0; |
"exec.argv0"); |
418 |
|
ccs_set_bool(&profile->preference.learning_symlink_target, |
419 |
|
value, "symlink.target"); |
420 |
|
return; |
421 |
} |
} |
422 |
if (!strcmp(data, "CONFIG")) { |
} |
423 |
|
|
424 |
|
static int ccs_set_mode(char *name, const char *value, |
425 |
|
struct ccs_profile *profile) |
426 |
|
{ |
427 |
|
u8 i; |
428 |
|
u8 config; |
429 |
|
if (!strcmp(name, "CONFIG")) { |
430 |
i = CCS_MAX_MAC_INDEX + CCS_MAX_CAPABILITY_INDEX |
i = CCS_MAX_MAC_INDEX + CCS_MAX_CAPABILITY_INDEX |
431 |
+ CCS_MAX_MAC_CATEGORY_INDEX; |
+ CCS_MAX_MAC_CATEGORY_INDEX; |
432 |
config = profile->default_config; |
config = profile->default_config; |
433 |
} else if (ccs_str_starts(&data, "CONFIG::")) { |
} else if (ccs_str_starts(&name, "CONFIG::")) { |
434 |
config = 0; |
config = 0; |
435 |
for (i = 0; i < CCS_MAX_MAC_INDEX + CCS_MAX_CAPABILITY_INDEX |
for (i = 0; i < CCS_MAX_MAC_INDEX + CCS_MAX_CAPABILITY_INDEX |
436 |
+ CCS_MAX_MAC_CATEGORY_INDEX; i++) { |
+ CCS_MAX_MAC_CATEGORY_INDEX; i++) { |
437 |
if (strcmp(data, ccs_mac_keywords[i])) |
if (strcmp(name, ccs_mac_keywords[i])) |
438 |
continue; |
continue; |
439 |
config = profile->config[i]; |
config = profile->config[i]; |
440 |
break; |
break; |
445 |
} else { |
} else { |
446 |
return -EINVAL; |
return -EINVAL; |
447 |
} |
} |
448 |
if (use_default) { |
if (strstr(value, "use_default")) { |
449 |
config = CCS_CONFIG_USE_DEFAULT; |
config = CCS_CONFIG_USE_DEFAULT; |
450 |
} else { |
} else { |
451 |
for (mode = 3; mode >= 0; mode--) |
u8 mode; |
452 |
if (strstr(cp, ccs_mode_4[mode])) |
for (mode = 0; mode < CCS_CONFIG_MAX_MODE; mode++) |
453 |
|
if (strstr(value, ccs_mode[mode])) |
454 |
/* |
/* |
455 |
* Update lower 3 bits in order to distinguish |
* Update lower 3 bits in order to distinguish |
456 |
* 'config' from 'CCS_CONFIG_USE_DEAFULT'. |
* 'config' from 'CCS_CONFIG_USE_DEAFULT'. |
457 |
*/ |
*/ |
458 |
config = (config & ~7) | mode; |
config = (config & ~7) | mode; |
|
#ifdef CONFIG_CCSECURITY_AUDIT |
|
459 |
if (config != CCS_CONFIG_USE_DEFAULT) { |
if (config != CCS_CONFIG_USE_DEFAULT) { |
460 |
if (strstr(cp, "grant_log=yes")) |
switch (ccs_find_yesno(value, "verbose")) { |
461 |
|
case 1: |
462 |
|
config |= CCS_CONFIG_VERBOSE; |
463 |
|
break; |
464 |
|
case 0: |
465 |
|
config &= ~CCS_CONFIG_VERBOSE; |
466 |
|
break; |
467 |
|
} |
468 |
|
#ifdef CONFIG_CCSECURITY_AUDIT |
469 |
|
switch (ccs_find_yesno(value, "grant_log")) { |
470 |
|
case 1: |
471 |
config |= CCS_CONFIG_WANT_GRANT_LOG; |
config |= CCS_CONFIG_WANT_GRANT_LOG; |
472 |
else if (strstr(cp, "grant_log=no")) |
break; |
473 |
|
case 0: |
474 |
config &= ~CCS_CONFIG_WANT_GRANT_LOG; |
config &= ~CCS_CONFIG_WANT_GRANT_LOG; |
475 |
if (strstr(cp, "reject_log=yes")) |
break; |
476 |
|
} |
477 |
|
switch (ccs_find_yesno(value, "reject_log")) { |
478 |
|
case 1: |
479 |
config |= CCS_CONFIG_WANT_REJECT_LOG; |
config |= CCS_CONFIG_WANT_REJECT_LOG; |
480 |
else if (strstr(cp, "reject_log=no")) |
break; |
481 |
|
case 0: |
482 |
config &= ~CCS_CONFIG_WANT_REJECT_LOG; |
config &= ~CCS_CONFIG_WANT_REJECT_LOG; |
483 |
} |
break; |
484 |
|
} |
485 |
#endif |
#endif |
486 |
|
} |
487 |
} |
} |
488 |
if (i < CCS_MAX_MAC_INDEX + CCS_MAX_CAPABILITY_INDEX |
if (i < CCS_MAX_MAC_INDEX + CCS_MAX_CAPABILITY_INDEX |
489 |
+ CCS_MAX_MAC_CATEGORY_INDEX) |
+ CCS_MAX_MAC_CATEGORY_INDEX) |
493 |
return 0; |
return 0; |
494 |
} |
} |
495 |
|
|
496 |
static bool ccs_print_preference(struct ccs_io_buffer *head, const int idx) |
/** |
497 |
|
* ccs_write_profile - Write profile table. |
498 |
|
* |
499 |
|
* @head: Pointer to "struct ccs_io_buffer". |
500 |
|
* |
501 |
|
* Returns 0 on success, negative value otherwise. |
502 |
|
*/ |
503 |
|
static int ccs_write_profile(struct ccs_io_buffer *head) |
504 |
{ |
{ |
505 |
struct ccs_preference *pref = &ccs_default_profile.preference; |
char *data = head->write_buf; |
506 |
const struct ccs_profile *profile = idx >= 0 ? |
unsigned int i; |
507 |
ccs_profile_ptr[idx] : NULL; |
char *cp; |
508 |
char buffer[16] = ""; |
struct ccs_profile *profile; |
509 |
if (profile) { |
if (sscanf(data, "PROFILE_VERSION=%u", &ccs_profile_version) == 1) |
510 |
buffer[sizeof(buffer) - 1] = '\0'; |
return 0; |
511 |
snprintf(buffer, sizeof(buffer) - 1, "%u-", idx); |
i = simple_strtoul(data, &cp, 10); |
512 |
} |
if (*cp != '-') |
513 |
if (profile) { |
return -EINVAL; |
514 |
pref = profile->audit; |
data = cp + 1; |
515 |
if (pref == &ccs_default_profile.preference) |
profile = ccs_assign_profile(i); |
516 |
pref = NULL; |
if (!profile) |
517 |
|
return -EINVAL; |
518 |
|
cp = strchr(data, '='); |
519 |
|
if (!cp) |
520 |
|
return -EINVAL; |
521 |
|
*cp++ = '\0'; |
522 |
|
if (ccs_str_starts(&data, "PREFERENCE::")) { |
523 |
|
ccs_set_pref(data, cp, profile); |
524 |
|
return 0; |
525 |
} |
} |
526 |
if (pref && !ccs_io_printf(head, "%s%s={ " |
if (!strcmp(data, "COMMENT")) { |
527 |
|
const struct ccs_path_info *old_comment = profile->comment; |
528 |
|
profile->comment = ccs_get_name(cp); |
529 |
|
ccs_put_name(old_comment); |
530 |
|
return 0; |
531 |
|
} |
532 |
|
return ccs_set_mode(data, cp, profile); |
533 |
|
} |
534 |
|
|
535 |
|
static void ccs_print_preference(struct ccs_io_buffer *head, const int index) |
536 |
|
{ |
537 |
|
struct ccs_profile *profile = ccs_profile_ptr[index]; |
538 |
|
struct ccs_preference *pref = &profile->preference; |
539 |
|
ccs_io_printf(head, "%u-PREFERENCE::%s={ " |
540 |
#ifdef CONFIG_CCSECURITY_AUDIT |
#ifdef CONFIG_CCSECURITY_AUDIT |
541 |
"max_grant_log=%u max_reject_log=%u " |
"max_grant_log=%u max_reject_log=%u " |
542 |
#endif |
#endif |
543 |
"task_info=%s path_info=%s }\n", buffer, |
"task_info=%s path_info=%s }\n", index, |
544 |
CCS_KEYWORD_PREFERENCE_AUDIT, |
"audit", |
545 |
#ifdef CONFIG_CCSECURITY_AUDIT |
#ifdef CONFIG_CCSECURITY_AUDIT |
546 |
pref->audit_max_grant_log, |
pref->audit_max_grant_log, |
547 |
pref->audit_max_reject_log, |
pref->audit_max_reject_log, |
548 |
#endif |
#endif |
549 |
ccs_yesno(pref->audit_task_info), |
ccs_yesno(pref->audit_task_info), |
550 |
ccs_yesno(pref->audit_path_info))) |
ccs_yesno(pref->audit_path_info)); |
551 |
return false; |
ccs_io_printf(head, "%u-PREFERENCE::%s={ " |
552 |
if (profile) { |
"max_entry=%u exec.realpath=%s " |
553 |
pref = profile->learning; |
"exec.argv0=%s symlink.target=%s }\n", |
554 |
if (pref == &ccs_default_profile.preference) |
index, "learning", |
555 |
pref = NULL; |
pref->learning_max_entry, |
556 |
} |
ccs_yesno(pref->learning_exec_realpath), |
557 |
if (pref && !ccs_io_printf(head, "%s%s={ " |
ccs_yesno(pref->learning_exec_argv0), |
558 |
"verbose=%s max_entry=%u exec.realpath=%s " |
ccs_yesno(pref->learning_symlink_target)); |
559 |
"exec.argv0=%s symlink.target=%s }\n", |
ccs_io_printf(head, "%u-PREFERENCE::%s={ penalty=%u }\n", index, |
560 |
buffer, CCS_KEYWORD_PREFERENCE_LEARNING, |
"enforcing", pref->enforcing_penalty); |
561 |
ccs_yesno(pref->learning_verbose), |
} |
562 |
pref->learning_max_entry, |
|
563 |
ccs_yesno(pref->learning_exec_realpath), |
static void ccs_print_config(struct ccs_io_buffer *head, const u8 config) |
564 |
ccs_yesno(pref->learning_exec_argv0), |
{ |
565 |
ccs_yesno(pref->learning_symlink_target))) |
ccs_io_printf(head, "={ mode=%s verbose=%s", ccs_mode[config & 3], |
566 |
return false; |
ccs_yesno(config & CCS_CONFIG_VERBOSE)); |
567 |
if (profile) { |
#ifdef CONFIG_CCSECURITY_AUDIT |
568 |
pref = profile->permissive; |
ccs_io_printf(head, " grant_log=%s reject_log=%s", |
569 |
if (pref == &ccs_default_profile.preference) |
ccs_yesno(config & CCS_CONFIG_WANT_GRANT_LOG), |
570 |
pref = NULL; |
ccs_yesno(config & CCS_CONFIG_WANT_REJECT_LOG)); |
571 |
} |
#endif |
572 |
if (pref && !ccs_io_printf(head, "%s%s={ verbose=%s }\n", buffer, |
ccs_set_string(head, " }\n"); |
|
CCS_KEYWORD_PREFERENCE_PERMISSIVE, |
|
|
ccs_yesno(pref->permissive_verbose))) |
|
|
return false; |
|
|
if (profile) { |
|
|
pref = profile->enforcing; |
|
|
if (pref == &ccs_default_profile.preference) |
|
|
pref = NULL; |
|
|
} |
|
|
return !pref || ccs_io_printf(head, "%s%s={ verbose=%s penalty=%u }\n", |
|
|
buffer, CCS_KEYWORD_PREFERENCE_ENFORCING, |
|
|
ccs_yesno(pref->enforcing_verbose), |
|
|
pref->enforcing_penalty); |
|
573 |
} |
} |
574 |
|
|
575 |
/** |
/** |
579 |
*/ |
*/ |
580 |
static void ccs_read_profile(struct ccs_io_buffer *head) |
static void ccs_read_profile(struct ccs_io_buffer *head) |
581 |
{ |
{ |
582 |
int index; |
u8 index; |
583 |
if (head->read_eof) |
const struct ccs_profile *profile; |
584 |
return; |
next: |
585 |
if (head->read_bit) |
index = head->r.index; |
586 |
goto body; |
profile = ccs_profile_ptr[index]; |
587 |
ccs_io_printf(head, "PROFILE_VERSION=%s\n", "20090903"); |
switch (head->r.step) { |
588 |
ccs_print_preference(head, -1); |
case 0: |
589 |
head->read_bit = 1; |
ccs_io_printf(head, "PROFILE_VERSION=%s\n", "20090903"); |
590 |
body: |
head->r.step++; |
591 |
for (index = head->read_step; index < CCS_MAX_PROFILES; index++) { |
break; |
592 |
bool done; |
case 1: |
593 |
u8 config; |
for ( ; head->r.index < CCS_MAX_PROFILES; |
594 |
int i; |
head->r.index++) |
595 |
int pos; |
if (ccs_profile_ptr[head->r.index]) |
596 |
const struct ccs_profile *profile = ccs_profile_ptr[index]; |
break; |
597 |
const struct ccs_path_info *comment; |
if (head->r.index == CCS_MAX_PROFILES) |
598 |
head->read_step = index; |
return; |
599 |
if (!profile) |
head->r.step++; |
600 |
continue; |
break; |
601 |
pos = head->read_avail; |
case 2: |
602 |
comment = profile->comment; |
{ |
603 |
done = ccs_io_printf(head, "%u-COMMENT=%s\n", index, |
const struct ccs_path_info *comment = profile->comment; |
604 |
comment ? comment->name : ""); |
ccs_io_printf(head, "%u-COMMENT=", index); |
605 |
if (!done) |
ccs_set_string(head, comment ? comment->name : ""); |
606 |
goto out; |
ccs_set_lf(head); |
607 |
config = profile->default_config; |
head->r.step++; |
608 |
#ifdef CONFIG_CCSECURITY_AUDIT |
} |
609 |
if (!ccs_io_printf(head, "%u-%s%s={ mode=%s " |
break; |
610 |
"grant_log=%s reject_log=%s }\n", index, |
case 3: |
611 |
"CONFIG", "", ccs_mode_4[config & 3], |
{ |
612 |
ccs_yesno(config & |
ccs_io_printf(head, "%u-%s", index, "CONFIG"); |
613 |
CCS_CONFIG_WANT_GRANT_LOG), |
ccs_print_config(head, profile->default_config); |
614 |
ccs_yesno(config & |
head->r.bit = 0; |
615 |
CCS_CONFIG_WANT_REJECT_LOG))) |
head->r.step++; |
616 |
goto out; |
} |
617 |
#else |
break; |
618 |
if (!ccs_io_printf(head, "%u-%s%s={ mode=%s }\n", index, |
case 4: |
619 |
"CONFIG", "", ccs_mode_4[config & 3])) |
for ( ; head->r.bit < CCS_MAX_MAC_INDEX |
620 |
goto out; |
+ CCS_MAX_CAPABILITY_INDEX |
621 |
#endif |
+ CCS_MAX_MAC_CATEGORY_INDEX; head->r.bit++) { |
622 |
for (i = 0; i < CCS_MAX_MAC_INDEX + CCS_MAX_CAPABILITY_INDEX |
const u8 i = head->r.bit; |
623 |
+ CCS_MAX_MAC_CATEGORY_INDEX; i++) { |
const u8 config = profile->config[i]; |
|
#ifdef CONFIG_CCSECURITY_AUDIT |
|
|
const char *g; |
|
|
const char *r; |
|
|
#endif |
|
|
config = profile->config[i]; |
|
624 |
if (config == CCS_CONFIG_USE_DEFAULT) |
if (config == CCS_CONFIG_USE_DEFAULT) |
625 |
continue; |
continue; |
626 |
#ifdef CONFIG_CCSECURITY_AUDIT |
ccs_io_printf(head, "%u-%s%s", index, "CONFIG::", |
627 |
g = ccs_yesno(config & CCS_CONFIG_WANT_GRANT_LOG); |
ccs_mac_keywords[i]); |
628 |
r = ccs_yesno(config & CCS_CONFIG_WANT_REJECT_LOG); |
ccs_print_config(head, config); |
629 |
if (!ccs_io_printf(head, "%u-%s%s={ mode=%s " |
head->r.bit++; |
630 |
"grant_log=%s reject_log=%s }\n", |
break; |
631 |
index, "CONFIG::", |
} |
632 |
ccs_mac_keywords[i], |
if (head->r.bit == CCS_MAX_MAC_INDEX |
633 |
ccs_mode_4[config & 3], g, r)) |
+ CCS_MAX_CAPABILITY_INDEX |
634 |
goto out; |
+ CCS_MAX_MAC_CATEGORY_INDEX) { |
635 |
#else |
ccs_print_preference(head, index); |
636 |
if (!ccs_io_printf(head, "%u-%s%s={ mode=%s }\n", |
head->r.index++; |
637 |
index, "CONFIG::", |
head->r.step = 1; |
|
ccs_mac_keywords[i], |
|
|
ccs_mode_4[config & 3])) |
|
|
goto out; |
|
|
#endif |
|
638 |
} |
} |
|
if (!ccs_print_preference(head, index)) |
|
|
goto out; |
|
|
continue; |
|
|
out: |
|
|
head->read_avail = pos; |
|
639 |
break; |
break; |
640 |
} |
} |
641 |
if (index == CCS_MAX_PROFILES) |
if (ccs_flush(head)) |
642 |
head->read_eof = true; |
goto next; |
643 |
} |
} |
644 |
|
|
645 |
static bool ccs_same_manager_entry(const struct ccs_acl_head *a, |
static bool ccs_same_manager(const struct ccs_acl_head *a, |
646 |
const struct ccs_acl_head *b) |
const struct ccs_acl_head *b) |
647 |
{ |
{ |
648 |
return container_of(a, struct ccs_manager, head)->manager |
return container_of(a, struct ccs_manager, head)->manager |
649 |
== container_of(b, struct ccs_manager, head)->manager; |
== container_of(b, struct ccs_manager, head)->manager; |
666 |
return -EINVAL; |
return -EINVAL; |
667 |
e.is_domain = true; |
e.is_domain = true; |
668 |
} else { |
} else { |
669 |
if (!ccs_correct_path(manager, 1, -1, -1)) |
if (!ccs_correct_path(manager)) |
670 |
return -EINVAL; |
return -EINVAL; |
671 |
} |
} |
672 |
e.manager = ccs_get_name(manager); |
e.manager = ccs_get_name(manager); |
673 |
if (!e.manager) |
if (!e.manager) |
674 |
return error; |
return error; |
675 |
error = ccs_update_policy(&e.head, sizeof(e), is_delete, |
error = ccs_update_policy(&e.head, sizeof(e), is_delete, |
676 |
CCS_ID_MANAGER, ccs_same_manager_entry); |
&ccs_policy_list[CCS_ID_MANAGER], |
677 |
|
ccs_same_manager); |
678 |
ccs_put_name(e.manager); |
ccs_put_name(e.manager); |
679 |
return error; |
return error; |
680 |
} |
} |
706 |
*/ |
*/ |
707 |
static void ccs_read_manager(struct ccs_io_buffer *head) |
static void ccs_read_manager(struct ccs_io_buffer *head) |
708 |
{ |
{ |
709 |
struct list_head *pos; |
if (head->r.eof) |
|
if (head->read_eof) |
|
710 |
return; |
return; |
711 |
list_for_each_cookie(pos, head->read_var2, |
list_for_each_cookie(head->r.acl, &ccs_policy_list[CCS_ID_MANAGER]) { |
712 |
&ccs_policy_list[CCS_ID_MANAGER]) { |
struct ccs_manager *ptr = |
713 |
struct ccs_manager *ptr |
list_entry(head->r.acl, typeof(*ptr), head.list); |
|
= list_entry(pos, typeof(*ptr), head.list); |
|
714 |
if (ptr->head.is_deleted) |
if (ptr->head.is_deleted) |
715 |
continue; |
continue; |
716 |
if (!ccs_io_printf(head, "%s\n", ptr->manager->name)) |
if (!ccs_flush(head)) |
717 |
return; |
return; |
718 |
|
ccs_set_string(head, ptr->manager->name); |
719 |
|
ccs_set_lf(head); |
720 |
} |
} |
721 |
head->read_eof = true; |
head->r.eof = true; |
722 |
} |
} |
723 |
|
|
724 |
/** |
/** |
743 |
return true; |
return true; |
744 |
if (!ccs_manage_by_non_root && (current_uid() || current_euid())) |
if (!ccs_manage_by_non_root && (current_uid() || current_euid())) |
745 |
return false; |
return false; |
|
list_for_each_entry_rcu(ptr, &ccs_policy_list[CCS_ID_MANAGER], |
|
|
head.list) { |
|
|
if (!ptr->head.is_deleted && ptr->is_domain |
|
|
&& !ccs_pathcmp(domainname, ptr->manager)) { |
|
|
/* Set manager flag. */ |
|
|
task->ccs_flags |= CCS_TASK_IS_MANAGER; |
|
|
return true; |
|
|
} |
|
|
} |
|
746 |
exe = ccs_get_exe(); |
exe = ccs_get_exe(); |
|
if (!exe) |
|
|
return false; |
|
747 |
list_for_each_entry_rcu(ptr, &ccs_policy_list[CCS_ID_MANAGER], |
list_for_each_entry_rcu(ptr, &ccs_policy_list[CCS_ID_MANAGER], |
748 |
head.list) { |
head.list) { |
749 |
if (!ptr->head.is_deleted && !ptr->is_domain |
if (ptr->head.is_deleted) |
750 |
&& !strcmp(exe, ptr->manager->name)) { |
continue; |
751 |
found = true; |
if (ptr->is_domain) { |
752 |
/* Set manager flag. */ |
if (ccs_pathcmp(domainname, ptr->manager)) |
753 |
task->ccs_flags |= CCS_TASK_IS_MANAGER; |
continue; |
754 |
break; |
} else { |
755 |
|
if (!exe || strcmp(exe, ptr->manager->name)) |
756 |
|
continue; |
757 |
} |
} |
758 |
|
/* Set manager flag. */ |
759 |
|
task->ccs_flags |= CCS_TASK_IS_MANAGER; |
760 |
|
found = true; |
761 |
|
break; |
762 |
} |
} |
763 |
if (!found) { /* Reduce error messages. */ |
if (!found) { /* Reduce error messages. */ |
764 |
static pid_t ccs_last_pid; |
static pid_t ccs_last_pid; |
784 |
static char *ccs_find_condition_part(char *data) |
static char *ccs_find_condition_part(char *data) |
785 |
{ |
{ |
786 |
char *cp = strstr(data, " if "); |
char *cp = strstr(data, " if "); |
787 |
if (cp) { |
if (!cp) |
|
while (1) { |
|
|
char *cp2 = strstr(cp + 3, " if "); |
|
|
if (!cp2) |
|
|
break; |
|
|
cp = cp2; |
|
|
} |
|
|
*cp++ = '\0'; |
|
|
} else { |
|
788 |
cp = strstr(data, " ; set "); |
cp = strstr(data, " ; set "); |
789 |
if (cp) |
if (cp) |
790 |
*cp++ = '\0'; |
*cp++ = '\0'; |
|
} |
|
791 |
return cp; |
return cp; |
792 |
} |
} |
793 |
|
|
806 |
unsigned int pid; |
unsigned int pid; |
807 |
struct ccs_domain_info *domain = NULL; |
struct ccs_domain_info *domain = NULL; |
808 |
bool global_pid = false; |
bool global_pid = false; |
809 |
if (!strcmp(data, "allow_execute")) { |
if (!strcmp(data, "execute")) { |
810 |
head->read_execute_only = true; |
head->r.print_execute_only = true; |
811 |
return true; |
return true; |
812 |
} |
} |
813 |
if (sscanf(data, "pid=%u", &pid) == 1 || |
if (sscanf(data, "pid=%u", &pid) == 1 || |
831 |
domain = ccs_find_domain(data + 7); |
domain = ccs_find_domain(data + 7); |
832 |
} else |
} else |
833 |
return false; |
return false; |
834 |
head->write_var1 = domain; |
head->w.domain = domain; |
835 |
/* Accessing read_buf is safe because head->io_sem is held. */ |
/* Accessing read_buf is safe because head->io_sem is held. */ |
836 |
if (!head->read_buf) |
if (!head->read_buf) |
837 |
return true; /* Do nothing if open(O_WRONLY). */ |
return true; /* Do nothing if open(O_WRONLY). */ |
838 |
head->read_avail = 0; |
memset(&head->r, 0, sizeof(head->r)); |
839 |
|
head->r.print_this_domain_only = true; |
840 |
|
if (domain) |
841 |
|
head->r.domain = &domain->list; |
842 |
|
else |
843 |
|
head->r.eof = true; |
844 |
ccs_io_printf(head, "# select %s\n", data); |
ccs_io_printf(head, "# select %s\n", data); |
845 |
head->read_single_domain = true; |
if (domain && domain->is_deleted) |
846 |
head->read_eof = !domain; |
ccs_set_string(head, "# This is a deleted domain.\n"); |
|
if (domain) { |
|
|
struct ccs_domain_info *d; |
|
|
head->read_var1 = NULL; |
|
|
list_for_each_entry_rcu(d, &ccs_domain_list, list) { |
|
|
if (d == domain) |
|
|
break; |
|
|
head->read_var1 = &d->list; |
|
|
} |
|
|
head->read_var2 = NULL; |
|
|
head->read_bit = 0; |
|
|
head->read_step = 0; |
|
|
if (domain->is_deleted) |
|
|
ccs_io_printf(head, "# This is a deleted domain.\n"); |
|
|
} |
|
847 |
return true; |
return true; |
848 |
} |
} |
849 |
|
|
850 |
static int ccs_write_domain2(char *data, struct ccs_domain_info *domain, |
static int ccs_write_domain2(char *data, struct ccs_domain_info *domain, |
851 |
struct ccs_condition *cond, const bool is_delete) |
const bool is_delete) |
852 |
{ |
{ |
|
u8 i; |
|
853 |
static const struct { |
static const struct { |
854 |
const char *keyword; |
const char *keyword; |
855 |
int (*write) (char *, struct ccs_domain_info *, |
int (*write) (char *, struct ccs_domain_info *, |
856 |
struct ccs_condition *, const bool); |
struct ccs_condition *, const bool); |
857 |
} ccs_callback[5] = { |
} ccs_callback[4] = { |
858 |
{ CCS_KEYWORD_ALLOW_NETWORK, ccs_write_network }, |
{ "network ", ccs_write_network }, |
859 |
{ CCS_KEYWORD_ALLOW_ENV, ccs_write_env }, |
{ "misc ", ccs_write_misc }, |
860 |
{ CCS_KEYWORD_ALLOW_CAPABILITY, ccs_write_capability }, |
{ "capability ", ccs_write_capability }, |
861 |
{ CCS_KEYWORD_ALLOW_SIGNAL, ccs_write_signal }, |
{ "ipc ", ccs_write_ipc }, |
|
{ CCS_KEYWORD_ALLOW_MOUNT, ccs_write_mount } |
|
862 |
}; |
}; |
863 |
int (*write) (char *, struct ccs_domain_info *, struct ccs_condition *, |
int (*write) (char *, struct ccs_domain_info *, struct ccs_condition *, |
864 |
const bool) = ccs_write_file; |
const bool) = ccs_write_file; |
865 |
for (i = 0; i < 5; i++) { |
int error; |
866 |
|
u8 i; |
867 |
|
struct ccs_condition *cond = NULL; |
868 |
|
char *cp = ccs_find_condition_part(data); |
869 |
|
if (cp) { |
870 |
|
cond = ccs_get_condition(cp); |
871 |
|
if (!cond) |
872 |
|
return -EINVAL; |
873 |
|
} |
874 |
|
for (i = 0; i < 4; i++) { |
875 |
if (!ccs_str_starts(&data, ccs_callback[i].keyword)) |
if (!ccs_str_starts(&data, ccs_callback[i].keyword)) |
876 |
continue; |
continue; |
877 |
write = ccs_callback[i].write; |
write = ccs_callback[i].write; |
878 |
break; |
break; |
879 |
} |
} |
880 |
return write(data, domain, cond, is_delete); |
error = write(data, domain, cond, is_delete); |
881 |
|
if (cond) |
882 |
|
ccs_put_condition(cond); |
883 |
|
return error; |
884 |
} |
} |
885 |
|
|
886 |
|
static const char *ccs_dif[CCS_MAX_DOMAIN_INFO_FLAGS] = { |
887 |
|
[CCS_DIF_QUOTA_WARNED] = CCS_KEYWORD_QUOTA_EXCEEDED "\n", |
888 |
|
[CCS_DIF_TRANSITION_FAILED] = CCS_KEYWORD_TRANSITION_FAILED "\n" |
889 |
|
}; |
890 |
|
|
891 |
/** |
/** |
892 |
* ccs_write_domain - Write domain policy. |
* ccs_write_domain - Write domain policy. |
893 |
* |
* |
898 |
static int ccs_write_domain(struct ccs_io_buffer *head) |
static int ccs_write_domain(struct ccs_io_buffer *head) |
899 |
{ |
{ |
900 |
char *data = head->write_buf; |
char *data = head->write_buf; |
901 |
struct ccs_domain_info *domain = head->write_var1; |
struct ccs_domain_info *domain = head->w.domain; |
902 |
bool is_delete = false; |
bool is_delete = false; |
903 |
bool is_select = false; |
bool is_select = false; |
904 |
unsigned int profile; |
unsigned int profile; |
|
struct ccs_condition *cond = NULL; |
|
|
char *cp; |
|
|
int error; |
|
905 |
if (ccs_str_starts(&data, CCS_KEYWORD_DELETE)) |
if (ccs_str_starts(&data, CCS_KEYWORD_DELETE)) |
906 |
is_delete = true; |
is_delete = true; |
907 |
else if (ccs_str_starts(&data, CCS_KEYWORD_SELECT)) |
else if (ccs_str_starts(&data, CCS_KEYWORD_SELECT)) |
918 |
else if (is_select) |
else if (is_select) |
919 |
domain = ccs_find_domain(data); |
domain = ccs_find_domain(data); |
920 |
else |
else |
921 |
domain = ccs_find_or_assign_new_domain(data, 0); |
domain = ccs_assign_domain(data, 0, 0, false); |
922 |
head->write_var1 = domain; |
head->w.domain = domain; |
923 |
return 0; |
return 0; |
924 |
} |
} |
925 |
if (!domain) |
if (!domain) |
931 |
domain->profile = (u8) profile; |
domain->profile = (u8) profile; |
932 |
return 0; |
return 0; |
933 |
} |
} |
934 |
if (!strcmp(data, CCS_KEYWORD_IGNORE_GLOBAL_ALLOW_READ)) { |
if (sscanf(data, CCS_KEYWORD_USE_GROUP "%u", &profile) == 1 |
935 |
domain->ignore_global_allow_read = !is_delete; |
&& profile < CCS_MAX_ACL_GROUPS) { |
936 |
|
domain->group = (u8) profile; |
937 |
return 0; |
return 0; |
938 |
} |
} |
939 |
if (!strcmp(data, CCS_KEYWORD_IGNORE_GLOBAL_ALLOW_ENV)) { |
for (profile = 0; profile < CCS_MAX_DOMAIN_INFO_FLAGS; profile++) { |
940 |
domain->ignore_global_allow_env = !is_delete; |
const char *cp = ccs_dif[profile]; |
941 |
return 0; |
if (strncmp(data, cp, strlen(cp) - 1)) |
942 |
} |
continue; |
943 |
if (!strcmp(data, CCS_KEYWORD_QUOTA_EXCEEDED)) { |
domain->flags[profile] = !is_delete; |
|
domain->quota_warned = !is_delete; |
|
|
return 0; |
|
|
} |
|
|
if (!strcmp(data, CCS_KEYWORD_TRANSITION_FAILED)) { |
|
|
domain->domain_transition_failed = !is_delete; |
|
944 |
return 0; |
return 0; |
945 |
} |
} |
946 |
cp = ccs_find_condition_part(data); |
return ccs_write_domain2(data, domain, is_delete); |
|
if (cp) { |
|
|
cond = ccs_get_condition(cp); |
|
|
if (!cond) |
|
|
return -EINVAL; |
|
|
} |
|
|
error = ccs_write_domain2(data, domain, cond, is_delete); |
|
|
if (cond) |
|
|
ccs_put_condition(cond); |
|
|
return error; |
|
947 |
} |
} |
948 |
|
|
949 |
/** |
/** |
951 |
* |
* |
952 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
953 |
* @ptr: Pointer to "struct ccs_name_union". |
* @ptr: Pointer to "struct ccs_name_union". |
|
* |
|
|
* Returns true on success, false otherwise. |
|
954 |
*/ |
*/ |
955 |
static bool ccs_print_name_union(struct ccs_io_buffer *head, |
static void ccs_print_name_union(struct ccs_io_buffer *head, |
956 |
const struct ccs_name_union *ptr) |
const struct ccs_name_union *ptr) |
957 |
{ |
{ |
958 |
int pos = head->read_avail; |
const bool cond = head->r.print_cond_part; |
959 |
if (pos && head->read_buf[pos - 1] == ' ') |
if (!cond) |
960 |
head->read_avail--; |
ccs_set_space(head); |
961 |
if (ptr->is_group) |
if (ptr->is_group) { |
962 |
return ccs_io_printf(head, " @%s", |
ccs_set_string(head, "@"); |
963 |
ptr->group->group_name->name); |
ccs_set_string(head, ptr->group->group_name->name); |
964 |
return ccs_io_printf(head, " %s", ptr->filename->name); |
} else { |
965 |
|
if (cond) |
966 |
|
ccs_set_string(head, "\""); |
967 |
|
ccs_set_string(head, ptr->filename->name); |
968 |
|
if (cond) |
969 |
|
ccs_set_string(head, "\""); |
970 |
|
} |
971 |
} |
} |
972 |
|
|
973 |
/** |
/** |
974 |
* ccs_print_name_union_quoted - Print a ccs_name_union with double quotes. |
* ccs_print_number_union - Print a ccs_number_union. |
975 |
* |
* |
976 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
977 |
* @ptr: Pointer to "struct ccs_name_union". |
* @ptr: Pointer to "struct ccs_number_union". |
|
* |
|
|
* Returns true on success, false otherwise. |
|
978 |
*/ |
*/ |
979 |
static bool ccs_print_name_union_quoted(struct ccs_io_buffer *head, |
static void ccs_print_number_union(struct ccs_io_buffer *head, |
980 |
const struct ccs_name_union *ptr) |
const struct ccs_number_union *ptr) |
981 |
{ |
{ |
982 |
if (ptr->is_group) |
if (!head->r.print_cond_part) |
983 |
return ccs_io_printf(head, "@%s", |
ccs_set_space(head); |
984 |
ptr->group->group_name->name); |
if (ptr->is_group) { |
985 |
return ccs_io_printf(head, "\"%s\"", ptr->filename->name); |
ccs_set_string(head, "@"); |
986 |
} |
ccs_set_string(head, ptr->group->group_name->name); |
987 |
|
} else { |
988 |
static void ccs_print_number(char *buffer, int buffer_len, |
int i; |
989 |
const struct ccs_number_union *ptr) |
unsigned long min = ptr->values[0]; |
990 |
{ |
const unsigned long max = ptr->values[1]; |
991 |
int i; |
u8 min_type = ptr->value_type[0]; |
992 |
unsigned long min = ptr->values[0]; |
const u8 max_type = ptr->value_type[1]; |
993 |
const unsigned long max = ptr->values[1]; |
char buffer[128]; |
994 |
u8 min_type = ptr->value_type[0]; |
buffer[0] = '\0'; |
995 |
const u8 max_type = ptr->value_type[1]; |
for (i = 0; i < 2; i++) { |
996 |
memset(buffer, 0, buffer_len); |
switch (min_type) { |
997 |
buffer_len -= 2; |
case CCS_VALUE_TYPE_HEXADECIMAL: |
998 |
for (i = 0; i < 2; i++) { |
ccs_addprintf(buffer, sizeof(buffer), "0x%lX", |
999 |
int len; |
min); |
1000 |
switch (min_type) { |
break; |
1001 |
case CCS_VALUE_TYPE_HEXADECIMAL: |
case CCS_VALUE_TYPE_OCTAL: |
1002 |
snprintf(buffer, buffer_len, "0x%lX", min); |
ccs_addprintf(buffer, sizeof(buffer), "0%lo", |
1003 |
break; |
min); |
1004 |
case CCS_VALUE_TYPE_OCTAL: |
break; |
1005 |
snprintf(buffer, buffer_len, "0%lo", min); |
default: |
1006 |
break; |
ccs_addprintf(buffer, sizeof(buffer), "%lu", |
1007 |
default: |
min); |
1008 |
snprintf(buffer, buffer_len, "%lu", min); |
break; |
1009 |
break; |
} |
1010 |
|
if (min == max && min_type == max_type) |
1011 |
|
break; |
1012 |
|
ccs_addprintf(buffer, sizeof(buffer), "-"); |
1013 |
|
min_type = max_type; |
1014 |
|
min = max; |
1015 |
} |
} |
1016 |
if (min == max && min_type == max_type) |
ccs_io_printf(head, "%s", buffer); |
|
break; |
|
|
len = strlen(buffer); |
|
|
buffer[len++] = '-'; |
|
|
buffer += len; |
|
|
buffer_len -= len; |
|
|
min_type = max_type; |
|
|
min = max; |
|
1017 |
} |
} |
1018 |
} |
} |
1019 |
|
|
1020 |
/** |
/** |
|
* ccs_print_number_union_common - Print a ccs_number_union. |
|
|
* |
|
|
* @head: Pointer to "struct ccs_io_buffer". |
|
|
* @ptr: Pointer to "struct ccs_number_union". |
|
|
* @need_space: True if a space character is needed. |
|
|
* |
|
|
* Returns true on success, false otherwise. |
|
|
*/ |
|
|
static bool ccs_print_number_union_common(struct ccs_io_buffer *head, |
|
|
const struct ccs_number_union *ptr, |
|
|
const bool need_space) |
|
|
{ |
|
|
char buffer[128]; |
|
|
if (need_space && !ccs_io_printf(head, " ")) |
|
|
return false; |
|
|
if (ptr->is_group) |
|
|
return ccs_io_printf(head, "@%s", |
|
|
ptr->group->group_name->name); |
|
|
ccs_print_number(buffer, sizeof(buffer), ptr); |
|
|
return ccs_io_printf(head, "%s", buffer); |
|
|
} |
|
|
|
|
|
/** |
|
|
* ccs_print_number_union - Print a ccs_number_union. |
|
|
* |
|
|
* @head: Pointer to "struct ccs_io_buffer". |
|
|
* @ptr: Pointer to "struct ccs_number_union". |
|
|
* |
|
|
* Returns true on success, false otherwise. |
|
|
*/ |
|
|
bool ccs_print_number_union(struct ccs_io_buffer *head, |
|
|
const struct ccs_number_union *ptr) |
|
|
{ |
|
|
return ccs_print_number_union_common(head, ptr, true); |
|
|
} |
|
|
|
|
|
/** |
|
|
* ccs_print_number_union_nospace - Print a ccs_number_union without a space character. |
|
|
* |
|
|
* @head: Pointer to "struct ccs_io_buffer". |
|
|
* @ptr: Pointer to "struct ccs_number_union". |
|
|
* |
|
|
* Returns true on success, false otherwise. |
|
|
*/ |
|
|
static bool ccs_print_number_union_nospace(struct ccs_io_buffer *head, |
|
|
const struct ccs_number_union *ptr) |
|
|
{ |
|
|
return ccs_print_number_union_common(head, ptr, false); |
|
|
} |
|
|
|
|
|
/** |
|
1021 |
* ccs_print_condition - Print condition part. |
* ccs_print_condition - Print condition part. |
1022 |
* |
* |
1023 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1024 |
* @cond: Pointer to "struct ccs_condition". May be NULL. |
* @cond: Pointer to "struct ccs_condition". |
1025 |
* |
* |
1026 |
* Returns true on success, false otherwise. |
* Returns true on success, false otherwise. |
1027 |
*/ |
*/ |
1028 |
static bool ccs_print_condition(struct ccs_io_buffer *head, |
static bool ccs_print_condition(struct ccs_io_buffer *head, |
1029 |
const struct ccs_condition *cond) |
const struct ccs_condition *cond) |
1030 |
{ |
{ |
1031 |
const struct ccs_condition_element *condp; |
switch (head->r.cond_step) { |
1032 |
const struct ccs_number_union *numbers_p; |
case 0: |
1033 |
const struct ccs_name_union *names_p; |
{ |
1034 |
const struct ccs_argv *argv; |
if (cond->condc) |
1035 |
const struct ccs_envp *envp; |
ccs_set_string(head, " if"); |
1036 |
u16 condc; |
head->r.cond_index = 0; |
1037 |
u16 i; |
head->r.cond_step++; |
1038 |
u16 j; |
} |
1039 |
char buffer[32]; |
/* fall through */ |
1040 |
if (!cond) |
case 1: |
1041 |
goto no_condition; |
{ |
1042 |
condc = cond->condc; |
const u16 condc = cond->condc; |
1043 |
condp = (const struct ccs_condition_element *) (cond + 1); |
const struct ccs_condition_element *condp = |
1044 |
numbers_p = (const struct ccs_number_union *) (condp + condc); |
(typeof(condp)) (cond + 1); |
1045 |
names_p = (const struct ccs_name_union *) |
const struct ccs_number_union *numbers_p = |
1046 |
(numbers_p + cond->numbers_count); |
(typeof(numbers_p)) (condp + condc); |
1047 |
argv = (const struct ccs_argv *) (names_p + cond->names_count); |
const struct ccs_name_union *names_p = |
1048 |
envp = (const struct ccs_envp *) (argv + cond->argc); |
(typeof(names_p)) |
1049 |
memset(buffer, 0, sizeof(buffer)); |
(numbers_p + cond->numbers_count); |
1050 |
if (condc && !ccs_io_printf(head, "%s", " if")) |
const struct ccs_argv *argv = |
1051 |
goto out; |
(typeof(argv)) (names_p + cond->names_count); |
1052 |
for (i = 0; i < condc; i++) { |
const struct ccs_envp *envp = |
1053 |
const u8 match = condp->equals; |
(typeof(envp)) (argv + cond->argc); |
1054 |
const u8 left = condp->left; |
u16 skip; |
1055 |
const u8 right = condp->right; |
for (skip = 0; skip < head->r.cond_index; skip++) { |
1056 |
condp++; |
const u8 left = condp->left; |
1057 |
switch (left) { |
const u8 right = condp->right; |
1058 |
case CCS_ARGV_ENTRY: |
condp++; |
1059 |
if (!ccs_io_printf(head, " exec.argv[%u]%s\"%s\"", |
switch (left) { |
1060 |
argv->index, argv->is_not ? |
case CCS_ARGV_ENTRY: |
1061 |
"!=" : "=", argv->value->name)) |
argv++; |
1062 |
goto out; |
continue; |
1063 |
argv++; |
case CCS_ENVP_ENTRY: |
1064 |
continue; |
envp++; |
1065 |
case CCS_ENVP_ENTRY: |
continue; |
1066 |
if (!ccs_io_printf(head, " exec.envp[\"%s\"]%s", |
case CCS_NUMBER_UNION: |
1067 |
envp->name->name, envp->is_not ? |
numbers_p++; |
1068 |
"!=" : "=")) |
break; |
1069 |
goto out; |
} |
1070 |
if (envp->value) { |
switch (right) { |
1071 |
if (!ccs_io_printf(head, "\"%s\"", |
case CCS_NAME_UNION: |
1072 |
envp->value->name)) |
names_p++; |
1073 |
goto out; |
break; |
1074 |
} else { |
case CCS_NUMBER_UNION: |
1075 |
if (!ccs_io_printf(head, "NULL")) |
numbers_p++; |
1076 |
goto out; |
break; |
1077 |
|
} |
1078 |
|
} |
1079 |
|
while (head->r.cond_index < condc) { |
1080 |
|
const u8 match = condp->equals; |
1081 |
|
const u8 left = condp->left; |
1082 |
|
const u8 right = condp->right; |
1083 |
|
if (!ccs_flush(head)) |
1084 |
|
return false; |
1085 |
|
condp++; |
1086 |
|
head->r.cond_index++; |
1087 |
|
ccs_set_space(head); |
1088 |
|
switch (left) { |
1089 |
|
case CCS_ARGV_ENTRY: |
1090 |
|
ccs_io_printf(head, |
1091 |
|
"exec.argv[%u]%s\"%s\"", |
1092 |
|
argv->index, |
1093 |
|
argv->is_not ? |
1094 |
|
"!=" : "=", |
1095 |
|
argv->value->name); |
1096 |
|
argv++; |
1097 |
|
continue; |
1098 |
|
case CCS_ENVP_ENTRY: |
1099 |
|
ccs_io_printf(head, |
1100 |
|
"exec.envp[\"%s\"]%s", |
1101 |
|
envp->name->name, |
1102 |
|
envp->is_not ? |
1103 |
|
"!=" : "="); |
1104 |
|
if (envp->value) { |
1105 |
|
ccs_set_string(head, "\""); |
1106 |
|
ccs_set_string(head, envp-> |
1107 |
|
value->name); |
1108 |
|
ccs_set_string(head, "\""); |
1109 |
|
} else { |
1110 |
|
ccs_set_string(head, "NULL"); |
1111 |
|
} |
1112 |
|
envp++; |
1113 |
|
continue; |
1114 |
|
case CCS_NUMBER_UNION: |
1115 |
|
ccs_print_number_union(head, |
1116 |
|
numbers_p++); |
1117 |
|
break; |
1118 |
|
default: |
1119 |
|
ccs_set_string(head, |
1120 |
|
ccs_condition_keyword[left]); |
1121 |
|
break; |
1122 |
|
} |
1123 |
|
ccs_set_string(head, match ? "=" : "!="); |
1124 |
|
switch (right) { |
1125 |
|
case CCS_NAME_UNION: |
1126 |
|
ccs_print_name_union(head, names_p++); |
1127 |
|
break; |
1128 |
|
case CCS_NUMBER_UNION: |
1129 |
|
ccs_print_number_union(head, |
1130 |
|
numbers_p++); |
1131 |
|
break; |
1132 |
|
default: |
1133 |
|
ccs_set_string(head, |
1134 |
|
ccs_condition_keyword[right]); |
1135 |
|
break; |
1136 |
|
} |
1137 |
} |
} |
|
envp++; |
|
|
continue; |
|
|
case CCS_NUMBER_UNION: |
|
|
if (!ccs_print_number_union(head, numbers_p++)) |
|
|
goto out; |
|
|
break; |
|
|
default: |
|
|
if (left >= CCS_MAX_CONDITION_KEYWORD) |
|
|
goto out; |
|
|
if (!ccs_io_printf(head, " %s", |
|
|
ccs_condition_keyword[left])) |
|
|
goto out; |
|
|
break; |
|
1138 |
} |
} |
1139 |
if (!ccs_io_printf(head, "%s", match ? "=" : "!=")) |
head->r.cond_step++; |
1140 |
goto out; |
/* fall through */ |
1141 |
switch (right) { |
case 2: |
1142 |
case CCS_NAME_UNION: |
if (!ccs_flush(head)) |
|
if (!ccs_print_name_union_quoted(head, names_p++)) |
|
|
goto out; |
|
|
break; |
|
|
case CCS_NUMBER_UNION: |
|
|
if (!ccs_print_number_union_nospace(head, numbers_p++)) |
|
|
goto out; |
|
|
break; |
|
|
default: |
|
|
if (right >= CCS_MAX_CONDITION_KEYWORD) |
|
|
goto out; |
|
|
if (!ccs_io_printf(head, "%s", |
|
|
ccs_condition_keyword[right])) |
|
|
goto out; |
|
1143 |
break; |
break; |
1144 |
|
head->r.cond_step++; |
1145 |
|
/* fall through */ |
1146 |
|
case 3: |
1147 |
|
{ |
1148 |
|
u8 j; |
1149 |
|
const u8 i = cond->post_state[3]; |
1150 |
|
if (i) |
1151 |
|
ccs_set_string(head, " ; set"); |
1152 |
|
for (j = 0; j < 3; j++) |
1153 |
|
if ((i & (1 << j))) |
1154 |
|
ccs_io_printf(head, |
1155 |
|
" task.state[%u]=%u", j, |
1156 |
|
cond->post_state[j]); |
1157 |
|
if (i & (1 << 4)) |
1158 |
|
ccs_io_printf(head, " audit=%s", |
1159 |
|
ccs_yesno(cond->post_state[4])); |
1160 |
} |
} |
1161 |
} |
ccs_set_lf(head); |
|
i = cond->post_state[3]; |
|
|
if (!i) |
|
|
goto no_condition; |
|
|
if (!ccs_io_printf(head, " ; set")) |
|
|
goto out; |
|
|
for (j = 0; j < 3; j++) { |
|
|
if (!(i & (1 << j))) |
|
|
continue; |
|
|
if (!ccs_io_printf(head, " task.state[%u]=%u", j, |
|
|
cond->post_state[j])) |
|
|
goto out; |
|
|
} |
|
|
no_condition: |
|
|
if (ccs_io_printf(head, "\n")) |
|
1162 |
return true; |
return true; |
1163 |
out: |
} |
1164 |
return false; |
return false; |
1165 |
} |
} |
1166 |
|
|
1167 |
/** |
/** |
1168 |
* ccs_print_path_acl - Print a path ACL entry. |
* ccs_fns - Find next set bit. |
1169 |
* |
* |
1170 |
* @head: Pointer to "struct ccs_io_buffer". |
* @perm: 8 bits value. |
1171 |
* @ptr: Pointer to "struct ccs_path_acl". |
* @bit: First bit to find. |
|
* @cond: Pointer to "struct ccs_condition". May be NULL. |
|
1172 |
* |
* |
1173 |
* Returns true on success, false otherwise. |
* Returns next set bit on success, 8 otherwise. |
1174 |
*/ |
*/ |
1175 |
static bool ccs_print_path_acl(struct ccs_io_buffer *head, |
static u8 ccs_fns(const u8 perm, u8 bit) |
|
struct ccs_path_acl *ptr, |
|
|
const struct ccs_condition *cond) |
|
1176 |
{ |
{ |
1177 |
int pos; |
for ( ; bit < 8; bit++) |
1178 |
u8 bit; |
if (perm & (1 << bit)) |
1179 |
const u16 perm = ptr->perm; |
break; |
1180 |
for (bit = head->read_bit; bit < CCS_MAX_PATH_OPERATION; bit++) { |
return bit; |
|
if (!(perm & (1 << bit))) |
|
|
continue; |
|
|
if (head->read_execute_only && bit != CCS_TYPE_EXECUTE |
|
|
&& bit != CCS_TYPE_TRANSIT) |
|
|
continue; |
|
|
/* Print "read/write" instead of "read" and "write". */ |
|
|
if ((bit == CCS_TYPE_READ || bit == CCS_TYPE_WRITE) |
|
|
&& (perm & (1 << CCS_TYPE_READ_WRITE))) |
|
|
continue; |
|
|
pos = head->read_avail; |
|
|
if (!ccs_io_printf(head, "allow_%s", ccs_path2keyword(bit)) || |
|
|
!ccs_print_name_union(head, &ptr->name) || |
|
|
!ccs_print_condition(head, cond)) { |
|
|
head->read_bit = bit; |
|
|
head->read_avail = pos; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
head->read_bit = 0; |
|
|
return true; |
|
1181 |
} |
} |
1182 |
|
|
1183 |
/** |
static void ccs_set_group(struct ccs_io_buffer *head) |
|
* ccs_print_path_number3_acl - Print a path_number3 ACL entry. |
|
|
* |
|
|
* @head: Pointer to "struct ccs_io_buffer". |
|
|
* @ptr: Pointer to "struct ccs_path_number3_acl". |
|
|
* @cond: Pointer to "struct ccs_condition". May be NULL. |
|
|
* |
|
|
* Returns true on success, false otherwise. |
|
|
*/ |
|
|
static bool ccs_print_path_number3_acl(struct ccs_io_buffer *head, |
|
|
struct ccs_path_number3_acl *ptr, |
|
|
const struct ccs_condition *cond) |
|
1184 |
{ |
{ |
1185 |
int pos; |
if (head->type == CCS_EXCEPTIONPOLICY) |
1186 |
u8 bit; |
ccs_io_printf(head, "acl_group %u ", head->r.group_index); |
|
const u16 perm = ptr->perm; |
|
|
for (bit = head->read_bit; bit < CCS_MAX_PATH_NUMBER3_OPERATION; |
|
|
bit++) { |
|
|
if (!(perm & (1 << bit))) |
|
|
continue; |
|
|
pos = head->read_avail; |
|
|
if (!ccs_io_printf(head, "allow_%s", |
|
|
ccs_path_number32keyword(bit)) || |
|
|
!ccs_print_name_union(head, &ptr->name) || |
|
|
!ccs_print_number_union(head, &ptr->mode) || |
|
|
!ccs_print_number_union(head, &ptr->major) || |
|
|
!ccs_print_number_union(head, &ptr->minor) || |
|
|
!ccs_print_condition(head, cond)) { |
|
|
head->read_bit = bit; |
|
|
head->read_avail = pos; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
head->read_bit = 0; |
|
|
return true; |
|
1187 |
} |
} |
1188 |
|
|
1189 |
/** |
/** |
1190 |
* ccs_print_path2_acl - Print a path2 ACL entry. |
* ccs_print_entry - Print an ACL entry. |
|
* |
|
|
* @head: Pointer to "struct ccs_io_buffer". |
|
|
* @ptr: Pointer to "struct ccs_path2_acl". |
|
|
* @cond: Pointer to "struct ccs_condition". May be NULL. |
|
|
* |
|
|
* Returns true on success, false otherwise. |
|
|
*/ |
|
|
static bool ccs_print_path2_acl(struct ccs_io_buffer *head, |
|
|
struct ccs_path2_acl *ptr, |
|
|
const struct ccs_condition *cond) |
|
|
{ |
|
|
int pos; |
|
|
u8 bit; |
|
|
const u8 perm = ptr->perm; |
|
|
for (bit = head->read_bit; bit < CCS_MAX_PATH2_OPERATION; bit++) { |
|
|
if (!(perm & (1 << bit))) |
|
|
continue; |
|
|
pos = head->read_avail; |
|
|
if (!ccs_io_printf(head, "allow_%s", |
|
|
ccs_path22keyword(bit)) || |
|
|
!ccs_print_name_union(head, &ptr->name1) || |
|
|
!ccs_print_name_union(head, &ptr->name2) || |
|
|
!ccs_print_condition(head, cond)) { |
|
|
head->read_bit = bit; |
|
|
head->read_avail = pos; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
head->read_bit = 0; |
|
|
return true; |
|
|
} |
|
|
|
|
|
/** |
|
|
* ccs_print_path_number_acl - Print a path_number ACL entry. |
|
1191 |
* |
* |
1192 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1193 |
* @ptr: Pointer to "struct ccs_path_number_acl". |
* @acl: Pointer to an ACL entry. |
|
* @cond: Pointer to "struct ccs_condition". May be NULL. |
|
1194 |
* |
* |
1195 |
* Returns true on success, false otherwise. |
* Returns true on success, false otherwise. |
1196 |
*/ |
*/ |
1197 |
static bool ccs_print_path_number_acl(struct ccs_io_buffer *head, |
static bool ccs_print_entry(struct ccs_io_buffer *head, |
1198 |
struct ccs_path_number_acl *ptr, |
const struct ccs_acl_info *acl) |
|
const struct ccs_condition *cond) |
|
1199 |
{ |
{ |
1200 |
int pos; |
const u8 acl_type = acl->type; |
1201 |
u8 bit; |
u8 bit; |
1202 |
const u8 perm = ptr->perm; |
if (head->r.print_cond_part) |
1203 |
for (bit = head->read_bit; bit < CCS_MAX_PATH_NUMBER_OPERATION; |
goto print_cond_part; |
1204 |
bit++) { |
if (acl->is_deleted) |
1205 |
if (!(perm & (1 << bit))) |
return true; |
1206 |
continue; |
next: |
1207 |
pos = head->read_avail; |
bit = head->r.bit; |
1208 |
if (!ccs_io_printf(head, "allow_%s", |
if (!ccs_flush(head)) |
|
ccs_path_number2keyword(bit)) || |
|
|
!ccs_print_name_union(head, &ptr->name) || |
|
|
!ccs_print_number_union(head, &ptr->number) || |
|
|
!ccs_print_condition(head, cond)) { |
|
|
head->read_bit = bit; |
|
|
head->read_avail = pos; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
head->read_bit = 0; |
|
|
return true; |
|
|
} |
|
|
|
|
|
/** |
|
|
* ccs_print_env_acl - Print an evironment variable name's ACL entry. |
|
|
* |
|
|
* @head: Pointer to "struct ccs_io_buffer". |
|
|
* @ptr: Pointer to "struct ccs_env_acl". |
|
|
* @cond: Pointer to "struct ccs_condition". May be NULL. |
|
|
* |
|
|
* Returns true on success, false otherwise. |
|
|
*/ |
|
|
static bool ccs_print_env_acl(struct ccs_io_buffer *head, |
|
|
struct ccs_env_acl *ptr, |
|
|
const struct ccs_condition *cond) |
|
|
{ |
|
|
const int pos = head->read_avail; |
|
|
if (!ccs_io_printf(head, CCS_KEYWORD_ALLOW_ENV "%s", ptr->env->name) || |
|
|
!ccs_print_condition(head, cond)) { |
|
|
head->read_avail = pos; |
|
|
return false; |
|
|
} |
|
|
return true; |
|
|
} |
|
|
|
|
|
/** |
|
|
* ccs_print_capability_acl - Print a capability ACL entry. |
|
|
* |
|
|
* @head: Pointer to "struct ccs_io_buffer". |
|
|
* @ptr: Pointer to "struct ccs_capability_acl". |
|
|
* @cond: Pointer to "struct ccs_condition". May be NULL. |
|
|
* |
|
|
* Returns true on success, false otherwise. |
|
|
*/ |
|
|
static bool ccs_print_capability_acl(struct ccs_io_buffer *head, |
|
|
struct ccs_capability_acl *ptr, |
|
|
const struct ccs_condition *cond) |
|
|
{ |
|
|
const int pos = head->read_avail; |
|
|
if (!ccs_io_printf(head, CCS_KEYWORD_ALLOW_CAPABILITY "%s", |
|
|
ccs_cap2keyword(ptr->operation)) || |
|
|
!ccs_print_condition(head, cond)) { |
|
|
head->read_avail = pos; |
|
1209 |
return false; |
return false; |
1210 |
} |
else if (acl_type == CCS_TYPE_PATH_ACL) { |
1211 |
return true; |
struct ccs_path_acl *ptr |
1212 |
} |
= container_of(acl, typeof(*ptr), head); |
1213 |
|
const u16 perm = ptr->perm; |
1214 |
/** |
for ( ; bit < CCS_MAX_PATH_OPERATION; bit++) { |
1215 |
* ccs_print_network_acl - Print a network ACL entry. |
if (!(perm & (1 << bit))) |
1216 |
* |
continue; |
1217 |
* @head: Pointer to "struct ccs_io_buffer". |
if (head->r.print_execute_only && |
1218 |
* @ptr: Pointer to "struct ccs_ip_network_acl". |
bit != CCS_TYPE_EXECUTE && bit != CCS_TYPE_TRANSIT) |
1219 |
* @cond: Pointer to "struct ccs_condition". May be NULL. |
continue; |
1220 |
* |
break; |
1221 |
* Returns true on success, false otherwise. |
} |
1222 |
*/ |
if (bit >= CCS_MAX_PATH_OPERATION) |
1223 |
static bool ccs_print_network_acl(struct ccs_io_buffer *head, |
goto done; |
1224 |
struct ccs_ip_network_acl *ptr, |
ccs_set_group(head); |
1225 |
const struct ccs_condition *cond) |
ccs_set_string(head, "file "); |
1226 |
{ |
ccs_set_string(head, ccs_path_keyword[bit]); |
1227 |
int pos; |
ccs_print_name_union(head, &ptr->name); |
1228 |
u8 bit; |
} else if (acl_type == CCS_TYPE_EXECUTE_HANDLER || |
1229 |
const u16 perm = ptr->perm; |
acl_type == CCS_TYPE_DENIED_EXECUTE_HANDLER) { |
1230 |
char buf[128]; |
struct ccs_execute_handler *ptr |
1231 |
for (bit = head->read_bit; bit < CCS_MAX_NETWORK_OPERATION; bit++) { |
= container_of(acl, typeof(*ptr), head); |
1232 |
const char *w[2] = { "", "" }; |
ccs_set_group(head); |
1233 |
if (!(perm & (1 << bit))) |
ccs_io_printf(head, "%s ", |
1234 |
continue; |
acl_type == CCS_TYPE_EXECUTE_HANDLER ? |
1235 |
pos = head->read_avail; |
CCS_KEYWORD_EXECUTE_HANDLER : |
1236 |
|
CCS_KEYWORD_DENIED_EXECUTE_HANDLER); |
1237 |
|
ccs_set_string(head, ptr->handler->name); |
1238 |
|
} else if (head->r.print_execute_only) { |
1239 |
|
return true; |
1240 |
|
} else if (acl_type == CCS_TYPE_MKDEV_ACL) { |
1241 |
|
struct ccs_mkdev_acl *ptr = |
1242 |
|
container_of(acl, typeof(*ptr), head); |
1243 |
|
bit = ccs_fns(ptr->perm, bit); |
1244 |
|
if (bit >= CCS_MAX_MKDEV_OPERATION) |
1245 |
|
goto done; |
1246 |
|
ccs_set_group(head); |
1247 |
|
ccs_set_string(head, "file "); |
1248 |
|
ccs_set_string(head, ccs_mkdev_keyword[bit]); |
1249 |
|
ccs_print_name_union(head, &ptr->name); |
1250 |
|
ccs_print_number_union(head, &ptr->mode); |
1251 |
|
ccs_print_number_union(head, &ptr->major); |
1252 |
|
ccs_print_number_union(head, &ptr->minor); |
1253 |
|
} else if (acl_type == CCS_TYPE_PATH2_ACL) { |
1254 |
|
struct ccs_path2_acl *ptr = |
1255 |
|
container_of(acl, typeof(*ptr), head); |
1256 |
|
bit = ccs_fns(ptr->perm, bit); |
1257 |
|
if (bit >= CCS_MAX_PATH2_OPERATION) |
1258 |
|
goto done; |
1259 |
|
ccs_set_group(head); |
1260 |
|
ccs_set_string(head, "file "); |
1261 |
|
ccs_set_string(head, ccs_path2_keyword[bit]); |
1262 |
|
ccs_print_name_union(head, &ptr->name1); |
1263 |
|
ccs_print_name_union(head, &ptr->name2); |
1264 |
|
} else if (acl_type == CCS_TYPE_PATH_NUMBER_ACL) { |
1265 |
|
struct ccs_path_number_acl *ptr = |
1266 |
|
container_of(acl, typeof(*ptr), head); |
1267 |
|
bit = ccs_fns(ptr->perm, bit); |
1268 |
|
if (bit >= CCS_MAX_PATH_NUMBER_OPERATION) |
1269 |
|
goto done; |
1270 |
|
ccs_set_group(head); |
1271 |
|
ccs_set_string(head, "file "); |
1272 |
|
ccs_set_string(head, ccs_path_number_keyword[bit]); |
1273 |
|
ccs_print_name_union(head, &ptr->name); |
1274 |
|
ccs_print_number_union(head, &ptr->number); |
1275 |
|
} else if (acl_type == CCS_TYPE_ENV_ACL) { |
1276 |
|
struct ccs_env_acl *ptr = |
1277 |
|
container_of(acl, typeof(*ptr), head); |
1278 |
|
ccs_set_group(head); |
1279 |
|
ccs_set_string(head, "misc env "); |
1280 |
|
ccs_set_string(head, ptr->env->name); |
1281 |
|
} else if (acl_type == CCS_TYPE_CAPABILITY_ACL) { |
1282 |
|
struct ccs_capability_acl *ptr = |
1283 |
|
container_of(acl, typeof(*ptr), head); |
1284 |
|
ccs_set_group(head); |
1285 |
|
ccs_set_string(head, "capability "); |
1286 |
|
ccs_set_string(head, ccs_cap2keyword(ptr->operation)); |
1287 |
|
} else if (acl_type == CCS_TYPE_IP_NETWORK_ACL) { |
1288 |
|
struct ccs_ip_network_acl *ptr = |
1289 |
|
container_of(acl, typeof(*ptr), head); |
1290 |
|
bit = ccs_fns(ptr->perm, bit); |
1291 |
|
if (bit >= CCS_MAX_NETWORK_OPERATION) |
1292 |
|
goto done; |
1293 |
|
ccs_set_group(head); |
1294 |
|
ccs_set_string(head, "network "); |
1295 |
|
ccs_set_string(head, ccs_net_protocol_keyword[ptr->protocol]); |
1296 |
|
ccs_set_space(head); |
1297 |
|
ccs_set_string(head, ccs_net_keyword[bit]); |
1298 |
|
ccs_set_space(head); |
1299 |
switch (ptr->address_type) { |
switch (ptr->address_type) { |
1300 |
|
char buf[128]; |
1301 |
case CCS_IP_ADDRESS_TYPE_ADDRESS_GROUP: |
case CCS_IP_ADDRESS_TYPE_ADDRESS_GROUP: |
1302 |
w[0] = "@"; |
ccs_set_string(head, "@"); |
1303 |
w[1] = ptr->address.group->group_name->name; |
ccs_set_string(head, |
1304 |
|
ptr->address.group->group_name->name); |
1305 |
break; |
break; |
1306 |
case CCS_IP_ADDRESS_TYPE_IPv4: |
case CCS_IP_ADDRESS_TYPE_IPv4: |
1307 |
ccs_print_ipv4(buf, sizeof(buf), ptr->address.ipv4.min, |
ccs_print_ipv4(buf, sizeof(buf), ptr->address.ipv4.min, |
1308 |
ptr->address.ipv4.max); |
ptr->address.ipv4.max); |
1309 |
w[0] = buf; |
ccs_io_printf(head, "%s", buf); |
1310 |
break; |
break; |
1311 |
case CCS_IP_ADDRESS_TYPE_IPv6: |
case CCS_IP_ADDRESS_TYPE_IPv6: |
1312 |
ccs_print_ipv6(buf, sizeof(buf), ptr->address.ipv6.min, |
ccs_print_ipv6(buf, sizeof(buf), ptr->address.ipv6.min, |
1313 |
ptr->address.ipv6.max); |
ptr->address.ipv6.max); |
1314 |
w[0] = buf; |
ccs_io_printf(head, "%s", buf); |
1315 |
break; |
break; |
1316 |
} |
} |
1317 |
if (!ccs_io_printf(head, CCS_KEYWORD_ALLOW_NETWORK "%s %s%s", |
ccs_print_number_union(head, &ptr->port); |
1318 |
ccs_net2keyword(bit), w[0], w[1]) || |
} else if (acl_type == CCS_TYPE_SIGNAL_ACL) { |
1319 |
!ccs_print_number_union(head, &ptr->port) || |
struct ccs_signal_acl *ptr = |
1320 |
!ccs_print_condition(head, cond)) |
container_of(acl, typeof(*ptr), head); |
1321 |
goto out; |
ccs_set_group(head); |
1322 |
|
ccs_set_string(head, "ipc signal "); |
1323 |
|
ccs_io_printf(head, "%u ", ptr->sig); |
1324 |
|
ccs_set_string(head, ptr->domainname->name); |
1325 |
|
} else if (acl_type == CCS_TYPE_MOUNT_ACL) { |
1326 |
|
struct ccs_mount_acl *ptr = |
1327 |
|
container_of(acl, typeof(*ptr), head); |
1328 |
|
ccs_set_group(head); |
1329 |
|
ccs_io_printf(head, "file mount"); |
1330 |
|
ccs_print_name_union(head, &ptr->dev_name); |
1331 |
|
ccs_print_name_union(head, &ptr->dir_name); |
1332 |
|
ccs_print_name_union(head, &ptr->fs_type); |
1333 |
|
ccs_print_number_union(head, &ptr->flags); |
1334 |
|
} |
1335 |
|
head->r.bit = bit + 1; |
1336 |
|
if (acl->cond) { |
1337 |
|
head->r.print_cond_part = true; |
1338 |
|
head->r.cond_step = 0; |
1339 |
|
if (!ccs_flush(head)) |
1340 |
|
return false; |
1341 |
|
print_cond_part: |
1342 |
|
if (!ccs_print_condition(head, acl->cond)) |
1343 |
|
return false; |
1344 |
|
head->r.print_cond_part = false; |
1345 |
|
} else { |
1346 |
|
ccs_set_lf(head); |
1347 |
} |
} |
1348 |
head->read_bit = 0; |
switch (acl_type) { |
1349 |
return true; |
case CCS_TYPE_PATH_ACL: |
1350 |
out: |
case CCS_TYPE_MKDEV_ACL: |
1351 |
head->read_bit = bit; |
case CCS_TYPE_PATH2_ACL: |
1352 |
head->read_avail = pos; |
case CCS_TYPE_PATH_NUMBER_ACL: |
1353 |
return false; |
case CCS_TYPE_IP_NETWORK_ACL: |
1354 |
} |
goto next; |
|
|
|
|
/** |
|
|
* ccs_print_signal_acl - Print a signal ACL entry. |
|
|
* |
|
|
* @head: Pointer to "struct ccs_io_buffer". |
|
|
* @ptr: Pointer to "struct signale_acl". |
|
|
* @cond: Pointer to "struct ccs_condition". May be NULL. |
|
|
* |
|
|
* Returns true on success, false otherwise. |
|
|
*/ |
|
|
static bool ccs_print_signal_acl(struct ccs_io_buffer *head, |
|
|
struct ccs_signal_acl *ptr, |
|
|
const struct ccs_condition *cond) |
|
|
{ |
|
|
const int pos = head->read_avail; |
|
|
if (!ccs_io_printf(head, CCS_KEYWORD_ALLOW_SIGNAL "%u %s", |
|
|
ptr->sig, ptr->domainname->name) || |
|
|
!ccs_print_condition(head, cond)) { |
|
|
head->read_avail = pos; |
|
|
return false; |
|
1355 |
} |
} |
1356 |
|
done: |
1357 |
|
head->r.bit = 0; |
1358 |
return true; |
return true; |
1359 |
} |
} |
1360 |
|
|
1361 |
/** |
/** |
1362 |
* ccs_print_execute_handler_record - Print an execute handler ACL entry. |
* ccs_read_domain2 - Read domain policy. |
|
* |
|
|
* @head: Pointer to "struct ccs_io_buffer". |
|
|
* @keyword: Name of the keyword. |
|
|
* @ptr: Pointer to "struct ccs_execute_handler_record". |
|
1363 |
* |
* |
1364 |
* Returns true on success, false otherwise. |
* @head: Pointer to "struct ccs_io_buffer". |
1365 |
*/ |
* @domain: Pointer to "struct ccs_domain_info". |
|
static bool ccs_print_execute_handler_record(struct ccs_io_buffer *head, |
|
|
const char *keyword, |
|
|
struct ccs_execute_handler_record |
|
|
*ptr) |
|
|
{ |
|
|
return ccs_io_printf(head, "%s %s\n", keyword, ptr->handler->name); |
|
|
} |
|
|
|
|
|
/** |
|
|
* ccs_print_mount_acl - Print a mount ACL entry. |
|
1366 |
* |
* |
1367 |
* @head: Pointer to "struct ccs_io_buffer". |
* Caller holds ccs_read_lock(). |
|
* @ptr: Pointer to "struct ccs_mount_acl". |
|
|
* @cond: Pointer to "struct ccs_condition". May be NULL. |
|
1368 |
* |
* |
1369 |
* Returns true on success, false otherwise. |
* Returns true on success, false otherwise. |
1370 |
*/ |
*/ |
1371 |
static bool ccs_print_mount_acl(struct ccs_io_buffer *head, |
static bool ccs_read_domain2(struct ccs_io_buffer *head, |
1372 |
struct ccs_mount_acl *ptr, |
struct ccs_domain_info *domain) |
|
const struct ccs_condition *cond) |
|
1373 |
{ |
{ |
1374 |
const int pos = head->read_avail; |
list_for_each_cookie(head->r.acl, &domain->acl_info_list) { |
1375 |
if (!ccs_io_printf(head, CCS_KEYWORD_ALLOW_MOUNT) || |
struct ccs_acl_info *ptr = |
1376 |
!ccs_print_name_union(head, &ptr->dev_name) || |
list_entry(head->r.acl, typeof(*ptr), list); |
1377 |
!ccs_print_name_union(head, &ptr->dir_name) || |
if (!ccs_print_entry(head, ptr)) |
1378 |
!ccs_print_name_union(head, &ptr->fs_type) || |
return false; |
|
!ccs_print_number_union(head, &ptr->flags) || |
|
|
!ccs_print_condition(head, cond)) { |
|
|
head->read_avail = pos; |
|
|
return false; |
|
1379 |
} |
} |
1380 |
|
head->r.acl = NULL; |
1381 |
return true; |
return true; |
1382 |
} |
} |
1383 |
|
|
1384 |
/** |
/** |
|
* ccs_print_entry - Print an ACL entry. |
|
|
* |
|
|
* @head: Pointer to "struct ccs_io_buffer". |
|
|
* @ptr: Pointer to an ACL entry. |
|
|
* |
|
|
* Returns true on success, false otherwise. |
|
|
*/ |
|
|
static bool ccs_print_entry(struct ccs_io_buffer *head, |
|
|
struct ccs_acl_info *ptr) |
|
|
{ |
|
|
const struct ccs_condition *cond = ptr->cond; |
|
|
const u8 acl_type = ptr->type; |
|
|
if (ptr->is_deleted) |
|
|
return true; |
|
|
if (acl_type == CCS_TYPE_PATH_ACL) { |
|
|
struct ccs_path_acl *acl |
|
|
= container_of(ptr, struct ccs_path_acl, head); |
|
|
return ccs_print_path_acl(head, acl, cond); |
|
|
} |
|
|
if (acl_type == CCS_TYPE_EXECUTE_HANDLER) { |
|
|
struct ccs_execute_handler_record *acl |
|
|
= container_of(ptr, struct ccs_execute_handler_record, |
|
|
head); |
|
|
const char *keyword = CCS_KEYWORD_EXECUTE_HANDLER; |
|
|
return ccs_print_execute_handler_record(head, keyword, acl); |
|
|
} |
|
|
if (acl_type == CCS_TYPE_DENIED_EXECUTE_HANDLER) { |
|
|
struct ccs_execute_handler_record *acl |
|
|
= container_of(ptr, struct ccs_execute_handler_record, |
|
|
head); |
|
|
const char *keyword = CCS_KEYWORD_DENIED_EXECUTE_HANDLER; |
|
|
return ccs_print_execute_handler_record(head, keyword, acl); |
|
|
} |
|
|
if (head->read_execute_only) |
|
|
return true; |
|
|
if (acl_type == CCS_TYPE_PATH_NUMBER3_ACL) { |
|
|
struct ccs_path_number3_acl *acl |
|
|
= container_of(ptr, struct ccs_path_number3_acl, head); |
|
|
return ccs_print_path_number3_acl(head, acl, cond); |
|
|
} |
|
|
if (acl_type == CCS_TYPE_PATH2_ACL) { |
|
|
struct ccs_path2_acl *acl |
|
|
= container_of(ptr, struct ccs_path2_acl, head); |
|
|
return ccs_print_path2_acl(head, acl, cond); |
|
|
} |
|
|
if (acl_type == CCS_TYPE_PATH_NUMBER_ACL) { |
|
|
struct ccs_path_number_acl *acl |
|
|
= container_of(ptr, struct ccs_path_number_acl, head); |
|
|
return ccs_print_path_number_acl(head, acl, cond); |
|
|
} |
|
|
if (acl_type == CCS_TYPE_ENV_ACL) { |
|
|
struct ccs_env_acl *acl |
|
|
= container_of(ptr, struct ccs_env_acl, head); |
|
|
return ccs_print_env_acl(head, acl, cond); |
|
|
} |
|
|
if (acl_type == CCS_TYPE_CAPABILITY_ACL) { |
|
|
struct ccs_capability_acl *acl |
|
|
= container_of(ptr, struct ccs_capability_acl, head); |
|
|
return ccs_print_capability_acl(head, acl, cond); |
|
|
} |
|
|
if (acl_type == CCS_TYPE_IP_NETWORK_ACL) { |
|
|
struct ccs_ip_network_acl *acl |
|
|
= container_of(ptr, struct ccs_ip_network_acl, head); |
|
|
return ccs_print_network_acl(head, acl, cond); |
|
|
} |
|
|
if (acl_type == CCS_TYPE_SIGNAL_ACL) { |
|
|
struct ccs_signal_acl *acl |
|
|
= container_of(ptr, struct ccs_signal_acl, head); |
|
|
return ccs_print_signal_acl(head, acl, cond); |
|
|
} |
|
|
if (acl_type == CCS_TYPE_MOUNT_ACL) { |
|
|
struct ccs_mount_acl *acl |
|
|
= container_of(ptr, struct ccs_mount_acl, head); |
|
|
return ccs_print_mount_acl(head, acl, cond); |
|
|
} |
|
|
BUG(); /* This must not happen. */ |
|
|
return false; |
|
|
} |
|
|
|
|
|
/** |
|
1385 |
* ccs_read_domain - Read domain policy. |
* ccs_read_domain - Read domain policy. |
1386 |
* |
* |
1387 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1390 |
*/ |
*/ |
1391 |
static void ccs_read_domain(struct ccs_io_buffer *head) |
static void ccs_read_domain(struct ccs_io_buffer *head) |
1392 |
{ |
{ |
1393 |
struct list_head *dpos; |
if (head->r.eof) |
|
struct list_head *apos; |
|
|
if (head->read_eof) |
|
1394 |
return; |
return; |
1395 |
if (head->read_step == 0) |
list_for_each_cookie(head->r.domain, &ccs_domain_list) { |
1396 |
head->read_step = 1; |
struct ccs_domain_info *domain = |
1397 |
list_for_each_cookie(dpos, head->read_var1, &ccs_domain_list) { |
list_entry(head->r.domain, typeof(*domain), list); |
1398 |
struct ccs_domain_info *domain; |
switch (head->r.step) { |
1399 |
const char *quota_exceeded = ""; |
u8 i; |
1400 |
const char *transition_failed = ""; |
case 0: |
1401 |
const char *ignore_global_allow_read = ""; |
if (domain->is_deleted && |
1402 |
const char *ignore_global_allow_env = ""; |
!head->r.print_this_domain_only) |
1403 |
domain = list_entry(dpos, struct ccs_domain_info, list); |
continue; |
1404 |
if (head->read_step != 1) |
/* Print domainname and flags. */ |
1405 |
goto acl_loop; |
ccs_set_string(head, domain->domainname->name); |
1406 |
if (domain->is_deleted && !head->read_single_domain) |
ccs_set_lf(head); |
1407 |
continue; |
ccs_io_printf(head, CCS_KEYWORD_USE_PROFILE "%u\n", |
1408 |
/* Print domainname and flags. */ |
domain->profile); |
1409 |
if (domain->quota_warned) |
ccs_io_printf(head, CCS_KEYWORD_USE_GROUP "%u\n", |
1410 |
quota_exceeded = CCS_KEYWORD_QUOTA_EXCEEDED "\n"; |
domain->group); |
1411 |
if (domain->domain_transition_failed) |
for (i = 0; i < CCS_MAX_DOMAIN_INFO_FLAGS; i++) |
1412 |
transition_failed = CCS_KEYWORD_TRANSITION_FAILED "\n"; |
if (domain->flags[i]) |
1413 |
if (domain->ignore_global_allow_read) |
ccs_set_string(head, ccs_dif[i]); |
1414 |
ignore_global_allow_read |
head->r.step++; |
1415 |
= CCS_KEYWORD_IGNORE_GLOBAL_ALLOW_READ "\n"; |
ccs_set_lf(head); |
1416 |
if (domain->ignore_global_allow_env) |
/* fall through */ |
1417 |
ignore_global_allow_env |
case 1: |
1418 |
= CCS_KEYWORD_IGNORE_GLOBAL_ALLOW_ENV "\n"; |
if (!ccs_read_domain2(head, domain)) |
|
if (!ccs_io_printf(head, "%s\n" CCS_KEYWORD_USE_PROFILE "%u\n" |
|
|
"%s%s%s%s\n", domain->domainname->name, |
|
|
domain->profile, quota_exceeded, |
|
|
transition_failed, |
|
|
ignore_global_allow_read, |
|
|
ignore_global_allow_env)) |
|
|
return; |
|
|
head->read_step = 2; |
|
|
acl_loop: |
|
|
if (head->read_step == 3) |
|
|
goto tail_mark; |
|
|
/* Print ACL entries in the domain. */ |
|
|
list_for_each_cookie(apos, head->read_var2, |
|
|
&domain->acl_info_list) { |
|
|
struct ccs_acl_info *ptr |
|
|
= list_entry(apos, struct ccs_acl_info, list); |
|
|
if (!ccs_print_entry(head, ptr)) |
|
1419 |
return; |
return; |
1420 |
|
head->r.step++; |
1421 |
|
if (!ccs_set_lf(head)) |
1422 |
|
return; |
1423 |
|
/* fall through */ |
1424 |
|
case 2: |
1425 |
|
head->r.step = 0; |
1426 |
|
if (head->r.print_this_domain_only) |
1427 |
|
goto done; |
1428 |
} |
} |
|
head->read_step = 3; |
|
|
tail_mark: |
|
|
if (!ccs_io_printf(head, "\n")) |
|
|
return; |
|
|
head->read_step = 1; |
|
|
if (head->read_single_domain) |
|
|
break; |
|
1429 |
} |
} |
1430 |
head->read_eof = true; |
done: |
1431 |
|
head->r.eof = true; |
1432 |
} |
} |
1433 |
|
|
1434 |
/** |
/** |
1479 |
*/ |
*/ |
1480 |
static void ccs_read_domain_profile(struct ccs_io_buffer *head) |
static void ccs_read_domain_profile(struct ccs_io_buffer *head) |
1481 |
{ |
{ |
1482 |
struct list_head *pos; |
if (head->r.eof) |
|
if (head->read_eof) |
|
1483 |
return; |
return; |
1484 |
list_for_each_cookie(pos, head->read_var1, &ccs_domain_list) { |
list_for_each_cookie(head->r.domain, &ccs_domain_list) { |
1485 |
struct ccs_domain_info *domain; |
struct ccs_domain_info *domain = |
1486 |
domain = list_entry(pos, struct ccs_domain_info, list); |
list_entry(head->r.domain, typeof(*domain), list); |
1487 |
if (domain->is_deleted) |
if (domain->is_deleted) |
1488 |
continue; |
continue; |
1489 |
if (!ccs_io_printf(head, "%u %s\n", domain->profile, |
if (!ccs_flush(head)) |
|
domain->domainname->name)) |
|
1490 |
return; |
return; |
1491 |
|
ccs_io_printf(head, "%u ", domain->profile); |
1492 |
|
ccs_set_string(head, domain->domainname->name); |
1493 |
|
ccs_set_lf(head); |
1494 |
} |
} |
1495 |
head->read_eof = true; |
head->r.eof = true; |
1496 |
} |
} |
1497 |
|
|
1498 |
/** |
/** |
1504 |
*/ |
*/ |
1505 |
static int ccs_write_pid(struct ccs_io_buffer *head) |
static int ccs_write_pid(struct ccs_io_buffer *head) |
1506 |
{ |
{ |
1507 |
head->read_eof = false; |
head->r.eof = false; |
1508 |
return 0; |
return 0; |
1509 |
} |
} |
1510 |
|
|
1530 |
u32 ccs_flags = 0; |
u32 ccs_flags = 0; |
1531 |
/* Accessing write_buf is safe because head->io_sem is held. */ |
/* Accessing write_buf is safe because head->io_sem is held. */ |
1532 |
if (!buf) { |
if (!buf) { |
1533 |
head->read_eof = true; |
head->r.eof = true; |
1534 |
return; /* Do nothing if open(O_RDONLY). */ |
return; /* Do nothing if open(O_RDONLY). */ |
1535 |
} |
} |
1536 |
if (head->read_avail || head->read_eof) |
if (head->r.w_pos || head->r.eof) |
1537 |
return; |
return; |
1538 |
head->read_eof = true; |
head->r.eof = true; |
1539 |
if (ccs_str_starts(&buf, "info ")) |
if (ccs_str_starts(&buf, "info ")) |
1540 |
task_info = true; |
task_info = true; |
1541 |
if (ccs_str_starts(&buf, "global-pid ")) |
if (ccs_str_starts(&buf, "global-pid ")) |
1557 |
ccs_tasklist_unlock(); |
ccs_tasklist_unlock(); |
1558 |
if (!domain) |
if (!domain) |
1559 |
return; |
return; |
1560 |
if (!task_info) |
if (!task_info) { |
1561 |
ccs_io_printf(head, "%u %u %s", pid, domain->profile, |
ccs_io_printf(head, "%u %u ", pid, domain->profile); |
1562 |
domain->domainname->name); |
ccs_set_string(head, domain->domainname->name); |
1563 |
else |
} else { |
1564 |
ccs_io_printf(head, "%u manager=%s execute_handler=%s " |
ccs_io_printf(head, "%u manager=%s execute_handler=%s " |
1565 |
"state[0]=%u state[1]=%u state[2]=%u", pid, |
"state[0]=%u state[1]=%u state[2]=%u", pid, |
1566 |
ccs_yesno(ccs_flags & |
ccs_yesno(ccs_flags & |
1570 |
(u8) (ccs_flags >> 24), |
(u8) (ccs_flags >> 24), |
1571 |
(u8) (ccs_flags >> 16), |
(u8) (ccs_flags >> 16), |
1572 |
(u8) (ccs_flags >> 8)); |
(u8) (ccs_flags >> 8)); |
1573 |
|
} |
1574 |
} |
} |
1575 |
|
|
1576 |
|
static const char *ccs_transition_type[CCS_MAX_TRANSITION_TYPE] = { |
1577 |
|
[CCS_TRANSITION_CONTROL_NO_INITIALIZE] |
1578 |
|
= CCS_KEYWORD_NO_INITIALIZE_DOMAIN, |
1579 |
|
[CCS_TRANSITION_CONTROL_INITIALIZE] = CCS_KEYWORD_INITIALIZE_DOMAIN, |
1580 |
|
[CCS_TRANSITION_CONTROL_NO_KEEP] = CCS_KEYWORD_NO_KEEP_DOMAIN, |
1581 |
|
[CCS_TRANSITION_CONTROL_KEEP] = CCS_KEYWORD_KEEP_DOMAIN |
1582 |
|
}; |
1583 |
|
|
1584 |
|
static const char *ccs_group_name[CCS_MAX_GROUP] = { |
1585 |
|
[CCS_PATH_GROUP] = CCS_KEYWORD_PATH_GROUP, |
1586 |
|
[CCS_NUMBER_GROUP] = CCS_KEYWORD_NUMBER_GROUP, |
1587 |
|
[CCS_ADDRESS_GROUP] = CCS_KEYWORD_ADDRESS_GROUP |
1588 |
|
}; |
1589 |
|
|
1590 |
/** |
/** |
1591 |
* ccs_write_exception - Write exception policy. |
* ccs_write_exception - Write exception policy. |
1592 |
* |
* |
1601 |
u8 i; |
u8 i; |
1602 |
static const struct { |
static const struct { |
1603 |
const char *keyword; |
const char *keyword; |
1604 |
int (*write) (char *, const bool, const u8); |
int (*write) (char *, const bool); |
1605 |
} ccs_callback[10] = { |
} ccs_callback[3] = { |
|
{ CCS_KEYWORD_NO_KEEP_DOMAIN, ccs_write_domain_keeper }, |
|
|
{ CCS_KEYWORD_NO_INITIALIZE_DOMAIN, |
|
|
ccs_write_domain_initializer }, |
|
|
{ CCS_KEYWORD_KEEP_DOMAIN, ccs_write_domain_keeper }, |
|
|
{ CCS_KEYWORD_INITIALIZE_DOMAIN, |
|
|
ccs_write_domain_initializer }, |
|
1606 |
{ CCS_KEYWORD_AGGREGATOR, ccs_write_aggregator }, |
{ CCS_KEYWORD_AGGREGATOR, ccs_write_aggregator }, |
|
{ CCS_KEYWORD_ALLOW_READ, ccs_write_global_read }, |
|
|
{ CCS_KEYWORD_ALLOW_ENV, ccs_write_global_env }, |
|
1607 |
{ CCS_KEYWORD_FILE_PATTERN, ccs_write_pattern }, |
{ CCS_KEYWORD_FILE_PATTERN, ccs_write_pattern }, |
|
{ CCS_KEYWORD_DENY_REWRITE, ccs_write_no_rewrite }, |
|
1608 |
{ CCS_KEYWORD_DENY_AUTOBIND, ccs_write_reserved_port } |
{ CCS_KEYWORD_DENY_AUTOBIND, ccs_write_reserved_port } |
1609 |
}; |
}; |
1610 |
static const char *ccs_name[CCS_MAX_GROUP] = { |
for (i = 0; i < 3; i++) |
|
[CCS_PATH_GROUP] = CCS_KEYWORD_PATH_GROUP, |
|
|
[CCS_NUMBER_GROUP] = CCS_KEYWORD_NUMBER_GROUP, |
|
|
[CCS_ADDRESS_GROUP] = CCS_KEYWORD_ADDRESS_GROUP |
|
|
}; |
|
|
for (i = 0; i < 10; i++) { |
|
1611 |
if (ccs_str_starts(&data, ccs_callback[i].keyword)) |
if (ccs_str_starts(&data, ccs_callback[i].keyword)) |
1612 |
return ccs_callback[i].write(data, is_delete, i < 2); |
return ccs_callback[i].write(data, is_delete); |
1613 |
} |
for (i = 0; i < CCS_MAX_TRANSITION_TYPE; i++) |
1614 |
for (i = 0; i < CCS_MAX_GROUP; i++) { |
if (ccs_str_starts(&data, ccs_transition_type[i])) |
1615 |
if (ccs_str_starts(&data, ccs_name[i])) |
return ccs_write_transition_control(data, is_delete, |
1616 |
|
i); |
1617 |
|
for (i = 0; i < CCS_MAX_GROUP; i++) |
1618 |
|
if (ccs_str_starts(&data, ccs_group_name[i])) |
1619 |
return ccs_write_group(data, is_delete, i); |
return ccs_write_group(data, is_delete, i); |
1620 |
|
if (ccs_str_starts(&data, "acl_group ")) { |
1621 |
|
unsigned int group; |
1622 |
|
if (sscanf(data, "%u", &group) == 1 && |
1623 |
|
group < CCS_MAX_ACL_GROUPS) { |
1624 |
|
data = strchr(data, ' '); |
1625 |
|
if (data) |
1626 |
|
return ccs_write_domain2(data + 1, |
1627 |
|
&ccs_acl_group[group], |
1628 |
|
is_delete); |
1629 |
|
} |
1630 |
} |
} |
1631 |
return -EINVAL; |
return -EINVAL; |
1632 |
} |
} |
1643 |
*/ |
*/ |
1644 |
static bool ccs_read_group(struct ccs_io_buffer *head, const int idx) |
static bool ccs_read_group(struct ccs_io_buffer *head, const int idx) |
1645 |
{ |
{ |
1646 |
struct list_head *gpos; |
list_for_each_cookie(head->r.group, &ccs_group_list[idx]) { |
|
struct list_head *mpos; |
|
|
const char *w[3] = { "", "", "" }; |
|
|
if (idx == CCS_PATH_GROUP) |
|
|
w[0] = CCS_KEYWORD_PATH_GROUP; |
|
|
else if (idx == CCS_NUMBER_GROUP) |
|
|
w[0] = CCS_KEYWORD_NUMBER_GROUP; |
|
|
else if (idx == CCS_ADDRESS_GROUP) |
|
|
w[0] = CCS_KEYWORD_ADDRESS_GROUP; |
|
|
list_for_each_cookie(gpos, head->read_var1, &ccs_group_list[idx]) { |
|
1647 |
struct ccs_group *group = |
struct ccs_group *group = |
1648 |
list_entry(gpos, struct ccs_group, head.list); |
list_entry(head->r.group, typeof(*group), head.list); |
1649 |
w[1] = group->group_name->name; |
list_for_each_cookie(head->r.acl, &group->member_list) { |
|
list_for_each_cookie(mpos, head->read_var2, |
|
|
&group->member_list) { |
|
|
char buffer[128]; |
|
1650 |
struct ccs_acl_head *ptr = |
struct ccs_acl_head *ptr = |
1651 |
list_entry(mpos, struct ccs_acl_head, list); |
list_entry(head->r.acl, typeof(*ptr), list); |
1652 |
if (ptr->is_deleted) |
if (ptr->is_deleted) |
1653 |
continue; |
continue; |
1654 |
|
if (!ccs_flush(head)) |
1655 |
|
return false; |
1656 |
|
ccs_set_string(head, ccs_group_name[idx]); |
1657 |
|
ccs_set_string(head, group->group_name->name); |
1658 |
if (idx == CCS_PATH_GROUP) { |
if (idx == CCS_PATH_GROUP) { |
1659 |
w[2] = container_of(ptr, struct ccs_path_group, |
ccs_set_space(head); |
1660 |
head)->member_name->name; |
ccs_set_string(head, container_of |
1661 |
|
(ptr, struct ccs_path_group, |
1662 |
|
head)->member_name->name); |
1663 |
} else if (idx == CCS_NUMBER_GROUP) { |
} else if (idx == CCS_NUMBER_GROUP) { |
1664 |
w[2] = buffer; |
ccs_print_number_union(head, &container_of |
1665 |
ccs_print_number(buffer, sizeof(buffer), |
(ptr, struct ccs_number_group, |
1666 |
&container_of |
head)->number); |
|
(ptr, struct ccs_number_group, |
|
|
head)->number); |
|
1667 |
} else if (idx == CCS_ADDRESS_GROUP) { |
} else if (idx == CCS_ADDRESS_GROUP) { |
1668 |
|
char buffer[128]; |
1669 |
struct ccs_address_group *member = |
struct ccs_address_group *member = |
1670 |
container_of(ptr, typeof(*member), |
container_of(ptr, typeof(*member), |
1671 |
head); |
head); |
|
w[2] = buffer; |
|
1672 |
if (member->is_ipv6) |
if (member->is_ipv6) |
1673 |
ccs_print_ipv6(buffer, sizeof(buffer), |
ccs_print_ipv6(buffer, sizeof(buffer), |
1674 |
member->min.ipv6, |
member->min.ipv6, |
1677 |
ccs_print_ipv4(buffer, sizeof(buffer), |
ccs_print_ipv4(buffer, sizeof(buffer), |
1678 |
member->min.ipv4, |
member->min.ipv4, |
1679 |
member->max.ipv4); |
member->max.ipv4); |
1680 |
|
ccs_io_printf(head, " %s", buffer); |
1681 |
} |
} |
1682 |
if (!ccs_io_printf(head, "%s%s %s\n", w[0], w[1], |
ccs_set_lf(head); |
|
w[2])) |
|
|
return false; |
|
1683 |
} |
} |
1684 |
|
head->r.acl = NULL; |
1685 |
} |
} |
1686 |
|
head->r.group = NULL; |
1687 |
return true; |
return true; |
1688 |
} |
} |
1689 |
|
|
1699 |
*/ |
*/ |
1700 |
static bool ccs_read_policy(struct ccs_io_buffer *head, const int idx) |
static bool ccs_read_policy(struct ccs_io_buffer *head, const int idx) |
1701 |
{ |
{ |
1702 |
struct list_head *pos; |
list_for_each_cookie(head->r.acl, &ccs_policy_list[idx]) { |
1703 |
list_for_each_cookie(pos, head->read_var2, &ccs_policy_list[idx]) { |
struct ccs_acl_head *acl = |
1704 |
const char *w[4] = { "", "", "", "" }; |
container_of(head->r.acl, typeof(*acl), list); |
|
char buffer[16]; |
|
|
struct ccs_acl_head *acl = container_of(pos, typeof(*acl), |
|
|
list); |
|
1705 |
if (acl->is_deleted) |
if (acl->is_deleted) |
1706 |
continue; |
continue; |
1707 |
|
if (!ccs_flush(head)) |
1708 |
|
return false; |
1709 |
switch (idx) { |
switch (idx) { |
1710 |
case CCS_ID_DOMAIN_KEEPER: |
case CCS_ID_TRANSITION_CONTROL: |
|
{ |
|
|
struct ccs_domain_keeper *ptr = |
|
|
container_of(acl, typeof(*ptr), head); |
|
|
w[0] = ptr->is_not ? |
|
|
CCS_KEYWORD_NO_KEEP_DOMAIN : |
|
|
CCS_KEYWORD_KEEP_DOMAIN; |
|
|
if (ptr->program) { |
|
|
w[1] = ptr->program->name; |
|
|
w[2] = " from "; |
|
|
} |
|
|
w[3] = ptr->domainname->name; |
|
|
} |
|
|
break; |
|
|
case CCS_ID_DOMAIN_INITIALIZER: |
|
1711 |
{ |
{ |
1712 |
struct ccs_domain_initializer *ptr = |
struct ccs_transition_control *ptr = |
1713 |
container_of(acl, typeof(*ptr), head); |
container_of(acl, typeof(*ptr), head); |
1714 |
w[0] = ptr->is_not ? |
ccs_set_string(head, |
1715 |
CCS_KEYWORD_NO_INITIALIZE_DOMAIN : |
ccs_transition_type[ptr->type]); |
1716 |
CCS_KEYWORD_INITIALIZE_DOMAIN; |
ccs_set_string(head, ptr->program ? |
1717 |
w[1] = ptr->program->name; |
ptr->program->name : "any"); |
1718 |
if (ptr->domainname) { |
ccs_set_string(head, " from "); |
1719 |
w[2] = " from "; |
ccs_set_string(head, ptr->domainname ? |
1720 |
w[3] = ptr->domainname->name; |
ptr->domainname->name : "any"); |
|
} |
|
1721 |
} |
} |
1722 |
break; |
break; |
1723 |
case CCS_ID_AGGREGATOR: |
case CCS_ID_AGGREGATOR: |
1724 |
{ |
{ |
1725 |
struct ccs_aggregator *ptr = |
struct ccs_aggregator *ptr = |
1726 |
container_of(acl, typeof(*ptr), head); |
container_of(acl, typeof(*ptr), head); |
1727 |
w[0] = CCS_KEYWORD_AGGREGATOR; |
ccs_set_string(head, CCS_KEYWORD_AGGREGATOR); |
1728 |
w[1] = ptr->original_name->name; |
ccs_set_string(head, ptr->original_name->name); |
1729 |
w[2] = " "; |
ccs_set_space(head); |
1730 |
w[3] = ptr->aggregated_name->name; |
ccs_set_string(head, |
1731 |
} |
ptr->aggregated_name->name); |
|
break; |
|
|
case CCS_ID_GLOBAL_READ: |
|
|
{ |
|
|
struct ccs_global_read *ptr = |
|
|
container_of(acl, typeof(*ptr), head); |
|
|
w[0] = CCS_KEYWORD_ALLOW_READ; |
|
|
w[1] = ptr->filename->name; |
|
1732 |
} |
} |
1733 |
break; |
break; |
1734 |
case CCS_ID_PATTERN: |
case CCS_ID_PATTERN: |
1735 |
{ |
{ |
1736 |
struct ccs_pattern *ptr = |
struct ccs_pattern *ptr = |
1737 |
container_of(acl, typeof(*ptr), head); |
container_of(acl, typeof(*ptr), head); |
1738 |
w[0] = CCS_KEYWORD_FILE_PATTERN; |
ccs_set_string(head, CCS_KEYWORD_FILE_PATTERN); |
1739 |
w[1] = ptr->pattern->name; |
ccs_set_string(head, ptr->pattern->name); |
|
} |
|
|
break; |
|
|
case CCS_ID_NO_REWRITE: |
|
|
{ |
|
|
struct ccs_no_rewrite *ptr = |
|
|
container_of(acl, typeof(*ptr), head); |
|
|
w[0] = CCS_KEYWORD_DENY_REWRITE; |
|
|
w[1] = ptr->pattern->name; |
|
|
} |
|
|
break; |
|
|
case CCS_ID_GLOBAL_ENV: |
|
|
{ |
|
|
struct ccs_global_env *ptr = |
|
|
container_of(acl, typeof(*ptr), head); |
|
|
w[0] = CCS_KEYWORD_ALLOW_ENV; |
|
|
w[1] = ptr->env->name; |
|
1740 |
} |
} |
1741 |
break; |
break; |
1742 |
case CCS_ID_RESERVEDPORT: |
case CCS_ID_RESERVEDPORT: |
1745 |
container_of(acl, typeof(*ptr), head); |
container_of(acl, typeof(*ptr), head); |
1746 |
const u16 min_port = ptr->min_port; |
const u16 min_port = ptr->min_port; |
1747 |
const u16 max_port = ptr->max_port; |
const u16 max_port = ptr->max_port; |
1748 |
w[0] = CCS_KEYWORD_DENY_AUTOBIND; |
ccs_set_string(head, |
1749 |
snprintf(buffer, sizeof(buffer) - 1, "%u%c%u", |
CCS_KEYWORD_DENY_AUTOBIND); |
1750 |
min_port, min_port != max_port ? |
ccs_io_printf(head, "%u", min_port); |
1751 |
'-' : '\0', max_port); |
if (min_port != max_port) |
1752 |
buffer[sizeof(buffer) - 1] = '\0'; |
ccs_io_printf(head, "-%u", max_port); |
|
w[1] = buffer; |
|
1753 |
} |
} |
1754 |
break; |
break; |
1755 |
|
default: |
1756 |
|
continue; |
1757 |
} |
} |
1758 |
if (!ccs_io_printf(head, "%s%s%s%s\n", w[0], w[1], w[2], w[3])) |
ccs_set_lf(head); |
|
return false; |
|
1759 |
} |
} |
1760 |
|
head->r.acl = NULL; |
1761 |
return true; |
return true; |
1762 |
} |
} |
1763 |
|
|
1770 |
*/ |
*/ |
1771 |
static void ccs_read_exception(struct ccs_io_buffer *head) |
static void ccs_read_exception(struct ccs_io_buffer *head) |
1772 |
{ |
{ |
1773 |
if (head->read_eof) |
if (head->r.eof) |
1774 |
return; |
return; |
1775 |
while (head->read_step < CCS_MAX_POLICY && |
while (head->r.step < CCS_MAX_POLICY && |
1776 |
ccs_read_policy(head, head->read_step)) |
ccs_read_policy(head, head->r.step)) |
1777 |
head->read_step++; |
head->r.step++; |
1778 |
if (head->read_step < CCS_MAX_POLICY) |
if (head->r.step < CCS_MAX_POLICY) |
1779 |
return; |
return; |
1780 |
while (head->read_step < CCS_MAX_POLICY + CCS_MAX_GROUP && |
while (head->r.step < CCS_MAX_POLICY + CCS_MAX_GROUP && |
1781 |
ccs_read_group(head, head->read_step - CCS_MAX_POLICY)) |
ccs_read_group(head, head->r.step - CCS_MAX_POLICY)) |
1782 |
head->read_step++; |
head->r.step++; |
1783 |
head->read_eof = head->read_step == CCS_MAX_POLICY + CCS_MAX_GROUP; |
if (head->r.step < CCS_MAX_POLICY + CCS_MAX_GROUP) |
1784 |
} |
return; |
1785 |
|
while (head->r.step < CCS_MAX_POLICY + CCS_MAX_GROUP |
1786 |
/** |
+ CCS_MAX_ACL_GROUPS) { |
1787 |
* ccs_get_argv0 - Get argv[0]. |
head->r.group_index = head->r.step - CCS_MAX_POLICY |
1788 |
* |
- CCS_MAX_GROUP; |
1789 |
* @ee: Pointer to "struct ccs_execve". |
if (!ccs_read_domain2(head, |
1790 |
* |
&ccs_acl_group[head->r.group_index])) |
1791 |
* Returns true on success, false otherwise. |
return; |
1792 |
*/ |
head->r.step++; |
|
static bool ccs_get_argv0(struct ccs_execve *ee) |
|
|
{ |
|
|
struct linux_binprm *bprm = ee->bprm; |
|
|
char *arg_ptr = ee->tmp; |
|
|
int arg_len = 0; |
|
|
unsigned long pos = bprm->p; |
|
|
int offset = pos % PAGE_SIZE; |
|
|
bool done = false; |
|
|
if (!bprm->argc) |
|
|
goto out; |
|
|
while (1) { |
|
|
if (!ccs_dump_page(bprm, pos, &ee->dump)) |
|
|
goto out; |
|
|
pos += PAGE_SIZE - offset; |
|
|
/* Read. */ |
|
|
while (offset < PAGE_SIZE) { |
|
|
const char *kaddr = ee->dump.data; |
|
|
const unsigned char c = kaddr[offset++]; |
|
|
if (c && arg_len < CCS_EXEC_TMPSIZE - 10) { |
|
|
if (c == '\\') { |
|
|
arg_ptr[arg_len++] = '\\'; |
|
|
arg_ptr[arg_len++] = '\\'; |
|
|
} else if (c > ' ' && c < 127) { |
|
|
arg_ptr[arg_len++] = c; |
|
|
} else { |
|
|
arg_ptr[arg_len++] = '\\'; |
|
|
arg_ptr[arg_len++] = (c >> 6) + '0'; |
|
|
arg_ptr[arg_len++] |
|
|
= ((c >> 3) & 7) + '0'; |
|
|
arg_ptr[arg_len++] = (c & 7) + '0'; |
|
|
} |
|
|
} else { |
|
|
arg_ptr[arg_len] = '\0'; |
|
|
done = true; |
|
|
break; |
|
|
} |
|
|
} |
|
|
offset = 0; |
|
|
if (done) |
|
|
break; |
|
|
} |
|
|
return true; |
|
|
out: |
|
|
return false; |
|
|
} |
|
|
|
|
|
/** |
|
|
* ccs_get_execute_condition - Get condition part for execute requests. |
|
|
* |
|
|
* @ee: Pointer to "struct ccs_execve". |
|
|
* |
|
|
* Returns pointer to "struct ccs_condition" on success, NULL otherwise. |
|
|
*/ |
|
|
static struct ccs_condition *ccs_get_execute_condition(struct ccs_execve |
|
|
*ee) |
|
|
{ |
|
|
struct ccs_condition *cond; |
|
|
char *buf; |
|
|
int len = 256; |
|
|
char *realpath = NULL; |
|
|
char *argv0 = NULL; |
|
|
const struct ccs_profile *profile = ccs_profile(ccs_current_domain()-> |
|
|
profile); |
|
|
if (profile->learning->learning_exec_realpath) { |
|
|
struct file *file = ee->bprm->file; |
|
|
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 20) |
|
|
struct path path = { file->f_vfsmnt, file->f_dentry }; |
|
|
realpath = ccs_realpath_from_path(&path); |
|
|
#else |
|
|
realpath = ccs_realpath_from_path(&file->f_path); |
|
|
#endif |
|
|
if (realpath) |
|
|
len += strlen(realpath) + 17; |
|
|
} |
|
|
if (profile->learning->learning_exec_argv0) { |
|
|
if (ccs_get_argv0(ee)) { |
|
|
argv0 = ee->tmp; |
|
|
len += strlen(argv0) + 16; |
|
|
} |
|
|
} |
|
|
buf = kmalloc(len, CCS_GFP_FLAGS); |
|
|
if (!buf) { |
|
|
kfree(realpath); |
|
|
return NULL; |
|
|
} |
|
|
snprintf(buf, len - 1, "if"); |
|
|
if (current->ccs_flags & CCS_TASK_IS_EXECUTE_HANDLER) { |
|
|
const int pos = strlen(buf); |
|
|
snprintf(buf + pos, len - pos - 1, |
|
|
" task.type=execute_handler"); |
|
|
} |
|
|
if (realpath) { |
|
|
const int pos = strlen(buf); |
|
|
snprintf(buf + pos, len - pos - 1, " exec.realpath=\"%s\"", |
|
|
realpath); |
|
|
kfree(realpath); |
|
|
} |
|
|
if (argv0) { |
|
|
const int pos = strlen(buf); |
|
|
snprintf(buf + pos, len - pos - 1, " exec.argv[0]=\"%s\"", |
|
|
argv0); |
|
|
} |
|
|
cond = ccs_get_condition(buf); |
|
|
kfree(buf); |
|
|
return cond; |
|
|
} |
|
|
|
|
|
/** |
|
|
* ccs_get_symlink_condition - Get condition part for symlink requests. |
|
|
* |
|
|
* @r: Pointer to "struct ccs_request_info". |
|
|
* |
|
|
* Returns pointer to "struct ccs_condition" on success, NULL otherwise. |
|
|
*/ |
|
|
static struct ccs_condition *ccs_get_symlink_condition(struct ccs_request_info |
|
|
*r) |
|
|
{ |
|
|
struct ccs_condition *cond; |
|
|
char *buf; |
|
|
int len = 256; |
|
|
const char *symlink = NULL; |
|
|
const struct ccs_profile *profile = ccs_profile(r->profile); |
|
|
if (profile->learning->learning_symlink_target) { |
|
|
symlink = r->obj->symlink_target->name; |
|
|
len += strlen(symlink) + 18; |
|
1793 |
} |
} |
1794 |
buf = kmalloc(len, CCS_GFP_FLAGS); |
head->r.eof = true; |
|
if (!buf) |
|
|
return NULL; |
|
|
snprintf(buf, len - 1, "if"); |
|
|
if (current->ccs_flags & CCS_TASK_IS_EXECUTE_HANDLER) { |
|
|
const int pos = strlen(buf); |
|
|
snprintf(buf + pos, len - pos - 1, |
|
|
" task.type=execute_handler"); |
|
|
} |
|
|
if (symlink) { |
|
|
const int pos = strlen(buf); |
|
|
snprintf(buf + pos, len - pos - 1, " symlink.target=\"%s\"", |
|
|
symlink); |
|
|
} |
|
|
cond = ccs_get_condition(buf); |
|
|
kfree(buf); |
|
|
return cond; |
|
1795 |
} |
} |
1796 |
|
|
1797 |
/* Wait queue for ccs_query_list. */ |
/* Wait queue for ccs_query_list. */ |
1801 |
static DEFINE_SPINLOCK(ccs_query_list_lock); |
static DEFINE_SPINLOCK(ccs_query_list_lock); |
1802 |
|
|
1803 |
/* Structure for query. */ |
/* Structure for query. */ |
1804 |
struct ccs_query_entry { |
struct ccs_query { |
1805 |
struct list_head list; |
struct list_head list; |
1806 |
char *query; |
char *query; |
1807 |
int query_len; |
int query_len; |
1810 |
int answer; |
int answer; |
1811 |
}; |
}; |
1812 |
|
|
1813 |
/* The list for "struct ccs_query_entry". */ |
/* The list for "struct ccs_query". */ |
1814 |
static LIST_HEAD(ccs_query_list); |
static LIST_HEAD(ccs_query_list); |
1815 |
|
|
1816 |
/* Number of "struct file" referring /proc/ccs/query interface. */ |
/* Number of "struct file" referring /proc/ccs/query interface. */ |
1817 |
static atomic_t ccs_query_observers = ATOMIC_INIT(0); |
static atomic_t ccs_query_observers = ATOMIC_INIT(0); |
1818 |
|
|
1819 |
|
static void ccs_truncate(char *str) |
1820 |
|
{ |
1821 |
|
while (* (unsigned char *) str > (unsigned char) ' ') |
1822 |
|
str++; |
1823 |
|
*str = '\0'; |
1824 |
|
} |
1825 |
|
|
1826 |
/** |
/** |
1827 |
* ccs_supervisor - Ask for the supervisor's decision. |
* ccs_supervisor - Ask for the supervisor's decision. |
1828 |
* |
* |
1829 |
* @r: Pointer to "struct ccs_request_info". |
* @r: Pointer to "struct ccs_request_info". |
1830 |
* @fmt: The printf()'s format string, followed by parameters. |
* @fmt: The printf()'s format string, followed by parameters. |
1831 |
* |
* |
1832 |
* Returns 0 if the supervisor decided to permit the access request which |
* Returns 0 if the supervisor decided to permit the access request which |
1833 |
* violated the policy in enforcing mode, CCS_RETRY_REQUEST if the supervisor |
* violated the policy in enforcing mode, CCS_RETRY_REQUEST if the supervisor |
1841 |
int pos; |
int pos; |
1842 |
int len; |
int len; |
1843 |
static unsigned int ccs_serial; |
static unsigned int ccs_serial; |
1844 |
struct ccs_query_entry *ccs_query_entry = NULL; |
struct ccs_query *entry = NULL; |
1845 |
bool quota_exceeded = false; |
bool quota_exceeded = false; |
1846 |
char *header; |
char *header; |
1847 |
struct ccs_domain_info * const domain = ccs_current_domain(); |
struct ccs_domain_info * const domain = ccs_current_domain(); |
1848 |
switch (r->mode) { |
va_start(args, fmt); |
1849 |
|
len = vsnprintf((char *) &pos, sizeof(pos) - 1, fmt, args) + 80; |
1850 |
|
va_end(args); |
1851 |
|
if (r->mode == CCS_CONFIG_LEARNING) { |
1852 |
char *buffer; |
char *buffer; |
1853 |
struct ccs_condition *cond; |
char *realpath = NULL; |
1854 |
case CCS_CONFIG_LEARNING: |
char *argv0 = NULL; |
1855 |
|
char *symlink = NULL; |
1856 |
|
char *handler = NULL; |
1857 |
|
const struct ccs_preference *pref; |
1858 |
if (!ccs_domain_quota_ok(r)) |
if (!ccs_domain_quota_ok(r)) |
1859 |
return 0; |
return 0; |
1860 |
va_start(args, fmt); |
header = ccs_init_log(&len, r); |
1861 |
len = vsnprintf((char *) &pos, sizeof(pos) - 1, fmt, args) + 4; |
if (!header) |
|
va_end(args); |
|
|
buffer = kmalloc(len, CCS_GFP_FLAGS); |
|
|
if (!buffer) |
|
1862 |
return 0; |
return 0; |
1863 |
va_start(args, fmt); |
pref = &ccs_profile(r->profile)->preference; |
1864 |
vsnprintf(buffer, len - 1, fmt, args); |
/* strstr() will return NULL if ordering is wrong. */ |
1865 |
va_end(args); |
if (r->param_type == CCS_TYPE_PATH_ACL && |
1866 |
ccs_normalize_line(buffer); |
r->param.path.operation == CCS_TYPE_EXECUTE) { |
1867 |
if (r->ee && !strncmp(buffer, "allow_execute ", 14)) |
if (pref->learning_exec_argv0) { |
1868 |
cond = ccs_get_execute_condition(r->ee); |
argv0 = strstr(header, " argv[]={ \""); |
1869 |
else if (r->obj && r->obj->symlink_target) |
if (argv0) { |
1870 |
cond = ccs_get_symlink_condition(r); |
argv0 += 10; |
1871 |
else if ((current->ccs_flags & CCS_TASK_IS_EXECUTE_HANDLER)) { |
ccs_truncate(argv0); |
1872 |
char str[] = "if task.type=execute_handler"; |
} |
1873 |
cond = ccs_get_condition(str); |
} |
1874 |
} else |
if (pref->learning_exec_realpath) { |
1875 |
cond = NULL; |
realpath = strstr(header, |
1876 |
ccs_write_domain2(buffer, domain, cond, false); |
" exec={ realpath=\""); |
1877 |
ccs_put_condition(cond); |
if (realpath) { |
1878 |
kfree(buffer); |
realpath += 8; |
1879 |
/* fall through */ |
ccs_truncate(realpath); |
1880 |
case CCS_CONFIG_PERMISSIVE: |
} |
1881 |
|
} |
1882 |
|
} else if (r->param_type == CCS_TYPE_PATH_ACL && |
1883 |
|
r->param.path.operation == CCS_TYPE_SYMLINK && |
1884 |
|
pref->learning_symlink_target) { |
1885 |
|
symlink = strstr(header, " symlink.target=\""); |
1886 |
|
if (symlink) |
1887 |
|
ccs_truncate(symlink + 1); |
1888 |
|
} |
1889 |
|
handler = strstr(header, "type=execute_handler"); |
1890 |
|
if (handler) |
1891 |
|
ccs_truncate(handler); |
1892 |
|
buffer = kmalloc(len, CCS_GFP_FLAGS); |
1893 |
|
if (buffer) { |
1894 |
|
va_start(args, fmt); |
1895 |
|
vsnprintf(buffer, len - 1, fmt, args); |
1896 |
|
va_end(args); |
1897 |
|
if (handler || realpath || argv0 || symlink) { |
1898 |
|
ccs_addprintf(buffer, len, " if"); |
1899 |
|
if (handler) |
1900 |
|
ccs_addprintf(buffer, len, " task.%s", |
1901 |
|
handler); |
1902 |
|
if (realpath) |
1903 |
|
ccs_addprintf(buffer, len, " exec.%s", |
1904 |
|
realpath); |
1905 |
|
if (argv0) |
1906 |
|
ccs_addprintf(buffer, len, |
1907 |
|
" exec.argv[0]=%s", |
1908 |
|
argv0); |
1909 |
|
if (symlink) |
1910 |
|
ccs_addprintf(buffer, len, "%s", |
1911 |
|
symlink); |
1912 |
|
} |
1913 |
|
ccs_normalize_line(buffer); |
1914 |
|
ccs_write_domain2(buffer, domain, false); |
1915 |
|
kfree(buffer); |
1916 |
|
} |
1917 |
|
kfree(header); |
1918 |
return 0; |
return 0; |
1919 |
} |
} |
1920 |
|
if (r->mode != CCS_CONFIG_ENFORCING) |
1921 |
|
return 0; |
1922 |
if (!atomic_read(&ccs_query_observers)) { |
if (!atomic_read(&ccs_query_observers)) { |
1923 |
int i; |
int i; |
1924 |
if (current->ccs_flags & CCS_DONT_SLEEP_ON_ENFORCE_ERROR) |
if (current->ccs_flags & CCS_DONT_SLEEP_ON_ENFORCE_ERROR) |
1925 |
return -EPERM; |
return -EPERM; |
1926 |
for (i = 0; i < ccs_profile(domain->profile)->enforcing-> |
for (i = 0; i < ccs_profile(domain->profile)->preference. |
1927 |
enforcing_penalty; i++) { |
enforcing_penalty; i++) { |
1928 |
set_current_state(TASK_INTERRUPTIBLE); |
set_current_state(TASK_INTERRUPTIBLE); |
1929 |
schedule_timeout(HZ / 10); |
schedule_timeout(HZ / 10); |
1930 |
} |
} |
1931 |
return -EPERM; |
return -EPERM; |
1932 |
} |
} |
1933 |
va_start(args, fmt); |
header = ccs_init_log(&len, r); |
|
len = vsnprintf((char *) &pos, sizeof(pos) - 1, fmt, args) + 32; |
|
|
va_end(args); |
|
|
header = ccs_init_audit_log(&len, r); |
|
1934 |
if (!header) |
if (!header) |
1935 |
goto out; |
goto out; |
1936 |
ccs_query_entry = kzalloc(sizeof(*ccs_query_entry), CCS_GFP_FLAGS); |
entry = kzalloc(sizeof(*entry), CCS_GFP_FLAGS); |
1937 |
if (!ccs_query_entry) |
if (!entry) |
1938 |
goto out; |
goto out; |
1939 |
len = ccs_round2(len); |
len = ccs_round2(len); |
1940 |
ccs_query_entry->query = kzalloc(len, CCS_GFP_FLAGS); |
entry->query = kzalloc(len, CCS_GFP_FLAGS); |
1941 |
if (!ccs_query_entry->query) |
if (!entry->query) |
1942 |
goto out; |
goto out; |
|
INIT_LIST_HEAD(&ccs_query_entry->list); |
|
1943 |
spin_lock(&ccs_query_list_lock); |
spin_lock(&ccs_query_list_lock); |
1944 |
if (ccs_quota_for_query && ccs_query_memory_size + len + |
if (ccs_quota_for_query && ccs_query_memory_size + len + |
1945 |
sizeof(*ccs_query_entry) >= ccs_quota_for_query) { |
sizeof(*entry) >= ccs_quota_for_query) { |
1946 |
quota_exceeded = true; |
quota_exceeded = true; |
1947 |
} else { |
} else { |
1948 |
ccs_query_memory_size += len + sizeof(*ccs_query_entry); |
ccs_query_memory_size += len + sizeof(*entry); |
1949 |
ccs_query_entry->serial = ccs_serial++; |
entry->serial = ccs_serial++; |
1950 |
} |
} |
1951 |
spin_unlock(&ccs_query_list_lock); |
spin_unlock(&ccs_query_list_lock); |
1952 |
if (quota_exceeded) |
if (quota_exceeded) |
1953 |
goto out; |
goto out; |
1954 |
pos = snprintf(ccs_query_entry->query, len - 1, "Q%u-%hu\n%s", |
pos = snprintf(entry->query, len - 1, "Q%u-%hu\n%s", |
1955 |
ccs_query_entry->serial, r->retry, header); |
entry->serial, r->retry, header); |
1956 |
kfree(header); |
kfree(header); |
1957 |
header = NULL; |
header = NULL; |
1958 |
va_start(args, fmt); |
va_start(args, fmt); |
1959 |
vsnprintf(ccs_query_entry->query + pos, len - 1 - pos, fmt, args); |
vsnprintf(entry->query + pos, len - 1 - pos, fmt, args); |
1960 |
ccs_query_entry->query_len = strlen(ccs_query_entry->query) + 1; |
entry->query_len = strlen(entry->query) + 1; |
1961 |
va_end(args); |
va_end(args); |
1962 |
spin_lock(&ccs_query_list_lock); |
spin_lock(&ccs_query_list_lock); |
1963 |
list_add_tail(&ccs_query_entry->list, &ccs_query_list); |
list_add_tail(&entry->list, &ccs_query_list); |
1964 |
spin_unlock(&ccs_query_list_lock); |
spin_unlock(&ccs_query_list_lock); |
1965 |
/* Give 10 seconds for supervisor's opinion. */ |
/* Give 10 seconds for supervisor's opinion. */ |
1966 |
for (ccs_query_entry->timer = 0; |
for (entry->timer = 0; |
1967 |
atomic_read(&ccs_query_observers) && ccs_query_entry->timer < 100; |
atomic_read(&ccs_query_observers) && entry->timer < 100; |
1968 |
ccs_query_entry->timer++) { |
entry->timer++) { |
1969 |
wake_up(&ccs_query_wait); |
wake_up(&ccs_query_wait); |
1970 |
set_current_state(TASK_INTERRUPTIBLE); |
set_current_state(TASK_INTERRUPTIBLE); |
1971 |
schedule_timeout(HZ / 10); |
schedule_timeout(HZ / 10); |
1972 |
if (ccs_query_entry->answer) |
if (entry->answer) |
1973 |
break; |
break; |
1974 |
} |
} |
1975 |
spin_lock(&ccs_query_list_lock); |
spin_lock(&ccs_query_list_lock); |
1976 |
list_del(&ccs_query_entry->list); |
list_del(&entry->list); |
1977 |
ccs_query_memory_size -= len + sizeof(*ccs_query_entry); |
ccs_query_memory_size -= len + sizeof(*entry); |
1978 |
spin_unlock(&ccs_query_list_lock); |
spin_unlock(&ccs_query_list_lock); |
1979 |
switch (ccs_query_entry->answer) { |
switch (entry->answer) { |
1980 |
case 3: /* Asked to retry by administrator. */ |
case 3: /* Asked to retry by administrator. */ |
1981 |
error = CCS_RETRY_REQUEST; |
error = CCS_RETRY_REQUEST; |
1982 |
r->retry++; |
r->retry++; |
1993 |
break; |
break; |
1994 |
} |
} |
1995 |
out: |
out: |
1996 |
if (ccs_query_entry) |
if (entry) |
1997 |
kfree(ccs_query_entry->query); |
kfree(entry->query); |
1998 |
kfree(ccs_query_entry); |
kfree(entry); |
1999 |
kfree(header); |
kfree(header); |
2000 |
return error; |
return error; |
2001 |
} |
} |
2018 |
for (i = 0; i < 2; i++) { |
for (i = 0; i < 2; i++) { |
2019 |
spin_lock(&ccs_query_list_lock); |
spin_lock(&ccs_query_list_lock); |
2020 |
list_for_each(tmp, &ccs_query_list) { |
list_for_each(tmp, &ccs_query_list) { |
2021 |
struct ccs_query_entry *ptr = |
struct ccs_query *ptr = |
2022 |
list_entry(tmp, struct ccs_query_entry, list); |
list_entry(tmp, typeof(*ptr), list); |
2023 |
if (ptr->answer) |
if (ptr->answer) |
2024 |
continue; |
continue; |
2025 |
found = true; |
found = true; |
2046 |
int pos = 0; |
int pos = 0; |
2047 |
int len = 0; |
int len = 0; |
2048 |
char *buf; |
char *buf; |
2049 |
if (head->read_avail) |
if (head->r.w_pos) |
2050 |
return; |
return; |
2051 |
if (head->read_buf) { |
if (head->read_buf) { |
2052 |
kfree(head->read_buf); |
kfree(head->read_buf); |
2053 |
head->read_buf = NULL; |
head->read_buf = NULL; |
|
head->readbuf_size = 0; |
|
2054 |
} |
} |
2055 |
spin_lock(&ccs_query_list_lock); |
spin_lock(&ccs_query_list_lock); |
2056 |
list_for_each(tmp, &ccs_query_list) { |
list_for_each(tmp, &ccs_query_list) { |
2057 |
struct ccs_query_entry *ptr |
struct ccs_query *ptr = list_entry(tmp, typeof(*ptr), list); |
|
= list_entry(tmp, struct ccs_query_entry, list); |
|
2058 |
if (ptr->answer) |
if (ptr->answer) |
2059 |
continue; |
continue; |
2060 |
if (pos++ != head->read_step) |
if (pos++ != head->r.query_index) |
2061 |
continue; |
continue; |
2062 |
len = ptr->query_len; |
len = ptr->query_len; |
2063 |
break; |
break; |
2064 |
} |
} |
2065 |
spin_unlock(&ccs_query_list_lock); |
spin_unlock(&ccs_query_list_lock); |
2066 |
if (!len) { |
if (!len) { |
2067 |
head->read_step = 0; |
head->r.query_index = 0; |
2068 |
return; |
return; |
2069 |
} |
} |
2070 |
buf = kzalloc(len, CCS_GFP_FLAGS); |
buf = kzalloc(len, CCS_GFP_FLAGS); |
2073 |
pos = 0; |
pos = 0; |
2074 |
spin_lock(&ccs_query_list_lock); |
spin_lock(&ccs_query_list_lock); |
2075 |
list_for_each(tmp, &ccs_query_list) { |
list_for_each(tmp, &ccs_query_list) { |
2076 |
struct ccs_query_entry *ptr |
struct ccs_query *ptr = list_entry(tmp, typeof(*ptr), list); |
|
= list_entry(tmp, struct ccs_query_entry, list); |
|
2077 |
if (ptr->answer) |
if (ptr->answer) |
2078 |
continue; |
continue; |
2079 |
if (pos++ != head->read_step) |
if (pos++ != head->r.query_index) |
2080 |
continue; |
continue; |
2081 |
/* |
/* |
2082 |
* Some query can be skipped because ccs_query_list |
* Some query can be skipped because ccs_query_list |
2088 |
} |
} |
2089 |
spin_unlock(&ccs_query_list_lock); |
spin_unlock(&ccs_query_list_lock); |
2090 |
if (buf[0]) { |
if (buf[0]) { |
|
head->read_avail = len; |
|
|
head->readbuf_size = head->read_avail; |
|
2091 |
head->read_buf = buf; |
head->read_buf = buf; |
2092 |
head->read_step++; |
head->r.w[head->r.w_pos++] = buf; |
2093 |
|
head->r.query_index++; |
2094 |
} else { |
} else { |
2095 |
kfree(buf); |
kfree(buf); |
2096 |
} |
} |
2111 |
unsigned int answer; |
unsigned int answer; |
2112 |
spin_lock(&ccs_query_list_lock); |
spin_lock(&ccs_query_list_lock); |
2113 |
list_for_each(tmp, &ccs_query_list) { |
list_for_each(tmp, &ccs_query_list) { |
2114 |
struct ccs_query_entry *ptr |
struct ccs_query *ptr = list_entry(tmp, typeof(*ptr), list); |
|
= list_entry(tmp, struct ccs_query_entry, list); |
|
2115 |
ptr->timer = 0; |
ptr->timer = 0; |
2116 |
} |
} |
2117 |
spin_unlock(&ccs_query_list_lock); |
spin_unlock(&ccs_query_list_lock); |
2119 |
return -EINVAL; |
return -EINVAL; |
2120 |
spin_lock(&ccs_query_list_lock); |
spin_lock(&ccs_query_list_lock); |
2121 |
list_for_each(tmp, &ccs_query_list) { |
list_for_each(tmp, &ccs_query_list) { |
2122 |
struct ccs_query_entry *ptr |
struct ccs_query *ptr = list_entry(tmp, typeof(*ptr), list); |
|
= list_entry(tmp, struct ccs_query_entry, list); |
|
2123 |
if (ptr->serial != serial) |
if (ptr->serial != serial) |
2124 |
continue; |
continue; |
2125 |
if (!ptr->answer) |
if (!ptr->answer) |
2137 |
*/ |
*/ |
2138 |
static void ccs_read_version(struct ccs_io_buffer *head) |
static void ccs_read_version(struct ccs_io_buffer *head) |
2139 |
{ |
{ |
2140 |
if (head->read_eof) |
if (head->r.eof) |
2141 |
return; |
return; |
2142 |
ccs_io_printf(head, "1.7.2"); |
ccs_set_string(head, "1.8.0-pre"); |
2143 |
head->read_eof = true; |
head->r.eof = true; |
2144 |
} |
} |
2145 |
|
|
2146 |
/** |
/** |
2150 |
*/ |
*/ |
2151 |
static void ccs_read_self_domain(struct ccs_io_buffer *head) |
static void ccs_read_self_domain(struct ccs_io_buffer *head) |
2152 |
{ |
{ |
2153 |
if (head->read_eof) |
if (head->r.eof) |
2154 |
return; |
return; |
2155 |
/* |
/* |
2156 |
* ccs_current_domain()->domainname != NULL because every process |
* ccs_current_domain()->domainname != NULL because every process |
2157 |
* belongs to a domain and the domain's name cannot be NULL. |
* belongs to a domain and the domain's name cannot be NULL. |
2158 |
*/ |
*/ |
2159 |
ccs_io_printf(head, "%s", ccs_current_domain()->domainname->name); |
ccs_io_printf(head, "%s", ccs_current_domain()->domainname->name); |
2160 |
head->read_eof = true; |
head->r.eof = true; |
2161 |
} |
} |
2162 |
|
|
2163 |
/** |
/** |
2187 |
#ifdef CONFIG_CCSECURITY_AUDIT |
#ifdef CONFIG_CCSECURITY_AUDIT |
2188 |
case CCS_GRANTLOG: /* /proc/ccs/grant_log */ |
case CCS_GRANTLOG: /* /proc/ccs/grant_log */ |
2189 |
case CCS_REJECTLOG: /* /proc/ccs/reject_log */ |
case CCS_REJECTLOG: /* /proc/ccs/reject_log */ |
2190 |
head->poll = ccs_poll_audit_log; |
head->poll = ccs_poll_log; |
2191 |
head->read = ccs_read_audit_log; |
head->read = ccs_read_log; |
2192 |
break; |
break; |
2193 |
#endif |
#endif |
2194 |
case CCS_SELFDOMAIN: /* /proc/ccs/self_domain */ |
case CCS_SELFDOMAIN: /* /proc/ccs/self_domain */ |
2316 |
int ccs_read_control(struct file *file, char __user *buffer, |
int ccs_read_control(struct file *file, char __user *buffer, |
2317 |
const int buffer_len) |
const int buffer_len) |
2318 |
{ |
{ |
2319 |
int len = 0; |
int len; |
2320 |
struct ccs_io_buffer *head = file->private_data; |
struct ccs_io_buffer *head = file->private_data; |
|
char *cp; |
|
2321 |
int idx; |
int idx; |
2322 |
if (!head->read) |
if (!head->read) |
2323 |
return -ENOSYS; |
return -ENOSYS; |
2325 |
return -EFAULT; |
return -EFAULT; |
2326 |
if (mutex_lock_interruptible(&head->io_sem)) |
if (mutex_lock_interruptible(&head->io_sem)) |
2327 |
return -EINTR; |
return -EINTR; |
2328 |
|
head->read_user_buf = buffer; |
2329 |
|
head->read_user_buf_avail = buffer_len; |
2330 |
idx = ccs_read_lock(); |
idx = ccs_read_lock(); |
2331 |
while (1) { |
if (ccs_flush(head)) |
2332 |
/* Call the policy handler. */ |
/* Call the policy handler. */ |
2333 |
head->read(head); |
head->read(head); |
2334 |
/* Write to buffer. */ |
ccs_flush(head); |
|
len = head->read_avail; |
|
|
if (len || head->poll || head->read_eof) |
|
|
break; |
|
|
len = head->readbuf_size * 2; |
|
|
cp = kzalloc(len, CCS_GFP_FLAGS); |
|
|
if (!cp) { |
|
|
len = -ENOMEM; |
|
|
goto out; |
|
|
} |
|
|
kfree(head->read_buf); |
|
|
head->read_buf = cp; |
|
|
head->readbuf_size = len; |
|
|
} |
|
|
if (len > buffer_len) |
|
|
len = buffer_len; |
|
|
if (!len) |
|
|
goto out; |
|
|
/* head->read_buf changes by some functions. */ |
|
|
cp = head->read_buf; |
|
|
if (copy_to_user(buffer, cp, len)) { |
|
|
len = -EFAULT; |
|
|
goto out; |
|
|
} |
|
|
head->read_avail -= len; |
|
|
memmove(cp, cp + len, head->read_avail); |
|
|
out: |
|
2335 |
ccs_read_unlock(idx); |
ccs_read_unlock(idx); |
2336 |
|
len = head->read_user_buf - buffer; |
2337 |
mutex_unlock(&head->io_sem); |
mutex_unlock(&head->io_sem); |
2338 |
return len; |
return len; |
2339 |
} |
} |
2372 |
/* Read a line and dispatch it to the policy handler. */ |
/* Read a line and dispatch it to the policy handler. */ |
2373 |
while (avail_len > 0) { |
while (avail_len > 0) { |
2374 |
char c; |
char c; |
2375 |
if (head->write_avail >= head->writebuf_size - 1) { |
if (head->w.avail >= head->writebuf_size - 1) { |
2376 |
const int len = head->writebuf_size * 2; |
const int len = head->writebuf_size * 2; |
2377 |
char *cp = kzalloc(len, CCS_GFP_FLAGS); |
char *cp = kzalloc(len, CCS_GFP_FLAGS); |
2378 |
if (!cp) { |
if (!cp) { |
2379 |
error = -ENOMEM; |
error = -ENOMEM; |
2380 |
break; |
break; |
2381 |
} |
} |
2382 |
memmove(cp, cp0, head->write_avail); |
memmove(cp, cp0, head->w.avail); |
2383 |
kfree(cp0); |
kfree(cp0); |
2384 |
head->write_buf = cp; |
head->write_buf = cp; |
2385 |
cp0 = cp; |
cp0 = cp; |
2391 |
} |
} |
2392 |
buffer++; |
buffer++; |
2393 |
avail_len--; |
avail_len--; |
2394 |
cp0[head->write_avail++] = c; |
cp0[head->w.avail++] = c; |
2395 |
if (c != '\n') |
if (c != '\n') |
2396 |
continue; |
continue; |
2397 |
cp0[head->write_avail - 1] = '\0'; |
cp0[head->w.avail - 1] = '\0'; |
2398 |
head->write_avail = 0; |
head->w.avail = 0; |
2399 |
ccs_normalize_line(cp0); |
ccs_normalize_line(cp0); |
2400 |
head->write(head); |
head->write(head); |
2401 |
} |
} |