Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 2 | /* |
| 3 | * security/tomoyo/util.c |
| 4 | * |
Tetsuo Handa | 0f2a55d | 2011-07-14 14:46:51 +0900 | [diff] [blame] | 5 | * Copyright (C) 2005-2011 NTT DATA CORPORATION |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <linux/slab.h> |
Ingo Molnar | b2d0910 | 2017-02-04 01:27:20 +0100 | [diff] [blame] | 9 | #include <linux/rculist.h> |
| 10 | |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 11 | #include "common.h" |
| 12 | |
| 13 | /* Lock for protecting policy. */ |
| 14 | DEFINE_MUTEX(tomoyo_policy_lock); |
| 15 | |
| 16 | /* Has /sbin/init started? */ |
| 17 | bool tomoyo_policy_loaded; |
| 18 | |
Tetsuo Handa | 2c47ab9 | 2011-06-26 23:21:19 +0900 | [diff] [blame] | 19 | /* |
| 20 | * Mapping table from "enum tomoyo_mac_index" to |
| 21 | * "enum tomoyo_mac_category_index". |
| 22 | */ |
| 23 | const u8 tomoyo_index2category[TOMOYO_MAX_MAC_INDEX] = { |
| 24 | /* CONFIG::file group */ |
| 25 | [TOMOYO_MAC_FILE_EXECUTE] = TOMOYO_MAC_CATEGORY_FILE, |
| 26 | [TOMOYO_MAC_FILE_OPEN] = TOMOYO_MAC_CATEGORY_FILE, |
| 27 | [TOMOYO_MAC_FILE_CREATE] = TOMOYO_MAC_CATEGORY_FILE, |
| 28 | [TOMOYO_MAC_FILE_UNLINK] = TOMOYO_MAC_CATEGORY_FILE, |
| 29 | [TOMOYO_MAC_FILE_GETATTR] = TOMOYO_MAC_CATEGORY_FILE, |
| 30 | [TOMOYO_MAC_FILE_MKDIR] = TOMOYO_MAC_CATEGORY_FILE, |
| 31 | [TOMOYO_MAC_FILE_RMDIR] = TOMOYO_MAC_CATEGORY_FILE, |
| 32 | [TOMOYO_MAC_FILE_MKFIFO] = TOMOYO_MAC_CATEGORY_FILE, |
| 33 | [TOMOYO_MAC_FILE_MKSOCK] = TOMOYO_MAC_CATEGORY_FILE, |
| 34 | [TOMOYO_MAC_FILE_TRUNCATE] = TOMOYO_MAC_CATEGORY_FILE, |
| 35 | [TOMOYO_MAC_FILE_SYMLINK] = TOMOYO_MAC_CATEGORY_FILE, |
| 36 | [TOMOYO_MAC_FILE_MKBLOCK] = TOMOYO_MAC_CATEGORY_FILE, |
| 37 | [TOMOYO_MAC_FILE_MKCHAR] = TOMOYO_MAC_CATEGORY_FILE, |
| 38 | [TOMOYO_MAC_FILE_LINK] = TOMOYO_MAC_CATEGORY_FILE, |
| 39 | [TOMOYO_MAC_FILE_RENAME] = TOMOYO_MAC_CATEGORY_FILE, |
| 40 | [TOMOYO_MAC_FILE_CHMOD] = TOMOYO_MAC_CATEGORY_FILE, |
| 41 | [TOMOYO_MAC_FILE_CHOWN] = TOMOYO_MAC_CATEGORY_FILE, |
| 42 | [TOMOYO_MAC_FILE_CHGRP] = TOMOYO_MAC_CATEGORY_FILE, |
| 43 | [TOMOYO_MAC_FILE_IOCTL] = TOMOYO_MAC_CATEGORY_FILE, |
| 44 | [TOMOYO_MAC_FILE_CHROOT] = TOMOYO_MAC_CATEGORY_FILE, |
| 45 | [TOMOYO_MAC_FILE_MOUNT] = TOMOYO_MAC_CATEGORY_FILE, |
| 46 | [TOMOYO_MAC_FILE_UMOUNT] = TOMOYO_MAC_CATEGORY_FILE, |
| 47 | [TOMOYO_MAC_FILE_PIVOT_ROOT] = TOMOYO_MAC_CATEGORY_FILE, |
Tetsuo Handa | 059d84d | 2011-09-10 15:23:54 +0900 | [diff] [blame] | 48 | /* CONFIG::network group */ |
| 49 | [TOMOYO_MAC_NETWORK_INET_STREAM_BIND] = |
| 50 | TOMOYO_MAC_CATEGORY_NETWORK, |
| 51 | [TOMOYO_MAC_NETWORK_INET_STREAM_LISTEN] = |
| 52 | TOMOYO_MAC_CATEGORY_NETWORK, |
| 53 | [TOMOYO_MAC_NETWORK_INET_STREAM_CONNECT] = |
| 54 | TOMOYO_MAC_CATEGORY_NETWORK, |
| 55 | [TOMOYO_MAC_NETWORK_INET_DGRAM_BIND] = |
| 56 | TOMOYO_MAC_CATEGORY_NETWORK, |
| 57 | [TOMOYO_MAC_NETWORK_INET_DGRAM_SEND] = |
| 58 | TOMOYO_MAC_CATEGORY_NETWORK, |
| 59 | [TOMOYO_MAC_NETWORK_INET_RAW_BIND] = |
| 60 | TOMOYO_MAC_CATEGORY_NETWORK, |
| 61 | [TOMOYO_MAC_NETWORK_INET_RAW_SEND] = |
| 62 | TOMOYO_MAC_CATEGORY_NETWORK, |
| 63 | [TOMOYO_MAC_NETWORK_UNIX_STREAM_BIND] = |
| 64 | TOMOYO_MAC_CATEGORY_NETWORK, |
| 65 | [TOMOYO_MAC_NETWORK_UNIX_STREAM_LISTEN] = |
| 66 | TOMOYO_MAC_CATEGORY_NETWORK, |
| 67 | [TOMOYO_MAC_NETWORK_UNIX_STREAM_CONNECT] = |
| 68 | TOMOYO_MAC_CATEGORY_NETWORK, |
| 69 | [TOMOYO_MAC_NETWORK_UNIX_DGRAM_BIND] = |
| 70 | TOMOYO_MAC_CATEGORY_NETWORK, |
| 71 | [TOMOYO_MAC_NETWORK_UNIX_DGRAM_SEND] = |
| 72 | TOMOYO_MAC_CATEGORY_NETWORK, |
| 73 | [TOMOYO_MAC_NETWORK_UNIX_SEQPACKET_BIND] = |
| 74 | TOMOYO_MAC_CATEGORY_NETWORK, |
| 75 | [TOMOYO_MAC_NETWORK_UNIX_SEQPACKET_LISTEN] = |
| 76 | TOMOYO_MAC_CATEGORY_NETWORK, |
| 77 | [TOMOYO_MAC_NETWORK_UNIX_SEQPACKET_CONNECT] = |
| 78 | TOMOYO_MAC_CATEGORY_NETWORK, |
Tetsuo Handa | d58e0da | 2011-09-10 15:22:48 +0900 | [diff] [blame] | 79 | /* CONFIG::misc group */ |
| 80 | [TOMOYO_MAC_ENVIRON] = TOMOYO_MAC_CATEGORY_MISC, |
Tetsuo Handa | 2c47ab9 | 2011-06-26 23:21:19 +0900 | [diff] [blame] | 81 | }; |
| 82 | |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 83 | /** |
Tetsuo Handa | b22b8b9 | 2011-06-26 23:21:50 +0900 | [diff] [blame] | 84 | * tomoyo_convert_time - Convert time_t to YYYY/MM/DD hh/mm/ss. |
| 85 | * |
| 86 | * @time: Seconds since 1970/01/01 00:00:00. |
| 87 | * @stamp: Pointer to "struct tomoyo_time". |
| 88 | * |
| 89 | * Returns nothing. |
Tetsuo Handa | b22b8b9 | 2011-06-26 23:21:50 +0900 | [diff] [blame] | 90 | */ |
Arnd Bergmann | 9273409 | 2017-10-19 14:29:04 +0200 | [diff] [blame] | 91 | void tomoyo_convert_time(time64_t time64, struct tomoyo_time *stamp) |
Tetsuo Handa | b22b8b9 | 2011-06-26 23:21:50 +0900 | [diff] [blame] | 92 | { |
Arnd Bergmann | 9273409 | 2017-10-19 14:29:04 +0200 | [diff] [blame] | 93 | struct tm tm; |
Tetsuo Handa | cdcf672 | 2019-01-24 18:37:35 +0900 | [diff] [blame] | 94 | |
Arnd Bergmann | 9273409 | 2017-10-19 14:29:04 +0200 | [diff] [blame] | 95 | time64_to_tm(time64, 0, &tm); |
| 96 | stamp->sec = tm.tm_sec; |
| 97 | stamp->min = tm.tm_min; |
| 98 | stamp->hour = tm.tm_hour; |
| 99 | stamp->day = tm.tm_mday; |
| 100 | stamp->month = tm.tm_mon + 1; |
| 101 | stamp->year = tm.tm_year + 1900; |
Tetsuo Handa | b22b8b9 | 2011-06-26 23:21:50 +0900 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | /** |
Tetsuo Handa | a238cf5 | 2011-06-26 23:17:10 +0900 | [diff] [blame] | 105 | * tomoyo_permstr - Find permission keywords. |
| 106 | * |
| 107 | * @string: String representation for permissions in foo/bar/buz format. |
| 108 | * @keyword: Keyword to find from @string/ |
| 109 | * |
Yangtao Li | f09c296 | 2018-11-01 11:55:08 -0400 | [diff] [blame] | 110 | * Returns true if @keyword was found in @string, false otherwise. |
Tetsuo Handa | a238cf5 | 2011-06-26 23:17:10 +0900 | [diff] [blame] | 111 | * |
| 112 | * This function assumes that strncmp(w1, w2, strlen(w1)) != 0 if w1 != w2. |
| 113 | */ |
| 114 | bool tomoyo_permstr(const char *string, const char *keyword) |
| 115 | { |
| 116 | const char *cp = strstr(string, keyword); |
Tetsuo Handa | cdcf672 | 2019-01-24 18:37:35 +0900 | [diff] [blame] | 117 | |
Tetsuo Handa | a238cf5 | 2011-06-26 23:17:10 +0900 | [diff] [blame] | 118 | if (cp) |
| 119 | return cp == string || *(cp - 1) == '/'; |
| 120 | return false; |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * tomoyo_read_token - Read a word from a line. |
| 125 | * |
| 126 | * @param: Pointer to "struct tomoyo_acl_param". |
| 127 | * |
| 128 | * Returns a word on success, "" otherwise. |
| 129 | * |
| 130 | * To allow the caller to skip NULL check, this function returns "" rather than |
| 131 | * NULL if there is no more words to read. |
| 132 | */ |
| 133 | char *tomoyo_read_token(struct tomoyo_acl_param *param) |
| 134 | { |
| 135 | char *pos = param->data; |
| 136 | char *del = strchr(pos, ' '); |
Tetsuo Handa | cdcf672 | 2019-01-24 18:37:35 +0900 | [diff] [blame] | 137 | |
Tetsuo Handa | a238cf5 | 2011-06-26 23:17:10 +0900 | [diff] [blame] | 138 | if (del) |
| 139 | *del++ = '\0'; |
| 140 | else |
| 141 | del = pos + strlen(pos); |
| 142 | param->data = del; |
| 143 | return pos; |
| 144 | } |
| 145 | |
Tetsuo Handa | a207516 | 2020-09-09 20:05:58 +0900 | [diff] [blame^] | 146 | static bool tomoyo_correct_path2(const char *filename, const size_t len); |
| 147 | |
Tetsuo Handa | a238cf5 | 2011-06-26 23:17:10 +0900 | [diff] [blame] | 148 | /** |
Tetsuo Handa | 731d37a | 2011-09-10 15:25:58 +0900 | [diff] [blame] | 149 | * tomoyo_get_domainname - Read a domainname from a line. |
| 150 | * |
| 151 | * @param: Pointer to "struct tomoyo_acl_param". |
| 152 | * |
| 153 | * Returns a domainname on success, NULL otherwise. |
| 154 | */ |
| 155 | const struct tomoyo_path_info *tomoyo_get_domainname |
| 156 | (struct tomoyo_acl_param *param) |
| 157 | { |
| 158 | char *start = param->data; |
| 159 | char *pos = start; |
Tetsuo Handa | cdcf672 | 2019-01-24 18:37:35 +0900 | [diff] [blame] | 160 | |
Tetsuo Handa | 731d37a | 2011-09-10 15:25:58 +0900 | [diff] [blame] | 161 | while (*pos) { |
Tetsuo Handa | a207516 | 2020-09-09 20:05:58 +0900 | [diff] [blame^] | 162 | if (*pos++ != ' ' || |
| 163 | tomoyo_correct_path2(pos, strchrnul(pos, ' ') - pos)) |
Tetsuo Handa | 731d37a | 2011-09-10 15:25:58 +0900 | [diff] [blame] | 164 | continue; |
Tetsuo Handa | a207516 | 2020-09-09 20:05:58 +0900 | [diff] [blame^] | 165 | *(pos - 1) = '\0'; |
Tetsuo Handa | 731d37a | 2011-09-10 15:25:58 +0900 | [diff] [blame] | 166 | break; |
| 167 | } |
| 168 | param->data = pos; |
| 169 | if (tomoyo_correct_domain(start)) |
| 170 | return tomoyo_get_name(start); |
| 171 | return NULL; |
| 172 | } |
| 173 | |
| 174 | /** |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 175 | * tomoyo_parse_ulong - Parse an "unsigned long" value. |
| 176 | * |
| 177 | * @result: Pointer to "unsigned long". |
| 178 | * @str: Pointer to string to parse. |
| 179 | * |
Tetsuo Handa | 0df7e8b | 2011-06-26 23:16:36 +0900 | [diff] [blame] | 180 | * Returns one of values in "enum tomoyo_value_type". |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 181 | * |
| 182 | * The @src is updated to point the first character after the value |
| 183 | * on success. |
| 184 | */ |
Tetsuo Handa | 2066a36 | 2011-07-08 13:21:37 +0900 | [diff] [blame] | 185 | u8 tomoyo_parse_ulong(unsigned long *result, char **str) |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 186 | { |
| 187 | const char *cp = *str; |
| 188 | char *ep; |
| 189 | int base = 10; |
Tetsuo Handa | cdcf672 | 2019-01-24 18:37:35 +0900 | [diff] [blame] | 190 | |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 191 | if (*cp == '0') { |
| 192 | char c = *(cp + 1); |
Tetsuo Handa | cdcf672 | 2019-01-24 18:37:35 +0900 | [diff] [blame] | 193 | |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 194 | if (c == 'x' || c == 'X') { |
| 195 | base = 16; |
| 196 | cp += 2; |
| 197 | } else if (c >= '0' && c <= '7') { |
| 198 | base = 8; |
| 199 | cp++; |
| 200 | } |
| 201 | } |
| 202 | *result = simple_strtoul(cp, &ep, base); |
| 203 | if (cp == ep) |
Tetsuo Handa | 0df7e8b | 2011-06-26 23:16:36 +0900 | [diff] [blame] | 204 | return TOMOYO_VALUE_TYPE_INVALID; |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 205 | *str = ep; |
| 206 | switch (base) { |
| 207 | case 16: |
| 208 | return TOMOYO_VALUE_TYPE_HEXADECIMAL; |
| 209 | case 8: |
| 210 | return TOMOYO_VALUE_TYPE_OCTAL; |
| 211 | default: |
| 212 | return TOMOYO_VALUE_TYPE_DECIMAL; |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | /** |
| 217 | * tomoyo_print_ulong - Print an "unsigned long" value. |
| 218 | * |
| 219 | * @buffer: Pointer to buffer. |
| 220 | * @buffer_len: Size of @buffer. |
| 221 | * @value: An "unsigned long" value. |
| 222 | * @type: Type of @value. |
| 223 | * |
| 224 | * Returns nothing. |
| 225 | */ |
| 226 | void tomoyo_print_ulong(char *buffer, const int buffer_len, |
| 227 | const unsigned long value, const u8 type) |
| 228 | { |
| 229 | if (type == TOMOYO_VALUE_TYPE_DECIMAL) |
| 230 | snprintf(buffer, buffer_len, "%lu", value); |
| 231 | else if (type == TOMOYO_VALUE_TYPE_OCTAL) |
| 232 | snprintf(buffer, buffer_len, "0%lo", value); |
| 233 | else if (type == TOMOYO_VALUE_TYPE_HEXADECIMAL) |
| 234 | snprintf(buffer, buffer_len, "0x%lX", value); |
| 235 | else |
| 236 | snprintf(buffer, buffer_len, "type(%u)", type); |
| 237 | } |
| 238 | |
| 239 | /** |
| 240 | * tomoyo_parse_name_union - Parse a tomoyo_name_union. |
| 241 | * |
Tetsuo Handa | a238cf5 | 2011-06-26 23:17:10 +0900 | [diff] [blame] | 242 | * @param: Pointer to "struct tomoyo_acl_param". |
| 243 | * @ptr: Pointer to "struct tomoyo_name_union". |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 244 | * |
| 245 | * Returns true on success, false otherwise. |
| 246 | */ |
Tetsuo Handa | a238cf5 | 2011-06-26 23:17:10 +0900 | [diff] [blame] | 247 | bool tomoyo_parse_name_union(struct tomoyo_acl_param *param, |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 248 | struct tomoyo_name_union *ptr) |
| 249 | { |
Tetsuo Handa | a238cf5 | 2011-06-26 23:17:10 +0900 | [diff] [blame] | 250 | char *filename; |
Tetsuo Handa | cdcf672 | 2019-01-24 18:37:35 +0900 | [diff] [blame] | 251 | |
Tetsuo Handa | a238cf5 | 2011-06-26 23:17:10 +0900 | [diff] [blame] | 252 | if (param->data[0] == '@') { |
| 253 | param->data++; |
| 254 | ptr->group = tomoyo_get_group(param, TOMOYO_PATH_GROUP); |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 255 | return ptr->group != NULL; |
| 256 | } |
Tetsuo Handa | a238cf5 | 2011-06-26 23:17:10 +0900 | [diff] [blame] | 257 | filename = tomoyo_read_token(param); |
| 258 | if (!tomoyo_correct_word(filename)) |
| 259 | return false; |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 260 | ptr->filename = tomoyo_get_name(filename); |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 261 | return ptr->filename != NULL; |
| 262 | } |
| 263 | |
| 264 | /** |
| 265 | * tomoyo_parse_number_union - Parse a tomoyo_number_union. |
| 266 | * |
Tetsuo Handa | a238cf5 | 2011-06-26 23:17:10 +0900 | [diff] [blame] | 267 | * @param: Pointer to "struct tomoyo_acl_param". |
| 268 | * @ptr: Pointer to "struct tomoyo_number_union". |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 269 | * |
| 270 | * Returns true on success, false otherwise. |
| 271 | */ |
Tetsuo Handa | a238cf5 | 2011-06-26 23:17:10 +0900 | [diff] [blame] | 272 | bool tomoyo_parse_number_union(struct tomoyo_acl_param *param, |
| 273 | struct tomoyo_number_union *ptr) |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 274 | { |
Tetsuo Handa | a238cf5 | 2011-06-26 23:17:10 +0900 | [diff] [blame] | 275 | char *data; |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 276 | u8 type; |
| 277 | unsigned long v; |
Tetsuo Handa | cdcf672 | 2019-01-24 18:37:35 +0900 | [diff] [blame] | 278 | |
Tetsuo Handa | a238cf5 | 2011-06-26 23:17:10 +0900 | [diff] [blame] | 279 | memset(ptr, 0, sizeof(*ptr)); |
| 280 | if (param->data[0] == '@') { |
| 281 | param->data++; |
| 282 | ptr->group = tomoyo_get_group(param, TOMOYO_NUMBER_GROUP); |
| 283 | return ptr->group != NULL; |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 284 | } |
Tetsuo Handa | a238cf5 | 2011-06-26 23:17:10 +0900 | [diff] [blame] | 285 | data = tomoyo_read_token(param); |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 286 | type = tomoyo_parse_ulong(&v, &data); |
Tetsuo Handa | a238cf5 | 2011-06-26 23:17:10 +0900 | [diff] [blame] | 287 | if (type == TOMOYO_VALUE_TYPE_INVALID) |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 288 | return false; |
Tetsuo Handa | a238cf5 | 2011-06-26 23:17:10 +0900 | [diff] [blame] | 289 | ptr->values[0] = v; |
| 290 | ptr->value_type[0] = type; |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 291 | if (!*data) { |
Tetsuo Handa | a238cf5 | 2011-06-26 23:17:10 +0900 | [diff] [blame] | 292 | ptr->values[1] = v; |
| 293 | ptr->value_type[1] = type; |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 294 | return true; |
| 295 | } |
| 296 | if (*data++ != '-') |
| 297 | return false; |
| 298 | type = tomoyo_parse_ulong(&v, &data); |
Tetsuo Handa | a238cf5 | 2011-06-26 23:17:10 +0900 | [diff] [blame] | 299 | if (type == TOMOYO_VALUE_TYPE_INVALID || *data || ptr->values[0] > v) |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 300 | return false; |
Tetsuo Handa | a238cf5 | 2011-06-26 23:17:10 +0900 | [diff] [blame] | 301 | ptr->values[1] = v; |
| 302 | ptr->value_type[1] = type; |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 303 | return true; |
| 304 | } |
| 305 | |
| 306 | /** |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 307 | * tomoyo_byte_range - Check whether the string is a \ooo style octal value. |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 308 | * |
| 309 | * @str: Pointer to the string. |
| 310 | * |
| 311 | * Returns true if @str is a \ooo style octal value, false otherwise. |
| 312 | * |
| 313 | * TOMOYO uses \ooo style representation for 0x01 - 0x20 and 0x7F - 0xFF. |
| 314 | * This function verifies that \ooo is in valid range. |
| 315 | */ |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 316 | static inline bool tomoyo_byte_range(const char *str) |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 317 | { |
| 318 | return *str >= '0' && *str++ <= '3' && |
| 319 | *str >= '0' && *str++ <= '7' && |
| 320 | *str >= '0' && *str <= '7'; |
| 321 | } |
| 322 | |
| 323 | /** |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 324 | * tomoyo_alphabet_char - Check whether the character is an alphabet. |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 325 | * |
| 326 | * @c: The character to check. |
| 327 | * |
| 328 | * Returns true if @c is an alphabet character, false otherwise. |
| 329 | */ |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 330 | static inline bool tomoyo_alphabet_char(const char c) |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 331 | { |
| 332 | return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'); |
| 333 | } |
| 334 | |
| 335 | /** |
| 336 | * tomoyo_make_byte - Make byte value from three octal characters. |
| 337 | * |
| 338 | * @c1: The first character. |
| 339 | * @c2: The second character. |
| 340 | * @c3: The third character. |
| 341 | * |
| 342 | * Returns byte value. |
| 343 | */ |
| 344 | static inline u8 tomoyo_make_byte(const u8 c1, const u8 c2, const u8 c3) |
| 345 | { |
| 346 | return ((c1 - '0') << 6) + ((c2 - '0') << 3) + (c3 - '0'); |
| 347 | } |
| 348 | |
| 349 | /** |
Tetsuo Handa | 0df7e8b | 2011-06-26 23:16:36 +0900 | [diff] [blame] | 350 | * tomoyo_valid - Check whether the character is a valid char. |
| 351 | * |
| 352 | * @c: The character to check. |
| 353 | * |
| 354 | * Returns true if @c is a valid character, false otherwise. |
| 355 | */ |
| 356 | static inline bool tomoyo_valid(const unsigned char c) |
| 357 | { |
| 358 | return c > ' ' && c < 127; |
| 359 | } |
| 360 | |
| 361 | /** |
| 362 | * tomoyo_invalid - Check whether the character is an invalid char. |
| 363 | * |
| 364 | * @c: The character to check. |
| 365 | * |
| 366 | * Returns true if @c is an invalid character, false otherwise. |
| 367 | */ |
| 368 | static inline bool tomoyo_invalid(const unsigned char c) |
| 369 | { |
| 370 | return c && (c <= ' ' || c >= 127); |
| 371 | } |
| 372 | |
| 373 | /** |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 374 | * tomoyo_str_starts - Check whether the given string starts with the given keyword. |
| 375 | * |
| 376 | * @src: Pointer to pointer to the string. |
| 377 | * @find: Pointer to the keyword. |
| 378 | * |
| 379 | * Returns true if @src starts with @find, false otherwise. |
| 380 | * |
| 381 | * The @src is updated to point the first character after the @find |
| 382 | * if @src starts with @find. |
| 383 | */ |
| 384 | bool tomoyo_str_starts(char **src, const char *find) |
| 385 | { |
| 386 | const int len = strlen(find); |
| 387 | char *tmp = *src; |
| 388 | |
| 389 | if (strncmp(tmp, find, len)) |
| 390 | return false; |
| 391 | tmp += len; |
| 392 | *src = tmp; |
| 393 | return true; |
| 394 | } |
| 395 | |
| 396 | /** |
| 397 | * tomoyo_normalize_line - Format string. |
| 398 | * |
| 399 | * @buffer: The line to normalize. |
| 400 | * |
| 401 | * Leading and trailing whitespaces are removed. |
| 402 | * Multiple whitespaces are packed into single space. |
| 403 | * |
| 404 | * Returns nothing. |
| 405 | */ |
| 406 | void tomoyo_normalize_line(unsigned char *buffer) |
| 407 | { |
| 408 | unsigned char *sp = buffer; |
| 409 | unsigned char *dp = buffer; |
| 410 | bool first = true; |
| 411 | |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 412 | while (tomoyo_invalid(*sp)) |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 413 | sp++; |
| 414 | while (*sp) { |
| 415 | if (!first) |
| 416 | *dp++ = ' '; |
| 417 | first = false; |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 418 | while (tomoyo_valid(*sp)) |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 419 | *dp++ = *sp++; |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 420 | while (tomoyo_invalid(*sp)) |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 421 | sp++; |
| 422 | } |
| 423 | *dp = '\0'; |
| 424 | } |
| 425 | |
| 426 | /** |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 427 | * tomoyo_correct_word2 - Validate a string. |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 428 | * |
Tetsuo Handa | 0f2a55d | 2011-07-14 14:46:51 +0900 | [diff] [blame] | 429 | * @string: The string to check. Maybe non-'\0'-terminated. |
Tetsuo Handa | 3f62963 | 2010-06-03 20:37:26 +0900 | [diff] [blame] | 430 | * @len: Length of @string. |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 431 | * |
Tetsuo Handa | 3f62963 | 2010-06-03 20:37:26 +0900 | [diff] [blame] | 432 | * Check whether the given string follows the naming rules. |
| 433 | * Returns true if @string follows the naming rules, false otherwise. |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 434 | */ |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 435 | static bool tomoyo_correct_word2(const char *string, size_t len) |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 436 | { |
Tetsuo Handa | 3f62963 | 2010-06-03 20:37:26 +0900 | [diff] [blame] | 437 | const char *const start = string; |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 438 | bool in_repetition = false; |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 439 | unsigned char c; |
| 440 | unsigned char d; |
| 441 | unsigned char e; |
Tetsuo Handa | cdcf672 | 2019-01-24 18:37:35 +0900 | [diff] [blame] | 442 | |
Tetsuo Handa | 3f62963 | 2010-06-03 20:37:26 +0900 | [diff] [blame] | 443 | if (!len) |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 444 | goto out; |
Tetsuo Handa | 3f62963 | 2010-06-03 20:37:26 +0900 | [diff] [blame] | 445 | while (len--) { |
| 446 | c = *string++; |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 447 | if (c == '\\') { |
Tetsuo Handa | 3f62963 | 2010-06-03 20:37:26 +0900 | [diff] [blame] | 448 | if (!len--) |
| 449 | goto out; |
| 450 | c = *string++; |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 451 | switch (c) { |
| 452 | case '\\': /* "\\" */ |
| 453 | continue; |
| 454 | case '$': /* "\$" */ |
| 455 | case '+': /* "\+" */ |
| 456 | case '?': /* "\?" */ |
| 457 | case '*': /* "\*" */ |
| 458 | case '@': /* "\@" */ |
| 459 | case 'x': /* "\x" */ |
| 460 | case 'X': /* "\X" */ |
| 461 | case 'a': /* "\a" */ |
| 462 | case 'A': /* "\A" */ |
| 463 | case '-': /* "\-" */ |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 464 | continue; |
| 465 | case '{': /* "/\{" */ |
Tetsuo Handa | 3f62963 | 2010-06-03 20:37:26 +0900 | [diff] [blame] | 466 | if (string - 3 < start || *(string - 3) != '/') |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 467 | break; |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 468 | in_repetition = true; |
| 469 | continue; |
| 470 | case '}': /* "\}/" */ |
Tetsuo Handa | 3f62963 | 2010-06-03 20:37:26 +0900 | [diff] [blame] | 471 | if (*string != '/') |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 472 | break; |
| 473 | if (!in_repetition) |
| 474 | break; |
| 475 | in_repetition = false; |
| 476 | continue; |
| 477 | case '0': /* "\ooo" */ |
| 478 | case '1': |
| 479 | case '2': |
| 480 | case '3': |
Tetsuo Handa | 3f62963 | 2010-06-03 20:37:26 +0900 | [diff] [blame] | 481 | if (!len-- || !len--) |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 482 | break; |
Tetsuo Handa | 3f62963 | 2010-06-03 20:37:26 +0900 | [diff] [blame] | 483 | d = *string++; |
| 484 | e = *string++; |
| 485 | if (d < '0' || d > '7' || e < '0' || e > '7') |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 486 | break; |
| 487 | c = tomoyo_make_byte(c, d, e); |
Tetsuo Handa | 25add8c | 2012-01-15 11:05:59 +0900 | [diff] [blame] | 488 | if (c <= ' ' || c >= 127) |
| 489 | continue; |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 490 | } |
| 491 | goto out; |
| 492 | } else if (in_repetition && c == '/') { |
| 493 | goto out; |
Tetsuo Handa | 25add8c | 2012-01-15 11:05:59 +0900 | [diff] [blame] | 494 | } else if (c <= ' ' || c >= 127) { |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 495 | goto out; |
| 496 | } |
| 497 | } |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 498 | if (in_repetition) |
| 499 | goto out; |
| 500 | return true; |
| 501 | out: |
| 502 | return false; |
| 503 | } |
| 504 | |
| 505 | /** |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 506 | * tomoyo_correct_word - Validate a string. |
Tetsuo Handa | 3f62963 | 2010-06-03 20:37:26 +0900 | [diff] [blame] | 507 | * |
| 508 | * @string: The string to check. |
| 509 | * |
| 510 | * Check whether the given string follows the naming rules. |
| 511 | * Returns true if @string follows the naming rules, false otherwise. |
| 512 | */ |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 513 | bool tomoyo_correct_word(const char *string) |
Tetsuo Handa | 3f62963 | 2010-06-03 20:37:26 +0900 | [diff] [blame] | 514 | { |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 515 | return tomoyo_correct_word2(string, strlen(string)); |
Tetsuo Handa | 3f62963 | 2010-06-03 20:37:26 +0900 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | /** |
Tetsuo Handa | a207516 | 2020-09-09 20:05:58 +0900 | [diff] [blame^] | 519 | * tomoyo_correct_path2 - Check whether the given pathname follows the naming rules. |
| 520 | * |
| 521 | * @filename: The pathname to check. |
| 522 | * @len: Length of @filename. |
| 523 | * |
| 524 | * Returns true if @filename follows the naming rules, false otherwise. |
| 525 | */ |
| 526 | static bool tomoyo_correct_path2(const char *filename, const size_t len) |
| 527 | { |
| 528 | const char *cp1 = memchr(filename, '/', len); |
| 529 | const char *cp2 = memchr(filename, '.', len); |
| 530 | |
| 531 | return cp1 && (!cp2 || (cp1 < cp2)) && tomoyo_correct_word2(filename, len); |
| 532 | } |
| 533 | |
| 534 | /** |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 535 | * tomoyo_correct_path - Validate a pathname. |
Tetsuo Handa | 3f62963 | 2010-06-03 20:37:26 +0900 | [diff] [blame] | 536 | * |
| 537 | * @filename: The pathname to check. |
| 538 | * |
| 539 | * Check whether the given pathname follows the naming rules. |
| 540 | * Returns true if @filename follows the naming rules, false otherwise. |
| 541 | */ |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 542 | bool tomoyo_correct_path(const char *filename) |
Tetsuo Handa | 3f62963 | 2010-06-03 20:37:26 +0900 | [diff] [blame] | 543 | { |
Tetsuo Handa | a207516 | 2020-09-09 20:05:58 +0900 | [diff] [blame^] | 544 | return tomoyo_correct_path2(filename, strlen(filename)); |
Tetsuo Handa | 3f62963 | 2010-06-03 20:37:26 +0900 | [diff] [blame] | 545 | } |
| 546 | |
| 547 | /** |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 548 | * tomoyo_correct_domain - Check whether the given domainname follows the naming rules. |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 549 | * |
Tetsuo Handa | 3f62963 | 2010-06-03 20:37:26 +0900 | [diff] [blame] | 550 | * @domainname: The domainname to check. |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 551 | * |
| 552 | * Returns true if @domainname follows the naming rules, false otherwise. |
| 553 | */ |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 554 | bool tomoyo_correct_domain(const unsigned char *domainname) |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 555 | { |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 556 | if (!domainname || !tomoyo_domain_def(domainname)) |
| 557 | return false; |
| 558 | domainname = strchr(domainname, ' '); |
| 559 | if (!domainname++) |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 560 | return true; |
Tetsuo Handa | 3f62963 | 2010-06-03 20:37:26 +0900 | [diff] [blame] | 561 | while (1) { |
| 562 | const unsigned char *cp = strchr(domainname, ' '); |
Tetsuo Handa | cdcf672 | 2019-01-24 18:37:35 +0900 | [diff] [blame] | 563 | |
Tetsuo Handa | 3f62963 | 2010-06-03 20:37:26 +0900 | [diff] [blame] | 564 | if (!cp) |
| 565 | break; |
Tetsuo Handa | a207516 | 2020-09-09 20:05:58 +0900 | [diff] [blame^] | 566 | if (!tomoyo_correct_path2(domainname, cp - domainname)) |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 567 | return false; |
Tetsuo Handa | 3f62963 | 2010-06-03 20:37:26 +0900 | [diff] [blame] | 568 | domainname = cp + 1; |
| 569 | } |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 570 | return tomoyo_correct_path(domainname); |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 571 | } |
| 572 | |
| 573 | /** |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 574 | * tomoyo_domain_def - Check whether the given token can be a domainname. |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 575 | * |
| 576 | * @buffer: The token to check. |
| 577 | * |
| 578 | * Returns true if @buffer possibly be a domainname, false otherwise. |
| 579 | */ |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 580 | bool tomoyo_domain_def(const unsigned char *buffer) |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 581 | { |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 582 | const unsigned char *cp; |
| 583 | int len; |
Tetsuo Handa | cdcf672 | 2019-01-24 18:37:35 +0900 | [diff] [blame] | 584 | |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 585 | if (*buffer != '<') |
| 586 | return false; |
| 587 | cp = strchr(buffer, ' '); |
| 588 | if (!cp) |
| 589 | len = strlen(buffer); |
| 590 | else |
| 591 | len = cp - buffer; |
| 592 | if (buffer[len - 1] != '>' || |
| 593 | !tomoyo_correct_word2(buffer + 1, len - 2)) |
| 594 | return false; |
| 595 | return true; |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 596 | } |
| 597 | |
| 598 | /** |
| 599 | * tomoyo_find_domain - Find a domain by the given name. |
| 600 | * |
| 601 | * @domainname: The domainname to find. |
| 602 | * |
| 603 | * Returns pointer to "struct tomoyo_domain_info" if found, NULL otherwise. |
| 604 | * |
| 605 | * Caller holds tomoyo_read_lock(). |
| 606 | */ |
| 607 | struct tomoyo_domain_info *tomoyo_find_domain(const char *domainname) |
| 608 | { |
| 609 | struct tomoyo_domain_info *domain; |
| 610 | struct tomoyo_path_info name; |
| 611 | |
| 612 | name.name = domainname; |
| 613 | tomoyo_fill_path_info(&name); |
Tetsuo Handa | 6bd5ce6 | 2019-12-16 19:16:48 +0900 | [diff] [blame] | 614 | list_for_each_entry_rcu(domain, &tomoyo_domain_list, list, |
| 615 | srcu_read_lock_held(&tomoyo_ss)) { |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 616 | if (!domain->is_deleted && |
| 617 | !tomoyo_pathcmp(&name, domain->domainname)) |
| 618 | return domain; |
| 619 | } |
| 620 | return NULL; |
| 621 | } |
| 622 | |
| 623 | /** |
| 624 | * tomoyo_const_part_length - Evaluate the initial length without a pattern in a token. |
| 625 | * |
| 626 | * @filename: The string to evaluate. |
| 627 | * |
| 628 | * Returns the initial length without a pattern in @filename. |
| 629 | */ |
| 630 | static int tomoyo_const_part_length(const char *filename) |
| 631 | { |
| 632 | char c; |
| 633 | int len = 0; |
| 634 | |
| 635 | if (!filename) |
| 636 | return 0; |
| 637 | while ((c = *filename++) != '\0') { |
| 638 | if (c != '\\') { |
| 639 | len++; |
| 640 | continue; |
| 641 | } |
| 642 | c = *filename++; |
| 643 | switch (c) { |
| 644 | case '\\': /* "\\" */ |
| 645 | len += 2; |
| 646 | continue; |
| 647 | case '0': /* "\ooo" */ |
| 648 | case '1': |
| 649 | case '2': |
| 650 | case '3': |
| 651 | c = *filename++; |
| 652 | if (c < '0' || c > '7') |
| 653 | break; |
| 654 | c = *filename++; |
| 655 | if (c < '0' || c > '7') |
| 656 | break; |
| 657 | len += 4; |
| 658 | continue; |
| 659 | } |
| 660 | break; |
| 661 | } |
| 662 | return len; |
| 663 | } |
| 664 | |
| 665 | /** |
| 666 | * tomoyo_fill_path_info - Fill in "struct tomoyo_path_info" members. |
| 667 | * |
| 668 | * @ptr: Pointer to "struct tomoyo_path_info" to fill in. |
| 669 | * |
| 670 | * The caller sets "struct tomoyo_path_info"->name. |
| 671 | */ |
| 672 | void tomoyo_fill_path_info(struct tomoyo_path_info *ptr) |
| 673 | { |
| 674 | const char *name = ptr->name; |
| 675 | const int len = strlen(name); |
| 676 | |
| 677 | ptr->const_len = tomoyo_const_part_length(name); |
| 678 | ptr->is_dir = len && (name[len - 1] == '/'); |
| 679 | ptr->is_patterned = (ptr->const_len < len); |
Linus Torvalds | 8387ff2 | 2016-06-10 07:51:30 -0700 | [diff] [blame] | 680 | ptr->hash = full_name_hash(NULL, name, len); |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 681 | } |
| 682 | |
| 683 | /** |
| 684 | * tomoyo_file_matches_pattern2 - Pattern matching without '/' character and "\-" pattern. |
| 685 | * |
| 686 | * @filename: The start of string to check. |
| 687 | * @filename_end: The end of string to check. |
| 688 | * @pattern: The start of pattern to compare. |
| 689 | * @pattern_end: The end of pattern to compare. |
| 690 | * |
| 691 | * Returns true if @filename matches @pattern, false otherwise. |
| 692 | */ |
| 693 | static bool tomoyo_file_matches_pattern2(const char *filename, |
| 694 | const char *filename_end, |
| 695 | const char *pattern, |
| 696 | const char *pattern_end) |
| 697 | { |
| 698 | while (filename < filename_end && pattern < pattern_end) { |
| 699 | char c; |
Tetsuo Handa | cdcf672 | 2019-01-24 18:37:35 +0900 | [diff] [blame] | 700 | int i; |
| 701 | int j; |
| 702 | |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 703 | if (*pattern != '\\') { |
| 704 | if (*filename++ != *pattern++) |
| 705 | return false; |
| 706 | continue; |
| 707 | } |
| 708 | c = *filename; |
| 709 | pattern++; |
| 710 | switch (*pattern) { |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 711 | case '?': |
| 712 | if (c == '/') { |
| 713 | return false; |
| 714 | } else if (c == '\\') { |
| 715 | if (filename[1] == '\\') |
| 716 | filename++; |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 717 | else if (tomoyo_byte_range(filename + 1)) |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 718 | filename += 3; |
| 719 | else |
| 720 | return false; |
| 721 | } |
| 722 | break; |
| 723 | case '\\': |
| 724 | if (c != '\\') |
| 725 | return false; |
| 726 | if (*++filename != '\\') |
| 727 | return false; |
| 728 | break; |
| 729 | case '+': |
| 730 | if (!isdigit(c)) |
| 731 | return false; |
| 732 | break; |
| 733 | case 'x': |
| 734 | if (!isxdigit(c)) |
| 735 | return false; |
| 736 | break; |
| 737 | case 'a': |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 738 | if (!tomoyo_alphabet_char(c)) |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 739 | return false; |
| 740 | break; |
| 741 | case '0': |
| 742 | case '1': |
| 743 | case '2': |
| 744 | case '3': |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 745 | if (c == '\\' && tomoyo_byte_range(filename + 1) |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 746 | && strncmp(filename + 1, pattern, 3) == 0) { |
| 747 | filename += 3; |
| 748 | pattern += 2; |
| 749 | break; |
| 750 | } |
| 751 | return false; /* Not matched. */ |
| 752 | case '*': |
| 753 | case '@': |
| 754 | for (i = 0; i <= filename_end - filename; i++) { |
| 755 | if (tomoyo_file_matches_pattern2( |
| 756 | filename + i, filename_end, |
| 757 | pattern + 1, pattern_end)) |
| 758 | return true; |
| 759 | c = filename[i]; |
| 760 | if (c == '.' && *pattern == '@') |
| 761 | break; |
| 762 | if (c != '\\') |
| 763 | continue; |
| 764 | if (filename[i + 1] == '\\') |
| 765 | i++; |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 766 | else if (tomoyo_byte_range(filename + i + 1)) |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 767 | i += 3; |
| 768 | else |
| 769 | break; /* Bad pattern. */ |
| 770 | } |
| 771 | return false; /* Not matched. */ |
| 772 | default: |
| 773 | j = 0; |
| 774 | c = *pattern; |
| 775 | if (c == '$') { |
| 776 | while (isdigit(filename[j])) |
| 777 | j++; |
| 778 | } else if (c == 'X') { |
| 779 | while (isxdigit(filename[j])) |
| 780 | j++; |
| 781 | } else if (c == 'A') { |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 782 | while (tomoyo_alphabet_char(filename[j])) |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 783 | j++; |
| 784 | } |
| 785 | for (i = 1; i <= j; i++) { |
| 786 | if (tomoyo_file_matches_pattern2( |
| 787 | filename + i, filename_end, |
| 788 | pattern + 1, pattern_end)) |
| 789 | return true; |
| 790 | } |
| 791 | return false; /* Not matched or bad pattern. */ |
| 792 | } |
| 793 | filename++; |
| 794 | pattern++; |
| 795 | } |
| 796 | while (*pattern == '\\' && |
| 797 | (*(pattern + 1) == '*' || *(pattern + 1) == '@')) |
| 798 | pattern += 2; |
| 799 | return filename == filename_end && pattern == pattern_end; |
| 800 | } |
| 801 | |
| 802 | /** |
| 803 | * tomoyo_file_matches_pattern - Pattern matching without '/' character. |
| 804 | * |
| 805 | * @filename: The start of string to check. |
| 806 | * @filename_end: The end of string to check. |
| 807 | * @pattern: The start of pattern to compare. |
| 808 | * @pattern_end: The end of pattern to compare. |
| 809 | * |
| 810 | * Returns true if @filename matches @pattern, false otherwise. |
| 811 | */ |
| 812 | static bool tomoyo_file_matches_pattern(const char *filename, |
| 813 | const char *filename_end, |
| 814 | const char *pattern, |
| 815 | const char *pattern_end) |
| 816 | { |
| 817 | const char *pattern_start = pattern; |
| 818 | bool first = true; |
| 819 | bool result; |
| 820 | |
| 821 | while (pattern < pattern_end - 1) { |
| 822 | /* Split at "\-" pattern. */ |
| 823 | if (*pattern++ != '\\' || *pattern++ != '-') |
| 824 | continue; |
| 825 | result = tomoyo_file_matches_pattern2(filename, |
| 826 | filename_end, |
| 827 | pattern_start, |
| 828 | pattern - 2); |
| 829 | if (first) |
| 830 | result = !result; |
| 831 | if (result) |
| 832 | return false; |
| 833 | first = false; |
| 834 | pattern_start = pattern; |
| 835 | } |
| 836 | result = tomoyo_file_matches_pattern2(filename, filename_end, |
| 837 | pattern_start, pattern_end); |
| 838 | return first ? result : !result; |
| 839 | } |
| 840 | |
| 841 | /** |
| 842 | * tomoyo_path_matches_pattern2 - Do pathname pattern matching. |
| 843 | * |
| 844 | * @f: The start of string to check. |
| 845 | * @p: The start of pattern to compare. |
| 846 | * |
| 847 | * Returns true if @f matches @p, false otherwise. |
| 848 | */ |
| 849 | static bool tomoyo_path_matches_pattern2(const char *f, const char *p) |
| 850 | { |
| 851 | const char *f_delimiter; |
| 852 | const char *p_delimiter; |
| 853 | |
| 854 | while (*f && *p) { |
| 855 | f_delimiter = strchr(f, '/'); |
| 856 | if (!f_delimiter) |
| 857 | f_delimiter = f + strlen(f); |
| 858 | p_delimiter = strchr(p, '/'); |
| 859 | if (!p_delimiter) |
| 860 | p_delimiter = p + strlen(p); |
| 861 | if (*p == '\\' && *(p + 1) == '{') |
| 862 | goto recursive; |
| 863 | if (!tomoyo_file_matches_pattern(f, f_delimiter, p, |
| 864 | p_delimiter)) |
| 865 | return false; |
| 866 | f = f_delimiter; |
| 867 | if (*f) |
| 868 | f++; |
| 869 | p = p_delimiter; |
| 870 | if (*p) |
| 871 | p++; |
| 872 | } |
| 873 | /* Ignore trailing "\*" and "\@" in @pattern. */ |
| 874 | while (*p == '\\' && |
| 875 | (*(p + 1) == '*' || *(p + 1) == '@')) |
| 876 | p += 2; |
| 877 | return !*f && !*p; |
| 878 | recursive: |
| 879 | /* |
| 880 | * The "\{" pattern is permitted only after '/' character. |
| 881 | * This guarantees that below "*(p - 1)" is safe. |
| 882 | * Also, the "\}" pattern is permitted only before '/' character |
| 883 | * so that "\{" + "\}" pair will not break the "\-" operator. |
| 884 | */ |
| 885 | if (*(p - 1) != '/' || p_delimiter <= p + 3 || *p_delimiter != '/' || |
| 886 | *(p_delimiter - 1) != '}' || *(p_delimiter - 2) != '\\') |
| 887 | return false; /* Bad pattern. */ |
| 888 | do { |
| 889 | /* Compare current component with pattern. */ |
| 890 | if (!tomoyo_file_matches_pattern(f, f_delimiter, p + 2, |
| 891 | p_delimiter - 2)) |
| 892 | break; |
| 893 | /* Proceed to next component. */ |
| 894 | f = f_delimiter; |
| 895 | if (!*f) |
| 896 | break; |
| 897 | f++; |
| 898 | /* Continue comparison. */ |
| 899 | if (tomoyo_path_matches_pattern2(f, p_delimiter + 1)) |
| 900 | return true; |
| 901 | f_delimiter = strchr(f, '/'); |
| 902 | } while (f_delimiter); |
| 903 | return false; /* Not matched. */ |
| 904 | } |
| 905 | |
| 906 | /** |
| 907 | * tomoyo_path_matches_pattern - Check whether the given filename matches the given pattern. |
| 908 | * |
| 909 | * @filename: The filename to check. |
| 910 | * @pattern: The pattern to compare. |
| 911 | * |
| 912 | * Returns true if matches, false otherwise. |
| 913 | * |
| 914 | * The following patterns are available. |
| 915 | * \\ \ itself. |
| 916 | * \ooo Octal representation of a byte. |
| 917 | * \* Zero or more repetitions of characters other than '/'. |
| 918 | * \@ Zero or more repetitions of characters other than '/' or '.'. |
| 919 | * \? 1 byte character other than '/'. |
| 920 | * \$ One or more repetitions of decimal digits. |
| 921 | * \+ 1 decimal digit. |
| 922 | * \X One or more repetitions of hexadecimal digits. |
| 923 | * \x 1 hexadecimal digit. |
| 924 | * \A One or more repetitions of alphabet characters. |
| 925 | * \a 1 alphabet character. |
| 926 | * |
| 927 | * \- Subtraction operator. |
| 928 | * |
| 929 | * /\{dir\}/ '/' + 'One or more repetitions of dir/' (e.g. /dir/ /dir/dir/ |
| 930 | * /dir/dir/dir/ ). |
| 931 | */ |
| 932 | bool tomoyo_path_matches_pattern(const struct tomoyo_path_info *filename, |
| 933 | const struct tomoyo_path_info *pattern) |
| 934 | { |
| 935 | const char *f = filename->name; |
| 936 | const char *p = pattern->name; |
| 937 | const int len = pattern->const_len; |
| 938 | |
| 939 | /* If @pattern doesn't contain pattern, I can use strcmp(). */ |
| 940 | if (!pattern->is_patterned) |
| 941 | return !tomoyo_pathcmp(filename, pattern); |
| 942 | /* Don't compare directory and non-directory. */ |
| 943 | if (filename->is_dir != pattern->is_dir) |
| 944 | return false; |
| 945 | /* Compare the initial length without patterns. */ |
| 946 | if (strncmp(f, p, len)) |
| 947 | return false; |
| 948 | f += len; |
| 949 | p += len; |
| 950 | return tomoyo_path_matches_pattern2(f, p); |
| 951 | } |
| 952 | |
| 953 | /** |
| 954 | * tomoyo_get_exe - Get tomoyo_realpath() of current process. |
| 955 | * |
| 956 | * Returns the tomoyo_realpath() of current process on success, NULL otherwise. |
| 957 | * |
| 958 | * This function uses kzalloc(), so the caller must call kfree() |
| 959 | * if this function didn't return NULL. |
| 960 | */ |
| 961 | const char *tomoyo_get_exe(void) |
| 962 | { |
Davidlohr Bueso | d4144ea | 2015-04-16 12:49:18 -0700 | [diff] [blame] | 963 | struct file *exe_file; |
| 964 | const char *cp; |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 965 | struct mm_struct *mm = current->mm; |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 966 | |
| 967 | if (!mm) |
| 968 | return NULL; |
Davidlohr Bueso | d4144ea | 2015-04-16 12:49:18 -0700 | [diff] [blame] | 969 | exe_file = get_mm_exe_file(mm); |
| 970 | if (!exe_file) |
| 971 | return NULL; |
| 972 | |
| 973 | cp = tomoyo_realpath_from_path(&exe_file->f_path); |
| 974 | fput(exe_file); |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 975 | return cp; |
| 976 | } |
| 977 | |
| 978 | /** |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 979 | * tomoyo_get_mode - Get MAC mode. |
| 980 | * |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 981 | * @ns: Pointer to "struct tomoyo_policy_namespace". |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 982 | * @profile: Profile number. |
| 983 | * @index: Index number of functionality. |
| 984 | * |
| 985 | * Returns mode. |
| 986 | */ |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 987 | int tomoyo_get_mode(const struct tomoyo_policy_namespace *ns, const u8 profile, |
| 988 | const u8 index) |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 989 | { |
| 990 | u8 mode; |
Tetsuo Handa | d58e0da | 2011-09-10 15:22:48 +0900 | [diff] [blame] | 991 | struct tomoyo_profile *p; |
| 992 | |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 993 | if (!tomoyo_policy_loaded) |
| 994 | return TOMOYO_CONFIG_DISABLED; |
Tetsuo Handa | d58e0da | 2011-09-10 15:22:48 +0900 | [diff] [blame] | 995 | p = tomoyo_profile(ns, profile); |
| 996 | mode = p->config[index]; |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 997 | if (mode == TOMOYO_CONFIG_USE_DEFAULT) |
Tetsuo Handa | d58e0da | 2011-09-10 15:22:48 +0900 | [diff] [blame] | 998 | mode = p->config[tomoyo_index2category[index] |
| 999 | + TOMOYO_MAX_MAC_INDEX]; |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 1000 | if (mode == TOMOYO_CONFIG_USE_DEFAULT) |
Tetsuo Handa | d58e0da | 2011-09-10 15:22:48 +0900 | [diff] [blame] | 1001 | mode = p->default_config; |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 1002 | return mode & 3; |
| 1003 | } |
| 1004 | |
| 1005 | /** |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 1006 | * tomoyo_init_request_info - Initialize "struct tomoyo_request_info" members. |
| 1007 | * |
| 1008 | * @r: Pointer to "struct tomoyo_request_info" to initialize. |
| 1009 | * @domain: Pointer to "struct tomoyo_domain_info". NULL for tomoyo_domain(). |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 1010 | * @index: Index number of functionality. |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 1011 | * |
| 1012 | * Returns mode. |
| 1013 | */ |
| 1014 | int tomoyo_init_request_info(struct tomoyo_request_info *r, |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 1015 | struct tomoyo_domain_info *domain, const u8 index) |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 1016 | { |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 1017 | u8 profile; |
Tetsuo Handa | cdcf672 | 2019-01-24 18:37:35 +0900 | [diff] [blame] | 1018 | |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 1019 | memset(r, 0, sizeof(*r)); |
| 1020 | if (!domain) |
| 1021 | domain = tomoyo_domain(); |
| 1022 | r->domain = domain; |
Tetsuo Handa | 57c2590 | 2010-06-03 20:38:44 +0900 | [diff] [blame] | 1023 | profile = domain->profile; |
| 1024 | r->profile = profile; |
| 1025 | r->type = index; |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 1026 | r->mode = tomoyo_get_mode(domain->ns, profile, index); |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 1027 | return r->mode; |
| 1028 | } |
| 1029 | |
| 1030 | /** |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 1031 | * tomoyo_domain_quota_is_ok - Check for domain's quota. |
| 1032 | * |
| 1033 | * @r: Pointer to "struct tomoyo_request_info". |
| 1034 | * |
| 1035 | * Returns true if the domain is not exceeded quota, false otherwise. |
| 1036 | * |
| 1037 | * Caller holds tomoyo_read_lock(). |
| 1038 | */ |
| 1039 | bool tomoyo_domain_quota_is_ok(struct tomoyo_request_info *r) |
| 1040 | { |
| 1041 | unsigned int count = 0; |
| 1042 | struct tomoyo_domain_info *domain = r->domain; |
| 1043 | struct tomoyo_acl_info *ptr; |
| 1044 | |
| 1045 | if (r->mode != TOMOYO_CONFIG_LEARNING) |
| 1046 | return false; |
| 1047 | if (!domain) |
| 1048 | return true; |
Tetsuo Handa | 6bd5ce6 | 2019-12-16 19:16:48 +0900 | [diff] [blame] | 1049 | list_for_each_entry_rcu(ptr, &domain->acl_info_list, list, |
| 1050 | srcu_read_lock_held(&tomoyo_ss)) { |
Tetsuo Handa | 7c75964 | 2011-06-26 23:15:31 +0900 | [diff] [blame] | 1051 | u16 perm; |
| 1052 | u8 i; |
Tetsuo Handa | cdcf672 | 2019-01-24 18:37:35 +0900 | [diff] [blame] | 1053 | |
Tetsuo Handa | 7e3d199 | 2010-07-27 10:08:29 +0900 | [diff] [blame] | 1054 | if (ptr->is_deleted) |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 1055 | continue; |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 1056 | switch (ptr->type) { |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 1057 | case TOMOYO_TYPE_PATH_ACL: |
| 1058 | perm = container_of(ptr, struct tomoyo_path_acl, head) |
| 1059 | ->perm; |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 1060 | break; |
| 1061 | case TOMOYO_TYPE_PATH2_ACL: |
| 1062 | perm = container_of(ptr, struct tomoyo_path2_acl, head) |
| 1063 | ->perm; |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 1064 | break; |
| 1065 | case TOMOYO_TYPE_PATH_NUMBER_ACL: |
| 1066 | perm = container_of(ptr, struct tomoyo_path_number_acl, |
| 1067 | head)->perm; |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 1068 | break; |
Tetsuo Handa | 7509315 | 2010-06-16 16:23:55 +0900 | [diff] [blame] | 1069 | case TOMOYO_TYPE_MKDEV_ACL: |
| 1070 | perm = container_of(ptr, struct tomoyo_mkdev_acl, |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 1071 | head)->perm; |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 1072 | break; |
Tetsuo Handa | 545a726 | 2011-10-11 14:06:41 +0900 | [diff] [blame] | 1073 | case TOMOYO_TYPE_INET_ACL: |
| 1074 | perm = container_of(ptr, struct tomoyo_inet_acl, |
| 1075 | head)->perm; |
| 1076 | break; |
| 1077 | case TOMOYO_TYPE_UNIX_ACL: |
| 1078 | perm = container_of(ptr, struct tomoyo_unix_acl, |
| 1079 | head)->perm; |
| 1080 | break; |
| 1081 | case TOMOYO_TYPE_MANUAL_TASK_ACL: |
| 1082 | perm = 0; |
| 1083 | break; |
Tetsuo Handa | 237ab45 | 2010-06-12 20:46:22 +0900 | [diff] [blame] | 1084 | default: |
Tetsuo Handa | 7c75964 | 2011-06-26 23:15:31 +0900 | [diff] [blame] | 1085 | perm = 1; |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 1086 | } |
Tetsuo Handa | 7c75964 | 2011-06-26 23:15:31 +0900 | [diff] [blame] | 1087 | for (i = 0; i < 16; i++) |
| 1088 | if (perm & (1 << i)) |
| 1089 | count++; |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 1090 | } |
Tetsuo Handa | bd03a3e | 2011-06-26 23:19:52 +0900 | [diff] [blame] | 1091 | if (count < tomoyo_profile(domain->ns, domain->profile)-> |
Tetsuo Handa | d5ca172 | 2011-06-26 23:18:21 +0900 | [diff] [blame] | 1092 | pref[TOMOYO_PREF_MAX_LEARNING_ENTRY]) |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 1093 | return true; |
Tetsuo Handa | 2c47ab9 | 2011-06-26 23:21:19 +0900 | [diff] [blame] | 1094 | if (!domain->flags[TOMOYO_DIF_QUOTA_WARNED]) { |
| 1095 | domain->flags[TOMOYO_DIF_QUOTA_WARNED] = true; |
| 1096 | /* r->granted = false; */ |
| 1097 | tomoyo_write_log(r, "%s", tomoyo_dif[TOMOYO_DIF_QUOTA_WARNED]); |
Tetsuo Handa | 4ad98ac | 2019-05-07 20:34:22 +0900 | [diff] [blame] | 1098 | #ifndef CONFIG_SECURITY_TOMOYO_INSECURE_BUILTIN_SETTING |
Tetsuo Handa | cdcf672 | 2019-01-24 18:37:35 +0900 | [diff] [blame] | 1099 | pr_warn("WARNING: Domain '%s' has too many ACLs to hold. Stopped learning mode.\n", |
| 1100 | domain->domainname->name); |
Tetsuo Handa | 4ad98ac | 2019-05-07 20:34:22 +0900 | [diff] [blame] | 1101 | #endif |
Tetsuo Handa | c3ef150 | 2010-05-17 10:12:46 +0900 | [diff] [blame] | 1102 | } |
| 1103 | return false; |
| 1104 | } |