1 |
/* |
/* |
2 |
* security/ccsecurity/policy_io.c |
* security/ccsecurity/policy_io.c |
3 |
* |
* |
4 |
* Copyright (C) 2005-2009 NTT DATA CORPORATION |
* Copyright (C) 2005-2010 NTT DATA CORPORATION |
5 |
* |
* |
6 |
* Version: 1.7.1-pre 2009/10/16 |
* Version: 1.7.2+ 2010/06/04 |
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. |
33 |
.preference.permissive_verbose = true |
.preference.permissive_verbose = true |
34 |
}; |
}; |
35 |
|
|
36 |
|
/* Profile version. Currently only 20090903 is defined. */ |
37 |
|
static unsigned int ccs_profile_version; |
38 |
|
|
39 |
/* Profile table. Memory is allocated as needed. */ |
/* Profile table. Memory is allocated as needed. */ |
40 |
static struct ccs_profile *ccs_profile_ptr[CCS_MAX_PROFILES]; |
static struct ccs_profile *ccs_profile_ptr[CCS_MAX_PROFILES]; |
41 |
|
|
|
/* Lock for protecting "struct ccs_profile"->comment */ |
|
|
static DEFINE_SPINLOCK(ccs_profile_comment_lock); |
|
|
|
|
42 |
/* String table for functionality that takes 4 modes. */ |
/* String table for functionality that takes 4 modes. */ |
43 |
static const char *ccs_mode_4[4] = { |
static const char *ccs_mode[CCS_CONFIG_MAX_MODE] = { |
44 |
"disabled", "learning", "permissive", "enforcing" |
[CCS_CONFIG_DISABLED] = "disabled", |
45 |
|
[CCS_CONFIG_LEARNING] = "learning", |
46 |
|
[CCS_CONFIG_PERMISSIVE] = "permissive", |
47 |
|
[CCS_CONFIG_ENFORCING] = "enforcing" |
48 |
}; |
}; |
49 |
|
|
50 |
/* String table for /proc/ccs/profile */ |
/* String table for /proc/ccs/profile */ |
97 |
= "file::umount", |
= "file::umount", |
98 |
[CCS_MAC_FILE_PIVOT_ROOT] |
[CCS_MAC_FILE_PIVOT_ROOT] |
99 |
= "file::pivot_root", |
= "file::pivot_root", |
100 |
|
[CCS_MAC_FILE_TRANSIT] |
101 |
|
= "file::transit", |
102 |
[CCS_MAC_ENVIRON] |
[CCS_MAC_ENVIRON] |
103 |
= "misc::env", |
= "misc::env", |
104 |
[CCS_MAC_NETWORK_UDP_BIND] |
[CCS_MAC_NETWORK_UDP_BIND] |
249 |
} |
} |
250 |
|
|
251 |
/** |
/** |
252 |
* ccs_find_or_assign_new_profile - Create a new profile. |
* ccs_assign_profile - Create a new profile. |
253 |
* |
* |
254 |
* @profile: Profile number to create. |
* @profile: Profile number to create. |
255 |
* |
* |
256 |
* Returns pointer to "struct ccs_profile" on success, NULL otherwise. |
* Returns pointer to "struct ccs_profile" on success, NULL otherwise. |
257 |
*/ |
*/ |
258 |
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) |
|
259 |
{ |
{ |
260 |
struct ccs_profile *ptr; |
struct ccs_profile *ptr; |
261 |
struct ccs_profile *entry; |
struct ccs_profile *entry; |
264 |
ptr = ccs_profile_ptr[profile]; |
ptr = ccs_profile_ptr[profile]; |
265 |
if (ptr) |
if (ptr) |
266 |
return ptr; |
return ptr; |
267 |
entry = kzalloc(sizeof(*entry), GFP_KERNEL); |
entry = kzalloc(sizeof(*entry), CCS_GFP_FLAGS); |
268 |
mutex_lock(&ccs_policy_lock); |
if (mutex_lock_interruptible(&ccs_policy_lock)) |
269 |
|
goto out; |
270 |
ptr = ccs_profile_ptr[profile]; |
ptr = ccs_profile_ptr[profile]; |
271 |
if (!ptr && ccs_memory_ok(entry, sizeof(*entry))) { |
if (!ptr && ccs_memory_ok(entry, sizeof(*entry))) { |
272 |
ptr = entry; |
ptr = entry; |
283 |
entry = NULL; |
entry = NULL; |
284 |
} |
} |
285 |
mutex_unlock(&ccs_policy_lock); |
mutex_unlock(&ccs_policy_lock); |
286 |
|
out: |
287 |
kfree(entry); |
kfree(entry); |
288 |
return ptr; |
return ptr; |
289 |
} |
} |
291 |
/** |
/** |
292 |
* ccs_check_profile - Check all profiles currently assigned to domains are defined. |
* ccs_check_profile - Check all profiles currently assigned to domains are defined. |
293 |
*/ |
*/ |
294 |
void ccs_check_profile(void) |
static void ccs_check_profile(void) |
295 |
{ |
{ |
296 |
struct ccs_domain_info *domain; |
struct ccs_domain_info *domain; |
297 |
|
const int idx = ccs_read_lock(); |
298 |
ccs_policy_loaded = true; |
ccs_policy_loaded = true; |
299 |
list_for_each_entry_rcu(domain, &ccs_domain_list, list) { |
list_for_each_entry_rcu(domain, &ccs_domain_list, list) { |
300 |
const u8 profile = domain->profile; |
const u8 profile = domain->profile; |
303 |
panic("Profile %u (used by '%s') not defined.\n", |
panic("Profile %u (used by '%s') not defined.\n", |
304 |
profile, domain->domainname->name); |
profile, domain->domainname->name); |
305 |
} |
} |
306 |
|
ccs_read_unlock(idx); |
307 |
|
if (ccs_profile_version != 20090903) |
308 |
|
panic("Profile version %u is not supported.\n", |
309 |
|
ccs_profile_version); |
310 |
|
printk(KERN_INFO "CCSecurity: 1.7.2+ 2010/06/04\n"); |
311 |
|
printk(KERN_INFO "Mandatory Access Control activated.\n"); |
312 |
} |
} |
313 |
|
|
314 |
/** |
/** |
327 |
return ptr; |
return ptr; |
328 |
} |
} |
329 |
|
|
330 |
/** |
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) |
|
331 |
{ |
{ |
332 |
char *data = head->write_buf; |
const char *cp = strstr(string, find); |
333 |
unsigned int i; |
if (cp) { |
334 |
int value; |
cp += strlen(find); |
335 |
int mode; |
if (strncmp(cp, "=yes", 4)) |
336 |
u8 config; |
return 1; |
337 |
bool use_default = false; |
else if (strncmp(cp, "=no", 3)) |
338 |
char *cp; |
return 0; |
|
struct ccs_profile *profile; |
|
|
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; |
|
339 |
} |
} |
340 |
cp = strchr(data, '='); |
return -1; |
341 |
if (!cp) |
} |
342 |
return -EINVAL; |
|
343 |
*cp++ = '\0'; |
static void ccs_set_bool(bool *b, const char *string, const char *find) |
344 |
if (profile != &ccs_default_profile) |
{ |
345 |
use_default = strstr(cp, "use_default") != NULL; |
switch (ccs_find_yesno(string, find)) { |
346 |
if (strstr(cp, "verbose=yes")) |
case 1: |
347 |
value = 1; |
*b = true; |
348 |
else if (strstr(cp, "verbose=no")) |
break; |
349 |
value = 0; |
case 0: |
350 |
else |
*b = false; |
351 |
value = -1; |
break; |
352 |
if (!strcmp(data, "PREFERENCE::audit")) { |
} |
353 |
#ifdef CONFIG_CCSECURITY_AUDIT |
} |
354 |
char *cp2; |
|
355 |
#endif |
static void ccs_set_uint(unsigned int *i, const char *string, const char *find) |
356 |
|
{ |
357 |
|
const char *cp = strstr(string, find); |
358 |
|
if (cp) |
359 |
|
sscanf(cp + strlen(find), "=%u", i); |
360 |
|
} |
361 |
|
|
362 |
|
static void ccs_set_pref(const char *cp, const char *data, |
363 |
|
struct ccs_profile *profile, const bool use_default) |
364 |
|
{ |
365 |
|
struct ccs_preference **pref; |
366 |
|
bool *verbose; |
367 |
|
if (!strcmp(data, "audit")) { |
368 |
if (use_default) { |
if (use_default) { |
369 |
profile->audit = &ccs_default_profile.preference; |
pref = &profile->audit; |
370 |
return 0; |
goto set_default; |
371 |
} |
} |
372 |
profile->audit = &profile->preference; |
profile->audit = &profile->preference; |
373 |
#ifdef CONFIG_CCSECURITY_AUDIT |
#ifdef CONFIG_CCSECURITY_AUDIT |
374 |
cp2 = strstr(cp, "max_grant_log="); |
ccs_set_uint(&profile->preference.audit_max_grant_log, cp, |
375 |
if (cp2) |
"max_grant_log"); |
376 |
sscanf(cp2 + 14, "%u", |
ccs_set_uint(&profile->preference.audit_max_reject_log, cp, |
377 |
&profile->preference.audit_max_grant_log); |
"max_reject_log"); |
|
cp2 = strstr(cp, "max_reject_log="); |
|
|
if (cp2) |
|
|
sscanf(cp2 + 15, "%u", |
|
|
&profile->preference.audit_max_reject_log); |
|
378 |
#endif |
#endif |
379 |
if (strstr(cp, "task_info=yes")) |
ccs_set_bool(&profile->preference.audit_task_info, cp, |
380 |
profile->preference.audit_task_info = true; |
"task_info"); |
381 |
else if (strstr(cp, "task_info=no")) |
ccs_set_bool(&profile->preference.audit_path_info, cp, |
382 |
profile->preference.audit_task_info = false; |
"path_info"); |
383 |
if (strstr(cp, "path_info=yes")) |
return; |
|
profile->preference.audit_path_info = true; |
|
|
else if (strstr(cp, "path_info=no")) |
|
|
profile->preference.audit_path_info = false; |
|
|
return 0; |
|
384 |
} |
} |
385 |
if (!strcmp(data, "PREFERENCE::enforcing")) { |
if (!strcmp(data, "enforcing")) { |
|
char *cp2; |
|
386 |
if (use_default) { |
if (use_default) { |
387 |
profile->enforcing = &ccs_default_profile.preference; |
pref = &profile->enforcing; |
388 |
return 0; |
goto set_default; |
389 |
} |
} |
390 |
profile->enforcing = &profile->preference; |
profile->enforcing = &profile->preference; |
391 |
if (value >= 0) |
ccs_set_uint(&profile->preference.enforcing_penalty, cp, |
392 |
profile->preference.enforcing_verbose = value; |
"penalty"); |
393 |
cp2 = strstr(cp, "penalty="); |
verbose = &profile->preference.enforcing_verbose; |
394 |
if (cp2) |
goto set_verbose; |
|
sscanf(cp2 + 8, "%u", |
|
|
&profile->preference.enforcing_penalty); |
|
|
return 0; |
|
395 |
} |
} |
396 |
if (!strcmp(data, "PREFERENCE::permissive")) { |
if (!strcmp(data, "permissive")) { |
397 |
if (use_default) { |
if (use_default) { |
398 |
profile->permissive = &ccs_default_profile.preference; |
pref = &profile->permissive; |
399 |
return 0; |
goto set_default; |
400 |
} |
} |
401 |
profile->permissive = &profile->preference; |
profile->permissive = &profile->preference; |
402 |
if (value >= 0) |
verbose = &profile->preference.permissive_verbose; |
403 |
profile->preference.permissive_verbose = value; |
goto set_verbose; |
|
return 0; |
|
404 |
} |
} |
405 |
if (!strcmp(data, "PREFERENCE::learning")) { |
if (!strcmp(data, "learning")) { |
|
char *cp2; |
|
406 |
if (use_default) { |
if (use_default) { |
407 |
profile->learning = &ccs_default_profile.preference; |
pref = &profile->learning; |
408 |
return 0; |
goto set_default; |
409 |
} |
} |
410 |
profile->learning = &profile->preference; |
profile->learning = &profile->preference; |
411 |
if (value >= 0) |
ccs_set_uint(&profile->preference.learning_max_entry, cp, |
412 |
profile->preference.learning_verbose = value; |
"max_entry"); |
413 |
cp2 = strstr(cp, "max_entry="); |
ccs_set_bool(&profile->preference.learning_exec_realpath, cp, |
414 |
if (cp2) |
"exec.realpath"); |
415 |
sscanf(cp2 + 10, "%u", |
ccs_set_bool(&profile->preference.learning_exec_argv0, cp, |
416 |
&profile->preference.learning_max_entry); |
"exec.argv0"); |
417 |
if (strstr(cp, "exec.realpath=yes")) |
ccs_set_bool(&profile->preference.learning_symlink_target, cp, |
418 |
profile->preference.learning_exec_realpath = true; |
"symlink.target"); |
419 |
else if (strstr(cp, "exec.realpath=no")) |
verbose = &profile->preference.learning_verbose; |
420 |
profile->preference.learning_exec_realpath = false; |
goto set_verbose; |
421 |
if (strstr(cp, "exec.argv0=yes")) |
} |
422 |
profile->preference.learning_exec_argv0 = true; |
return; |
423 |
else if (strstr(cp, "exec.argv0=no")) |
set_default: |
424 |
profile->preference.learning_exec_argv0 = false; |
*pref = &ccs_default_profile.preference; |
425 |
if (strstr(cp, "symlink.target=yes")) |
return; |
426 |
profile->preference.learning_symlink_target = true; |
set_verbose: |
427 |
else if (strstr(cp, "symlink.target=no")) |
ccs_set_bool(verbose, cp, "verbose"); |
428 |
profile->preference.learning_symlink_target = false; |
} |
429 |
return 0; |
|
430 |
} |
static int ccs_set_mode(const char *cp, char *data, |
431 |
if (profile == &ccs_default_profile) |
struct ccs_profile *profile, const bool use_default) |
432 |
return -EINVAL; |
{ |
433 |
if (!strcmp(data, "COMMENT")) { |
u8 i; |
434 |
const struct ccs_path_info *new_comment = ccs_get_name(cp); |
u8 config; |
|
const struct ccs_path_info *old_comment; |
|
|
/* Protect reader from ccs_put_name(). */ |
|
|
spin_lock(&ccs_profile_comment_lock); |
|
|
old_comment = profile->comment; |
|
|
profile->comment = new_comment; |
|
|
spin_unlock(&ccs_profile_comment_lock); |
|
|
ccs_put_name(old_comment); |
|
|
return 0; |
|
|
} |
|
435 |
if (!strcmp(data, "CONFIG")) { |
if (!strcmp(data, "CONFIG")) { |
436 |
i = CCS_MAX_MAC_INDEX + CCS_MAX_CAPABILITY_INDEX |
i = CCS_MAX_MAC_INDEX + CCS_MAX_CAPABILITY_INDEX |
437 |
+ CCS_MAX_MAC_CATEGORY_INDEX; |
+ CCS_MAX_MAC_CATEGORY_INDEX; |
454 |
if (use_default) { |
if (use_default) { |
455 |
config = CCS_CONFIG_USE_DEFAULT; |
config = CCS_CONFIG_USE_DEFAULT; |
456 |
} else { |
} else { |
457 |
for (mode = 3; mode >= 0; mode--) |
u8 mode; |
458 |
if (strstr(cp, ccs_mode_4[mode])) |
for (mode = 0; mode < CCS_CONFIG_MAX_MODE; mode--) |
459 |
|
if (strstr(cp, ccs_mode[mode])) |
460 |
/* |
/* |
461 |
* Update lower 3 bits in order to distinguish |
* Update lower 3 bits in order to distinguish |
462 |
* 'config' from 'CCS_CONFIG_USE_DEAFULT'. |
* 'config' from 'CCS_CONFIG_USE_DEAFULT'. |
464 |
config = (config & ~7) | mode; |
config = (config & ~7) | mode; |
465 |
#ifdef CONFIG_CCSECURITY_AUDIT |
#ifdef CONFIG_CCSECURITY_AUDIT |
466 |
if (config != CCS_CONFIG_USE_DEFAULT) { |
if (config != CCS_CONFIG_USE_DEFAULT) { |
467 |
if (strstr(cp, "grant_log=yes")) |
switch (ccs_find_yesno(cp, "grant_log")) { |
468 |
|
case 1: |
469 |
config |= CCS_CONFIG_WANT_GRANT_LOG; |
config |= CCS_CONFIG_WANT_GRANT_LOG; |
470 |
else if (strstr(cp, "grant_log=no")) |
break; |
471 |
|
case 0: |
472 |
config &= ~CCS_CONFIG_WANT_GRANT_LOG; |
config &= ~CCS_CONFIG_WANT_GRANT_LOG; |
473 |
if (strstr(cp, "reject_log=yes")) |
break; |
474 |
|
} |
475 |
|
switch (ccs_find_yesno(cp, "reject_log")) { |
476 |
|
case 1: |
477 |
config |= CCS_CONFIG_WANT_REJECT_LOG; |
config |= CCS_CONFIG_WANT_REJECT_LOG; |
478 |
else if (strstr(cp, "reject_log=no")) |
break; |
479 |
|
case 0: |
480 |
config &= ~CCS_CONFIG_WANT_REJECT_LOG; |
config &= ~CCS_CONFIG_WANT_REJECT_LOG; |
481 |
|
break; |
482 |
|
} |
483 |
} |
} |
484 |
#endif |
#endif |
485 |
} |
} |
492 |
} |
} |
493 |
|
|
494 |
/** |
/** |
495 |
|
* ccs_write_profile - Write profile table. |
496 |
|
* |
497 |
|
* @head: Pointer to "struct ccs_io_buffer". |
498 |
|
* |
499 |
|
* Returns 0 on success, negative value otherwise. |
500 |
|
*/ |
501 |
|
static int ccs_write_profile(struct ccs_io_buffer *head) |
502 |
|
{ |
503 |
|
char *data = head->write_buf; |
504 |
|
bool use_default = false; |
505 |
|
char *cp; |
506 |
|
int i; |
507 |
|
struct ccs_profile *profile; |
508 |
|
if (sscanf(data, "PROFILE_VERSION=%u", &ccs_profile_version) == 1) |
509 |
|
return 0; |
510 |
|
i = simple_strtoul(data, &cp, 10); |
511 |
|
if (data == cp) { |
512 |
|
profile = &ccs_default_profile; |
513 |
|
} else { |
514 |
|
if (*cp != '-') |
515 |
|
return -EINVAL; |
516 |
|
data = cp + 1; |
517 |
|
profile = ccs_assign_profile(i); |
518 |
|
if (!profile) |
519 |
|
return -EINVAL; |
520 |
|
} |
521 |
|
cp = strchr(data, '='); |
522 |
|
if (!cp) |
523 |
|
return -EINVAL; |
524 |
|
*cp++ = '\0'; |
525 |
|
if (profile != &ccs_default_profile) |
526 |
|
use_default = strstr(cp, "use_default") != NULL; |
527 |
|
if (ccs_str_starts(&data, "PREFERENCE::")) { |
528 |
|
ccs_set_pref(cp, data, profile, use_default); |
529 |
|
return 0; |
530 |
|
} |
531 |
|
if (profile == &ccs_default_profile) |
532 |
|
return -EINVAL; |
533 |
|
if (!strcmp(data, "COMMENT")) { |
534 |
|
const struct ccs_path_info *old_comment = profile->comment; |
535 |
|
profile->comment = ccs_get_name(cp); |
536 |
|
ccs_put_name(old_comment); |
537 |
|
return 0; |
538 |
|
} |
539 |
|
return ccs_set_mode(cp, data, profile, use_default); |
540 |
|
} |
541 |
|
|
542 |
|
static bool ccs_print_preference(struct ccs_io_buffer *head, const int idx) |
543 |
|
{ |
544 |
|
struct ccs_preference *pref = &ccs_default_profile.preference; |
545 |
|
const struct ccs_profile *profile = idx >= 0 ? |
546 |
|
ccs_profile_ptr[idx] : NULL; |
547 |
|
char buffer[16] = ""; |
548 |
|
if (profile) { |
549 |
|
buffer[sizeof(buffer) - 1] = '\0'; |
550 |
|
snprintf(buffer, sizeof(buffer) - 1, "%u-", idx); |
551 |
|
} |
552 |
|
if (profile) { |
553 |
|
pref = profile->audit; |
554 |
|
if (pref == &ccs_default_profile.preference) |
555 |
|
pref = NULL; |
556 |
|
} |
557 |
|
if (pref && !ccs_io_printf(head, "%sPREFERENCE::%s={ " |
558 |
|
#ifdef CONFIG_CCSECURITY_AUDIT |
559 |
|
"max_grant_log=%u max_reject_log=%u " |
560 |
|
#endif |
561 |
|
"task_info=%s path_info=%s }\n", buffer, |
562 |
|
"audit", |
563 |
|
#ifdef CONFIG_CCSECURITY_AUDIT |
564 |
|
pref->audit_max_grant_log, |
565 |
|
pref->audit_max_reject_log, |
566 |
|
#endif |
567 |
|
ccs_yesno(pref->audit_task_info), |
568 |
|
ccs_yesno(pref->audit_path_info))) |
569 |
|
return false; |
570 |
|
if (profile) { |
571 |
|
pref = profile->learning; |
572 |
|
if (pref == &ccs_default_profile.preference) |
573 |
|
pref = NULL; |
574 |
|
} |
575 |
|
if (pref && !ccs_io_printf(head, "%sPREFERENCE::%s={ " |
576 |
|
"verbose=%s max_entry=%u exec.realpath=%s " |
577 |
|
"exec.argv0=%s symlink.target=%s }\n", |
578 |
|
buffer, "learning", |
579 |
|
ccs_yesno(pref->learning_verbose), |
580 |
|
pref->learning_max_entry, |
581 |
|
ccs_yesno(pref->learning_exec_realpath), |
582 |
|
ccs_yesno(pref->learning_exec_argv0), |
583 |
|
ccs_yesno(pref->learning_symlink_target))) |
584 |
|
return false; |
585 |
|
if (profile) { |
586 |
|
pref = profile->permissive; |
587 |
|
if (pref == &ccs_default_profile.preference) |
588 |
|
pref = NULL; |
589 |
|
} |
590 |
|
if (pref && !ccs_io_printf(head, "%sPREFERENCE::%s={ verbose=%s }\n", |
591 |
|
buffer, "permissive", |
592 |
|
ccs_yesno(pref->permissive_verbose))) |
593 |
|
return false; |
594 |
|
if (profile) { |
595 |
|
pref = profile->enforcing; |
596 |
|
if (pref == &ccs_default_profile.preference) |
597 |
|
pref = NULL; |
598 |
|
} |
599 |
|
return !pref || ccs_io_printf(head, "%sPREFERENCE::%s={ verbose=%s " |
600 |
|
"penalty=%u }\n", buffer, "enforcing", |
601 |
|
ccs_yesno(pref->enforcing_verbose), |
602 |
|
pref->enforcing_penalty); |
603 |
|
} |
604 |
|
|
605 |
|
/** |
606 |
* ccs_read_profile - Read profile table. |
* ccs_read_profile - Read profile table. |
607 |
* |
* |
608 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
615 |
if (head->read_bit) |
if (head->read_bit) |
616 |
goto body; |
goto body; |
617 |
ccs_io_printf(head, "PROFILE_VERSION=%s\n", "20090903"); |
ccs_io_printf(head, "PROFILE_VERSION=%s\n", "20090903"); |
618 |
ccs_io_printf(head, "PREFERENCE::audit={ " |
ccs_print_preference(head, -1); |
|
#ifdef CONFIG_CCSECURITY_AUDIT |
|
|
"max_grant_log=%u max_reject_log=%u " |
|
|
#endif |
|
|
"task_info=%s path_info=%s }\n", |
|
|
#ifdef CONFIG_CCSECURITY_AUDIT |
|
|
ccs_default_profile.preference.audit_max_grant_log, |
|
|
ccs_default_profile.preference.audit_max_reject_log, |
|
|
#endif |
|
|
ccs_yesno(ccs_default_profile.preference. |
|
|
audit_task_info), |
|
|
ccs_yesno(ccs_default_profile.preference. |
|
|
audit_path_info)); |
|
|
ccs_io_printf(head, "PREFERENCE::learning={ verbose=%s max_entry=%u " |
|
|
"exec.realpath=%s exec.argv0=%s symlink.target=%s }\n", |
|
|
ccs_yesno(ccs_default_profile.preference. |
|
|
learning_verbose), |
|
|
ccs_default_profile.preference.learning_max_entry, |
|
|
ccs_yesno(ccs_default_profile.preference. |
|
|
learning_exec_realpath), |
|
|
ccs_yesno(ccs_default_profile.preference. |
|
|
learning_exec_argv0), |
|
|
ccs_yesno(ccs_default_profile.preference. |
|
|
learning_symlink_target)); |
|
|
ccs_io_printf(head, "PREFERENCE::permissive={ verbose=%s }\n", |
|
|
ccs_yesno(ccs_default_profile.preference. |
|
|
permissive_verbose)); |
|
|
ccs_io_printf(head, "PREFERENCE::enforcing={ verbose=%s penalty=%u " |
|
|
"}\n", |
|
|
ccs_yesno(ccs_default_profile.preference. |
|
|
enforcing_verbose), |
|
|
ccs_default_profile.preference.enforcing_penalty); |
|
619 |
head->read_bit = 1; |
head->read_bit = 1; |
620 |
body: |
body: |
621 |
for (index = head->read_step; index < CCS_MAX_PROFILES; index++) { |
for (index = head->read_step; index < CCS_MAX_PROFILES; index++) { |
624 |
int i; |
int i; |
625 |
int pos; |
int pos; |
626 |
const struct ccs_profile *profile = ccs_profile_ptr[index]; |
const struct ccs_profile *profile = ccs_profile_ptr[index]; |
627 |
|
const struct ccs_path_info *comment; |
628 |
head->read_step = index; |
head->read_step = index; |
629 |
if (!profile) |
if (!profile) |
630 |
continue; |
continue; |
631 |
pos = head->read_avail; |
pos = head->read_avail; |
632 |
spin_lock(&ccs_profile_comment_lock); |
comment = profile->comment; |
633 |
done = ccs_io_printf(head, "%u-COMMENT=%s\n", index, |
done = ccs_io_printf(head, "%u-COMMENT=%s\n", index, |
634 |
profile->comment ? profile->comment->name |
comment ? comment->name : ""); |
|
: ""); |
|
|
spin_unlock(&ccs_profile_comment_lock); |
|
635 |
if (!done) |
if (!done) |
636 |
goto out; |
goto out; |
637 |
config = profile->default_config; |
config = profile->default_config; |
638 |
#ifdef CONFIG_CCSECURITY_AUDIT |
#ifdef CONFIG_CCSECURITY_AUDIT |
639 |
if (!ccs_io_printf(head, "%u-CONFIG={ mode=%s grant_log=%s " |
if (!ccs_io_printf(head, "%u-%s%s={ mode=%s " |
640 |
"reject_log=%s }\n", index, |
"grant_log=%s reject_log=%s }\n", index, |
641 |
ccs_mode_4[config & 3], |
"CONFIG", "", ccs_mode[config & 3], |
642 |
ccs_yesno(config & |
ccs_yesno(config & |
643 |
CCS_CONFIG_WANT_GRANT_LOG), |
CCS_CONFIG_WANT_GRANT_LOG), |
644 |
ccs_yesno(config & |
ccs_yesno(config & |
645 |
CCS_CONFIG_WANT_REJECT_LOG))) |
CCS_CONFIG_WANT_REJECT_LOG))) |
646 |
goto out; |
goto out; |
647 |
#else |
#else |
648 |
if (!ccs_io_printf(head, "%u-CONFIG={ mode=%s }\n", index, |
if (!ccs_io_printf(head, "%u-%s%s={ mode=%s }\n", index, |
649 |
ccs_mode_4[config & 3])) |
"CONFIG", "", ccs_mode[config & 3])) |
650 |
goto out; |
goto out; |
651 |
#endif |
#endif |
652 |
for (i = 0; i < CCS_MAX_MAC_INDEX + CCS_MAX_CAPABILITY_INDEX |
for (i = 0; i < CCS_MAX_MAC_INDEX + CCS_MAX_CAPABILITY_INDEX |
661 |
#ifdef CONFIG_CCSECURITY_AUDIT |
#ifdef CONFIG_CCSECURITY_AUDIT |
662 |
g = ccs_yesno(config & CCS_CONFIG_WANT_GRANT_LOG); |
g = ccs_yesno(config & CCS_CONFIG_WANT_GRANT_LOG); |
663 |
r = ccs_yesno(config & CCS_CONFIG_WANT_REJECT_LOG); |
r = ccs_yesno(config & CCS_CONFIG_WANT_REJECT_LOG); |
664 |
if (!ccs_io_printf(head, "%u-CONFIG::%s={ mode=%s " |
if (!ccs_io_printf(head, "%u-%s%s={ mode=%s " |
665 |
"grant_log=%s reject_log=%s }\n", |
"grant_log=%s reject_log=%s }\n", |
666 |
index, ccs_mac_keywords[i], |
index, "CONFIG::", |
667 |
ccs_mode_4[config & 3], g, r)) |
ccs_mac_keywords[i], |
668 |
|
ccs_mode[config & 3], g, r)) |
669 |
goto out; |
goto out; |
670 |
#else |
#else |
671 |
if (!ccs_io_printf(head, "%u-CONFIG::%s={ mode=%s }\n", |
if (!ccs_io_printf(head, "%u-%s%s={ mode=%s }\n", |
672 |
index, ccs_mac_keywords[i], |
index, "CONFIG::", |
673 |
ccs_mode_4[config & 3])) |
ccs_mac_keywords[i], |
674 |
|
ccs_mode[config & 3])) |
675 |
goto out; |
goto out; |
676 |
#endif |
#endif |
677 |
} |
} |
678 |
if (profile->audit != &ccs_default_profile.preference && |
if (!ccs_print_preference(head, index)) |
|
!ccs_io_printf(head, "%u-PREFERENCE::audit={ " |
|
|
#ifdef CONFIG_CCSECURITY_AUDIT |
|
|
"max_grant_log=%u max_reject_log=%u " |
|
|
#endif |
|
|
"task_info=%s path_info=%s }\n", index, |
|
|
#ifdef CONFIG_CCSECURITY_AUDIT |
|
|
profile->preference.audit_max_grant_log, |
|
|
profile->preference.audit_max_reject_log, |
|
|
#endif |
|
|
ccs_yesno(profile->preference. |
|
|
audit_task_info), |
|
|
ccs_yesno(profile->preference. |
|
|
audit_path_info))) |
|
|
goto out; |
|
|
if (profile->learning != &ccs_default_profile.preference && |
|
|
!ccs_io_printf(head, "%u-PREFERENCE::learning={ " |
|
|
"verbose=%s max_entry=%u exec.realpath=%s " |
|
|
"exec.argv0=%s symlink.target=%s }\n", |
|
|
index, |
|
|
ccs_yesno(profile->preference. |
|
|
learning_verbose), |
|
|
profile->preference.learning_max_entry, |
|
|
ccs_yesno(profile->preference. |
|
|
learning_exec_realpath), |
|
|
ccs_yesno(profile->preference. |
|
|
learning_exec_argv0), |
|
|
ccs_yesno(profile->preference. |
|
|
learning_symlink_target))) |
|
|
goto out; |
|
|
if (profile->permissive != &ccs_default_profile.preference && |
|
|
!ccs_io_printf(head, "%u-PREFERENCE::permissive={ " |
|
|
"verbose=%s }\n", index, |
|
|
ccs_yesno(profile->preference. |
|
|
permissive_verbose))) |
|
|
goto out; |
|
|
if (profile->enforcing != &ccs_default_profile.preference && |
|
|
!ccs_io_printf(head, "%u-PREFERENCE::enforcing={ " |
|
|
"verbose=%s penalty=%u }\n", index, |
|
|
ccs_yesno(profile->preference. |
|
|
enforcing_verbose), |
|
|
profile->preference.enforcing_penalty)) |
|
679 |
goto out; |
goto out; |
680 |
continue; |
continue; |
681 |
out: |
out: |
686 |
head->read_eof = true; |
head->read_eof = true; |
687 |
} |
} |
688 |
|
|
689 |
/* The list for "struct ccs_policy_manager_entry". */ |
static bool ccs_same_manager_entry(const struct ccs_acl_head *a, |
690 |
LIST_HEAD(ccs_policy_manager_list); |
const struct ccs_acl_head *b) |
691 |
|
{ |
692 |
|
return container_of(a, struct ccs_manager, head)->manager |
693 |
|
== container_of(b, struct ccs_manager, head)->manager; |
694 |
|
} |
695 |
|
|
696 |
/** |
/** |
697 |
* ccs_update_manager_entry - Add a manager entry. |
* ccs_update_manager_entry - Add a manager entry. |
703 |
*/ |
*/ |
704 |
static int ccs_update_manager_entry(const char *manager, const bool is_delete) |
static int ccs_update_manager_entry(const char *manager, const bool is_delete) |
705 |
{ |
{ |
706 |
struct ccs_policy_manager_entry *entry = NULL; |
struct ccs_manager e = { }; |
|
struct ccs_policy_manager_entry *ptr; |
|
|
struct ccs_policy_manager_entry e = { }; |
|
707 |
int error = is_delete ? -ENOENT : -ENOMEM; |
int error = is_delete ? -ENOENT : -ENOMEM; |
708 |
if (ccs_is_domain_def(manager)) { |
if (ccs_domain_def(manager)) { |
709 |
if (!ccs_is_correct_domain(manager)) |
if (!ccs_correct_domain(manager)) |
710 |
return -EINVAL; |
return -EINVAL; |
711 |
e.is_domain = true; |
e.is_domain = true; |
712 |
} else { |
} else { |
713 |
if (!ccs_is_correct_path(manager, 1, -1, -1)) |
if (!ccs_correct_path(manager)) |
714 |
return -EINVAL; |
return -EINVAL; |
715 |
} |
} |
716 |
e.manager = ccs_get_name(manager); |
e.manager = ccs_get_name(manager); |
717 |
if (!e.manager) |
if (!e.manager) |
718 |
return -ENOMEM; |
return error; |
719 |
if (!is_delete) |
error = ccs_update_policy(&e.head, sizeof(e), is_delete, |
720 |
entry = kmalloc(sizeof(e), GFP_KERNEL); |
CCS_ID_MANAGER, ccs_same_manager_entry); |
|
mutex_lock(&ccs_policy_lock); |
|
|
list_for_each_entry_rcu(ptr, &ccs_policy_manager_list, list) { |
|
|
if (ptr->manager != e.manager) |
|
|
continue; |
|
|
ptr->is_deleted = is_delete; |
|
|
error = 0; |
|
|
break; |
|
|
} |
|
|
if (!is_delete && error && ccs_commit_ok(entry, &e, sizeof(e))) { |
|
|
list_add_tail_rcu(&entry->list, &ccs_policy_manager_list); |
|
|
entry = NULL; |
|
|
error = 0; |
|
|
} |
|
|
mutex_unlock(&ccs_policy_lock); |
|
721 |
ccs_put_name(e.manager); |
ccs_put_name(e.manager); |
|
kfree(entry); |
|
722 |
return error; |
return error; |
723 |
} |
} |
724 |
|
|
725 |
/** |
/** |
726 |
* ccs_write_manager_policy - Write manager policy. |
* ccs_write_manager - Write manager policy. |
727 |
* |
* |
728 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
729 |
* |
* |
730 |
* Returns 0 on success, negative value otherwise. |
* Returns 0 on success, negative value otherwise. |
731 |
*/ |
*/ |
732 |
static int ccs_write_manager_policy(struct ccs_io_buffer *head) |
static int ccs_write_manager(struct ccs_io_buffer *head) |
733 |
{ |
{ |
734 |
char *data = head->write_buf; |
char *data = head->write_buf; |
735 |
bool is_delete = ccs_str_starts(&data, CCS_KEYWORD_DELETE); |
bool is_delete = ccs_str_starts(&data, CCS_KEYWORD_DELETE); |
741 |
} |
} |
742 |
|
|
743 |
/** |
/** |
744 |
* ccs_read_manager_policy - Read manager policy. |
* ccs_read_manager - Read manager policy. |
745 |
* |
* |
746 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
747 |
* |
* |
748 |
* Caller holds ccs_read_lock(). |
* Caller holds ccs_read_lock(). |
749 |
*/ |
*/ |
750 |
static void ccs_read_manager_policy(struct ccs_io_buffer *head) |
static void ccs_read_manager(struct ccs_io_buffer *head) |
751 |
{ |
{ |
752 |
struct list_head *pos; |
struct list_head *pos; |
753 |
if (head->read_eof) |
if (head->read_eof) |
754 |
return; |
return; |
755 |
list_for_each_cookie(pos, head->read_var2, &ccs_policy_manager_list) { |
list_for_each_cookie(pos, head->read_var2, |
756 |
struct ccs_policy_manager_entry *ptr; |
&ccs_policy_list[CCS_ID_MANAGER]) { |
757 |
ptr = list_entry(pos, struct ccs_policy_manager_entry, list); |
struct ccs_manager *ptr |
758 |
if (ptr->is_deleted) |
= list_entry(pos, typeof(*ptr), head.list); |
759 |
|
if (ptr->head.is_deleted) |
760 |
continue; |
continue; |
761 |
if (!ccs_io_printf(head, "%s\n", ptr->manager->name)) |
if (!ccs_io_printf(head, "%s\n", ptr->manager->name)) |
762 |
return; |
return; |
765 |
} |
} |
766 |
|
|
767 |
/** |
/** |
768 |
* ccs_is_policy_manager - Check whether the current process is a policy manager. |
* ccs_manager - Check whether the current process is a policy manager. |
769 |
* |
* |
770 |
* Returns true if the current process is permitted to modify policy |
* Returns true if the current process is permitted to modify policy |
771 |
* via /proc/ccs/ interface. |
* via /proc/ccs/ interface. |
772 |
* |
* |
773 |
* Caller holds ccs_read_lock(). |
* Caller holds ccs_read_lock(). |
774 |
*/ |
*/ |
775 |
static bool ccs_is_policy_manager(void) |
static bool ccs_manager(void) |
776 |
{ |
{ |
777 |
struct ccs_policy_manager_entry *ptr; |
struct ccs_manager *ptr; |
778 |
const char *exe; |
const char *exe; |
779 |
struct task_struct *task = current; |
struct task_struct *task = current; |
780 |
const struct ccs_path_info *domainname |
const struct ccs_path_info *domainname |
782 |
bool found = false; |
bool found = false; |
783 |
if (!ccs_policy_loaded) |
if (!ccs_policy_loaded) |
784 |
return true; |
return true; |
785 |
if (task->ccs_flags & CCS_TASK_IS_POLICY_MANAGER) |
if (task->ccs_flags & CCS_TASK_IS_MANAGER) |
786 |
return true; |
return true; |
787 |
if (!ccs_manage_by_non_root && (current_uid() || current_euid())) |
if (!ccs_manage_by_non_root && (current_uid() || current_euid())) |
788 |
return false; |
return false; |
|
list_for_each_entry_rcu(ptr, &ccs_policy_manager_list, list) { |
|
|
if (!ptr->is_deleted && ptr->is_domain |
|
|
&& !ccs_pathcmp(domainname, ptr->manager)) { |
|
|
/* Set manager flag. */ |
|
|
task->ccs_flags |= CCS_TASK_IS_POLICY_MANAGER; |
|
|
return true; |
|
|
} |
|
|
} |
|
789 |
exe = ccs_get_exe(); |
exe = ccs_get_exe(); |
790 |
if (!exe) |
list_for_each_entry_rcu(ptr, &ccs_policy_list[CCS_ID_MANAGER], |
791 |
return false; |
head.list) { |
792 |
list_for_each_entry_rcu(ptr, &ccs_policy_manager_list, list) { |
if (ptr->head.is_deleted) |
793 |
if (!ptr->is_deleted && !ptr->is_domain |
continue; |
794 |
&& !strcmp(exe, ptr->manager->name)) { |
if (ptr->is_domain) { |
795 |
found = true; |
if (ccs_pathcmp(domainname, ptr->manager)) |
796 |
/* Set manager flag. */ |
continue; |
797 |
task->ccs_flags |= CCS_TASK_IS_POLICY_MANAGER; |
} else { |
798 |
break; |
if (!exe || strcmp(exe, ptr->manager->name)) |
799 |
|
continue; |
800 |
} |
} |
801 |
|
/* Set manager flag. */ |
802 |
|
task->ccs_flags |= CCS_TASK_IS_MANAGER; |
803 |
|
found = true; |
804 |
|
break; |
805 |
} |
} |
806 |
if (!found) { /* Reduce error messages. */ |
if (!found) { /* Reduce error messages. */ |
807 |
static pid_t ccs_last_pid; |
static pid_t ccs_last_pid; |
827 |
static char *ccs_find_condition_part(char *data) |
static char *ccs_find_condition_part(char *data) |
828 |
{ |
{ |
829 |
char *cp = strstr(data, " if "); |
char *cp = strstr(data, " if "); |
830 |
if (cp) { |
if (!cp) |
|
while (1) { |
|
|
char *cp2 = strstr(cp + 3, " if "); |
|
|
if (!cp2) |
|
|
break; |
|
|
cp = cp2; |
|
|
} |
|
|
*cp++ = '\0'; |
|
|
} else { |
|
831 |
cp = strstr(data, " ; set "); |
cp = strstr(data, " ; set "); |
832 |
if (cp) |
if (cp) |
833 |
*cp++ = '\0'; |
*cp++ = '\0'; |
|
} |
|
834 |
return cp; |
return cp; |
835 |
} |
} |
836 |
|
|
837 |
/** |
/** |
838 |
* ccs_is_select_one - Parse select command. |
* ccs_select_one - Parse select command. |
839 |
* |
* |
840 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
841 |
* @data: String to parse. |
* @data: String to parse. |
844 |
* |
* |
845 |
* Caller holds ccs_read_lock(). |
* Caller holds ccs_read_lock(). |
846 |
*/ |
*/ |
847 |
static bool ccs_is_select_one(struct ccs_io_buffer *head, const char *data) |
static bool ccs_select_one(struct ccs_io_buffer *head, const char *data) |
848 |
{ |
{ |
849 |
unsigned int pid; |
unsigned int pid; |
850 |
struct ccs_domain_info *domain = NULL; |
struct ccs_domain_info *domain = NULL; |
856 |
if (sscanf(data, "pid=%u", &pid) == 1 || |
if (sscanf(data, "pid=%u", &pid) == 1 || |
857 |
(global_pid = true, sscanf(data, "global-pid=%u", &pid) == 1)) { |
(global_pid = true, sscanf(data, "global-pid=%u", &pid) == 1)) { |
858 |
struct task_struct *p; |
struct task_struct *p; |
859 |
read_lock(&tasklist_lock); |
ccs_tasklist_lock(); |
860 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24) |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24) |
861 |
if (global_pid) |
if (global_pid) |
862 |
p = find_task_by_pid_ns(pid, &init_pid_ns); |
p = ccsecurity_exports.find_task_by_pid_ns(pid, |
863 |
|
&init_pid_ns); |
864 |
else |
else |
865 |
p = find_task_by_vpid(pid); |
p = ccsecurity_exports.find_task_by_vpid(pid); |
866 |
#else |
#else |
867 |
p = find_task_by_pid(pid); |
p = find_task_by_pid(pid); |
868 |
#endif |
#endif |
869 |
if (p) |
if (p) |
870 |
domain = ccs_task_domain(p); |
domain = ccs_task_domain(p); |
871 |
read_unlock(&tasklist_lock); |
ccs_tasklist_unlock(); |
872 |
} else if (!strncmp(data, "domain=", 7)) { |
} else if (!strncmp(data, "domain=", 7)) { |
873 |
if (ccs_is_domain_def(data + 7)) |
if (ccs_domain_def(data + 7)) |
874 |
domain = ccs_find_domain(data + 7); |
domain = ccs_find_domain(data + 7); |
875 |
} else |
} else |
876 |
return false; |
return false; |
899 |
return true; |
return true; |
900 |
} |
} |
901 |
|
|
902 |
static int ccs_write_domain_policy2(char *data, struct ccs_domain_info *domain, |
static int ccs_write_domain2(char *data, struct ccs_domain_info *domain, |
903 |
struct ccs_condition *cond, |
const bool is_delete) |
904 |
const bool is_delete) |
{ |
905 |
{ |
static const struct { |
906 |
if (ccs_str_starts(&data, CCS_KEYWORD_ALLOW_CAPABILITY)) |
const char *keyword; |
907 |
return ccs_write_capability_policy(data, domain, cond, |
int (*write) (char *, struct ccs_domain_info *, |
908 |
is_delete); |
struct ccs_condition *, const bool); |
909 |
if (ccs_str_starts(&data, CCS_KEYWORD_ALLOW_NETWORK)) |
} ccs_callback[5] = { |
910 |
return ccs_write_network_policy(data, domain, cond, is_delete); |
{ CCS_KEYWORD_ALLOW_NETWORK, ccs_write_network }, |
911 |
if (ccs_str_starts(&data, CCS_KEYWORD_ALLOW_SIGNAL)) |
{ CCS_KEYWORD_ALLOW_ENV, ccs_write_env }, |
912 |
return ccs_write_signal_policy(data, domain, cond, is_delete); |
{ CCS_KEYWORD_ALLOW_CAPABILITY, ccs_write_capability }, |
913 |
if (ccs_str_starts(&data, CCS_KEYWORD_ALLOW_ENV)) |
{ CCS_KEYWORD_ALLOW_SIGNAL, ccs_write_signal }, |
914 |
return ccs_write_env_policy(data, domain, cond, is_delete); |
{ CCS_KEYWORD_ALLOW_MOUNT, ccs_write_mount } |
915 |
if (ccs_str_starts(&data, CCS_KEYWORD_ALLOW_MOUNT)) |
}; |
916 |
return ccs_write_mount_policy(data, domain, cond, is_delete); |
int (*write) (char *, struct ccs_domain_info *, struct ccs_condition *, |
917 |
return ccs_write_file_policy(data, domain, cond, is_delete); |
const bool) = ccs_write_file; |
918 |
|
int error; |
919 |
|
u8 i; |
920 |
|
struct ccs_condition *cond = NULL; |
921 |
|
char *cp = ccs_find_condition_part(data); |
922 |
|
if (cp) { |
923 |
|
cond = ccs_get_condition(cp); |
924 |
|
if (!cond) |
925 |
|
return -EINVAL; |
926 |
|
} |
927 |
|
for (i = 0; i < 5; i++) { |
928 |
|
if (!ccs_str_starts(&data, ccs_callback[i].keyword)) |
929 |
|
continue; |
930 |
|
write = ccs_callback[i].write; |
931 |
|
break; |
932 |
|
} |
933 |
|
error = write(data, domain, cond, is_delete); |
934 |
|
if (cond) |
935 |
|
ccs_put_condition(cond); |
936 |
|
return error; |
937 |
} |
} |
938 |
|
|
939 |
|
static const char *ccs_dif[CCS_MAX_DOMAIN_INFO_FLAGS] = { |
940 |
|
[CCS_DIF_QUOTA_WARNED] = CCS_KEYWORD_QUOTA_EXCEEDED "\n", |
941 |
|
[CCS_DIF_IGNORE_GLOBAL] = CCS_KEYWORD_IGNORE_GLOBAL "\n", |
942 |
|
[CCS_DIF_IGNORE_GLOBAL_ALLOW_READ] |
943 |
|
= CCS_KEYWORD_IGNORE_GLOBAL_ALLOW_READ "\n", |
944 |
|
[CCS_DIF_IGNORE_GLOBAL_ALLOW_ENV] |
945 |
|
= CCS_KEYWORD_IGNORE_GLOBAL_ALLOW_ENV "\n", |
946 |
|
[CCS_DIF_TRANSITION_FAILED] = CCS_KEYWORD_TRANSITION_FAILED "\n" |
947 |
|
}; |
948 |
|
|
949 |
/** |
/** |
950 |
* ccs_write_domain_policy - Write domain policy. |
* ccs_write_domain - Write domain policy. |
951 |
* |
* |
952 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
953 |
* |
* |
954 |
* Returns 0 on success, negative value otherwise. |
* Returns 0 on success, negative value otherwise. |
955 |
*/ |
*/ |
956 |
static int ccs_write_domain_policy(struct ccs_io_buffer *head) |
static int ccs_write_domain(struct ccs_io_buffer *head) |
957 |
{ |
{ |
958 |
char *data = head->write_buf; |
char *data = head->write_buf; |
959 |
struct ccs_domain_info *domain = head->write_var1; |
struct ccs_domain_info *domain = head->write_var1; |
960 |
bool is_delete = false; |
bool is_delete = false; |
961 |
bool is_select = false; |
bool is_select = false; |
962 |
unsigned int profile; |
unsigned int profile; |
|
struct ccs_condition *cond = NULL; |
|
|
char *cp; |
|
|
int error; |
|
963 |
if (ccs_str_starts(&data, CCS_KEYWORD_DELETE)) |
if (ccs_str_starts(&data, CCS_KEYWORD_DELETE)) |
964 |
is_delete = true; |
is_delete = true; |
965 |
else if (ccs_str_starts(&data, CCS_KEYWORD_SELECT)) |
else if (ccs_str_starts(&data, CCS_KEYWORD_SELECT)) |
966 |
is_select = true; |
is_select = true; |
967 |
if (is_select && ccs_is_select_one(head, data)) |
if (is_select && ccs_select_one(head, data)) |
968 |
return 0; |
return 0; |
969 |
/* Don't allow updating policies by non manager programs. */ |
/* Don't allow updating policies by non manager programs. */ |
970 |
if (!ccs_is_policy_manager()) |
if (!ccs_manager()) |
971 |
return -EPERM; |
return -EPERM; |
972 |
if (ccs_is_domain_def(data)) { |
if (ccs_domain_def(data)) { |
973 |
domain = NULL; |
domain = NULL; |
974 |
if (is_delete) |
if (is_delete) |
975 |
ccs_delete_domain(data); |
ccs_delete_domain(data); |
976 |
else if (is_select) |
else if (is_select) |
977 |
domain = ccs_find_domain(data); |
domain = ccs_find_domain(data); |
978 |
else |
else |
979 |
domain = ccs_find_or_assign_new_domain(data, 0); |
domain = ccs_assign_domain(data, 0); |
980 |
head->write_var1 = domain; |
head->write_var1 = domain; |
981 |
return 0; |
return 0; |
982 |
} |
} |
989 |
domain->profile = (u8) profile; |
domain->profile = (u8) profile; |
990 |
return 0; |
return 0; |
991 |
} |
} |
992 |
if (!strcmp(data, CCS_KEYWORD_IGNORE_GLOBAL_ALLOW_READ)) { |
for (profile = 0; profile < CCS_MAX_DOMAIN_INFO_FLAGS; profile++) { |
993 |
domain->ignore_global_allow_read = !is_delete; |
const char *cp = ccs_dif[profile]; |
994 |
return 0; |
if (strncmp(data, cp, strlen(cp) - 1)) |
995 |
} |
continue; |
996 |
if (!strcmp(data, CCS_KEYWORD_IGNORE_GLOBAL_ALLOW_ENV)) { |
domain->flags[profile] = !is_delete; |
|
domain->ignore_global_allow_env = !is_delete; |
|
997 |
return 0; |
return 0; |
998 |
} |
} |
999 |
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_domain_policy2(data, domain, cond, is_delete); |
|
|
if (cond) |
|
|
ccs_put_condition(cond); |
|
|
return error; |
|
1000 |
} |
} |
1001 |
|
|
1002 |
/** |
/** |
1036 |
return ccs_io_printf(head, "\"%s\"", ptr->filename->name); |
return ccs_io_printf(head, "\"%s\"", ptr->filename->name); |
1037 |
} |
} |
1038 |
|
|
1039 |
|
static void ccs_print_number(char *buffer, int buffer_len, |
1040 |
|
const struct ccs_number_union *ptr) |
1041 |
|
{ |
1042 |
|
int i; |
1043 |
|
unsigned long min = ptr->values[0]; |
1044 |
|
const unsigned long max = ptr->values[1]; |
1045 |
|
u8 min_type = ptr->value_type[0]; |
1046 |
|
const u8 max_type = ptr->value_type[1]; |
1047 |
|
memset(buffer, 0, buffer_len); |
1048 |
|
buffer_len -= 2; |
1049 |
|
for (i = 0; i < 2; i++) { |
1050 |
|
int len; |
1051 |
|
switch (min_type) { |
1052 |
|
case CCS_VALUE_TYPE_HEXADECIMAL: |
1053 |
|
snprintf(buffer, buffer_len, "0x%lX", min); |
1054 |
|
break; |
1055 |
|
case CCS_VALUE_TYPE_OCTAL: |
1056 |
|
snprintf(buffer, buffer_len, "0%lo", min); |
1057 |
|
break; |
1058 |
|
default: |
1059 |
|
snprintf(buffer, buffer_len, "%lu", min); |
1060 |
|
break; |
1061 |
|
} |
1062 |
|
if (min == max && min_type == max_type) |
1063 |
|
break; |
1064 |
|
len = strlen(buffer); |
1065 |
|
buffer[len++] = '-'; |
1066 |
|
buffer += len; |
1067 |
|
buffer_len -= len; |
1068 |
|
min_type = max_type; |
1069 |
|
min = max; |
1070 |
|
} |
1071 |
|
} |
1072 |
|
|
1073 |
/** |
/** |
1074 |
* ccs_print_number_union_common - Print a ccs_number_union. |
* ccs_print_number_union_common - Print a ccs_number_union. |
1075 |
* |
* |
1083 |
const struct ccs_number_union *ptr, |
const struct ccs_number_union *ptr, |
1084 |
const bool need_space) |
const bool need_space) |
1085 |
{ |
{ |
1086 |
unsigned long min; |
char buffer[128]; |
|
unsigned long max; |
|
|
u8 min_type; |
|
|
u8 max_type; |
|
1087 |
if (need_space && !ccs_io_printf(head, " ")) |
if (need_space && !ccs_io_printf(head, " ")) |
1088 |
return false; |
return false; |
1089 |
if (ptr->is_group) |
if (ptr->is_group) |
1090 |
return ccs_io_printf(head, "@%s", |
return ccs_io_printf(head, "@%s", |
1091 |
ptr->group->group_name->name); |
ptr->group->group_name->name); |
1092 |
min_type = ptr->min_type; |
ccs_print_number(buffer, sizeof(buffer), ptr); |
1093 |
max_type = ptr->max_type; |
return ccs_io_printf(head, "%s", buffer); |
|
min = ptr->values[0]; |
|
|
max = ptr->values[1]; |
|
|
switch (min_type) { |
|
|
case CCS_VALUE_TYPE_HEXADECIMAL: |
|
|
if (!ccs_io_printf(head, "0x%lX", min)) |
|
|
return false; |
|
|
break; |
|
|
case CCS_VALUE_TYPE_OCTAL: |
|
|
if (!ccs_io_printf(head, "0%lo", min)) |
|
|
return false; |
|
|
break; |
|
|
default: |
|
|
if (!ccs_io_printf(head, "%lu", min)) |
|
|
return false; |
|
|
break; |
|
|
} |
|
|
if (min == max && min_type == max_type) |
|
|
return true; |
|
|
switch (max_type) { |
|
|
case CCS_VALUE_TYPE_HEXADECIMAL: |
|
|
return ccs_io_printf(head, "-0x%lX", max); |
|
|
case CCS_VALUE_TYPE_OCTAL: |
|
|
return ccs_io_printf(head, "-0%lo", max); |
|
|
default: |
|
|
return ccs_io_printf(head, "-%lu", max); |
|
|
} |
|
1094 |
} |
} |
1095 |
|
|
1096 |
/** |
/** |
1101 |
* |
* |
1102 |
* Returns true on success, false otherwise. |
* Returns true on success, false otherwise. |
1103 |
*/ |
*/ |
1104 |
bool ccs_print_number_union(struct ccs_io_buffer *head, |
static bool ccs_print_number_union(struct ccs_io_buffer *head, |
1105 |
const struct ccs_number_union *ptr) |
const struct ccs_number_union *ptr) |
1106 |
{ |
{ |
1107 |
return ccs_print_number_union_common(head, ptr, true); |
return ccs_print_number_union_common(head, ptr, true); |
1108 |
} |
} |
1125 |
* ccs_print_condition - Print condition part. |
* ccs_print_condition - Print condition part. |
1126 |
* |
* |
1127 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1128 |
* @cond: Pointer to "struct ccs_condition". May be NULL. |
* @cond: Pointer to "struct ccs_condition". Maybe NULL. |
1129 |
* |
* |
1130 |
* Returns true on success, false otherwise. |
* Returns true on success, false otherwise. |
1131 |
*/ |
*/ |
1135 |
const struct ccs_condition_element *condp; |
const struct ccs_condition_element *condp; |
1136 |
const struct ccs_number_union *numbers_p; |
const struct ccs_number_union *numbers_p; |
1137 |
const struct ccs_name_union *names_p; |
const struct ccs_name_union *names_p; |
1138 |
const struct ccs_argv_entry *argv; |
const struct ccs_argv *argv; |
1139 |
const struct ccs_envp_entry *envp; |
const struct ccs_envp *envp; |
1140 |
u16 condc; |
u16 condc; |
1141 |
u16 i; |
u16 i; |
1142 |
u16 j; |
u16 j; |
1148 |
numbers_p = (const struct ccs_number_union *) (condp + condc); |
numbers_p = (const struct ccs_number_union *) (condp + condc); |
1149 |
names_p = (const struct ccs_name_union *) |
names_p = (const struct ccs_name_union *) |
1150 |
(numbers_p + cond->numbers_count); |
(numbers_p + cond->numbers_count); |
1151 |
argv = (const struct ccs_argv_entry *) (names_p + cond->names_count); |
argv = (const struct ccs_argv *) (names_p + cond->names_count); |
1152 |
envp = (const struct ccs_envp_entry *) (argv + cond->argc); |
envp = (const struct ccs_envp *) (argv + cond->argc); |
1153 |
memset(buffer, 0, sizeof(buffer)); |
memset(buffer, 0, sizeof(buffer)); |
1154 |
if (condc && !ccs_io_printf(head, "%s", " if")) |
if (condc && !ccs_io_printf(head, "%s", " if")) |
1155 |
goto out; |
goto out; |
1225 |
cond->post_state[j])) |
cond->post_state[j])) |
1226 |
goto out; |
goto out; |
1227 |
} |
} |
1228 |
|
if (i & (1 << 4)) { |
1229 |
|
if (!ccs_io_printf(head, " audit=%s", |
1230 |
|
ccs_yesno(cond->post_state[4]))) |
1231 |
|
goto out; |
1232 |
|
} |
1233 |
no_condition: |
no_condition: |
1234 |
if (ccs_io_printf(head, "\n")) |
if (ccs_io_printf(head, "\n")) |
1235 |
return true; |
return true; |
1242 |
* |
* |
1243 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1244 |
* @ptr: Pointer to "struct ccs_path_acl". |
* @ptr: Pointer to "struct ccs_path_acl". |
|
* @cond: Pointer to "struct ccs_condition". May be NULL. |
|
1245 |
* |
* |
1246 |
* Returns true on success, false otherwise. |
* Returns true on success, false otherwise. |
1247 |
*/ |
*/ |
1248 |
static bool ccs_print_path_acl(struct ccs_io_buffer *head, |
static bool ccs_print_path_acl(struct ccs_io_buffer *head, |
1249 |
struct ccs_path_acl *ptr, |
struct ccs_path_acl *ptr) |
|
const struct ccs_condition *cond) |
|
1250 |
{ |
{ |
1251 |
int pos; |
int pos; |
1252 |
u8 bit; |
u8 bit; |
1254 |
for (bit = head->read_bit; bit < CCS_MAX_PATH_OPERATION; bit++) { |
for (bit = head->read_bit; bit < CCS_MAX_PATH_OPERATION; bit++) { |
1255 |
if (!(perm & (1 << bit))) |
if (!(perm & (1 << bit))) |
1256 |
continue; |
continue; |
1257 |
if (head->read_execute_only && bit != CCS_TYPE_EXECUTE) |
if (head->read_execute_only && bit != CCS_TYPE_EXECUTE |
1258 |
|
&& bit != CCS_TYPE_TRANSIT) |
1259 |
continue; |
continue; |
1260 |
/* Print "read/write" instead of "read" and "write". */ |
/* Print "read/write" instead of "read" and "write". */ |
1261 |
if ((bit == CCS_TYPE_READ || bit == CCS_TYPE_WRITE) |
if ((bit == CCS_TYPE_READ || bit == CCS_TYPE_WRITE) |
1264 |
pos = head->read_avail; |
pos = head->read_avail; |
1265 |
if (!ccs_io_printf(head, "allow_%s", ccs_path2keyword(bit)) || |
if (!ccs_io_printf(head, "allow_%s", ccs_path2keyword(bit)) || |
1266 |
!ccs_print_name_union(head, &ptr->name) || |
!ccs_print_name_union(head, &ptr->name) || |
1267 |
!ccs_print_condition(head, cond)) { |
!ccs_print_condition(head, ptr->head.cond)) { |
1268 |
head->read_bit = bit; |
head->read_bit = bit; |
1269 |
head->read_avail = pos; |
head->read_avail = pos; |
1270 |
return false; |
return false; |
1279 |
* |
* |
1280 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1281 |
* @ptr: Pointer to "struct ccs_path_number3_acl". |
* @ptr: Pointer to "struct ccs_path_number3_acl". |
|
* @cond: Pointer to "struct ccs_condition". May be NULL. |
|
1282 |
* |
* |
1283 |
* Returns true on success, false otherwise. |
* Returns true on success, false otherwise. |
1284 |
*/ |
*/ |
1285 |
static bool ccs_print_path_number3_acl(struct ccs_io_buffer *head, |
static bool ccs_print_path_number3_acl(struct ccs_io_buffer *head, |
1286 |
struct ccs_path_number3_acl *ptr, |
struct ccs_path_number3_acl *ptr) |
|
const struct ccs_condition *cond) |
|
1287 |
{ |
{ |
1288 |
int pos; |
int pos; |
1289 |
u8 bit; |
u8 bit; |
1299 |
!ccs_print_number_union(head, &ptr->mode) || |
!ccs_print_number_union(head, &ptr->mode) || |
1300 |
!ccs_print_number_union(head, &ptr->major) || |
!ccs_print_number_union(head, &ptr->major) || |
1301 |
!ccs_print_number_union(head, &ptr->minor) || |
!ccs_print_number_union(head, &ptr->minor) || |
1302 |
!ccs_print_condition(head, cond)) { |
!ccs_print_condition(head, ptr->head.cond)) { |
1303 |
head->read_bit = bit; |
head->read_bit = bit; |
1304 |
head->read_avail = pos; |
head->read_avail = pos; |
1305 |
return false; |
return false; |
1314 |
* |
* |
1315 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1316 |
* @ptr: Pointer to "struct ccs_path2_acl". |
* @ptr: Pointer to "struct ccs_path2_acl". |
|
* @cond: Pointer to "struct ccs_condition". May be NULL. |
|
1317 |
* |
* |
1318 |
* Returns true on success, false otherwise. |
* Returns true on success, false otherwise. |
1319 |
*/ |
*/ |
1320 |
static bool ccs_print_path2_acl(struct ccs_io_buffer *head, |
static bool ccs_print_path2_acl(struct ccs_io_buffer *head, |
1321 |
struct ccs_path2_acl *ptr, |
struct ccs_path2_acl *ptr) |
|
const struct ccs_condition *cond) |
|
1322 |
{ |
{ |
1323 |
int pos; |
int pos; |
1324 |
u8 bit; |
u8 bit; |
1331 |
ccs_path22keyword(bit)) || |
ccs_path22keyword(bit)) || |
1332 |
!ccs_print_name_union(head, &ptr->name1) || |
!ccs_print_name_union(head, &ptr->name1) || |
1333 |
!ccs_print_name_union(head, &ptr->name2) || |
!ccs_print_name_union(head, &ptr->name2) || |
1334 |
!ccs_print_condition(head, cond)) { |
!ccs_print_condition(head, ptr->head.cond)) { |
1335 |
head->read_bit = bit; |
head->read_bit = bit; |
1336 |
head->read_avail = pos; |
head->read_avail = pos; |
1337 |
return false; |
return false; |
1346 |
* |
* |
1347 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1348 |
* @ptr: Pointer to "struct ccs_path_number_acl". |
* @ptr: Pointer to "struct ccs_path_number_acl". |
|
* @cond: Pointer to "struct ccs_condition". May be NULL. |
|
1349 |
* |
* |
1350 |
* Returns true on success, false otherwise. |
* Returns true on success, false otherwise. |
1351 |
*/ |
*/ |
1352 |
static bool ccs_print_path_number_acl(struct ccs_io_buffer *head, |
static bool ccs_print_path_number_acl(struct ccs_io_buffer *head, |
1353 |
struct ccs_path_number_acl *ptr, |
struct ccs_path_number_acl *ptr) |
|
const struct ccs_condition *cond) |
|
1354 |
{ |
{ |
1355 |
int pos; |
int pos; |
1356 |
u8 bit; |
u8 bit; |
1364 |
ccs_path_number2keyword(bit)) || |
ccs_path_number2keyword(bit)) || |
1365 |
!ccs_print_name_union(head, &ptr->name) || |
!ccs_print_name_union(head, &ptr->name) || |
1366 |
!ccs_print_number_union(head, &ptr->number) || |
!ccs_print_number_union(head, &ptr->number) || |
1367 |
!ccs_print_condition(head, cond)) { |
!ccs_print_condition(head, ptr->head.cond)) { |
1368 |
head->read_bit = bit; |
head->read_bit = bit; |
1369 |
head->read_avail = pos; |
head->read_avail = pos; |
1370 |
return false; |
return false; |
1379 |
* |
* |
1380 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1381 |
* @ptr: Pointer to "struct ccs_env_acl". |
* @ptr: Pointer to "struct ccs_env_acl". |
|
* @cond: Pointer to "struct ccs_condition". May be NULL. |
|
1382 |
* |
* |
1383 |
* Returns true on success, false otherwise. |
* Returns true on success, false otherwise. |
1384 |
*/ |
*/ |
1385 |
static bool ccs_print_env_acl(struct ccs_io_buffer *head, |
static bool ccs_print_env_acl(struct ccs_io_buffer *head, |
1386 |
struct ccs_env_acl *ptr, |
struct ccs_env_acl *ptr) |
|
const struct ccs_condition *cond) |
|
1387 |
{ |
{ |
1388 |
const int pos = head->read_avail; |
const int pos = head->read_avail; |
1389 |
if (!ccs_io_printf(head, CCS_KEYWORD_ALLOW_ENV "%s", ptr->env->name) || |
if (!ccs_io_printf(head, CCS_KEYWORD_ALLOW_ENV "%s", ptr->env->name) || |
1390 |
!ccs_print_condition(head, cond)) { |
!ccs_print_condition(head, ptr->head.cond)) { |
1391 |
head->read_avail = pos; |
head->read_avail = pos; |
1392 |
return false; |
return false; |
1393 |
} |
} |
1399 |
* |
* |
1400 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1401 |
* @ptr: Pointer to "struct ccs_capability_acl". |
* @ptr: Pointer to "struct ccs_capability_acl". |
|
* @cond: Pointer to "struct ccs_condition". May be NULL. |
|
1402 |
* |
* |
1403 |
* Returns true on success, false otherwise. |
* Returns true on success, false otherwise. |
1404 |
*/ |
*/ |
1405 |
static bool ccs_print_capability_acl(struct ccs_io_buffer *head, |
static bool ccs_print_capability_acl(struct ccs_io_buffer *head, |
1406 |
struct ccs_capability_acl *ptr, |
struct ccs_capability_acl *ptr) |
|
const struct ccs_condition *cond) |
|
1407 |
{ |
{ |
1408 |
const int pos = head->read_avail; |
const int pos = head->read_avail; |
1409 |
if (!ccs_io_printf(head, CCS_KEYWORD_ALLOW_CAPABILITY "%s", |
if (!ccs_io_printf(head, CCS_KEYWORD_ALLOW_CAPABILITY "%s", |
1410 |
ccs_cap2keyword(ptr->operation)) || |
ccs_cap2keyword(ptr->operation)) || |
1411 |
!ccs_print_condition(head, cond)) { |
!ccs_print_condition(head, ptr->head.cond)) { |
1412 |
head->read_avail = pos; |
head->read_avail = pos; |
1413 |
return false; |
return false; |
1414 |
} |
} |
1416 |
} |
} |
1417 |
|
|
1418 |
/** |
/** |
|
* ccs_print_ipv4_entry - Print IPv4 address of a network ACL entry. |
|
|
* |
|
|
* @head: Pointer to "struct ccs_io_buffer". |
|
|
* @ptr: Pointer to "struct ccs_ip_network_acl". |
|
|
* |
|
|
* Returns true on success, false otherwise. |
|
|
*/ |
|
|
static bool ccs_print_ipv4_entry(struct ccs_io_buffer *head, |
|
|
struct ccs_ip_network_acl *ptr) |
|
|
{ |
|
|
const u32 min_address = ptr->address.ipv4.min; |
|
|
const u32 max_address = ptr->address.ipv4.max; |
|
|
if (!ccs_io_printf(head, "%u.%u.%u.%u", HIPQUAD(min_address))) |
|
|
return false; |
|
|
if (min_address != max_address |
|
|
&& !ccs_io_printf(head, "-%u.%u.%u.%u", HIPQUAD(max_address))) |
|
|
return false; |
|
|
return true; |
|
|
} |
|
|
|
|
|
/** |
|
|
* ccs_print_ipv6_entry - Print IPv6 address of a network ACL entry. |
|
|
* |
|
|
* @head: Pointer to "struct ccs_io_buffer". |
|
|
* @ptr: Pointer to "struct ccs_ip_network_acl". |
|
|
* |
|
|
* Returns true on success, false otherwise. |
|
|
*/ |
|
|
static bool ccs_print_ipv6_entry(struct ccs_io_buffer *head, |
|
|
struct ccs_ip_network_acl *ptr) |
|
|
{ |
|
|
char buf[64]; |
|
|
const struct in6_addr *min_address = ptr->address.ipv6.min; |
|
|
const struct in6_addr *max_address = ptr->address.ipv6.max; |
|
|
ccs_print_ipv6(buf, sizeof(buf), min_address); |
|
|
if (!ccs_io_printf(head, "%s", buf)) |
|
|
return false; |
|
|
if (min_address != max_address) { |
|
|
ccs_print_ipv6(buf, sizeof(buf), max_address); |
|
|
if (!ccs_io_printf(head, "-%s", buf)) |
|
|
return false; |
|
|
} |
|
|
return true; |
|
|
} |
|
|
|
|
|
/** |
|
1419 |
* ccs_print_network_acl - Print a network ACL entry. |
* ccs_print_network_acl - Print a network ACL entry. |
1420 |
* |
* |
1421 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1422 |
* @ptr: Pointer to "struct ccs_ip_network_acl". |
* @ptr: Pointer to "struct ccs_ip_network_acl". |
|
* @cond: Pointer to "struct ccs_condition". May be NULL. |
|
1423 |
* |
* |
1424 |
* Returns true on success, false otherwise. |
* Returns true on success, false otherwise. |
1425 |
*/ |
*/ |
1426 |
static bool ccs_print_network_acl(struct ccs_io_buffer *head, |
static bool ccs_print_network_acl(struct ccs_io_buffer *head, |
1427 |
struct ccs_ip_network_acl *ptr, |
struct ccs_ip_network_acl *ptr) |
|
const struct ccs_condition *cond) |
|
1428 |
{ |
{ |
1429 |
int pos; |
int pos; |
1430 |
u8 bit; |
u8 bit; |
1431 |
const u16 perm = ptr->perm; |
const u8 perm = ptr->perm; |
1432 |
|
char buf[128]; |
1433 |
for (bit = head->read_bit; bit < CCS_MAX_NETWORK_OPERATION; bit++) { |
for (bit = head->read_bit; bit < CCS_MAX_NETWORK_OPERATION; bit++) { |
1434 |
|
const char *w[2] = { "", "" }; |
1435 |
if (!(perm & (1 << bit))) |
if (!(perm & (1 << bit))) |
1436 |
continue; |
continue; |
1437 |
pos = head->read_avail; |
pos = head->read_avail; |
|
if (!ccs_io_printf(head, CCS_KEYWORD_ALLOW_NETWORK "%s ", |
|
|
ccs_net2keyword(bit))) |
|
|
goto out; |
|
1438 |
switch (ptr->address_type) { |
switch (ptr->address_type) { |
1439 |
case CCS_IP_ADDRESS_TYPE_ADDRESS_GROUP: |
case CCS_IP_ADDRESS_TYPE_ADDRESS_GROUP: |
1440 |
if (!ccs_io_printf(head, "@%s", ptr->address.group-> |
w[0] = "@"; |
1441 |
group_name->name)) |
w[1] = ptr->address.group->group_name->name; |
|
goto out; |
|
1442 |
break; |
break; |
1443 |
case CCS_IP_ADDRESS_TYPE_IPv4: |
case CCS_IP_ADDRESS_TYPE_IPv4: |
1444 |
if (!ccs_print_ipv4_entry(head, ptr)) |
ccs_print_ipv4(buf, sizeof(buf), ptr->address.ipv4.min, |
1445 |
goto out; |
ptr->address.ipv4.max); |
1446 |
|
w[0] = buf; |
1447 |
break; |
break; |
1448 |
case CCS_IP_ADDRESS_TYPE_IPv6: |
case CCS_IP_ADDRESS_TYPE_IPv6: |
1449 |
if (!ccs_print_ipv6_entry(head, ptr)) |
ccs_print_ipv6(buf, sizeof(buf), ptr->address.ipv6.min, |
1450 |
goto out; |
ptr->address.ipv6.max); |
1451 |
|
w[0] = buf; |
1452 |
break; |
break; |
1453 |
} |
} |
1454 |
if (!ccs_print_number_union(head, &ptr->port) || |
if (!ccs_io_printf(head, CCS_KEYWORD_ALLOW_NETWORK "%s %s%s", |
1455 |
!ccs_print_condition(head, cond)) |
ccs_net2keyword(bit), w[0], w[1]) || |
1456 |
|
!ccs_print_number_union(head, &ptr->port) || |
1457 |
|
!ccs_print_condition(head, ptr->head.cond)) |
1458 |
goto out; |
goto out; |
1459 |
} |
} |
1460 |
head->read_bit = 0; |
head->read_bit = 0; |
1470 |
* |
* |
1471 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1472 |
* @ptr: Pointer to "struct signale_acl". |
* @ptr: Pointer to "struct signale_acl". |
|
* @cond: Pointer to "struct ccs_condition". May be NULL. |
|
1473 |
* |
* |
1474 |
* Returns true on success, false otherwise. |
* Returns true on success, false otherwise. |
1475 |
*/ |
*/ |
1476 |
static bool ccs_print_signal_acl(struct ccs_io_buffer *head, |
static bool ccs_print_signal_acl(struct ccs_io_buffer *head, |
1477 |
struct ccs_signal_acl *ptr, |
struct ccs_signal_acl *ptr) |
|
const struct ccs_condition *cond) |
|
1478 |
{ |
{ |
1479 |
const int pos = head->read_avail; |
const int pos = head->read_avail; |
1480 |
if (!ccs_io_printf(head, CCS_KEYWORD_ALLOW_SIGNAL "%u %s", |
if (!ccs_io_printf(head, CCS_KEYWORD_ALLOW_SIGNAL "%u %s", |
1481 |
ptr->sig, ptr->domainname->name) || |
ptr->sig, ptr->domainname->name) || |
1482 |
!ccs_print_condition(head, cond)) { |
!ccs_print_condition(head, ptr->head.cond)) { |
1483 |
head->read_avail = pos; |
head->read_avail = pos; |
1484 |
return false; |
return false; |
1485 |
} |
} |
1487 |
} |
} |
1488 |
|
|
1489 |
/** |
/** |
1490 |
* ccs_print_execute_handler_record - Print an execute handler ACL entry. |
* ccs_print_execute_handler - Print an execute handler ACL entry. |
1491 |
* |
* |
1492 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1493 |
* @keyword: Name of the keyword. |
* @keyword: Name of the keyword. |
1494 |
* @ptr: Pointer to "struct ccs_execute_handler_record". |
* @ptr: Pointer to "struct ccs_execute_handler". |
1495 |
* |
* |
1496 |
* Returns true on success, false otherwise. |
* Returns true on success, false otherwise. |
1497 |
*/ |
*/ |
1498 |
static bool ccs_print_execute_handler_record(struct ccs_io_buffer *head, |
static bool ccs_print_execute_handler(struct ccs_io_buffer *head, |
1499 |
const char *keyword, |
const char *keyword, |
1500 |
struct ccs_execute_handler_record * |
struct ccs_execute_handler *ptr) |
|
ptr) |
|
1501 |
{ |
{ |
1502 |
return ccs_io_printf(head, "%s %s\n", keyword, ptr->handler->name); |
const int pos = head->read_avail; |
1503 |
|
if (!ccs_io_printf(head, "%s %s", keyword, ptr->handler->name) || |
1504 |
|
!ccs_print_condition(head, ptr->head.cond)) { |
1505 |
|
head->read_avail = pos; |
1506 |
|
return false; |
1507 |
|
} |
1508 |
|
return true; |
1509 |
} |
} |
1510 |
|
|
1511 |
/** |
/** |
1513 |
* |
* |
1514 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1515 |
* @ptr: Pointer to "struct ccs_mount_acl". |
* @ptr: Pointer to "struct ccs_mount_acl". |
|
* @cond: Pointer to "struct ccs_condition". May be NULL. |
|
1516 |
* |
* |
1517 |
* Returns true on success, false otherwise. |
* Returns true on success, false otherwise. |
1518 |
*/ |
*/ |
1519 |
static bool ccs_print_mount_acl(struct ccs_io_buffer *head, |
static bool ccs_print_mount_acl(struct ccs_io_buffer *head, |
1520 |
struct ccs_mount_acl *ptr, |
struct ccs_mount_acl *ptr) |
|
const struct ccs_condition *cond) |
|
1521 |
{ |
{ |
1522 |
const int pos = head->read_avail; |
const int pos = head->read_avail; |
1523 |
if (!ccs_io_printf(head, CCS_KEYWORD_ALLOW_MOUNT) || |
if (!ccs_io_printf(head, CCS_KEYWORD_ALLOW_MOUNT) || |
1525 |
!ccs_print_name_union(head, &ptr->dir_name) || |
!ccs_print_name_union(head, &ptr->dir_name) || |
1526 |
!ccs_print_name_union(head, &ptr->fs_type) || |
!ccs_print_name_union(head, &ptr->fs_type) || |
1527 |
!ccs_print_number_union(head, &ptr->flags) || |
!ccs_print_number_union(head, &ptr->flags) || |
1528 |
!ccs_print_condition(head, cond)) { |
!ccs_print_condition(head, ptr->head.cond)) { |
1529 |
head->read_avail = pos; |
head->read_avail = pos; |
1530 |
return false; |
return false; |
1531 |
} |
} |
1543 |
static bool ccs_print_entry(struct ccs_io_buffer *head, |
static bool ccs_print_entry(struct ccs_io_buffer *head, |
1544 |
struct ccs_acl_info *ptr) |
struct ccs_acl_info *ptr) |
1545 |
{ |
{ |
|
const struct ccs_condition *cond = ptr->cond; |
|
1546 |
const u8 acl_type = ptr->type; |
const u8 acl_type = ptr->type; |
1547 |
if (ptr->is_deleted) |
if (ptr->is_deleted) |
1548 |
return true; |
return true; |
1549 |
if (acl_type == CCS_TYPE_PATH_ACL) { |
if (acl_type == CCS_TYPE_PATH_ACL) { |
1550 |
struct ccs_path_acl *acl |
struct ccs_path_acl *acl |
1551 |
= container_of(ptr, struct ccs_path_acl, head); |
= container_of(ptr, typeof(*acl), head); |
1552 |
return ccs_print_path_acl(head, acl, cond); |
return ccs_print_path_acl(head, acl); |
1553 |
} |
} |
1554 |
if (acl_type == CCS_TYPE_EXECUTE_HANDLER) { |
if (acl_type == CCS_TYPE_EXECUTE_HANDLER || |
1555 |
struct ccs_execute_handler_record *acl |
acl_type == CCS_TYPE_DENIED_EXECUTE_HANDLER) { |
1556 |
= container_of(ptr, struct ccs_execute_handler_record, |
struct ccs_execute_handler *acl |
1557 |
head); |
= container_of(ptr, typeof(*acl), head); |
1558 |
const char *keyword = CCS_KEYWORD_EXECUTE_HANDLER; |
const char *keyword = acl_type == CCS_TYPE_EXECUTE_HANDLER ? |
1559 |
return ccs_print_execute_handler_record(head, keyword, acl); |
CCS_KEYWORD_EXECUTE_HANDLER : |
1560 |
} |
CCS_KEYWORD_DENIED_EXECUTE_HANDLER; |
1561 |
if (acl_type == CCS_TYPE_DENIED_EXECUTE_HANDLER) { |
return ccs_print_execute_handler(head, keyword, acl); |
|
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); |
|
1562 |
} |
} |
1563 |
if (head->read_execute_only) |
if (head->read_execute_only) |
1564 |
return true; |
return true; |
1565 |
if (acl_type == CCS_TYPE_PATH_NUMBER3_ACL) { |
if (acl_type == CCS_TYPE_PATH_NUMBER3_ACL) { |
1566 |
struct ccs_path_number3_acl *acl |
struct ccs_path_number3_acl *acl |
1567 |
= container_of(ptr, struct ccs_path_number3_acl, head); |
= container_of(ptr, typeof(*acl), head); |
1568 |
return ccs_print_path_number3_acl(head, acl, cond); |
return ccs_print_path_number3_acl(head, acl); |
1569 |
} |
} |
1570 |
if (acl_type == CCS_TYPE_PATH2_ACL) { |
if (acl_type == CCS_TYPE_PATH2_ACL) { |
1571 |
struct ccs_path2_acl *acl |
struct ccs_path2_acl *acl |
1572 |
= container_of(ptr, struct ccs_path2_acl, head); |
= container_of(ptr, typeof(*acl), head); |
1573 |
return ccs_print_path2_acl(head, acl, cond); |
return ccs_print_path2_acl(head, acl); |
1574 |
} |
} |
1575 |
if (acl_type == CCS_TYPE_PATH_NUMBER_ACL) { |
if (acl_type == CCS_TYPE_PATH_NUMBER_ACL) { |
1576 |
struct ccs_path_number_acl *acl |
struct ccs_path_number_acl *acl |
1577 |
= container_of(ptr, struct ccs_path_number_acl, head); |
= container_of(ptr, typeof(*acl), head); |
1578 |
return ccs_print_path_number_acl(head, acl, cond); |
return ccs_print_path_number_acl(head, acl); |
1579 |
} |
} |
1580 |
if (acl_type == CCS_TYPE_ENV_ACL) { |
if (acl_type == CCS_TYPE_ENV_ACL) { |
1581 |
struct ccs_env_acl *acl |
struct ccs_env_acl *acl |
1582 |
= container_of(ptr, struct ccs_env_acl, head); |
= container_of(ptr, typeof(*acl), head); |
1583 |
return ccs_print_env_acl(head, acl, cond); |
return ccs_print_env_acl(head, acl); |
1584 |
} |
} |
1585 |
if (acl_type == CCS_TYPE_CAPABILITY_ACL) { |
if (acl_type == CCS_TYPE_CAPABILITY_ACL) { |
1586 |
struct ccs_capability_acl *acl |
struct ccs_capability_acl *acl |
1587 |
= container_of(ptr, struct ccs_capability_acl, head); |
= container_of(ptr, typeof(*acl), head); |
1588 |
return ccs_print_capability_acl(head, acl, cond); |
return ccs_print_capability_acl(head, acl); |
1589 |
} |
} |
1590 |
if (acl_type == CCS_TYPE_IP_NETWORK_ACL) { |
if (acl_type == CCS_TYPE_IP_NETWORK_ACL) { |
1591 |
struct ccs_ip_network_acl *acl |
struct ccs_ip_network_acl *acl |
1592 |
= container_of(ptr, struct ccs_ip_network_acl, head); |
= container_of(ptr, typeof(*acl), head); |
1593 |
return ccs_print_network_acl(head, acl, cond); |
return ccs_print_network_acl(head, acl); |
1594 |
} |
} |
1595 |
if (acl_type == CCS_TYPE_SIGNAL_ACL) { |
if (acl_type == CCS_TYPE_SIGNAL_ACL) { |
1596 |
struct ccs_signal_acl *acl |
struct ccs_signal_acl *acl |
1597 |
= container_of(ptr, struct ccs_signal_acl, head); |
= container_of(ptr, typeof(*acl), head); |
1598 |
return ccs_print_signal_acl(head, acl, cond); |
return ccs_print_signal_acl(head, acl); |
1599 |
} |
} |
1600 |
if (acl_type == CCS_TYPE_MOUNT_ACL) { |
if (acl_type == CCS_TYPE_MOUNT_ACL) { |
1601 |
struct ccs_mount_acl *acl |
struct ccs_mount_acl *acl |
1602 |
= container_of(ptr, struct ccs_mount_acl, head); |
= container_of(ptr, typeof(*acl), head); |
1603 |
return ccs_print_mount_acl(head, acl, cond); |
return ccs_print_mount_acl(head, acl); |
1604 |
} |
} |
1605 |
BUG(); /* This must not happen. */ |
BUG(); /* This must not happen. */ |
1606 |
return false; |
return false; |
1607 |
} |
} |
1608 |
|
|
1609 |
/** |
/** |
1610 |
* ccs_read_domain_policy - Read domain policy. |
* ccs_read_domain2 - Read domain policy. |
1611 |
|
* |
1612 |
|
* @head: Pointer to "struct ccs_io_buffer". |
1613 |
|
* @domain: Pointer to "struct ccs_domain_info". |
1614 |
|
* |
1615 |
|
* Caller holds ccs_read_lock(). |
1616 |
|
* |
1617 |
|
* Returns true on success, false otherwise. |
1618 |
|
*/ |
1619 |
|
static bool ccs_read_domain2(struct ccs_io_buffer *head, |
1620 |
|
struct ccs_domain_info *domain) |
1621 |
|
{ |
1622 |
|
struct list_head *pos; |
1623 |
|
/* Print ACL entries in the domain. */ |
1624 |
|
list_for_each_cookie(pos, head->read_var2, &domain->acl_info_list) { |
1625 |
|
struct ccs_acl_info *ptr |
1626 |
|
= list_entry(pos, struct ccs_acl_info, list); |
1627 |
|
if (!ccs_print_entry(head, ptr)) |
1628 |
|
return false; |
1629 |
|
} |
1630 |
|
return true; |
1631 |
|
} |
1632 |
|
|
1633 |
|
/** |
1634 |
|
* ccs_read_domain - Read domain policy. |
1635 |
* |
* |
1636 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1637 |
* |
* |
1638 |
* Caller holds ccs_read_lock(). |
* Caller holds ccs_read_lock(). |
1639 |
*/ |
*/ |
1640 |
static void ccs_read_domain_policy(struct ccs_io_buffer *head) |
static void ccs_read_domain(struct ccs_io_buffer *head) |
1641 |
{ |
{ |
1642 |
struct list_head *dpos; |
struct list_head *pos; |
|
struct list_head *apos; |
|
1643 |
if (head->read_eof) |
if (head->read_eof) |
1644 |
return; |
return; |
1645 |
if (head->read_step == 0) |
list_for_each_cookie(pos, head->read_var1, &ccs_domain_list) { |
1646 |
head->read_step = 1; |
struct ccs_domain_info *domain = |
1647 |
list_for_each_cookie(dpos, head->read_var1, &ccs_domain_list) { |
list_entry(pos, struct ccs_domain_info, list); |
1648 |
struct ccs_domain_info *domain; |
switch (head->read_step) { |
1649 |
const char *quota_exceeded = ""; |
u8 i; |
1650 |
const char *transition_failed = ""; |
const char *w[CCS_MAX_DOMAIN_INFO_FLAGS]; |
1651 |
const char *ignore_global_allow_read = ""; |
case 0: |
1652 |
const char *ignore_global_allow_env = ""; |
if (domain->is_deleted && !head->read_single_domain) |
1653 |
domain = list_entry(dpos, struct ccs_domain_info, list); |
continue; |
1654 |
if (head->read_step != 1) |
/* Print domainname and flags. */ |
1655 |
goto acl_loop; |
for (i = 0; i < CCS_MAX_DOMAIN_INFO_FLAGS; i++) |
1656 |
if (domain->is_deleted && !head->read_single_domain) |
w[i] = domain->flags[i] ? ccs_dif[i] : ""; |
1657 |
continue; |
if (!ccs_io_printf(head, "%s\n" CCS_KEYWORD_USE_PROFILE |
1658 |
/* Print domainname and flags. */ |
"%u\n%s%s%s%s%s\n", |
1659 |
if (domain->quota_warned) |
domain->domainname->name, |
1660 |
quota_exceeded = "quota_exceeded\n"; |
domain->profile, |
1661 |
if (domain->domain_transition_failed) |
w[CCS_DIF_QUOTA_WARNED], |
1662 |
transition_failed = "transition_failed\n"; |
w[CCS_DIF_IGNORE_GLOBAL], |
1663 |
if (domain->ignore_global_allow_read) |
w[CCS_DIF_IGNORE_GLOBAL_ALLOW_READ], |
1664 |
ignore_global_allow_read |
w[CCS_DIF_IGNORE_GLOBAL_ALLOW_ENV], |
1665 |
= CCS_KEYWORD_IGNORE_GLOBAL_ALLOW_READ "\n"; |
w[CCS_DIF_TRANSITION_FAILED])) |
1666 |
if (domain->ignore_global_allow_env) |
return; |
1667 |
ignore_global_allow_env |
head->read_step++; |
1668 |
= CCS_KEYWORD_IGNORE_GLOBAL_ALLOW_ENV "\n"; |
/* fall through */ |
1669 |
if (!ccs_io_printf(head, "%s\n" CCS_KEYWORD_USE_PROFILE "%u\n" |
case 1: |
1670 |
"%s%s%s%s\n", domain->domainname->name, |
if (!ccs_read_domain2(head, domain)) |
|
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)) |
|
1671 |
return; |
return; |
1672 |
|
head->read_step++; |
1673 |
|
/* fall through */ |
1674 |
|
case 2: |
1675 |
|
if (!ccs_io_printf(head, "\n")) |
1676 |
|
return; |
1677 |
|
head->read_step = 0; |
1678 |
|
if (head->read_single_domain) |
1679 |
|
goto out; |
1680 |
} |
} |
|
head->read_step = 3; |
|
|
tail_mark: |
|
|
if (!ccs_io_printf(head, "\n")) |
|
|
return; |
|
|
head->read_step = 1; |
|
|
if (head->read_single_domain) |
|
|
break; |
|
1681 |
} |
} |
1682 |
|
out: |
1683 |
head->read_eof = true; |
head->read_eof = true; |
1684 |
} |
} |
1685 |
|
|
1780 |
struct ccs_domain_info *domain = NULL; |
struct ccs_domain_info *domain = NULL; |
1781 |
u32 ccs_flags = 0; |
u32 ccs_flags = 0; |
1782 |
/* Accessing write_buf is safe because head->io_sem is held. */ |
/* Accessing write_buf is safe because head->io_sem is held. */ |
1783 |
if (!buf) |
if (!buf) { |
1784 |
|
head->read_eof = true; |
1785 |
return; /* Do nothing if open(O_RDONLY). */ |
return; /* Do nothing if open(O_RDONLY). */ |
1786 |
|
} |
1787 |
if (head->read_avail || head->read_eof) |
if (head->read_avail || head->read_eof) |
1788 |
return; |
return; |
1789 |
head->read_eof = true; |
head->read_eof = true; |
1792 |
if (ccs_str_starts(&buf, "global-pid ")) |
if (ccs_str_starts(&buf, "global-pid ")) |
1793 |
global_pid = true; |
global_pid = true; |
1794 |
pid = (unsigned int) simple_strtoul(buf, NULL, 10); |
pid = (unsigned int) simple_strtoul(buf, NULL, 10); |
1795 |
read_lock(&tasklist_lock); |
ccs_tasklist_lock(); |
1796 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24) |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24) |
1797 |
if (global_pid) |
if (global_pid) |
1798 |
p = find_task_by_pid_ns(pid, &init_pid_ns); |
p = ccsecurity_exports.find_task_by_pid_ns(pid, &init_pid_ns); |
1799 |
else |
else |
1800 |
p = find_task_by_vpid(pid); |
p = ccsecurity_exports.find_task_by_vpid(pid); |
1801 |
#else |
#else |
1802 |
p = find_task_by_pid(pid); |
p = find_task_by_pid(pid); |
1803 |
#endif |
#endif |
1805 |
domain = ccs_task_domain(p); |
domain = ccs_task_domain(p); |
1806 |
ccs_flags = p->ccs_flags; |
ccs_flags = p->ccs_flags; |
1807 |
} |
} |
1808 |
read_unlock(&tasklist_lock); |
ccs_tasklist_unlock(); |
1809 |
if (!domain) |
if (!domain) |
1810 |
return; |
return; |
1811 |
if (!task_info) |
if (!task_info) |
1815 |
ccs_io_printf(head, "%u manager=%s execute_handler=%s " |
ccs_io_printf(head, "%u manager=%s execute_handler=%s " |
1816 |
"state[0]=%u state[1]=%u state[2]=%u", pid, |
"state[0]=%u state[1]=%u state[2]=%u", pid, |
1817 |
ccs_yesno(ccs_flags & |
ccs_yesno(ccs_flags & |
1818 |
CCS_TASK_IS_POLICY_MANAGER), |
CCS_TASK_IS_MANAGER), |
1819 |
ccs_yesno(ccs_flags & |
ccs_yesno(ccs_flags & |
1820 |
CCS_TASK_IS_EXECUTE_HANDLER), |
CCS_TASK_IS_EXECUTE_HANDLER), |
1821 |
(u8) (ccs_flags >> 24), |
(u8) (ccs_flags >> 24), |
1824 |
} |
} |
1825 |
|
|
1826 |
/** |
/** |
1827 |
* ccs_write_exception_policy - Write exception policy. |
* ccs_write_exception - Write exception policy. |
1828 |
* |
* |
1829 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1830 |
* |
* |
1831 |
* Returns 0 on success, negative value otherwise. |
* Returns 0 on success, negative value otherwise. |
1832 |
*/ |
*/ |
1833 |
static int ccs_write_exception_policy(struct ccs_io_buffer *head) |
static int ccs_write_exception(struct ccs_io_buffer *head) |
1834 |
{ |
{ |
1835 |
char *data = head->write_buf; |
char *data = head->write_buf; |
1836 |
bool is_delete = ccs_str_starts(&data, CCS_KEYWORD_DELETE); |
const bool is_delete = ccs_str_starts(&data, CCS_KEYWORD_DELETE); |
1837 |
if (ccs_str_starts(&data, CCS_KEYWORD_KEEP_DOMAIN)) |
u8 i; |
1838 |
return ccs_write_domain_keeper_policy(data, false, is_delete); |
static const struct { |
1839 |
if (ccs_str_starts(&data, CCS_KEYWORD_NO_KEEP_DOMAIN)) |
const char *keyword; |
1840 |
return ccs_write_domain_keeper_policy(data, true, is_delete); |
int (*write) (char *, const bool, const u8); |
1841 |
if (ccs_str_starts(&data, CCS_KEYWORD_INITIALIZE_DOMAIN)) |
} ccs_callback[8] = { |
1842 |
return ccs_write_domain_initializer_policy(data, false, |
{ CCS_KEYWORD_NO_KEEP_DOMAIN, ccs_write_domain_keeper }, |
1843 |
is_delete); |
{ CCS_KEYWORD_NO_INITIALIZE_DOMAIN, |
1844 |
if (ccs_str_starts(&data, CCS_KEYWORD_NO_INITIALIZE_DOMAIN)) |
ccs_write_domain_initializer }, |
1845 |
return ccs_write_domain_initializer_policy(data, true, |
{ CCS_KEYWORD_KEEP_DOMAIN, ccs_write_domain_keeper }, |
1846 |
is_delete); |
{ CCS_KEYWORD_INITIALIZE_DOMAIN, |
1847 |
if (ccs_str_starts(&data, CCS_KEYWORD_AGGREGATOR)) |
ccs_write_domain_initializer }, |
1848 |
return ccs_write_aggregator_policy(data, is_delete); |
{ CCS_KEYWORD_AGGREGATOR, ccs_write_aggregator }, |
1849 |
if (ccs_str_starts(&data, CCS_KEYWORD_ALLOW_READ)) |
{ CCS_KEYWORD_FILE_PATTERN, ccs_write_pattern }, |
1850 |
return ccs_write_globally_readable_policy(data, is_delete); |
{ CCS_KEYWORD_DENY_REWRITE, ccs_write_no_rewrite }, |
1851 |
if (ccs_str_starts(&data, CCS_KEYWORD_ALLOW_ENV)) |
{ CCS_KEYWORD_DENY_AUTOBIND, ccs_write_reserved_port } |
1852 |
return ccs_write_globally_usable_env_policy(data, is_delete); |
}; |
1853 |
if (ccs_str_starts(&data, CCS_KEYWORD_FILE_PATTERN)) |
static const char *ccs_name[CCS_MAX_GROUP] = { |
1854 |
return ccs_write_pattern_policy(data, is_delete); |
[CCS_PATH_GROUP] = CCS_KEYWORD_PATH_GROUP, |
1855 |
if (ccs_str_starts(&data, CCS_KEYWORD_PATH_GROUP)) |
[CCS_NUMBER_GROUP] = CCS_KEYWORD_NUMBER_GROUP, |
1856 |
return ccs_write_path_group_policy(data, is_delete); |
[CCS_ADDRESS_GROUP] = CCS_KEYWORD_ADDRESS_GROUP |
1857 |
if (ccs_str_starts(&data, CCS_KEYWORD_NUMBER_GROUP)) |
}; |
1858 |
return ccs_write_number_group_policy(data, is_delete); |
for (i = 0; i < 8; i++) { |
1859 |
if (ccs_str_starts(&data, CCS_KEYWORD_DENY_REWRITE)) |
if (ccs_str_starts(&data, ccs_callback[i].keyword)) |
1860 |
return ccs_write_no_rewrite_policy(data, is_delete); |
return ccs_callback[i].write(data, is_delete, i < 2); |
1861 |
if (ccs_str_starts(&data, CCS_KEYWORD_ADDRESS_GROUP)) |
} |
1862 |
return ccs_write_address_group_policy(data, is_delete); |
for (i = 0; i < CCS_MAX_GROUP; i++) { |
1863 |
if (ccs_str_starts(&data, CCS_KEYWORD_DENY_AUTOBIND)) |
if (ccs_str_starts(&data, ccs_name[i])) |
1864 |
return ccs_write_reserved_port_policy(data, is_delete); |
return ccs_write_group(data, is_delete, i); |
1865 |
return -EINVAL; |
} |
1866 |
|
return ccs_write_domain2(data, &ccs_global_domain, is_delete); |
1867 |
} |
} |
1868 |
|
|
1869 |
/** |
/** |
1870 |
* ccs_read_exception_policy - Read exception policy. |
* ccs_read_group - Read "struct ccs_path_group"/"struct ccs_number_group"/"struct ccs_address_group" list. |
1871 |
* |
* |
1872 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1873 |
|
* @idx: Index number. |
1874 |
|
* |
1875 |
|
* Returns true on success, false otherwise. |
1876 |
* |
* |
1877 |
* Caller holds ccs_read_lock(). |
* Caller holds ccs_read_lock(). |
1878 |
*/ |
*/ |
1879 |
static void ccs_read_exception_policy(struct ccs_io_buffer *head) |
static bool ccs_read_group(struct ccs_io_buffer *head, const int idx) |
1880 |
{ |
{ |
1881 |
if (head->read_eof) |
struct list_head *gpos; |
1882 |
return; |
struct list_head *mpos; |
1883 |
switch (head->read_step) { |
const char *w[3] = { "", "", "" }; |
1884 |
case 0: |
if (idx == CCS_PATH_GROUP) |
1885 |
head->read_var2 = NULL; |
w[0] = CCS_KEYWORD_PATH_GROUP; |
1886 |
head->read_step = 1; |
else if (idx == CCS_NUMBER_GROUP) |
1887 |
case 1: |
w[0] = CCS_KEYWORD_NUMBER_GROUP; |
1888 |
if (!ccs_read_domain_keeper_policy(head)) |
else if (idx == CCS_ADDRESS_GROUP) |
1889 |
break; |
w[0] = CCS_KEYWORD_ADDRESS_GROUP; |
1890 |
head->read_var2 = NULL; |
list_for_each_cookie(gpos, head->read_var1, &ccs_group_list[idx]) { |
1891 |
head->read_step = 2; |
struct ccs_group *group = |
1892 |
case 2: |
list_entry(gpos, struct ccs_group, head.list); |
1893 |
if (!ccs_read_globally_readable_policy(head)) |
w[1] = group->group_name->name; |
1894 |
break; |
list_for_each_cookie(mpos, head->read_var2, |
1895 |
head->read_var2 = NULL; |
&group->member_list) { |
1896 |
head->read_step = 3; |
char buffer[128]; |
1897 |
case 3: |
struct ccs_acl_head *ptr = |
1898 |
if (!ccs_read_globally_usable_env_policy(head)) |
list_entry(mpos, struct ccs_acl_head, list); |
1899 |
break; |
if (ptr->is_deleted) |
1900 |
head->read_var2 = NULL; |
continue; |
1901 |
head->read_step = 4; |
if (idx == CCS_PATH_GROUP) { |
1902 |
case 4: |
w[2] = container_of(ptr, struct ccs_path_group, |
1903 |
if (!ccs_read_domain_initializer_policy(head)) |
head)->member_name->name; |
1904 |
break; |
} else if (idx == CCS_NUMBER_GROUP) { |
1905 |
head->read_var2 = NULL; |
w[2] = buffer; |
1906 |
head->read_step = 6; |
ccs_print_number(buffer, sizeof(buffer), |
1907 |
case 6: |
&container_of |
1908 |
if (!ccs_read_aggregator_policy(head)) |
(ptr, struct ccs_number_group, |
1909 |
break; |
head)->number); |
1910 |
head->read_var2 = NULL; |
} else if (idx == CCS_ADDRESS_GROUP) { |
1911 |
head->read_step = 7; |
struct ccs_address_group *member = |
1912 |
case 7: |
container_of(ptr, typeof(*member), |
1913 |
if (!ccs_read_file_pattern(head)) |
head); |
1914 |
|
w[2] = buffer; |
1915 |
|
if (member->is_ipv6) |
1916 |
|
ccs_print_ipv6(buffer, sizeof(buffer), |
1917 |
|
member->min.ipv6, |
1918 |
|
member->max.ipv6); |
1919 |
|
else |
1920 |
|
ccs_print_ipv4(buffer, sizeof(buffer), |
1921 |
|
member->min.ipv4, |
1922 |
|
member->max.ipv4); |
1923 |
|
} |
1924 |
|
if (!ccs_io_printf(head, "%s%s %s\n", w[0], w[1], |
1925 |
|
w[2])) |
1926 |
|
return false; |
1927 |
|
} |
1928 |
|
} |
1929 |
|
return true; |
1930 |
|
} |
1931 |
|
|
1932 |
|
/** |
1933 |
|
* ccs_read_policy - Read "struct ccs_..._entry" list. |
1934 |
|
* |
1935 |
|
* @head: Pointer to "struct ccs_io_buffer". |
1936 |
|
* @idx: Index number. |
1937 |
|
* |
1938 |
|
* Returns true on success, false otherwise. |
1939 |
|
* |
1940 |
|
* Caller holds ccs_read_lock(). |
1941 |
|
*/ |
1942 |
|
static bool ccs_read_policy(struct ccs_io_buffer *head, const int idx) |
1943 |
|
{ |
1944 |
|
struct list_head *pos; |
1945 |
|
list_for_each_cookie(pos, head->read_var2, &ccs_policy_list[idx]) { |
1946 |
|
const char *w[4] = { "", "", "", "" }; |
1947 |
|
char buffer[16]; |
1948 |
|
struct ccs_acl_head *acl = container_of(pos, typeof(*acl), |
1949 |
|
list); |
1950 |
|
if (acl->is_deleted) |
1951 |
|
continue; |
1952 |
|
switch (idx) { |
1953 |
|
case CCS_ID_DOMAIN_KEEPER: |
1954 |
|
{ |
1955 |
|
struct ccs_domain_keeper *ptr = |
1956 |
|
container_of(acl, typeof(*ptr), head); |
1957 |
|
w[0] = ptr->is_not ? |
1958 |
|
CCS_KEYWORD_NO_KEEP_DOMAIN : |
1959 |
|
CCS_KEYWORD_KEEP_DOMAIN; |
1960 |
|
if (ptr->program) { |
1961 |
|
w[1] = ptr->program->name; |
1962 |
|
w[2] = " from "; |
1963 |
|
} |
1964 |
|
w[3] = ptr->domainname->name; |
1965 |
|
} |
1966 |
break; |
break; |
1967 |
head->read_var2 = NULL; |
case CCS_ID_DOMAIN_INITIALIZER: |
1968 |
head->read_step = 8; |
{ |
1969 |
case 8: |
struct ccs_domain_initializer *ptr = |
1970 |
if (!ccs_read_no_rewrite_policy(head)) |
container_of(acl, typeof(*ptr), head); |
1971 |
|
w[0] = ptr->is_not ? |
1972 |
|
CCS_KEYWORD_NO_INITIALIZE_DOMAIN : |
1973 |
|
CCS_KEYWORD_INITIALIZE_DOMAIN; |
1974 |
|
w[1] = ptr->program->name; |
1975 |
|
if (ptr->domainname) { |
1976 |
|
w[2] = " from "; |
1977 |
|
w[3] = ptr->domainname->name; |
1978 |
|
} |
1979 |
|
} |
1980 |
break; |
break; |
1981 |
head->read_var2 = NULL; |
case CCS_ID_AGGREGATOR: |
1982 |
head->read_step = 9; |
{ |
1983 |
case 9: |
struct ccs_aggregator *ptr = |
1984 |
if (!ccs_read_path_group_policy(head)) |
container_of(acl, typeof(*ptr), head); |
1985 |
|
w[0] = CCS_KEYWORD_AGGREGATOR; |
1986 |
|
w[1] = ptr->original_name->name; |
1987 |
|
w[2] = " "; |
1988 |
|
w[3] = ptr->aggregated_name->name; |
1989 |
|
} |
1990 |
break; |
break; |
1991 |
head->read_var1 = NULL; |
case CCS_ID_PATTERN: |
1992 |
head->read_var2 = NULL; |
{ |
1993 |
head->read_step = 10; |
struct ccs_pattern *ptr = |
1994 |
case 10: |
container_of(acl, typeof(*ptr), head); |
1995 |
if (!ccs_read_number_group_policy(head)) |
w[0] = CCS_KEYWORD_FILE_PATTERN; |
1996 |
|
w[1] = ptr->pattern->name; |
1997 |
|
} |
1998 |
break; |
break; |
1999 |
head->read_var1 = NULL; |
case CCS_ID_NO_REWRITE: |
2000 |
head->read_var2 = NULL; |
{ |
2001 |
head->read_step = 11; |
struct ccs_no_rewrite *ptr = |
2002 |
case 11: |
container_of(acl, typeof(*ptr), head); |
2003 |
if (!ccs_read_address_group_policy(head)) |
w[0] = CCS_KEYWORD_DENY_REWRITE; |
2004 |
|
w[1] = ptr->pattern->name; |
2005 |
|
} |
2006 |
break; |
break; |
2007 |
head->read_var2 = NULL; |
case CCS_ID_RESERVEDPORT: |
2008 |
head->read_step = 12; |
{ |
2009 |
case 12: |
struct ccs_reserved *ptr = |
2010 |
if (!ccs_read_reserved_port_policy(head)) |
container_of(acl, typeof(*ptr), head); |
2011 |
|
const u16 min_port = ptr->min_port; |
2012 |
|
const u16 max_port = ptr->max_port; |
2013 |
|
w[0] = CCS_KEYWORD_DENY_AUTOBIND; |
2014 |
|
snprintf(buffer, sizeof(buffer) - 1, "%u%c%u", |
2015 |
|
min_port, min_port != max_port ? |
2016 |
|
'-' : '\0', max_port); |
2017 |
|
buffer[sizeof(buffer) - 1] = '\0'; |
2018 |
|
w[1] = buffer; |
2019 |
|
} |
2020 |
break; |
break; |
2021 |
head->read_eof = true; |
default: |
2022 |
|
continue; |
2023 |
|
} |
2024 |
|
if (!ccs_io_printf(head, "%s%s%s%s\n", w[0], w[1], w[2], w[3])) |
2025 |
|
return false; |
2026 |
} |
} |
2027 |
|
return true; |
2028 |
|
} |
2029 |
|
|
2030 |
|
static void ccs_read_global_domain(struct ccs_io_buffer *head) |
2031 |
|
{ |
2032 |
|
if (!head->read_eof) |
2033 |
|
head->read_eof = ccs_read_domain2(head, &ccs_global_domain); |
2034 |
|
} |
2035 |
|
|
2036 |
|
/** |
2037 |
|
* ccs_read_exception - Read exception policy. |
2038 |
|
* |
2039 |
|
* @head: Pointer to "struct ccs_io_buffer". |
2040 |
|
* |
2041 |
|
* Caller holds ccs_read_lock(). |
2042 |
|
*/ |
2043 |
|
static void ccs_read_exception(struct ccs_io_buffer *head) |
2044 |
|
{ |
2045 |
|
if (head->read_eof) |
2046 |
|
return; |
2047 |
|
while (head->read_step < CCS_MAX_POLICY && |
2048 |
|
ccs_read_policy(head, head->read_step)) |
2049 |
|
head->read_step++; |
2050 |
|
if (head->read_step < CCS_MAX_POLICY) |
2051 |
|
return; |
2052 |
|
while (head->read_step < CCS_MAX_POLICY + CCS_MAX_GROUP && |
2053 |
|
ccs_read_group(head, head->read_step - CCS_MAX_POLICY)) |
2054 |
|
head->read_step++; |
2055 |
|
if (head->read_step < CCS_MAX_POLICY + CCS_MAX_GROUP) |
2056 |
|
return; |
2057 |
|
head->read = ccs_read_global_domain; |
2058 |
} |
} |
2059 |
|
|
2060 |
/** |
/** |
2061 |
* ccs_get_argv0 - Get argv[0]. |
* ccs_get_argv0 - Get argv[0]. |
2062 |
* |
* |
2063 |
* @ee: Pointer to "struct ccs_execve_entry". |
* @ee: Pointer to "struct ccs_execve". |
2064 |
* |
* |
2065 |
* Returns true on success, false otherwise. |
* Returns true on success, false otherwise. |
2066 |
*/ |
*/ |
2067 |
static bool ccs_get_argv0(struct ccs_execve_entry *ee) |
static bool ccs_get_argv0(struct ccs_execve *ee) |
2068 |
{ |
{ |
2069 |
struct linux_binprm *bprm = ee->bprm; |
struct linux_binprm *bprm = ee->bprm; |
2070 |
char *arg_ptr = ee->tmp; |
char *arg_ptr = ee->tmp; |
2110 |
return false; |
return false; |
2111 |
} |
} |
2112 |
|
|
|
/** |
|
|
* ccs_get_execute_condition - Get condition part for execute requests. |
|
|
* |
|
|
* @ee: Pointer to "struct ccs_execve_entry". |
|
|
* |
|
|
* Returns pointer to "struct ccs_condition" on success, NULL otherwise. |
|
|
*/ |
|
|
static struct ccs_condition *ccs_get_execute_condition(struct ccs_execve_entry |
|
|
*ee) |
|
|
{ |
|
|
struct ccs_condition *cond; |
|
|
char *buf; |
|
|
int len = 256; |
|
|
char *realpath = NULL; |
|
|
char *argv0 = NULL; |
|
|
const struct ccs_profile *profile = ccs_profile(ee->r.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, GFP_KERNEL); |
|
|
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; |
|
|
} |
|
|
buf = kmalloc(len, GFP_KERNEL); |
|
|
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; |
|
|
} |
|
|
|
|
2113 |
/* Wait queue for ccs_query_list. */ |
/* Wait queue for ccs_query_list. */ |
2114 |
static DECLARE_WAIT_QUEUE_HEAD(ccs_query_wait); |
static DECLARE_WAIT_QUEUE_HEAD(ccs_query_wait); |
2115 |
|
|
2132 |
/* Number of "struct file" referring /proc/ccs/query interface. */ |
/* Number of "struct file" referring /proc/ccs/query interface. */ |
2133 |
static atomic_t ccs_query_observers = ATOMIC_INIT(0); |
static atomic_t ccs_query_observers = ATOMIC_INIT(0); |
2134 |
|
|
2135 |
|
static void ccs_addprintf(char *buffer, int len, const char *fmt, ...) |
2136 |
|
{ |
2137 |
|
va_list args; |
2138 |
|
const int pos = strlen(buffer); |
2139 |
|
va_start(args, fmt); |
2140 |
|
vsnprintf(buffer + pos, len - pos - 1, fmt, args); |
2141 |
|
va_end(args); |
2142 |
|
} |
2143 |
|
|
2144 |
/** |
/** |
2145 |
* ccs_supervisor - Ask for the supervisor's decision. |
* ccs_supervisor - Ask for the supervisor's decision. |
2146 |
* |
* |
2147 |
* @r: Pointer to "struct ccs_request_info". |
* @r: Pointer to "struct ccs_request_info". |
2148 |
* @fmt: The printf()'s format string, followed by parameters. |
* @fmt: The printf()'s format string, followed by parameters. |
2149 |
* |
* |
2150 |
* Returns 0 if the supervisor decided to permit the access request which |
* Returns 0 if the supervisor decided to permit the access request which |
2151 |
* violated the policy in enforcing mode, 1 if the supervisor decided to |
* violated the policy in enforcing mode, CCS_RETRY_REQUEST if the supervisor |
2152 |
* retry the access request which violated the policy in enforcing mode, |
* decided to retry the access request which violated the policy in enforcing |
2153 |
* 0 if it is not in enforcing mode, -EPERM otherwise. |
* mode, 0 if it is not in enforcing mode, -EPERM otherwise. |
2154 |
*/ |
*/ |
2155 |
int ccs_supervisor(struct ccs_request_info *r, const char *fmt, ...) |
int ccs_supervisor(struct ccs_request_info *r, const char *fmt, ...) |
2156 |
{ |
{ |
2162 |
struct ccs_query_entry *ccs_query_entry = NULL; |
struct ccs_query_entry *ccs_query_entry = NULL; |
2163 |
bool quota_exceeded = false; |
bool quota_exceeded = false; |
2164 |
char *header; |
char *header; |
2165 |
if (!r->domain) |
struct ccs_domain_info * const domain = ccs_current_domain(); |
2166 |
r->domain = ccs_current_domain(); |
va_start(args, fmt); |
2167 |
switch (r->mode) { |
len = vsnprintf((char *) &pos, sizeof(pos) - 1, fmt, args) + 80; |
2168 |
|
va_end(args); |
2169 |
|
if (r->mode == CCS_CONFIG_LEARNING) { |
2170 |
char *buffer; |
char *buffer; |
2171 |
struct ccs_condition *cond; |
char *realpath = NULL; |
2172 |
case CCS_CONFIG_LEARNING: |
char *argv0 = NULL; |
2173 |
|
const char *symlink = NULL; |
2174 |
|
const struct ccs_preference *pref; |
2175 |
if (!ccs_domain_quota_ok(r)) |
if (!ccs_domain_quota_ok(r)) |
2176 |
return 0; |
return 0; |
2177 |
va_start(args, fmt); |
pref = ccs_profile(r->profile)->learning; |
2178 |
len = vsnprintf((char *) &pos, sizeof(pos) - 1, fmt, args) + 4; |
if (r->param_type == CCS_TYPE_PATH_ACL && |
2179 |
va_end(args); |
r->param.path.operation == CCS_TYPE_EXECUTE) { |
2180 |
buffer = kmalloc(len, GFP_KERNEL); |
if (pref->learning_exec_realpath) { |
2181 |
if (!buffer) |
struct file *file = r->ee->bprm->file; |
2182 |
return 0; |
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 20) |
2183 |
va_start(args, fmt); |
struct path path = { file->f_vfsmnt, |
2184 |
vsnprintf(buffer, len - 1, fmt, args); |
file->f_dentry }; |
2185 |
va_end(args); |
realpath = ccs_realpath_from_path(&path); |
2186 |
ccs_normalize_line(buffer); |
#else |
2187 |
if (r->ee && !strncmp(buffer, "allow_execute ", 14)) |
realpath = ccs_realpath_from_path(&file-> |
2188 |
cond = ccs_get_execute_condition(r->ee); |
f_path); |
2189 |
else if (r->obj && r->obj->symlink_target) |
#endif |
2190 |
cond = ccs_get_symlink_condition(r); |
if (realpath) |
2191 |
else if ((current->ccs_flags & CCS_TASK_IS_EXECUTE_HANDLER)) { |
len += strlen(realpath); |
2192 |
char str[] = "if task.type=execute_handler"; |
} |
2193 |
cond = ccs_get_condition(str); |
if (pref->learning_exec_argv0) { |
2194 |
} else |
if (ccs_get_argv0(r->ee)) { |
2195 |
cond = NULL; |
argv0 = r->ee->tmp; |
2196 |
ccs_write_domain_policy2(buffer, r->domain, cond, false); |
len += strlen(argv0); |
2197 |
ccs_put_condition(cond); |
} |
2198 |
kfree(buffer); |
} |
2199 |
/* fall through */ |
} |
2200 |
case CCS_CONFIG_PERMISSIVE: |
if (r->param_type == CCS_TYPE_PATH_ACL && |
2201 |
|
r->param.path.operation == CCS_TYPE_SYMLINK && |
2202 |
|
pref->learning_symlink_target) { |
2203 |
|
symlink = r->obj->symlink_target->name; |
2204 |
|
len += strlen(symlink); |
2205 |
|
} |
2206 |
|
buffer = kmalloc(len, CCS_GFP_FLAGS); |
2207 |
|
if (buffer) { |
2208 |
|
const bool handler = (current->ccs_flags & |
2209 |
|
CCS_TASK_IS_EXECUTE_HANDLER) |
2210 |
|
!= 0; |
2211 |
|
va_start(args, fmt); |
2212 |
|
vsnprintf(buffer, len - 1, fmt, args); |
2213 |
|
va_end(args); |
2214 |
|
if (handler || realpath || argv0 || symlink) { |
2215 |
|
ccs_addprintf(buffer, len, " if"); |
2216 |
|
if (handler) |
2217 |
|
ccs_addprintf(buffer, len, " task.type" |
2218 |
|
"=execute_handler"); |
2219 |
|
if (realpath) |
2220 |
|
ccs_addprintf(buffer, len, |
2221 |
|
" exec.realpath=\"%s\"", |
2222 |
|
realpath); |
2223 |
|
if (argv0) |
2224 |
|
ccs_addprintf(buffer, len, |
2225 |
|
" exec.argv[0]=\"%s\"", |
2226 |
|
argv0); |
2227 |
|
if (symlink) |
2228 |
|
ccs_addprintf(buffer, len, |
2229 |
|
" symlink.target=\"%s\"", |
2230 |
|
symlink); |
2231 |
|
} |
2232 |
|
ccs_normalize_line(buffer); |
2233 |
|
ccs_write_domain2(buffer, domain, false); |
2234 |
|
kfree(buffer); |
2235 |
|
} |
2236 |
|
kfree(realpath); |
2237 |
return 0; |
return 0; |
2238 |
} |
} |
2239 |
|
if (r->mode != CCS_CONFIG_ENFORCING) |
2240 |
|
return 0; |
2241 |
if (!atomic_read(&ccs_query_observers)) { |
if (!atomic_read(&ccs_query_observers)) { |
2242 |
int i; |
int i; |
2243 |
if (current->ccs_flags & CCS_DONT_SLEEP_ON_ENFORCE_ERROR) |
if (current->ccs_flags & CCS_DONT_SLEEP_ON_ENFORCE_ERROR) |
2244 |
return -EPERM; |
return -EPERM; |
2245 |
for (i = 0; i < ccs_profile(r->domain->profile)->enforcing-> |
for (i = 0; i < ccs_profile(domain->profile)->enforcing-> |
2246 |
enforcing_penalty; i++) { |
enforcing_penalty; i++) { |
2247 |
set_current_state(TASK_INTERRUPTIBLE); |
set_current_state(TASK_INTERRUPTIBLE); |
2248 |
schedule_timeout(HZ / 10); |
schedule_timeout(HZ / 10); |
2249 |
} |
} |
2250 |
return -EPERM; |
return -EPERM; |
2251 |
} |
} |
2252 |
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); |
|
2253 |
if (!header) |
if (!header) |
2254 |
goto out; |
goto out; |
2255 |
ccs_query_entry = kzalloc(sizeof(*ccs_query_entry), GFP_KERNEL); |
ccs_query_entry = kzalloc(sizeof(*ccs_query_entry), CCS_GFP_FLAGS); |
2256 |
if (!ccs_query_entry) |
if (!ccs_query_entry) |
2257 |
goto out; |
goto out; |
2258 |
len = ccs_round2(len); |
len = ccs_round2(len); |
2259 |
ccs_query_entry->query = kzalloc(len, GFP_KERNEL); |
ccs_query_entry->query = kzalloc(len, CCS_GFP_FLAGS); |
2260 |
if (!ccs_query_entry->query) |
if (!ccs_query_entry->query) |
2261 |
goto out; |
goto out; |
2262 |
INIT_LIST_HEAD(&ccs_query_entry->list); |
INIT_LIST_HEAD(&ccs_query_entry->list); |
2271 |
spin_unlock(&ccs_query_list_lock); |
spin_unlock(&ccs_query_list_lock); |
2272 |
if (quota_exceeded) |
if (quota_exceeded) |
2273 |
goto out; |
goto out; |
2274 |
pos = snprintf(ccs_query_entry->query, len - 1, "Q%u-%hu\n%s", |
snprintf(ccs_query_entry->query, len - 1, "Q%u-%hu\n%s", |
2275 |
ccs_query_entry->serial, r->retry, header); |
ccs_query_entry->serial, r->retry, header); |
2276 |
kfree(header); |
kfree(header); |
2277 |
header = NULL; |
header = NULL; |
2278 |
va_start(args, fmt); |
ccs_addprintf(ccs_query_entry->query, len, fmt, args); |
|
vsnprintf(ccs_query_entry->query + pos, len - 1 - pos, fmt, args); |
|
2279 |
ccs_query_entry->query_len = strlen(ccs_query_entry->query) + 1; |
ccs_query_entry->query_len = strlen(ccs_query_entry->query) + 1; |
|
va_end(args); |
|
2280 |
spin_lock(&ccs_query_list_lock); |
spin_lock(&ccs_query_list_lock); |
2281 |
list_add_tail(&ccs_query_entry->list, &ccs_query_list); |
list_add_tail(&ccs_query_entry->list, &ccs_query_list); |
2282 |
spin_unlock(&ccs_query_list_lock); |
spin_unlock(&ccs_query_list_lock); |
2296 |
spin_unlock(&ccs_query_list_lock); |
spin_unlock(&ccs_query_list_lock); |
2297 |
switch (ccs_query_entry->answer) { |
switch (ccs_query_entry->answer) { |
2298 |
case 3: /* Asked to retry by administrator. */ |
case 3: /* Asked to retry by administrator. */ |
2299 |
error = 1; |
error = CCS_RETRY_REQUEST; |
2300 |
r->retry++; |
r->retry++; |
2301 |
break; |
break; |
2302 |
case 1: |
case 1: |
2336 |
for (i = 0; i < 2; i++) { |
for (i = 0; i < 2; i++) { |
2337 |
spin_lock(&ccs_query_list_lock); |
spin_lock(&ccs_query_list_lock); |
2338 |
list_for_each(tmp, &ccs_query_list) { |
list_for_each(tmp, &ccs_query_list) { |
2339 |
struct ccs_query_entry *ptr |
struct ccs_query_entry *ptr = |
2340 |
= list_entry(tmp, struct ccs_query_entry, list); |
list_entry(tmp, struct ccs_query_entry, list); |
2341 |
if (ptr->answer) |
if (ptr->answer) |
2342 |
continue; |
continue; |
2343 |
found = true; |
found = true; |
2387 |
head->read_step = 0; |
head->read_step = 0; |
2388 |
return; |
return; |
2389 |
} |
} |
2390 |
buf = kzalloc(len, GFP_KERNEL); |
buf = kzalloc(len, CCS_GFP_FLAGS); |
2391 |
if (!buf) |
if (!buf) |
2392 |
return; |
return; |
2393 |
pos = 0; |
pos = 0; |
2463 |
{ |
{ |
2464 |
if (head->read_eof) |
if (head->read_eof) |
2465 |
return; |
return; |
2466 |
ccs_io_printf(head, "1.7.1-pre"); |
ccs_io_printf(head, "1.7.2"); |
2467 |
head->read_eof = true; |
head->read_eof = true; |
2468 |
} |
} |
2469 |
|
|
2494 |
*/ |
*/ |
2495 |
int ccs_open_control(const u8 type, struct file *file) |
int ccs_open_control(const u8 type, struct file *file) |
2496 |
{ |
{ |
2497 |
struct ccs_io_buffer *head = kzalloc(sizeof(*head), GFP_KERNEL); |
struct ccs_io_buffer *head = kzalloc(sizeof(*head), CCS_GFP_FLAGS); |
2498 |
if (!head) |
if (!head) |
2499 |
return -ENOMEM; |
return -ENOMEM; |
2500 |
mutex_init(&head->io_sem); |
mutex_init(&head->io_sem); |
2501 |
head->type = type; |
head->type = type; |
2502 |
switch (type) { |
switch (type) { |
2503 |
case CCS_DOMAINPOLICY: /* /proc/ccs/domain_policy */ |
case CCS_DOMAINPOLICY: /* /proc/ccs/domain_policy */ |
2504 |
head->write = ccs_write_domain_policy; |
head->write = ccs_write_domain; |
2505 |
head->read = ccs_read_domain_policy; |
head->read = ccs_read_domain; |
2506 |
break; |
break; |
2507 |
case CCS_EXCEPTIONPOLICY: /* /proc/ccs/exception_policy */ |
case CCS_EXCEPTIONPOLICY: /* /proc/ccs/exception_policy */ |
2508 |
head->write = ccs_write_exception_policy; |
head->write = ccs_write_exception; |
2509 |
head->read = ccs_read_exception_policy; |
head->read = ccs_read_exception; |
2510 |
break; |
break; |
2511 |
#ifdef CONFIG_CCSECURITY_AUDIT |
#ifdef CONFIG_CCSECURITY_AUDIT |
2512 |
case CCS_GRANTLOG: /* /proc/ccs/grant_log */ |
case CCS_GRANTLOG: /* /proc/ccs/grant_log */ |
|
head->poll = ccs_poll_grant_log; |
|
|
head->read = ccs_read_grant_log; |
|
|
break; |
|
2513 |
case CCS_REJECTLOG: /* /proc/ccs/reject_log */ |
case CCS_REJECTLOG: /* /proc/ccs/reject_log */ |
2514 |
head->poll = ccs_poll_reject_log; |
head->poll = ccs_poll_log; |
2515 |
head->read = ccs_read_reject_log; |
head->read = ccs_read_log; |
2516 |
break; |
break; |
2517 |
#endif |
#endif |
2518 |
case CCS_SELFDOMAIN: /* /proc/ccs/self_domain */ |
case CCS_SELFDOMAIN: /* /proc/ccs/self_domain */ |
2552 |
head->read = ccs_read_query; |
head->read = ccs_read_query; |
2553 |
break; |
break; |
2554 |
case CCS_MANAGER: /* /proc/ccs/manager */ |
case CCS_MANAGER: /* /proc/ccs/manager */ |
2555 |
head->write = ccs_write_manager_policy; |
head->write = ccs_write_manager; |
2556 |
head->read = ccs_read_manager_policy; |
head->read = ccs_read_manager; |
2557 |
break; |
break; |
2558 |
} |
} |
2559 |
if (!(file->f_mode & FMODE_READ)) { |
if (!(file->f_mode & FMODE_READ)) { |
2567 |
/* Don't allocate read_buf for poll() access. */ |
/* Don't allocate read_buf for poll() access. */ |
2568 |
if (!head->readbuf_size) |
if (!head->readbuf_size) |
2569 |
head->readbuf_size = 4096; |
head->readbuf_size = 4096; |
2570 |
head->read_buf = kzalloc(head->readbuf_size, GFP_KERNEL); |
head->read_buf = kzalloc(head->readbuf_size, CCS_GFP_FLAGS); |
2571 |
if (!head->read_buf) { |
if (!head->read_buf) { |
2572 |
kfree(head); |
kfree(head); |
2573 |
return -ENOMEM; |
return -ENOMEM; |
2581 |
head->write = NULL; |
head->write = NULL; |
2582 |
} else if (head->write) { |
} else if (head->write) { |
2583 |
head->writebuf_size = 4096; |
head->writebuf_size = 4096; |
2584 |
head->write_buf = kzalloc(head->writebuf_size, GFP_KERNEL); |
head->write_buf = kzalloc(head->writebuf_size, CCS_GFP_FLAGS); |
2585 |
if (!head->write_buf) { |
if (!head->write_buf) { |
2586 |
kfree(head->read_buf); |
kfree(head->read_buf); |
2587 |
kfree(head); |
kfree(head); |
2590 |
} |
} |
2591 |
if (type != CCS_QUERY && |
if (type != CCS_QUERY && |
2592 |
type != CCS_GRANTLOG && type != CCS_REJECTLOG) |
type != CCS_GRANTLOG && type != CCS_REJECTLOG) |
2593 |
head->reader_idx = ccs_read_lock(); |
head->reader_idx = ccs_lock(); |
2594 |
file->private_data = head; |
file->private_data = head; |
2595 |
/* |
/* |
2596 |
* Call the handler now if the file is /proc/ccs/self_domain |
* Call the handler now if the file is /proc/ccs/self_domain |
2643 |
int len = 0; |
int len = 0; |
2644 |
struct ccs_io_buffer *head = file->private_data; |
struct ccs_io_buffer *head = file->private_data; |
2645 |
char *cp; |
char *cp; |
2646 |
|
int idx; |
2647 |
if (!head->read) |
if (!head->read) |
2648 |
return -ENOSYS; |
return -ENOSYS; |
2649 |
if (!access_ok(VERIFY_WRITE, buffer, buffer_len)) |
if (!access_ok(VERIFY_WRITE, buffer, buffer_len)) |
2650 |
return -EFAULT; |
return -EFAULT; |
2651 |
if (mutex_lock_interruptible(&head->io_sem)) |
if (mutex_lock_interruptible(&head->io_sem)) |
2652 |
return -EINTR; |
return -EINTR; |
2653 |
|
idx = ccs_read_lock(); |
2654 |
while (1) { |
while (1) { |
2655 |
/* Call the policy handler. */ |
/* Call the policy handler. */ |
2656 |
head->read(head); |
head->read(head); |
2659 |
if (len || head->poll || head->read_eof) |
if (len || head->poll || head->read_eof) |
2660 |
break; |
break; |
2661 |
len = head->readbuf_size * 2; |
len = head->readbuf_size * 2; |
2662 |
cp = kzalloc(len, GFP_KERNEL); |
cp = kzalloc(len, CCS_GFP_FLAGS); |
2663 |
if (!cp) { |
if (!cp) { |
2664 |
len = -ENOMEM; |
len = -ENOMEM; |
2665 |
goto out; |
goto out; |
2681 |
head->read_avail -= len; |
head->read_avail -= len; |
2682 |
memmove(cp, cp + len, head->read_avail); |
memmove(cp, cp + len, head->read_avail); |
2683 |
out: |
out: |
2684 |
|
ccs_read_unlock(idx); |
2685 |
mutex_unlock(&head->io_sem); |
mutex_unlock(&head->io_sem); |
2686 |
return len; |
return len; |
2687 |
} |
} |
2702 |
int error = buffer_len; |
int error = buffer_len; |
2703 |
int avail_len = buffer_len; |
int avail_len = buffer_len; |
2704 |
char *cp0 = head->write_buf; |
char *cp0 = head->write_buf; |
2705 |
|
int idx; |
2706 |
if (!head->write) |
if (!head->write) |
2707 |
return -ENOSYS; |
return -ENOSYS; |
2708 |
if (!access_ok(VERIFY_READ, buffer, buffer_len)) |
if (!access_ok(VERIFY_READ, buffer, buffer_len)) |
2709 |
return -EFAULT; |
return -EFAULT; |
|
/* Don't allow updating policies by non manager programs. */ |
|
|
if (head->write != ccs_write_pid && |
|
|
head->write != ccs_write_domain_policy && |
|
|
!ccs_is_policy_manager()) |
|
|
return -EPERM; |
|
2710 |
if (mutex_lock_interruptible(&head->io_sem)) |
if (mutex_lock_interruptible(&head->io_sem)) |
2711 |
return -EINTR; |
return -EINTR; |
2712 |
|
idx = ccs_read_lock(); |
2713 |
|
/* Don't allow updating policies by non manager programs. */ |
2714 |
|
if (head->write != ccs_write_pid && head->write != ccs_write_domain && |
2715 |
|
!ccs_manager()) { |
2716 |
|
ccs_read_unlock(idx); |
2717 |
|
mutex_unlock(&head->io_sem); |
2718 |
|
return -EPERM; |
2719 |
|
} |
2720 |
/* Read a line and dispatch it to the policy handler. */ |
/* Read a line and dispatch it to the policy handler. */ |
2721 |
while (avail_len > 0) { |
while (avail_len > 0) { |
2722 |
char c; |
char c; |
2723 |
if (head->write_avail >= head->writebuf_size - 1) { |
if (head->write_avail >= head->writebuf_size - 1) { |
2724 |
const int len = head->writebuf_size * 2; |
const int len = head->writebuf_size * 2; |
2725 |
char *cp = kzalloc(len, GFP_KERNEL); |
char *cp = kzalloc(len, CCS_GFP_FLAGS); |
2726 |
if (!cp) { |
if (!cp) { |
2727 |
error = -ENOMEM; |
error = -ENOMEM; |
2728 |
break; |
break; |
2747 |
ccs_normalize_line(cp0); |
ccs_normalize_line(cp0); |
2748 |
head->write(head); |
head->write(head); |
2749 |
} |
} |
2750 |
|
ccs_read_unlock(idx); |
2751 |
mutex_unlock(&head->io_sem); |
mutex_unlock(&head->io_sem); |
2752 |
return error; |
return error; |
2753 |
} |
} |
2771 |
atomic_dec(&ccs_query_observers); |
atomic_dec(&ccs_query_observers); |
2772 |
if (type != CCS_QUERY && |
if (type != CCS_QUERY && |
2773 |
type != CCS_GRANTLOG && type != CCS_REJECTLOG) |
type != CCS_GRANTLOG && type != CCS_REJECTLOG) |
2774 |
ccs_read_unlock(head->reader_idx); |
ccs_unlock(head->reader_idx); |
2775 |
/* Release memory used for policy I/O. */ |
/* Release memory used for policy I/O. */ |
2776 |
kfree(head->read_buf); |
kfree(head->read_buf); |
2777 |
head->read_buf = NULL; |
head->read_buf = NULL; |
2784 |
ccs_run_gc(); |
ccs_run_gc(); |
2785 |
return 0; |
return 0; |
2786 |
} |
} |
2787 |
|
|
2788 |
|
void __init ccs_policy_io_init(void) |
2789 |
|
{ |
2790 |
|
ccsecurity_ops.check_profile = ccs_check_profile; |
2791 |
|
} |