1 |
/* |
/* |
2 |
* fs/ccs_common.c |
* security/ccsecurity/util.c |
3 |
* |
* |
4 |
* Common functions for SAKURA and TOMOYO. |
* Copyright (C) 2005-2009 NTT DATA CORPORATION |
5 |
* |
* |
6 |
* Copyright (C) 2005-2007 NTT DATA CORPORATION |
* Version: 1.7.0-pre 2009/08/08 |
|
* |
|
|
* Version: 1.5.3-pre 2007/12/18 |
|
7 |
* |
* |
8 |
* This file is applicable to both 2.4.30 and 2.6.11 and later. |
* This file is applicable to both 2.4.30 and 2.6.11 and later. |
9 |
* See README.ccs for ChangeLog. |
* See README.ccs for ChangeLog. |
10 |
* |
* |
11 |
*/ |
*/ |
12 |
|
|
13 |
#include <linux/string.h> |
#include "internal.h" |
|
#include <linux/mm.h> |
|
|
#include <linux/utime.h> |
|
|
#include <linux/file.h> |
|
|
#include <linux/module.h> |
|
|
#include <linux/slab.h> |
|
|
#include <asm/uaccess.h> |
|
|
#include <stdarg.h> |
|
|
#include <linux/version.h> |
|
|
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0) |
|
|
#include <linux/namei.h> |
|
|
#include <linux/mount.h> |
|
|
static const int lookup_flags = LOOKUP_FOLLOW; |
|
|
#else |
|
|
static const int lookup_flags = LOOKUP_FOLLOW | LOOKUP_POSITIVE; |
|
|
#endif |
|
|
#include <linux/realpath.h> |
|
|
#include <linux/ccs_common.h> |
|
|
#include <linux/ccs_proc.h> |
|
|
#include <linux/tomoyo.h> |
|
|
|
|
|
#ifdef CONFIG_TOMOYO_MAX_ACCEPT_ENTRY |
|
|
#define MAX_ACCEPT_ENTRY (CONFIG_TOMOYO_MAX_ACCEPT_ENTRY) |
|
|
#else |
|
|
#define MAX_ACCEPT_ENTRY 2048 |
|
|
#endif |
|
|
#ifdef CONFIG_TOMOYO_MAX_GRANT_LOG |
|
|
#define MAX_GRANT_LOG (CONFIG_TOMOYO_MAX_GRANT_LOG) |
|
|
#else |
|
|
#define MAX_GRANT_LOG 1024 |
|
|
#endif |
|
|
#ifdef CONFIG_TOMOYO_MAX_REJECT_LOG |
|
|
#define MAX_REJECT_LOG (CONFIG_TOMOYO_MAX_REJECT_LOG) |
|
|
#else |
|
|
#define MAX_REJECT_LOG 1024 |
|
|
#endif |
|
|
|
|
|
/************************* VARIABLES *************************/ |
|
14 |
|
|
15 |
/* /sbin/init started? */ |
DEFINE_MUTEX(ccs_policy_lock); |
|
int sbin_init_started = 0; |
|
16 |
|
|
17 |
const char *ccs_log_level = KERN_DEBUG; |
/* Has /sbin/init started? */ |
18 |
|
bool ccs_policy_loaded; |
19 |
|
|
20 |
static struct { |
/* Capability name used by domain policy. */ |
21 |
const char *keyword; |
const char *ccs_capability_control_keyword[CCS_MAX_CAPABILITY_INDEX] |
22 |
unsigned int current_value; |
= { |
23 |
const unsigned int max_value; |
[CCS_INET_STREAM_SOCKET_CREATE] = "inet_tcp_create", |
24 |
} ccs_control_array[CCS_MAX_CONTROL_INDEX] = { |
[CCS_INET_STREAM_SOCKET_LISTEN] = "inet_tcp_listen", |
25 |
[CCS_PROFILE_COMMENT] = { "COMMENT", 0, 0 }, /* Reserved for string. */ |
[CCS_INET_STREAM_SOCKET_CONNECT] = "inet_tcp_connect", |
26 |
[CCS_TOMOYO_MAC_FOR_FILE] = { "MAC_FOR_FILE", 0, 3 }, |
[CCS_USE_INET_DGRAM_SOCKET] = "use_inet_udp", |
27 |
[CCS_TOMOYO_MAC_FOR_ARGV0] = { "MAC_FOR_ARGV0", 0, 3 }, |
[CCS_USE_INET_RAW_SOCKET] = "use_inet_ip", |
28 |
[CCS_TOMOYO_MAC_FOR_ENV] = { "MAC_FOR_ENV", 0, 3 }, |
[CCS_USE_ROUTE_SOCKET] = "use_route", |
29 |
[CCS_TOMOYO_MAC_FOR_NETWORK] = { "MAC_FOR_NETWORK", 0, 3 }, |
[CCS_USE_PACKET_SOCKET] = "use_packet", |
30 |
[CCS_TOMOYO_MAC_FOR_SIGNAL] = { "MAC_FOR_SIGNAL", 0, 3 }, |
[CCS_SYS_MOUNT] = "SYS_MOUNT", |
31 |
[CCS_SAKURA_DENY_CONCEAL_MOUNT] = { "DENY_CONCEAL_MOUNT", 0, 3 }, |
[CCS_SYS_UMOUNT] = "SYS_UMOUNT", |
32 |
[CCS_SAKURA_RESTRICT_CHROOT] = { "RESTRICT_CHROOT", 0, 3 }, |
[CCS_SYS_REBOOT] = "SYS_REBOOT", |
33 |
[CCS_SAKURA_RESTRICT_MOUNT] = { "RESTRICT_MOUNT", 0, 3 }, |
[CCS_SYS_CHROOT] = "SYS_CHROOT", |
34 |
[CCS_SAKURA_RESTRICT_UNMOUNT] = { "RESTRICT_UNMOUNT", 0, 3 }, |
[CCS_SYS_KILL] = "SYS_KILL", |
35 |
[CCS_SAKURA_RESTRICT_PIVOT_ROOT] = { "RESTRICT_PIVOT_ROOT", 0, 3 }, |
[CCS_SYS_VHANGUP] = "SYS_VHANGUP", |
36 |
[CCS_SAKURA_RESTRICT_AUTOBIND] = { "RESTRICT_AUTOBIND", 0, 1 }, |
[CCS_SYS_SETTIME] = "SYS_TIME", |
37 |
[CCS_TOMOYO_MAX_ACCEPT_ENTRY] = { "MAX_ACCEPT_ENTRY", MAX_ACCEPT_ENTRY, INT_MAX }, |
[CCS_SYS_NICE] = "SYS_NICE", |
38 |
[CCS_TOMOYO_MAX_GRANT_LOG] = { "MAX_GRANT_LOG", MAX_GRANT_LOG, INT_MAX }, |
[CCS_SYS_SETHOSTNAME] = "SYS_SETHOSTNAME", |
39 |
[CCS_TOMOYO_MAX_REJECT_LOG] = { "MAX_REJECT_LOG", MAX_REJECT_LOG, INT_MAX }, |
[CCS_USE_KERNEL_MODULE] = "use_kernel_module", |
40 |
[CCS_TOMOYO_VERBOSE] = { "TOMOYO_VERBOSE", 1, 1 }, |
[CCS_CREATE_FIFO] = "create_fifo", |
41 |
[CCS_ALLOW_ENFORCE_GRACE] = { "ALLOW_ENFORCE_GRACE", 0, 1 }, |
[CCS_CREATE_BLOCK_DEV] = "create_block_dev", |
42 |
[CCS_SLEEP_PERIOD] = { "SLEEP_PERIOD", 0, 3000 }, /* in 0.1 second */ |
[CCS_CREATE_CHAR_DEV] = "create_char_dev", |
43 |
[CCS_TOMOYO_ALT_EXEC] = { "ALT_EXEC", 0, 0 }, /* Reserved for string. */ |
[CCS_CREATE_UNIX_SOCKET] = "create_unix_socket", |
44 |
|
[CCS_SYS_LINK] = "SYS_LINK", |
45 |
|
[CCS_SYS_SYMLINK] = "SYS_SYMLINK", |
46 |
|
[CCS_SYS_RENAME] = "SYS_RENAME", |
47 |
|
[CCS_SYS_UNLINK] = "SYS_UNLINK", |
48 |
|
[CCS_SYS_CHMOD] = "SYS_CHMOD", |
49 |
|
[CCS_SYS_CHOWN] = "SYS_CHOWN", |
50 |
|
[CCS_SYS_IOCTL] = "SYS_IOCTL", |
51 |
|
[CCS_SYS_KEXEC_LOAD] = "SYS_KEXEC_LOAD", |
52 |
|
[CCS_SYS_PIVOT_ROOT] = "SYS_PIVOT_ROOT", |
53 |
|
[CCS_SYS_PTRACE] = "SYS_PTRACE", |
54 |
|
[CCS_CONCEAL_MOUNT] = "conceal_mount", |
55 |
}; |
}; |
56 |
|
|
57 |
struct profile { |
/* Profile table. Memory is allocated as needed. */ |
58 |
unsigned int value[CCS_MAX_CONTROL_INDEX]; |
struct ccs_profile *ccs_profile_ptr[CCS_MAX_PROFILES]; |
|
const struct path_info *comment; |
|
|
const struct path_info *alt_exec; |
|
|
}; |
|
59 |
|
|
60 |
static struct profile *profile_ptr[MAX_PROFILES]; |
/* Utility functions. */ |
61 |
|
|
62 |
/************************* UTILITY FUNCTIONS *************************/ |
/** |
63 |
|
* ccs_parse_ulong - Parse an "unsigned long" value. |
64 |
|
* |
65 |
|
* @result: Pointer to "unsigned long". |
66 |
|
* @str: Pointer to string to parse. |
67 |
|
* |
68 |
|
* Returns value type on success, 0 otherwise. |
69 |
|
* |
70 |
|
* The @src is updated to point the first character after the value |
71 |
|
* on success. |
72 |
|
*/ |
73 |
|
u8 ccs_parse_ulong(unsigned long *result, char **str) |
74 |
|
{ |
75 |
|
const char *cp = *str; |
76 |
|
char *ep; |
77 |
|
int base = 10; |
78 |
|
if (*cp == '0') { |
79 |
|
char c = *(cp + 1); |
80 |
|
if (c == 'x' || c == 'X') { |
81 |
|
base = 16; |
82 |
|
cp += 2; |
83 |
|
} else if (c >= '0' && c <= '7') { |
84 |
|
base = 8; |
85 |
|
cp++; |
86 |
|
} |
87 |
|
} |
88 |
|
*result = simple_strtoul(cp, &ep, base); |
89 |
|
if (cp == ep) |
90 |
|
return 0; |
91 |
|
*str = ep; |
92 |
|
switch (base) { |
93 |
|
case 16: |
94 |
|
return CCS_VALUE_TYPE_HEXADECIMAL; |
95 |
|
case 8: |
96 |
|
return CCS_VALUE_TYPE_OCTAL; |
97 |
|
default: |
98 |
|
return CCS_VALUE_TYPE_DECIMAL; |
99 |
|
} |
100 |
|
} |
101 |
|
|
102 |
#ifdef CONFIG_TOMOYO |
/** |
103 |
static int __init TOMOYO_Quiet_Setup(char *str) |
* ccs_print_ulong - Print an "unsigned long" value. |
104 |
|
* |
105 |
|
* @buffer: Pointer to buffer. |
106 |
|
* @buffer_len: Size of @buffer. |
107 |
|
* @value: An "unsigned long" value. |
108 |
|
* @type: Type of @value. |
109 |
|
* |
110 |
|
* Returns nothing. |
111 |
|
*/ |
112 |
|
void ccs_print_ulong(char *buffer, const int buffer_len, |
113 |
|
const unsigned long value, const u8 type) |
114 |
{ |
{ |
115 |
ccs_control_array[CCS_TOMOYO_VERBOSE].current_value = 0; |
if (type == CCS_VALUE_TYPE_DECIMAL) |
116 |
return 0; |
snprintf(buffer, buffer_len, "%lu", value); |
117 |
|
else if (type == CCS_VALUE_TYPE_OCTAL) |
118 |
|
snprintf(buffer, buffer_len, "0%lo", value); |
119 |
|
else if (type == CCS_VALUE_TYPE_HEXADECIMAL) |
120 |
|
snprintf(buffer, buffer_len, "0x%lX", value); |
121 |
|
else |
122 |
|
snprintf(buffer, buffer_len, "type(%u)", type); |
123 |
|
} |
124 |
|
|
125 |
|
bool ccs_parse_name_union(const char *filename, struct ccs_name_union *ptr) |
126 |
|
{ |
127 |
|
if (!ccs_is_correct_path(filename, 0, 0, 0)) |
128 |
|
return false; |
129 |
|
if (filename[0] == '@') { |
130 |
|
ptr->group = ccs_get_path_group(filename + 1); |
131 |
|
ptr->is_group = true; |
132 |
|
return ptr->group != NULL; |
133 |
|
} |
134 |
|
ptr->filename = ccs_get_name(filename); |
135 |
|
ptr->is_group = false; |
136 |
|
return ptr->filename != NULL; |
137 |
|
} |
138 |
|
|
139 |
|
bool ccs_parse_number_union(char *data, struct ccs_number_union *num) |
140 |
|
{ |
141 |
|
u8 type; |
142 |
|
unsigned long v; |
143 |
|
memset(num, 0, sizeof(*num)); |
144 |
|
if (data[0] == '@') { |
145 |
|
if (!ccs_is_correct_path(data, 0, 0, 0)) |
146 |
|
return false; |
147 |
|
num->group = ccs_get_number_group(data + 1); |
148 |
|
num->is_group = true; |
149 |
|
return num->group != NULL; |
150 |
|
} |
151 |
|
type = ccs_parse_ulong(&v, &data); |
152 |
|
if (!type) |
153 |
|
return false; |
154 |
|
num->values[0] = v; |
155 |
|
num->min_type = type; |
156 |
|
if (!*data) { |
157 |
|
num->values[1] = v; |
158 |
|
num->max_type = type; |
159 |
|
return true; |
160 |
|
} |
161 |
|
if (*data++ != '-') |
162 |
|
return false; |
163 |
|
type = ccs_parse_ulong(&v, &data); |
164 |
|
if (!type || *data) |
165 |
|
return false; |
166 |
|
num->values[1] = v; |
167 |
|
num->max_type = type; |
168 |
|
return true; |
169 |
} |
} |
170 |
|
|
171 |
__setup("TOMOYO_QUIET", TOMOYO_Quiet_Setup); |
/** |
172 |
#endif |
* ccs_is_byte_range - Check whether the string isa \ooo style octal value. |
173 |
|
* |
174 |
|
* @str: Pointer to the string. |
175 |
|
* |
176 |
|
* Returns true if @str is a \ooo style octal value, false otherwise. |
177 |
|
*/ |
178 |
|
static inline bool ccs_is_byte_range(const char *str) |
179 |
|
{ |
180 |
|
return *str >= '0' && *str++ <= '3' && |
181 |
|
*str >= '0' && *str++ <= '7' && |
182 |
|
*str >= '0' && *str <= '7'; |
183 |
|
} |
184 |
|
|
185 |
/* Am I root? */ |
/** |
186 |
static int isRoot(void) |
* ccs_is_decimal - Check whether the character is a decimal character. |
187 |
|
* |
188 |
|
* @c: The character to check. |
189 |
|
* |
190 |
|
* Returns true if @c is a decimal character, false otherwise. |
191 |
|
*/ |
192 |
|
static inline bool ccs_is_decimal(const char c) |
193 |
{ |
{ |
194 |
return !current->uid && !current->euid; |
return c >= '0' && c <= '9'; |
195 |
} |
} |
196 |
|
|
197 |
/* |
/** |
198 |
* Format string. |
* ccs_is_hexadecimal - Check whether the character is a hexadecimal character. |
199 |
|
* |
200 |
|
* @c: The character to check. |
201 |
|
* |
202 |
|
* Returns true if @c is a hexadecimal character, false otherwise. |
203 |
|
*/ |
204 |
|
static inline bool ccs_is_hexadecimal(const char c) |
205 |
|
{ |
206 |
|
return (c >= '0' && c <= '9') || |
207 |
|
(c >= 'A' && c <= 'F') || |
208 |
|
(c >= 'a' && c <= 'f'); |
209 |
|
} |
210 |
|
|
211 |
|
/** |
212 |
|
* ccs_is_alphabet_char - Check whether the character is an alphabet. |
213 |
|
* |
214 |
|
* @c: The character to check. |
215 |
|
* |
216 |
|
* Returns true if @c is an alphabet character, false otherwise. |
217 |
|
*/ |
218 |
|
static inline bool ccs_is_alphabet_char(const char c) |
219 |
|
{ |
220 |
|
return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'); |
221 |
|
} |
222 |
|
|
223 |
|
/** |
224 |
|
* ccs_make_byte - Make byte value from three octal characters. |
225 |
|
* |
226 |
|
* @c1: The first character. |
227 |
|
* @c2: The second character. |
228 |
|
* @c3: The third character. |
229 |
|
* |
230 |
|
* Returns byte value. |
231 |
|
*/ |
232 |
|
static inline u8 ccs_make_byte(const u8 c1, const u8 c2, const u8 c3) |
233 |
|
{ |
234 |
|
return ((c1 - '0') << 6) + ((c2 - '0') << 3) + (c3 - '0'); |
235 |
|
} |
236 |
|
|
237 |
|
/** |
238 |
|
* ccs_str_starts - Check whether the given string starts with the given keyword. |
239 |
|
* |
240 |
|
* @src: Pointer to pointer to the string. |
241 |
|
* @find: Pointer to the keyword. |
242 |
|
* |
243 |
|
* Returns true if @src starts with @find, false otherwise. |
244 |
|
* |
245 |
|
* The @src is updated to point the first character after the @find |
246 |
|
* if @src starts with @find. |
247 |
|
*/ |
248 |
|
bool ccs_str_starts(char **src, const char *find) |
249 |
|
{ |
250 |
|
const int len = strlen(find); |
251 |
|
char *tmp = *src; |
252 |
|
if (strncmp(tmp, find, len)) |
253 |
|
return false; |
254 |
|
tmp += len; |
255 |
|
*src = tmp; |
256 |
|
return true; |
257 |
|
} |
258 |
|
|
259 |
|
/** |
260 |
|
* ccs_normalize_line - Format string. |
261 |
|
* |
262 |
|
* @buffer: The line to normalize. |
263 |
|
* |
264 |
* Leading and trailing whitespaces are removed. |
* Leading and trailing whitespaces are removed. |
265 |
* Multiple whitespaces are packed into single space. |
* Multiple whitespaces are packed into single space. |
266 |
|
* |
267 |
|
* Returns nothing. |
268 |
*/ |
*/ |
269 |
static void NormalizeLine(unsigned char *buffer) |
void ccs_normalize_line(unsigned char *buffer) |
270 |
{ |
{ |
271 |
unsigned char *sp = buffer, *dp = buffer; |
unsigned char *sp = buffer; |
272 |
int first = 1; |
unsigned char *dp = buffer; |
273 |
while (*sp && (*sp <= ' ' || *sp >= 127)) sp++; |
bool first = true; |
274 |
|
while (*sp && (*sp <= ' ' || *sp >= 127)) |
275 |
|
sp++; |
276 |
while (*sp) { |
while (*sp) { |
277 |
if (!first) *dp++ = ' '; |
if (!first) |
278 |
first = 0; |
*dp++ = ' '; |
279 |
while (*sp > ' ' && *sp < 127) *dp++ = *sp++; |
first = false; |
280 |
while (*sp && (*sp <= ' ' || *sp >= 127)) sp++; |
while (*sp > ' ' && *sp < 127) |
281 |
|
*dp++ = *sp++; |
282 |
|
while (*sp && (*sp <= ' ' || *sp >= 127)) |
283 |
|
sp++; |
284 |
} |
} |
285 |
*dp = '\0'; |
*dp = '\0'; |
286 |
} |
} |
287 |
|
|
288 |
/* |
/** |
289 |
* Check whether the given filename follows the naming rules. |
* ccs_tokenize - Tokenize string. |
290 |
* Returns nonzero if follows, zero otherwise. |
* |
291 |
|
* @buffer: The line to tokenize. |
292 |
|
* @w: Pointer to "char *". |
293 |
|
* @size: Sizeof @w . |
294 |
|
* |
295 |
|
* Returns true on success, false otherwise. |
296 |
|
*/ |
297 |
|
bool ccs_tokenize(char *buffer, char *w[], size_t size) |
298 |
|
{ |
299 |
|
int count = size / sizeof(char *); |
300 |
|
int i; |
301 |
|
for (i = 0; i < count; i++) |
302 |
|
w[i] = ""; |
303 |
|
for (i = 0; i < count; i++) { |
304 |
|
char *cp = strchr(buffer, ' '); |
305 |
|
if (cp) |
306 |
|
*cp = '\0'; |
307 |
|
w[i] = buffer; |
308 |
|
if (!cp) |
309 |
|
break; |
310 |
|
buffer = cp + 1; |
311 |
|
} |
312 |
|
return i < count || !*buffer; |
313 |
|
} |
314 |
|
|
315 |
|
/** |
316 |
|
* ccs_is_correct_path - Validate a pathname. |
317 |
|
* @filename: The pathname to check. |
318 |
|
* @start_type: Should the pathname start with '/'? |
319 |
|
* 1 = must / -1 = must not / 0 = don't care |
320 |
|
* @pattern_type: Can the pathname contain a wildcard? |
321 |
|
* 1 = must / -1 = must not / 0 = don't care |
322 |
|
* @end_type: Should the pathname end with '/'? |
323 |
|
* 1 = must / -1 = must not / 0 = don't care |
324 |
|
* |
325 |
|
* Check whether the given filename follows the naming rules. |
326 |
|
* Returns true if @filename follows the naming rules, false otherwise. |
327 |
*/ |
*/ |
328 |
bool IsCorrectPath(const char *filename, const int start_type, const int pattern_type, const int end_type, const char *function) |
bool ccs_is_correct_path(const char *filename, const s8 start_type, |
329 |
|
const s8 pattern_type, const s8 end_type) |
330 |
{ |
{ |
331 |
int contains_pattern = 0; |
bool contains_pattern = false; |
332 |
char c, d, e; |
unsigned char c; |
333 |
|
unsigned char d; |
334 |
|
unsigned char e; |
335 |
const char *original_filename = filename; |
const char *original_filename = filename; |
336 |
if (!filename) goto out; |
if (!filename) |
337 |
|
goto out; |
338 |
c = *filename; |
c = *filename; |
339 |
if (start_type == 1) { /* Must start with '/' */ |
if (start_type == 1) { /* Must start with '/' */ |
340 |
if (c != '/') goto out; |
if (c != '/') |
341 |
|
goto out; |
342 |
} else if (start_type == -1) { /* Must not start with '/' */ |
} else if (start_type == -1) { /* Must not start with '/' */ |
343 |
if (c == '/') goto out; |
if (c == '/') |
344 |
|
goto out; |
345 |
} |
} |
346 |
if (c) c = * (strchr(filename, '\0') - 1); |
if (c) |
347 |
|
c = *(filename + strlen(filename) - 1); |
348 |
if (end_type == 1) { /* Must end with '/' */ |
if (end_type == 1) { /* Must end with '/' */ |
349 |
if (c != '/') goto out; |
if (c != '/') |
350 |
|
goto out; |
351 |
} else if (end_type == -1) { /* Must not end with '/' */ |
} else if (end_type == -1) { /* Must not end with '/' */ |
352 |
if (c == '/') goto out; |
if (c == '/') |
353 |
|
goto out; |
354 |
} |
} |
355 |
while ((c = *filename++) != '\0') { |
while (1) { |
356 |
|
c = *filename++; |
357 |
|
if (!c) |
358 |
|
break; |
359 |
if (c == '\\') { |
if (c == '\\') { |
360 |
switch ((c = *filename++)) { |
c = *filename++; |
361 |
|
switch (c) { |
362 |
case '\\': /* "\\" */ |
case '\\': /* "\\" */ |
363 |
continue; |
continue; |
364 |
case '$': /* "\$" */ |
case '$': /* "\$" */ |
371 |
case 'a': /* "\a" */ |
case 'a': /* "\a" */ |
372 |
case 'A': /* "\A" */ |
case 'A': /* "\A" */ |
373 |
case '-': /* "\-" */ |
case '-': /* "\-" */ |
374 |
if (pattern_type == -1) break; /* Must not contain pattern */ |
if (pattern_type == -1) |
375 |
contains_pattern = 1; |
break; /* Must not contain pattern */ |
376 |
|
contains_pattern = true; |
377 |
continue; |
continue; |
378 |
case '0': /* "\ooo" */ |
case '0': /* "\ooo" */ |
379 |
case '1': |
case '1': |
380 |
case '2': |
case '2': |
381 |
case '3': |
case '3': |
382 |
if ((d = *filename++) >= '0' && d <= '7' && (e = *filename++) >= '0' && e <= '7') { |
d = *filename++; |
383 |
const unsigned char f = |
if (d < '0' || d > '7') |
384 |
(((unsigned char) (c - '0')) << 6) + |
break; |
385 |
(((unsigned char) (d - '0')) << 3) + |
e = *filename++; |
386 |
(((unsigned char) (e - '0'))); |
if (e < '0' || e > '7') |
387 |
if (f && (f <= ' ' || f >= 127)) continue; /* pattern is not \000 */ |
break; |
388 |
} |
c = ccs_make_byte(c, d, e); |
389 |
|
if (c && (c <= ' ' || c >= 127)) |
390 |
|
continue; /* pattern is not \000 */ |
391 |
} |
} |
392 |
goto out; |
goto out; |
393 |
} else if (c <= ' ' || c >= 127) { |
} else if (c <= ' ' || c >= 127) { |
395 |
} |
} |
396 |
} |
} |
397 |
if (pattern_type == 1) { /* Must contain pattern */ |
if (pattern_type == 1) { /* Must contain pattern */ |
398 |
if (!contains_pattern) goto out; |
if (!contains_pattern) |
399 |
|
goto out; |
400 |
} |
} |
401 |
return 1; |
return true; |
402 |
out: |
out: |
403 |
printk(KERN_DEBUG "%s: Invalid pathname '%s'\n", function, original_filename); |
printk(KERN_DEBUG "Invalid pathname '%s'\n", original_filename); |
404 |
return 0; |
return false; |
405 |
} |
} |
406 |
|
|
407 |
/* |
/** |
408 |
* Check whether the given domainname follows the naming rules. |
* ccs_is_correct_domain - Check whether the given domainname follows the naming rules. |
409 |
* Returns nonzero if follows, zero otherwise. |
* @domainname: The domainname to check. |
410 |
|
* |
411 |
|
* Returns true if @domainname follows the naming rules, false otherwise. |
412 |
*/ |
*/ |
413 |
bool IsCorrectDomain(const unsigned char *domainname, const char *function) |
bool ccs_is_correct_domain(const unsigned char *domainname) |
414 |
{ |
{ |
415 |
unsigned char c, d, e; |
unsigned char c; |
416 |
|
unsigned char d; |
417 |
|
unsigned char e; |
418 |
const char *org_domainname = domainname; |
const char *org_domainname = domainname; |
419 |
if (!domainname || strncmp(domainname, ROOT_NAME, ROOT_NAME_LEN)) goto out; |
if (!domainname || strncmp(domainname, ROOT_NAME, ROOT_NAME_LEN)) |
420 |
|
goto out; |
421 |
domainname += ROOT_NAME_LEN; |
domainname += ROOT_NAME_LEN; |
422 |
if (!*domainname) return 1; |
if (!*domainname) |
423 |
|
return true; |
424 |
do { |
do { |
425 |
if (*domainname++ != ' ') goto out; |
if (*domainname++ != ' ') |
426 |
if (*domainname++ != '/') goto out; |
goto out; |
427 |
while ((c = *domainname) != '\0' && c != ' ') { |
if (*domainname++ != '/') |
428 |
|
goto out; |
429 |
|
while (1) { |
430 |
|
c = *domainname; |
431 |
|
if (!c || c == ' ') |
432 |
|
break; |
433 |
domainname++; |
domainname++; |
434 |
if (c == '\\') { |
if (c == '\\') { |
435 |
switch ((c = *domainname++)) { |
c = *domainname++; |
436 |
|
switch ((c)) { |
437 |
case '\\': /* "\\" */ |
case '\\': /* "\\" */ |
438 |
continue; |
continue; |
439 |
case '0': /* "\ooo" */ |
case '0': /* "\ooo" */ |
440 |
case '1': |
case '1': |
441 |
case '2': |
case '2': |
442 |
case '3': |
case '3': |
443 |
if ((d = *domainname++) >= '0' && d <= '7' && (e = *domainname++) >= '0' && e <= '7') { |
d = *domainname++; |
444 |
const unsigned char f = |
if (d < '0' || d > '7') |
445 |
(((unsigned char) (c - '0')) << 6) + |
break; |
446 |
(((unsigned char) (d - '0')) << 3) + |
e = *domainname++; |
447 |
(((unsigned char) (e - '0'))); |
if (e < '0' || e > '7') |
448 |
if (f && (f <= ' ' || f >= 127)) continue; /* pattern is not \000 */ |
break; |
449 |
} |
c = ccs_make_byte(c, d, e); |
450 |
|
if (c && (c <= ' ' || c >= 127)) |
451 |
|
/* pattern is not \000 */ |
452 |
|
continue; |
453 |
} |
} |
454 |
goto out; |
goto out; |
455 |
} else if (c < ' ' || c >= 127) { |
} else if (c < ' ' || c >= 127) { |
457 |
} |
} |
458 |
} |
} |
459 |
} while (*domainname); |
} while (*domainname); |
460 |
return 1; |
return true; |
461 |
out: |
out: |
462 |
printk(KERN_DEBUG "%s: Invalid domainname '%s'\n", function, org_domainname); |
printk(KERN_DEBUG "Invalid domainname '%s'\n", org_domainname); |
463 |
return 0; |
return false; |
464 |
} |
} |
465 |
|
|
466 |
bool IsDomainDef(const unsigned char *buffer) |
/** |
467 |
|
* ccs_is_domain_def - Check whether the given token can be a domainname. |
468 |
|
* |
469 |
|
* @buffer: The token to check. |
470 |
|
* |
471 |
|
* Returns true if @buffer possibly be a domainname, false otherwise. |
472 |
|
*/ |
473 |
|
bool ccs_is_domain_def(const unsigned char *buffer) |
474 |
{ |
{ |
475 |
/* while (*buffer && (*buffer <= ' ' || *buffer >= 127)) buffer++; */ |
return !strncmp(buffer, ROOT_NAME, ROOT_NAME_LEN); |
|
return strncmp(buffer, ROOT_NAME, ROOT_NAME_LEN) == 0; |
|
476 |
} |
} |
477 |
|
|
478 |
struct domain_info *FindDomain(const char *domainname0) |
/** |
479 |
|
* ccs_find_domain - Find a domain by the given name. |
480 |
|
* |
481 |
|
* @domainname: The domainname to find. |
482 |
|
* |
483 |
|
* Returns pointer to "struct ccs_domain_info" if found, NULL otherwise. |
484 |
|
* |
485 |
|
* Caller holds ccs_read_lock(). |
486 |
|
*/ |
487 |
|
struct ccs_domain_info *ccs_find_domain(const char *domainname) |
488 |
{ |
{ |
489 |
struct domain_info *domain; |
struct ccs_domain_info *domain; |
490 |
struct path_info domainname; |
struct ccs_path_info name; |
491 |
domainname.name = domainname0; |
ccs_check_read_lock(); |
492 |
fill_path_info(&domainname); |
name.name = domainname; |
493 |
list1_for_each_entry(domain, &domain_list, list) { |
ccs_fill_path_info(&name); |
494 |
if (!domain->is_deleted && !pathcmp(&domainname, domain->domainname)) return domain; |
list_for_each_entry_rcu(domain, &ccs_domain_list, list) { |
495 |
|
if (!domain->is_deleted && |
496 |
|
!ccs_pathcmp(&name, domain->domainname)) |
497 |
|
return domain; |
498 |
} |
} |
499 |
return NULL; |
return NULL; |
500 |
} |
} |
501 |
|
|
502 |
static int PathDepth(const char *pathname) |
/** |
503 |
|
* ccs_path_depth - Evaluate the number of '/' in a string. |
504 |
|
* |
505 |
|
* @pathname: The string to evaluate. |
506 |
|
* |
507 |
|
* Returns path depth of the string. |
508 |
|
* |
509 |
|
* I score 2 for each of the '/' in the @pathname |
510 |
|
* and score 1 if the @pathname ends with '/'. |
511 |
|
*/ |
512 |
|
static int ccs_path_depth(const char *pathname) |
513 |
{ |
{ |
514 |
int i = 0; |
int i = 0; |
515 |
if (pathname) { |
if (pathname) { |
516 |
char *ep = strchr(pathname, '\0'); |
const char *ep = pathname + strlen(pathname); |
517 |
if (pathname < ep--) { |
if (pathname < ep--) { |
518 |
if (*ep != '/') i++; |
if (*ep != '/') |
519 |
while (pathname <= ep) if (*ep-- == '/') i += 2; |
i++; |
520 |
|
while (pathname <= ep) |
521 |
|
if (*ep-- == '/') |
522 |
|
i += 2; |
523 |
} |
} |
524 |
} |
} |
525 |
return i; |
return i; |
526 |
} |
} |
527 |
|
|
528 |
static int const_part_length(const char *filename) |
/** |
529 |
|
* ccs_const_part_length - Evaluate the initial length without a pattern in a token. |
530 |
|
* |
531 |
|
* @filename: The string to evaluate. |
532 |
|
* |
533 |
|
* Returns the initial length without a pattern in @filename. |
534 |
|
*/ |
535 |
|
static int ccs_const_part_length(const char *filename) |
536 |
{ |
{ |
537 |
|
char c; |
538 |
int len = 0; |
int len = 0; |
539 |
if (filename) { |
if (!filename) |
540 |
char c; |
return 0; |
541 |
while ((c = *filename++) != '\0') { |
while (1) { |
542 |
if (c != '\\') { len++; continue; } |
c = *filename++; |
543 |
switch (c = *filename++) { |
if (!c) |
|
case '\\': /* "\\" */ |
|
|
len += 2; continue; |
|
|
case '0': /* "\ooo" */ |
|
|
case '1': |
|
|
case '2': |
|
|
case '3': |
|
|
if ((c = *filename++) >= '0' && c <= '7' && (c = *filename++) >= '0' && c <= '7') { len += 4; continue; } |
|
|
} |
|
544 |
break; |
break; |
545 |
|
if (c != '\\') { |
546 |
|
len++; |
547 |
|
continue; |
548 |
|
} |
549 |
|
c = *filename++; |
550 |
|
switch (c) { |
551 |
|
case '\\': /* "\\" */ |
552 |
|
len += 2; |
553 |
|
continue; |
554 |
|
case '0': /* "\ooo" */ |
555 |
|
case '1': |
556 |
|
case '2': |
557 |
|
case '3': |
558 |
|
c = *filename++; |
559 |
|
if (c < '0' || c > '7') |
560 |
|
break; |
561 |
|
c = *filename++; |
562 |
|
if (c < '0' || c > '7') |
563 |
|
break; |
564 |
|
len += 4; |
565 |
|
continue; |
566 |
} |
} |
567 |
|
break; |
568 |
} |
} |
569 |
return len; |
return len; |
570 |
} |
} |
571 |
|
|
572 |
void fill_path_info(struct path_info *ptr) |
/** |
573 |
|
* ccs_fill_path_info - Fill in "struct ccs_path_info" members. |
574 |
|
* |
575 |
|
* @ptr: Pointer to "struct ccs_path_info" to fill in. |
576 |
|
* |
577 |
|
* The caller sets "struct ccs_path_info"->name. |
578 |
|
*/ |
579 |
|
void ccs_fill_path_info(struct ccs_path_info *ptr) |
580 |
{ |
{ |
581 |
const char *name = ptr->name; |
const char *name = ptr->name; |
582 |
const int len = strlen(name); |
const int len = strlen(name); |
583 |
ptr->total_len = len; |
ptr->total_len = len; |
584 |
ptr->const_len = const_part_length(name); |
ptr->const_len = ccs_const_part_length(name); |
585 |
ptr->is_dir = len && (name[len - 1] == '/'); |
ptr->is_dir = len && (name[len - 1] == '/'); |
586 |
ptr->is_patterned = (ptr->const_len < len); |
ptr->is_patterned = (ptr->const_len < len); |
587 |
ptr->hash = full_name_hash(name, len); |
ptr->hash = full_name_hash(name, len); |
588 |
ptr->depth = PathDepth(name); |
ptr->depth = ccs_path_depth(name); |
589 |
} |
} |
590 |
|
|
591 |
static int FileMatchesToPattern2(const char *filename, const char *filename_end, const char *pattern, const char *pattern_end) |
/** |
592 |
|
* ccs_file_matches_pattern2 - Pattern matching without '/' character |
593 |
|
* and "\-" pattern. |
594 |
|
* |
595 |
|
* @filename: The start of string to check. |
596 |
|
* @filename_end: The end of string to check. |
597 |
|
* @pattern: The start of pattern to compare. |
598 |
|
* @pattern_end: The end of pattern to compare. |
599 |
|
* |
600 |
|
* Returns true if @filename matches @pattern, false otherwise. |
601 |
|
*/ |
602 |
|
static bool ccs_file_matches_pattern2(const char *filename, |
603 |
|
const char *filename_end, |
604 |
|
const char *pattern, |
605 |
|
const char *pattern_end) |
606 |
{ |
{ |
607 |
while (filename < filename_end && pattern < pattern_end) { |
while (filename < filename_end && pattern < pattern_end) { |
608 |
|
char c; |
609 |
if (*pattern != '\\') { |
if (*pattern != '\\') { |
610 |
if (*filename++ != *pattern++) return 0; |
if (*filename++ != *pattern++) |
611 |
} else { |
return false; |
612 |
char c = *filename; |
continue; |
613 |
pattern++; |
} |
614 |
switch (*pattern) { |
c = *filename; |
615 |
case '?': |
pattern++; |
616 |
if (c == '/') { |
switch (*pattern) { |
617 |
return 0; |
int i; |
618 |
} else if (c == '\\') { |
int j; |
619 |
if ((c = filename[1]) == '\\') { |
case '?': |
620 |
filename++; /* safe because filename is \\ */ |
if (c == '/') { |
621 |
} else if (c >= '0' && c <= '3' && (c = filename[2]) >= '0' && c <= '7' && (c = filename[3]) >= '0' && c <= '7') { |
return false; |
622 |
filename += 3; /* safe because filename is \ooo */ |
} else if (c == '\\') { |
623 |
} else { |
if (filename[1] == '\\') |
624 |
return 0; |
filename++; |
625 |
} |
else if (ccs_is_byte_range(filename + 1)) |
626 |
} |
filename += 3; |
627 |
break; |
else |
628 |
case '\\': |
return false; |
629 |
if (c != '\\') return 0; |
} |
630 |
if (*++filename != '\\') return 0; /* safe because *filename != '\0' */ |
break; |
631 |
break; |
case '\\': |
632 |
case '+': |
if (c != '\\') |
633 |
if (c < '0' || c > '9') return 0; |
return false; |
634 |
break; |
if (*++filename != '\\') |
635 |
case 'x': |
return false; |
636 |
if (!((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f'))) return 0; |
break; |
637 |
break; |
case '+': |
638 |
case 'a': |
if (!ccs_is_decimal(c)) |
639 |
if (!((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'))) return 0; |
return false; |
640 |
|
break; |
641 |
|
case 'x': |
642 |
|
if (!ccs_is_hexadecimal(c)) |
643 |
|
return false; |
644 |
|
break; |
645 |
|
case 'a': |
646 |
|
if (!ccs_is_alphabet_char(c)) |
647 |
|
return false; |
648 |
|
break; |
649 |
|
case '0': |
650 |
|
case '1': |
651 |
|
case '2': |
652 |
|
case '3': |
653 |
|
if (c == '\\' && ccs_is_byte_range(filename + 1) |
654 |
|
&& strncmp(filename + 1, pattern, 3) == 0) { |
655 |
|
filename += 3; |
656 |
|
pattern += 2; |
657 |
break; |
break; |
658 |
case '0': |
} |
659 |
case '1': |
return false; /* Not matched. */ |
660 |
case '2': |
case '*': |
661 |
case '3': |
case '@': |
662 |
if (c == '\\' && (c = filename[1]) >= '0' && c <= '3' && c == *pattern |
for (i = 0; i <= filename_end - filename; i++) { |
663 |
&& (c = filename[2]) >= '0' && c <= '7' && c == pattern[1] |
if (ccs_file_matches_pattern2(filename + i, |
664 |
&& (c = filename[3]) >= '0' && c <= '7' && c == pattern[2]) { |
filename_end, |
665 |
filename += 3; /* safe because filename is \ooo */ |
pattern + 1, |
666 |
pattern += 2; /* safe because pattern is \ooo */ |
pattern_end)) |
667 |
|
return true; |
668 |
|
c = filename[i]; |
669 |
|
if (c == '.' && *pattern == '@') |
670 |
break; |
break; |
671 |
} |
if (c != '\\') |
672 |
return 0; /* Not matched. */ |
continue; |
673 |
case '*': |
if (filename[i + 1] == '\\') |
674 |
case '@': |
i++; |
675 |
{ |
else if (ccs_is_byte_range(filename + i + 1)) |
676 |
int i; |
i += 3; |
677 |
for (i = 0; i <= filename_end - filename; i++) { |
else |
678 |
if (FileMatchesToPattern2(filename + i, filename_end, pattern + 1, pattern_end)) return 1; |
break; /* Bad pattern. */ |
679 |
if ((c = filename[i]) == '.' && *pattern == '@') break; |
} |
680 |
if (c == '\\') { |
return false; /* Not matched. */ |
681 |
if ((c = filename[i + 1]) == '\\') { |
default: |
682 |
i++; /* safe because filename is \\ */ |
j = 0; |
683 |
} else if (c >= '0' && c <= '3' && (c = filename[i + 2]) >= '0' && c <= '7' && (c = filename[i + 3]) >= '0' && c <= '7') { |
c = *pattern; |
684 |
i += 3; /* safe because filename is \ooo */ |
if (c == '$') { |
685 |
} else { |
while (ccs_is_decimal(filename[j])) |
686 |
break; /* Bad pattern. */ |
j++; |
687 |
} |
} else if (c == 'X') { |
688 |
} |
while (ccs_is_hexadecimal(filename[j])) |
689 |
} |
j++; |
690 |
return 0; /* Not matched. */ |
} else if (c == 'A') { |
691 |
} |
while (ccs_is_alphabet_char(filename[j])) |
692 |
default: |
j++; |
|
{ |
|
|
int i, j = 0; |
|
|
if ((c = *pattern) == '$') { |
|
|
while ((c = filename[j]) >= '0' && c <= '9') j++; |
|
|
} else if (c == 'X') { |
|
|
while (((c = filename[j]) >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f')) j++; |
|
|
} else if (c == 'A') { |
|
|
while (((c = filename[j]) >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')) j++; |
|
|
} |
|
|
for (i = 1; i <= j; i++) { |
|
|
if (FileMatchesToPattern2(filename + i, filename_end, pattern + 1, pattern_end)) return 1; |
|
|
} |
|
|
} |
|
|
return 0; /* Not matched or bad pattern. */ |
|
693 |
} |
} |
694 |
filename++; /* safe because *filename != '\0' */ |
for (i = 1; i <= j; i++) { |
695 |
pattern++; /* safe because *pattern != '\0' */ |
if (ccs_file_matches_pattern2(filename + i, |
696 |
|
filename_end, |
697 |
|
pattern + 1, |
698 |
|
pattern_end)) |
699 |
|
return true; |
700 |
|
} |
701 |
|
return false; /* Not matched or bad pattern. */ |
702 |
} |
} |
703 |
|
filename++; |
704 |
|
pattern++; |
705 |
} |
} |
706 |
while (*pattern == '\\' && (*(pattern + 1) == '*' || *(pattern + 1) == '@')) pattern += 2; |
while (*pattern == '\\' && |
707 |
return (filename == filename_end && pattern == pattern_end); |
(*(pattern + 1) == '*' || *(pattern + 1) == '@')) |
708 |
|
pattern += 2; |
709 |
|
return filename == filename_end && pattern == pattern_end; |
710 |
} |
} |
711 |
|
|
712 |
static int FileMatchesToPattern(const char *filename, const char *filename_end, const char *pattern, const char *pattern_end) |
/** |
713 |
|
* ccs_file_matches_pattern - Pattern matching without without '/' character. |
714 |
|
* |
715 |
|
* @filename: The start of string to check. |
716 |
|
* @filename_end: The end of string to check. |
717 |
|
* @pattern: The start of pattern to compare. |
718 |
|
* @pattern_end: The end of pattern to compare. |
719 |
|
* |
720 |
|
* Returns true if @filename matches @pattern, false otherwise. |
721 |
|
*/ |
722 |
|
static bool ccs_file_matches_pattern(const char *filename, |
723 |
|
const char *filename_end, |
724 |
|
const char *pattern, |
725 |
|
const char *pattern_end) |
726 |
{ |
{ |
727 |
const char *pattern_start = pattern; |
const char *pattern_start = pattern; |
728 |
int first = 1; |
bool first = true; |
729 |
int result; |
bool result; |
730 |
while (pattern < pattern_end - 1) { |
while (pattern < pattern_end - 1) { |
731 |
if (*pattern++ != '\\' || *pattern++ != '-') continue; |
/* Split at "\-" pattern. */ |
732 |
result = FileMatchesToPattern2(filename, filename_end, pattern_start, pattern - 2); |
if (*pattern++ != '\\' || *pattern++ != '-') |
733 |
if (first) result = !result; |
continue; |
734 |
if (result) return 0; |
result = ccs_file_matches_pattern2(filename, filename_end, |
735 |
first = 0; |
pattern_start, pattern - 2); |
736 |
|
if (first) |
737 |
|
result = !result; |
738 |
|
if (result) |
739 |
|
return false; |
740 |
|
first = false; |
741 |
pattern_start = pattern; |
pattern_start = pattern; |
742 |
} |
} |
743 |
result = FileMatchesToPattern2(filename, filename_end, pattern_start, pattern_end); |
result = ccs_file_matches_pattern2(filename, filename_end, |
744 |
|
pattern_start, pattern_end); |
745 |
return first ? result : !result; |
return first ? result : !result; |
746 |
} |
} |
747 |
|
|
748 |
/* |
/** |
749 |
* Check whether the given pathname matches to the given pattern. |
* ccs_path_matches_pattern - Check whether the given filename matches the given pattern. |
750 |
* Returns nonzero if matches, zero otherwise. |
* @filename: The filename to check. |
751 |
|
* @pattern: The pattern to compare. |
752 |
* |
* |
753 |
* The following patterns are available. |
* Returns true if matches, false otherwise. |
754 |
* \\ \ itself. |
* |
755 |
* \ooo Octal representation of a byte. |
* The following patterns are available. |
756 |
* \* More than or equals to 0 character other than '/'. |
* \\ \ itself. |
757 |
* \@ More than or equals to 0 character other than '/' or '.'. |
* \ooo Octal representation of a byte. |
758 |
* \? 1 byte character other than '/'. |
* \* More than or equals to 0 character other than '/'. |
759 |
* \$ More than or equals to 1 decimal digit. |
* \@ More than or equals to 0 character other than '/' or '.'. |
760 |
* \+ 1 decimal digit. |
* \? 1 byte character other than '/'. |
761 |
* \X More than or equals to 1 hexadecimal digit. |
* \$ More than or equals to 1 decimal digit. |
762 |
* \x 1 hexadecimal digit. |
* \+ 1 decimal digit. |
763 |
* \A More than or equals to 1 alphabet character. |
* \X More than or equals to 1 hexadecimal digit. |
764 |
* \a 1 alphabet character. |
* \x 1 hexadecimal digit. |
765 |
* \- Subtraction operator. |
* \A More than or equals to 1 alphabet character. |
766 |
*/ |
* \a 1 alphabet character. |
767 |
|
* \- Subtraction operator. |
768 |
int PathMatchesToPattern(const struct path_info *pathname0, const struct path_info *pattern0) |
*/ |
769 |
{ |
bool ccs_path_matches_pattern(const struct ccs_path_info *filename, |
770 |
/* if (!pathname || !pattern) return 0; */ |
const struct ccs_path_info *pattern) |
771 |
const char *pathname = pathname0->name, *pattern = pattern0->name; |
{ |
772 |
const int len = pattern0->const_len; |
/* |
773 |
if (!pattern0->is_patterned) return !pathcmp(pathname0, pattern0); |
if (!filename || !pattern) |
774 |
if (pathname0->depth != pattern0->depth) return 0; |
return false; |
775 |
if (strncmp(pathname, pattern, len)) return 0; |
*/ |
776 |
pathname += len; pattern += len; |
const char *f = filename->name; |
777 |
while (*pathname && *pattern) { |
const char *p = pattern->name; |
778 |
const char *pathname_delimiter = strchr(pathname, '/'), *pattern_delimiter = strchr(pattern, '/'); |
const int len = pattern->const_len; |
779 |
if (!pathname_delimiter) pathname_delimiter = strchr(pathname, '\0'); |
/* If @pattern doesn't contain pattern, I can use strcmp(). */ |
780 |
if (!pattern_delimiter) pattern_delimiter = strchr(pattern, '\0'); |
if (!pattern->is_patterned) |
781 |
if (!FileMatchesToPattern(pathname, pathname_delimiter, pattern, pattern_delimiter)) return 0; |
return !ccs_pathcmp(filename, pattern); |
782 |
pathname = *pathname_delimiter ? pathname_delimiter + 1 : pathname_delimiter; |
/* Don't compare if the number of '/' differs. */ |
783 |
pattern = *pattern_delimiter ? pattern_delimiter + 1 : pattern_delimiter; |
if (filename->depth != pattern->depth) |
784 |
} |
return false; |
785 |
while (*pattern == '\\' && (*(pattern + 1) == '*' || *(pattern + 1) == '@')) pattern += 2; |
/* Compare the initial length without patterns. */ |
786 |
return (!*pathname && !*pattern); |
if (strncmp(f, p, len)) |
787 |
} |
return false; |
788 |
|
f += len; |
789 |
/* |
p += len; |
790 |
* Transactional printf() to struct io_buffer structure. |
/* Main loop. Compare each directory component. */ |
791 |
* snprintf() will truncate, but io_printf() won't. |
while (*f && *p) { |
792 |
* Returns zero on success, nonzero otherwise. |
const char *f_delimiter = strchr(f, '/'); |
793 |
*/ |
const char *p_delimiter = strchr(p, '/'); |
794 |
int io_printf(struct io_buffer *head, const char *fmt, ...) |
if (!f_delimiter) |
795 |
{ |
f_delimiter = f + strlen(f); |
796 |
va_list args; |
if (!p_delimiter) |
797 |
int len, pos = head->read_avail, size = head->readbuf_size - pos; |
p_delimiter = p + strlen(p); |
798 |
if (size <= 0) return -ENOMEM; |
if (!ccs_file_matches_pattern(f, f_delimiter, p, p_delimiter)) |
799 |
va_start(args, fmt); |
return false; |
800 |
len = vsnprintf(head->read_buf + pos, size, fmt, args); |
f = f_delimiter; |
801 |
va_end(args); |
if (*f) |
802 |
if (pos + len >= head->readbuf_size) return -ENOMEM; |
f++; |
803 |
head->read_avail += len; |
p = p_delimiter; |
804 |
return 0; |
if (*p) |
805 |
|
p++; |
806 |
|
} |
807 |
|
/* Ignore trailing "\*" and "\@" in @pattern. */ |
808 |
|
while (*p == '\\' && |
809 |
|
(*(p + 1) == '*' || *(p + 1) == '@')) |
810 |
|
p += 2; |
811 |
|
return !*f && !*p; |
812 |
} |
} |
813 |
|
|
814 |
/* |
/** |
815 |
* Get realpath() of current process. |
* ccs_get_exe - Get ccs_realpath() of current process. |
816 |
* This function uses ccs_alloc(), so caller must ccs_free() if this function didn't return NULL. |
* |
817 |
|
* Returns the ccs_realpath() of current process on success, NULL otherwise. |
818 |
|
* |
819 |
|
* This function uses kzalloc(), so the caller must kfree() |
820 |
|
* if this function didn't return NULL. |
821 |
*/ |
*/ |
822 |
const char *GetEXE(void) |
const char *ccs_get_exe(void) |
823 |
{ |
{ |
824 |
struct mm_struct *mm = current->mm; |
struct mm_struct *mm = current->mm; |
825 |
struct vm_area_struct *vma; |
struct vm_area_struct *vma; |
826 |
const char *cp = NULL; |
const char *cp = NULL; |
827 |
if (!mm) return NULL; |
if (!mm) |
828 |
|
return NULL; |
829 |
down_read(&mm->mmap_sem); |
down_read(&mm->mmap_sem); |
830 |
for (vma = mm->mmap; vma; vma = vma->vm_next) { |
for (vma = mm->mmap; vma; vma = vma->vm_next) { |
831 |
if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file) { |
if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file) { |
832 |
cp = realpath_from_dentry(vma->vm_file->f_dentry, vma->vm_file->f_vfsmnt); |
cp = ccs_realpath_from_dentry(vma->vm_file->f_dentry, |
833 |
|
vma->vm_file->f_vfsmnt); |
834 |
break; |
break; |
835 |
} |
} |
836 |
} |
} |
838 |
return cp; |
return cp; |
839 |
} |
} |
840 |
|
|
841 |
const char *GetMSG(const bool is_enforce) |
/** |
842 |
{ |
* ccs_get_msg - Get warning message. |
843 |
if (is_enforce) return "ERROR"; else return "WARNING"; |
* |
844 |
} |
* @is_enforce: Is it enforcing mode? |
845 |
|
* |
846 |
const char *GetAltExec(void) |
* Returns "ERROR" or "WARNING". |
847 |
{ |
*/ |
848 |
const u8 profile = current->domain_info->profile; |
const char *ccs_get_msg(const bool is_enforce) |
|
const struct path_info *alt_exec = profile_ptr[profile] ? profile_ptr[profile]->alt_exec : NULL; |
|
|
return alt_exec ? alt_exec->name : NULL; |
|
|
} |
|
|
|
|
|
/************************* DOMAIN POLICY HANDLER *************************/ |
|
|
|
|
|
/* Check whether the given access control is enabled. */ |
|
|
unsigned int CheckCCSFlags(const unsigned int index) |
|
|
{ |
|
|
const u8 profile = current->domain_info->profile; |
|
|
return sbin_init_started && index < CCS_MAX_CONTROL_INDEX |
|
|
#if MAX_PROFILES != 256 |
|
|
&& profile < MAX_PROFILES |
|
|
#endif |
|
|
&& profile_ptr[profile] ? profile_ptr[profile]->value[index] : 0; |
|
|
} |
|
|
|
|
|
bool TomoyoVerboseMode(void) |
|
|
{ |
|
|
return CheckCCSFlags(CCS_TOMOYO_VERBOSE) != 0; |
|
|
} |
|
|
|
|
|
/* Check whether the given access control is enforce mode. */ |
|
|
bool CheckCCSEnforce(const unsigned int index) |
|
|
{ |
|
|
return CheckCCSFlags(index) == 3; |
|
|
} |
|
|
|
|
|
bool CheckDomainQuota(struct domain_info * const domain) |
|
|
{ |
|
|
unsigned int count = 0; |
|
|
struct acl_info *ptr; |
|
|
if (!domain) return 1; |
|
|
list1_for_each_entry(ptr, &domain->acl_info_list, list) { |
|
|
if (!ptr->is_deleted) count++; |
|
|
} |
|
|
if (count < CheckCCSFlags(CCS_TOMOYO_MAX_ACCEPT_ENTRY)) return 1; |
|
|
if (!domain->quota_warned) { |
|
|
domain->quota_warned = 1; |
|
|
printk("TOMOYO-WARNING: Domain '%s' has so many ACLs to hold. Stopped learning mode.\n", domain->domainname->name); |
|
|
} |
|
|
return 0; |
|
|
} |
|
|
|
|
|
/* Check whether the given access control is learning mode. */ |
|
|
bool CheckCCSAccept(const unsigned int index, struct domain_info * const domain) |
|
849 |
{ |
{ |
850 |
if (CheckCCSFlags(index) != 1) return 0; |
if (is_enforce) |
851 |
return CheckDomainQuota(domain); |
return "ERROR"; |
852 |
|
else |
853 |
|
return "WARNING"; |
854 |
} |
} |
855 |
|
|
856 |
static struct profile *FindOrAssignNewProfile(const unsigned int profile) |
/** |
857 |
|
* ccs_can_sleep - Check whether it is permitted to do operations that may sleep. |
858 |
|
* |
859 |
|
* Returns true if it is permitted to do operations that may sleep, |
860 |
|
* false otherwise. |
861 |
|
* |
862 |
|
* TOMOYO Linux supports interactive enforcement that lets processes |
863 |
|
* wait for the administrator's decision. |
864 |
|
* All hooks but the one for ccs_may_autobind() are inserted where |
865 |
|
* it is permitted to do operations that may sleep. |
866 |
|
* Thus, this warning should not happen. |
867 |
|
*/ |
868 |
|
bool ccs_can_sleep(void) |
869 |
{ |
{ |
870 |
static DEFINE_MUTEX(profile_lock); |
static u8 count = 20; |
871 |
struct profile *ptr = NULL; |
if (likely(!in_interrupt())) |
872 |
mutex_lock(&profile_lock); |
return true; |
873 |
if (profile < MAX_PROFILES && (ptr = profile_ptr[profile]) == NULL) { |
if (count) { |
874 |
if ((ptr = alloc_element(sizeof(*ptr))) != NULL) { |
count--; |
875 |
int i; |
printk(KERN_ERR "BUG: sleeping function called " |
876 |
for (i = 0; i < CCS_MAX_CONTROL_INDEX; i++) ptr->value[i] = ccs_control_array[i].current_value; |
"from invalid context.\n"); |
877 |
mb(); /* Avoid out-of-order execution. */ |
dump_stack(); |
|
profile_ptr[profile] = ptr; |
|
|
} |
|
878 |
} |
} |
879 |
mutex_unlock(&profile_lock); |
return false; |
|
return ptr; |
|
880 |
} |
} |
881 |
|
|
882 |
/* #define ALT_EXEC */ |
/** |
883 |
|
* ccs_check_flags - Check mode for specified functionality. |
884 |
static int SetProfile(struct io_buffer *head) |
* |
885 |
|
* @domain: Pointer to "struct ccs_domain_info". NULL for ccs_current_domain(). |
886 |
|
* @index: The functionality to check mode. |
887 |
|
* |
888 |
|
* Returns the mode of specified functionality. |
889 |
|
*/ |
890 |
|
unsigned int ccs_check_flags(const struct ccs_domain_info *domain, |
891 |
|
const u8 index) |
892 |
{ |
{ |
893 |
char *data = head->write_buf; |
u8 profile; |
894 |
unsigned int i, value; |
if (!domain) |
895 |
char *cp; |
domain = ccs_current_domain(); |
896 |
struct profile *profile; |
profile = domain->profile; |
897 |
if (!isRoot()) return -EPERM; |
return ccs_policy_loaded && index < CCS_MAX_CONTROL_INDEX |
898 |
i = simple_strtoul(data, &cp, 10); |
#if CCS_MAX_PROFILES != 256 |
899 |
if (data != cp) { |
&& profile < CCS_MAX_PROFILES |
|
if (*cp != '-') return -EINVAL; |
|
|
data= cp + 1; |
|
|
} |
|
|
profile = FindOrAssignNewProfile(i); |
|
|
if (!profile) return -EINVAL; |
|
|
cp = strchr(data, '='); |
|
|
if (!cp) return -EINVAL; |
|
|
*cp = '\0'; |
|
|
UpdateCounter(CCS_UPDATES_COUNTER_PROFILE); |
|
|
if (strcmp(data, ccs_control_array[CCS_PROFILE_COMMENT].keyword) == 0) { |
|
|
profile->comment = SaveName(cp + 1); |
|
|
return 0; |
|
|
} |
|
|
#ifdef ALT_EXEC |
|
|
#ifdef CONFIG_TOMOYO |
|
|
if (strcmp(data, ccs_control_array[CCS_TOMOYO_ALT_EXEC].keyword) == 0) { |
|
|
cp++; |
|
|
if (*cp && !IsCorrectPath(cp, 1, -1, -1, __FUNCTION__)) cp = ""; |
|
|
profile->alt_exec = SaveName(cp); |
|
|
return 0; |
|
|
} |
|
|
#endif |
|
|
#endif |
|
|
if (sscanf(cp + 1, "%u", &value) != 1) return -EINVAL; |
|
|
#ifdef CONFIG_TOMOYO |
|
|
if (strncmp(data, KEYWORD_MAC_FOR_CAPABILITY, KEYWORD_MAC_FOR_CAPABILITY_LEN) == 0) { |
|
|
return SetCapabilityStatus(data + KEYWORD_MAC_FOR_CAPABILITY_LEN, value, i); |
|
|
} |
|
900 |
#endif |
#endif |
901 |
for (i = 0; i < CCS_MAX_CONTROL_INDEX; i++) { |
&& ccs_profile_ptr[profile] ? |
902 |
if (strcmp(data, ccs_control_array[i].keyword)) continue; |
ccs_profile_ptr[profile]->value[index] : 0; |
|
if (value > ccs_control_array[i].max_value) value = ccs_control_array[i].max_value; |
|
|
profile->value[i] = value; |
|
|
return 0; |
|
|
} |
|
|
return -EINVAL; |
|
903 |
} |
} |
904 |
|
|
905 |
static int ReadProfile(struct io_buffer *head) |
/** |
906 |
|
* ccs_check_capability_flags - Check mode for specified capability. |
907 |
|
* |
908 |
|
* @domain: Pointer to "struct ccs_domain_info". NULL for ccs_current_domain(). |
909 |
|
* @index: The capability to check mode. |
910 |
|
* |
911 |
|
* Returns the mode of specified capability. |
912 |
|
*/ |
913 |
|
static u8 ccs_check_capability_flags(const struct ccs_domain_info *domain, |
914 |
|
const u8 index) |
915 |
{ |
{ |
916 |
if (!head->read_eof) { |
const u8 profile = domain ? domain->profile : |
917 |
if (!isRoot()) return -EPERM; |
ccs_current_domain()->profile; |
918 |
if (!head->read_var2) { |
return ccs_policy_loaded && index < CCS_MAX_CAPABILITY_INDEX |
919 |
int step; |
#if CCS_MAX_PROFILES != 256 |
920 |
for (step = head->read_step; step < MAX_PROFILES * CCS_MAX_CONTROL_INDEX; step++) { |
&& profile < CCS_MAX_PROFILES |
|
const int i = step / CCS_MAX_CONTROL_INDEX, j = step % CCS_MAX_CONTROL_INDEX; |
|
|
const struct profile *profile = profile_ptr[i]; |
|
|
head->read_step = step; |
|
|
if (!profile) continue; |
|
|
switch (j) { |
|
|
case -1: /* Dummy */ |
|
|
#ifndef CONFIG_SAKURA |
|
|
case CCS_SAKURA_DENY_CONCEAL_MOUNT: |
|
|
case CCS_SAKURA_RESTRICT_CHROOT: |
|
|
case CCS_SAKURA_RESTRICT_MOUNT: |
|
|
case CCS_SAKURA_RESTRICT_UNMOUNT: |
|
|
case CCS_SAKURA_RESTRICT_PIVOT_ROOT: |
|
|
case CCS_SAKURA_RESTRICT_AUTOBIND: |
|
921 |
#endif |
#endif |
922 |
#ifndef CONFIG_TOMOYO |
&& ccs_profile_ptr[profile] ? |
923 |
case CCS_TOMOYO_MAC_FOR_FILE: |
ccs_profile_ptr[profile]->capability_value[index] : 0; |
|
case CCS_TOMOYO_MAC_FOR_ARGV0: |
|
|
case CCS_TOMOYO_MAC_FOR_ENV: |
|
|
case CCS_TOMOYO_MAC_FOR_NETWORK: |
|
|
case CCS_TOMOYO_MAC_FOR_SIGNAL: |
|
|
case CCS_TOMOYO_MAX_ACCEPT_ENTRY: |
|
|
case CCS_TOMOYO_MAX_GRANT_LOG: |
|
|
case CCS_TOMOYO_MAX_REJECT_LOG: |
|
|
case CCS_TOMOYO_VERBOSE: |
|
|
#endif |
|
|
#ifndef ALT_EXEC |
|
|
case CCS_TOMOYO_ALT_EXEC: |
|
|
case CCS_SLEEP_PERIOD: |
|
|
#endif |
|
|
continue; |
|
|
} |
|
|
if (j == CCS_PROFILE_COMMENT) { |
|
|
if (io_printf(head, "%u-%s=%s\n", i, ccs_control_array[CCS_PROFILE_COMMENT].keyword, profile->comment ? profile->comment->name : "")) break; |
|
|
} else if (j == CCS_TOMOYO_ALT_EXEC) { |
|
|
const struct path_info *alt_exec = profile->alt_exec; |
|
|
if (io_printf(head, "%u-%s=%s\n", i, ccs_control_array[CCS_TOMOYO_ALT_EXEC].keyword, alt_exec ? alt_exec->name : "")) break; |
|
|
} else { |
|
|
if (io_printf(head, "%u-%s=%u\n", i, ccs_control_array[j].keyword, profile->value[j])) break; |
|
|
} |
|
|
} |
|
|
if (step == MAX_PROFILES * CCS_MAX_CONTROL_INDEX) { |
|
|
head->read_var2 = (void *) ""; |
|
|
head->read_step = 0; |
|
|
} |
|
|
} |
|
|
if (head->read_var2) { |
|
|
#ifdef CONFIG_TOMOYO |
|
|
if (ReadCapabilityStatus(head) == 0) |
|
|
#endif |
|
|
head->read_eof = 1; |
|
|
} |
|
|
} |
|
|
return 0; |
|
924 |
} |
} |
925 |
|
|
926 |
/************************* POLICY MANAGER HANDLER *************************/ |
/** |
927 |
|
* ccs_cap2keyword - Convert capability operation to capability name. |
928 |
struct policy_manager_entry { |
* |
929 |
struct list1_head list; |
* @operation: The capability index. |
930 |
const struct path_info *manager; |
* |
931 |
bool is_domain; |
* Returns the name of the specified capability's name. |
932 |
bool is_deleted; |
*/ |
933 |
}; |
const char *ccs_cap2keyword(const u8 operation) |
|
|
|
|
static LIST1_HEAD(policy_manager_list); |
|
|
|
|
|
static int AddManagerEntry(const char *manager, const bool is_delete) |
|
934 |
{ |
{ |
935 |
struct policy_manager_entry *new_entry, *ptr; |
return operation < CCS_MAX_CAPABILITY_INDEX |
936 |
static DEFINE_MUTEX(lock); |
? ccs_capability_control_keyword[operation] : NULL; |
|
const struct path_info *saved_manager; |
|
|
int error = -ENOMEM; |
|
|
bool is_domain = 0; |
|
|
if (!isRoot()) return -EPERM; |
|
|
if (IsDomainDef(manager)) { |
|
|
if (!IsCorrectDomain(manager, __FUNCTION__)) return -EINVAL; |
|
|
is_domain = 1; |
|
|
} else { |
|
|
if (!IsCorrectPath(manager, 1, -1, -1, __FUNCTION__)) return -EINVAL; |
|
|
} |
|
|
if ((saved_manager = SaveName(manager)) == NULL) return -ENOMEM; |
|
|
mutex_lock(&lock); |
|
|
list1_for_each_entry(ptr, &policy_manager_list, list) { |
|
|
if (ptr->manager == saved_manager) { |
|
|
ptr->is_deleted = is_delete; |
|
|
error = 0; |
|
|
goto out; |
|
|
} |
|
|
} |
|
|
if (is_delete) { |
|
|
error = -ENOENT; |
|
|
goto out; |
|
|
} |
|
|
if ((new_entry = alloc_element(sizeof(*new_entry))) == NULL) goto out; |
|
|
new_entry->manager = saved_manager; |
|
|
new_entry->is_domain = is_domain; |
|
|
list1_add_tail_mb(&new_entry->list, &policy_manager_list); |
|
|
error = 0; |
|
|
out: |
|
|
mutex_unlock(&lock); |
|
|
if (!error) UpdateCounter(CCS_UPDATES_COUNTER_MANAGER); |
|
|
return error; |
|
937 |
} |
} |
938 |
|
|
939 |
static int AddManagerPolicy(struct io_buffer *head) |
/** |
940 |
|
* ccs_init_request_info - Initialize "struct ccs_request_info" members. |
941 |
|
* |
942 |
|
* @r: Pointer to "struct ccs_request_info" to initialize. |
943 |
|
* @domain: Pointer to "struct ccs_domain_info". NULL for ccs_current_domain(). |
944 |
|
* @index: Index number of functionality. |
945 |
|
*/ |
946 |
|
void ccs_init_request_info(struct ccs_request_info *r, |
947 |
|
struct ccs_domain_info *domain, const u8 index) |
948 |
{ |
{ |
949 |
const char *data = head->write_buf; |
memset(r, 0, sizeof(*r)); |
950 |
bool is_delete = 0; |
if (!domain) |
951 |
if (!isRoot()) return -EPERM; |
domain = ccs_current_domain(); |
952 |
if (strncmp(data, KEYWORD_DELETE, KEYWORD_DELETE_LEN) == 0) { |
r->domain = domain; |
953 |
data += KEYWORD_DELETE_LEN; |
r->profile = domain->profile; |
954 |
is_delete = 1; |
if (index < CCS_MAX_CONTROL_INDEX) |
955 |
} |
r->mode = ccs_check_flags(domain, index); |
956 |
return AddManagerEntry(data, is_delete); |
else |
957 |
|
r->mode = ccs_check_capability_flags(domain, index |
958 |
|
- CCS_MAX_CONTROL_INDEX); |
959 |
} |
} |
960 |
|
|
961 |
static int ReadManagerPolicy(struct io_buffer *head) |
/** |
962 |
|
* ccs_verbose_mode - Check whether TOMOYO is verbose mode. |
963 |
|
* |
964 |
|
* @domain: Pointer to "struct ccs_domain_info". NULL for ccs_current_domain(). |
965 |
|
* |
966 |
|
* Returns true if domain policy violation warning should be printed to |
967 |
|
* console. |
968 |
|
*/ |
969 |
|
bool ccs_verbose_mode(const struct ccs_domain_info *domain) |
970 |
{ |
{ |
971 |
struct list1_head *pos; |
return ccs_check_flags(domain, CCS_VERBOSE) != 0; |
|
if (head->read_eof) return 0; |
|
|
if (!isRoot()) return -EPERM; |
|
|
list1_for_each_cookie(pos, head->read_var2, &policy_manager_list) { |
|
|
struct policy_manager_entry *ptr; |
|
|
ptr = list1_entry(pos, struct policy_manager_entry, list); |
|
|
if (ptr->is_deleted) continue; |
|
|
if (io_printf(head, "%s\n", ptr->manager->name)) return 0; |
|
|
} |
|
|
head->read_eof = 1; |
|
|
return 0; |
|
972 |
} |
} |
973 |
|
|
974 |
/* Check whether the current process is a policy manager. */ |
/** |
975 |
static int IsPolicyManager(void) |
* ccs_domain_quota_ok - Check for domain's quota. |
976 |
|
* |
977 |
|
* @r: Pointer to "struct ccs_request_info". |
978 |
|
* |
979 |
|
* Returns true if the domain is not exceeded quota, false otherwise. |
980 |
|
* |
981 |
|
* Caller holds ccs_read_lock(). |
982 |
|
*/ |
983 |
|
bool ccs_domain_quota_ok(struct ccs_request_info *r) |
984 |
{ |
{ |
985 |
struct policy_manager_entry *ptr; |
unsigned int count = 0; |
986 |
const char *exe; |
struct ccs_domain_info *domain = r->domain; |
987 |
const struct path_info *domainname = current->domain_info->domainname; |
struct ccs_acl_info *ptr; |
988 |
bool found = 0; |
ccs_check_read_lock(); |
989 |
if (!sbin_init_started) return 1; |
if (r->mode != 1) |
990 |
list1_for_each_entry(ptr, &policy_manager_list, list) { |
return false; |
991 |
if (!ptr->is_deleted && ptr->is_domain && !pathcmp(domainname, ptr->manager)) return 1; |
if (!domain) |
992 |
} |
return true; |
993 |
if ((exe = GetEXE()) == NULL) return 0; |
list_for_each_entry_rcu(ptr, &domain->acl_info_list, list) { |
994 |
list1_for_each_entry(ptr, &policy_manager_list, list) { |
if (ptr->is_deleted) |
995 |
if (!ptr->is_deleted && !ptr->is_domain && !strcmp(exe, ptr->manager->name)) { |
continue; |
996 |
found = 1; |
switch (ptr->type) { |
997 |
|
struct ccs_single_path_acl_record *acl1; |
998 |
|
struct ccs_double_path_acl_record *acl2; |
999 |
|
u16 perm; |
1000 |
|
case CCS_TYPE_SINGLE_PATH_ACL: |
1001 |
|
acl1 = container_of(ptr, |
1002 |
|
struct ccs_single_path_acl_record, |
1003 |
|
head); |
1004 |
|
perm = acl1->perm; |
1005 |
|
if (perm & (1 << CCS_TYPE_EXECUTE_ACL)) |
1006 |
|
count++; |
1007 |
|
if (perm & ((1 << CCS_TYPE_READ_ACL) | |
1008 |
|
(1 << CCS_TYPE_WRITE_ACL))) |
1009 |
|
count++; |
1010 |
|
if (perm & (1 << CCS_TYPE_CREATE_ACL)) |
1011 |
|
count++; |
1012 |
|
if (perm & (1 << CCS_TYPE_UNLINK_ACL)) |
1013 |
|
count++; |
1014 |
|
if (perm & (1 << CCS_TYPE_MKDIR_ACL)) |
1015 |
|
count++; |
1016 |
|
if (perm & (1 << CCS_TYPE_RMDIR_ACL)) |
1017 |
|
count++; |
1018 |
|
if (perm & (1 << CCS_TYPE_MKFIFO_ACL)) |
1019 |
|
count++; |
1020 |
|
if (perm & (1 << CCS_TYPE_MKSOCK_ACL)) |
1021 |
|
count++; |
1022 |
|
if (perm & (1 << CCS_TYPE_MKBLOCK_ACL)) |
1023 |
|
count++; |
1024 |
|
if (perm & (1 << CCS_TYPE_MKCHAR_ACL)) |
1025 |
|
count++; |
1026 |
|
if (perm & (1 << CCS_TYPE_TRUNCATE_ACL)) |
1027 |
|
count++; |
1028 |
|
if (perm & (1 << CCS_TYPE_SYMLINK_ACL)) |
1029 |
|
count++; |
1030 |
|
if (perm & (1 << CCS_TYPE_REWRITE_ACL)) |
1031 |
|
count++; |
1032 |
break; |
break; |
1033 |
} |
case CCS_TYPE_DOUBLE_PATH_ACL: |
1034 |
} |
acl2 = container_of(ptr, |
1035 |
if (!found) { /* Reduce error messages. */ |
struct ccs_double_path_acl_record, |
1036 |
static pid_t last_pid = 0; |
head); |
1037 |
const pid_t pid = current->pid; |
perm = acl2->perm; |
1038 |
if (last_pid != pid) { |
if (perm & (1 << CCS_TYPE_LINK_ACL)) |
1039 |
printk("%s ( %s ) is not permitted to update policies.\n", domainname->name, exe); |
count++; |
1040 |
last_pid = pid; |
if (perm & (1 << CCS_TYPE_RENAME_ACL)) |
1041 |
} |
count++; |
|
} |
|
|
ccs_free(exe); |
|
|
return found; |
|
|
} |
|
|
|
|
|
#ifdef CONFIG_TOMOYO |
|
|
|
|
|
/************************* DOMAIN POLICY HANDLER *************************/ |
|
|
|
|
|
static char *FindConditionPart(char *data) |
|
|
{ |
|
|
char *cp = strstr(data, " if "), *cp2; |
|
|
if (cp) { |
|
|
while ((cp2 = strstr(cp + 3, " if ")) != NULL) cp = cp2; |
|
|
*cp++ = '\0'; |
|
|
} |
|
|
return cp; |
|
|
} |
|
|
|
|
|
static int AddDomainPolicy(struct io_buffer *head) |
|
|
{ |
|
|
char *data = head->write_buf; |
|
|
struct domain_info *domain = head->write_var1; |
|
|
bool is_delete = 0, is_select = 0, is_undelete = 0; |
|
|
unsigned int profile; |
|
|
const struct condition_list *cond = NULL; |
|
|
char *cp; |
|
|
if (!isRoot()) return -EPERM; |
|
|
if (strncmp(data, KEYWORD_DELETE, KEYWORD_DELETE_LEN) == 0) { |
|
|
data += KEYWORD_DELETE_LEN; |
|
|
is_delete = 1; |
|
|
} else if (strncmp(data, KEYWORD_SELECT, KEYWORD_SELECT_LEN) == 0) { |
|
|
data += KEYWORD_SELECT_LEN; |
|
|
is_select = 1; |
|
|
} else if (strncmp(data, KEYWORD_UNDELETE, KEYWORD_UNDELETE_LEN) == 0) { |
|
|
data += KEYWORD_UNDELETE_LEN; |
|
|
is_undelete = 1; |
|
|
} |
|
|
UpdateCounter(CCS_UPDATES_COUNTER_DOMAIN_POLICY); |
|
|
if (IsDomainDef(data)) { |
|
|
if (is_delete) { |
|
|
DeleteDomain(data); |
|
|
domain = NULL; |
|
|
} else if (is_select) { |
|
|
domain = FindDomain(data); |
|
|
} else if (is_undelete) { |
|
|
domain = UndeleteDomain(data); |
|
|
} else { |
|
|
domain = FindOrAssignNewDomain(data, 0); |
|
|
} |
|
|
head->write_var1 = domain; |
|
|
return 0; |
|
|
} |
|
|
if (!domain) return -EINVAL; |
|
|
|
|
|
if (sscanf(data, KEYWORD_USE_PROFILE "%u", &profile) == 1 && profile < MAX_PROFILES) { |
|
|
if (profile_ptr[profile] || !sbin_init_started) domain->profile = (u8) profile; |
|
|
return 0; |
|
|
} |
|
|
cp = FindConditionPart(data); |
|
|
if (cp && (cond = FindOrAssignNewCondition(cp)) == NULL) return -EINVAL; |
|
|
if (strncmp(data, KEYWORD_ALLOW_CAPABILITY, KEYWORD_ALLOW_CAPABILITY_LEN) == 0) { |
|
|
return AddCapabilityPolicy(data + KEYWORD_ALLOW_CAPABILITY_LEN, domain, cond, is_delete); |
|
|
} else if (strncmp(data, KEYWORD_ALLOW_NETWORK, KEYWORD_ALLOW_NETWORK_LEN) == 0) { |
|
|
return AddNetworkPolicy(data + KEYWORD_ALLOW_NETWORK_LEN, domain, cond, is_delete); |
|
|
} else if (strncmp(data, KEYWORD_ALLOW_SIGNAL, KEYWORD_ALLOW_SIGNAL_LEN) == 0) { |
|
|
return AddSignalPolicy(data + KEYWORD_ALLOW_SIGNAL_LEN, domain, cond, is_delete); |
|
|
} else if (strncmp(data, KEYWORD_ALLOW_ARGV0, KEYWORD_ALLOW_ARGV0_LEN) == 0) { |
|
|
return AddArgv0Policy(data + KEYWORD_ALLOW_ARGV0_LEN, domain, cond, is_delete); |
|
|
} else if (strncmp(data, KEYWORD_ALLOW_ENV, KEYWORD_ALLOW_ENV_LEN) == 0) { |
|
|
return AddEnvPolicy(data + KEYWORD_ALLOW_ENV_LEN, domain, cond, is_delete); |
|
|
} else { |
|
|
return AddFilePolicy(data, domain, cond, is_delete); |
|
|
} |
|
|
return -EINVAL; |
|
|
} |
|
|
|
|
|
static int ReadDomainPolicy(struct io_buffer *head) |
|
|
{ |
|
|
struct list1_head *dpos; |
|
|
struct list1_head *apos; |
|
|
if (head->read_eof) return 0; |
|
|
if (head->read_step == 0) { |
|
|
if (!isRoot()) return -EPERM; |
|
|
head->read_step = 1; |
|
|
} |
|
|
list1_for_each_cookie(dpos, head->read_var1, &domain_list) { |
|
|
struct domain_info *domain; |
|
|
domain = list1_entry(dpos, struct domain_info, list); |
|
|
if (head->read_step != 1) goto acl_loop; |
|
|
if (domain->is_deleted) continue; |
|
|
if (io_printf(head, "%s\n" KEYWORD_USE_PROFILE "%u\n%s\n", domain->domainname->name, domain->profile, domain->quota_warned ? "quota_exceeded\n" : "")) return 0; |
|
|
head->read_step = 2; |
|
|
acl_loop: ; |
|
|
if (head->read_step == 3) goto tail_mark; |
|
|
list1_for_each_cookie(apos, head->read_var2, &domain->acl_info_list) { |
|
|
struct acl_info *ptr; |
|
|
int pos; |
|
|
u8 acl_type; |
|
|
ptr = list1_entry(apos, struct acl_info, list); |
|
|
if (ptr->is_deleted) continue; |
|
|
pos = head->read_avail; |
|
|
acl_type = ptr->type; |
|
|
if (acl_type == TYPE_FILE_ACL) { |
|
|
struct file_acl_record *ptr2 = container_of(ptr, struct file_acl_record, head); |
|
|
const unsigned char b = ptr2->u_is_group; |
|
|
if (io_printf(head, "%d %s%s", ptr2->perm, |
|
|
b ? "@" : "", |
|
|
b ? ptr2->u.group->group_name->name : ptr2->u.filename->name)) goto print_acl_rollback; |
|
|
} else if (acl_type == TYPE_ARGV0_ACL) { |
|
|
struct argv0_acl_record *ptr2 = container_of(ptr, struct argv0_acl_record, head); |
|
|
if (io_printf(head, KEYWORD_ALLOW_ARGV0 "%s %s", |
|
|
ptr2->filename->name, ptr2->argv0->name)) goto print_acl_rollback; |
|
|
} else if (acl_type == TYPE_ENV_ACL) { |
|
|
struct env_acl_record *ptr2 = container_of(ptr, struct env_acl_record, head); |
|
|
if (io_printf(head, KEYWORD_ALLOW_ENV "%s", ptr2->env->name)) goto print_acl_rollback; |
|
|
} else if (acl_type == TYPE_CAPABILITY_ACL) { |
|
|
struct capability_acl_record *ptr2 = container_of(ptr, struct capability_acl_record, head); |
|
|
if (io_printf(head, KEYWORD_ALLOW_CAPABILITY "%s", capability2keyword(ptr2->capability))) goto print_acl_rollback; |
|
|
} else if (acl_type == TYPE_IP_NETWORK_ACL) { |
|
|
struct ip_network_acl_record *ptr2 = container_of(ptr, struct ip_network_acl_record, head); |
|
|
if (io_printf(head, KEYWORD_ALLOW_NETWORK "%s ", network2keyword(ptr2->operation_type))) goto print_acl_rollback; |
|
|
switch (ptr2->record_type) { |
|
|
case IP_RECORD_TYPE_ADDRESS_GROUP: |
|
|
if (io_printf(head, "@%s", ptr2->u.group->group_name->name)) goto print_acl_rollback; |
|
|
break; |
|
|
case IP_RECORD_TYPE_IPv4: |
|
|
{ |
|
|
const u32 min_address = ptr2->u.ipv4.min, max_address = ptr2->u.ipv4.max; |
|
|
if (io_printf(head, "%u.%u.%u.%u", HIPQUAD(min_address))) goto print_acl_rollback; |
|
|
if (min_address != max_address && io_printf(head, "-%u.%u.%u.%u", HIPQUAD(max_address))) goto print_acl_rollback; |
|
|
} |
|
|
break; |
|
|
case IP_RECORD_TYPE_IPv6: |
|
|
{ |
|
|
char buf[64]; |
|
|
const struct in6_addr *min_address = ptr2->u.ipv6.min, *max_address = ptr2->u.ipv6.max; |
|
|
print_ipv6(buf, sizeof(buf), min_address); |
|
|
if (io_printf(head, "%s", buf)) goto print_acl_rollback; |
|
|
if (min_address != max_address) { |
|
|
print_ipv6(buf, sizeof(buf), max_address); |
|
|
if (io_printf(head, "-%s", buf)) goto print_acl_rollback; |
|
|
} |
|
|
} |
|
|
break; |
|
|
} |
|
|
{ |
|
|
const u16 min_port = ptr2->min_port, max_port = ptr2->max_port; |
|
|
if (io_printf(head, " %u", min_port)) goto print_acl_rollback; |
|
|
if (min_port != max_port && io_printf(head, "-%u", max_port)) goto print_acl_rollback; |
|
|
} |
|
|
} else if (acl_type == TYPE_SIGNAL_ACL) { |
|
|
struct signal_acl_record *ptr2 = container_of(ptr, struct signal_acl_record, head); |
|
|
if (io_printf(head, KEYWORD_ALLOW_SIGNAL "%u %s", ptr2->sig, ptr2->domainname->name)) goto print_acl_rollback; |
|
|
} else { |
|
|
const char *keyword = acltype2keyword(acl_type); |
|
|
if (!keyword) continue; |
|
|
if (acltype2paths(acl_type) == 2) { |
|
|
struct double_acl_record *ptr2 = container_of(ptr, struct double_acl_record, head); |
|
|
const bool b0 = ptr2->u1_is_group, b1 = ptr2->u2_is_group; |
|
|
if (io_printf(head, "allow_%s %s%s %s%s", keyword, |
|
|
b0 ? "@" : "", b0 ? ptr2->u1.group1->group_name->name : ptr2->u1.filename1->name, |
|
|
b1 ? "@" : "", b1 ? ptr2->u2.group2->group_name->name : ptr2->u2.filename2->name)) goto print_acl_rollback; |
|
|
} else { |
|
|
struct single_acl_record *ptr2 = container_of(ptr, struct single_acl_record, head); |
|
|
const bool b = ptr2->u_is_group; |
|
|
if (io_printf(head, "allow_%s %s%s", keyword, |
|
|
b ? "@" : "", b ? ptr2->u.group->group_name->name : ptr2->u.filename->name)) goto print_acl_rollback; |
|
|
} |
|
|
} |
|
|
if (DumpCondition(head, ptr->cond)) { |
|
|
print_acl_rollback: ; |
|
|
head->read_avail = pos; |
|
|
return 0; |
|
|
} |
|
|
} |
|
|
head->read_step = 3; |
|
|
tail_mark: ; |
|
|
if (io_printf(head, "\n")) return 0; |
|
|
head->read_step = 1; |
|
|
} |
|
|
head->read_eof = 1; |
|
|
return 0; |
|
|
} |
|
|
|
|
|
#endif |
|
|
|
|
|
static int UpdateDomainProfile(struct io_buffer *head) |
|
|
{ |
|
|
char *data = head->write_buf; |
|
|
char *cp = strchr(data, ' '); |
|
|
struct domain_info *domain; |
|
|
unsigned int profile; |
|
|
if (!isRoot()) return -EPERM; |
|
|
if (!cp) return -EINVAL; |
|
|
*cp = '\0'; |
|
|
domain = FindDomain(cp + 1); |
|
|
profile = simple_strtoul(data, NULL, 10); |
|
|
if (domain && profile < MAX_PROFILES && (profile_ptr[profile] || !sbin_init_started)) domain->profile = (u8) profile; |
|
|
UpdateCounter(CCS_UPDATES_COUNTER_DOMAIN_POLICY); |
|
|
return 0; |
|
|
} |
|
|
|
|
|
static int ReadDomainProfile(struct io_buffer *head) |
|
|
{ |
|
|
struct list1_head *pos; |
|
|
if (head->read_eof) return 0; |
|
|
if (!isRoot()) return -EPERM; |
|
|
list1_for_each_cookie(pos, head->read_var1, &domain_list) { |
|
|
struct domain_info *domain; |
|
|
domain = list1_entry(pos, struct domain_info, list); |
|
|
if (domain->is_deleted) continue; |
|
|
if (io_printf(head, "%u %s\n", domain->profile, domain->domainname->name)) return 0; |
|
|
} |
|
|
head->read_eof = 1; |
|
|
return 0; |
|
|
} |
|
|
|
|
|
static int WritePID(struct io_buffer *head) |
|
|
{ |
|
|
head->read_step = (int) simple_strtoul(head->write_buf, NULL, 10); |
|
|
head->read_eof = 0; |
|
|
return 0; |
|
|
} |
|
|
|
|
|
static int ReadPID(struct io_buffer *head) |
|
|
{ |
|
|
if (head->read_avail == 0 && !head->read_eof) { |
|
|
const int pid = head->read_step; |
|
|
struct task_struct *p; |
|
|
struct domain_info *domain = NULL; |
|
|
/***** CRITICAL SECTION START *****/ |
|
|
read_lock(&tasklist_lock); |
|
|
p = find_task_by_pid(pid); |
|
|
if (p) domain = p->domain_info; |
|
|
read_unlock(&tasklist_lock); |
|
|
/***** CRITICAL SECTION END *****/ |
|
|
if (domain) io_printf(head, "%d %u %s", pid, domain->profile, domain->domainname->name); |
|
|
head->read_eof = 1; |
|
|
} |
|
|
return 0; |
|
|
} |
|
|
|
|
|
/************************* EXCEPTION POLICY HANDLER *************************/ |
|
|
|
|
|
#ifdef CONFIG_TOMOYO |
|
|
|
|
|
static int AddExceptionPolicy(struct io_buffer *head) |
|
|
{ |
|
|
char *data = head->write_buf; |
|
|
bool is_delete = 0; |
|
|
if (!isRoot()) return -EPERM; |
|
|
UpdateCounter(CCS_UPDATES_COUNTER_EXCEPTION_POLICY); |
|
|
if (strncmp(data, KEYWORD_DELETE, KEYWORD_DELETE_LEN) == 0) { |
|
|
data += KEYWORD_DELETE_LEN; |
|
|
is_delete = 1; |
|
|
} |
|
|
if (strncmp(data, KEYWORD_KEEP_DOMAIN, KEYWORD_KEEP_DOMAIN_LEN) == 0) { |
|
|
return AddDomainKeeperPolicy(data + KEYWORD_KEEP_DOMAIN_LEN, 0, is_delete); |
|
|
} else if (strncmp(data, KEYWORD_NO_KEEP_DOMAIN, KEYWORD_NO_KEEP_DOMAIN_LEN) == 0) { |
|
|
return AddDomainKeeperPolicy(data + KEYWORD_NO_KEEP_DOMAIN_LEN, 1, is_delete); |
|
|
} else if (strncmp(data, KEYWORD_INITIALIZE_DOMAIN, KEYWORD_INITIALIZE_DOMAIN_LEN) == 0) { |
|
|
return AddDomainInitializerPolicy(data + KEYWORD_INITIALIZE_DOMAIN_LEN, 0, is_delete); |
|
|
} else if (strncmp(data, KEYWORD_NO_INITIALIZE_DOMAIN, KEYWORD_NO_INITIALIZE_DOMAIN_LEN) == 0) { |
|
|
return AddDomainInitializerPolicy(data + KEYWORD_NO_INITIALIZE_DOMAIN_LEN, 1, is_delete); |
|
|
} else if (strncmp(data, KEYWORD_ALIAS, KEYWORD_ALIAS_LEN) == 0) { |
|
|
return AddAliasPolicy(data + KEYWORD_ALIAS_LEN, is_delete); |
|
|
} else if (strncmp(data, KEYWORD_AGGREGATOR, KEYWORD_AGGREGATOR_LEN) == 0) { |
|
|
return AddAggregatorPolicy(data + KEYWORD_AGGREGATOR_LEN, is_delete); |
|
|
} else if (strncmp(data, KEYWORD_ALLOW_READ, KEYWORD_ALLOW_READ_LEN) == 0) { |
|
|
return AddGloballyReadablePolicy(data + KEYWORD_ALLOW_READ_LEN, is_delete); |
|
|
} else if (strncmp(data, KEYWORD_ALLOW_ENV, KEYWORD_ALLOW_ENV_LEN) == 0) { |
|
|
return AddGloballyUsableEnvPolicy(data + KEYWORD_ALLOW_ENV_LEN, is_delete); |
|
|
} else if (strncmp(data, KEYWORD_FILE_PATTERN, KEYWORD_FILE_PATTERN_LEN) == 0) { |
|
|
return AddPatternPolicy(data + KEYWORD_FILE_PATTERN_LEN, is_delete); |
|
|
} else if (strncmp(data, KEYWORD_PATH_GROUP, KEYWORD_PATH_GROUP_LEN) == 0) { |
|
|
return AddPathGroupPolicy(data + KEYWORD_PATH_GROUP_LEN, is_delete); |
|
|
} else if (strncmp(data, KEYWORD_DENY_REWRITE, KEYWORD_DENY_REWRITE_LEN) == 0) { |
|
|
return AddNoRewritePolicy(data + KEYWORD_DENY_REWRITE_LEN, is_delete); |
|
|
} else if (strncmp(data, KEYWORD_ADDRESS_GROUP, KEYWORD_ADDRESS_GROUP_LEN) == 0) { |
|
|
return AddAddressGroupPolicy(data + KEYWORD_ADDRESS_GROUP_LEN, is_delete); |
|
|
} |
|
|
return -EINVAL; |
|
|
} |
|
|
|
|
|
static int ReadExceptionPolicy(struct io_buffer *head) |
|
|
{ |
|
|
if (!head->read_eof) { |
|
|
switch (head->read_step) { |
|
|
case 0: |
|
|
if (!isRoot()) return -EPERM; |
|
|
head->read_var2 = NULL; head->read_step = 1; |
|
|
case 1: |
|
|
if (ReadDomainKeeperPolicy(head)) break; |
|
|
head->read_var2 = NULL; head->read_step = 2; |
|
|
case 2: |
|
|
if (ReadGloballyReadablePolicy(head)) break; |
|
|
head->read_var2 = NULL; head->read_step = 3; |
|
|
case 3: |
|
|
if (ReadGloballyUsableEnvPolicy(head)) break; |
|
|
head->read_var2 = NULL; head->read_step = 4; |
|
|
case 4: |
|
|
if (ReadDomainInitializerPolicy(head)) break; |
|
|
head->read_var2 = NULL; head->read_step = 5; |
|
|
case 5: |
|
|
if (ReadAliasPolicy(head)) break; |
|
|
head->read_var2 = NULL; head->read_step = 6; |
|
|
case 6: |
|
|
if (ReadAggregatorPolicy(head)) break; |
|
|
head->read_var2 = NULL; head->read_step = 7; |
|
|
case 7: |
|
|
if (ReadPatternPolicy(head)) break; |
|
|
head->read_var2 = NULL; head->read_step = 8; |
|
|
case 8: |
|
|
if (ReadNoRewritePolicy(head)) break; |
|
|
head->read_var2 = NULL; head->read_step = 9; |
|
|
case 9: |
|
|
if (ReadPathGroupPolicy(head)) break; |
|
|
head->read_var1 = head->read_var2 = NULL; head->read_step = 10; |
|
|
case 10: |
|
|
if (ReadAddressGroupPolicy(head)) break; |
|
|
head->read_eof = 1; |
|
1042 |
break; |
break; |
1043 |
default: |
case CCS_TYPE_EXECUTE_HANDLER: |
1044 |
return -EINVAL; |
case CCS_TYPE_DENIED_EXECUTE_HANDLER: |
|
} |
|
|
} |
|
|
return 0; |
|
|
} |
|
|
|
|
|
#endif |
|
|
|
|
|
/************************* SYSTEM POLICY HANDLER *************************/ |
|
|
|
|
|
#ifdef CONFIG_SAKURA |
|
|
|
|
|
static int AddSystemPolicy(struct io_buffer *head) |
|
|
{ |
|
|
char *data = head->write_buf; |
|
|
bool is_delete = 0; |
|
|
if (!isRoot()) return -EPERM; |
|
|
UpdateCounter(CCS_UPDATES_COUNTER_SYSTEM_POLICY); |
|
|
if (strncmp(data, KEYWORD_DELETE, KEYWORD_DELETE_LEN) == 0) { |
|
|
data += KEYWORD_DELETE_LEN; |
|
|
is_delete = 1; |
|
|
} |
|
|
if (strncmp(data, KEYWORD_ALLOW_MOUNT, KEYWORD_ALLOW_MOUNT_LEN) == 0) |
|
|
return AddMountPolicy(data + KEYWORD_ALLOW_MOUNT_LEN, is_delete); |
|
|
if (strncmp(data, KEYWORD_DENY_UNMOUNT, KEYWORD_DENY_UNMOUNT_LEN) == 0) |
|
|
return AddNoUmountPolicy(data + KEYWORD_DENY_UNMOUNT_LEN, is_delete); |
|
|
if (strncmp(data, KEYWORD_ALLOW_CHROOT, KEYWORD_ALLOW_CHROOT_LEN) == 0) |
|
|
return AddChrootPolicy(data + KEYWORD_ALLOW_CHROOT_LEN, is_delete); |
|
|
if (strncmp(data, KEYWORD_ALLOW_PIVOT_ROOT, KEYWORD_ALLOW_PIVOT_ROOT_LEN) == 0) |
|
|
return AddPivotRootPolicy(data + KEYWORD_ALLOW_PIVOT_ROOT_LEN, is_delete); |
|
|
if (strncmp(data, KEYWORD_DENY_AUTOBIND, KEYWORD_DENY_AUTOBIND_LEN) == 0) |
|
|
return AddReservedPortPolicy(data + KEYWORD_DENY_AUTOBIND_LEN, is_delete); |
|
|
return -EINVAL; |
|
|
} |
|
|
|
|
|
static int ReadSystemPolicy(struct io_buffer *head) |
|
|
{ |
|
|
if (!head->read_eof) { |
|
|
switch (head->read_step) { |
|
|
case 0: |
|
|
if (!isRoot()) return -EPERM; |
|
|
head->read_var2 = NULL; head->read_step = 1; |
|
|
case 1: |
|
|
if (ReadMountPolicy(head)) break; |
|
|
head->read_var2 = NULL; head->read_step = 2; |
|
|
case 2: |
|
|
if (ReadNoUmountPolicy(head)) break; |
|
|
head->read_var2 = NULL; head->read_step = 3; |
|
|
case 3: |
|
|
if (ReadChrootPolicy(head)) break; |
|
|
head->read_var2 = NULL; head->read_step = 4; |
|
|
case 4: |
|
|
if (ReadPivotRootPolicy(head)) break; |
|
|
head->read_var2 = NULL; head->read_step = 5; |
|
|
case 5: |
|
|
if (ReadReservedPortPolicy(head)) break; |
|
|
head->read_eof = 1; |
|
1045 |
break; |
break; |
1046 |
default: |
default: |
1047 |
return -EINVAL; |
count++; |
1048 |
} |
} |
1049 |
} |
} |
1050 |
return 0; |
if (count < ccs_check_flags(domain, CCS_MAX_ACCEPT_ENTRY)) |
1051 |
} |
return true; |
1052 |
|
if (!domain->quota_warned) { |
1053 |
#endif |
domain->quota_warned = true; |
1054 |
|
printk(KERN_WARNING "TOMOYO-WARNING: " |
1055 |
/************************* POLICY LOADER *************************/ |
"Domain '%s' has so many ACLs to hold. " |
1056 |
|
"Stopped learning mode.\n", domain->domainname->name); |
|
static int profile_loaded = 0; |
|
|
|
|
|
static const char *ccs_loader = NULL; |
|
|
|
|
|
static int __init CCS_loader_Setup(char *str) |
|
|
{ |
|
|
ccs_loader = str; |
|
|
return 0; |
|
|
} |
|
|
|
|
|
__setup("CCS_loader=", CCS_loader_Setup); |
|
|
|
|
|
void CCS_LoadPolicy(const char *filename) |
|
|
{ |
|
|
if (sbin_init_started) return; |
|
|
/* |
|
|
* Check filename is /sbin/init or /sbin/ccs-start . |
|
|
* /sbin/ccs-start is a dummy filename in case where /sbin/init can't be passed. |
|
|
* You can create /sbin/ccs-start by "ln -s /bin/true /sbin/ccs-start", for |
|
|
* only the pathname is needed to activate Mandatory Access Control. |
|
|
*/ |
|
|
if (strcmp(filename, "/sbin/init") != 0 && strcmp(filename, "/sbin/ccs-start") != 0) return; |
|
|
/* |
|
|
* Don't activate MAC if the path given by 'CCS_loader=' option doesn't exist. |
|
|
* If initrd.img includes /sbin/init but real-root-dev has not mounted on / yet, |
|
|
* activating MAC will block the system since policies are not loaded yet. |
|
|
* So let do_execve() call this function everytime. |
|
|
*/ |
|
|
{ |
|
|
struct nameidata nd; |
|
|
if (!ccs_loader) ccs_loader = "/sbin/ccs-init"; |
|
|
if (path_lookup(ccs_loader, lookup_flags, &nd)) { |
|
|
printk("Not activating Mandatory Access Control now since %s doesn't exist.\n", ccs_loader); |
|
|
return; |
|
|
} |
|
|
path_release(&nd); |
|
|
} |
|
|
if (!profile_loaded) { |
|
|
char *argv[2], *envp[3]; |
|
|
printk("Calling %s to load policy. Please wait.\n", ccs_loader); |
|
|
argv[0] = (char *) ccs_loader; |
|
|
argv[1] = NULL; |
|
|
envp[0] = "HOME=/"; |
|
|
envp[1] = "PATH=/sbin:/bin:/usr/sbin:/usr/bin"; |
|
|
envp[2] = NULL; |
|
|
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0) |
|
|
call_usermodehelper(argv[0], argv, envp, 1); |
|
|
#else |
|
|
call_usermodehelper(argv[0], argv, envp); |
|
|
#endif |
|
|
while (!profile_loaded) { |
|
|
set_current_state(TASK_INTERRUPTIBLE); |
|
|
schedule_timeout(HZ / 10); |
|
|
} |
|
|
} |
|
|
#ifdef CONFIG_SAKURA |
|
|
printk("SAKURA: 1.5.3-pre 2007/12/18\n"); |
|
|
#endif |
|
|
#ifdef CONFIG_TOMOYO |
|
|
printk("TOMOYO: 1.5.3-pre 2007/12/17\n"); |
|
|
#endif |
|
|
//if (!profile_loaded) panic("No profiles loaded. Run policy loader using 'init=' option.\n"); |
|
|
printk("Mandatory Access Control activated.\n"); |
|
|
sbin_init_started = 1; |
|
|
ccs_log_level = KERN_WARNING; |
|
|
{ /* Check all profiles currently assigned to domains are defined. */ |
|
|
struct domain_info *domain; |
|
|
list1_for_each_entry(domain, &domain_list, list) { |
|
|
const u8 profile = domain->profile; |
|
|
if (!profile_ptr[profile]) panic("Profile %u (used by '%s') not defined.\n", profile, domain->domainname->name); |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/************************* MAC Decision Delayer *************************/ |
|
|
|
|
|
static DECLARE_WAIT_QUEUE_HEAD(query_wait); |
|
|
|
|
|
static spinlock_t query_lock = SPIN_LOCK_UNLOCKED; |
|
|
|
|
|
struct query_entry { |
|
|
struct list_head list; |
|
|
char *query; |
|
|
int query_len; |
|
|
unsigned int serial; |
|
|
int timer; |
|
|
int answer; |
|
|
}; |
|
|
|
|
|
static LIST_HEAD(query_list); |
|
|
static atomic_t queryd_watcher = ATOMIC_INIT(0); |
|
|
|
|
|
int CheckSupervisor(const char *fmt, ...) |
|
|
{ |
|
|
va_list args; |
|
|
int error = -EPERM; |
|
|
int pos, len; |
|
|
static unsigned int serial = 0; |
|
|
struct query_entry *query_entry; |
|
|
if (!CheckCCSFlags(CCS_ALLOW_ENFORCE_GRACE) || !atomic_read(&queryd_watcher)) { |
|
|
#ifdef ALT_EXEC |
|
|
if ((current->tomoyo_flags & CCS_DONT_SLEEP_ON_ENFORCE_ERROR) == 0) { |
|
|
int i; |
|
|
for (i = 0; i < CheckCCSFlags(CCS_SLEEP_PERIOD); i++) { |
|
|
set_current_state(TASK_INTERRUPTIBLE); |
|
|
schedule_timeout(HZ / 10); |
|
|
} |
|
|
} |
|
|
#endif |
|
|
return -EPERM; |
|
|
} |
|
|
va_start(args, fmt); |
|
|
len = vsnprintf((char *) &pos, sizeof(pos) - 1, fmt, args) + 32; |
|
|
va_end(args); |
|
|
if ((query_entry = ccs_alloc(sizeof(*query_entry))) == NULL || |
|
|
(query_entry->query = ccs_alloc(len)) == NULL) goto out; |
|
|
INIT_LIST_HEAD(&query_entry->list); |
|
|
/***** CRITICAL SECTION START *****/ |
|
|
spin_lock(&query_lock); |
|
|
query_entry->serial = serial++; |
|
|
spin_unlock(&query_lock); |
|
|
/***** CRITICAL SECTION END *****/ |
|
|
pos = snprintf(query_entry->query, len - 1, "Q%u\n", query_entry->serial); |
|
|
va_start(args, fmt); |
|
|
vsnprintf(query_entry->query + pos, len - 1 - pos, fmt, args); |
|
|
query_entry->query_len = strlen(query_entry->query) + 1; |
|
|
va_end(args); |
|
|
/***** CRITICAL SECTION START *****/ |
|
|
spin_lock(&query_lock); |
|
|
list_add_tail(&query_entry->list, &query_list); |
|
|
spin_unlock(&query_lock); |
|
|
/***** CRITICAL SECTION END *****/ |
|
|
UpdateCounter(CCS_UPDATES_COUNTER_QUERY); |
|
|
/* Give 10 seconds for supervisor's opinion. */ |
|
|
for (query_entry->timer = 0; atomic_read(&queryd_watcher) && CheckCCSFlags(CCS_ALLOW_ENFORCE_GRACE) && query_entry->timer < 100; query_entry->timer++) { |
|
|
wake_up(&query_wait); |
|
|
set_current_state(TASK_INTERRUPTIBLE); |
|
|
schedule_timeout(HZ / 10); |
|
|
if (query_entry->answer) break; |
|
|
} |
|
|
UpdateCounter(CCS_UPDATES_COUNTER_QUERY); |
|
|
/***** CRITICAL SECTION START *****/ |
|
|
spin_lock(&query_lock); |
|
|
list_del(&query_entry->list); |
|
|
spin_unlock(&query_lock); |
|
|
/***** CRITICAL SECTION END *****/ |
|
|
switch (query_entry->answer) { |
|
|
case 1: |
|
|
/* Granted by administrator. */ |
|
|
error = 0; |
|
|
break; |
|
|
case 0: |
|
|
/* Timed out. */ |
|
|
break; |
|
|
default: |
|
|
/* Rejected by administrator. */ |
|
|
break; |
|
|
} |
|
|
out: ; |
|
|
if (query_entry) ccs_free(query_entry->query); |
|
|
ccs_free(query_entry); |
|
|
return error; |
|
|
} |
|
|
|
|
|
static int PollQuery(struct file *file, poll_table *wait) |
|
|
{ |
|
|
int found; |
|
|
/***** CRITICAL SECTION START *****/ |
|
|
spin_lock(&query_lock); |
|
|
found = !list_empty(&query_list); |
|
|
spin_unlock(&query_lock); |
|
|
/***** CRITICAL SECTION END *****/ |
|
|
if (found) return POLLIN | POLLRDNORM; |
|
|
poll_wait(file, &query_wait, wait); |
|
|
/***** CRITICAL SECTION START *****/ |
|
|
spin_lock(&query_lock); |
|
|
found = !list_empty(&query_list); |
|
|
spin_unlock(&query_lock); |
|
|
/***** CRITICAL SECTION END *****/ |
|
|
if (found) return POLLIN | POLLRDNORM; |
|
|
return 0; |
|
|
} |
|
|
|
|
|
static int ReadQuery(struct io_buffer *head) |
|
|
{ |
|
|
struct list_head *tmp; |
|
|
int pos = 0, len = 0; |
|
|
char *buf; |
|
|
if (head->read_avail) return 0; |
|
|
if (head->read_buf) { |
|
|
ccs_free(head->read_buf); head->read_buf = NULL; |
|
|
head->readbuf_size = 0; |
|
|
} |
|
|
/***** CRITICAL SECTION START *****/ |
|
|
spin_lock(&query_lock); |
|
|
list_for_each(tmp, &query_list) { |
|
|
struct query_entry *ptr = list_entry(tmp, struct query_entry, list); |
|
|
if (pos++ == head->read_step) { |
|
|
len = ptr->query_len; |
|
|
break; |
|
|
} |
|
|
} |
|
|
spin_unlock(&query_lock); |
|
|
/***** CRITICAL SECTION END *****/ |
|
|
if (!len) { |
|
|
head->read_step = 0; |
|
|
return 0; |
|
|
} |
|
|
if ((buf = ccs_alloc(len)) != NULL) { |
|
|
pos = 0; |
|
|
/***** CRITICAL SECTION START *****/ |
|
|
spin_lock(&query_lock); |
|
|
list_for_each(tmp, &query_list) { |
|
|
struct query_entry *ptr = list_entry(tmp, struct query_entry, list); |
|
|
if (pos++ == head->read_step) { |
|
|
/* Some query can be skiipped since query_list can change, but I don't care. */ |
|
|
if (len == ptr->query_len) memmove(buf, ptr->query, len); |
|
|
break; |
|
|
} |
|
|
} |
|
|
spin_unlock(&query_lock); |
|
|
/***** CRITICAL SECTION END *****/ |
|
|
if (buf[0]) { |
|
|
head->readbuf_size = head->read_avail = len; |
|
|
head->read_buf = buf; |
|
|
head->read_step++; |
|
|
} else { |
|
|
ccs_free(buf); |
|
|
} |
|
|
} |
|
|
return 0; |
|
|
} |
|
|
|
|
|
static int WriteAnswer(struct io_buffer *head) |
|
|
{ |
|
|
char *data = head->write_buf; |
|
|
struct list_head *tmp; |
|
|
unsigned int serial, answer; |
|
|
/***** CRITICAL SECTION START *****/ |
|
|
spin_lock(&query_lock); |
|
|
list_for_each(tmp, &query_list) { |
|
|
struct query_entry *ptr = list_entry(tmp, struct query_entry, list); |
|
|
ptr->timer = 0; |
|
|
} |
|
|
spin_unlock(&query_lock); |
|
|
/***** CRITICAL SECTION END *****/ |
|
|
if (sscanf(data, "A%u=%u", &serial, &answer) != 2) return -EINVAL; |
|
|
/***** CRITICAL SECTION START *****/ |
|
|
spin_lock(&query_lock); |
|
|
list_for_each(tmp, &query_list) { |
|
|
struct query_entry *ptr = list_entry(tmp, struct query_entry, list); |
|
|
if (ptr->serial != serial) continue; |
|
|
if (!ptr->answer) ptr->answer = answer; |
|
|
break; |
|
|
} |
|
|
spin_unlock(&query_lock); |
|
|
/***** CRITICAL SECTION END *****/ |
|
|
return 0; |
|
|
} |
|
|
|
|
|
/************************* /proc INTERFACE HANDLER *************************/ |
|
|
|
|
|
/* Policy updates counter. */ |
|
|
static unsigned int updates_counter[MAX_CCS_UPDATES_COUNTER]; |
|
|
static spinlock_t updates_counter_lock = SPIN_LOCK_UNLOCKED; |
|
|
|
|
|
void UpdateCounter(const unsigned char index) |
|
|
{ |
|
|
/***** CRITICAL SECTION START *****/ |
|
|
spin_lock(&updates_counter_lock); |
|
|
if (index < MAX_CCS_UPDATES_COUNTER) updates_counter[index]++; |
|
|
spin_unlock(&updates_counter_lock); |
|
|
/***** CRITICAL SECTION END *****/ |
|
|
} |
|
|
|
|
|
static int ReadUpdatesCounter(struct io_buffer *head) |
|
|
{ |
|
|
if (!head->read_eof) { |
|
|
unsigned int counter[MAX_CCS_UPDATES_COUNTER]; |
|
|
/***** CRITICAL SECTION START *****/ |
|
|
spin_lock(&updates_counter_lock); |
|
|
memmove(counter, updates_counter, sizeof(updates_counter)); |
|
|
memset(updates_counter, 0, sizeof(updates_counter)); |
|
|
spin_unlock(&updates_counter_lock); |
|
|
/***** CRITICAL SECTION END *****/ |
|
|
io_printf(head, |
|
|
"/proc/ccs/system_policy: %10u\n" |
|
|
"/proc/ccs/domain_policy: %10u\n" |
|
|
"/proc/ccs/exception_policy: %10u\n" |
|
|
"/proc/ccs/profile: %10u\n" |
|
|
"/proc/ccs/query: %10u\n" |
|
|
"/proc/ccs/manager: %10u\n" |
|
|
"/proc/ccs/grant_log: %10u\n" |
|
|
"/proc/ccs/reject_log: %10u\n", |
|
|
counter[CCS_UPDATES_COUNTER_SYSTEM_POLICY], |
|
|
counter[CCS_UPDATES_COUNTER_DOMAIN_POLICY], |
|
|
counter[CCS_UPDATES_COUNTER_EXCEPTION_POLICY], |
|
|
counter[CCS_UPDATES_COUNTER_PROFILE], |
|
|
counter[CCS_UPDATES_COUNTER_QUERY], |
|
|
counter[CCS_UPDATES_COUNTER_MANAGER], |
|
|
counter[CCS_UPDATES_COUNTER_GRANT_LOG], |
|
|
counter[CCS_UPDATES_COUNTER_REJECT_LOG]); |
|
|
head->read_eof = 1; |
|
|
} |
|
|
return 0; |
|
|
} |
|
|
|
|
|
static int ReadVersion(struct io_buffer *head) |
|
|
{ |
|
|
if (!head->read_eof) { |
|
|
if (io_printf(head, "1.5.3-pre") == 0) head->read_eof = 1; |
|
|
} |
|
|
return 0; |
|
|
} |
|
|
|
|
|
static int ReadMemoryCounter(struct io_buffer *head) |
|
|
{ |
|
|
if (!head->read_eof) { |
|
|
const int shared = GetMemoryUsedForSaveName(), private = GetMemoryUsedForElements(), dynamic = GetMemoryUsedForDynamic(); |
|
|
if (io_printf(head, "Shared: %10u\nPrivate: %10u\nDynamic: %10u\nTotal: %10u\n", shared, private, dynamic, shared + private + dynamic) == 0) head->read_eof = 1; |
|
|
} |
|
|
return 0; |
|
|
} |
|
|
|
|
|
static int ReadSelfDomain(struct io_buffer *head) |
|
|
{ |
|
|
if (!head->read_eof) { |
|
|
io_printf(head, "%s", current->domain_info->domainname->name); |
|
|
head->read_eof = 1; |
|
|
} |
|
|
return 0; |
|
|
} |
|
|
|
|
|
int CCS_OpenControl(const int type, struct file *file) |
|
|
{ |
|
|
struct io_buffer *head = ccs_alloc(sizeof(*head)); |
|
|
if (!head) return -ENOMEM; |
|
|
mutex_init(&head->read_sem); |
|
|
mutex_init(&head->write_sem); |
|
|
switch (type) { |
|
|
#ifdef CONFIG_SAKURA |
|
|
case CCS_SYSTEMPOLICY: |
|
|
head->write = AddSystemPolicy; |
|
|
head->read = ReadSystemPolicy; |
|
|
break; |
|
|
#endif |
|
|
#ifdef CONFIG_TOMOYO |
|
|
case CCS_DOMAINPOLICY: |
|
|
head->write = AddDomainPolicy; |
|
|
head->read = ReadDomainPolicy; |
|
|
break; |
|
|
case CCS_EXCEPTIONPOLICY: |
|
|
head->write = AddExceptionPolicy; |
|
|
head->read = ReadExceptionPolicy; |
|
|
break; |
|
|
case CCS_GRANTLOG: |
|
|
head->poll = PollGrantLog; |
|
|
head->read = ReadGrantLog; |
|
|
break; |
|
|
case CCS_REJECTLOG: |
|
|
head->poll = PollRejectLog; |
|
|
head->read = ReadRejectLog; |
|
|
break; |
|
|
#endif |
|
|
case CCS_SELFDOMAIN: |
|
|
head->read = ReadSelfDomain; |
|
|
break; |
|
|
case CCS_DOMAIN_STATUS: |
|
|
head->write = UpdateDomainProfile; |
|
|
head->read = ReadDomainProfile; |
|
|
break; |
|
|
case CCS_PROCESS_STATUS: |
|
|
head->write = WritePID; |
|
|
head->read = ReadPID; |
|
|
break; |
|
|
case CCS_VERSION: |
|
|
head->read = ReadVersion; |
|
|
head->readbuf_size = 128; |
|
|
break; |
|
|
case CCS_MEMINFO: |
|
|
head->read = ReadMemoryCounter; |
|
|
head->readbuf_size = 128; |
|
|
break; |
|
|
case CCS_PROFILE: |
|
|
head->write = SetProfile; |
|
|
head->read = ReadProfile; |
|
|
break; |
|
|
case CCS_QUERY: |
|
|
head->poll = PollQuery; |
|
|
head->write = WriteAnswer; |
|
|
head->read = ReadQuery; |
|
|
break; |
|
|
case CCS_MANAGER: |
|
|
head->write = AddManagerPolicy; |
|
|
head->read = ReadManagerPolicy; |
|
|
break; |
|
|
case CCS_UPDATESCOUNTER: |
|
|
head->read = ReadUpdatesCounter; |
|
|
break; |
|
|
} |
|
|
if (type != CCS_GRANTLOG && type != CCS_REJECTLOG && type != CCS_QUERY) { |
|
|
if (!head->readbuf_size) head->readbuf_size = PAGE_SIZE * 2; |
|
|
if ((head->read_buf = ccs_alloc(head->readbuf_size)) == NULL) { |
|
|
ccs_free(head); |
|
|
return -ENOMEM; |
|
|
} |
|
|
} |
|
|
if (head->write) { |
|
|
head->writebuf_size = PAGE_SIZE * 2; |
|
|
if ((head->write_buf = ccs_alloc(head->writebuf_size)) == NULL) { |
|
|
ccs_free(head->read_buf); |
|
|
ccs_free(head); |
|
|
return -ENOMEM; |
|
|
} |
|
|
} |
|
|
file->private_data = head; |
|
|
if (type == CCS_SELFDOMAIN) CCS_ReadControl(file, NULL, 0); |
|
|
else if (head->write == WriteAnswer) atomic_inc(&queryd_watcher); |
|
|
return 0; |
|
|
} |
|
|
|
|
|
static int CopyToUser(struct io_buffer *head, char __user * buffer, int buffer_len) |
|
|
{ |
|
|
int len = head->read_avail; |
|
|
char *cp = head->read_buf; |
|
|
if (len > buffer_len) len = buffer_len; |
|
|
if (len) { |
|
|
if (copy_to_user(buffer, cp, len)) return -EFAULT; |
|
|
head->read_avail -= len; |
|
|
memmove(cp, cp + len, head->read_avail); |
|
|
} |
|
|
return len; |
|
|
} |
|
|
|
|
|
int CCS_PollControl(struct file *file, poll_table *wait) |
|
|
{ |
|
|
struct io_buffer *head = file->private_data; |
|
|
if (!head->poll) return -ENOSYS; |
|
|
return head->poll(file, wait); |
|
|
} |
|
|
|
|
|
int CCS_ReadControl(struct file *file, char __user *buffer, const int buffer_len) |
|
|
{ |
|
|
int len = 0; |
|
|
struct io_buffer *head = file->private_data; |
|
|
if (!head->read) return -ENOSYS; |
|
|
if (!access_ok(VERIFY_WRITE, buffer, buffer_len)) return -EFAULT; |
|
|
if (mutex_lock_interruptible(&head->read_sem)) return -EINTR; |
|
|
len = head->read(head); |
|
|
if (len >= 0) len = CopyToUser(head, buffer, buffer_len); |
|
|
mutex_unlock(&head->read_sem); |
|
|
return len; |
|
|
} |
|
|
|
|
|
int CCS_WriteControl(struct file *file, const char __user *buffer, const int buffer_len) |
|
|
{ |
|
|
struct io_buffer *head = file->private_data; |
|
|
int error = buffer_len; |
|
|
int avail_len = buffer_len; |
|
|
char *cp0 = head->write_buf; |
|
|
if (!head->write) return -ENOSYS; |
|
|
if (!access_ok(VERIFY_READ, buffer, buffer_len)) return -EFAULT; |
|
|
if (!isRoot()) return -EPERM; |
|
|
if (head->write != WritePID && !IsPolicyManager()) { |
|
|
return -EPERM; /* Forbid updating policies for non manager programs. */ |
|
1057 |
} |
} |
1058 |
if (mutex_lock_interruptible(&head->write_sem)) return -EINTR; |
return false; |
|
while (avail_len > 0) { |
|
|
char c; |
|
|
if (head->write_avail >= head->writebuf_size - 1) { |
|
|
error = -ENOMEM; |
|
|
break; |
|
|
} else if (get_user(c, buffer)) { |
|
|
error = -EFAULT; |
|
|
break; |
|
|
} |
|
|
buffer++; avail_len--; |
|
|
cp0[head->write_avail++] = c; |
|
|
if (c != '\n') continue; |
|
|
cp0[head->write_avail - 1] = '\0'; |
|
|
head->write_avail = 0; |
|
|
NormalizeLine(cp0); |
|
|
head->write(head); |
|
|
} |
|
|
mutex_unlock(&head->write_sem); |
|
|
return error; |
|
|
} |
|
|
|
|
|
|
|
|
int CCS_CloseControl(struct file *file) |
|
|
{ |
|
|
struct io_buffer *head = file->private_data; |
|
|
if (head->write == WriteAnswer) atomic_dec(&queryd_watcher); |
|
|
else if (head->read == ReadMemoryCounter) profile_loaded = 1; |
|
|
ccs_free(head->read_buf); head->read_buf = NULL; |
|
|
ccs_free(head->write_buf); head->write_buf = NULL; |
|
|
ccs_free(head); head = NULL; |
|
|
file->private_data = NULL; |
|
|
return 0; |
|
1059 |
} |
} |