3 |
* |
* |
4 |
* Copyright (C) 2005-2009 NTT DATA CORPORATION |
* Copyright (C) 2005-2009 NTT DATA CORPORATION |
5 |
* |
* |
6 |
* Version: 1.7.0-pre 2009/08/08 |
* Version: 1.7.0 2009/10/01 |
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. |
12 |
|
|
13 |
#include "internal.h" |
#include "internal.h" |
14 |
|
|
15 |
/* Lock for protecting ccs_profile->comment */ |
static struct ccs_profile ccs_default_profile = { |
16 |
static DEFINE_SPINLOCK(ccs_profile_comment_lock); |
.learning = &ccs_default_profile.preference, |
17 |
|
.permissive = &ccs_default_profile.preference, |
18 |
/* String table for functionality that takes 2 modes. */ |
.enforcing = &ccs_default_profile.preference, |
19 |
static const char *ccs_mode_2[2] = { |
.audit = &ccs_default_profile.preference, |
20 |
"disabled", "enabled" |
#ifdef CONFIG_CCSECURITY_AUDIT |
21 |
|
.preference.audit_max_grant_log = CONFIG_CCSECURITY_MAX_GRANT_LOG, |
22 |
|
.preference.audit_max_reject_log = CONFIG_CCSECURITY_MAX_REJECT_LOG, |
23 |
|
#endif |
24 |
|
.preference.audit_task_info = true, |
25 |
|
.preference.audit_path_info = true, |
26 |
|
.preference.enforcing_penalty = 0, |
27 |
|
.preference.enforcing_verbose = true, |
28 |
|
.preference.learning_max_entry = CONFIG_CCSECURITY_MAX_ACCEPT_ENTRY, |
29 |
|
.preference.learning_verbose = false, |
30 |
|
.preference.learning_exec_realpath = true, |
31 |
|
.preference.learning_exec_argv0 = true, |
32 |
|
.preference.learning_symlink_target = true, |
33 |
|
.preference.permissive_verbose = true |
34 |
}; |
}; |
35 |
|
|
36 |
|
/* Profile table. Memory is allocated as needed. */ |
37 |
|
static struct ccs_profile *ccs_profile_ptr[CCS_MAX_PROFILES]; |
38 |
|
|
39 |
|
/* Lock for protecting "struct ccs_profile"->comment */ |
40 |
|
static DEFINE_SPINLOCK(ccs_profile_comment_lock); |
41 |
|
|
42 |
|
/* String table for functionality that takes 4 modes. */ |
43 |
static const char *ccs_mode_4[4] = { |
static const char *ccs_mode_4[4] = { |
44 |
"disabled", "learning", "permissive", "enforcing" |
"disabled", "learning", "permissive", "enforcing" |
45 |
}; |
}; |
46 |
|
|
47 |
static bool ccs_mac_keywords_used[CCS_MAX_MAC_INDEX + |
/* String table for /proc/ccs/profile */ |
|
CCS_MAX_CAPABILITY_INDEX]; |
|
|
|
|
48 |
static const char *ccs_mac_keywords[CCS_MAX_MAC_INDEX + |
static const char *ccs_mac_keywords[CCS_MAX_MAC_INDEX + |
49 |
CCS_MAX_CAPABILITY_INDEX] = { |
CCS_MAX_CAPABILITY_INDEX + |
50 |
[CCS_MAC_EXECUTE] = "execute", |
CCS_MAX_MAC_CATEGORY_INDEX] = { |
51 |
[CCS_MAC_OPEN] = "open", |
[CCS_MAC_FILE_EXECUTE] |
52 |
[CCS_MAC_CREATE] = "create", |
= "file::execute", |
53 |
[CCS_MAC_UNLINK] = "unlink", |
[CCS_MAC_FILE_OPEN] |
54 |
[CCS_MAC_MKDIR] = "mkdir", |
= "file::open", |
55 |
[CCS_MAC_RMDIR] = "rmdir", |
[CCS_MAC_FILE_CREATE] |
56 |
[CCS_MAC_MKFIFO] = "mkfifo", |
= "file::create", |
57 |
[CCS_MAC_MKSOCK] = "mksock", |
[CCS_MAC_FILE_UNLINK] |
58 |
[CCS_MAC_TRUNCATE] = "truncate", |
= "file::unlink", |
59 |
[CCS_MAC_SYMLINK] = "symlink", |
[CCS_MAC_FILE_MKDIR] |
60 |
[CCS_MAC_REWRITE] = "rewrite", |
= "file::mkdir", |
61 |
[CCS_MAC_MKBLOCK] = "mkblock", |
[CCS_MAC_FILE_RMDIR] |
62 |
[CCS_MAC_MKCHAR] = "mkchar", |
= "file::rmdir", |
63 |
[CCS_MAC_LINK] = "link", |
[CCS_MAC_FILE_MKFIFO] |
64 |
[CCS_MAC_RENAME] = "rename", |
= "file::mkfifo", |
65 |
[CCS_MAC_CHMOD] = "chmod", |
[CCS_MAC_FILE_MKSOCK] |
66 |
[CCS_MAC_CHOWN] = "chown", |
= "file::mksock", |
67 |
[CCS_MAC_CHGRP] = "chgrp", |
[CCS_MAC_FILE_TRUNCATE] |
68 |
[CCS_MAC_IOCTL] = "ioctl", |
= "file::truncate", |
69 |
[CCS_MAC_CHROOT] = "chroot", |
[CCS_MAC_FILE_SYMLINK] |
70 |
[CCS_MAC_MOUNT] = "mount", |
= "file::symlink", |
71 |
[CCS_MAC_UMOUNT] = "umount", |
[CCS_MAC_FILE_REWRITE] |
72 |
[CCS_MAC_PIVOT_ROOT] = "pivot_root", |
= "file::rewrite", |
73 |
[CCS_MAC_ENVIRON] = "env", |
[CCS_MAC_FILE_MKBLOCK] |
74 |
[CCS_MAC_NETWORK] = "network", |
= "file::mkblock", |
75 |
[CCS_MAC_SIGNAL] = "signal", |
[CCS_MAC_FILE_MKCHAR] |
76 |
|
= "file::mkchar", |
77 |
|
[CCS_MAC_FILE_LINK] |
78 |
|
= "file::link", |
79 |
|
[CCS_MAC_FILE_RENAME] |
80 |
|
= "file::rename", |
81 |
|
[CCS_MAC_FILE_CHMOD] |
82 |
|
= "file::chmod", |
83 |
|
[CCS_MAC_FILE_CHOWN] |
84 |
|
= "file::chown", |
85 |
|
[CCS_MAC_FILE_CHGRP] |
86 |
|
= "file::chgrp", |
87 |
|
[CCS_MAC_FILE_IOCTL] |
88 |
|
= "file::ioctl", |
89 |
|
[CCS_MAC_FILE_CHROOT] |
90 |
|
= "file::chroot", |
91 |
|
[CCS_MAC_FILE_MOUNT] |
92 |
|
= "file::mount", |
93 |
|
[CCS_MAC_FILE_UMOUNT] |
94 |
|
= "file::umount", |
95 |
|
[CCS_MAC_FILE_PIVOT_ROOT] |
96 |
|
= "file::pivot_root", |
97 |
|
[CCS_MAC_ENVIRON] |
98 |
|
= "misc::env", |
99 |
|
[CCS_MAC_NETWORK_UDP_BIND] |
100 |
|
= "network::inet_udp_bind", |
101 |
|
[CCS_MAC_NETWORK_UDP_CONNECT] |
102 |
|
= "network::inet_udp_connect", |
103 |
|
[CCS_MAC_NETWORK_TCP_BIND] |
104 |
|
= "network::inet_tcp_bind", |
105 |
|
[CCS_MAC_NETWORK_TCP_LISTEN] |
106 |
|
= "network::inet_tcp_listen", |
107 |
|
[CCS_MAC_NETWORK_TCP_CONNECT] |
108 |
|
= "network::inet_tcp_connect", |
109 |
|
[CCS_MAC_NETWORK_TCP_ACCEPT] |
110 |
|
= "network::inet_tcp_accept", |
111 |
|
[CCS_MAC_NETWORK_RAW_BIND] |
112 |
|
= "network::inet_raw_bind", |
113 |
|
[CCS_MAC_NETWORK_RAW_CONNECT] |
114 |
|
= "network::inet_raw_connect", |
115 |
|
[CCS_MAC_SIGNAL] |
116 |
|
= "ipc::signal", |
117 |
[CCS_MAX_MAC_INDEX + CCS_INET_STREAM_SOCKET_CREATE] |
[CCS_MAX_MAC_INDEX + CCS_INET_STREAM_SOCKET_CREATE] |
118 |
= "inet_tcp_create", |
= "capability::inet_tcp_create", |
119 |
[CCS_MAX_MAC_INDEX + CCS_INET_STREAM_SOCKET_LISTEN] |
[CCS_MAX_MAC_INDEX + CCS_INET_STREAM_SOCKET_LISTEN] |
120 |
= "inet_tcp_listen", |
= "capability::inet_tcp_listen", |
121 |
[CCS_MAX_MAC_INDEX + CCS_INET_STREAM_SOCKET_CONNECT] |
[CCS_MAX_MAC_INDEX + CCS_INET_STREAM_SOCKET_CONNECT] |
122 |
= "inet_tcp_connect", |
= "capability::inet_tcp_connect", |
123 |
[CCS_MAX_MAC_INDEX + CCS_USE_INET_DGRAM_SOCKET] = "use_inet_udp", |
[CCS_MAX_MAC_INDEX + CCS_USE_INET_DGRAM_SOCKET] |
124 |
[CCS_MAX_MAC_INDEX + CCS_USE_INET_RAW_SOCKET] = "use_inet_ip", |
= "capability::use_inet_udp", |
125 |
[CCS_MAX_MAC_INDEX + CCS_USE_ROUTE_SOCKET] = "use_route", |
[CCS_MAX_MAC_INDEX + CCS_USE_INET_RAW_SOCKET] |
126 |
[CCS_MAX_MAC_INDEX + CCS_USE_PACKET_SOCKET] = "use_packet", |
= "capability::use_inet_ip", |
127 |
[CCS_MAX_MAC_INDEX + CCS_SYS_MOUNT] = "SYS_MOUNT", |
[CCS_MAX_MAC_INDEX + CCS_USE_ROUTE_SOCKET] |
128 |
[CCS_MAX_MAC_INDEX + CCS_SYS_UMOUNT] = "SYS_UMOUNT", |
= "capability::use_route", |
129 |
[CCS_MAX_MAC_INDEX + CCS_SYS_REBOOT] = "SYS_REBOOT", |
[CCS_MAX_MAC_INDEX + CCS_USE_PACKET_SOCKET] |
130 |
[CCS_MAX_MAC_INDEX + CCS_SYS_CHROOT] = "SYS_CHROOT", |
= "capability::use_packet", |
131 |
[CCS_MAX_MAC_INDEX + CCS_SYS_KILL] = "SYS_KILL", |
[CCS_MAX_MAC_INDEX + CCS_SYS_MOUNT] |
132 |
[CCS_MAX_MAC_INDEX + CCS_SYS_VHANGUP] = "SYS_VHANGUP", |
= "capability::SYS_MOUNT", |
133 |
[CCS_MAX_MAC_INDEX + CCS_SYS_SETTIME] = "SYS_TIME", |
[CCS_MAX_MAC_INDEX + CCS_SYS_UMOUNT] |
134 |
[CCS_MAX_MAC_INDEX + CCS_SYS_NICE] = "SYS_NICE", |
= "capability::SYS_UMOUNT", |
135 |
[CCS_MAX_MAC_INDEX + CCS_SYS_SETHOSTNAME] = "SYS_SETHOSTNAME", |
[CCS_MAX_MAC_INDEX + CCS_SYS_REBOOT] |
136 |
[CCS_MAX_MAC_INDEX + CCS_USE_KERNEL_MODULE] = "use_kernel_module", |
= "capability::SYS_REBOOT", |
137 |
[CCS_MAX_MAC_INDEX + CCS_CREATE_FIFO] = "create_fifo", |
[CCS_MAX_MAC_INDEX + CCS_SYS_CHROOT] |
138 |
[CCS_MAX_MAC_INDEX + CCS_CREATE_BLOCK_DEV] = "create_block_dev", |
= "capability::SYS_CHROOT", |
139 |
[CCS_MAX_MAC_INDEX + CCS_CREATE_CHAR_DEV] = "create_char_dev", |
[CCS_MAX_MAC_INDEX + CCS_SYS_KILL] |
140 |
[CCS_MAX_MAC_INDEX + CCS_CREATE_UNIX_SOCKET] = "create_unix_socket", |
= "capability::SYS_KILL", |
141 |
[CCS_MAX_MAC_INDEX + CCS_SYS_LINK] = "SYS_LINK", |
[CCS_MAX_MAC_INDEX + CCS_SYS_VHANGUP] |
142 |
[CCS_MAX_MAC_INDEX + CCS_SYS_SYMLINK] = "SYS_SYMLINK", |
= "capability::SYS_VHANGUP", |
143 |
[CCS_MAX_MAC_INDEX + CCS_SYS_RENAME] = "SYS_RENAME", |
[CCS_MAX_MAC_INDEX + CCS_SYS_SETTIME] |
144 |
[CCS_MAX_MAC_INDEX + CCS_SYS_UNLINK] = "SYS_UNLINK", |
= "capability::SYS_TIME", |
145 |
[CCS_MAX_MAC_INDEX + CCS_SYS_CHMOD] = "SYS_CHMOD", |
[CCS_MAX_MAC_INDEX + CCS_SYS_NICE] |
146 |
[CCS_MAX_MAC_INDEX + CCS_SYS_CHOWN] = "SYS_CHOWN", |
= "capability::SYS_NICE", |
147 |
[CCS_MAX_MAC_INDEX + CCS_SYS_IOCTL] = "SYS_IOCTL", |
[CCS_MAX_MAC_INDEX + CCS_SYS_SETHOSTNAME] |
148 |
[CCS_MAX_MAC_INDEX + CCS_SYS_KEXEC_LOAD] = "SYS_KEXEC_LOAD", |
= "capability::SYS_SETHOSTNAME", |
149 |
[CCS_MAX_MAC_INDEX + CCS_SYS_PIVOT_ROOT] = "SYS_PIVOT_ROOT", |
[CCS_MAX_MAC_INDEX + CCS_USE_KERNEL_MODULE] |
150 |
[CCS_MAX_MAC_INDEX + CCS_SYS_PTRACE] = "SYS_PTRACE", |
= "capability::use_kernel_module", |
151 |
[CCS_MAX_MAC_INDEX + CCS_CONCEAL_MOUNT] = "conceal_mount" |
[CCS_MAX_MAC_INDEX + CCS_CREATE_FIFO] |
152 |
}; |
= "capability::create_fifo", |
153 |
|
[CCS_MAX_MAC_INDEX + CCS_CREATE_BLOCK_DEV] |
154 |
/* Table for profile. */ |
= "capability::create_block_dev", |
155 |
static struct { |
[CCS_MAX_MAC_INDEX + CCS_CREATE_CHAR_DEV] |
156 |
const char *keyword; |
= "capability::create_char_dev", |
157 |
unsigned int current_value; |
[CCS_MAX_MAC_INDEX + CCS_CREATE_UNIX_SOCKET] |
158 |
const unsigned int max_value; |
= "capability::create_unix_socket", |
159 |
} ccs_control_array[CCS_MAX_CONTROL_INDEX] = { |
[CCS_MAX_MAC_INDEX + CCS_SYS_LINK] |
160 |
[CCS_AUTOLEARN_EXEC_REALPATH] = { "AUTOLEARN_EXEC_REALPATH", 0, 1 }, |
= "capability::SYS_LINK", |
161 |
[CCS_AUTOLEARN_EXEC_ARGV0] = { "AUTOLEARN_EXEC_ARGV0", 0, 1 }, |
[CCS_MAX_MAC_INDEX + CCS_SYS_SYMLINK] |
162 |
[CCS_MAX_ACCEPT_ENTRY] |
= "capability::SYS_SYMLINK", |
163 |
= { "MAX_ACCEPT_ENTRY", CONFIG_CCSECURITY_MAX_ACCEPT_ENTRY, INT_MAX }, |
[CCS_MAX_MAC_INDEX + CCS_SYS_RENAME] |
164 |
#ifdef CONFIG_CCSECURITY_AUDIT |
= "capability::SYS_RENAME", |
165 |
[CCS_MAX_GRANT_LOG] |
[CCS_MAX_MAC_INDEX + CCS_SYS_UNLINK] |
166 |
= { "MAX_GRANT_LOG", CONFIG_CCSECURITY_MAX_GRANT_LOG, INT_MAX }, |
= "capability::SYS_UNLINK", |
167 |
[CCS_MAX_REJECT_LOG] |
[CCS_MAX_MAC_INDEX + CCS_SYS_CHMOD] |
168 |
= { "MAX_REJECT_LOG", CONFIG_CCSECURITY_MAX_REJECT_LOG, INT_MAX }, |
= "capability::SYS_CHMOD", |
169 |
#endif |
[CCS_MAX_MAC_INDEX + CCS_SYS_CHOWN] |
170 |
[CCS_VERBOSE] = { "PRINT_VIOLATION", 1, 1 }, |
= "capability::SYS_CHOWN", |
171 |
[CCS_SLEEP_PERIOD] = { "SLEEP_PERIOD", 0, 3000 }, /* in 0.1 second */ |
[CCS_MAX_MAC_INDEX + CCS_SYS_IOCTL] |
172 |
|
= "capability::SYS_IOCTL", |
173 |
|
[CCS_MAX_MAC_INDEX + CCS_SYS_KEXEC_LOAD] |
174 |
|
= "capability::SYS_KEXEC_LOAD", |
175 |
|
[CCS_MAX_MAC_INDEX + CCS_SYS_PIVOT_ROOT] |
176 |
|
= "capability::SYS_PIVOT_ROOT", |
177 |
|
[CCS_MAX_MAC_INDEX + CCS_SYS_PTRACE] |
178 |
|
= "capability::SYS_PTRACE", |
179 |
|
[CCS_MAX_MAC_INDEX + CCS_CONCEAL_MOUNT] |
180 |
|
= "capability::conceal_mount", |
181 |
|
[CCS_MAX_MAC_INDEX + CCS_MAX_CAPABILITY_INDEX |
182 |
|
+ CCS_MAC_CATEGORY_FILE] = "file", |
183 |
|
[CCS_MAX_MAC_INDEX + CCS_MAX_CAPABILITY_INDEX |
184 |
|
+ CCS_MAC_CATEGORY_NETWORK] = "network", |
185 |
|
[CCS_MAX_MAC_INDEX + CCS_MAX_CAPABILITY_INDEX |
186 |
|
+ CCS_MAC_CATEGORY_MISC] = "misc", |
187 |
|
[CCS_MAX_MAC_INDEX + CCS_MAX_CAPABILITY_INDEX |
188 |
|
+ CCS_MAC_CATEGORY_IPC] = "ipc", |
189 |
|
[CCS_MAX_MAC_INDEX + CCS_MAX_CAPABILITY_INDEX |
190 |
|
+ CCS_MAC_CATEGORY_CAPABILITY] = "capability", |
191 |
}; |
}; |
192 |
|
|
193 |
/* Permit policy management by non-root user? */ |
/* Permit policy management by non-root user? */ |
203 |
const char *ccs_cap2keyword(const u8 operation) |
const char *ccs_cap2keyword(const u8 operation) |
204 |
{ |
{ |
205 |
return operation < CCS_MAX_CAPABILITY_INDEX |
return operation < CCS_MAX_CAPABILITY_INDEX |
206 |
? ccs_mac_keywords[CCS_MAX_MAC_INDEX + operation] : NULL; |
? ccs_mac_keywords[CCS_MAX_MAC_INDEX + operation] + 12 : NULL; |
207 |
} |
} |
208 |
|
|
209 |
/** |
/** |
210 |
* ccs_quiet_setup - Set CCS_VERBOSE=0 by default. |
* ccs_yesno - Return "yes" or "no". |
|
* |
|
|
* @str: Unused. |
|
211 |
* |
* |
212 |
* Returns 0. |
* @value: Bool value. |
213 |
*/ |
*/ |
214 |
static int __init ccs_quiet_setup(char *str) |
static const char *ccs_yesno(const unsigned int value) |
215 |
{ |
{ |
216 |
ccs_control_array[CCS_VERBOSE].current_value = 0; |
return value ? "yes" : "no"; |
|
return 0; |
|
217 |
} |
} |
218 |
|
|
|
__setup("CCS_QUIET", ccs_quiet_setup); |
|
|
|
|
219 |
/** |
/** |
220 |
* ccs_io_printf - Transactional printf() to "struct ccs_io_buffer" structure. |
* ccs_io_printf - Transactional printf() to "struct ccs_io_buffer" structure. |
221 |
* |
* |
255 |
{ |
{ |
256 |
struct ccs_profile *ptr; |
struct ccs_profile *ptr; |
257 |
struct ccs_profile *entry; |
struct ccs_profile *entry; |
|
int i; |
|
258 |
if (profile >= CCS_MAX_PROFILES) |
if (profile >= CCS_MAX_PROFILES) |
259 |
return NULL; |
return NULL; |
260 |
ptr = ccs_profile_ptr[profile]; |
ptr = ccs_profile_ptr[profile]; |
265 |
ptr = ccs_profile_ptr[profile]; |
ptr = ccs_profile_ptr[profile]; |
266 |
if (!ptr && ccs_memory_ok(entry, sizeof(*entry))) { |
if (!ptr && ccs_memory_ok(entry, sizeof(*entry))) { |
267 |
ptr = entry; |
ptr = entry; |
268 |
for (i = 0; i < CCS_MAX_CONTROL_INDEX; i++) |
ptr->audit = &ccs_default_profile.preference; |
269 |
ptr->value[i] = ccs_control_array[i].current_value; |
ptr->learning = &ccs_default_profile.preference; |
270 |
|
ptr->permissive = &ccs_default_profile.preference; |
271 |
|
ptr->enforcing = &ccs_default_profile.preference; |
272 |
|
ptr->default_config = CCS_CONFIG_DISABLED | |
273 |
|
CCS_CONFIG_WANT_GRANT_LOG | CCS_CONFIG_WANT_REJECT_LOG; |
274 |
|
memset(ptr->config, CCS_CONFIG_USE_DEFAULT, |
275 |
|
sizeof(ptr->config)); |
276 |
mb(); /* Avoid out-of-order execution. */ |
mb(); /* Avoid out-of-order execution. */ |
277 |
ccs_profile_ptr[profile] = ptr; |
ccs_profile_ptr[profile] = ptr; |
278 |
entry = NULL; |
entry = NULL; |
283 |
} |
} |
284 |
|
|
285 |
/** |
/** |
286 |
|
* ccs_check_profile - Check all profiles currently assigned to domains are defined. |
287 |
|
*/ |
288 |
|
void ccs_check_profile(void) |
289 |
|
{ |
290 |
|
struct ccs_domain_info *domain; |
291 |
|
ccs_policy_loaded = true; |
292 |
|
list_for_each_entry_rcu(domain, &ccs_domain_list, list) { |
293 |
|
const u8 profile = domain->profile; |
294 |
|
if (ccs_profile_ptr[profile]) |
295 |
|
continue; |
296 |
|
panic("Profile %u (used by '%s') not defined.\n", |
297 |
|
profile, domain->domainname->name); |
298 |
|
} |
299 |
|
} |
300 |
|
|
301 |
|
/** |
302 |
|
* ccs_profile - Find a profile. |
303 |
|
* |
304 |
|
* @profile: Profile number to find. |
305 |
|
* |
306 |
|
* Returns pointer to "struct ccs_profile". |
307 |
|
*/ |
308 |
|
struct ccs_profile *ccs_profile(const u8 profile) |
309 |
|
{ |
310 |
|
struct ccs_profile *ptr = ccs_profile_ptr[profile]; |
311 |
|
if (!ccs_policy_loaded) |
312 |
|
return &ccs_default_profile; |
313 |
|
BUG_ON(!ptr); |
314 |
|
return ptr; |
315 |
|
} |
316 |
|
|
317 |
|
/** |
318 |
* ccs_write_profile - Write profile table. |
* ccs_write_profile - Write profile table. |
319 |
* |
* |
320 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
325 |
{ |
{ |
326 |
char *data = head->write_buf; |
char *data = head->write_buf; |
327 |
unsigned int i; |
unsigned int i; |
328 |
unsigned int value; |
int value; |
|
int index = -1; |
|
329 |
int mode; |
int mode; |
330 |
|
u8 config; |
331 |
|
bool use_default = false; |
332 |
char *cp; |
char *cp; |
333 |
struct ccs_profile *ccs_profile; |
struct ccs_profile *profile; |
334 |
i = simple_strtoul(data, &cp, 10); |
i = simple_strtoul(data, &cp, 10); |
335 |
if (data != cp) { |
if (data == cp) { |
336 |
|
profile = &ccs_default_profile; |
337 |
|
} else { |
338 |
if (*cp != '-') |
if (*cp != '-') |
339 |
return -EINVAL; |
return -EINVAL; |
340 |
data = cp + 1; |
data = cp + 1; |
341 |
|
profile = ccs_find_or_assign_new_profile(i); |
342 |
|
if (!profile) |
343 |
|
return -EINVAL; |
344 |
} |
} |
|
ccs_profile = ccs_find_or_assign_new_profile(i); |
|
|
if (!ccs_profile) |
|
|
return -EINVAL; |
|
345 |
cp = strchr(data, '='); |
cp = strchr(data, '='); |
346 |
if (!cp) |
if (!cp) |
347 |
return -EINVAL; |
return -EINVAL; |
348 |
*cp++ = '\0'; |
*cp++ = '\0'; |
349 |
|
if (profile != &ccs_default_profile) |
350 |
|
use_default = strstr(cp, "use_default") != NULL; |
351 |
|
if (strstr(cp, "verbose=yes")) |
352 |
|
value = 1; |
353 |
|
else if (strstr(cp, "verbose=no")) |
354 |
|
value = 0; |
355 |
|
else |
356 |
|
value = -1; |
357 |
|
if (!strcmp(data, "PREFERENCE::audit")) { |
358 |
|
#ifdef CONFIG_CCSECURITY_AUDIT |
359 |
|
char *cp2; |
360 |
|
#endif |
361 |
|
if (use_default) { |
362 |
|
profile->audit = &ccs_default_profile.preference; |
363 |
|
return 0; |
364 |
|
} |
365 |
|
profile->audit = &profile->preference; |
366 |
|
#ifdef CONFIG_CCSECURITY_AUDIT |
367 |
|
cp2 = strstr(cp, "max_grant_log="); |
368 |
|
if (cp2) |
369 |
|
sscanf(cp2 + 14, "%u", |
370 |
|
&profile->preference.audit_max_grant_log); |
371 |
|
cp2 = strstr(cp, "max_reject_log="); |
372 |
|
if (cp2) |
373 |
|
sscanf(cp2 + 15, "%u", |
374 |
|
&profile->preference.audit_max_reject_log); |
375 |
|
#endif |
376 |
|
if (strstr(cp, "task_info=yes")) |
377 |
|
profile->preference.audit_task_info = true; |
378 |
|
else if (strstr(cp, "task_info=no")) |
379 |
|
profile->preference.audit_task_info = false; |
380 |
|
if (strstr(cp, "path_info=yes")) |
381 |
|
profile->preference.audit_path_info = true; |
382 |
|
else if (strstr(cp, "path_info=no")) |
383 |
|
profile->preference.audit_path_info = false; |
384 |
|
return 0; |
385 |
|
} |
386 |
|
if (!strcmp(data, "PREFERENCE::enforcing")) { |
387 |
|
char *cp2; |
388 |
|
if (use_default) { |
389 |
|
profile->enforcing = &ccs_default_profile.preference; |
390 |
|
return 0; |
391 |
|
} |
392 |
|
profile->enforcing = &profile->preference; |
393 |
|
if (value >= 0) |
394 |
|
profile->preference.enforcing_verbose = value; |
395 |
|
cp2 = strstr(cp, "penalty="); |
396 |
|
if (cp2) |
397 |
|
sscanf(cp2 + 8, "%u", |
398 |
|
&profile->preference.enforcing_penalty); |
399 |
|
return 0; |
400 |
|
} |
401 |
|
if (!strcmp(data, "PREFERENCE::permissive")) { |
402 |
|
if (use_default) { |
403 |
|
profile->permissive = &ccs_default_profile.preference; |
404 |
|
return 0; |
405 |
|
} |
406 |
|
profile->permissive = &profile->preference; |
407 |
|
if (value >= 0) |
408 |
|
profile->preference.permissive_verbose = value; |
409 |
|
return 0; |
410 |
|
} |
411 |
|
if (!strcmp(data, "PREFERENCE::learning")) { |
412 |
|
char *cp2; |
413 |
|
if (use_default) { |
414 |
|
profile->learning = &ccs_default_profile.preference; |
415 |
|
return 0; |
416 |
|
} |
417 |
|
profile->learning = &profile->preference; |
418 |
|
if (value >= 0) |
419 |
|
profile->preference.learning_verbose = value; |
420 |
|
cp2 = strstr(cp, "max_entry="); |
421 |
|
if (cp2) |
422 |
|
sscanf(cp2 + 10, "%u", |
423 |
|
&profile->preference.learning_max_entry); |
424 |
|
if (strstr(cp, "exec.realpath=yes")) |
425 |
|
profile->preference.learning_exec_realpath = true; |
426 |
|
else if (strstr(cp, "exec.realpath=no")) |
427 |
|
profile->preference.learning_exec_realpath = false; |
428 |
|
if (strstr(cp, "exec.argv0=yes")) |
429 |
|
profile->preference.learning_exec_argv0 = true; |
430 |
|
else if (strstr(cp, "exec.argv0=no")) |
431 |
|
profile->preference.learning_exec_argv0 = false; |
432 |
|
if (strstr(cp, "symlink.target=yes")) |
433 |
|
profile->preference.learning_symlink_target = true; |
434 |
|
else if (strstr(cp, "symlink.target=no")) |
435 |
|
profile->preference.learning_symlink_target = false; |
436 |
|
return 0; |
437 |
|
} |
438 |
|
if (profile == &ccs_default_profile) |
439 |
|
return -EINVAL; |
440 |
if (!strcmp(data, "COMMENT")) { |
if (!strcmp(data, "COMMENT")) { |
441 |
const struct ccs_path_info *new_comment = ccs_get_name(cp); |
const struct ccs_path_info *new_comment = ccs_get_name(cp); |
442 |
const struct ccs_path_info *old_comment; |
const struct ccs_path_info *old_comment; |
443 |
/* Protect reader from ccs_put_name(). */ |
/* Protect reader from ccs_put_name(). */ |
444 |
spin_lock(&ccs_profile_comment_lock); |
spin_lock(&ccs_profile_comment_lock); |
445 |
old_comment = ccs_profile->comment; |
old_comment = profile->comment; |
446 |
ccs_profile->comment = new_comment; |
profile->comment = new_comment; |
447 |
spin_unlock(&ccs_profile_comment_lock); |
spin_unlock(&ccs_profile_comment_lock); |
448 |
ccs_put_name(old_comment); |
ccs_put_name(old_comment); |
449 |
return 0; |
return 0; |
450 |
} |
} |
451 |
if (!ccs_str_starts(&data, "MAC::")) |
if (!strcmp(data, "CONFIG")) { |
452 |
goto not_mac; |
i = CCS_MAX_MAC_INDEX + CCS_MAX_CAPABILITY_INDEX |
453 |
if (ccs_str_starts(&data, CCS_KEYWORD_CAPABILITY)) |
+ CCS_MAX_MAC_CATEGORY_INDEX; |
454 |
for (i = 0; i < CCS_MAX_CAPABILITY_INDEX; i++) { |
config = profile->default_config; |
455 |
if (strcmp(data, |
} else if (ccs_str_starts(&data, "CONFIG::")) { |
456 |
ccs_mac_keywords[CCS_MAX_MAC_INDEX + i])) |
config = 0; |
457 |
continue; |
for (i = 0; i < CCS_MAX_MAC_INDEX + CCS_MAX_CAPABILITY_INDEX |
458 |
index = CCS_MAX_MAC_INDEX + i; |
+ CCS_MAX_MAC_CATEGORY_INDEX; i++) { |
|
break; |
|
|
} |
|
|
else |
|
|
for (i = 0; i < CCS_MAX_MAC_INDEX; i++) { |
|
459 |
if (strcmp(data, ccs_mac_keywords[i])) |
if (strcmp(data, ccs_mac_keywords[i])) |
460 |
continue; |
continue; |
461 |
index = i; |
config = profile->config[i]; |
462 |
break; |
break; |
463 |
} |
} |
464 |
if (index < 0) |
if (i == CCS_MAX_MAC_INDEX + CCS_MAX_CAPABILITY_INDEX |
465 |
|
+ CCS_MAX_MAC_CATEGORY_INDEX) |
466 |
|
return -EINVAL; |
467 |
|
} else { |
468 |
return -EINVAL; |
return -EINVAL; |
|
ccs_mac_keywords_used[index] = 1; |
|
|
ccs_profile->no_grant_log[index] = !!strstr(cp, "no_grant_log"); |
|
|
ccs_profile->no_reject_log[index] = !!strstr(cp, "no_reject_log"); |
|
|
for (mode = 0; mode < 4; mode++) |
|
|
if (strstr(cp, ccs_mode_4[mode])) |
|
|
ccs_profile->mac_mode[index] = mode; |
|
|
return 0; |
|
|
not_mac: |
|
|
for (i = 0; i < CCS_MAX_CONTROL_INDEX; i++) { |
|
|
if (strcmp(data, ccs_control_array[i].keyword)) |
|
|
continue; |
|
|
if (sscanf(cp, "%u", &value) != 1) { |
|
|
int j; |
|
|
for (j = 0; j < 2; j++) { |
|
|
if (strcmp(cp, ccs_mode_2[j])) |
|
|
continue; |
|
|
value = j; |
|
|
break; |
|
|
} |
|
|
if (j == 2) |
|
|
return -EINVAL; |
|
|
} else if (value > ccs_control_array[i].max_value) { |
|
|
value = ccs_control_array[i].max_value; |
|
|
} |
|
|
ccs_profile->value[i] = value; |
|
|
return 0; |
|
469 |
} |
} |
470 |
return -EINVAL; |
if (use_default) { |
471 |
} |
config = CCS_CONFIG_USE_DEFAULT; |
472 |
|
} else { |
473 |
static bool ccs_print_mac_mode(struct ccs_io_buffer *head, u8 index) |
for (mode = 3; mode >= 0; mode--) |
474 |
{ |
if (strstr(cp, ccs_mode_4[mode])) |
475 |
const int pos = head->read_avail; |
/* |
476 |
int i; |
* Update lower 3 bits in order to distinguish |
477 |
const struct ccs_profile *ccs_profile = ccs_profile_ptr[index]; |
* 'config' from 'CCS_CONFIG_USE_DEAFULT'. |
478 |
for (i = 0; i < CCS_MAX_MAC_INDEX + CCS_MAX_CAPABILITY_INDEX; i++) { |
*/ |
479 |
if (!ccs_mac_keywords_used[index]) |
config = (config & ~7) | mode; |
480 |
continue; |
#ifdef CONFIG_CCSECURITY_AUDIT |
481 |
if (!ccs_io_printf(head, "%u-MAC::%s%s=%s %s %s\n", index, |
if (config != CCS_CONFIG_USE_DEFAULT) { |
482 |
i >= CCS_MAX_MAC_INDEX ? |
if (strstr(cp, "grant_log=yes")) |
483 |
CCS_KEYWORD_CAPABILITY : "", |
config |= CCS_CONFIG_WANT_GRANT_LOG; |
484 |
ccs_mac_keywords[i], |
else if (strstr(cp, "grant_log=no")) |
485 |
ccs_mode_4[ccs_profile->mac_mode[i]], |
config &= ~CCS_CONFIG_WANT_GRANT_LOG; |
486 |
ccs_profile->no_grant_log[i] ? |
if (strstr(cp, "reject_log=yes")) |
487 |
"no_grant_log" : "", |
config |= CCS_CONFIG_WANT_REJECT_LOG; |
488 |
ccs_profile->no_reject_log[i] ? |
else if (strstr(cp, "reject_log=no")) |
489 |
"no_reject_log" : "")) |
config &= ~CCS_CONFIG_WANT_REJECT_LOG; |
490 |
goto out; |
} |
491 |
|
#endif |
492 |
} |
} |
493 |
return true; |
if (i < CCS_MAX_MAC_INDEX + CCS_MAX_CAPABILITY_INDEX |
494 |
out: |
+ CCS_MAX_MAC_CATEGORY_INDEX) |
495 |
head->read_avail = pos; |
profile->config[i] = config; |
496 |
return false; |
else if (config != CCS_CONFIG_USE_DEFAULT) |
497 |
|
profile->default_config = config; |
498 |
|
return 0; |
499 |
} |
} |
500 |
|
|
501 |
/** |
/** |
502 |
* ccs_read_profile - Read profile table. |
* ccs_read_profile - Read profile table. |
503 |
* |
* |
504 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
|
* |
|
|
* Returns 0. |
|
505 |
*/ |
*/ |
506 |
static int ccs_read_profile(struct ccs_io_buffer *head) |
static void ccs_read_profile(struct ccs_io_buffer *head) |
507 |
{ |
{ |
508 |
static const int ccs_total = CCS_MAX_CONTROL_INDEX + 2; |
int index; |
|
int step; |
|
509 |
if (head->read_eof) |
if (head->read_eof) |
510 |
return 0; |
return; |
511 |
for (step = head->read_step; step < CCS_MAX_PROFILES * ccs_total; |
if (head->read_bit) |
512 |
step++) { |
goto body; |
513 |
const u8 index = step / ccs_total; |
ccs_io_printf(head, "PROFILE_VERSION=%s\n", "20090903"); |
514 |
u8 type = step % ccs_total; |
ccs_io_printf(head, "PREFERENCE::audit={ " |
515 |
const struct ccs_profile *ccs_profile = ccs_profile_ptr[index]; |
#ifdef CONFIG_CCSECURITY_AUDIT |
516 |
head->read_step = step; |
"max_grant_log=%u max_reject_log=%u " |
517 |
if (!ccs_profile) |
#endif |
518 |
continue; |
"task_info=%s path_info=%s }\n", |
519 |
if (!type) { /* Print profile' comment tag. */ |
#ifdef CONFIG_CCSECURITY_AUDIT |
520 |
bool done; |
ccs_default_profile.preference.audit_max_grant_log, |
521 |
spin_lock(&ccs_profile_comment_lock); |
ccs_default_profile.preference.audit_max_reject_log, |
522 |
done = ccs_io_printf(head, "%u-COMMENT=%s\n", |
#endif |
523 |
index, ccs_profile->comment ? |
ccs_yesno(ccs_default_profile.preference. |
524 |
ccs_profile->comment->name : ""); |
audit_task_info), |
525 |
spin_unlock(&ccs_profile_comment_lock); |
ccs_yesno(ccs_default_profile.preference. |
526 |
if (!done) |
audit_path_info)); |
527 |
break; |
ccs_io_printf(head, "PREFERENCE::learning={ verbose=%s max_entry=%u " |
528 |
continue; |
"exec.realpath=%s exec.argv0=%s symlink.target=%s }\n", |
529 |
} else if (type == 1) { |
ccs_yesno(ccs_default_profile.preference. |
530 |
if (!ccs_print_mac_mode(head, index)) |
learning_verbose), |
531 |
break; |
ccs_default_profile.preference.learning_max_entry, |
532 |
|
ccs_yesno(ccs_default_profile.preference. |
533 |
|
learning_exec_realpath), |
534 |
|
ccs_yesno(ccs_default_profile.preference. |
535 |
|
learning_exec_argv0), |
536 |
|
ccs_yesno(ccs_default_profile.preference. |
537 |
|
learning_symlink_target)); |
538 |
|
ccs_io_printf(head, "PREFERENCE::permissive={ verbose=%s }\n", |
539 |
|
ccs_yesno(ccs_default_profile.preference. |
540 |
|
permissive_verbose)); |
541 |
|
ccs_io_printf(head, "PREFERENCE::enforcing={ verbose=%s penalty=%u " |
542 |
|
"}\n", |
543 |
|
ccs_yesno(ccs_default_profile.preference. |
544 |
|
enforcing_verbose), |
545 |
|
ccs_default_profile.preference.enforcing_penalty); |
546 |
|
head->read_bit = 1; |
547 |
|
body: |
548 |
|
for (index = head->read_step; index < CCS_MAX_PROFILES; index++) { |
549 |
|
bool done; |
550 |
|
u8 config; |
551 |
|
int i; |
552 |
|
int pos; |
553 |
|
const struct ccs_profile *profile = ccs_profile_ptr[index]; |
554 |
|
head->read_step = index; |
555 |
|
if (!profile) |
556 |
continue; |
continue; |
557 |
|
pos = head->read_avail; |
558 |
|
spin_lock(&ccs_profile_comment_lock); |
559 |
|
done = ccs_io_printf(head, "%u-COMMENT=%s\n", index, |
560 |
|
profile->comment ? profile->comment->name |
561 |
|
: ""); |
562 |
|
spin_unlock(&ccs_profile_comment_lock); |
563 |
|
if (!done) |
564 |
|
goto out; |
565 |
|
config = profile->default_config; |
566 |
|
#ifdef CONFIG_CCSECURITY_AUDIT |
567 |
|
if (!ccs_io_printf(head, "%u-CONFIG={ mode=%s grant_log=%s " |
568 |
|
"reject_log=%s }\n", index, |
569 |
|
ccs_mode_4[config & 3], |
570 |
|
ccs_yesno(config & |
571 |
|
CCS_CONFIG_WANT_GRANT_LOG), |
572 |
|
ccs_yesno(config & |
573 |
|
CCS_CONFIG_WANT_REJECT_LOG))) |
574 |
|
goto out; |
575 |
|
#else |
576 |
|
if (!ccs_io_printf(head, "%u-CONFIG={ mode=%s }\n", index, |
577 |
|
ccs_mode_4[config & 3])) |
578 |
|
goto out; |
579 |
|
#endif |
580 |
|
for (i = 0; i < CCS_MAX_MAC_INDEX + CCS_MAX_CAPABILITY_INDEX |
581 |
|
+ CCS_MAX_MAC_CATEGORY_INDEX; i++) { |
582 |
|
#ifdef CONFIG_CCSECURITY_AUDIT |
583 |
|
const char *g; |
584 |
|
const char *r; |
585 |
|
#endif |
586 |
|
config = profile->config[i]; |
587 |
|
if (config == CCS_CONFIG_USE_DEFAULT) |
588 |
|
continue; |
589 |
|
#ifdef CONFIG_CCSECURITY_AUDIT |
590 |
|
g = ccs_yesno(config & CCS_CONFIG_WANT_GRANT_LOG); |
591 |
|
r = ccs_yesno(config & CCS_CONFIG_WANT_REJECT_LOG); |
592 |
|
if (!ccs_io_printf(head, "%u-CONFIG::%s={ mode=%s " |
593 |
|
"grant_log=%s reject_log=%s }\n", |
594 |
|
index, ccs_mac_keywords[i], |
595 |
|
ccs_mode_4[config & 3], g, r)) |
596 |
|
goto out; |
597 |
|
#else |
598 |
|
if (!ccs_io_printf(head, "%u-CONFIG::%s={ mode=%s }\n", |
599 |
|
index, ccs_mac_keywords[i], |
600 |
|
ccs_mode_4[config & 3])) |
601 |
|
goto out; |
602 |
|
#endif |
603 |
} |
} |
604 |
type -= 2; |
if (profile->audit != &ccs_default_profile.preference && |
605 |
{ |
!ccs_io_printf(head, "%u-PREFERENCE::audit={ " |
606 |
const unsigned int value = ccs_profile->value[type]; |
#ifdef CONFIG_CCSECURITY_AUDIT |
607 |
const char *keyword = ccs_control_array[type].keyword; |
"max_grant_log=%u max_reject_log=%u " |
608 |
if (ccs_control_array[type].max_value == 1) { |
#endif |
609 |
if (!ccs_io_printf(head, "%u-%s=%s\n", index, |
"task_info=%s path_info=%s }\n", index, |
610 |
keyword, ccs_mode_2[value])) |
#ifdef CONFIG_CCSECURITY_AUDIT |
611 |
break; |
profile->preference.audit_max_grant_log, |
612 |
} else { |
profile->preference.audit_max_reject_log, |
613 |
if (!ccs_io_printf(head, "%u-%s=%u\n", index, |
#endif |
614 |
keyword, value)) |
ccs_yesno(profile->preference. |
615 |
break; |
audit_task_info), |
616 |
} |
ccs_yesno(profile->preference. |
617 |
} |
audit_path_info))) |
618 |
|
goto out; |
619 |
|
if (profile->learning != &ccs_default_profile.preference && |
620 |
|
!ccs_io_printf(head, "%u-PREFERENCE::learning={ " |
621 |
|
"verbose=%s max_entry=%u exec.realpath=%s " |
622 |
|
"exec.argv0=%s symlink.target=%s }\n", |
623 |
|
index, |
624 |
|
ccs_yesno(profile->preference. |
625 |
|
learning_verbose), |
626 |
|
profile->preference.learning_max_entry, |
627 |
|
ccs_yesno(profile->preference. |
628 |
|
learning_exec_realpath), |
629 |
|
ccs_yesno(profile->preference. |
630 |
|
learning_exec_argv0), |
631 |
|
ccs_yesno(profile->preference. |
632 |
|
learning_symlink_target))) |
633 |
|
goto out; |
634 |
|
if (profile->permissive != &ccs_default_profile.preference && |
635 |
|
!ccs_io_printf(head, "%u-PREFERENCE::permissive={ " |
636 |
|
"verbose=%s }\n", index, |
637 |
|
ccs_yesno(profile->preference. |
638 |
|
permissive_verbose))) |
639 |
|
goto out; |
640 |
|
if (profile->enforcing != &ccs_default_profile.preference && |
641 |
|
!ccs_io_printf(head, "%u-PREFERENCE::enforcing={ " |
642 |
|
"verbose=%s penalty=%u }\n", index, |
643 |
|
ccs_yesno(profile->preference. |
644 |
|
enforcing_verbose), |
645 |
|
profile->preference.enforcing_penalty)) |
646 |
|
goto out; |
647 |
|
continue; |
648 |
|
out: |
649 |
|
head->read_avail = pos; |
650 |
|
break; |
651 |
} |
} |
652 |
if (step == CCS_MAX_PROFILES * ccs_total) |
if (index == CCS_MAX_PROFILES) |
653 |
head->read_eof = true; |
head->read_eof = true; |
|
return 0; |
|
654 |
} |
} |
655 |
|
|
656 |
/* The list for "struct ccs_policy_manager_entry". */ |
/* The list for "struct ccs_policy_manager_entry". */ |
725 |
* |
* |
726 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
727 |
* |
* |
|
* Returns 0. |
|
|
* |
|
728 |
* Caller holds ccs_read_lock(). |
* Caller holds ccs_read_lock(). |
729 |
*/ |
*/ |
730 |
static int ccs_read_manager_policy(struct ccs_io_buffer *head) |
static void ccs_read_manager_policy(struct ccs_io_buffer *head) |
731 |
{ |
{ |
732 |
struct list_head *pos; |
struct list_head *pos; |
|
ccs_assert_read_lock(); |
|
733 |
if (head->read_eof) |
if (head->read_eof) |
734 |
return 0; |
return; |
735 |
list_for_each_cookie(pos, head->read_var2, &ccs_policy_manager_list) { |
list_for_each_cookie(pos, head->read_var2, &ccs_policy_manager_list) { |
736 |
struct ccs_policy_manager_entry *ptr; |
struct ccs_policy_manager_entry *ptr; |
737 |
ptr = list_entry(pos, struct ccs_policy_manager_entry, list); |
ptr = list_entry(pos, struct ccs_policy_manager_entry, list); |
738 |
if (ptr->is_deleted) |
if (ptr->is_deleted) |
739 |
continue; |
continue; |
740 |
if (!ccs_io_printf(head, "%s\n", ptr->manager->name)) |
if (!ccs_io_printf(head, "%s\n", ptr->manager->name)) |
741 |
return 0; |
return; |
742 |
} |
} |
743 |
head->read_eof = true; |
head->read_eof = true; |
|
return 0; |
|
744 |
} |
} |
745 |
|
|
746 |
/** |
/** |
759 |
const struct ccs_path_info *domainname |
const struct ccs_path_info *domainname |
760 |
= ccs_current_domain()->domainname; |
= ccs_current_domain()->domainname; |
761 |
bool found = false; |
bool found = false; |
|
ccs_assert_read_lock(); |
|
762 |
if (!ccs_policy_loaded) |
if (!ccs_policy_loaded) |
763 |
return true; |
return true; |
764 |
if (task->ccs_flags & CCS_TASK_IS_POLICY_MANAGER) |
if (task->ccs_flags & CCS_TASK_IS_POLICY_MANAGER) |
839 |
{ |
{ |
840 |
unsigned int pid; |
unsigned int pid; |
841 |
struct ccs_domain_info *domain = NULL; |
struct ccs_domain_info *domain = NULL; |
842 |
ccs_assert_read_lock(); |
bool global_pid = false; |
843 |
if (!strcmp(data, "allow_execute")) { |
if (!strcmp(data, "allow_execute")) { |
844 |
head->read_execute_only = true; |
head->read_execute_only = true; |
845 |
return true; |
return true; |
846 |
} |
} |
847 |
if (sscanf(data, "pid=%u", &pid) == 1) { |
if (sscanf(data, "pid=%u", &pid) == 1 || |
848 |
|
(global_pid = true, sscanf(data, "global-pid=%u", &pid) == 1)) { |
849 |
struct task_struct *p; |
struct task_struct *p; |
850 |
read_lock(&tasklist_lock); |
read_lock(&tasklist_lock); |
851 |
|
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24) |
852 |
|
if (global_pid) |
853 |
|
p = find_task_by_pid_ns(pid, &init_pid_ns); |
854 |
|
else |
855 |
|
p = find_task_by_vpid(pid); |
856 |
|
#else |
857 |
p = find_task_by_pid(pid); |
p = find_task_by_pid(pid); |
858 |
|
#endif |
859 |
if (p) |
if (p) |
860 |
domain = ccs_task_domain(p); |
domain = ccs_task_domain(p); |
861 |
read_unlock(&tasklist_lock); |
read_unlock(&tasklist_lock); |
904 |
return ccs_write_env_policy(data, domain, cond, is_delete); |
return ccs_write_env_policy(data, domain, cond, is_delete); |
905 |
if (ccs_str_starts(&data, CCS_KEYWORD_ALLOW_MOUNT)) |
if (ccs_str_starts(&data, CCS_KEYWORD_ALLOW_MOUNT)) |
906 |
return ccs_write_mount_policy(data, domain, cond, is_delete); |
return ccs_write_mount_policy(data, domain, cond, is_delete); |
|
if (ccs_str_starts(&data, CCS_KEYWORD_ALLOW_UNMOUNT)) |
|
|
return ccs_write_umount_policy(data, domain, cond, is_delete); |
|
|
if (ccs_str_starts(&data, CCS_KEYWORD_ALLOW_CHROOT)) |
|
|
return ccs_write_chroot_policy(data, domain, cond, is_delete); |
|
|
if (ccs_str_starts(&data, CCS_KEYWORD_ALLOW_PIVOT_ROOT)) |
|
|
return ccs_write_pivot_root_policy(data, domain, cond, |
|
|
is_delete); |
|
907 |
return ccs_write_file_policy(data, domain, cond, is_delete); |
return ccs_write_file_policy(data, domain, cond, is_delete); |
908 |
} |
} |
909 |
|
|
949 |
|
|
950 |
if (sscanf(data, CCS_KEYWORD_USE_PROFILE "%u", &profile) == 1 |
if (sscanf(data, CCS_KEYWORD_USE_PROFILE "%u", &profile) == 1 |
951 |
&& profile < CCS_MAX_PROFILES) { |
&& profile < CCS_MAX_PROFILES) { |
952 |
if (ccs_profile_ptr[profile] || !ccs_policy_loaded) |
if (!ccs_policy_loaded || ccs_profile_ptr[(u8) profile]) |
953 |
domain->profile = (u8) profile; |
domain->profile = (u8) profile; |
954 |
return 0; |
return 0; |
955 |
} |
} |
973 |
return error; |
return error; |
974 |
} |
} |
975 |
|
|
976 |
|
/** |
977 |
|
* ccs_print_name_union - Print a ccs_name_union. |
978 |
|
* |
979 |
|
* @head: Pointer to "struct ccs_io_buffer". |
980 |
|
* @ptr: Pointer to "struct ccs_name_union". |
981 |
|
* |
982 |
|
* Returns true on success, false otherwise. |
983 |
|
*/ |
984 |
static bool ccs_print_name_union(struct ccs_io_buffer *head, |
static bool ccs_print_name_union(struct ccs_io_buffer *head, |
985 |
const struct ccs_name_union *ptr) |
const struct ccs_name_union *ptr) |
986 |
{ |
{ |
993 |
return ccs_io_printf(head, " %s", ptr->filename->name); |
return ccs_io_printf(head, " %s", ptr->filename->name); |
994 |
} |
} |
995 |
|
|
996 |
|
/** |
997 |
|
* ccs_print_name_union_quoted - Print a ccs_name_union with double quotes. |
998 |
|
* |
999 |
|
* @head: Pointer to "struct ccs_io_buffer". |
1000 |
|
* @ptr: Pointer to "struct ccs_name_union". |
1001 |
|
* |
1002 |
|
* Returns true on success, false otherwise. |
1003 |
|
*/ |
1004 |
static bool ccs_print_name_union_quoted(struct ccs_io_buffer *head, |
static bool ccs_print_name_union_quoted(struct ccs_io_buffer *head, |
1005 |
const struct ccs_name_union *ptr) |
const struct ccs_name_union *ptr) |
1006 |
{ |
{ |
1010 |
return ccs_io_printf(head, "\"%s\"", ptr->filename->name); |
return ccs_io_printf(head, "\"%s\"", ptr->filename->name); |
1011 |
} |
} |
1012 |
|
|
1013 |
|
/** |
1014 |
|
* ccs_print_number_union_common - Print a ccs_number_union. |
1015 |
|
* |
1016 |
|
* @head: Pointer to "struct ccs_io_buffer". |
1017 |
|
* @ptr: Pointer to "struct ccs_number_union". |
1018 |
|
* @need_space: True if a space character is needed. |
1019 |
|
* |
1020 |
|
* Returns true on success, false otherwise. |
1021 |
|
*/ |
1022 |
static bool ccs_print_number_union_common(struct ccs_io_buffer *head, |
static bool ccs_print_number_union_common(struct ccs_io_buffer *head, |
1023 |
const struct ccs_number_union *ptr, |
const struct ccs_number_union *ptr, |
1024 |
const bool need_space) |
const bool need_space) |
1062 |
} |
} |
1063 |
} |
} |
1064 |
|
|
1065 |
|
/** |
1066 |
|
* ccs_print_number_union - Print a ccs_number_union. |
1067 |
|
* |
1068 |
|
* @head: Pointer to "struct ccs_io_buffer". |
1069 |
|
* @ptr: Pointer to "struct ccs_number_union". |
1070 |
|
* |
1071 |
|
* Returns true on success, false otherwise. |
1072 |
|
*/ |
1073 |
bool ccs_print_number_union(struct ccs_io_buffer *head, |
bool ccs_print_number_union(struct ccs_io_buffer *head, |
1074 |
const struct ccs_number_union *ptr) |
const struct ccs_number_union *ptr) |
1075 |
{ |
{ |
1076 |
return ccs_print_number_union_common(head, ptr, true); |
return ccs_print_number_union_common(head, ptr, true); |
1077 |
} |
} |
1078 |
|
|
1079 |
|
/** |
1080 |
|
* ccs_print_number_union_nospace - Print a ccs_number_union without a space character. |
1081 |
|
* |
1082 |
|
* @head: Pointer to "struct ccs_io_buffer". |
1083 |
|
* @ptr: Pointer to "struct ccs_number_union". |
1084 |
|
* |
1085 |
|
* Returns true on success, false otherwise. |
1086 |
|
*/ |
1087 |
static bool ccs_print_number_union_nospace(struct ccs_io_buffer *head, |
static bool ccs_print_number_union_nospace(struct ccs_io_buffer *head, |
1088 |
const struct ccs_number_union *ptr) |
const struct ccs_number_union *ptr) |
1089 |
{ |
{ |
1211 |
* Returns true on success, false otherwise. |
* Returns true on success, false otherwise. |
1212 |
*/ |
*/ |
1213 |
static bool ccs_print_path_acl(struct ccs_io_buffer *head, |
static bool ccs_print_path_acl(struct ccs_io_buffer *head, |
1214 |
struct ccs_path_acl *ptr, |
struct ccs_path_acl *ptr, |
1215 |
const struct ccs_condition *cond) |
const struct ccs_condition *cond) |
1216 |
{ |
{ |
1217 |
int pos; |
int pos; |
1218 |
u8 bit; |
u8 bit; |
1249 |
* Returns true on success, false otherwise. |
* Returns true on success, false otherwise. |
1250 |
*/ |
*/ |
1251 |
static bool ccs_print_path_number3_acl(struct ccs_io_buffer *head, |
static bool ccs_print_path_number3_acl(struct ccs_io_buffer *head, |
1252 |
struct ccs_path_number3_acl *ptr, |
struct ccs_path_number3_acl *ptr, |
1253 |
const struct ccs_condition *cond) |
const struct ccs_condition *cond) |
1254 |
{ |
{ |
1255 |
int pos; |
int pos; |
1256 |
u8 bit; |
u8 bit; |
1277 |
} |
} |
1278 |
|
|
1279 |
/** |
/** |
1280 |
* ccs_print_path2_acl - Print a double path ACL entry. |
* ccs_print_path2_acl - Print a path2 ACL entry. |
1281 |
* |
* |
1282 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1283 |
* @ptr: Pointer to "struct ccs_path2_acl". |
* @ptr: Pointer to "struct ccs_path2_acl". |
1286 |
* Returns true on success, false otherwise. |
* Returns true on success, false otherwise. |
1287 |
*/ |
*/ |
1288 |
static bool ccs_print_path2_acl(struct ccs_io_buffer *head, |
static bool ccs_print_path2_acl(struct ccs_io_buffer *head, |
1289 |
struct ccs_path2_acl *ptr, |
struct ccs_path2_acl *ptr, |
1290 |
const struct ccs_condition *cond) |
const struct ccs_condition *cond) |
1291 |
{ |
{ |
1292 |
int pos; |
int pos; |
1293 |
u8 bit; |
u8 bit; |
1311 |
} |
} |
1312 |
|
|
1313 |
/** |
/** |
1314 |
* ccs_print_path_number_acl - Print an ioctl/chmod/chown/chgrp ACL entry. |
* ccs_print_path_number_acl - Print a path_number ACL entry. |
1315 |
* |
* |
1316 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1317 |
* @ptr: Pointer to "struct ccs_path_number_acl". |
* @ptr: Pointer to "struct ccs_path_number_acl". |
1553 |
} |
} |
1554 |
|
|
1555 |
/** |
/** |
|
* ccs_print_umount_acl - Print a mount ACL entry. |
|
|
* |
|
|
* @head: Pointer to "struct ccs_io_buffer". |
|
|
* @ptr: Pointer to "struct ccs_umount_acl". |
|
|
* @cond: Pointer to "struct ccs_condition". May be NULL. |
|
|
* |
|
|
* Returns true on success, false otherwise. |
|
|
*/ |
|
|
static bool ccs_print_umount_acl(struct ccs_io_buffer *head, |
|
|
struct ccs_umount_acl *ptr, |
|
|
const struct ccs_condition *cond) |
|
|
{ |
|
|
const int pos = head->read_avail; |
|
|
if (!ccs_io_printf(head, CCS_KEYWORD_ALLOW_UNMOUNT) || |
|
|
!ccs_print_name_union(head, &ptr->dir) || |
|
|
!ccs_print_condition(head, cond)) { |
|
|
head->read_avail = pos; |
|
|
return false; |
|
|
} |
|
|
return true; |
|
|
} |
|
|
|
|
|
/** |
|
|
* ccs_print_chroot_acl - Print a chroot ACL entry. |
|
|
* |
|
|
* @head: Pointer to "struct ccs_io_buffer". |
|
|
* @ptr: Pointer to "struct ccs_chroot_acl". |
|
|
* @cond: Pointer to "struct ccs_condition". May be NULL. |
|
|
* |
|
|
* Returns true on success, false otherwise. |
|
|
*/ |
|
|
static bool ccs_print_chroot_acl(struct ccs_io_buffer *head, |
|
|
struct ccs_chroot_acl *ptr, |
|
|
const struct ccs_condition *cond) |
|
|
{ |
|
|
const int pos = head->read_avail; |
|
|
if (!ccs_io_printf(head, CCS_KEYWORD_ALLOW_CHROOT) || |
|
|
!ccs_print_name_union(head, &ptr->dir) || |
|
|
!ccs_print_condition(head, cond)) { |
|
|
head->read_avail = pos; |
|
|
return false; |
|
|
} |
|
|
return true; |
|
|
} |
|
|
|
|
|
/** |
|
|
* ccs_print_pivot_root_acl - Print a pivot_root ACL entry. |
|
|
* |
|
|
* @head: Pointer to "struct ccs_io_buffer". |
|
|
* @ptr: Pointer to "struct ccs_pivot_root_acl". |
|
|
* @cond: Pointer to "struct ccs_condition". May be NULL. |
|
|
* |
|
|
* Returns true on success, false otherwise. |
|
|
*/ |
|
|
static bool ccs_print_pivot_root_acl(struct ccs_io_buffer *head, |
|
|
struct ccs_pivot_root_acl *ptr, |
|
|
const struct ccs_condition *cond) |
|
|
{ |
|
|
const int pos = head->read_avail; |
|
|
if (!ccs_io_printf(head, CCS_KEYWORD_ALLOW_PIVOT_ROOT) || |
|
|
!ccs_print_name_union(head, &ptr->new_root) || |
|
|
!ccs_print_name_union(head, &ptr->old_root) || |
|
|
!ccs_print_condition(head, cond)) { |
|
|
head->read_avail = pos; |
|
|
return false; |
|
|
} |
|
|
return true; |
|
|
} |
|
|
|
|
|
/** |
|
1556 |
* ccs_print_entry - Print an ACL entry. |
* ccs_print_entry - Print an ACL entry. |
1557 |
* |
* |
1558 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1569 |
return true; |
return true; |
1570 |
if (acl_type == CCS_TYPE_PATH_ACL) { |
if (acl_type == CCS_TYPE_PATH_ACL) { |
1571 |
struct ccs_path_acl *acl |
struct ccs_path_acl *acl |
1572 |
= container_of(ptr, struct ccs_path_acl, |
= container_of(ptr, struct ccs_path_acl, head); |
|
head); |
|
1573 |
return ccs_print_path_acl(head, acl, cond); |
return ccs_print_path_acl(head, acl, cond); |
1574 |
} |
} |
1575 |
if (acl_type == CCS_TYPE_EXECUTE_HANDLER) { |
if (acl_type == CCS_TYPE_EXECUTE_HANDLER) { |
1632 |
= container_of(ptr, struct ccs_mount_acl, head); |
= container_of(ptr, struct ccs_mount_acl, head); |
1633 |
return ccs_print_mount_acl(head, acl, cond); |
return ccs_print_mount_acl(head, acl, cond); |
1634 |
} |
} |
|
if (acl_type == CCS_TYPE_UMOUNT_ACL) { |
|
|
struct ccs_umount_acl *acl |
|
|
= container_of(ptr, struct ccs_umount_acl, head); |
|
|
return ccs_print_umount_acl(head, acl, cond); |
|
|
} |
|
|
if (acl_type == CCS_TYPE_CHROOT_ACL) { |
|
|
struct ccs_chroot_acl *acl |
|
|
= container_of(ptr, struct ccs_chroot_acl, head); |
|
|
return ccs_print_chroot_acl(head, acl, cond); |
|
|
} |
|
|
if (acl_type == CCS_TYPE_PIVOT_ROOT_ACL) { |
|
|
struct ccs_pivot_root_acl *acl |
|
|
= container_of(ptr, struct ccs_pivot_root_acl, |
|
|
head); |
|
|
return ccs_print_pivot_root_acl(head, acl, cond); |
|
|
} |
|
1635 |
BUG(); /* This must not happen. */ |
BUG(); /* This must not happen. */ |
1636 |
return false; |
return false; |
1637 |
} |
} |
1641 |
* |
* |
1642 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1643 |
* |
* |
|
* Returns 0. |
|
|
* |
|
1644 |
* Caller holds ccs_read_lock(). |
* Caller holds ccs_read_lock(). |
1645 |
*/ |
*/ |
1646 |
static int ccs_read_domain_policy(struct ccs_io_buffer *head) |
static void ccs_read_domain_policy(struct ccs_io_buffer *head) |
1647 |
{ |
{ |
1648 |
struct list_head *dpos; |
struct list_head *dpos; |
1649 |
struct list_head *apos; |
struct list_head *apos; |
|
ccs_assert_read_lock(); |
|
1650 |
if (head->read_eof) |
if (head->read_eof) |
1651 |
return 0; |
return; |
1652 |
if (head->read_step == 0) |
if (head->read_step == 0) |
1653 |
head->read_step = 1; |
head->read_step = 1; |
1654 |
list_for_each_cookie(dpos, head->read_var1, &ccs_domain_list) { |
list_for_each_cookie(dpos, head->read_var1, &ccs_domain_list) { |
1679 |
transition_failed, |
transition_failed, |
1680 |
ignore_global_allow_read, |
ignore_global_allow_read, |
1681 |
ignore_global_allow_env)) |
ignore_global_allow_env)) |
1682 |
return 0; |
return; |
1683 |
head->read_step = 2; |
head->read_step = 2; |
1684 |
acl_loop: |
acl_loop: |
1685 |
if (head->read_step == 3) |
if (head->read_step == 3) |
1690 |
struct ccs_acl_info *ptr |
struct ccs_acl_info *ptr |
1691 |
= list_entry(apos, struct ccs_acl_info, list); |
= list_entry(apos, struct ccs_acl_info, list); |
1692 |
if (!ccs_print_entry(head, ptr)) |
if (!ccs_print_entry(head, ptr)) |
1693 |
return 0; |
return; |
1694 |
} |
} |
1695 |
head->read_step = 3; |
head->read_step = 3; |
1696 |
tail_mark: |
tail_mark: |
1697 |
if (!ccs_io_printf(head, "\n")) |
if (!ccs_io_printf(head, "\n")) |
1698 |
return 0; |
return; |
1699 |
head->read_step = 1; |
head->read_step = 1; |
1700 |
if (head->read_single_domain) |
if (head->read_single_domain) |
1701 |
break; |
break; |
1702 |
} |
} |
1703 |
head->read_eof = true; |
head->read_eof = true; |
|
return 0; |
|
1704 |
} |
} |
1705 |
|
|
1706 |
/** |
/** |
1713 |
* This is equivalent to doing |
* This is equivalent to doing |
1714 |
* |
* |
1715 |
* ( echo "select " $domainname; echo "use_profile " $profile ) | |
* ( echo "select " $domainname; echo "use_profile " $profile ) | |
1716 |
* /usr/lib/ccs/loadpolicy -d |
* /usr/sbin/ccs-loadpolicy -d |
1717 |
* |
* |
1718 |
* Caller holds ccs_read_lock(). |
* Caller holds ccs_read_lock(). |
1719 |
*/ |
*/ |
1723 |
char *cp = strchr(data, ' '); |
char *cp = strchr(data, ' '); |
1724 |
struct ccs_domain_info *domain; |
struct ccs_domain_info *domain; |
1725 |
unsigned int profile; |
unsigned int profile; |
|
ccs_assert_read_lock(); |
|
1726 |
if (!cp) |
if (!cp) |
1727 |
return -EINVAL; |
return -EINVAL; |
1728 |
*cp = '\0'; |
*cp = '\0'; |
1730 |
if (profile >= CCS_MAX_PROFILES) |
if (profile >= CCS_MAX_PROFILES) |
1731 |
return -EINVAL; |
return -EINVAL; |
1732 |
domain = ccs_find_domain(cp + 1); |
domain = ccs_find_domain(cp + 1); |
1733 |
if (domain && (ccs_profile_ptr[profile] || !ccs_policy_loaded)) |
if (domain && (!ccs_policy_loaded || ccs_profile_ptr[(u8) profile])) |
1734 |
domain->profile = (u8) profile; |
domain->profile = (u8) profile; |
1735 |
return 0; |
return 0; |
1736 |
} |
} |
1740 |
* |
* |
1741 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1742 |
* |
* |
|
* Returns list of profile number and domainname pairs. |
|
|
* |
|
1743 |
* This is equivalent to doing |
* This is equivalent to doing |
1744 |
* |
* |
1745 |
* grep -A 1 '^<kernel>' /proc/ccs/domain_policy | |
* grep -A 1 '^<kernel>' /proc/ccs/domain_policy | |
1749 |
* |
* |
1750 |
* Caller holds ccs_read_lock(). |
* Caller holds ccs_read_lock(). |
1751 |
*/ |
*/ |
1752 |
static int ccs_read_domain_profile(struct ccs_io_buffer *head) |
static void ccs_read_domain_profile(struct ccs_io_buffer *head) |
1753 |
{ |
{ |
1754 |
struct list_head *pos; |
struct list_head *pos; |
|
ccs_assert_read_lock(); |
|
1755 |
if (head->read_eof) |
if (head->read_eof) |
1756 |
return 0; |
return; |
1757 |
list_for_each_cookie(pos, head->read_var1, &ccs_domain_list) { |
list_for_each_cookie(pos, head->read_var1, &ccs_domain_list) { |
1758 |
struct ccs_domain_info *domain; |
struct ccs_domain_info *domain; |
1759 |
domain = list_entry(pos, struct ccs_domain_info, list); |
domain = list_entry(pos, struct ccs_domain_info, list); |
1761 |
continue; |
continue; |
1762 |
if (!ccs_io_printf(head, "%u %s\n", domain->profile, |
if (!ccs_io_printf(head, "%u %s\n", domain->profile, |
1763 |
domain->domainname->name)) |
domain->domainname->name)) |
1764 |
return 0; |
return; |
1765 |
} |
} |
1766 |
head->read_eof = true; |
head->read_eof = true; |
|
return 0; |
|
1767 |
} |
} |
1768 |
|
|
1769 |
/** |
/** |
1790 |
* |
* |
1791 |
* Caller holds ccs_read_lock(). |
* Caller holds ccs_read_lock(). |
1792 |
*/ |
*/ |
1793 |
static int ccs_read_pid(struct ccs_io_buffer *head) |
static void ccs_read_pid(struct ccs_io_buffer *head) |
1794 |
{ |
{ |
1795 |
char *buf = head->write_buf; |
char *buf = head->write_buf; |
1796 |
bool task_info = false; |
bool task_info = false; |
1797 |
|
bool global_pid = false; |
1798 |
unsigned int pid; |
unsigned int pid; |
1799 |
struct task_struct *p; |
struct task_struct *p; |
1800 |
struct ccs_domain_info *domain = NULL; |
struct ccs_domain_info *domain = NULL; |
1801 |
u32 ccs_flags = 0; |
u32 ccs_flags = 0; |
|
ccs_assert_read_lock(); |
|
1802 |
/* Accessing write_buf is safe because head->io_sem is held. */ |
/* Accessing write_buf is safe because head->io_sem is held. */ |
1803 |
if (!buf) |
if (!buf) |
1804 |
goto done; /* Do nothing if open(O_RDONLY). */ |
return; /* Do nothing if open(O_RDONLY). */ |
1805 |
if (head->read_avail || head->read_eof) |
if (head->read_avail || head->read_eof) |
1806 |
goto done; |
return; |
1807 |
head->read_eof = true; |
head->read_eof = true; |
1808 |
if (ccs_str_starts(&buf, "info ")) |
if (ccs_str_starts(&buf, "info ")) |
1809 |
task_info = true; |
task_info = true; |
1810 |
|
if (ccs_str_starts(&buf, "global-pid ")) |
1811 |
|
global_pid = true; |
1812 |
pid = (unsigned int) simple_strtoul(buf, NULL, 10); |
pid = (unsigned int) simple_strtoul(buf, NULL, 10); |
1813 |
read_lock(&tasklist_lock); |
read_lock(&tasklist_lock); |
1814 |
|
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24) |
1815 |
|
if (global_pid) |
1816 |
|
p = find_task_by_pid_ns(pid, &init_pid_ns); |
1817 |
|
else |
1818 |
|
p = find_task_by_vpid(pid); |
1819 |
|
#else |
1820 |
p = find_task_by_pid(pid); |
p = find_task_by_pid(pid); |
1821 |
|
#endif |
1822 |
if (p) { |
if (p) { |
1823 |
domain = ccs_task_domain(p); |
domain = ccs_task_domain(p); |
1824 |
ccs_flags = p->ccs_flags; |
ccs_flags = p->ccs_flags; |
1825 |
} |
} |
1826 |
read_unlock(&tasklist_lock); |
read_unlock(&tasklist_lock); |
1827 |
if (!domain) |
if (!domain) |
1828 |
goto done; |
return; |
1829 |
if (!task_info) |
if (!task_info) |
1830 |
ccs_io_printf(head, "%u %u %s", pid, domain->profile, |
ccs_io_printf(head, "%u %u %s", pid, domain->profile, |
1831 |
domain->domainname->name); |
domain->domainname->name); |
1832 |
else |
else |
1833 |
ccs_io_printf(head, "%u manager=%s execute_handler=%s " |
ccs_io_printf(head, "%u manager=%s execute_handler=%s " |
1834 |
"state[0]=%u state[1]=%u state[2]=%u", pid, |
"state[0]=%u state[1]=%u state[2]=%u", pid, |
1835 |
ccs_flags & CCS_TASK_IS_POLICY_MANAGER ? |
ccs_yesno(ccs_flags & |
1836 |
"yes" : "no", |
CCS_TASK_IS_POLICY_MANAGER), |
1837 |
ccs_flags & CCS_TASK_IS_EXECUTE_HANDLER ? |
ccs_yesno(ccs_flags & |
1838 |
"yes" : "no", |
CCS_TASK_IS_EXECUTE_HANDLER), |
1839 |
(u8) (ccs_flags >> 24), |
(u8) (ccs_flags >> 24), |
1840 |
(u8) (ccs_flags >> 16), |
(u8) (ccs_flags >> 16), |
1841 |
(u8) (ccs_flags >> 8)); |
(u8) (ccs_flags >> 8)); |
|
done: |
|
|
return 0; |
|
1842 |
} |
} |
1843 |
|
|
1844 |
/** |
/** |
1888 |
* |
* |
1889 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1890 |
* |
* |
|
* Returns 0 on success, -EINVAL otherwise. |
|
|
* |
|
1891 |
* Caller holds ccs_read_lock(). |
* Caller holds ccs_read_lock(). |
1892 |
*/ |
*/ |
1893 |
static int ccs_read_exception_policy(struct ccs_io_buffer *head) |
static void ccs_read_exception_policy(struct ccs_io_buffer *head) |
1894 |
{ |
{ |
1895 |
ccs_assert_read_lock(); |
if (head->read_eof) |
1896 |
if (!head->read_eof) { |
return; |
1897 |
switch (head->read_step) { |
switch (head->read_step) { |
1898 |
case 0: |
case 0: |
1899 |
head->read_var2 = NULL; |
head->read_var2 = NULL; |
1900 |
head->read_step = 1; |
head->read_step = 1; |
1901 |
case 1: |
case 1: |
1902 |
if (!ccs_read_domain_keeper_policy(head)) |
if (!ccs_read_domain_keeper_policy(head)) |
|
break; |
|
|
head->read_var2 = NULL; |
|
|
head->read_step = 2; |
|
|
case 2: |
|
|
if (!ccs_read_globally_readable_policy(head)) |
|
|
break; |
|
|
head->read_var2 = NULL; |
|
|
head->read_step = 3; |
|
|
case 3: |
|
|
if (!ccs_read_globally_usable_env_policy(head)) |
|
|
break; |
|
|
head->read_var2 = NULL; |
|
|
head->read_step = 4; |
|
|
case 4: |
|
|
if (!ccs_read_domain_initializer_policy(head)) |
|
|
break; |
|
|
head->read_var2 = NULL; |
|
|
head->read_step = 6; |
|
|
case 6: |
|
|
if (!ccs_read_aggregator_policy(head)) |
|
|
break; |
|
|
head->read_var2 = NULL; |
|
|
head->read_step = 7; |
|
|
case 7: |
|
|
if (!ccs_read_file_pattern(head)) |
|
|
break; |
|
|
head->read_var2 = NULL; |
|
|
head->read_step = 8; |
|
|
case 8: |
|
|
if (!ccs_read_no_rewrite_policy(head)) |
|
|
break; |
|
|
head->read_var2 = NULL; |
|
|
head->read_step = 9; |
|
|
case 9: |
|
|
if (!ccs_read_path_group_policy(head)) |
|
|
break; |
|
|
head->read_var1 = NULL; |
|
|
head->read_var2 = NULL; |
|
|
head->read_step = 10; |
|
|
case 10: |
|
|
if (!ccs_read_number_group_policy(head)) |
|
|
break; |
|
|
head->read_var1 = NULL; |
|
|
head->read_var2 = NULL; |
|
|
head->read_step = 11; |
|
|
case 11: |
|
|
if (!ccs_read_address_group_policy(head)) |
|
|
break; |
|
|
head->read_var2 = NULL; |
|
|
head->read_step = 12; |
|
|
case 12: |
|
|
if (!ccs_read_reserved_port_policy(head)) |
|
|
break; |
|
|
head->read_eof = true; |
|
1903 |
break; |
break; |
1904 |
default: |
head->read_var2 = NULL; |
1905 |
return -EINVAL; |
head->read_step = 2; |
1906 |
} |
case 2: |
1907 |
|
if (!ccs_read_globally_readable_policy(head)) |
1908 |
|
break; |
1909 |
|
head->read_var2 = NULL; |
1910 |
|
head->read_step = 3; |
1911 |
|
case 3: |
1912 |
|
if (!ccs_read_globally_usable_env_policy(head)) |
1913 |
|
break; |
1914 |
|
head->read_var2 = NULL; |
1915 |
|
head->read_step = 4; |
1916 |
|
case 4: |
1917 |
|
if (!ccs_read_domain_initializer_policy(head)) |
1918 |
|
break; |
1919 |
|
head->read_var2 = NULL; |
1920 |
|
head->read_step = 6; |
1921 |
|
case 6: |
1922 |
|
if (!ccs_read_aggregator_policy(head)) |
1923 |
|
break; |
1924 |
|
head->read_var2 = NULL; |
1925 |
|
head->read_step = 7; |
1926 |
|
case 7: |
1927 |
|
if (!ccs_read_file_pattern(head)) |
1928 |
|
break; |
1929 |
|
head->read_var2 = NULL; |
1930 |
|
head->read_step = 8; |
1931 |
|
case 8: |
1932 |
|
if (!ccs_read_no_rewrite_policy(head)) |
1933 |
|
break; |
1934 |
|
head->read_var2 = NULL; |
1935 |
|
head->read_step = 9; |
1936 |
|
case 9: |
1937 |
|
if (!ccs_read_path_group_policy(head)) |
1938 |
|
break; |
1939 |
|
head->read_var1 = NULL; |
1940 |
|
head->read_var2 = NULL; |
1941 |
|
head->read_step = 10; |
1942 |
|
case 10: |
1943 |
|
if (!ccs_read_number_group_policy(head)) |
1944 |
|
break; |
1945 |
|
head->read_var1 = NULL; |
1946 |
|
head->read_var2 = NULL; |
1947 |
|
head->read_step = 11; |
1948 |
|
case 11: |
1949 |
|
if (!ccs_read_address_group_policy(head)) |
1950 |
|
break; |
1951 |
|
head->read_var2 = NULL; |
1952 |
|
head->read_step = 12; |
1953 |
|
case 12: |
1954 |
|
if (!ccs_read_reserved_port_policy(head)) |
1955 |
|
break; |
1956 |
|
head->read_eof = true; |
1957 |
} |
} |
|
return 0; |
|
1958 |
} |
} |
1959 |
|
|
1960 |
/** |
/** |
1982 |
while (offset < PAGE_SIZE) { |
while (offset < PAGE_SIZE) { |
1983 |
const char *kaddr = ee->dump.data; |
const char *kaddr = ee->dump.data; |
1984 |
const unsigned char c = kaddr[offset++]; |
const unsigned char c = kaddr[offset++]; |
1985 |
if (c && arg_len < CCS_MAX_PATHNAME_LEN - 10) { |
if (c && arg_len < CCS_EXEC_TMPSIZE - 10) { |
1986 |
if (c == '\\') { |
if (c == '\\') { |
1987 |
arg_ptr[arg_len++] = '\\'; |
arg_ptr[arg_len++] = '\\'; |
1988 |
arg_ptr[arg_len++] = '\\'; |
arg_ptr[arg_len++] = '\\'; |
|
} else if (c == '/') { |
|
|
arg_len = 0; |
|
1989 |
} else if (c > ' ' && c < 127) { |
} else if (c > ' ' && c < 127) { |
1990 |
arg_ptr[arg_len++] = c; |
arg_ptr[arg_len++] = c; |
1991 |
} else { |
} else { |
2010 |
return false; |
return false; |
2011 |
} |
} |
2012 |
|
|
2013 |
|
/** |
2014 |
|
* ccs_get_execute_condition - Get condition part for execute requests. |
2015 |
|
* |
2016 |
|
* @ee: Pointer to "struct ccs_execve_entry". |
2017 |
|
* |
2018 |
|
* Returns pointer to "struct ccs_condition" on success, NULL otherwise. |
2019 |
|
*/ |
2020 |
static struct ccs_condition *ccs_get_execute_condition(struct ccs_execve_entry |
static struct ccs_condition *ccs_get_execute_condition(struct ccs_execve_entry |
2021 |
*ee) |
*ee) |
2022 |
{ |
{ |
2025 |
int len = 256; |
int len = 256; |
2026 |
char *realpath = NULL; |
char *realpath = NULL; |
2027 |
char *argv0 = NULL; |
char *argv0 = NULL; |
2028 |
if (ccs_flags(NULL, CCS_AUTOLEARN_EXEC_REALPATH)) { |
const struct ccs_profile *profile = ccs_profile(ee->r.domain->profile); |
2029 |
|
if (profile->learning->learning_exec_realpath) { |
2030 |
struct file *file = ee->bprm->file; |
struct file *file = ee->bprm->file; |
2031 |
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 20) |
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 20) |
2032 |
struct path path = { file->f_vfsmnt, file->f_dentry }; |
struct path path = { file->f_vfsmnt, file->f_dentry }; |
2037 |
if (realpath) |
if (realpath) |
2038 |
len += strlen(realpath) + 17; |
len += strlen(realpath) + 17; |
2039 |
} |
} |
2040 |
if (ccs_flags(NULL, CCS_AUTOLEARN_EXEC_REALPATH)) { |
if (profile->learning->learning_exec_argv0) { |
2041 |
if (ccs_get_argv0(ee)) { |
if (ccs_get_argv0(ee)) { |
2042 |
argv0 = ee->tmp; |
argv0 = ee->tmp; |
2043 |
len += strlen(argv0) + 16; |
len += strlen(argv0) + 16; |
2044 |
} |
} |
2045 |
} |
} |
2046 |
buf = kmalloc(len, GFP_KERNEL); |
buf = kmalloc(len, GFP_KERNEL); |
2047 |
if (!buf) |
if (!buf) { |
2048 |
|
kfree(realpath); |
2049 |
return NULL; |
return NULL; |
2050 |
|
} |
2051 |
snprintf(buf, len - 1, "if"); |
snprintf(buf, len - 1, "if"); |
2052 |
if (current->ccs_flags & CCS_TASK_IS_EXECUTE_HANDLER) { |
if (current->ccs_flags & CCS_TASK_IS_EXECUTE_HANDLER) { |
2053 |
const int pos = strlen(buf); |
const int pos = strlen(buf); |
2070 |
return cond; |
return cond; |
2071 |
} |
} |
2072 |
|
|
2073 |
|
/** |
2074 |
|
* ccs_get_symlink_condition - Get condition part for symlink requests. |
2075 |
|
* |
2076 |
|
* @r: Pointer to "struct ccs_request_info". |
2077 |
|
* |
2078 |
|
* Returns pointer to "struct ccs_condition" on success, NULL otherwise. |
2079 |
|
*/ |
2080 |
|
static struct ccs_condition *ccs_get_symlink_condition(struct ccs_request_info |
2081 |
|
*r) |
2082 |
|
{ |
2083 |
|
struct ccs_condition *cond; |
2084 |
|
char *buf; |
2085 |
|
int len = 256; |
2086 |
|
const char *symlink = NULL; |
2087 |
|
const struct ccs_profile *profile = ccs_profile(r->profile); |
2088 |
|
if (profile->learning->learning_symlink_target) { |
2089 |
|
symlink = r->obj->symlink_target->name; |
2090 |
|
len += strlen(symlink) + 18; |
2091 |
|
} |
2092 |
|
buf = kmalloc(len, GFP_KERNEL); |
2093 |
|
if (!buf) |
2094 |
|
return NULL; |
2095 |
|
snprintf(buf, len - 1, "if"); |
2096 |
|
if (current->ccs_flags & CCS_TASK_IS_EXECUTE_HANDLER) { |
2097 |
|
const int pos = strlen(buf); |
2098 |
|
snprintf(buf + pos, len - pos - 1, |
2099 |
|
" task.type=execute_handler"); |
2100 |
|
} |
2101 |
|
if (symlink) { |
2102 |
|
const int pos = strlen(buf); |
2103 |
|
snprintf(buf + pos, len - pos - 1, " symlink.target=\"%s\"", |
2104 |
|
symlink); |
2105 |
|
} |
2106 |
|
cond = ccs_get_condition(buf); |
2107 |
|
kfree(buf); |
2108 |
|
return cond; |
2109 |
|
} |
2110 |
|
|
2111 |
/* Wait queue for ccs_query_list. */ |
/* Wait queue for ccs_query_list. */ |
2112 |
static DECLARE_WAIT_QUEUE_HEAD(ccs_query_wait); |
static DECLARE_WAIT_QUEUE_HEAD(ccs_query_wait); |
2113 |
|
|
2156 |
switch (r->mode) { |
switch (r->mode) { |
2157 |
char *buffer; |
char *buffer; |
2158 |
struct ccs_condition *cond; |
struct ccs_condition *cond; |
2159 |
case 1: |
case CCS_CONFIG_LEARNING: |
2160 |
if (!ccs_domain_quota_ok(r)) |
if (!ccs_domain_quota_ok(r)) |
2161 |
return 0; |
return 0; |
2162 |
va_start(args, fmt); |
va_start(args, fmt); |
2171 |
ccs_normalize_line(buffer); |
ccs_normalize_line(buffer); |
2172 |
if (r->ee && !strncmp(buffer, "allow_execute ", 14)) |
if (r->ee && !strncmp(buffer, "allow_execute ", 14)) |
2173 |
cond = ccs_get_execute_condition(r->ee); |
cond = ccs_get_execute_condition(r->ee); |
2174 |
|
else if (r->obj && r->obj->symlink_target) |
2175 |
|
cond = ccs_get_symlink_condition(r); |
2176 |
else if ((current->ccs_flags & CCS_TASK_IS_EXECUTE_HANDLER)) { |
else if ((current->ccs_flags & CCS_TASK_IS_EXECUTE_HANDLER)) { |
2177 |
char str[] = "if task.type=execute_handler"; |
char str[] = "if task.type=execute_handler"; |
2178 |
cond = ccs_get_condition(str); |
cond = ccs_get_condition(str); |
2182 |
ccs_put_condition(cond); |
ccs_put_condition(cond); |
2183 |
kfree(buffer); |
kfree(buffer); |
2184 |
/* fall through */ |
/* fall through */ |
2185 |
case 2: |
case CCS_CONFIG_PERMISSIVE: |
2186 |
return 0; |
return 0; |
2187 |
} |
} |
2188 |
if (!atomic_read(&ccs_query_observers)) { |
if (!atomic_read(&ccs_query_observers)) { |
2189 |
int i; |
int i; |
2190 |
if (current->ccs_flags & CCS_DONT_SLEEP_ON_ENFORCE_ERROR) |
if (current->ccs_flags & CCS_DONT_SLEEP_ON_ENFORCE_ERROR) |
2191 |
return -EPERM; |
return -EPERM; |
2192 |
for (i = 0; i < ccs_flags(r->domain, CCS_SLEEP_PERIOD); |
for (i = 0; i < ccs_profile(r->domain->profile)->enforcing-> |
2193 |
i++) { |
enforcing_penalty; i++) { |
2194 |
set_current_state(TASK_INTERRUPTIBLE); |
set_current_state(TASK_INTERRUPTIBLE); |
2195 |
schedule_timeout(HZ / 10); |
schedule_timeout(HZ / 10); |
2196 |
} |
} |
2309 |
* ccs_read_query - Read access requests which violated policy in enforcing mode. |
* ccs_read_query - Read access requests which violated policy in enforcing mode. |
2310 |
* |
* |
2311 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
|
* |
|
|
* Returns 0. |
|
2312 |
*/ |
*/ |
2313 |
static int ccs_read_query(struct ccs_io_buffer *head) |
static void ccs_read_query(struct ccs_io_buffer *head) |
2314 |
{ |
{ |
2315 |
struct list_head *tmp; |
struct list_head *tmp; |
2316 |
int pos = 0; |
int pos = 0; |
2317 |
int len = 0; |
int len = 0; |
2318 |
char *buf; |
char *buf; |
2319 |
if (head->read_avail) |
if (head->read_avail) |
2320 |
return 0; |
return; |
2321 |
if (head->read_buf) { |
if (head->read_buf) { |
2322 |
kfree(head->read_buf); |
kfree(head->read_buf); |
2323 |
head->read_buf = NULL; |
head->read_buf = NULL; |
2337 |
spin_unlock(&ccs_query_list_lock); |
spin_unlock(&ccs_query_list_lock); |
2338 |
if (!len) { |
if (!len) { |
2339 |
head->read_step = 0; |
head->read_step = 0; |
2340 |
return 0; |
return; |
2341 |
} |
} |
2342 |
buf = kzalloc(len, GFP_KERNEL); |
buf = kzalloc(len, GFP_KERNEL); |
2343 |
if (!buf) |
if (!buf) |
2344 |
return 0; |
return; |
2345 |
pos = 0; |
pos = 0; |
2346 |
spin_lock(&ccs_query_list_lock); |
spin_lock(&ccs_query_list_lock); |
2347 |
list_for_each(tmp, &ccs_query_list) { |
list_for_each(tmp, &ccs_query_list) { |
2368 |
} else { |
} else { |
2369 |
kfree(buf); |
kfree(buf); |
2370 |
} |
} |
|
return 0; |
|
2371 |
} |
} |
2372 |
|
|
2373 |
/** |
/** |
2410 |
* ccs_read_version: Get version. |
* ccs_read_version: Get version. |
2411 |
* |
* |
2412 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
|
* |
|
|
* Returns version information. |
|
2413 |
*/ |
*/ |
2414 |
static int ccs_read_version(struct ccs_io_buffer *head) |
static void ccs_read_version(struct ccs_io_buffer *head) |
2415 |
{ |
{ |
2416 |
if (!head->read_eof) { |
if (head->read_eof) |
2417 |
ccs_io_printf(head, "1.7.0-pre"); |
return; |
2418 |
head->read_eof = true; |
ccs_io_printf(head, "1.7.0"); |
2419 |
} |
head->read_eof = true; |
|
return 0; |
|
2420 |
} |
} |
2421 |
|
|
2422 |
/** |
/** |
2423 |
* ccs_read_self_domain - Get the current process's domainname. |
* ccs_read_self_domain - Get the current process's domainname. |
2424 |
* |
* |
2425 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
|
* |
|
|
* Returns the current process's domainname. |
|
2426 |
*/ |
*/ |
2427 |
static int ccs_read_self_domain(struct ccs_io_buffer *head) |
static void ccs_read_self_domain(struct ccs_io_buffer *head) |
2428 |
{ |
{ |
2429 |
if (!head->read_eof) { |
if (head->read_eof) |
2430 |
/* |
return; |
2431 |
* ccs_current_domain()->domainname != NULL |
/* |
2432 |
* because every process belongs to a domain and |
* ccs_current_domain()->domainname != NULL because every process |
2433 |
* the domain's name cannot be NULL. |
* belongs to a domain and the domain's name cannot be NULL. |
2434 |
*/ |
*/ |
2435 |
ccs_io_printf(head, "%s", |
ccs_io_printf(head, "%s", ccs_current_domain()->domainname->name); |
2436 |
ccs_current_domain()->domainname->name); |
head->read_eof = true; |
|
head->read_eof = true; |
|
|
} |
|
|
return 0; |
|
2437 |
} |
} |
2438 |
|
|
2439 |
/** |
/** |
2571 |
* @wait: Pointer to "poll_table". |
* @wait: Pointer to "poll_table". |
2572 |
* |
* |
2573 |
* Waits for read readiness. |
* Waits for read readiness. |
2574 |
* /proc/ccs/query is handled by /usr/lib/ccs/ccs-queryd and |
* /proc/ccs/query is handled by /usr/sbin/ccs-queryd and |
2575 |
* /proc/ccs/grant_log and /proc/ccs/reject_log are handled by |
* /proc/ccs/grant_log and /proc/ccs/reject_log are handled by |
2576 |
* /usr/lib/ccs/ccs-auditd. |
* /usr/sbin/ccs-auditd . |
2577 |
*/ |
*/ |
2578 |
int ccs_poll_control(struct file *file, poll_table *wait) |
int ccs_poll_control(struct file *file, poll_table *wait) |
2579 |
{ |
{ |
2604 |
return -EFAULT; |
return -EFAULT; |
2605 |
if (mutex_lock_interruptible(&head->io_sem)) |
if (mutex_lock_interruptible(&head->io_sem)) |
2606 |
return -EINTR; |
return -EINTR; |
2607 |
retry: |
while (1) { |
2608 |
/* Call the policy handler. */ |
/* Call the policy handler. */ |
2609 |
len = head->read(head); |
head->read(head); |
2610 |
if (len < 0) |
/* Write to buffer. */ |
2611 |
goto out; |
len = head->read_avail; |
2612 |
/* Write to buffer. */ |
if (len || head->poll || head->read_eof) |
2613 |
len = head->read_avail; |
break; |
2614 |
if (!len && !head->poll && !head->read_eof) { |
len = head->readbuf_size * 2; |
|
const int len = head->readbuf_size * 2; |
|
2615 |
cp = kzalloc(len, GFP_KERNEL); |
cp = kzalloc(len, GFP_KERNEL); |
2616 |
if (cp) { |
if (!cp) { |
2617 |
kfree(head->read_buf); |
len = -ENOMEM; |
2618 |
head->read_buf = cp; |
goto out; |
|
head->readbuf_size = len; |
|
|
goto retry; |
|
2619 |
} |
} |
2620 |
|
kfree(head->read_buf); |
2621 |
|
head->read_buf = cp; |
2622 |
|
head->readbuf_size = len; |
2623 |
} |
} |
2624 |
if (len > buffer_len) |
if (len > buffer_len) |
2625 |
len = buffer_len; |
len = buffer_len; |