5 |
* |
* |
6 |
* Copyright (C) 2005-2008 NTT DATA CORPORATION |
* Copyright (C) 2005-2008 NTT DATA CORPORATION |
7 |
* |
* |
8 |
* Version: 1.6.6-pre 2008/12/22 |
* Version: 1.6.6-pre 2008/12/24 |
9 |
* |
* |
10 |
* 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. |
11 |
* See README.ccs for ChangeLog. |
* See README.ccs for ChangeLog. |
27 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 0) |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 0) |
28 |
#include <linux/namei.h> |
#include <linux/namei.h> |
29 |
#include <linux/mount.h> |
#include <linux/mount.h> |
30 |
static const int lookup_flags = LOOKUP_FOLLOW; |
static const int ccs_lookup_flags = LOOKUP_FOLLOW; |
31 |
#else |
#else |
32 |
static const int lookup_flags = LOOKUP_FOLLOW | LOOKUP_POSITIVE; |
static const int ccs_lookup_flags = LOOKUP_FOLLOW | LOOKUP_POSITIVE; |
33 |
#endif |
#endif |
34 |
#include <linux/realpath.h> |
#include <linux/realpath.h> |
35 |
#include <linux/ccs_common.h> |
#include <linux/ccs_common.h> |
56 |
#endif |
#endif |
57 |
|
|
58 |
/* Has /sbin/init started? */ |
/* Has /sbin/init started? */ |
59 |
bool sbin_init_started; |
bool ccs_sbin_init_started; |
60 |
|
|
61 |
/* Log level for SAKURA's printk(). */ |
/* Log level for SAKURA's printk(). */ |
62 |
const char *ccs_log_level = KERN_DEBUG; |
const char *ccs_log_level = KERN_DEBUG; |
63 |
|
|
64 |
/* String table for functionality that takes 4 modes. */ |
/* String table for functionality that takes 4 modes. */ |
65 |
static const char *mode_4[4] = { |
static const char *ccs_mode_4[4] = { |
66 |
"disabled", "learning", "permissive", "enforcing" |
"disabled", "learning", "permissive", "enforcing" |
67 |
}; |
}; |
68 |
/* String table for functionality that takes 2 modes. */ |
/* String table for functionality that takes 2 modes. */ |
69 |
static const char *mode_2[4] = { |
static const char *ccs_mode_2[4] = { |
70 |
"disabled", "enabled", "enabled", "enabled" |
"disabled", "enabled", "enabled", "enabled" |
71 |
}; |
}; |
72 |
|
|
100 |
|
|
101 |
#ifdef CONFIG_TOMOYO |
#ifdef CONFIG_TOMOYO |
102 |
/* Capability name used by domain policy. */ |
/* Capability name used by domain policy. */ |
103 |
static const char *capability_control_keyword[TOMOYO_MAX_CAPABILITY_INDEX] = { |
static const char *ccs_capability_control_keyword[TOMOYO_MAX_CAPABILITY_INDEX] |
104 |
|
= { |
105 |
[TOMOYO_INET_STREAM_SOCKET_CREATE] = "inet_tcp_create", |
[TOMOYO_INET_STREAM_SOCKET_CREATE] = "inet_tcp_create", |
106 |
[TOMOYO_INET_STREAM_SOCKET_LISTEN] = "inet_tcp_listen", |
[TOMOYO_INET_STREAM_SOCKET_LISTEN] = "inet_tcp_listen", |
107 |
[TOMOYO_INET_STREAM_SOCKET_CONNECT] = "inet_tcp_connect", |
[TOMOYO_INET_STREAM_SOCKET_CONNECT] = "inet_tcp_connect", |
137 |
#endif |
#endif |
138 |
|
|
139 |
/* Profile table. Memory is allocated as needed. */ |
/* Profile table. Memory is allocated as needed. */ |
140 |
static struct profile { |
static struct ccs_profile { |
141 |
unsigned int value[CCS_MAX_CONTROL_INDEX]; |
unsigned int value[CCS_MAX_CONTROL_INDEX]; |
142 |
const struct path_info *comment; |
const struct ccs_path_info *comment; |
143 |
#ifdef CONFIG_TOMOYO |
#ifdef CONFIG_TOMOYO |
144 |
unsigned char capability_value[TOMOYO_MAX_CAPABILITY_INDEX]; |
unsigned char capability_value[TOMOYO_MAX_CAPABILITY_INDEX]; |
145 |
#endif |
#endif |
146 |
} *profile_ptr[MAX_PROFILES]; |
} *ccs_profile_ptr[MAX_PROFILES]; |
147 |
|
|
148 |
/* Permit policy management by non-root user? */ |
/* Permit policy management by non-root user? */ |
149 |
static bool manage_by_non_root; |
static bool ccs_manage_by_non_root; |
150 |
|
|
151 |
/* Utility functions. */ |
/* Utility functions. */ |
152 |
|
|
153 |
#ifdef CONFIG_TOMOYO |
#ifdef CONFIG_TOMOYO |
154 |
/** |
/** |
155 |
* tomoyo_quiet_setup - Set TOMOYO_VERBOSE=0 by default. |
* ccs_quiet_setup - Set TOMOYO_VERBOSE=0 by default. |
156 |
* |
* |
157 |
* @str: Unused. |
* @str: Unused. |
158 |
* |
* |
159 |
* Returns 0. |
* Returns 0. |
160 |
*/ |
*/ |
161 |
static int __init tomoyo_quiet_setup(char *str) |
static int __init ccs_quiet_setup(char *str) |
162 |
{ |
{ |
163 |
ccs_control_array[CCS_TOMOYO_VERBOSE].current_value = 0; |
ccs_control_array[CCS_TOMOYO_VERBOSE].current_value = 0; |
164 |
return 0; |
return 0; |
165 |
} |
} |
166 |
|
|
167 |
__setup("TOMOYO_QUIET", tomoyo_quiet_setup); |
__setup("TOMOYO_QUIET", ccs_quiet_setup); |
168 |
#endif |
#endif |
169 |
|
|
170 |
/** |
/** |
171 |
* is_byte_range - Check whether the string isa \ooo style octal value. |
* ccs_is_byte_range - Check whether the string isa \ooo style octal value. |
172 |
* |
* |
173 |
* @str: Pointer to the string. |
* @str: Pointer to the string. |
174 |
* |
* |
175 |
* Returns true if @str is a \ooo style octal value, false otherwise. |
* Returns true if @str is a \ooo style octal value, false otherwise. |
176 |
*/ |
*/ |
177 |
static inline bool is_byte_range(const char *str) |
static inline bool ccs_is_byte_range(const char *str) |
178 |
{ |
{ |
179 |
return *str >= '0' && *str++ <= '3' && |
return *str >= '0' && *str++ <= '3' && |
180 |
*str >= '0' && *str++ <= '7' && |
*str >= '0' && *str++ <= '7' && |
182 |
} |
} |
183 |
|
|
184 |
/** |
/** |
185 |
* is_decimal - Check whether the character is a decimal character. |
* ccs_is_decimal - Check whether the character is a decimal character. |
186 |
* |
* |
187 |
* @c: The character to check. |
* @c: The character to check. |
188 |
* |
* |
189 |
* Returns true if @c is a decimal character, false otherwise. |
* Returns true if @c is a decimal character, false otherwise. |
190 |
*/ |
*/ |
191 |
static inline bool is_decimal(const char c) |
static inline bool ccs_is_decimal(const char c) |
192 |
{ |
{ |
193 |
return c >= '0' && c <= '9'; |
return c >= '0' && c <= '9'; |
194 |
} |
} |
195 |
|
|
196 |
/** |
/** |
197 |
* is_hexadecimal - Check whether the character is a hexadecimal character. |
* ccs_is_hexadecimal - Check whether the character is a hexadecimal character. |
198 |
* |
* |
199 |
* @c: The character to check. |
* @c: The character to check. |
200 |
* |
* |
201 |
* Returns true if @c is a hexadecimal character, false otherwise. |
* Returns true if @c is a hexadecimal character, false otherwise. |
202 |
*/ |
*/ |
203 |
static inline bool is_hexadecimal(const char c) |
static inline bool ccs_is_hexadecimal(const char c) |
204 |
{ |
{ |
205 |
return (c >= '0' && c <= '9') || |
return (c >= '0' && c <= '9') || |
206 |
(c >= 'A' && c <= 'F') || |
(c >= 'A' && c <= 'F') || |
208 |
} |
} |
209 |
|
|
210 |
/** |
/** |
211 |
* is_alphabet_char - Check whether the character is an alphabet. |
* ccs_is_alphabet_char - Check whether the character is an alphabet. |
212 |
* |
* |
213 |
* @c: The character to check. |
* @c: The character to check. |
214 |
* |
* |
215 |
* Returns true if @c is an alphabet character, false otherwise. |
* Returns true if @c is an alphabet character, false otherwise. |
216 |
*/ |
*/ |
217 |
static inline bool is_alphabet_char(const char c) |
static inline bool ccs_is_alphabet_char(const char c) |
218 |
{ |
{ |
219 |
return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'); |
return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'); |
220 |
} |
} |
221 |
|
|
222 |
/** |
/** |
223 |
* make_byte - Make byte value from three octal characters. |
* ccs_make_byte - Make byte value from three octal characters. |
224 |
* |
* |
225 |
* @c1: The first character. |
* @c1: The first character. |
226 |
* @c2: The second character. |
* @c2: The second character. |
228 |
* |
* |
229 |
* Returns byte value. |
* Returns byte value. |
230 |
*/ |
*/ |
231 |
static inline u8 make_byte(const u8 c1, const u8 c2, const u8 c3) |
static inline u8 ccs_make_byte(const u8 c1, const u8 c2, const u8 c3) |
232 |
{ |
{ |
233 |
return ((c1 - '0') << 6) + ((c2 - '0') << 3) + (c3 - '0'); |
return ((c1 - '0') << 6) + ((c2 - '0') << 3) + (c3 - '0'); |
234 |
} |
} |
235 |
|
|
236 |
/** |
/** |
237 |
* str_starts - Check whether the given string starts with the given keyword. |
* ccs_str_starts - Check whether the given string starts with the given keyword. |
238 |
* |
* |
239 |
* @src: Pointer to pointer to the string. |
* @src: Pointer to pointer to the string. |
240 |
* @find: Pointer to the keyword. |
* @find: Pointer to the keyword. |
244 |
* The @src is updated to point the first character after the @find |
* The @src is updated to point the first character after the @find |
245 |
* if @src starts with @find. |
* if @src starts with @find. |
246 |
*/ |
*/ |
247 |
static bool str_starts(char **src, const char *find) |
static bool ccs_str_starts(char **src, const char *find) |
248 |
{ |
{ |
249 |
const int len = strlen(find); |
const int len = strlen(find); |
250 |
char *tmp = *src; |
char *tmp = *src; |
256 |
} |
} |
257 |
|
|
258 |
/** |
/** |
259 |
* normalize_line - Format string. |
* ccs_normalize_line - Format string. |
260 |
* |
* |
261 |
* @buffer: The line to normalize. |
* @buffer: The line to normalize. |
262 |
* |
* |
265 |
* |
* |
266 |
* Returns nothing. |
* Returns nothing. |
267 |
*/ |
*/ |
268 |
static void normalize_line(unsigned char *buffer) |
static void ccs_normalize_line(unsigned char *buffer) |
269 |
{ |
{ |
270 |
unsigned char *sp = buffer; |
unsigned char *sp = buffer; |
271 |
unsigned char *dp = buffer; |
unsigned char *dp = buffer; |
359 |
e = *filename++; |
e = *filename++; |
360 |
if (e < '0' || e > '7') |
if (e < '0' || e > '7') |
361 |
break; |
break; |
362 |
c = make_byte(c, d, e); |
c = ccs_make_byte(c, d, e); |
363 |
if (c && (c <= ' ' || c >= 127)) |
if (c && (c <= ' ' || c >= 127)) |
364 |
continue; /* pattern is not \000 */ |
continue; /* pattern is not \000 */ |
365 |
} |
} |
423 |
e = *domainname++; |
e = *domainname++; |
424 |
if (e < '0' || e > '7') |
if (e < '0' || e > '7') |
425 |
break; |
break; |
426 |
c = make_byte(c, d, e); |
c = ccs_make_byte(c, d, e); |
427 |
if (c && (c <= ' ' || c >= 127)) |
if (c && (c <= ' ' || c >= 127)) |
428 |
/* pattern is not \000 */ |
/* pattern is not \000 */ |
429 |
continue; |
continue; |
463 |
struct domain_info *ccs_find_domain(const char *domainname) |
struct domain_info *ccs_find_domain(const char *domainname) |
464 |
{ |
{ |
465 |
struct domain_info *domain; |
struct domain_info *domain; |
466 |
struct path_info name; |
struct ccs_path_info name; |
467 |
name.name = domainname; |
name.name = domainname; |
468 |
ccs_fill_path_info(&name); |
ccs_fill_path_info(&name); |
469 |
list1_for_each_entry(domain, &domain_list, list) { |
list1_for_each_entry(domain, &ccs_domain_list, list) { |
470 |
if (!domain->is_deleted && |
if (!domain->is_deleted && |
471 |
!ccs_pathcmp(&name, domain->domainname)) |
!ccs_pathcmp(&name, domain->domainname)) |
472 |
return domain; |
return domain; |
475 |
} |
} |
476 |
|
|
477 |
/** |
/** |
478 |
* path_depth - Evaluate the number of '/' in a string. |
* ccs_path_depth - Evaluate the number of '/' in a string. |
479 |
* |
* |
480 |
* @pathname: The string to evaluate. |
* @pathname: The string to evaluate. |
481 |
* |
* |
484 |
* I score 2 for each of the '/' in the @pathname |
* I score 2 for each of the '/' in the @pathname |
485 |
* and score 1 if the @pathname ends with '/'. |
* and score 1 if the @pathname ends with '/'. |
486 |
*/ |
*/ |
487 |
static int path_depth(const char *pathname) |
static int ccs_path_depth(const char *pathname) |
488 |
{ |
{ |
489 |
int i = 0; |
int i = 0; |
490 |
if (pathname) { |
if (pathname) { |
501 |
} |
} |
502 |
|
|
503 |
/** |
/** |
504 |
* const_part_length - Evaluate the initial length without a pattern in a token. |
* ccs_const_part_length - Evaluate the initial length without a pattern in a token. |
505 |
* |
* |
506 |
* @filename: The string to evaluate. |
* @filename: The string to evaluate. |
507 |
* |
* |
508 |
* Returns the initial length without a pattern in @filename. |
* Returns the initial length without a pattern in @filename. |
509 |
*/ |
*/ |
510 |
static int const_part_length(const char *filename) |
static int ccs_const_part_length(const char *filename) |
511 |
{ |
{ |
512 |
char c; |
char c; |
513 |
int len = 0; |
int len = 0; |
545 |
} |
} |
546 |
|
|
547 |
/** |
/** |
548 |
* ccs_fill_path_info - Fill in "struct path_info" members. |
* ccs_fill_path_info - Fill in "struct ccs_path_info" members. |
549 |
* |
* |
550 |
* @ptr: Pointer to "struct path_info" to fill in. |
* @ptr: Pointer to "struct ccs_path_info" to fill in. |
551 |
* |
* |
552 |
* The caller sets "struct path_info"->name. |
* The caller sets "struct ccs_path_info"->name. |
553 |
*/ |
*/ |
554 |
void ccs_fill_path_info(struct path_info *ptr) |
void ccs_fill_path_info(struct ccs_path_info *ptr) |
555 |
{ |
{ |
556 |
const char *name = ptr->name; |
const char *name = ptr->name; |
557 |
const int len = strlen(name); |
const int len = strlen(name); |
558 |
ptr->total_len = len; |
ptr->total_len = len; |
559 |
ptr->const_len = const_part_length(name); |
ptr->const_len = ccs_const_part_length(name); |
560 |
ptr->is_dir = len && (name[len - 1] == '/'); |
ptr->is_dir = len && (name[len - 1] == '/'); |
561 |
ptr->is_patterned = (ptr->const_len < len); |
ptr->is_patterned = (ptr->const_len < len); |
562 |
ptr->hash = full_name_hash(name, len); |
ptr->hash = full_name_hash(name, len); |
563 |
ptr->depth = path_depth(name); |
ptr->depth = ccs_path_depth(name); |
564 |
} |
} |
565 |
|
|
566 |
/** |
/** |
567 |
* file_matches_to_pattern2 - Pattern matching without '/' character |
* ccs_file_matches_to_pattern2 - Pattern matching without '/' character |
568 |
* and "\-" pattern. |
* and "\-" pattern. |
569 |
* |
* |
570 |
* @filename: The start of string to check. |
* @filename: The start of string to check. |
574 |
* |
* |
575 |
* Returns true if @filename matches @pattern, false otherwise. |
* Returns true if @filename matches @pattern, false otherwise. |
576 |
*/ |
*/ |
577 |
static bool file_matches_to_pattern2(const char *filename, |
static bool ccs_file_matches_to_pattern2(const char *filename, |
578 |
const char *filename_end, |
const char *filename_end, |
579 |
const char *pattern, |
const char *pattern, |
580 |
const char *pattern_end) |
const char *pattern_end) |
581 |
{ |
{ |
582 |
while (filename < filename_end && pattern < pattern_end) { |
while (filename < filename_end && pattern < pattern_end) { |
583 |
char c; |
char c; |
597 |
} else if (c == '\\') { |
} else if (c == '\\') { |
598 |
if (filename[1] == '\\') |
if (filename[1] == '\\') |
599 |
filename++; |
filename++; |
600 |
else if (is_byte_range(filename + 1)) |
else if (ccs_is_byte_range(filename + 1)) |
601 |
filename += 3; |
filename += 3; |
602 |
else |
else |
603 |
return false; |
return false; |
610 |
return false; |
return false; |
611 |
break; |
break; |
612 |
case '+': |
case '+': |
613 |
if (!is_decimal(c)) |
if (!ccs_is_decimal(c)) |
614 |
return false; |
return false; |
615 |
break; |
break; |
616 |
case 'x': |
case 'x': |
617 |
if (!is_hexadecimal(c)) |
if (!ccs_is_hexadecimal(c)) |
618 |
return false; |
return false; |
619 |
break; |
break; |
620 |
case 'a': |
case 'a': |
621 |
if (!is_alphabet_char(c)) |
if (!ccs_is_alphabet_char(c)) |
622 |
return false; |
return false; |
623 |
break; |
break; |
624 |
case '0': |
case '0': |
625 |
case '1': |
case '1': |
626 |
case '2': |
case '2': |
627 |
case '3': |
case '3': |
628 |
if (c == '\\' && is_byte_range(filename + 1) |
if (c == '\\' && ccs_is_byte_range(filename + 1) |
629 |
&& strncmp(filename + 1, pattern, 3) == 0) { |
&& strncmp(filename + 1, pattern, 3) == 0) { |
630 |
filename += 3; |
filename += 3; |
631 |
pattern += 2; |
pattern += 2; |
635 |
case '*': |
case '*': |
636 |
case '@': |
case '@': |
637 |
for (i = 0; i <= filename_end - filename; i++) { |
for (i = 0; i <= filename_end - filename; i++) { |
638 |
if (file_matches_to_pattern2(filename + i, |
if (ccs_file_matches_to_pattern2(filename + i, |
639 |
filename_end, |
filename_end, |
640 |
pattern + 1, |
pattern + 1, |
641 |
pattern_end)) |
pattern_end)) |
642 |
return true; |
return true; |
643 |
c = filename[i]; |
c = filename[i]; |
644 |
if (c == '.' && *pattern == '@') |
if (c == '.' && *pattern == '@') |
647 |
continue; |
continue; |
648 |
if (filename[i + 1] == '\\') |
if (filename[i + 1] == '\\') |
649 |
i++; |
i++; |
650 |
else if (is_byte_range(filename + i + 1)) |
else if (ccs_is_byte_range(filename + i + 1)) |
651 |
i += 3; |
i += 3; |
652 |
else |
else |
653 |
break; /* Bad pattern. */ |
break; /* Bad pattern. */ |
657 |
j = 0; |
j = 0; |
658 |
c = *pattern; |
c = *pattern; |
659 |
if (c == '$') { |
if (c == '$') { |
660 |
while (is_decimal(filename[j])) |
while (ccs_is_decimal(filename[j])) |
661 |
j++; |
j++; |
662 |
} else if (c == 'X') { |
} else if (c == 'X') { |
663 |
while (is_hexadecimal(filename[j])) |
while (ccs_is_hexadecimal(filename[j])) |
664 |
j++; |
j++; |
665 |
} else if (c == 'A') { |
} else if (c == 'A') { |
666 |
while (is_alphabet_char(filename[j])) |
while (ccs_is_alphabet_char(filename[j])) |
667 |
j++; |
j++; |
668 |
} |
} |
669 |
for (i = 1; i <= j; i++) { |
for (i = 1; i <= j; i++) { |
670 |
if (file_matches_to_pattern2(filename + i, |
if (ccs_file_matches_to_pattern2(filename + i, |
671 |
filename_end, |
filename_end, |
672 |
pattern + 1, |
pattern + 1, |
673 |
pattern_end)) |
pattern_end)) |
674 |
return true; |
return true; |
675 |
} |
} |
676 |
return false; /* Not matched or bad pattern. */ |
return false; /* Not matched or bad pattern. */ |
685 |
} |
} |
686 |
|
|
687 |
/** |
/** |
688 |
* file_matches_to_pattern - Pattern matching without without '/' character. |
* ccs_file_matches_to_pattern - Pattern matching without without '/' character. |
689 |
* |
* |
690 |
* @filename: The start of string to check. |
* @filename: The start of string to check. |
691 |
* @filename_end: The end of string to check. |
* @filename_end: The end of string to check. |
694 |
* |
* |
695 |
* Returns true if @filename matches @pattern, false otherwise. |
* Returns true if @filename matches @pattern, false otherwise. |
696 |
*/ |
*/ |
697 |
static bool file_matches_to_pattern(const char *filename, |
static bool ccs_file_matches_to_pattern(const char *filename, |
698 |
const char *filename_end, |
const char *filename_end, |
699 |
const char *pattern, |
const char *pattern, |
700 |
const char *pattern_end) |
const char *pattern_end) |
701 |
{ |
{ |
702 |
const char *pattern_start = pattern; |
const char *pattern_start = pattern; |
703 |
bool first = true; |
bool first = true; |
706 |
/* Split at "\-" pattern. */ |
/* Split at "\-" pattern. */ |
707 |
if (*pattern++ != '\\' || *pattern++ != '-') |
if (*pattern++ != '\\' || *pattern++ != '-') |
708 |
continue; |
continue; |
709 |
result = file_matches_to_pattern2(filename, filename_end, |
result = ccs_file_matches_to_pattern2(filename, filename_end, |
710 |
pattern_start, pattern - 2); |
pattern_start, |
711 |
|
pattern - 2); |
712 |
if (first) |
if (first) |
713 |
result = !result; |
result = !result; |
714 |
if (result) |
if (result) |
716 |
first = false; |
first = false; |
717 |
pattern_start = pattern; |
pattern_start = pattern; |
718 |
} |
} |
719 |
result = file_matches_to_pattern2(filename, filename_end, |
result = ccs_file_matches_to_pattern2(filename, filename_end, |
720 |
pattern_start, pattern_end); |
pattern_start, pattern_end); |
721 |
return first ? result : !result; |
return first ? result : !result; |
722 |
} |
} |
723 |
|
|
742 |
* \a 1 alphabet character. |
* \a 1 alphabet character. |
743 |
* \- Subtraction operator. |
* \- Subtraction operator. |
744 |
*/ |
*/ |
745 |
bool ccs_path_matches_pattern(const struct path_info *filename, |
bool ccs_path_matches_pattern(const struct ccs_path_info *filename, |
746 |
const struct path_info *pattern) |
const struct ccs_path_info *pattern) |
747 |
{ |
{ |
748 |
/* |
/* |
749 |
if (!filename || !pattern) |
if (!filename || !pattern) |
771 |
f_delimiter = f + strlen(f); |
f_delimiter = f + strlen(f); |
772 |
if (!p_delimiter) |
if (!p_delimiter) |
773 |
p_delimiter = p + strlen(p); |
p_delimiter = p + strlen(p); |
774 |
if (!file_matches_to_pattern(f, f_delimiter, p, p_delimiter)) |
if (!ccs_file_matches_to_pattern(f, f_delimiter, |
775 |
|
p, p_delimiter)) |
776 |
return false; |
return false; |
777 |
f = f_delimiter; |
f = f_delimiter; |
778 |
if (*f) |
if (*f) |
897 |
if (!domain) |
if (!domain) |
898 |
domain = current->domain_info; |
domain = current->domain_info; |
899 |
profile = domain->profile; |
profile = domain->profile; |
900 |
return sbin_init_started && index < CCS_MAX_CONTROL_INDEX |
return ccs_sbin_init_started && index < CCS_MAX_CONTROL_INDEX |
901 |
#if MAX_PROFILES != 256 |
#if MAX_PROFILES != 256 |
902 |
&& profile < MAX_PROFILES |
&& profile < MAX_PROFILES |
903 |
#endif |
#endif |
904 |
&& profile_ptr[profile] ? |
&& ccs_profile_ptr[profile] ? |
905 |
profile_ptr[profile]->value[index] : 0; |
ccs_profile_ptr[profile]->value[index] : 0; |
906 |
} |
} |
907 |
|
|
908 |
#ifdef CONFIG_TOMOYO |
#ifdef CONFIG_TOMOYO |
919 |
{ |
{ |
920 |
const u8 profile = domain ? domain->profile : |
const u8 profile = domain ? domain->profile : |
921 |
current->domain_info->profile; |
current->domain_info->profile; |
922 |
return sbin_init_started && index < TOMOYO_MAX_CAPABILITY_INDEX |
return ccs_sbin_init_started && index < TOMOYO_MAX_CAPABILITY_INDEX |
923 |
#if MAX_PROFILES != 256 |
#if MAX_PROFILES != 256 |
924 |
&& profile < MAX_PROFILES |
&& profile < MAX_PROFILES |
925 |
#endif |
#endif |
926 |
&& profile_ptr[profile] ? |
&& ccs_profile_ptr[profile] ? |
927 |
profile_ptr[profile]->capability_value[index] : 0; |
ccs_profile_ptr[profile]->capability_value[index] : 0; |
928 |
} |
} |
929 |
|
|
930 |
/** |
/** |
937 |
const char *ccs_cap2keyword(const u8 operation) |
const char *ccs_cap2keyword(const u8 operation) |
938 |
{ |
{ |
939 |
return operation < TOMOYO_MAX_CAPABILITY_INDEX |
return operation < TOMOYO_MAX_CAPABILITY_INDEX |
940 |
? capability_control_keyword[operation] : NULL; |
? ccs_capability_control_keyword[operation] : NULL; |
941 |
} |
} |
942 |
|
|
943 |
#endif |
#endif |
989 |
bool ccs_check_domain_quota(struct domain_info * const domain) |
bool ccs_check_domain_quota(struct domain_info * const domain) |
990 |
{ |
{ |
991 |
unsigned int count = 0; |
unsigned int count = 0; |
992 |
struct acl_info *ptr; |
struct ccs_acl_info *ptr; |
993 |
if (!domain) |
if (!domain) |
994 |
return true; |
return true; |
995 |
list1_for_each_entry(ptr, &domain->acl_info_list, list) { |
list1_for_each_entry(ptr, &domain->acl_info_list, list) { |
996 |
if (ptr->type & ACL_DELETED) |
if (ptr->type & ACL_DELETED) |
997 |
continue; |
continue; |
998 |
switch (ccs_acl_type2(ptr)) { |
switch (ccs_acl_type2(ptr)) { |
999 |
struct single_path_acl_record *acl1; |
struct ccs_single_path_acl_record *acl1; |
1000 |
struct double_path_acl_record *acl2; |
struct ccs_double_path_acl_record *acl2; |
1001 |
u16 perm; |
u16 perm; |
1002 |
case TYPE_SINGLE_PATH_ACL: |
case TYPE_SINGLE_PATH_ACL: |
1003 |
acl1 = container_of(ptr, struct single_path_acl_record, |
acl1 = container_of(ptr, |
1004 |
|
struct ccs_single_path_acl_record, |
1005 |
head); |
head); |
1006 |
perm = acl1->perm; |
perm = acl1->perm; |
1007 |
if (perm & (1 << TYPE_EXECUTE_ACL)) |
if (perm & (1 << TYPE_EXECUTE_ACL)) |
1033 |
count++; |
count++; |
1034 |
break; |
break; |
1035 |
case TYPE_DOUBLE_PATH_ACL: |
case TYPE_DOUBLE_PATH_ACL: |
1036 |
acl2 = container_of(ptr, struct double_path_acl_record, |
acl2 = container_of(ptr, |
1037 |
|
struct ccs_double_path_acl_record, |
1038 |
head); |
head); |
1039 |
perm = acl2->perm; |
perm = acl2->perm; |
1040 |
if (perm & (1 << TYPE_LINK_ACL)) |
if (perm & (1 << TYPE_LINK_ACL)) |
1065 |
* |
* |
1066 |
* @profile: Profile number to create. |
* @profile: Profile number to create. |
1067 |
* |
* |
1068 |
* Returns pointer to "struct profile" on success, NULL otherwise. |
* Returns pointer to "struct ccs_profile" on success, NULL otherwise. |
1069 |
*/ |
*/ |
1070 |
static struct profile *ccs_find_or_assign_new_profile(const unsigned int |
static struct ccs_profile *ccs_find_or_assign_new_profile(const unsigned int |
1071 |
profile) |
profile) |
1072 |
{ |
{ |
1073 |
static DEFINE_MUTEX(lock); |
static DEFINE_MUTEX(lock); |
1074 |
struct profile *ptr = NULL; |
struct ccs_profile *ptr = NULL; |
1075 |
mutex_lock(&lock); |
mutex_lock(&lock); |
1076 |
if (profile < MAX_PROFILES) { |
if (profile < MAX_PROFILES) { |
1077 |
ptr = profile_ptr[profile]; |
ptr = ccs_profile_ptr[profile]; |
1078 |
if (ptr) |
if (ptr) |
1079 |
goto ok; |
goto ok; |
1080 |
ptr = ccs_alloc_element(sizeof(*ptr)); |
ptr = ccs_alloc_element(sizeof(*ptr)); |
1088 |
* because they are always 0. |
* because they are always 0. |
1089 |
*/ |
*/ |
1090 |
mb(); /* Avoid out-of-order execution. */ |
mb(); /* Avoid out-of-order execution. */ |
1091 |
profile_ptr[profile] = ptr; |
ccs_profile_ptr[profile] = ptr; |
1092 |
} |
} |
1093 |
} |
} |
1094 |
ok: |
ok: |
1097 |
} |
} |
1098 |
|
|
1099 |
/** |
/** |
1100 |
* write_profile - Write profile table. |
* ccs_write_profile - Write profile table. |
1101 |
* |
* |
1102 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1103 |
* |
* |
1104 |
* Returns 0 on success, negative value otherwise. |
* Returns 0 on success, negative value otherwise. |
1105 |
*/ |
*/ |
1106 |
static int write_profile(struct ccs_io_buffer *head) |
static int ccs_write_profile(struct ccs_io_buffer *head) |
1107 |
{ |
{ |
1108 |
char *data = head->write_buf; |
char *data = head->write_buf; |
1109 |
unsigned int i; |
unsigned int i; |
1110 |
unsigned int value; |
unsigned int value; |
1111 |
char *cp; |
char *cp; |
1112 |
struct profile *profile; |
struct ccs_profile *ccs_profile; |
1113 |
i = simple_strtoul(data, &cp, 10); |
i = simple_strtoul(data, &cp, 10); |
1114 |
if (data != cp) { |
if (data != cp) { |
1115 |
if (*cp != '-') |
if (*cp != '-') |
1116 |
return -EINVAL; |
return -EINVAL; |
1117 |
data = cp + 1; |
data = cp + 1; |
1118 |
} |
} |
1119 |
profile = ccs_find_or_assign_new_profile(i); |
ccs_profile = ccs_find_or_assign_new_profile(i); |
1120 |
if (!profile) |
if (!ccs_profile) |
1121 |
return -EINVAL; |
return -EINVAL; |
1122 |
cp = strchr(data, '='); |
cp = strchr(data, '='); |
1123 |
if (!cp) |
if (!cp) |
1125 |
*cp = '\0'; |
*cp = '\0'; |
1126 |
ccs_update_counter(CCS_UPDATES_COUNTER_PROFILE); |
ccs_update_counter(CCS_UPDATES_COUNTER_PROFILE); |
1127 |
if (!strcmp(data, "COMMENT")) { |
if (!strcmp(data, "COMMENT")) { |
1128 |
profile->comment = ccs_save_name(cp + 1); |
ccs_profile->comment = ccs_save_name(cp + 1); |
1129 |
return 0; |
return 0; |
1130 |
} |
} |
1131 |
#ifdef CONFIG_TOMOYO |
#ifdef CONFIG_TOMOYO |
1132 |
if (str_starts(&data, KEYWORD_MAC_FOR_CAPABILITY)) { |
if (ccs_str_starts(&data, KEYWORD_MAC_FOR_CAPABILITY)) { |
1133 |
if (sscanf(cp + 1, "%u", &value) != 1) { |
if (sscanf(cp + 1, "%u", &value) != 1) { |
1134 |
for (i = 0; i < 4; i++) { |
for (i = 0; i < 4; i++) { |
1135 |
if (strcmp(cp + 1, mode_4[i])) |
if (strcmp(cp + 1, ccs_mode_4[i])) |
1136 |
continue; |
continue; |
1137 |
value = i; |
value = i; |
1138 |
break; |
break; |
1143 |
if (value > 3) |
if (value > 3) |
1144 |
value = 3; |
value = 3; |
1145 |
for (i = 0; i < TOMOYO_MAX_CAPABILITY_INDEX; i++) { |
for (i = 0; i < TOMOYO_MAX_CAPABILITY_INDEX; i++) { |
1146 |
if (strcmp(data, capability_control_keyword[i])) |
if (strcmp(data, ccs_capability_control_keyword[i])) |
1147 |
continue; |
continue; |
1148 |
profile->capability_value[i] = value; |
ccs_profile->capability_value[i] = value; |
1149 |
return 0; |
return 0; |
1150 |
} |
} |
1151 |
return -EINVAL; |
return -EINVAL; |
1160 |
switch (i) { |
switch (i) { |
1161 |
case CCS_SAKURA_RESTRICT_AUTOBIND: |
case CCS_SAKURA_RESTRICT_AUTOBIND: |
1162 |
case CCS_TOMOYO_VERBOSE: |
case CCS_TOMOYO_VERBOSE: |
1163 |
modes = mode_2; |
modes = ccs_mode_2; |
1164 |
break; |
break; |
1165 |
default: |
default: |
1166 |
modes = mode_4; |
modes = ccs_mode_4; |
1167 |
break; |
break; |
1168 |
} |
} |
1169 |
for (j = 0; j < 4; j++) { |
for (j = 0; j < 4; j++) { |
1183 |
if (value == 1) |
if (value == 1) |
1184 |
value = 2; /* learning mode is not supported. */ |
value = 2; /* learning mode is not supported. */ |
1185 |
} |
} |
1186 |
profile->value[i] = value; |
ccs_profile->value[i] = value; |
1187 |
return 0; |
return 0; |
1188 |
} |
} |
1189 |
return -EINVAL; |
return -EINVAL; |
1190 |
} |
} |
1191 |
|
|
1192 |
/** |
/** |
1193 |
* read_profile - Read profile table. |
* ccs_read_profile - Read profile table. |
1194 |
* |
* |
1195 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1196 |
* |
* |
1197 |
* Returns 0. |
* Returns 0. |
1198 |
*/ |
*/ |
1199 |
static int read_profile(struct ccs_io_buffer *head) |
static int ccs_read_profile(struct ccs_io_buffer *head) |
1200 |
{ |
{ |
1201 |
static const int total |
static const int ccs_total |
1202 |
= CCS_MAX_CONTROL_INDEX + TOMOYO_MAX_CAPABILITY_INDEX + 1; |
= CCS_MAX_CONTROL_INDEX + TOMOYO_MAX_CAPABILITY_INDEX + 1; |
1203 |
int step; |
int step; |
1204 |
if (head->read_eof) |
if (head->read_eof) |
1205 |
return 0; |
return 0; |
1206 |
for (step = head->read_step; step < MAX_PROFILES * total; step++) { |
for (step = head->read_step; step < MAX_PROFILES * ccs_total; step++) { |
1207 |
const u8 index = step / total; |
const u8 index = step / ccs_total; |
1208 |
u8 type = step % total; |
u8 type = step % ccs_total; |
1209 |
const struct profile *profile = profile_ptr[index]; |
const struct ccs_profile *ccs_profile = ccs_profile_ptr[index]; |
1210 |
head->read_step = step; |
head->read_step = step; |
1211 |
if (!profile) |
if (!ccs_profile) |
1212 |
continue; |
continue; |
1213 |
#if !defined(CONFIG_SAKURA) || !defined(CONFIG_TOMOYO) |
#if !defined(CONFIG_SAKURA) || !defined(CONFIG_TOMOYO) |
1214 |
switch (type) { |
switch (type) { |
1236 |
#endif |
#endif |
1237 |
if (!type) { /* Print profile' comment tag. */ |
if (!type) { /* Print profile' comment tag. */ |
1238 |
if (!ccs_io_printf(head, "%u-COMMENT=%s\n", |
if (!ccs_io_printf(head, "%u-COMMENT=%s\n", |
1239 |
index, profile->comment ? |
index, ccs_profile->comment ? |
1240 |
profile->comment->name : "")) |
ccs_profile->comment->name : "")) |
1241 |
break; |
break; |
1242 |
continue; |
continue; |
1243 |
} |
} |
1245 |
if (type >= CCS_MAX_CONTROL_INDEX) { |
if (type >= CCS_MAX_CONTROL_INDEX) { |
1246 |
#ifdef CONFIG_TOMOYO |
#ifdef CONFIG_TOMOYO |
1247 |
const int i = type - CCS_MAX_CONTROL_INDEX; |
const int i = type - CCS_MAX_CONTROL_INDEX; |
1248 |
const u8 value = profile->capability_value[i]; |
const u8 value = ccs_profile->capability_value[i]; |
1249 |
if (!ccs_io_printf(head, |
if (!ccs_io_printf(head, |
1250 |
"%u-" KEYWORD_MAC_FOR_CAPABILITY |
"%u-" KEYWORD_MAC_FOR_CAPABILITY |
1251 |
"%s=%s\n", index, |
"%s=%s\n", index, |
1252 |
capability_control_keyword[i], |
ccs_capability_control_keyword[i], |
1253 |
mode_4[value])) |
ccs_mode_4[value])) |
1254 |
break; |
break; |
1255 |
#endif |
#endif |
1256 |
} else { |
} else { |
1257 |
const unsigned int value = profile->value[type]; |
const unsigned int value = ccs_profile->value[type]; |
1258 |
const char **modes = NULL; |
const char **modes = NULL; |
1259 |
const char *keyword = ccs_control_array[type].keyword; |
const char *keyword = ccs_control_array[type].keyword; |
1260 |
switch (ccs_control_array[type].max_value) { |
switch (ccs_control_array[type].max_value) { |
1261 |
case 3: |
case 3: |
1262 |
modes = mode_4; |
modes = ccs_mode_4; |
1263 |
break; |
break; |
1264 |
case 1: |
case 1: |
1265 |
modes = mode_2; |
modes = ccs_mode_2; |
1266 |
break; |
break; |
1267 |
} |
} |
1268 |
if (modes) { |
if (modes) { |
1276 |
} |
} |
1277 |
} |
} |
1278 |
} |
} |
1279 |
if (step == MAX_PROFILES * total) |
if (step == MAX_PROFILES * ccs_total) |
1280 |
head->read_eof = true; |
head->read_eof = true; |
1281 |
return 0; |
return 0; |
1282 |
} |
} |
1283 |
|
|
1284 |
/* Structure for policy manager. */ |
/* Structure for policy manager. */ |
1285 |
struct policy_manager_entry { |
struct ccs_policy_manager_entry { |
1286 |
struct list1_head list; |
struct list1_head list; |
1287 |
/* A path to program or a domainname. */ |
/* A path to program or a domainname. */ |
1288 |
const struct path_info *manager; |
const struct ccs_path_info *manager; |
1289 |
bool is_domain; /* True if manager is a domainname. */ |
bool is_domain; /* True if manager is a domainname. */ |
1290 |
bool is_deleted; /* True if this entry is deleted. */ |
bool is_deleted; /* True if this entry is deleted. */ |
1291 |
}; |
}; |
1292 |
|
|
1293 |
/* The list for "struct policy_manager_entry". */ |
/* The list for "struct ccs_policy_manager_entry". */ |
1294 |
static LIST1_HEAD(policy_manager_list); |
static LIST1_HEAD(ccs_policy_manager_list); |
1295 |
|
|
1296 |
/** |
/** |
1297 |
* update_manager_entry - Add a manager entry. |
* ccs_update_manager_entry - Add a manager entry. |
1298 |
* |
* |
1299 |
* @manager: The path to manager or the domainnamme. |
* @manager: The path to manager or the domainnamme. |
1300 |
* @is_delete: True if it is a delete request. |
* @is_delete: True if it is a delete request. |
1301 |
* |
* |
1302 |
* Returns 0 on success, negative value otherwise. |
* Returns 0 on success, negative value otherwise. |
1303 |
*/ |
*/ |
1304 |
static int update_manager_entry(const char *manager, const bool is_delete) |
static int ccs_update_manager_entry(const char *manager, const bool is_delete) |
1305 |
{ |
{ |
1306 |
struct policy_manager_entry *new_entry; |
struct ccs_policy_manager_entry *new_entry; |
1307 |
struct policy_manager_entry *ptr; |
struct ccs_policy_manager_entry *ptr; |
1308 |
static DEFINE_MUTEX(lock); |
static DEFINE_MUTEX(lock); |
1309 |
const struct path_info *saved_manager; |
const struct ccs_path_info *saved_manager; |
1310 |
int error = -ENOMEM; |
int error = -ENOMEM; |
1311 |
bool is_domain = false; |
bool is_domain = false; |
1312 |
if (ccs_is_domain_def(manager)) { |
if (ccs_is_domain_def(manager)) { |
1321 |
if (!saved_manager) |
if (!saved_manager) |
1322 |
return -ENOMEM; |
return -ENOMEM; |
1323 |
mutex_lock(&lock); |
mutex_lock(&lock); |
1324 |
list1_for_each_entry(ptr, &policy_manager_list, list) { |
list1_for_each_entry(ptr, &ccs_policy_manager_list, list) { |
1325 |
if (ptr->manager != saved_manager) |
if (ptr->manager != saved_manager) |
1326 |
continue; |
continue; |
1327 |
ptr->is_deleted = is_delete; |
ptr->is_deleted = is_delete; |
1337 |
goto out; |
goto out; |
1338 |
new_entry->manager = saved_manager; |
new_entry->manager = saved_manager; |
1339 |
new_entry->is_domain = is_domain; |
new_entry->is_domain = is_domain; |
1340 |
list1_add_tail_mb(&new_entry->list, &policy_manager_list); |
list1_add_tail_mb(&new_entry->list, &ccs_policy_manager_list); |
1341 |
error = 0; |
error = 0; |
1342 |
out: |
out: |
1343 |
mutex_unlock(&lock); |
mutex_unlock(&lock); |
1347 |
} |
} |
1348 |
|
|
1349 |
/** |
/** |
1350 |
* write_manager_policy - Write manager policy. |
* ccs_write_manager_policy - Write manager policy. |
1351 |
* |
* |
1352 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1353 |
* |
* |
1354 |
* Returns 0 on success, negative value otherwise. |
* Returns 0 on success, negative value otherwise. |
1355 |
*/ |
*/ |
1356 |
static int write_manager_policy(struct ccs_io_buffer *head) |
static int ccs_write_manager_policy(struct ccs_io_buffer *head) |
1357 |
{ |
{ |
1358 |
char *data = head->write_buf; |
char *data = head->write_buf; |
1359 |
bool is_delete = str_starts(&data, KEYWORD_DELETE); |
bool is_delete = ccs_str_starts(&data, KEYWORD_DELETE); |
1360 |
if (!strcmp(data, "manage_by_non_root")) { |
if (!strcmp(data, "manage_by_non_root")) { |
1361 |
manage_by_non_root = !is_delete; |
ccs_manage_by_non_root = !is_delete; |
1362 |
return 0; |
return 0; |
1363 |
} |
} |
1364 |
return update_manager_entry(data, is_delete); |
return ccs_update_manager_entry(data, is_delete); |
1365 |
} |
} |
1366 |
|
|
1367 |
/** |
/** |
1368 |
* read_manager_policy - Read manager policy. |
* ccs_read_manager_policy - Read manager policy. |
1369 |
* |
* |
1370 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1371 |
* |
* |
1372 |
* Returns 0. |
* Returns 0. |
1373 |
*/ |
*/ |
1374 |
static int read_manager_policy(struct ccs_io_buffer *head) |
static int ccs_read_manager_policy(struct ccs_io_buffer *head) |
1375 |
{ |
{ |
1376 |
struct list1_head *pos; |
struct list1_head *pos; |
1377 |
if (head->read_eof) |
if (head->read_eof) |
1378 |
return 0; |
return 0; |
1379 |
list1_for_each_cookie(pos, head->read_var2, &policy_manager_list) { |
list1_for_each_cookie(pos, head->read_var2, &ccs_policy_manager_list) { |
1380 |
struct policy_manager_entry *ptr; |
struct ccs_policy_manager_entry *ptr; |
1381 |
ptr = list1_entry(pos, struct policy_manager_entry, list); |
ptr = list1_entry(pos, struct ccs_policy_manager_entry, list); |
1382 |
if (ptr->is_deleted) |
if (ptr->is_deleted) |
1383 |
continue; |
continue; |
1384 |
if (!ccs_io_printf(head, "%s\n", ptr->manager->name)) |
if (!ccs_io_printf(head, "%s\n", ptr->manager->name)) |
1389 |
} |
} |
1390 |
|
|
1391 |
/** |
/** |
1392 |
* is_policy_manager - Check whether the current process is a policy manager. |
* ccs_is_policy_manager - Check whether the current process is a policy manager. |
1393 |
* |
* |
1394 |
* Returns true if the current process is permitted to modify policy |
* Returns true if the current process is permitted to modify policy |
1395 |
* via /proc/ccs/ interface. |
* via /proc/ccs/ interface. |
1396 |
*/ |
*/ |
1397 |
static bool is_policy_manager(void) |
static bool ccs_is_policy_manager(void) |
1398 |
{ |
{ |
1399 |
struct policy_manager_entry *ptr; |
struct ccs_policy_manager_entry *ptr; |
1400 |
const char *exe; |
const char *exe; |
1401 |
struct task_struct *task = current; |
struct task_struct *task = current; |
1402 |
const struct path_info *domainname = task->domain_info->domainname; |
const struct ccs_path_info *domainname = task->domain_info->domainname; |
1403 |
bool found = false; |
bool found = false; |
1404 |
if (!sbin_init_started) |
if (!ccs_sbin_init_started) |
1405 |
return true; |
return true; |
1406 |
if (task->tomoyo_flags & CCS_TASK_IS_POLICY_MANAGER) |
if (task->tomoyo_flags & CCS_TASK_IS_POLICY_MANAGER) |
1407 |
return true; |
return true; |
1408 |
if (!manage_by_non_root && (task->uid || task->euid)) |
if (!ccs_manage_by_non_root && (task->uid || task->euid)) |
1409 |
return false; |
return false; |
1410 |
list1_for_each_entry(ptr, &policy_manager_list, list) { |
list1_for_each_entry(ptr, &ccs_policy_manager_list, list) { |
1411 |
if (!ptr->is_deleted && ptr->is_domain |
if (!ptr->is_deleted && ptr->is_domain |
1412 |
&& !ccs_pathcmp(domainname, ptr->manager)) { |
&& !ccs_pathcmp(domainname, ptr->manager)) { |
1413 |
/* Set manager flag. */ |
/* Set manager flag. */ |
1418 |
exe = ccs_get_exe(); |
exe = ccs_get_exe(); |
1419 |
if (!exe) |
if (!exe) |
1420 |
return false; |
return false; |
1421 |
list1_for_each_entry(ptr, &policy_manager_list, list) { |
list1_for_each_entry(ptr, &ccs_policy_manager_list, list) { |
1422 |
if (!ptr->is_deleted && !ptr->is_domain |
if (!ptr->is_deleted && !ptr->is_domain |
1423 |
&& !strcmp(exe, ptr->manager->name)) { |
&& !strcmp(exe, ptr->manager->name)) { |
1424 |
found = true; |
found = true; |
1428 |
} |
} |
1429 |
} |
} |
1430 |
if (!found) { /* Reduce error messages. */ |
if (!found) { /* Reduce error messages. */ |
1431 |
static pid_t last_pid; |
static pid_t ccs_last_pid; |
1432 |
const pid_t pid = current->pid; |
const pid_t pid = current->pid; |
1433 |
if (last_pid != pid) { |
if (ccs_last_pid != pid) { |
1434 |
printk(KERN_WARNING "%s ( %s ) is not permitted to " |
printk(KERN_WARNING "%s ( %s ) is not permitted to " |
1435 |
"update policies.\n", domainname->name, exe); |
"update policies.\n", domainname->name, exe); |
1436 |
last_pid = pid; |
ccs_last_pid = pid; |
1437 |
} |
} |
1438 |
} |
} |
1439 |
ccs_free(exe); |
ccs_free(exe); |
1470 |
} |
} |
1471 |
|
|
1472 |
/** |
/** |
1473 |
* is_select_one - Parse select command. |
* ccs_is_select_one - Parse select command. |
1474 |
* |
* |
1475 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1476 |
* @data: String to parse. |
* @data: String to parse. |
1477 |
* |
* |
1478 |
* Returns true on success, false otherwise. |
* Returns true on success, false otherwise. |
1479 |
*/ |
*/ |
1480 |
static bool is_select_one(struct ccs_io_buffer *head, const char *data) |
static bool ccs_is_select_one(struct ccs_io_buffer *head, const char *data) |
1481 |
{ |
{ |
1482 |
unsigned int pid; |
unsigned int pid; |
1483 |
struct domain_info *domain = NULL; |
struct domain_info *domain = NULL; |
1510 |
if (domain) { |
if (domain) { |
1511 |
struct domain_info *d; |
struct domain_info *d; |
1512 |
head->read_var1 = NULL; |
head->read_var1 = NULL; |
1513 |
list1_for_each_entry(d, &domain_list, list) { |
list1_for_each_entry(d, &ccs_domain_list, list) { |
1514 |
if (d == domain) |
if (d == domain) |
1515 |
break; |
break; |
1516 |
head->read_var1 = &d->list; |
head->read_var1 = &d->list; |
1525 |
} |
} |
1526 |
|
|
1527 |
/** |
/** |
1528 |
* write_domain_policy - Write domain policy. |
* ccs_write_domain_policy - Write domain policy. |
1529 |
* |
* |
1530 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1531 |
* |
* |
1532 |
* Returns 0 on success, negative value otherwise. |
* Returns 0 on success, negative value otherwise. |
1533 |
*/ |
*/ |
1534 |
static int write_domain_policy(struct ccs_io_buffer *head) |
static int ccs_write_domain_policy(struct ccs_io_buffer *head) |
1535 |
{ |
{ |
1536 |
char *data = head->write_buf; |
char *data = head->write_buf; |
1537 |
struct domain_info *domain = head->write_var1; |
struct domain_info *domain = head->write_var1; |
1539 |
bool is_select = false; |
bool is_select = false; |
1540 |
bool is_undelete = false; |
bool is_undelete = false; |
1541 |
unsigned int profile; |
unsigned int profile; |
1542 |
const struct condition_list *cond = NULL; |
const struct ccs_condition_list *cond = NULL; |
1543 |
char *cp; |
char *cp; |
1544 |
if (str_starts(&data, KEYWORD_DELETE)) |
if (ccs_str_starts(&data, KEYWORD_DELETE)) |
1545 |
is_delete = true; |
is_delete = true; |
1546 |
else if (str_starts(&data, KEYWORD_SELECT)) |
else if (ccs_str_starts(&data, KEYWORD_SELECT)) |
1547 |
is_select = true; |
is_select = true; |
1548 |
else if (str_starts(&data, KEYWORD_UNDELETE)) |
else if (ccs_str_starts(&data, KEYWORD_UNDELETE)) |
1549 |
is_undelete = true; |
is_undelete = true; |
1550 |
if (is_select && is_select_one(head, data)) |
if (is_select && ccs_is_select_one(head, data)) |
1551 |
return 0; |
return 0; |
1552 |
/* Don't allow updating policies by non manager programs. */ |
/* Don't allow updating policies by non manager programs. */ |
1553 |
if (!is_policy_manager()) |
if (!ccs_is_policy_manager()) |
1554 |
return -EPERM; |
return -EPERM; |
1555 |
if (ccs_is_domain_def(data)) { |
if (ccs_is_domain_def(data)) { |
1556 |
domain = NULL; |
domain = NULL; |
1571 |
|
|
1572 |
if (sscanf(data, KEYWORD_USE_PROFILE "%u", &profile) == 1 |
if (sscanf(data, KEYWORD_USE_PROFILE "%u", &profile) == 1 |
1573 |
&& profile < MAX_PROFILES) { |
&& profile < MAX_PROFILES) { |
1574 |
if (profile_ptr[profile] || !sbin_init_started) |
if (ccs_profile_ptr[profile] || !ccs_sbin_init_started) |
1575 |
domain->profile = (u8) profile; |
domain->profile = (u8) profile; |
1576 |
return 0; |
return 0; |
1577 |
} |
} |
1591 |
if (!cond) |
if (!cond) |
1592 |
return -EINVAL; |
return -EINVAL; |
1593 |
} |
} |
1594 |
if (str_starts(&data, KEYWORD_ALLOW_CAPABILITY)) |
if (ccs_str_starts(&data, KEYWORD_ALLOW_CAPABILITY)) |
1595 |
return ccs_write_capability_policy(data, domain, cond, |
return ccs_write_capability_policy(data, domain, cond, |
1596 |
is_delete); |
is_delete); |
1597 |
else if (str_starts(&data, KEYWORD_ALLOW_NETWORK)) |
else if (ccs_str_starts(&data, KEYWORD_ALLOW_NETWORK)) |
1598 |
return ccs_write_network_policy(data, domain, cond, is_delete); |
return ccs_write_network_policy(data, domain, cond, is_delete); |
1599 |
else if (str_starts(&data, KEYWORD_ALLOW_SIGNAL)) |
else if (ccs_str_starts(&data, KEYWORD_ALLOW_SIGNAL)) |
1600 |
return ccs_write_signal_policy(data, domain, cond, is_delete); |
return ccs_write_signal_policy(data, domain, cond, is_delete); |
1601 |
else if (str_starts(&data, KEYWORD_ALLOW_ARGV0)) |
else if (ccs_str_starts(&data, KEYWORD_ALLOW_ARGV0)) |
1602 |
return ccs_write_argv0_policy(data, domain, cond, is_delete); |
return ccs_write_argv0_policy(data, domain, cond, is_delete); |
1603 |
else if (str_starts(&data, KEYWORD_ALLOW_ENV)) |
else if (ccs_str_starts(&data, KEYWORD_ALLOW_ENV)) |
1604 |
return ccs_write_env_policy(data, domain, cond, is_delete); |
return ccs_write_env_policy(data, domain, cond, is_delete); |
1605 |
else |
else |
1606 |
return ccs_write_file_policy(data, domain, cond, is_delete); |
return ccs_write_file_policy(data, domain, cond, is_delete); |
1607 |
} |
} |
1608 |
|
|
1609 |
/** |
/** |
1610 |
* print_single_path_acl - Print a single path ACL entry. |
* ccs_print_single_path_acl - Print a single path ACL entry. |
1611 |
* |
* |
1612 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1613 |
* @ptr: Pointer to "struct single_path_acl_record". |
* @ptr: Pointer to "struct ccs_single_path_acl_record". |
1614 |
* @cond: Pointer to "struct condition_list". May be NULL. |
* @cond: Pointer to "struct ccs_condition_list". May be NULL. |
1615 |
* |
* |
1616 |
* Returns true on success, false otherwise. |
* Returns true on success, false otherwise. |
1617 |
*/ |
*/ |
1618 |
static bool print_single_path_acl(struct ccs_io_buffer *head, |
static bool ccs_print_single_path_acl(struct ccs_io_buffer *head, |
1619 |
struct single_path_acl_record *ptr, |
struct ccs_single_path_acl_record *ptr, |
1620 |
const struct condition_list *cond) |
const struct ccs_condition_list *cond) |
1621 |
{ |
{ |
1622 |
int pos; |
int pos; |
1623 |
u8 bit; |
u8 bit; |
1656 |
} |
} |
1657 |
|
|
1658 |
/** |
/** |
1659 |
* print_double_path_acl - Print a double path ACL entry. |
* ccs_print_double_path_acl - Print a double path ACL entry. |
1660 |
* |
* |
1661 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1662 |
* @ptr: Pointer to "struct double_path_acl_record". |
* @ptr: Pointer to "struct ccs_double_path_acl_record". |
1663 |
* @cond: Pointer to "struct condition_list". May be NULL. |
* @cond: Pointer to "struct ccs_condition_list". May be NULL. |
1664 |
* |
* |
1665 |
* Returns true on success, false otherwise. |
* Returns true on success, false otherwise. |
1666 |
*/ |
*/ |
1667 |
static bool print_double_path_acl(struct ccs_io_buffer *head, |
static bool ccs_print_double_path_acl(struct ccs_io_buffer *head, |
1668 |
struct double_path_acl_record *ptr, |
struct ccs_double_path_acl_record *ptr, |
1669 |
const struct condition_list *cond) |
const struct ccs_condition_list *cond) |
1670 |
{ |
{ |
1671 |
int pos; |
int pos; |
1672 |
const char *atmark1 = ""; |
const char *atmark1 = ""; |
1707 |
} |
} |
1708 |
|
|
1709 |
/** |
/** |
1710 |
* print_argv0_acl - Print an argv[0] ACL entry. |
* ccs_print_argv0_acl - Print an argv[0] ACL entry. |
1711 |
* |
* |
1712 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1713 |
* @ptr: Pointer to "struct argv0_acl_record". |
* @ptr: Pointer to "struct ccs_argv0_acl_record". |
1714 |
* @cond: Pointer to "struct condition_list". May be NULL. |
* @cond: Pointer to "struct ccs_condition_list". May be NULL. |
1715 |
* |
* |
1716 |
* Returns true on success, false otherwise. |
* Returns true on success, false otherwise. |
1717 |
*/ |
*/ |
1718 |
static bool print_argv0_acl(struct ccs_io_buffer *head, |
static bool ccs_print_argv0_acl(struct ccs_io_buffer *head, |
1719 |
struct argv0_acl_record *ptr, |
struct ccs_argv0_acl_record *ptr, |
1720 |
const struct condition_list *cond) |
const struct ccs_condition_list *cond) |
1721 |
{ |
{ |
1722 |
int pos = head->read_avail; |
int pos = head->read_avail; |
1723 |
if (!ccs_io_printf(head, KEYWORD_ALLOW_ARGV0 "%s %s", |
if (!ccs_io_printf(head, KEYWORD_ALLOW_ARGV0 "%s %s", |
1732 |
} |
} |
1733 |
|
|
1734 |
/** |
/** |
1735 |
* print_env_acl - Print an evironment variable name's ACL entry. |
* ccs_print_env_acl - Print an evironment variable name's ACL entry. |
1736 |
* |
* |
1737 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1738 |
* @ptr: Pointer to "struct env_acl_record". |
* @ptr: Pointer to "struct ccs_env_acl_record". |
1739 |
* @cond: Pointer to "struct condition_list". May be NULL. |
* @cond: Pointer to "struct ccs_condition_list". May be NULL. |
1740 |
* |
* |
1741 |
* Returns true on success, false otherwise. |
* Returns true on success, false otherwise. |
1742 |
*/ |
*/ |
1743 |
static bool print_env_acl(struct ccs_io_buffer *head, |
static bool ccs_print_env_acl(struct ccs_io_buffer *head, |
1744 |
struct env_acl_record *ptr, |
struct ccs_env_acl_record *ptr, |
1745 |
const struct condition_list *cond) |
const struct ccs_condition_list *cond) |
1746 |
{ |
{ |
1747 |
int pos = head->read_avail; |
int pos = head->read_avail; |
1748 |
if (!ccs_io_printf(head, KEYWORD_ALLOW_ENV "%s", ptr->env->name)) |
if (!ccs_io_printf(head, KEYWORD_ALLOW_ENV "%s", ptr->env->name)) |
1756 |
} |
} |
1757 |
|
|
1758 |
/** |
/** |
1759 |
* print_capability_acl - Print a capability ACL entry. |
* ccs_print_capability_acl - Print a capability ACL entry. |
1760 |
* |
* |
1761 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1762 |
* @ptr: Pointer to "struct capability_acl_record". |
* @ptr: Pointer to "struct ccs_capability_acl_record". |
1763 |
* @cond: Pointer to "struct condition_list". May be NULL. |
* @cond: Pointer to "struct ccs_condition_list". May be NULL. |
1764 |
* |
* |
1765 |
* Returns true on success, false otherwise. |
* Returns true on success, false otherwise. |
1766 |
*/ |
*/ |
1767 |
static bool print_capability_acl(struct ccs_io_buffer *head, |
static bool ccs_print_capability_acl(struct ccs_io_buffer *head, |
1768 |
struct capability_acl_record *ptr, |
struct ccs_capability_acl_record *ptr, |
1769 |
const struct condition_list *cond) |
const struct ccs_condition_list *cond) |
1770 |
{ |
{ |
1771 |
int pos = head->read_avail; |
int pos = head->read_avail; |
1772 |
if (!ccs_io_printf(head, KEYWORD_ALLOW_CAPABILITY "%s", |
if (!ccs_io_printf(head, KEYWORD_ALLOW_CAPABILITY "%s", |
1781 |
} |
} |
1782 |
|
|
1783 |
/** |
/** |
1784 |
* print_ipv4_entry - Print IPv4 address of a network ACL entry. |
* ccs_print_ipv4_entry - Print IPv4 address of a network ACL entry. |
1785 |
* |
* |
1786 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1787 |
* @ptr: Pointer to "struct ip_network_acl_record". |
* @ptr: Pointer to "struct ccs_ip_network_acl_record". |
1788 |
* |
* |
1789 |
* Returns true on success, false otherwise. |
* Returns true on success, false otherwise. |
1790 |
*/ |
*/ |
1791 |
static bool print_ipv4_entry(struct ccs_io_buffer *head, |
static bool ccs_print_ipv4_entry(struct ccs_io_buffer *head, |
1792 |
struct ip_network_acl_record *ptr) |
struct ccs_ip_network_acl_record *ptr) |
1793 |
{ |
{ |
1794 |
const u32 min_address = ptr->u.ipv4.min; |
const u32 min_address = ptr->u.ipv4.min; |
1795 |
const u32 max_address = ptr->u.ipv4.max; |
const u32 max_address = ptr->u.ipv4.max; |
1802 |
} |
} |
1803 |
|
|
1804 |
/** |
/** |
1805 |
* print_ipv6_entry - Print IPv6 address of a network ACL entry. |
* ccs_print_ipv6_entry - Print IPv6 address of a network ACL entry. |
1806 |
* |
* |
1807 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1808 |
* @ptr: Pointer to "struct ip_network_acl_record". |
* @ptr: Pointer to "struct ccs_ip_network_acl_record". |
1809 |
* |
* |
1810 |
* Returns true on success, false otherwise. |
* Returns true on success, false otherwise. |
1811 |
*/ |
*/ |
1812 |
static bool print_ipv6_entry(struct ccs_io_buffer *head, |
static bool ccs_print_ipv6_entry(struct ccs_io_buffer *head, |
1813 |
struct ip_network_acl_record *ptr) |
struct ccs_ip_network_acl_record *ptr) |
1814 |
{ |
{ |
1815 |
char buf[64]; |
char buf[64]; |
1816 |
const struct in6_addr *min_address = ptr->u.ipv6.min; |
const struct in6_addr *min_address = ptr->u.ipv6.min; |
1827 |
} |
} |
1828 |
|
|
1829 |
/** |
/** |
1830 |
* print_port_entry - Print port number of a network ACL entry. |
* ccs_print_port_entry - Print port number of a network ACL entry. |
1831 |
* |
* |
1832 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1833 |
* @ptr: Pointer to "struct ip_network_acl_record". |
* @ptr: Pointer to "struct ccs_ip_network_acl_record". |
1834 |
* |
* |
1835 |
* Returns true on success, false otherwise. |
* Returns true on success, false otherwise. |
1836 |
*/ |
*/ |
1837 |
static bool print_port_entry(struct ccs_io_buffer *head, |
static bool ccs_print_port_entry(struct ccs_io_buffer *head, |
1838 |
struct ip_network_acl_record *ptr) |
struct ccs_ip_network_acl_record *ptr) |
1839 |
{ |
{ |
1840 |
const u16 min_port = ptr->min_port, max_port = ptr->max_port; |
const u16 min_port = ptr->min_port, max_port = ptr->max_port; |
1841 |
if (!ccs_io_printf(head, " %u", min_port)) |
if (!ccs_io_printf(head, " %u", min_port)) |
1846 |
} |
} |
1847 |
|
|
1848 |
/** |
/** |
1849 |
* print_network_acl - Print a network ACL entry. |
* ccs_print_network_acl - Print a network ACL entry. |
1850 |
* |
* |
1851 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1852 |
* @ptr: Pointer to "struct ip_network_acl_record". |
* @ptr: Pointer to "struct ccs_ip_network_acl_record". |
1853 |
* @cond: Pointer to "struct condition_list". May be NULL. |
* @cond: Pointer to "struct ccs_condition_list". May be NULL. |
1854 |
* |
* |
1855 |
* Returns true on success, false otherwise. |
* Returns true on success, false otherwise. |
1856 |
*/ |
*/ |
1857 |
static bool print_network_acl(struct ccs_io_buffer *head, |
static bool ccs_print_network_acl(struct ccs_io_buffer *head, |
1858 |
struct ip_network_acl_record *ptr, |
struct ccs_ip_network_acl_record *ptr, |
1859 |
const struct condition_list *cond) |
const struct ccs_condition_list *cond) |
1860 |
{ |
{ |
1861 |
int pos = head->read_avail; |
int pos = head->read_avail; |
1862 |
if (!ccs_io_printf(head, KEYWORD_ALLOW_NETWORK "%s ", |
if (!ccs_io_printf(head, KEYWORD_ALLOW_NETWORK "%s ", |
1868 |
goto out; |
goto out; |
1869 |
break; |
break; |
1870 |
case IP_RECORD_TYPE_IPv4: |
case IP_RECORD_TYPE_IPv4: |
1871 |
if (!print_ipv4_entry(head, ptr)) |
if (!ccs_print_ipv4_entry(head, ptr)) |
1872 |
goto out; |
goto out; |
1873 |
break; |
break; |
1874 |
case IP_RECORD_TYPE_IPv6: |
case IP_RECORD_TYPE_IPv6: |
1875 |
if (!print_ipv6_entry(head, ptr)) |
if (!ccs_print_ipv6_entry(head, ptr)) |
1876 |
goto out; |
goto out; |
1877 |
break; |
break; |
1878 |
} |
} |
1879 |
if (!print_port_entry(head, ptr)) |
if (!ccs_print_port_entry(head, ptr)) |
1880 |
goto out; |
goto out; |
1881 |
if (!ccs_print_condition(head, cond)) |
if (!ccs_print_condition(head, cond)) |
1882 |
goto out; |
goto out; |
1887 |
} |
} |
1888 |
|
|
1889 |
/** |
/** |
1890 |
* print_signal_acl - Print a signal ACL entry. |
* ccs_print_signal_acl - Print a signal ACL entry. |
1891 |
* |
* |
1892 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1893 |
* @ptr: Pointer to "struct signale_acl_record". |
* @ptr: Pointer to "struct signale_acl_record". |
1894 |
* @cond: Pointer to "struct condition_list". May be NULL. |
* @cond: Pointer to "struct ccs_condition_list". May be NULL. |
1895 |
* |
* |
1896 |
* Returns true on success, false otherwise. |
* Returns true on success, false otherwise. |
1897 |
*/ |
*/ |
1898 |
static bool print_signal_acl(struct ccs_io_buffer *head, |
static bool ccs_print_signal_acl(struct ccs_io_buffer *head, |
1899 |
struct signal_acl_record *ptr, |
struct ccs_signal_acl_record *ptr, |
1900 |
const struct condition_list *cond) |
const struct ccs_condition_list *cond) |
1901 |
{ |
{ |
1902 |
int pos = head->read_avail; |
int pos = head->read_avail; |
1903 |
if (!ccs_io_printf(head, KEYWORD_ALLOW_SIGNAL "%u %s", |
if (!ccs_io_printf(head, KEYWORD_ALLOW_SIGNAL "%u %s", |
1912 |
} |
} |
1913 |
|
|
1914 |
/** |
/** |
1915 |
* print_execute_handler_record - Print an execute handler ACL entry. |
* ccs_print_execute_handler_record - Print an execute handler ACL entry. |
1916 |
* |
* |
1917 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1918 |
* @keyword: Name of the keyword. |
* @keyword: Name of the keyword. |
1919 |
* @ptr: Pointer to "struct execute_handler_record". |
* @ptr: Pointer to "struct ccs_execute_handler_record". |
1920 |
* |
* |
1921 |
* Returns true on success, false otherwise. |
* Returns true on success, false otherwise. |
1922 |
*/ |
*/ |
1923 |
static bool print_execute_handler_record(struct ccs_io_buffer *head, |
static bool ccs_print_execute_handler_record(struct ccs_io_buffer *head, |
1924 |
const char *keyword, |
const char *keyword, |
1925 |
struct execute_handler_record *ptr) |
struct ccs_execute_handler_record * |
1926 |
|
ptr) |
1927 |
{ |
{ |
1928 |
return ccs_io_printf(head, "%s %s\n", keyword, ptr->handler->name); |
return ccs_io_printf(head, "%s %s\n", keyword, ptr->handler->name); |
1929 |
} |
} |
1930 |
|
|
1931 |
/** |
/** |
1932 |
* print_entry - Print an ACL entry. |
* ccs_print_entry - Print an ACL entry. |
1933 |
* |
* |
1934 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1935 |
* @ptr: Pointer to an ACL entry. |
* @ptr: Pointer to an ACL entry. |
1936 |
* |
* |
1937 |
* Returns true on success, false otherwise. |
* Returns true on success, false otherwise. |
1938 |
*/ |
*/ |
1939 |
static bool print_entry(struct ccs_io_buffer *head, struct acl_info *ptr) |
static bool ccs_print_entry(struct ccs_io_buffer *head, |
1940 |
|
struct ccs_acl_info *ptr) |
1941 |
{ |
{ |
1942 |
const struct condition_list *cond = ccs_get_condition_part(ptr); |
const struct ccs_condition_list *cond = ccs_get_condition_part(ptr); |
1943 |
const u8 acl_type = ccs_acl_type2(ptr); |
const u8 acl_type = ccs_acl_type2(ptr); |
1944 |
if (acl_type & ACL_DELETED) |
if (acl_type & ACL_DELETED) |
1945 |
return true; |
return true; |
1946 |
if (acl_type == TYPE_SINGLE_PATH_ACL) { |
if (acl_type == TYPE_SINGLE_PATH_ACL) { |
1947 |
struct single_path_acl_record *acl |
struct ccs_single_path_acl_record *acl |
1948 |
= container_of(ptr, struct single_path_acl_record, |
= container_of(ptr, struct ccs_single_path_acl_record, |
1949 |
head); |
head); |
1950 |
return print_single_path_acl(head, acl, cond); |
return ccs_print_single_path_acl(head, acl, cond); |
1951 |
} |
} |
1952 |
if (acl_type == TYPE_EXECUTE_HANDLER) { |
if (acl_type == TYPE_EXECUTE_HANDLER) { |
1953 |
struct execute_handler_record *acl |
struct ccs_execute_handler_record *acl |
1954 |
= container_of(ptr, struct execute_handler_record, |
= container_of(ptr, struct ccs_execute_handler_record, |
1955 |
head); |
head); |
1956 |
const char *keyword = KEYWORD_EXECUTE_HANDLER; |
const char *keyword = KEYWORD_EXECUTE_HANDLER; |
1957 |
return print_execute_handler_record(head, keyword, acl); |
return ccs_print_execute_handler_record(head, keyword, acl); |
1958 |
} |
} |
1959 |
if (acl_type == TYPE_DENIED_EXECUTE_HANDLER) { |
if (acl_type == TYPE_DENIED_EXECUTE_HANDLER) { |
1960 |
struct execute_handler_record *acl |
struct ccs_execute_handler_record *acl |
1961 |
= container_of(ptr, struct execute_handler_record, |
= container_of(ptr, struct ccs_execute_handler_record, |
1962 |
head); |
head); |
1963 |
const char *keyword = KEYWORD_DENIED_EXECUTE_HANDLER; |
const char *keyword = KEYWORD_DENIED_EXECUTE_HANDLER; |
1964 |
return print_execute_handler_record(head, keyword, acl); |
return ccs_print_execute_handler_record(head, keyword, acl); |
1965 |
} |
} |
1966 |
if (head->read_execute_only) |
if (head->read_execute_only) |
1967 |
return true; |
return true; |
1968 |
if (acl_type == TYPE_DOUBLE_PATH_ACL) { |
if (acl_type == TYPE_DOUBLE_PATH_ACL) { |
1969 |
struct double_path_acl_record *acl |
struct ccs_double_path_acl_record *acl |
1970 |
= container_of(ptr, struct double_path_acl_record, |
= container_of(ptr, struct ccs_double_path_acl_record, |
1971 |
head); |
head); |
1972 |
return print_double_path_acl(head, acl, cond); |
return ccs_print_double_path_acl(head, acl, cond); |
1973 |
} |
} |
1974 |
if (acl_type == TYPE_ARGV0_ACL) { |
if (acl_type == TYPE_ARGV0_ACL) { |
1975 |
struct argv0_acl_record *acl |
struct ccs_argv0_acl_record *acl |
1976 |
= container_of(ptr, struct argv0_acl_record, head); |
= container_of(ptr, struct ccs_argv0_acl_record, head); |
1977 |
return print_argv0_acl(head, acl, cond); |
return ccs_print_argv0_acl(head, acl, cond); |
1978 |
} |
} |
1979 |
if (acl_type == TYPE_ENV_ACL) { |
if (acl_type == TYPE_ENV_ACL) { |
1980 |
struct env_acl_record *acl |
struct ccs_env_acl_record *acl |
1981 |
= container_of(ptr, struct env_acl_record, head); |
= container_of(ptr, struct ccs_env_acl_record, head); |
1982 |
return print_env_acl(head, acl, cond); |
return ccs_print_env_acl(head, acl, cond); |
1983 |
} |
} |
1984 |
if (acl_type == TYPE_CAPABILITY_ACL) { |
if (acl_type == TYPE_CAPABILITY_ACL) { |
1985 |
struct capability_acl_record *acl |
struct ccs_capability_acl_record *acl |
1986 |
= container_of(ptr, struct capability_acl_record, head); |
= container_of(ptr, struct ccs_capability_acl_record, |
1987 |
return print_capability_acl(head, acl, cond); |
head); |
1988 |
|
return ccs_print_capability_acl(head, acl, cond); |
1989 |
} |
} |
1990 |
if (acl_type == TYPE_IP_NETWORK_ACL) { |
if (acl_type == TYPE_IP_NETWORK_ACL) { |
1991 |
struct ip_network_acl_record *acl |
struct ccs_ip_network_acl_record *acl |
1992 |
= container_of(ptr, struct ip_network_acl_record, head); |
= container_of(ptr, struct ccs_ip_network_acl_record, |
1993 |
return print_network_acl(head, acl, cond); |
head); |
1994 |
|
return ccs_print_network_acl(head, acl, cond); |
1995 |
} |
} |
1996 |
if (acl_type == TYPE_SIGNAL_ACL) { |
if (acl_type == TYPE_SIGNAL_ACL) { |
1997 |
struct signal_acl_record *acl |
struct ccs_signal_acl_record *acl |
1998 |
= container_of(ptr, struct signal_acl_record, head); |
= container_of(ptr, struct ccs_signal_acl_record, head); |
1999 |
return print_signal_acl(head, acl, cond); |
return ccs_print_signal_acl(head, acl, cond); |
2000 |
} |
} |
2001 |
/* Workaround for gcc 3.2.2's inline bug. */ |
/* Workaround for gcc 3.2.2's inline bug. */ |
2002 |
if (acl_type & ACL_DELETED) |
if (acl_type & ACL_DELETED) |
2006 |
} |
} |
2007 |
|
|
2008 |
/** |
/** |
2009 |
* read_domain_policy - Read domain policy. |
* ccs_read_domain_policy - Read domain policy. |
2010 |
* |
* |
2011 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
2012 |
* |
* |
2013 |
* Returns 0. |
* Returns 0. |
2014 |
*/ |
*/ |
2015 |
static int read_domain_policy(struct ccs_io_buffer *head) |
static int ccs_read_domain_policy(struct ccs_io_buffer *head) |
2016 |
{ |
{ |
2017 |
struct list1_head *dpos; |
struct list1_head *dpos; |
2018 |
struct list1_head *apos; |
struct list1_head *apos; |
2020 |
return 0; |
return 0; |
2021 |
if (head->read_step == 0) |
if (head->read_step == 0) |
2022 |
head->read_step = 1; |
head->read_step = 1; |
2023 |
list1_for_each_cookie(dpos, head->read_var1, &domain_list) { |
list1_for_each_cookie(dpos, head->read_var1, &ccs_domain_list) { |
2024 |
struct domain_info *domain; |
struct domain_info *domain; |
2025 |
const char *quota_exceeded = ""; |
const char *quota_exceeded = ""; |
2026 |
const char *transition_failed = ""; |
const char *transition_failed = ""; |
2050 |
ignore_global_allow_env)) |
ignore_global_allow_env)) |
2051 |
return 0; |
return 0; |
2052 |
head->read_step = 2; |
head->read_step = 2; |
2053 |
acl_loop: |
acl_loop: |
2054 |
if (head->read_step == 3) |
if (head->read_step == 3) |
2055 |
goto tail_mark; |
goto tail_mark; |
2056 |
/* Print ACL entries in the domain. */ |
/* Print ACL entries in the domain. */ |
2057 |
list1_for_each_cookie(apos, head->read_var2, |
list1_for_each_cookie(apos, head->read_var2, |
2058 |
&domain->acl_info_list) { |
&domain->acl_info_list) { |
2059 |
struct acl_info *ptr |
struct ccs_acl_info *ptr |
2060 |
= list1_entry(apos, struct acl_info, list); |
= list1_entry(apos, struct ccs_acl_info, list); |
2061 |
if (!print_entry(head, ptr)) |
if (!ccs_print_entry(head, ptr)) |
2062 |
return 0; |
return 0; |
2063 |
} |
} |
2064 |
head->read_step = 3; |
head->read_step = 3; |
2065 |
tail_mark: |
tail_mark: |
2066 |
if (!ccs_io_printf(head, "\n")) |
if (!ccs_io_printf(head, "\n")) |
2067 |
return 0; |
return 0; |
2068 |
head->read_step = 1; |
head->read_step = 1; |
2076 |
#endif |
#endif |
2077 |
|
|
2078 |
/** |
/** |
2079 |
* write_domain_profile - Assign profile for specified domain. |
* ccs_write_domain_profile - Assign profile for specified domain. |
2080 |
* |
* |
2081 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
2082 |
* |
* |
2087 |
* ( echo "select " $domainname; echo "use_profile " $profile ) | |
* ( echo "select " $domainname; echo "use_profile " $profile ) | |
2088 |
* /usr/lib/ccs/loadpolicy -d |
* /usr/lib/ccs/loadpolicy -d |
2089 |
*/ |
*/ |
2090 |
static int write_domain_profile(struct ccs_io_buffer *head) |
static int ccs_write_domain_profile(struct ccs_io_buffer *head) |
2091 |
{ |
{ |
2092 |
char *data = head->write_buf; |
char *data = head->write_buf; |
2093 |
char *cp = strchr(data, ' '); |
char *cp = strchr(data, ' '); |
2099 |
domain = ccs_find_domain(cp + 1); |
domain = ccs_find_domain(cp + 1); |
2100 |
profile = simple_strtoul(data, NULL, 10); |
profile = simple_strtoul(data, NULL, 10); |
2101 |
if (domain && profile < MAX_PROFILES |
if (domain && profile < MAX_PROFILES |
2102 |
&& (profile_ptr[profile] || !sbin_init_started)) |
&& (ccs_profile_ptr[profile] || !ccs_sbin_init_started)) |
2103 |
domain->profile = (u8) profile; |
domain->profile = (u8) profile; |
2104 |
ccs_update_counter(CCS_UPDATES_COUNTER_DOMAIN_POLICY); |
ccs_update_counter(CCS_UPDATES_COUNTER_DOMAIN_POLICY); |
2105 |
return 0; |
return 0; |
2106 |
} |
} |
2107 |
|
|
2108 |
/** |
/** |
2109 |
* read_domain_profile - Read only domainname and profile. |
* ccs_read_domain_profile - Read only domainname and profile. |
2110 |
* |
* |
2111 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
2112 |
* |
* |
2119 |
* domainname = $0; } else if ( $1 == "use_profile" ) { |
* domainname = $0; } else if ( $1 == "use_profile" ) { |
2120 |
* print $2 " " domainname; domainname = ""; } } ; ' |
* print $2 " " domainname; domainname = ""; } } ; ' |
2121 |
*/ |
*/ |
2122 |
static int read_domain_profile(struct ccs_io_buffer *head) |
static int ccs_read_domain_profile(struct ccs_io_buffer *head) |
2123 |
{ |
{ |
2124 |
struct list1_head *pos; |
struct list1_head *pos; |
2125 |
if (head->read_eof) |
if (head->read_eof) |
2126 |
return 0; |
return 0; |
2127 |
list1_for_each_cookie(pos, head->read_var1, &domain_list) { |
list1_for_each_cookie(pos, head->read_var1, &ccs_domain_list) { |
2128 |
struct domain_info *domain; |
struct domain_info *domain; |
2129 |
domain = list1_entry(pos, struct domain_info, list); |
domain = list1_entry(pos, struct domain_info, list); |
2130 |
if (domain->is_deleted) |
if (domain->is_deleted) |
2138 |
} |
} |
2139 |
|
|
2140 |
/** |
/** |
2141 |
* write_pid: Specify PID to obtain domainname. |
* ccs_write_pid: Specify PID to obtain domainname. |
2142 |
* |
* |
2143 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
2144 |
* |
* |
2145 |
* Returns 0. |
* Returns 0. |
2146 |
*/ |
*/ |
2147 |
static int write_pid(struct ccs_io_buffer *head) |
static int ccs_write_pid(struct ccs_io_buffer *head) |
2148 |
{ |
{ |
2149 |
head->read_eof = false; |
head->read_eof = false; |
2150 |
return 0; |
return 0; |
2151 |
} |
} |
2152 |
|
|
2153 |
/** |
/** |
2154 |
* read_pid - Read information of a process. |
* ccs_read_pid - Read information of a process. |
2155 |
* |
* |
2156 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
2157 |
* |
* |
2159 |
* process information of the specified PID on success, |
* process information of the specified PID on success, |
2160 |
* empty string otherwise. |
* empty string otherwise. |
2161 |
*/ |
*/ |
2162 |
static int read_pid(struct ccs_io_buffer *head) |
static int ccs_read_pid(struct ccs_io_buffer *head) |
2163 |
{ |
{ |
2164 |
char *buf = head->write_buf; |
char *buf = head->write_buf; |
2165 |
bool task_info = false; |
bool task_info = false; |
2173 |
if (head->read_avail || head->read_eof) |
if (head->read_avail || head->read_eof) |
2174 |
goto done; |
goto done; |
2175 |
head->read_eof = true; |
head->read_eof = true; |
2176 |
if (str_starts(&buf, "info ")) |
if (ccs_str_starts(&buf, "info ")) |
2177 |
task_info = true; |
task_info = true; |
2178 |
pid = (unsigned int) simple_strtoul(buf, NULL, 10); |
pid = (unsigned int) simple_strtoul(buf, NULL, 10); |
2179 |
/***** CRITICAL SECTION START *****/ |
/***** CRITICAL SECTION START *****/ |
2207 |
#ifdef CONFIG_TOMOYO |
#ifdef CONFIG_TOMOYO |
2208 |
|
|
2209 |
/** |
/** |
2210 |
* write_exception_policy - Write exception policy. |
* ccs_write_exception_policy - Write exception policy. |
2211 |
* |
* |
2212 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
2213 |
* |
* |
2214 |
* Returns 0 on success, negative value otherwise. |
* Returns 0 on success, negative value otherwise. |
2215 |
*/ |
*/ |
2216 |
static int write_exception_policy(struct ccs_io_buffer *head) |
static int ccs_write_exception_policy(struct ccs_io_buffer *head) |
2217 |
{ |
{ |
2218 |
char *data = head->write_buf; |
char *data = head->write_buf; |
2219 |
bool is_delete = str_starts(&data, KEYWORD_DELETE); |
bool is_delete = ccs_str_starts(&data, KEYWORD_DELETE); |
2220 |
if (str_starts(&data, KEYWORD_KEEP_DOMAIN)) |
if (ccs_str_starts(&data, KEYWORD_KEEP_DOMAIN)) |
2221 |
return ccs_write_domain_keeper_policy(data, false, is_delete); |
return ccs_write_domain_keeper_policy(data, false, is_delete); |
2222 |
if (str_starts(&data, KEYWORD_NO_KEEP_DOMAIN)) |
if (ccs_str_starts(&data, KEYWORD_NO_KEEP_DOMAIN)) |
2223 |
return ccs_write_domain_keeper_policy(data, true, is_delete); |
return ccs_write_domain_keeper_policy(data, true, is_delete); |
2224 |
if (str_starts(&data, KEYWORD_INITIALIZE_DOMAIN)) |
if (ccs_str_starts(&data, KEYWORD_INITIALIZE_DOMAIN)) |
2225 |
return ccs_write_domain_initializer_policy(data, false, |
return ccs_write_domain_initializer_policy(data, false, |
2226 |
is_delete); |
is_delete); |
2227 |
if (str_starts(&data, KEYWORD_NO_INITIALIZE_DOMAIN)) |
if (ccs_str_starts(&data, KEYWORD_NO_INITIALIZE_DOMAIN)) |
2228 |
return ccs_write_domain_initializer_policy(data, true, |
return ccs_write_domain_initializer_policy(data, true, |
2229 |
is_delete); |
is_delete); |
2230 |
if (str_starts(&data, KEYWORD_ALIAS)) |
if (ccs_str_starts(&data, KEYWORD_ALIAS)) |
2231 |
return ccs_write_alias_policy(data, is_delete); |
return ccs_write_alias_policy(data, is_delete); |
2232 |
if (str_starts(&data, KEYWORD_AGGREGATOR)) |
if (ccs_str_starts(&data, KEYWORD_AGGREGATOR)) |
2233 |
return ccs_write_aggregator_policy(data, is_delete); |
return ccs_write_aggregator_policy(data, is_delete); |
2234 |
if (str_starts(&data, KEYWORD_ALLOW_READ)) |
if (ccs_str_starts(&data, KEYWORD_ALLOW_READ)) |
2235 |
return ccs_write_globally_readable_policy(data, is_delete); |
return ccs_write_globally_readable_policy(data, is_delete); |
2236 |
if (str_starts(&data, KEYWORD_ALLOW_ENV)) |
if (ccs_str_starts(&data, KEYWORD_ALLOW_ENV)) |
2237 |
return ccs_write_globally_usable_env_policy(data, is_delete); |
return ccs_write_globally_usable_env_policy(data, is_delete); |
2238 |
if (str_starts(&data, KEYWORD_FILE_PATTERN)) |
if (ccs_str_starts(&data, KEYWORD_FILE_PATTERN)) |
2239 |
return ccs_write_pattern_policy(data, is_delete); |
return ccs_write_pattern_policy(data, is_delete); |
2240 |
if (str_starts(&data, KEYWORD_PATH_GROUP)) |
if (ccs_str_starts(&data, KEYWORD_PATH_GROUP)) |
2241 |
return ccs_write_path_group_policy(data, is_delete); |
return ccs_write_path_group_policy(data, is_delete); |
2242 |
if (str_starts(&data, KEYWORD_DENY_REWRITE)) |
if (ccs_str_starts(&data, KEYWORD_DENY_REWRITE)) |
2243 |
return ccs_write_no_rewrite_policy(data, is_delete); |
return ccs_write_no_rewrite_policy(data, is_delete); |
2244 |
if (str_starts(&data, KEYWORD_ADDRESS_GROUP)) |
if (ccs_str_starts(&data, KEYWORD_ADDRESS_GROUP)) |
2245 |
return ccs_write_address_group_policy(data, is_delete); |
return ccs_write_address_group_policy(data, is_delete); |
2246 |
return -EINVAL; |
return -EINVAL; |
2247 |
} |
} |
2248 |
|
|
2249 |
/** |
/** |
2250 |
* read_exception_policy - Read exception policy. |
* ccs_read_exception_policy - Read exception policy. |
2251 |
* |
* |
2252 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
2253 |
* |
* |
2254 |
* Returns 0 on success, -EINVAL otherwise. |
* Returns 0 on success, -EINVAL otherwise. |
2255 |
*/ |
*/ |
2256 |
static int read_exception_policy(struct ccs_io_buffer *head) |
static int ccs_read_exception_policy(struct ccs_io_buffer *head) |
2257 |
{ |
{ |
2258 |
if (!head->read_eof) { |
if (!head->read_eof) { |
2259 |
switch (head->read_step) { |
switch (head->read_step) { |
2323 |
#ifdef CONFIG_SAKURA |
#ifdef CONFIG_SAKURA |
2324 |
|
|
2325 |
/** |
/** |
2326 |
* write_system_policy - Write system policy. |
* ccs_write_system_policy - Write system policy. |
2327 |
* |
* |
2328 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
2329 |
* |
* |
2330 |
* Returns 0 on success, negative value otherwise. |
* Returns 0 on success, negative value otherwise. |
2331 |
*/ |
*/ |
2332 |
static int write_system_policy(struct ccs_io_buffer *head) |
static int ccs_write_system_policy(struct ccs_io_buffer *head) |
2333 |
{ |
{ |
2334 |
char *data = head->write_buf; |
char *data = head->write_buf; |
2335 |
bool is_delete = false; |
bool is_delete = false; |
2336 |
if (str_starts(&data, KEYWORD_DELETE)) |
if (ccs_str_starts(&data, KEYWORD_DELETE)) |
2337 |
is_delete = true; |
is_delete = true; |
2338 |
if (str_starts(&data, KEYWORD_ALLOW_MOUNT)) |
if (ccs_str_starts(&data, KEYWORD_ALLOW_MOUNT)) |
2339 |
return ccs_write_mount_policy(data, is_delete); |
return ccs_write_mount_policy(data, is_delete); |
2340 |
if (str_starts(&data, KEYWORD_DENY_UNMOUNT)) |
if (ccs_str_starts(&data, KEYWORD_DENY_UNMOUNT)) |
2341 |
return ccs_write_no_umount_policy(data, is_delete); |
return ccs_write_no_umount_policy(data, is_delete); |
2342 |
if (str_starts(&data, KEYWORD_ALLOW_CHROOT)) |
if (ccs_str_starts(&data, KEYWORD_ALLOW_CHROOT)) |
2343 |
return ccs_write_chroot_policy(data, is_delete); |
return ccs_write_chroot_policy(data, is_delete); |
2344 |
if (str_starts(&data, KEYWORD_ALLOW_PIVOT_ROOT)) |
if (ccs_str_starts(&data, KEYWORD_ALLOW_PIVOT_ROOT)) |
2345 |
return ccs_write_pivot_root_policy(data, is_delete); |
return ccs_write_pivot_root_policy(data, is_delete); |
2346 |
if (str_starts(&data, KEYWORD_DENY_AUTOBIND)) |
if (ccs_str_starts(&data, KEYWORD_DENY_AUTOBIND)) |
2347 |
return ccs_write_reserved_port_policy(data, is_delete); |
return ccs_write_reserved_port_policy(data, is_delete); |
2348 |
return -EINVAL; |
return -EINVAL; |
2349 |
} |
} |
2350 |
|
|
2351 |
/** |
/** |
2352 |
* read_system_policy - Read system policy. |
* ccs_read_system_policy - Read system policy. |
2353 |
* |
* |
2354 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
2355 |
* |
* |
2356 |
* Returns 0 on success, -EINVAL otherwise. |
* Returns 0 on success, -EINVAL otherwise. |
2357 |
*/ |
*/ |
2358 |
static int read_system_policy(struct ccs_io_buffer *head) |
static int ccs_read_system_policy(struct ccs_io_buffer *head) |
2359 |
{ |
{ |
2360 |
if (!head->read_eof) { |
if (!head->read_eof) { |
2361 |
switch (head->read_step) { |
switch (head->read_step) { |
2400 |
static const char *ccs_loader; |
static const char *ccs_loader; |
2401 |
|
|
2402 |
/** |
/** |
2403 |
* loader_setup - Specify the policy loader to use. |
* ccs_loader_setup - Specify the policy loader to use. |
2404 |
* |
* |
2405 |
* @str: Path to the policy loader. |
* @str: Path to the policy loader. |
2406 |
* |
* |
2407 |
* Returns 0. |
* Returns 0. |
2408 |
*/ |
*/ |
2409 |
static int __init loader_setup(char *str) |
static int __init ccs_loader_setup(char *str) |
2410 |
{ |
{ |
2411 |
ccs_loader = str; |
ccs_loader = str; |
2412 |
return 0; |
return 0; |
2413 |
} |
} |
2414 |
|
|
2415 |
__setup("CCS_loader=", loader_setup); |
__setup("CCS_loader=", ccs_loader_setup); |
2416 |
|
|
2417 |
/** |
/** |
2418 |
* policy_loader_exists - Check whether /sbin/ccs-init exists. |
* ccs_policy_loader_exists - Check whether /sbin/ccs-init exists. |
2419 |
* |
* |
2420 |
* Returns true if /sbin/ccs-init exists, false otherwise. |
* Returns true if /sbin/ccs-init exists, false otherwise. |
2421 |
*/ |
*/ |
2422 |
static bool policy_loader_exists(void) |
static bool ccs_policy_loader_exists(void) |
2423 |
{ |
{ |
2424 |
/* |
/* |
2425 |
* Don't activate MAC if the path given by 'CCS_loader=' option doesn't |
* Don't activate MAC if the path given by 'CCS_loader=' option doesn't |
2431 |
struct nameidata nd; |
struct nameidata nd; |
2432 |
if (!ccs_loader) |
if (!ccs_loader) |
2433 |
ccs_loader = "/sbin/ccs-init"; |
ccs_loader = "/sbin/ccs-init"; |
2434 |
if (path_lookup(ccs_loader, lookup_flags, &nd)) { |
if (path_lookup(ccs_loader, ccs_lookup_flags, &nd)) { |
2435 |
printk(KERN_INFO "Not activating Mandatory Access Control now " |
printk(KERN_INFO "Not activating Mandatory Access Control now " |
2436 |
"since %s doesn't exist.\n", ccs_loader); |
"since %s doesn't exist.\n", ccs_loader); |
2437 |
return false; |
return false; |
2446 |
|
|
2447 |
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 0) |
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 0) |
2448 |
/** |
/** |
2449 |
* run_ccs_loader - Start /sbin/ccs-init . |
* ccs_run_loader - Start /sbin/ccs-init . |
2450 |
* |
* |
2451 |
* @unused: Not used. |
* @unused: Not used. |
2452 |
* |
* |
2453 |
* Returns PID of /sbin/ccs-init on success, negative value otherwise. |
* Returns PID of /sbin/ccs-init on success, negative value otherwise. |
2454 |
*/ |
*/ |
2455 |
static int run_ccs_loader(void *unused) |
static int ccs_run_loader(void *unused) |
2456 |
{ |
{ |
2457 |
char *argv[2]; |
char *argv[2]; |
2458 |
char *envp[3]; |
char *envp[3]; |
2482 |
*/ |
*/ |
2483 |
void ccs_load_policy(const char *filename) |
void ccs_load_policy(const char *filename) |
2484 |
{ |
{ |
2485 |
if (sbin_init_started) |
if (ccs_sbin_init_started) |
2486 |
return; |
return; |
2487 |
/* |
/* |
2488 |
* Check filename is /sbin/init or /sbin/ccs-start. |
* Check filename is /sbin/init or /sbin/ccs-start. |
2493 |
if (strcmp(filename, "/sbin/init") && |
if (strcmp(filename, "/sbin/init") && |
2494 |
strcmp(filename, "/sbin/ccs-start")) |
strcmp(filename, "/sbin/ccs-start")) |
2495 |
return; |
return; |
2496 |
if (!policy_loader_exists()) |
if (!ccs_policy_loader_exists()) |
2497 |
return; |
return; |
2498 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 0) |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 0) |
2499 |
{ |
{ |
2512 |
{ |
{ |
2513 |
/* Copied from kernel/kmod.c */ |
/* Copied from kernel/kmod.c */ |
2514 |
struct task_struct *task = current; |
struct task_struct *task = current; |
2515 |
pid_t pid = kernel_thread(run_ccs_loader, NULL, 0); |
pid_t pid = kernel_thread(ccs_run_loader, NULL, 0); |
2516 |
sigset_t tmpsig; |
sigset_t tmpsig; |
2517 |
spin_lock_irq(&task->sighand->siglock); |
spin_lock_irq(&task->sighand->siglock); |
2518 |
tmpsig = task->blocked; |
tmpsig = task->blocked; |
2531 |
{ |
{ |
2532 |
/* Copied from kernel/kmod.c */ |
/* Copied from kernel/kmod.c */ |
2533 |
struct task_struct *task = current; |
struct task_struct *task = current; |
2534 |
pid_t pid = kernel_thread(run_ccs_loader, NULL, 0); |
pid_t pid = kernel_thread(ccs_run_loader, NULL, 0); |
2535 |
sigset_t tmpsig; |
sigset_t tmpsig; |
2536 |
spin_lock_irq(&task->sigmask_lock); |
spin_lock_irq(&task->sigmask_lock); |
2537 |
tmpsig = task->blocked; |
tmpsig = task->blocked; |
2548 |
} |
} |
2549 |
#endif |
#endif |
2550 |
#ifdef CONFIG_SAKURA |
#ifdef CONFIG_SAKURA |
2551 |
printk(KERN_INFO "SAKURA: 1.6.6-pre 2008/12/01\n"); |
printk(KERN_INFO "SAKURA: 1.6.6-pre 2008/12/24\n"); |
2552 |
#endif |
#endif |
2553 |
#ifdef CONFIG_TOMOYO |
#ifdef CONFIG_TOMOYO |
2554 |
printk(KERN_INFO "TOMOYO: 1.6.6-pre 2008/12/22\n"); |
printk(KERN_INFO "TOMOYO: 1.6.6-pre 2008/12/24\n"); |
2555 |
#endif |
#endif |
2556 |
printk(KERN_INFO "Mandatory Access Control activated.\n"); |
printk(KERN_INFO "Mandatory Access Control activated.\n"); |
2557 |
sbin_init_started = true; |
ccs_sbin_init_started = true; |
2558 |
ccs_log_level = KERN_WARNING; |
ccs_log_level = KERN_WARNING; |
2559 |
{ /* Check all profiles currently assigned to domains are defined. */ |
{ /* Check all profiles currently assigned to domains are defined. */ |
2560 |
struct domain_info *domain; |
struct domain_info *domain; |
2561 |
list1_for_each_entry(domain, &domain_list, list) { |
list1_for_each_entry(domain, &ccs_domain_list, list) { |
2562 |
const u8 profile = domain->profile; |
const u8 profile = domain->profile; |
2563 |
if (profile_ptr[profile]) |
if (ccs_profile_ptr[profile]) |
2564 |
continue; |
continue; |
2565 |
panic("Profile %u (used by '%s') not defined.\n", |
panic("Profile %u (used by '%s') not defined.\n", |
2566 |
profile, domain->domainname->name); |
profile, domain->domainname->name); |
2568 |
} |
} |
2569 |
} |
} |
2570 |
|
|
2571 |
/* Wait queue for query_list. */ |
/* Wait queue for ccs_query_list. */ |
2572 |
static DECLARE_WAIT_QUEUE_HEAD(query_wait); |
static DECLARE_WAIT_QUEUE_HEAD(ccs_query_wait); |
2573 |
|
|
2574 |
/* Lock for manipulating query_list. */ |
/* Lock for manipulating ccs_query_list. */ |
2575 |
static DEFINE_SPINLOCK(query_list_lock); |
static DEFINE_SPINLOCK(ccs_query_list_lock); |
2576 |
|
|
2577 |
/* Structure for query. */ |
/* Structure for query. */ |
2578 |
struct query_entry { |
struct ccs_query_entry { |
2579 |
struct list_head list; |
struct list_head list; |
2580 |
char *query; |
char *query; |
2581 |
int query_len; |
int query_len; |
2584 |
int answer; |
int answer; |
2585 |
}; |
}; |
2586 |
|
|
2587 |
/* The list for "struct query_entry". */ |
/* The list for "struct ccs_query_entry". */ |
2588 |
static LIST_HEAD(query_list); |
static LIST_HEAD(ccs_query_list); |
2589 |
|
|
2590 |
/* Number of "struct file" referring /proc/ccs/query interface. */ |
/* Number of "struct file" referring /proc/ccs/query interface. */ |
2591 |
static atomic_t queryd_watcher = ATOMIC_INIT(0); |
static atomic_t ccs_queryd_watcher = ATOMIC_INIT(0); |
2592 |
|
|
2593 |
/** |
/** |
2594 |
* ccs_check_supervisor - Ask for the supervisor's decision. |
* ccs_check_supervisor - Ask for the supervisor's decision. |
2607 |
int error = -EPERM; |
int error = -EPERM; |
2608 |
int pos; |
int pos; |
2609 |
int len; |
int len; |
2610 |
static unsigned int serial; |
static unsigned int ccs_serial; |
2611 |
struct query_entry *query_entry = NULL; |
struct ccs_query_entry *ccs_query_entry = NULL; |
2612 |
char *header; |
char *header; |
2613 |
if (!r->domain) |
if (!r->domain) |
2614 |
r->domain = current->domain_info; |
r->domain = current->domain_info; |
2615 |
if (!atomic_read(&queryd_watcher)) { |
if (!atomic_read(&ccs_queryd_watcher)) { |
2616 |
int i; |
int i; |
2617 |
if (current->tomoyo_flags & CCS_DONT_SLEEP_ON_ENFORCE_ERROR) |
if (current->tomoyo_flags & CCS_DONT_SLEEP_ON_ENFORCE_ERROR) |
2618 |
return -EPERM; |
return -EPERM; |
2633 |
#endif |
#endif |
2634 |
if (!header) |
if (!header) |
2635 |
goto out; |
goto out; |
2636 |
query_entry = ccs_alloc(sizeof(*query_entry), true); |
ccs_query_entry = ccs_alloc(sizeof(*ccs_query_entry), true); |
2637 |
if (!query_entry) |
if (!ccs_query_entry) |
2638 |
goto out; |
goto out; |
2639 |
query_entry->query = ccs_alloc(len, true); |
ccs_query_entry->query = ccs_alloc(len, true); |
2640 |
if (!query_entry->query) |
if (!ccs_query_entry->query) |
2641 |
goto out; |
goto out; |
2642 |
INIT_LIST_HEAD(&query_entry->list); |
INIT_LIST_HEAD(&ccs_query_entry->list); |
2643 |
/***** CRITICAL SECTION START *****/ |
/***** CRITICAL SECTION START *****/ |
2644 |
spin_lock(&query_list_lock); |
spin_lock(&ccs_query_list_lock); |
2645 |
query_entry->serial = serial++; |
ccs_query_entry->serial = ccs_serial++; |
2646 |
spin_unlock(&query_list_lock); |
spin_unlock(&ccs_query_list_lock); |
2647 |
/***** CRITICAL SECTION END *****/ |
/***** CRITICAL SECTION END *****/ |
2648 |
pos = snprintf(query_entry->query, len - 1, "Q%u-%hu\n%s", |
pos = snprintf(ccs_query_entry->query, len - 1, "Q%u-%hu\n%s", |
2649 |
query_entry->serial, r->retry, header); |
ccs_query_entry->serial, r->retry, header); |
2650 |
ccs_free(header); |
ccs_free(header); |
2651 |
header = NULL; |
header = NULL; |
2652 |
va_start(args, fmt); |
va_start(args, fmt); |
2653 |
vsnprintf(query_entry->query + pos, len - 1 - pos, fmt, args); |
vsnprintf(ccs_query_entry->query + pos, len - 1 - pos, fmt, args); |
2654 |
query_entry->query_len = strlen(query_entry->query) + 1; |
ccs_query_entry->query_len = strlen(ccs_query_entry->query) + 1; |
2655 |
va_end(args); |
va_end(args); |
2656 |
/***** CRITICAL SECTION START *****/ |
/***** CRITICAL SECTION START *****/ |
2657 |
spin_lock(&query_list_lock); |
spin_lock(&ccs_query_list_lock); |
2658 |
list_add_tail(&query_entry->list, &query_list); |
list_add_tail(&ccs_query_entry->list, &ccs_query_list); |
2659 |
spin_unlock(&query_list_lock); |
spin_unlock(&ccs_query_list_lock); |
2660 |
/***** CRITICAL SECTION END *****/ |
/***** CRITICAL SECTION END *****/ |
2661 |
ccs_update_counter(CCS_UPDATES_COUNTER_QUERY); |
ccs_update_counter(CCS_UPDATES_COUNTER_QUERY); |
2662 |
/* Give 10 seconds for supervisor's opinion. */ |
/* Give 10 seconds for supervisor's opinion. */ |
2663 |
for (query_entry->timer = 0; atomic_read(&queryd_watcher) |
for (ccs_query_entry->timer = 0; |
2664 |
&& query_entry->timer < 100; query_entry->timer++) { |
atomic_read(&ccs_queryd_watcher) && ccs_query_entry->timer < 100; |
2665 |
wake_up(&query_wait); |
ccs_query_entry->timer++) { |
2666 |
|
wake_up(&ccs_query_wait); |
2667 |
set_current_state(TASK_INTERRUPTIBLE); |
set_current_state(TASK_INTERRUPTIBLE); |
2668 |
schedule_timeout(HZ / 10); |
schedule_timeout(HZ / 10); |
2669 |
if (query_entry->answer) |
if (ccs_query_entry->answer) |
2670 |
break; |
break; |
2671 |
} |
} |
2672 |
ccs_update_counter(CCS_UPDATES_COUNTER_QUERY); |
ccs_update_counter(CCS_UPDATES_COUNTER_QUERY); |
2673 |
/***** CRITICAL SECTION START *****/ |
/***** CRITICAL SECTION START *****/ |
2674 |
spin_lock(&query_list_lock); |
spin_lock(&ccs_query_list_lock); |
2675 |
list_del(&query_entry->list); |
list_del(&ccs_query_entry->list); |
2676 |
spin_unlock(&query_list_lock); |
spin_unlock(&ccs_query_list_lock); |
2677 |
/***** CRITICAL SECTION END *****/ |
/***** CRITICAL SECTION END *****/ |
2678 |
switch (query_entry->answer) { |
switch (ccs_query_entry->answer) { |
2679 |
case 3: /* Asked to retry by administrator. */ |
case 3: /* Asked to retry by administrator. */ |
2680 |
error = 1; |
error = 1; |
2681 |
r->retry++; |
r->retry++; |
2692 |
break; |
break; |
2693 |
} |
} |
2694 |
out: |
out: |
2695 |
if (query_entry) |
if (ccs_query_entry) |
2696 |
ccs_free(query_entry->query); |
ccs_free(ccs_query_entry->query); |
2697 |
ccs_free(query_entry); |
ccs_free(ccs_query_entry); |
2698 |
ccs_free(header); |
ccs_free(header); |
2699 |
return error; |
return error; |
2700 |
} |
} |
2701 |
|
|
2702 |
/** |
/** |
2703 |
* poll_query - poll() for /proc/ccs/query. |
* ccs_poll_query - poll() for /proc/ccs/query. |
2704 |
* |
* |
2705 |
* @file: Pointer to "struct file". |
* @file: Pointer to "struct file". |
2706 |
* @wait: Pointer to "poll_table". |
* @wait: Pointer to "poll_table". |
2709 |
* |
* |
2710 |
* Waits for access requests which violated policy in enforcing mode. |
* Waits for access requests which violated policy in enforcing mode. |
2711 |
*/ |
*/ |
2712 |
static int poll_query(struct file *file, poll_table *wait) |
static int ccs_poll_query(struct file *file, poll_table *wait) |
2713 |
{ |
{ |
2714 |
struct list_head *tmp; |
struct list_head *tmp; |
2715 |
bool found = false; |
bool found = false; |
2716 |
u8 i; |
u8 i; |
2717 |
for (i = 0; i < 2; i++) { |
for (i = 0; i < 2; i++) { |
2718 |
/***** CRITICAL SECTION START *****/ |
/***** CRITICAL SECTION START *****/ |
2719 |
spin_lock(&query_list_lock); |
spin_lock(&ccs_query_list_lock); |
2720 |
list_for_each(tmp, &query_list) { |
list_for_each(tmp, &ccs_query_list) { |
2721 |
struct query_entry *ptr |
struct ccs_query_entry *ptr |
2722 |
= list_entry(tmp, struct query_entry, list); |
= list_entry(tmp, struct ccs_query_entry, list); |
2723 |
if (ptr->answer) |
if (ptr->answer) |
2724 |
continue; |
continue; |
2725 |
found = true; |
found = true; |
2726 |
break; |
break; |
2727 |
} |
} |
2728 |
spin_unlock(&query_list_lock); |
spin_unlock(&ccs_query_list_lock); |
2729 |
/***** CRITICAL SECTION END *****/ |
/***** CRITICAL SECTION END *****/ |
2730 |
if (found) |
if (found) |
2731 |
return POLLIN | POLLRDNORM; |
return POLLIN | POLLRDNORM; |
2732 |
if (i) |
if (i) |
2733 |
break; |
break; |
2734 |
poll_wait(file, &query_wait, wait); |
poll_wait(file, &ccs_query_wait, wait); |
2735 |
} |
} |
2736 |
return 0; |
return 0; |
2737 |
} |
} |
2738 |
|
|
2739 |
/** |
/** |
2740 |
* read_query - Read access requests which violated policy in enforcing mode. |
* ccs_read_query - Read access requests which violated policy in enforcing mode. |
2741 |
* |
* |
2742 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
2743 |
* |
* |
2744 |
* Returns 0. |
* Returns 0. |
2745 |
*/ |
*/ |
2746 |
static int read_query(struct ccs_io_buffer *head) |
static int ccs_read_query(struct ccs_io_buffer *head) |
2747 |
{ |
{ |
2748 |
struct list_head *tmp; |
struct list_head *tmp; |
2749 |
int pos = 0; |
int pos = 0; |
2757 |
head->readbuf_size = 0; |
head->readbuf_size = 0; |
2758 |
} |
} |
2759 |
/***** CRITICAL SECTION START *****/ |
/***** CRITICAL SECTION START *****/ |
2760 |
spin_lock(&query_list_lock); |
spin_lock(&ccs_query_list_lock); |
2761 |
list_for_each(tmp, &query_list) { |
list_for_each(tmp, &ccs_query_list) { |
2762 |
struct query_entry *ptr |
struct ccs_query_entry *ptr |
2763 |
= list_entry(tmp, struct query_entry, list); |
= list_entry(tmp, struct ccs_query_entry, list); |
2764 |
if (ptr->answer) |
if (ptr->answer) |
2765 |
continue; |
continue; |
2766 |
if (pos++ != head->read_step) |
if (pos++ != head->read_step) |
2768 |
len = ptr->query_len; |
len = ptr->query_len; |
2769 |
break; |
break; |
2770 |
} |
} |
2771 |
spin_unlock(&query_list_lock); |
spin_unlock(&ccs_query_list_lock); |
2772 |
/***** CRITICAL SECTION END *****/ |
/***** CRITICAL SECTION END *****/ |
2773 |
if (!len) { |
if (!len) { |
2774 |
head->read_step = 0; |
head->read_step = 0; |
2779 |
return 0; |
return 0; |
2780 |
pos = 0; |
pos = 0; |
2781 |
/***** CRITICAL SECTION START *****/ |
/***** CRITICAL SECTION START *****/ |
2782 |
spin_lock(&query_list_lock); |
spin_lock(&ccs_query_list_lock); |
2783 |
list_for_each(tmp, &query_list) { |
list_for_each(tmp, &ccs_query_list) { |
2784 |
struct query_entry *ptr |
struct ccs_query_entry *ptr |
2785 |
= list_entry(tmp, struct query_entry, list); |
= list_entry(tmp, struct ccs_query_entry, list); |
2786 |
if (ptr->answer) |
if (ptr->answer) |
2787 |
continue; |
continue; |
2788 |
if (pos++ != head->read_step) |
if (pos++ != head->read_step) |
2789 |
continue; |
continue; |
2790 |
/* |
/* |
2791 |
* Some query can be skipped because query_list |
* Some query can be skipped because ccs_query_list |
2792 |
* can change, but I don't care. |
* can change, but I don't care. |
2793 |
*/ |
*/ |
2794 |
if (len == ptr->query_len) |
if (len == ptr->query_len) |
2795 |
memmove(buf, ptr->query, len); |
memmove(buf, ptr->query, len); |
2796 |
break; |
break; |
2797 |
} |
} |
2798 |
spin_unlock(&query_list_lock); |
spin_unlock(&ccs_query_list_lock); |
2799 |
/***** CRITICAL SECTION END *****/ |
/***** CRITICAL SECTION END *****/ |
2800 |
if (buf[0]) { |
if (buf[0]) { |
2801 |
head->read_avail = len; |
head->read_avail = len; |
2809 |
} |
} |
2810 |
|
|
2811 |
/** |
/** |
2812 |
* write_answer - Write the supervisor's decision. |
* ccs_write_answer - Write the supervisor's decision. |
2813 |
* |
* |
2814 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
2815 |
* |
* |
2816 |
* Returns 0 on success, -EINVAL otherwise. |
* Returns 0 on success, -EINVAL otherwise. |
2817 |
*/ |
*/ |
2818 |
static int write_answer(struct ccs_io_buffer *head) |
static int ccs_write_answer(struct ccs_io_buffer *head) |
2819 |
{ |
{ |
2820 |
char *data = head->write_buf; |
char *data = head->write_buf; |
2821 |
struct list_head *tmp; |
struct list_head *tmp; |
2822 |
unsigned int serial; |
unsigned int serial; |
2823 |
unsigned int answer; |
unsigned int answer; |
2824 |
/***** CRITICAL SECTION START *****/ |
/***** CRITICAL SECTION START *****/ |
2825 |
spin_lock(&query_list_lock); |
spin_lock(&ccs_query_list_lock); |
2826 |
list_for_each(tmp, &query_list) { |
list_for_each(tmp, &ccs_query_list) { |
2827 |
struct query_entry *ptr |
struct ccs_query_entry *ptr |
2828 |
= list_entry(tmp, struct query_entry, list); |
= list_entry(tmp, struct ccs_query_entry, list); |
2829 |
ptr->timer = 0; |
ptr->timer = 0; |
2830 |
} |
} |
2831 |
spin_unlock(&query_list_lock); |
spin_unlock(&ccs_query_list_lock); |
2832 |
/***** CRITICAL SECTION END *****/ |
/***** CRITICAL SECTION END *****/ |
2833 |
if (sscanf(data, "A%u=%u", &serial, &answer) != 2) |
if (sscanf(data, "A%u=%u", &serial, &answer) != 2) |
2834 |
return -EINVAL; |
return -EINVAL; |
2835 |
/***** CRITICAL SECTION START *****/ |
/***** CRITICAL SECTION START *****/ |
2836 |
spin_lock(&query_list_lock); |
spin_lock(&ccs_query_list_lock); |
2837 |
list_for_each(tmp, &query_list) { |
list_for_each(tmp, &ccs_query_list) { |
2838 |
struct query_entry *ptr |
struct ccs_query_entry *ptr |
2839 |
= list_entry(tmp, struct query_entry, list); |
= list_entry(tmp, struct ccs_query_entry, list); |
2840 |
if (ptr->serial != serial) |
if (ptr->serial != serial) |
2841 |
continue; |
continue; |
2842 |
if (!ptr->answer) |
if (!ptr->answer) |
2843 |
ptr->answer = answer; |
ptr->answer = answer; |
2844 |
break; |
break; |
2845 |
} |
} |
2846 |
spin_unlock(&query_list_lock); |
spin_unlock(&ccs_query_list_lock); |
2847 |
/***** CRITICAL SECTION END *****/ |
/***** CRITICAL SECTION END *****/ |
2848 |
return 0; |
return 0; |
2849 |
} |
} |
2850 |
|
|
2851 |
/* Policy updates counter. */ |
/* Policy updates counter. */ |
2852 |
static unsigned int updates_counter[MAX_CCS_UPDATES_COUNTER]; |
static unsigned int ccs_updates_counter[MAX_CCS_UPDATES_COUNTER]; |
2853 |
|
|
2854 |
/* Policy updates counter lock. */ |
/* Policy updates counter lock. */ |
2855 |
static DEFINE_SPINLOCK(updates_counter_lock); |
static DEFINE_SPINLOCK(ccs_updates_counter_lock); |
2856 |
|
|
2857 |
/** |
/** |
2858 |
* ccs_update_counter - Increment policy change counter. |
* ccs_update_counter - Increment policy change counter. |
2864 |
void ccs_update_counter(const unsigned char index) |
void ccs_update_counter(const unsigned char index) |
2865 |
{ |
{ |
2866 |
/***** CRITICAL SECTION START *****/ |
/***** CRITICAL SECTION START *****/ |
2867 |
spin_lock(&updates_counter_lock); |
spin_lock(&ccs_updates_counter_lock); |
2868 |
if (index < MAX_CCS_UPDATES_COUNTER) |
if (index < MAX_CCS_UPDATES_COUNTER) |
2869 |
updates_counter[index]++; |
ccs_updates_counter[index]++; |
2870 |
spin_unlock(&updates_counter_lock); |
spin_unlock(&ccs_updates_counter_lock); |
2871 |
/***** CRITICAL SECTION END *****/ |
/***** CRITICAL SECTION END *****/ |
2872 |
} |
} |
2873 |
|
|
2874 |
/** |
/** |
2875 |
* read_updates_counter - Check for policy change counter. |
* ccs_read_updates_counter - Check for policy change counter. |
2876 |
* |
* |
2877 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
2878 |
* |
* |
2879 |
* Returns how many times policy has changed since the previous check. |
* Returns how many times policy has changed since the previous check. |
2880 |
*/ |
*/ |
2881 |
static int read_updates_counter(struct ccs_io_buffer *head) |
static int ccs_read_updates_counter(struct ccs_io_buffer *head) |
2882 |
{ |
{ |
2883 |
if (!head->read_eof) { |
if (!head->read_eof) { |
2884 |
unsigned int counter[MAX_CCS_UPDATES_COUNTER]; |
unsigned int counter[MAX_CCS_UPDATES_COUNTER]; |
2885 |
/***** CRITICAL SECTION START *****/ |
/***** CRITICAL SECTION START *****/ |
2886 |
spin_lock(&updates_counter_lock); |
spin_lock(&ccs_updates_counter_lock); |
2887 |
memmove(counter, updates_counter, sizeof(updates_counter)); |
memmove(counter, ccs_updates_counter, |
2888 |
memset(updates_counter, 0, sizeof(updates_counter)); |
sizeof(ccs_updates_counter)); |
2889 |
spin_unlock(&updates_counter_lock); |
memset(ccs_updates_counter, 0, sizeof(ccs_updates_counter)); |
2890 |
|
spin_unlock(&ccs_updates_counter_lock); |
2891 |
/***** CRITICAL SECTION END *****/ |
/***** CRITICAL SECTION END *****/ |
2892 |
ccs_io_printf(head, |
ccs_io_printf(head, |
2893 |
"/proc/ccs/system_policy: %10u\n" |
"/proc/ccs/system_policy: %10u\n" |
2912 |
} |
} |
2913 |
|
|
2914 |
/** |
/** |
2915 |
* read_version: Get version. |
* ccs_read_version: Get version. |
2916 |
* |
* |
2917 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
2918 |
* |
* |
2919 |
* Returns version information. |
* Returns version information. |
2920 |
*/ |
*/ |
2921 |
static int read_version(struct ccs_io_buffer *head) |
static int ccs_read_version(struct ccs_io_buffer *head) |
2922 |
{ |
{ |
2923 |
if (!head->read_eof) { |
if (!head->read_eof) { |
2924 |
ccs_io_printf(head, "1.6.6-pre"); |
ccs_io_printf(head, "1.6.6-pre"); |
2928 |
} |
} |
2929 |
|
|
2930 |
/** |
/** |
2931 |
* read_self_domain - Get the current process's domainname. |
* ccs_read_self_domain - Get the current process's domainname. |
2932 |
* |
* |
2933 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
2934 |
* |
* |
2935 |
* Returns the current process's domainname. |
* Returns the current process's domainname. |
2936 |
*/ |
*/ |
2937 |
static int read_self_domain(struct ccs_io_buffer *head) |
static int ccs_read_self_domain(struct ccs_io_buffer *head) |
2938 |
{ |
{ |
2939 |
if (!head->read_eof) { |
if (!head->read_eof) { |
2940 |
/* |
/* |
2966 |
switch (type) { |
switch (type) { |
2967 |
#ifdef CONFIG_SAKURA |
#ifdef CONFIG_SAKURA |
2968 |
case CCS_SYSTEMPOLICY: /* /proc/ccs/system_policy */ |
case CCS_SYSTEMPOLICY: /* /proc/ccs/system_policy */ |
2969 |
head->write = write_system_policy; |
head->write = ccs_write_system_policy; |
2970 |
head->read = read_system_policy; |
head->read = ccs_read_system_policy; |
2971 |
break; |
break; |
2972 |
#endif |
#endif |
2973 |
#ifdef CONFIG_TOMOYO |
#ifdef CONFIG_TOMOYO |
2974 |
case CCS_DOMAINPOLICY: /* /proc/ccs/domain_policy */ |
case CCS_DOMAINPOLICY: /* /proc/ccs/domain_policy */ |
2975 |
head->write = write_domain_policy; |
head->write = ccs_write_domain_policy; |
2976 |
head->read = read_domain_policy; |
head->read = ccs_read_domain_policy; |
2977 |
break; |
break; |
2978 |
case CCS_EXCEPTIONPOLICY: /* /proc/ccs/exception_policy */ |
case CCS_EXCEPTIONPOLICY: /* /proc/ccs/exception_policy */ |
2979 |
head->write = write_exception_policy; |
head->write = ccs_write_exception_policy; |
2980 |
head->read = read_exception_policy; |
head->read = ccs_read_exception_policy; |
2981 |
break; |
break; |
2982 |
case CCS_GRANTLOG: /* /proc/ccs/grant_log */ |
case CCS_GRANTLOG: /* /proc/ccs/grant_log */ |
2983 |
head->poll = ccs_poll_grant_log; |
head->poll = ccs_poll_grant_log; |
2989 |
break; |
break; |
2990 |
#endif |
#endif |
2991 |
case CCS_SELFDOMAIN: /* /proc/ccs/self_domain */ |
case CCS_SELFDOMAIN: /* /proc/ccs/self_domain */ |
2992 |
head->read = read_self_domain; |
head->read = ccs_read_self_domain; |
2993 |
break; |
break; |
2994 |
case CCS_DOMAIN_STATUS: /* /proc/ccs/.domain_status */ |
case CCS_DOMAIN_STATUS: /* /proc/ccs/.domain_status */ |
2995 |
head->write = write_domain_profile; |
head->write = ccs_write_domain_profile; |
2996 |
head->read = read_domain_profile; |
head->read = ccs_read_domain_profile; |
2997 |
break; |
break; |
2998 |
case CCS_EXECUTE_HANDLER: /* /proc/ccs/.execute_handler */ |
case CCS_EXECUTE_HANDLER: /* /proc/ccs/.execute_handler */ |
2999 |
/* Allow execute_handler to read process's status. */ |
/* Allow execute_handler to read process's status. */ |
3003 |
} |
} |
3004 |
/* fall through */ |
/* fall through */ |
3005 |
case CCS_PROCESS_STATUS: /* /proc/ccs/.process_status */ |
case CCS_PROCESS_STATUS: /* /proc/ccs/.process_status */ |
3006 |
head->write = write_pid; |
head->write = ccs_write_pid; |
3007 |
head->read = read_pid; |
head->read = ccs_read_pid; |
3008 |
break; |
break; |
3009 |
case CCS_VERSION: /* /proc/ccs/version */ |
case CCS_VERSION: /* /proc/ccs/version */ |
3010 |
head->read = read_version; |
head->read = ccs_read_version; |
3011 |
head->readbuf_size = 128; |
head->readbuf_size = 128; |
3012 |
break; |
break; |
3013 |
case CCS_MEMINFO: /* /proc/ccs/meminfo */ |
case CCS_MEMINFO: /* /proc/ccs/meminfo */ |
3016 |
head->readbuf_size = 512; |
head->readbuf_size = 512; |
3017 |
break; |
break; |
3018 |
case CCS_PROFILE: /* /proc/ccs/profile */ |
case CCS_PROFILE: /* /proc/ccs/profile */ |
3019 |
head->write = write_profile; |
head->write = ccs_write_profile; |
3020 |
head->read = read_profile; |
head->read = ccs_read_profile; |
3021 |
break; |
break; |
3022 |
case CCS_QUERY: /* /proc/ccs/query */ |
case CCS_QUERY: /* /proc/ccs/query */ |
3023 |
head->poll = poll_query; |
head->poll = ccs_poll_query; |
3024 |
head->write = write_answer; |
head->write = ccs_write_answer; |
3025 |
head->read = read_query; |
head->read = ccs_read_query; |
3026 |
break; |
break; |
3027 |
case CCS_MANAGER: /* /proc/ccs/manager */ |
case CCS_MANAGER: /* /proc/ccs/manager */ |
3028 |
head->write = write_manager_policy; |
head->write = ccs_write_manager_policy; |
3029 |
head->read = read_manager_policy; |
head->read = ccs_read_manager_policy; |
3030 |
break; |
break; |
3031 |
case CCS_UPDATESCOUNTER: /* /proc/ccs/.updates_counter */ |
case CCS_UPDATESCOUNTER: /* /proc/ccs/.ccs_updates_counter */ |
3032 |
head->read = read_updates_counter; |
head->read = ccs_read_updates_counter; |
3033 |
break; |
break; |
3034 |
} |
} |
3035 |
if (!(file->f_mode & FMODE_READ)) { |
if (!(file->f_mode & FMODE_READ)) { |
3081 |
* The monitor count is used by ccs_check_supervisor() to see if |
* The monitor count is used by ccs_check_supervisor() to see if |
3082 |
* there is some process monitoring /proc/ccs/query. |
* there is some process monitoring /proc/ccs/query. |
3083 |
*/ |
*/ |
3084 |
else if (head->write == write_answer || head->read == read_query) |
else if (head->write == ccs_write_answer || |
3085 |
atomic_inc(&queryd_watcher); |
head->read == ccs_read_query) |
3086 |
|
atomic_inc(&ccs_queryd_watcher); |
3087 |
return 0; |
return 0; |
3088 |
} |
} |
3089 |
|
|
3171 |
if (!access_ok(VERIFY_READ, buffer, buffer_len)) |
if (!access_ok(VERIFY_READ, buffer, buffer_len)) |
3172 |
return -EFAULT; |
return -EFAULT; |
3173 |
/* Don't allow updating policies by non manager programs. */ |
/* Don't allow updating policies by non manager programs. */ |
3174 |
if (head->write != write_pid && |
if (head->write != ccs_write_pid && |
3175 |
#ifdef CONFIG_TOMOYO |
#ifdef CONFIG_TOMOYO |
3176 |
head->write != write_domain_policy && |
head->write != ccs_write_domain_policy && |
3177 |
#endif |
#endif |
3178 |
!is_policy_manager()) |
!ccs_is_policy_manager()) |
3179 |
return -EPERM; |
return -EPERM; |
3180 |
if (mutex_lock_interruptible(&head->io_sem)) |
if (mutex_lock_interruptible(&head->io_sem)) |
3181 |
return -EINTR; |
return -EINTR; |
3196 |
continue; |
continue; |
3197 |
cp0[head->write_avail - 1] = '\0'; |
cp0[head->write_avail - 1] = '\0'; |
3198 |
head->write_avail = 0; |
head->write_avail = 0; |
3199 |
normalize_line(cp0); |
ccs_normalize_line(cp0); |
3200 |
head->write(head); |
head->write(head); |
3201 |
} |
} |
3202 |
mutex_unlock(&head->io_sem); |
mutex_unlock(&head->io_sem); |
3216 |
/* |
/* |
3217 |
* If the file is /proc/ccs/query , decrement the monitor count. |
* If the file is /proc/ccs/query , decrement the monitor count. |
3218 |
*/ |
*/ |
3219 |
if (head->write == write_answer || head->read == read_query) |
if (head->write == ccs_write_answer || head->read == ccs_read_query) |
3220 |
atomic_dec(&queryd_watcher); |
atomic_dec(&ccs_queryd_watcher); |
3221 |
/* Release memory used for policy I/O. */ |
/* Release memory used for policy I/O. */ |
3222 |
ccs_free(head->read_buf); |
ccs_free(head->read_buf); |
3223 |
head->read_buf = NULL; |
head->read_buf = NULL; |
3238 |
* Returns pointer to the ACL entry on success, NULL otherwise. |
* Returns pointer to the ACL entry on success, NULL otherwise. |
3239 |
*/ |
*/ |
3240 |
void *ccs_alloc_acl_element(const u8 acl_type, |
void *ccs_alloc_acl_element(const u8 acl_type, |
3241 |
const struct condition_list *condition) |
const struct ccs_condition_list *condition) |
3242 |
{ |
{ |
3243 |
int len; |
int len; |
3244 |
struct acl_info *ptr; |
struct ccs_acl_info *ptr; |
3245 |
switch (acl_type) { |
switch (acl_type) { |
3246 |
case TYPE_SINGLE_PATH_ACL: |
case TYPE_SINGLE_PATH_ACL: |
3247 |
len = sizeof(struct single_path_acl_record); |
len = sizeof(struct ccs_single_path_acl_record); |
3248 |
break; |
break; |
3249 |
case TYPE_DOUBLE_PATH_ACL: |
case TYPE_DOUBLE_PATH_ACL: |
3250 |
len = sizeof(struct double_path_acl_record); |
len = sizeof(struct ccs_double_path_acl_record); |
3251 |
break; |
break; |
3252 |
case TYPE_ARGV0_ACL: |
case TYPE_ARGV0_ACL: |
3253 |
len = sizeof(struct argv0_acl_record); |
len = sizeof(struct ccs_argv0_acl_record); |
3254 |
break; |
break; |
3255 |
case TYPE_ENV_ACL: |
case TYPE_ENV_ACL: |
3256 |
len = sizeof(struct env_acl_record); |
len = sizeof(struct ccs_env_acl_record); |
3257 |
break; |
break; |
3258 |
case TYPE_CAPABILITY_ACL: |
case TYPE_CAPABILITY_ACL: |
3259 |
len = sizeof(struct capability_acl_record); |
len = sizeof(struct ccs_capability_acl_record); |
3260 |
break; |
break; |
3261 |
case TYPE_IP_NETWORK_ACL: |
case TYPE_IP_NETWORK_ACL: |
3262 |
len = sizeof(struct ip_network_acl_record); |
len = sizeof(struct ccs_ip_network_acl_record); |
3263 |
break; |
break; |
3264 |
case TYPE_SIGNAL_ACL: |
case TYPE_SIGNAL_ACL: |
3265 |
len = sizeof(struct signal_acl_record); |
len = sizeof(struct ccs_signal_acl_record); |
3266 |
break; |
break; |
3267 |
case TYPE_EXECUTE_HANDLER: |
case TYPE_EXECUTE_HANDLER: |
3268 |
case TYPE_DENIED_EXECUTE_HANDLER: |
case TYPE_DENIED_EXECUTE_HANDLER: |
3269 |
len = sizeof(struct execute_handler_record); |
len = sizeof(struct ccs_execute_handler_record); |
3270 |
break; |
break; |
3271 |
default: |
default: |
3272 |
return NULL; |
return NULL; |
3273 |
} |
} |
3274 |
/* |
/* |
3275 |
* If the ACL doesn't have condition part, reduce memory usage |
* If the ACL doesn't have condition part, reduce memory usage |
3276 |
* by eliminating sizeof(struct condition_list *). |
* by eliminating sizeof(struct ccs_condition_list *). |
3277 |
*/ |
*/ |
3278 |
if (!condition) |
if (!condition) |
3279 |
len -= sizeof(ptr->access_me_via_ccs_get_condition_part); |
len -= sizeof(ptr->access_me_via_ccs_get_condition_part); |
3286 |
return ptr; |
return ptr; |
3287 |
} |
} |
3288 |
/* |
/* |
3289 |
* Substract sizeof(struct condition_list *) because I eliminated |
* Substract sizeof(struct ccs_condition_list *) because I eliminated |
3290 |
* sizeof(struct condition_list *) from "struct acl_info" |
* sizeof(struct ccs_condition_list *) from "struct ccs_acl_info" |
3291 |
* but I must return the start address of "struct acl_info". |
* but I must return the start address of "struct ccs_acl_info". |
3292 |
*/ |
*/ |
3293 |
ptr = (void *) (((u8 *) ptr) |
ptr = (void *) (((u8 *) ptr) |
3294 |
- sizeof(ptr->access_me_via_ccs_get_condition_part)); |
- sizeof(ptr->access_me_via_ccs_get_condition_part)); |