blob: cac431d381d24e057845364cb858962f1fa1a4dc [file] [log] [blame]
Tetsuo Handac3ef1502010-05-17 10:12:46 +09001/*
2 * security/tomoyo/util.c
3 *
Tetsuo Handa0f2a55d2011-07-14 14:46:51 +09004 * Copyright (C) 2005-2011 NTT DATA CORPORATION
Tetsuo Handac3ef1502010-05-17 10:12:46 +09005 */
6
7#include <linux/slab.h>
Ingo Molnarb2d09102017-02-04 01:27:20 +01008#include <linux/rculist.h>
9
Tetsuo Handac3ef1502010-05-17 10:12:46 +090010#include "common.h"
11
12/* Lock for protecting policy. */
13DEFINE_MUTEX(tomoyo_policy_lock);
14
15/* Has /sbin/init started? */
16bool tomoyo_policy_loaded;
17
Tetsuo Handa2c47ab92011-06-26 23:21:19 +090018/*
19 * Mapping table from "enum tomoyo_mac_index" to
20 * "enum tomoyo_mac_category_index".
21 */
22const u8 tomoyo_index2category[TOMOYO_MAX_MAC_INDEX] = {
23 /* CONFIG::file group */
24 [TOMOYO_MAC_FILE_EXECUTE] = TOMOYO_MAC_CATEGORY_FILE,
25 [TOMOYO_MAC_FILE_OPEN] = TOMOYO_MAC_CATEGORY_FILE,
26 [TOMOYO_MAC_FILE_CREATE] = TOMOYO_MAC_CATEGORY_FILE,
27 [TOMOYO_MAC_FILE_UNLINK] = TOMOYO_MAC_CATEGORY_FILE,
28 [TOMOYO_MAC_FILE_GETATTR] = TOMOYO_MAC_CATEGORY_FILE,
29 [TOMOYO_MAC_FILE_MKDIR] = TOMOYO_MAC_CATEGORY_FILE,
30 [TOMOYO_MAC_FILE_RMDIR] = TOMOYO_MAC_CATEGORY_FILE,
31 [TOMOYO_MAC_FILE_MKFIFO] = TOMOYO_MAC_CATEGORY_FILE,
32 [TOMOYO_MAC_FILE_MKSOCK] = TOMOYO_MAC_CATEGORY_FILE,
33 [TOMOYO_MAC_FILE_TRUNCATE] = TOMOYO_MAC_CATEGORY_FILE,
34 [TOMOYO_MAC_FILE_SYMLINK] = TOMOYO_MAC_CATEGORY_FILE,
35 [TOMOYO_MAC_FILE_MKBLOCK] = TOMOYO_MAC_CATEGORY_FILE,
36 [TOMOYO_MAC_FILE_MKCHAR] = TOMOYO_MAC_CATEGORY_FILE,
37 [TOMOYO_MAC_FILE_LINK] = TOMOYO_MAC_CATEGORY_FILE,
38 [TOMOYO_MAC_FILE_RENAME] = TOMOYO_MAC_CATEGORY_FILE,
39 [TOMOYO_MAC_FILE_CHMOD] = TOMOYO_MAC_CATEGORY_FILE,
40 [TOMOYO_MAC_FILE_CHOWN] = TOMOYO_MAC_CATEGORY_FILE,
41 [TOMOYO_MAC_FILE_CHGRP] = TOMOYO_MAC_CATEGORY_FILE,
42 [TOMOYO_MAC_FILE_IOCTL] = TOMOYO_MAC_CATEGORY_FILE,
43 [TOMOYO_MAC_FILE_CHROOT] = TOMOYO_MAC_CATEGORY_FILE,
44 [TOMOYO_MAC_FILE_MOUNT] = TOMOYO_MAC_CATEGORY_FILE,
45 [TOMOYO_MAC_FILE_UMOUNT] = TOMOYO_MAC_CATEGORY_FILE,
46 [TOMOYO_MAC_FILE_PIVOT_ROOT] = TOMOYO_MAC_CATEGORY_FILE,
Tetsuo Handa059d84d2011-09-10 15:23:54 +090047 /* CONFIG::network group */
48 [TOMOYO_MAC_NETWORK_INET_STREAM_BIND] =
49 TOMOYO_MAC_CATEGORY_NETWORK,
50 [TOMOYO_MAC_NETWORK_INET_STREAM_LISTEN] =
51 TOMOYO_MAC_CATEGORY_NETWORK,
52 [TOMOYO_MAC_NETWORK_INET_STREAM_CONNECT] =
53 TOMOYO_MAC_CATEGORY_NETWORK,
54 [TOMOYO_MAC_NETWORK_INET_DGRAM_BIND] =
55 TOMOYO_MAC_CATEGORY_NETWORK,
56 [TOMOYO_MAC_NETWORK_INET_DGRAM_SEND] =
57 TOMOYO_MAC_CATEGORY_NETWORK,
58 [TOMOYO_MAC_NETWORK_INET_RAW_BIND] =
59 TOMOYO_MAC_CATEGORY_NETWORK,
60 [TOMOYO_MAC_NETWORK_INET_RAW_SEND] =
61 TOMOYO_MAC_CATEGORY_NETWORK,
62 [TOMOYO_MAC_NETWORK_UNIX_STREAM_BIND] =
63 TOMOYO_MAC_CATEGORY_NETWORK,
64 [TOMOYO_MAC_NETWORK_UNIX_STREAM_LISTEN] =
65 TOMOYO_MAC_CATEGORY_NETWORK,
66 [TOMOYO_MAC_NETWORK_UNIX_STREAM_CONNECT] =
67 TOMOYO_MAC_CATEGORY_NETWORK,
68 [TOMOYO_MAC_NETWORK_UNIX_DGRAM_BIND] =
69 TOMOYO_MAC_CATEGORY_NETWORK,
70 [TOMOYO_MAC_NETWORK_UNIX_DGRAM_SEND] =
71 TOMOYO_MAC_CATEGORY_NETWORK,
72 [TOMOYO_MAC_NETWORK_UNIX_SEQPACKET_BIND] =
73 TOMOYO_MAC_CATEGORY_NETWORK,
74 [TOMOYO_MAC_NETWORK_UNIX_SEQPACKET_LISTEN] =
75 TOMOYO_MAC_CATEGORY_NETWORK,
76 [TOMOYO_MAC_NETWORK_UNIX_SEQPACKET_CONNECT] =
77 TOMOYO_MAC_CATEGORY_NETWORK,
Tetsuo Handad58e0da2011-09-10 15:22:48 +090078 /* CONFIG::misc group */
79 [TOMOYO_MAC_ENVIRON] = TOMOYO_MAC_CATEGORY_MISC,
Tetsuo Handa2c47ab92011-06-26 23:21:19 +090080};
81
Tetsuo Handac3ef1502010-05-17 10:12:46 +090082/**
Tetsuo Handab22b8b92011-06-26 23:21:50 +090083 * tomoyo_convert_time - Convert time_t to YYYY/MM/DD hh/mm/ss.
84 *
85 * @time: Seconds since 1970/01/01 00:00:00.
86 * @stamp: Pointer to "struct tomoyo_time".
87 *
88 * Returns nothing.
Tetsuo Handab22b8b92011-06-26 23:21:50 +090089 */
Arnd Bergmann92734092017-10-19 14:29:04 +020090void tomoyo_convert_time(time64_t time64, struct tomoyo_time *stamp)
Tetsuo Handab22b8b92011-06-26 23:21:50 +090091{
Arnd Bergmann92734092017-10-19 14:29:04 +020092 struct tm tm;
93 time64_to_tm(time64, 0, &tm);
94 stamp->sec = tm.tm_sec;
95 stamp->min = tm.tm_min;
96 stamp->hour = tm.tm_hour;
97 stamp->day = tm.tm_mday;
98 stamp->month = tm.tm_mon + 1;
99 stamp->year = tm.tm_year + 1900;
Tetsuo Handab22b8b92011-06-26 23:21:50 +0900100}
101
102/**
Tetsuo Handaa238cf52011-06-26 23:17:10 +0900103 * tomoyo_permstr - Find permission keywords.
104 *
105 * @string: String representation for permissions in foo/bar/buz format.
106 * @keyword: Keyword to find from @string/
107 *
108 * Returns ture if @keyword was found in @string, false otherwise.
109 *
110 * This function assumes that strncmp(w1, w2, strlen(w1)) != 0 if w1 != w2.
111 */
112bool tomoyo_permstr(const char *string, const char *keyword)
113{
114 const char *cp = strstr(string, keyword);
115 if (cp)
116 return cp == string || *(cp - 1) == '/';
117 return false;
118}
119
120/**
121 * tomoyo_read_token - Read a word from a line.
122 *
123 * @param: Pointer to "struct tomoyo_acl_param".
124 *
125 * Returns a word on success, "" otherwise.
126 *
127 * To allow the caller to skip NULL check, this function returns "" rather than
128 * NULL if there is no more words to read.
129 */
130char *tomoyo_read_token(struct tomoyo_acl_param *param)
131{
132 char *pos = param->data;
133 char *del = strchr(pos, ' ');
134 if (del)
135 *del++ = '\0';
136 else
137 del = pos + strlen(pos);
138 param->data = del;
139 return pos;
140}
141
142/**
Tetsuo Handa731d37a2011-09-10 15:25:58 +0900143 * tomoyo_get_domainname - Read a domainname from a line.
144 *
145 * @param: Pointer to "struct tomoyo_acl_param".
146 *
147 * Returns a domainname on success, NULL otherwise.
148 */
149const struct tomoyo_path_info *tomoyo_get_domainname
150(struct tomoyo_acl_param *param)
151{
152 char *start = param->data;
153 char *pos = start;
154 while (*pos) {
155 if (*pos++ != ' ' || *pos++ == '/')
156 continue;
157 pos -= 2;
158 *pos++ = '\0';
159 break;
160 }
161 param->data = pos;
162 if (tomoyo_correct_domain(start))
163 return tomoyo_get_name(start);
164 return NULL;
165}
166
167/**
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900168 * tomoyo_parse_ulong - Parse an "unsigned long" value.
169 *
170 * @result: Pointer to "unsigned long".
171 * @str: Pointer to string to parse.
172 *
Tetsuo Handa0df7e8b2011-06-26 23:16:36 +0900173 * Returns one of values in "enum tomoyo_value_type".
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900174 *
175 * The @src is updated to point the first character after the value
176 * on success.
177 */
Tetsuo Handa2066a362011-07-08 13:21:37 +0900178u8 tomoyo_parse_ulong(unsigned long *result, char **str)
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900179{
180 const char *cp = *str;
181 char *ep;
182 int base = 10;
183 if (*cp == '0') {
184 char c = *(cp + 1);
185 if (c == 'x' || c == 'X') {
186 base = 16;
187 cp += 2;
188 } else if (c >= '0' && c <= '7') {
189 base = 8;
190 cp++;
191 }
192 }
193 *result = simple_strtoul(cp, &ep, base);
194 if (cp == ep)
Tetsuo Handa0df7e8b2011-06-26 23:16:36 +0900195 return TOMOYO_VALUE_TYPE_INVALID;
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900196 *str = ep;
197 switch (base) {
198 case 16:
199 return TOMOYO_VALUE_TYPE_HEXADECIMAL;
200 case 8:
201 return TOMOYO_VALUE_TYPE_OCTAL;
202 default:
203 return TOMOYO_VALUE_TYPE_DECIMAL;
204 }
205}
206
207/**
208 * tomoyo_print_ulong - Print an "unsigned long" value.
209 *
210 * @buffer: Pointer to buffer.
211 * @buffer_len: Size of @buffer.
212 * @value: An "unsigned long" value.
213 * @type: Type of @value.
214 *
215 * Returns nothing.
216 */
217void tomoyo_print_ulong(char *buffer, const int buffer_len,
218 const unsigned long value, const u8 type)
219{
220 if (type == TOMOYO_VALUE_TYPE_DECIMAL)
221 snprintf(buffer, buffer_len, "%lu", value);
222 else if (type == TOMOYO_VALUE_TYPE_OCTAL)
223 snprintf(buffer, buffer_len, "0%lo", value);
224 else if (type == TOMOYO_VALUE_TYPE_HEXADECIMAL)
225 snprintf(buffer, buffer_len, "0x%lX", value);
226 else
227 snprintf(buffer, buffer_len, "type(%u)", type);
228}
229
230/**
231 * tomoyo_parse_name_union - Parse a tomoyo_name_union.
232 *
Tetsuo Handaa238cf52011-06-26 23:17:10 +0900233 * @param: Pointer to "struct tomoyo_acl_param".
234 * @ptr: Pointer to "struct tomoyo_name_union".
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900235 *
236 * Returns true on success, false otherwise.
237 */
Tetsuo Handaa238cf52011-06-26 23:17:10 +0900238bool tomoyo_parse_name_union(struct tomoyo_acl_param *param,
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900239 struct tomoyo_name_union *ptr)
240{
Tetsuo Handaa238cf52011-06-26 23:17:10 +0900241 char *filename;
242 if (param->data[0] == '@') {
243 param->data++;
244 ptr->group = tomoyo_get_group(param, TOMOYO_PATH_GROUP);
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900245 return ptr->group != NULL;
246 }
Tetsuo Handaa238cf52011-06-26 23:17:10 +0900247 filename = tomoyo_read_token(param);
248 if (!tomoyo_correct_word(filename))
249 return false;
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900250 ptr->filename = tomoyo_get_name(filename);
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900251 return ptr->filename != NULL;
252}
253
254/**
255 * tomoyo_parse_number_union - Parse a tomoyo_number_union.
256 *
Tetsuo Handaa238cf52011-06-26 23:17:10 +0900257 * @param: Pointer to "struct tomoyo_acl_param".
258 * @ptr: Pointer to "struct tomoyo_number_union".
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900259 *
260 * Returns true on success, false otherwise.
261 */
Tetsuo Handaa238cf52011-06-26 23:17:10 +0900262bool tomoyo_parse_number_union(struct tomoyo_acl_param *param,
263 struct tomoyo_number_union *ptr)
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900264{
Tetsuo Handaa238cf52011-06-26 23:17:10 +0900265 char *data;
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900266 u8 type;
267 unsigned long v;
Tetsuo Handaa238cf52011-06-26 23:17:10 +0900268 memset(ptr, 0, sizeof(*ptr));
269 if (param->data[0] == '@') {
270 param->data++;
271 ptr->group = tomoyo_get_group(param, TOMOYO_NUMBER_GROUP);
272 return ptr->group != NULL;
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900273 }
Tetsuo Handaa238cf52011-06-26 23:17:10 +0900274 data = tomoyo_read_token(param);
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900275 type = tomoyo_parse_ulong(&v, &data);
Tetsuo Handaa238cf52011-06-26 23:17:10 +0900276 if (type == TOMOYO_VALUE_TYPE_INVALID)
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900277 return false;
Tetsuo Handaa238cf52011-06-26 23:17:10 +0900278 ptr->values[0] = v;
279 ptr->value_type[0] = type;
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900280 if (!*data) {
Tetsuo Handaa238cf52011-06-26 23:17:10 +0900281 ptr->values[1] = v;
282 ptr->value_type[1] = type;
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900283 return true;
284 }
285 if (*data++ != '-')
286 return false;
287 type = tomoyo_parse_ulong(&v, &data);
Tetsuo Handaa238cf52011-06-26 23:17:10 +0900288 if (type == TOMOYO_VALUE_TYPE_INVALID || *data || ptr->values[0] > v)
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900289 return false;
Tetsuo Handaa238cf52011-06-26 23:17:10 +0900290 ptr->values[1] = v;
291 ptr->value_type[1] = type;
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900292 return true;
293}
294
295/**
Tetsuo Handa75093152010-06-16 16:23:55 +0900296 * tomoyo_byte_range - Check whether the string is a \ooo style octal value.
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900297 *
298 * @str: Pointer to the string.
299 *
300 * Returns true if @str is a \ooo style octal value, false otherwise.
301 *
302 * TOMOYO uses \ooo style representation for 0x01 - 0x20 and 0x7F - 0xFF.
303 * This function verifies that \ooo is in valid range.
304 */
Tetsuo Handa75093152010-06-16 16:23:55 +0900305static inline bool tomoyo_byte_range(const char *str)
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900306{
307 return *str >= '0' && *str++ <= '3' &&
308 *str >= '0' && *str++ <= '7' &&
309 *str >= '0' && *str <= '7';
310}
311
312/**
Tetsuo Handa75093152010-06-16 16:23:55 +0900313 * tomoyo_alphabet_char - Check whether the character is an alphabet.
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900314 *
315 * @c: The character to check.
316 *
317 * Returns true if @c is an alphabet character, false otherwise.
318 */
Tetsuo Handa75093152010-06-16 16:23:55 +0900319static inline bool tomoyo_alphabet_char(const char c)
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900320{
321 return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z');
322}
323
324/**
325 * tomoyo_make_byte - Make byte value from three octal characters.
326 *
327 * @c1: The first character.
328 * @c2: The second character.
329 * @c3: The third character.
330 *
331 * Returns byte value.
332 */
333static inline u8 tomoyo_make_byte(const u8 c1, const u8 c2, const u8 c3)
334{
335 return ((c1 - '0') << 6) + ((c2 - '0') << 3) + (c3 - '0');
336}
337
338/**
Tetsuo Handa0df7e8b2011-06-26 23:16:36 +0900339 * tomoyo_valid - Check whether the character is a valid char.
340 *
341 * @c: The character to check.
342 *
343 * Returns true if @c is a valid character, false otherwise.
344 */
345static inline bool tomoyo_valid(const unsigned char c)
346{
347 return c > ' ' && c < 127;
348}
349
350/**
351 * tomoyo_invalid - Check whether the character is an invalid char.
352 *
353 * @c: The character to check.
354 *
355 * Returns true if @c is an invalid character, false otherwise.
356 */
357static inline bool tomoyo_invalid(const unsigned char c)
358{
359 return c && (c <= ' ' || c >= 127);
360}
361
362/**
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900363 * tomoyo_str_starts - Check whether the given string starts with the given keyword.
364 *
365 * @src: Pointer to pointer to the string.
366 * @find: Pointer to the keyword.
367 *
368 * Returns true if @src starts with @find, false otherwise.
369 *
370 * The @src is updated to point the first character after the @find
371 * if @src starts with @find.
372 */
373bool tomoyo_str_starts(char **src, const char *find)
374{
375 const int len = strlen(find);
376 char *tmp = *src;
377
378 if (strncmp(tmp, find, len))
379 return false;
380 tmp += len;
381 *src = tmp;
382 return true;
383}
384
385/**
386 * tomoyo_normalize_line - Format string.
387 *
388 * @buffer: The line to normalize.
389 *
390 * Leading and trailing whitespaces are removed.
391 * Multiple whitespaces are packed into single space.
392 *
393 * Returns nothing.
394 */
395void tomoyo_normalize_line(unsigned char *buffer)
396{
397 unsigned char *sp = buffer;
398 unsigned char *dp = buffer;
399 bool first = true;
400
Tetsuo Handa75093152010-06-16 16:23:55 +0900401 while (tomoyo_invalid(*sp))
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900402 sp++;
403 while (*sp) {
404 if (!first)
405 *dp++ = ' ';
406 first = false;
Tetsuo Handa75093152010-06-16 16:23:55 +0900407 while (tomoyo_valid(*sp))
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900408 *dp++ = *sp++;
Tetsuo Handa75093152010-06-16 16:23:55 +0900409 while (tomoyo_invalid(*sp))
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900410 sp++;
411 }
412 *dp = '\0';
413}
414
415/**
Tetsuo Handa75093152010-06-16 16:23:55 +0900416 * tomoyo_correct_word2 - Validate a string.
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900417 *
Tetsuo Handa0f2a55d2011-07-14 14:46:51 +0900418 * @string: The string to check. Maybe non-'\0'-terminated.
Tetsuo Handa3f629632010-06-03 20:37:26 +0900419 * @len: Length of @string.
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900420 *
Tetsuo Handa3f629632010-06-03 20:37:26 +0900421 * Check whether the given string follows the naming rules.
422 * Returns true if @string follows the naming rules, false otherwise.
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900423 */
Tetsuo Handa75093152010-06-16 16:23:55 +0900424static bool tomoyo_correct_word2(const char *string, size_t len)
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900425{
Tetsuo Handa3f629632010-06-03 20:37:26 +0900426 const char *const start = string;
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900427 bool in_repetition = false;
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900428 unsigned char c;
429 unsigned char d;
430 unsigned char e;
Tetsuo Handa3f629632010-06-03 20:37:26 +0900431 if (!len)
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900432 goto out;
Tetsuo Handa3f629632010-06-03 20:37:26 +0900433 while (len--) {
434 c = *string++;
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900435 if (c == '\\') {
Tetsuo Handa3f629632010-06-03 20:37:26 +0900436 if (!len--)
437 goto out;
438 c = *string++;
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900439 switch (c) {
440 case '\\': /* "\\" */
441 continue;
442 case '$': /* "\$" */
443 case '+': /* "\+" */
444 case '?': /* "\?" */
445 case '*': /* "\*" */
446 case '@': /* "\@" */
447 case 'x': /* "\x" */
448 case 'X': /* "\X" */
449 case 'a': /* "\a" */
450 case 'A': /* "\A" */
451 case '-': /* "\-" */
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900452 continue;
453 case '{': /* "/\{" */
Tetsuo Handa3f629632010-06-03 20:37:26 +0900454 if (string - 3 < start || *(string - 3) != '/')
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900455 break;
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900456 in_repetition = true;
457 continue;
458 case '}': /* "\}/" */
Tetsuo Handa3f629632010-06-03 20:37:26 +0900459 if (*string != '/')
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900460 break;
461 if (!in_repetition)
462 break;
463 in_repetition = false;
464 continue;
465 case '0': /* "\ooo" */
466 case '1':
467 case '2':
468 case '3':
Tetsuo Handa3f629632010-06-03 20:37:26 +0900469 if (!len-- || !len--)
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900470 break;
Tetsuo Handa3f629632010-06-03 20:37:26 +0900471 d = *string++;
472 e = *string++;
473 if (d < '0' || d > '7' || e < '0' || e > '7')
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900474 break;
475 c = tomoyo_make_byte(c, d, e);
Tetsuo Handa25add8c2012-01-15 11:05:59 +0900476 if (c <= ' ' || c >= 127)
477 continue;
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900478 }
479 goto out;
480 } else if (in_repetition && c == '/') {
481 goto out;
Tetsuo Handa25add8c2012-01-15 11:05:59 +0900482 } else if (c <= ' ' || c >= 127) {
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900483 goto out;
484 }
485 }
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900486 if (in_repetition)
487 goto out;
488 return true;
489 out:
490 return false;
491}
492
493/**
Tetsuo Handa75093152010-06-16 16:23:55 +0900494 * tomoyo_correct_word - Validate a string.
Tetsuo Handa3f629632010-06-03 20:37:26 +0900495 *
496 * @string: The string to check.
497 *
498 * Check whether the given string follows the naming rules.
499 * Returns true if @string follows the naming rules, false otherwise.
500 */
Tetsuo Handa75093152010-06-16 16:23:55 +0900501bool tomoyo_correct_word(const char *string)
Tetsuo Handa3f629632010-06-03 20:37:26 +0900502{
Tetsuo Handa75093152010-06-16 16:23:55 +0900503 return tomoyo_correct_word2(string, strlen(string));
Tetsuo Handa3f629632010-06-03 20:37:26 +0900504}
505
506/**
Tetsuo Handa75093152010-06-16 16:23:55 +0900507 * tomoyo_correct_path - Validate a pathname.
Tetsuo Handa3f629632010-06-03 20:37:26 +0900508 *
509 * @filename: The pathname to check.
510 *
511 * Check whether the given pathname follows the naming rules.
512 * Returns true if @filename follows the naming rules, false otherwise.
513 */
Tetsuo Handa75093152010-06-16 16:23:55 +0900514bool tomoyo_correct_path(const char *filename)
Tetsuo Handa3f629632010-06-03 20:37:26 +0900515{
Tetsuo Handa75093152010-06-16 16:23:55 +0900516 return *filename == '/' && tomoyo_correct_word(filename);
Tetsuo Handa3f629632010-06-03 20:37:26 +0900517}
518
519/**
Tetsuo Handa75093152010-06-16 16:23:55 +0900520 * tomoyo_correct_domain - Check whether the given domainname follows the naming rules.
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900521 *
Tetsuo Handa3f629632010-06-03 20:37:26 +0900522 * @domainname: The domainname to check.
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900523 *
524 * Returns true if @domainname follows the naming rules, false otherwise.
525 */
Tetsuo Handa75093152010-06-16 16:23:55 +0900526bool tomoyo_correct_domain(const unsigned char *domainname)
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900527{
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900528 if (!domainname || !tomoyo_domain_def(domainname))
529 return false;
530 domainname = strchr(domainname, ' ');
531 if (!domainname++)
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900532 return true;
Tetsuo Handa3f629632010-06-03 20:37:26 +0900533 while (1) {
534 const unsigned char *cp = strchr(domainname, ' ');
535 if (!cp)
536 break;
537 if (*domainname != '/' ||
Tetsuo Handae77dc342011-05-12 06:40:51 +0900538 !tomoyo_correct_word2(domainname, cp - domainname))
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900539 return false;
Tetsuo Handa3f629632010-06-03 20:37:26 +0900540 domainname = cp + 1;
541 }
Tetsuo Handa75093152010-06-16 16:23:55 +0900542 return tomoyo_correct_path(domainname);
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900543}
544
545/**
Tetsuo Handa75093152010-06-16 16:23:55 +0900546 * tomoyo_domain_def - Check whether the given token can be a domainname.
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900547 *
548 * @buffer: The token to check.
549 *
550 * Returns true if @buffer possibly be a domainname, false otherwise.
551 */
Tetsuo Handa75093152010-06-16 16:23:55 +0900552bool tomoyo_domain_def(const unsigned char *buffer)
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900553{
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900554 const unsigned char *cp;
555 int len;
556 if (*buffer != '<')
557 return false;
558 cp = strchr(buffer, ' ');
559 if (!cp)
560 len = strlen(buffer);
561 else
562 len = cp - buffer;
563 if (buffer[len - 1] != '>' ||
564 !tomoyo_correct_word2(buffer + 1, len - 2))
565 return false;
566 return true;
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900567}
568
569/**
570 * tomoyo_find_domain - Find a domain by the given name.
571 *
572 * @domainname: The domainname to find.
573 *
574 * Returns pointer to "struct tomoyo_domain_info" if found, NULL otherwise.
575 *
576 * Caller holds tomoyo_read_lock().
577 */
578struct tomoyo_domain_info *tomoyo_find_domain(const char *domainname)
579{
580 struct tomoyo_domain_info *domain;
581 struct tomoyo_path_info name;
582
583 name.name = domainname;
584 tomoyo_fill_path_info(&name);
585 list_for_each_entry_rcu(domain, &tomoyo_domain_list, list) {
586 if (!domain->is_deleted &&
587 !tomoyo_pathcmp(&name, domain->domainname))
588 return domain;
589 }
590 return NULL;
591}
592
593/**
594 * tomoyo_const_part_length - Evaluate the initial length without a pattern in a token.
595 *
596 * @filename: The string to evaluate.
597 *
598 * Returns the initial length without a pattern in @filename.
599 */
600static int tomoyo_const_part_length(const char *filename)
601{
602 char c;
603 int len = 0;
604
605 if (!filename)
606 return 0;
607 while ((c = *filename++) != '\0') {
608 if (c != '\\') {
609 len++;
610 continue;
611 }
612 c = *filename++;
613 switch (c) {
614 case '\\': /* "\\" */
615 len += 2;
616 continue;
617 case '0': /* "\ooo" */
618 case '1':
619 case '2':
620 case '3':
621 c = *filename++;
622 if (c < '0' || c > '7')
623 break;
624 c = *filename++;
625 if (c < '0' || c > '7')
626 break;
627 len += 4;
628 continue;
629 }
630 break;
631 }
632 return len;
633}
634
635/**
636 * tomoyo_fill_path_info - Fill in "struct tomoyo_path_info" members.
637 *
638 * @ptr: Pointer to "struct tomoyo_path_info" to fill in.
639 *
640 * The caller sets "struct tomoyo_path_info"->name.
641 */
642void tomoyo_fill_path_info(struct tomoyo_path_info *ptr)
643{
644 const char *name = ptr->name;
645 const int len = strlen(name);
646
647 ptr->const_len = tomoyo_const_part_length(name);
648 ptr->is_dir = len && (name[len - 1] == '/');
649 ptr->is_patterned = (ptr->const_len < len);
Linus Torvalds8387ff22016-06-10 07:51:30 -0700650 ptr->hash = full_name_hash(NULL, name, len);
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900651}
652
653/**
654 * tomoyo_file_matches_pattern2 - Pattern matching without '/' character and "\-" pattern.
655 *
656 * @filename: The start of string to check.
657 * @filename_end: The end of string to check.
658 * @pattern: The start of pattern to compare.
659 * @pattern_end: The end of pattern to compare.
660 *
661 * Returns true if @filename matches @pattern, false otherwise.
662 */
663static bool tomoyo_file_matches_pattern2(const char *filename,
664 const char *filename_end,
665 const char *pattern,
666 const char *pattern_end)
667{
668 while (filename < filename_end && pattern < pattern_end) {
669 char c;
670 if (*pattern != '\\') {
671 if (*filename++ != *pattern++)
672 return false;
673 continue;
674 }
675 c = *filename;
676 pattern++;
677 switch (*pattern) {
678 int i;
679 int j;
680 case '?':
681 if (c == '/') {
682 return false;
683 } else if (c == '\\') {
684 if (filename[1] == '\\')
685 filename++;
Tetsuo Handa75093152010-06-16 16:23:55 +0900686 else if (tomoyo_byte_range(filename + 1))
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900687 filename += 3;
688 else
689 return false;
690 }
691 break;
692 case '\\':
693 if (c != '\\')
694 return false;
695 if (*++filename != '\\')
696 return false;
697 break;
698 case '+':
699 if (!isdigit(c))
700 return false;
701 break;
702 case 'x':
703 if (!isxdigit(c))
704 return false;
705 break;
706 case 'a':
Tetsuo Handa75093152010-06-16 16:23:55 +0900707 if (!tomoyo_alphabet_char(c))
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900708 return false;
709 break;
710 case '0':
711 case '1':
712 case '2':
713 case '3':
Tetsuo Handa75093152010-06-16 16:23:55 +0900714 if (c == '\\' && tomoyo_byte_range(filename + 1)
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900715 && strncmp(filename + 1, pattern, 3) == 0) {
716 filename += 3;
717 pattern += 2;
718 break;
719 }
720 return false; /* Not matched. */
721 case '*':
722 case '@':
723 for (i = 0; i <= filename_end - filename; i++) {
724 if (tomoyo_file_matches_pattern2(
725 filename + i, filename_end,
726 pattern + 1, pattern_end))
727 return true;
728 c = filename[i];
729 if (c == '.' && *pattern == '@')
730 break;
731 if (c != '\\')
732 continue;
733 if (filename[i + 1] == '\\')
734 i++;
Tetsuo Handa75093152010-06-16 16:23:55 +0900735 else if (tomoyo_byte_range(filename + i + 1))
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900736 i += 3;
737 else
738 break; /* Bad pattern. */
739 }
740 return false; /* Not matched. */
741 default:
742 j = 0;
743 c = *pattern;
744 if (c == '$') {
745 while (isdigit(filename[j]))
746 j++;
747 } else if (c == 'X') {
748 while (isxdigit(filename[j]))
749 j++;
750 } else if (c == 'A') {
Tetsuo Handa75093152010-06-16 16:23:55 +0900751 while (tomoyo_alphabet_char(filename[j]))
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900752 j++;
753 }
754 for (i = 1; i <= j; i++) {
755 if (tomoyo_file_matches_pattern2(
756 filename + i, filename_end,
757 pattern + 1, pattern_end))
758 return true;
759 }
760 return false; /* Not matched or bad pattern. */
761 }
762 filename++;
763 pattern++;
764 }
765 while (*pattern == '\\' &&
766 (*(pattern + 1) == '*' || *(pattern + 1) == '@'))
767 pattern += 2;
768 return filename == filename_end && pattern == pattern_end;
769}
770
771/**
772 * tomoyo_file_matches_pattern - Pattern matching without '/' character.
773 *
774 * @filename: The start of string to check.
775 * @filename_end: The end of string to check.
776 * @pattern: The start of pattern to compare.
777 * @pattern_end: The end of pattern to compare.
778 *
779 * Returns true if @filename matches @pattern, false otherwise.
780 */
781static bool tomoyo_file_matches_pattern(const char *filename,
782 const char *filename_end,
783 const char *pattern,
784 const char *pattern_end)
785{
786 const char *pattern_start = pattern;
787 bool first = true;
788 bool result;
789
790 while (pattern < pattern_end - 1) {
791 /* Split at "\-" pattern. */
792 if (*pattern++ != '\\' || *pattern++ != '-')
793 continue;
794 result = tomoyo_file_matches_pattern2(filename,
795 filename_end,
796 pattern_start,
797 pattern - 2);
798 if (first)
799 result = !result;
800 if (result)
801 return false;
802 first = false;
803 pattern_start = pattern;
804 }
805 result = tomoyo_file_matches_pattern2(filename, filename_end,
806 pattern_start, pattern_end);
807 return first ? result : !result;
808}
809
810/**
811 * tomoyo_path_matches_pattern2 - Do pathname pattern matching.
812 *
813 * @f: The start of string to check.
814 * @p: The start of pattern to compare.
815 *
816 * Returns true if @f matches @p, false otherwise.
817 */
818static bool tomoyo_path_matches_pattern2(const char *f, const char *p)
819{
820 const char *f_delimiter;
821 const char *p_delimiter;
822
823 while (*f && *p) {
824 f_delimiter = strchr(f, '/');
825 if (!f_delimiter)
826 f_delimiter = f + strlen(f);
827 p_delimiter = strchr(p, '/');
828 if (!p_delimiter)
829 p_delimiter = p + strlen(p);
830 if (*p == '\\' && *(p + 1) == '{')
831 goto recursive;
832 if (!tomoyo_file_matches_pattern(f, f_delimiter, p,
833 p_delimiter))
834 return false;
835 f = f_delimiter;
836 if (*f)
837 f++;
838 p = p_delimiter;
839 if (*p)
840 p++;
841 }
842 /* Ignore trailing "\*" and "\@" in @pattern. */
843 while (*p == '\\' &&
844 (*(p + 1) == '*' || *(p + 1) == '@'))
845 p += 2;
846 return !*f && !*p;
847 recursive:
848 /*
849 * The "\{" pattern is permitted only after '/' character.
850 * This guarantees that below "*(p - 1)" is safe.
851 * Also, the "\}" pattern is permitted only before '/' character
852 * so that "\{" + "\}" pair will not break the "\-" operator.
853 */
854 if (*(p - 1) != '/' || p_delimiter <= p + 3 || *p_delimiter != '/' ||
855 *(p_delimiter - 1) != '}' || *(p_delimiter - 2) != '\\')
856 return false; /* Bad pattern. */
857 do {
858 /* Compare current component with pattern. */
859 if (!tomoyo_file_matches_pattern(f, f_delimiter, p + 2,
860 p_delimiter - 2))
861 break;
862 /* Proceed to next component. */
863 f = f_delimiter;
864 if (!*f)
865 break;
866 f++;
867 /* Continue comparison. */
868 if (tomoyo_path_matches_pattern2(f, p_delimiter + 1))
869 return true;
870 f_delimiter = strchr(f, '/');
871 } while (f_delimiter);
872 return false; /* Not matched. */
873}
874
875/**
876 * tomoyo_path_matches_pattern - Check whether the given filename matches the given pattern.
877 *
878 * @filename: The filename to check.
879 * @pattern: The pattern to compare.
880 *
881 * Returns true if matches, false otherwise.
882 *
883 * The following patterns are available.
884 * \\ \ itself.
885 * \ooo Octal representation of a byte.
886 * \* Zero or more repetitions of characters other than '/'.
887 * \@ Zero or more repetitions of characters other than '/' or '.'.
888 * \? 1 byte character other than '/'.
889 * \$ One or more repetitions of decimal digits.
890 * \+ 1 decimal digit.
891 * \X One or more repetitions of hexadecimal digits.
892 * \x 1 hexadecimal digit.
893 * \A One or more repetitions of alphabet characters.
894 * \a 1 alphabet character.
895 *
896 * \- Subtraction operator.
897 *
898 * /\{dir\}/ '/' + 'One or more repetitions of dir/' (e.g. /dir/ /dir/dir/
899 * /dir/dir/dir/ ).
900 */
901bool tomoyo_path_matches_pattern(const struct tomoyo_path_info *filename,
902 const struct tomoyo_path_info *pattern)
903{
904 const char *f = filename->name;
905 const char *p = pattern->name;
906 const int len = pattern->const_len;
907
908 /* If @pattern doesn't contain pattern, I can use strcmp(). */
909 if (!pattern->is_patterned)
910 return !tomoyo_pathcmp(filename, pattern);
911 /* Don't compare directory and non-directory. */
912 if (filename->is_dir != pattern->is_dir)
913 return false;
914 /* Compare the initial length without patterns. */
915 if (strncmp(f, p, len))
916 return false;
917 f += len;
918 p += len;
919 return tomoyo_path_matches_pattern2(f, p);
920}
921
922/**
923 * tomoyo_get_exe - Get tomoyo_realpath() of current process.
924 *
925 * Returns the tomoyo_realpath() of current process on success, NULL otherwise.
926 *
927 * This function uses kzalloc(), so the caller must call kfree()
928 * if this function didn't return NULL.
929 */
930const char *tomoyo_get_exe(void)
931{
Davidlohr Buesod4144ea2015-04-16 12:49:18 -0700932 struct file *exe_file;
933 const char *cp;
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900934 struct mm_struct *mm = current->mm;
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900935
936 if (!mm)
937 return NULL;
Davidlohr Buesod4144ea2015-04-16 12:49:18 -0700938 exe_file = get_mm_exe_file(mm);
939 if (!exe_file)
940 return NULL;
941
942 cp = tomoyo_realpath_from_path(&exe_file->f_path);
943 fput(exe_file);
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900944 return cp;
945}
946
947/**
Tetsuo Handa57c25902010-06-03 20:38:44 +0900948 * tomoyo_get_mode - Get MAC mode.
949 *
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900950 * @ns: Pointer to "struct tomoyo_policy_namespace".
Tetsuo Handa57c25902010-06-03 20:38:44 +0900951 * @profile: Profile number.
952 * @index: Index number of functionality.
953 *
954 * Returns mode.
955 */
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900956int tomoyo_get_mode(const struct tomoyo_policy_namespace *ns, const u8 profile,
957 const u8 index)
Tetsuo Handa57c25902010-06-03 20:38:44 +0900958{
959 u8 mode;
Tetsuo Handad58e0da2011-09-10 15:22:48 +0900960 struct tomoyo_profile *p;
961
Tetsuo Handa57c25902010-06-03 20:38:44 +0900962 if (!tomoyo_policy_loaded)
963 return TOMOYO_CONFIG_DISABLED;
Tetsuo Handad58e0da2011-09-10 15:22:48 +0900964 p = tomoyo_profile(ns, profile);
965 mode = p->config[index];
Tetsuo Handa57c25902010-06-03 20:38:44 +0900966 if (mode == TOMOYO_CONFIG_USE_DEFAULT)
Tetsuo Handad58e0da2011-09-10 15:22:48 +0900967 mode = p->config[tomoyo_index2category[index]
968 + TOMOYO_MAX_MAC_INDEX];
Tetsuo Handa57c25902010-06-03 20:38:44 +0900969 if (mode == TOMOYO_CONFIG_USE_DEFAULT)
Tetsuo Handad58e0da2011-09-10 15:22:48 +0900970 mode = p->default_config;
Tetsuo Handa57c25902010-06-03 20:38:44 +0900971 return mode & 3;
972}
973
974/**
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900975 * tomoyo_init_request_info - Initialize "struct tomoyo_request_info" members.
976 *
977 * @r: Pointer to "struct tomoyo_request_info" to initialize.
978 * @domain: Pointer to "struct tomoyo_domain_info". NULL for tomoyo_domain().
Tetsuo Handa57c25902010-06-03 20:38:44 +0900979 * @index: Index number of functionality.
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900980 *
981 * Returns mode.
982 */
983int tomoyo_init_request_info(struct tomoyo_request_info *r,
Tetsuo Handa57c25902010-06-03 20:38:44 +0900984 struct tomoyo_domain_info *domain, const u8 index)
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900985{
Tetsuo Handa57c25902010-06-03 20:38:44 +0900986 u8 profile;
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900987 memset(r, 0, sizeof(*r));
988 if (!domain)
989 domain = tomoyo_domain();
990 r->domain = domain;
Tetsuo Handa57c25902010-06-03 20:38:44 +0900991 profile = domain->profile;
992 r->profile = profile;
993 r->type = index;
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900994 r->mode = tomoyo_get_mode(domain->ns, profile, index);
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900995 return r->mode;
996}
997
998/**
Tetsuo Handac3ef1502010-05-17 10:12:46 +0900999 * tomoyo_domain_quota_is_ok - Check for domain's quota.
1000 *
1001 * @r: Pointer to "struct tomoyo_request_info".
1002 *
1003 * Returns true if the domain is not exceeded quota, false otherwise.
1004 *
1005 * Caller holds tomoyo_read_lock().
1006 */
1007bool tomoyo_domain_quota_is_ok(struct tomoyo_request_info *r)
1008{
1009 unsigned int count = 0;
1010 struct tomoyo_domain_info *domain = r->domain;
1011 struct tomoyo_acl_info *ptr;
1012
1013 if (r->mode != TOMOYO_CONFIG_LEARNING)
1014 return false;
1015 if (!domain)
1016 return true;
1017 list_for_each_entry_rcu(ptr, &domain->acl_info_list, list) {
Tetsuo Handa7c759642011-06-26 23:15:31 +09001018 u16 perm;
1019 u8 i;
Tetsuo Handa7e3d1992010-07-27 10:08:29 +09001020 if (ptr->is_deleted)
Tetsuo Handa237ab452010-06-12 20:46:22 +09001021 continue;
Tetsuo Handac3ef1502010-05-17 10:12:46 +09001022 switch (ptr->type) {
Tetsuo Handac3ef1502010-05-17 10:12:46 +09001023 case TOMOYO_TYPE_PATH_ACL:
1024 perm = container_of(ptr, struct tomoyo_path_acl, head)
1025 ->perm;
Tetsuo Handac3ef1502010-05-17 10:12:46 +09001026 break;
1027 case TOMOYO_TYPE_PATH2_ACL:
1028 perm = container_of(ptr, struct tomoyo_path2_acl, head)
1029 ->perm;
Tetsuo Handac3ef1502010-05-17 10:12:46 +09001030 break;
1031 case TOMOYO_TYPE_PATH_NUMBER_ACL:
1032 perm = container_of(ptr, struct tomoyo_path_number_acl,
1033 head)->perm;
Tetsuo Handac3ef1502010-05-17 10:12:46 +09001034 break;
Tetsuo Handa75093152010-06-16 16:23:55 +09001035 case TOMOYO_TYPE_MKDEV_ACL:
1036 perm = container_of(ptr, struct tomoyo_mkdev_acl,
Tetsuo Handac3ef1502010-05-17 10:12:46 +09001037 head)->perm;
Tetsuo Handac3ef1502010-05-17 10:12:46 +09001038 break;
Tetsuo Handa545a7262011-10-11 14:06:41 +09001039 case TOMOYO_TYPE_INET_ACL:
1040 perm = container_of(ptr, struct tomoyo_inet_acl,
1041 head)->perm;
1042 break;
1043 case TOMOYO_TYPE_UNIX_ACL:
1044 perm = container_of(ptr, struct tomoyo_unix_acl,
1045 head)->perm;
1046 break;
1047 case TOMOYO_TYPE_MANUAL_TASK_ACL:
1048 perm = 0;
1049 break;
Tetsuo Handa237ab452010-06-12 20:46:22 +09001050 default:
Tetsuo Handa7c759642011-06-26 23:15:31 +09001051 perm = 1;
Tetsuo Handac3ef1502010-05-17 10:12:46 +09001052 }
Tetsuo Handa7c759642011-06-26 23:15:31 +09001053 for (i = 0; i < 16; i++)
1054 if (perm & (1 << i))
1055 count++;
Tetsuo Handac3ef1502010-05-17 10:12:46 +09001056 }
Tetsuo Handabd03a3e2011-06-26 23:19:52 +09001057 if (count < tomoyo_profile(domain->ns, domain->profile)->
Tetsuo Handad5ca1722011-06-26 23:18:21 +09001058 pref[TOMOYO_PREF_MAX_LEARNING_ENTRY])
Tetsuo Handac3ef1502010-05-17 10:12:46 +09001059 return true;
Tetsuo Handa2c47ab92011-06-26 23:21:19 +09001060 if (!domain->flags[TOMOYO_DIF_QUOTA_WARNED]) {
1061 domain->flags[TOMOYO_DIF_QUOTA_WARNED] = true;
1062 /* r->granted = false; */
1063 tomoyo_write_log(r, "%s", tomoyo_dif[TOMOYO_DIF_QUOTA_WARNED]);
1064 printk(KERN_WARNING "WARNING: "
Tetsuo Handad5ca1722011-06-26 23:18:21 +09001065 "Domain '%s' has too many ACLs to hold. "
Tetsuo Handac3ef1502010-05-17 10:12:46 +09001066 "Stopped learning mode.\n", domain->domainname->name);
1067 }
1068 return false;
1069}