1 |
/* |
/* |
2 |
* security/ccsecurity/policy_io.c |
* security/ccsecurity/policy_io.c |
3 |
* |
* |
4 |
* Copyright (C) 2005-2010 NTT DATA CORPORATION |
* Copyright (C) 2005-2011 NTT DATA CORPORATION |
|
* |
|
|
* Version: 1.7.2-pre 2010/03/08 |
|
|
* |
|
|
* This file is applicable to both 2.4.30 and 2.6.11 and later. |
|
|
* See README.ccs for ChangeLog. |
|
5 |
* |
* |
6 |
|
* Version: 1.8.2+ 2011/07/07 |
7 |
*/ |
*/ |
8 |
|
|
9 |
#include "internal.h" |
#include "internal.h" |
10 |
|
|
11 |
static struct ccs_profile ccs_default_profile = { |
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 0) |
12 |
.learning = &ccs_default_profile.preference, |
|
13 |
.permissive = &ccs_default_profile.preference, |
/** |
14 |
.enforcing = &ccs_default_profile.preference, |
* __wait_event_interruptible_timeout - Sleep until a condition gets true or a timeout elapses. |
15 |
.audit = &ccs_default_profile.preference, |
* |
16 |
#ifdef CONFIG_CCSECURITY_AUDIT |
* @wq: The waitqueue to wait on. |
17 |
.preference.audit_max_grant_log = CONFIG_CCSECURITY_MAX_GRANT_LOG, |
* @condition: A C expression for the event to wait for. |
18 |
.preference.audit_max_reject_log = CONFIG_CCSECURITY_MAX_REJECT_LOG, |
* @ret: Timeout, in jiffies. |
19 |
|
* |
20 |
|
* Returns 0 if the @timeout elapsed, -ERESTARTSYS if it was interrupted by a |
21 |
|
* signal, and the remaining jiffies otherwise if the condition evaluated to |
22 |
|
* true before the timeout elapsed. |
23 |
|
* |
24 |
|
* This is for compatibility with older kernels. |
25 |
|
*/ |
26 |
|
#define __wait_event_interruptible_timeout(wq, condition, ret) \ |
27 |
|
do { \ |
28 |
|
wait_queue_t __wait; \ |
29 |
|
init_waitqueue_entry(&__wait, current); \ |
30 |
|
\ |
31 |
|
add_wait_queue(&wq, &__wait); \ |
32 |
|
for (;;) { \ |
33 |
|
set_current_state(TASK_INTERRUPTIBLE); \ |
34 |
|
if (condition) \ |
35 |
|
break; \ |
36 |
|
if (!signal_pending(current)) { \ |
37 |
|
ret = schedule_timeout(ret); \ |
38 |
|
if (!ret) \ |
39 |
|
break; \ |
40 |
|
continue; \ |
41 |
|
} \ |
42 |
|
ret = -ERESTARTSYS; \ |
43 |
|
break; \ |
44 |
|
} \ |
45 |
|
current->state = TASK_RUNNING; \ |
46 |
|
remove_wait_queue(&wq, &__wait); \ |
47 |
|
} while (0) |
48 |
|
|
49 |
|
/** |
50 |
|
* wait_event_interruptible_timeout - Sleep until a condition gets true or a timeout elapses. |
51 |
|
* |
52 |
|
* @wq: The waitqueue to wait on. |
53 |
|
* @condition: A C expression for the event to wait for. |
54 |
|
* @timeout: Timeout, in jiffies. |
55 |
|
* |
56 |
|
* Returns 0 if the @timeout elapsed, -ERESTARTSYS if it was interrupted by a |
57 |
|
* signal, and the remaining jiffies otherwise if the condition evaluated to |
58 |
|
* true before the timeout elapsed. |
59 |
|
* |
60 |
|
* This is for compatibility with older kernels. |
61 |
|
*/ |
62 |
|
#define wait_event_interruptible_timeout(wq, condition, timeout) \ |
63 |
|
({ \ |
64 |
|
long __ret = timeout; \ |
65 |
|
if (!(condition)) \ |
66 |
|
__wait_event_interruptible_timeout(wq, condition, __ret); \ |
67 |
|
__ret; \ |
68 |
|
}) |
69 |
|
|
70 |
#endif |
#endif |
71 |
.preference.audit_task_info = true, |
|
72 |
.preference.audit_path_info = true, |
/** |
73 |
.preference.enforcing_penalty = 0, |
* list_for_each_cookie - iterate over a list with cookie. |
74 |
.preference.enforcing_verbose = true, |
* |
75 |
.preference.learning_max_entry = CONFIG_CCSECURITY_MAX_ACCEPT_ENTRY, |
* @pos: Pointer to "struct list_head". |
76 |
.preference.learning_verbose = false, |
* @head: Pointer to "struct list_head". |
77 |
.preference.learning_exec_realpath = true, |
*/ |
78 |
.preference.learning_exec_argv0 = true, |
#define list_for_each_cookie(pos, head) \ |
79 |
.preference.learning_symlink_target = true, |
for (pos = pos ? pos : srcu_dereference((head)->next, &ccs_ss); \ |
80 |
.preference.permissive_verbose = true |
pos != (head); pos = srcu_dereference(pos->next, &ccs_ss)) |
81 |
|
|
82 |
|
/* String table for operation mode. */ |
83 |
|
const char * const ccs_mode[CCS_CONFIG_MAX_MODE] = { |
84 |
|
[CCS_CONFIG_DISABLED] = "disabled", |
85 |
|
[CCS_CONFIG_LEARNING] = "learning", |
86 |
|
[CCS_CONFIG_PERMISSIVE] = "permissive", |
87 |
|
[CCS_CONFIG_ENFORCING] = "enforcing" |
88 |
|
}; |
89 |
|
|
90 |
|
/* String table for /proc/ccs/profile interface. */ |
91 |
|
const char * const ccs_mac_keywords[CCS_MAX_MAC_INDEX |
92 |
|
+ CCS_MAX_MAC_CATEGORY_INDEX] = { |
93 |
|
/* CONFIG::file group */ |
94 |
|
[CCS_MAC_FILE_EXECUTE] = "execute", |
95 |
|
[CCS_MAC_FILE_OPEN] = "open", |
96 |
|
[CCS_MAC_FILE_CREATE] = "create", |
97 |
|
[CCS_MAC_FILE_UNLINK] = "unlink", |
98 |
|
[CCS_MAC_FILE_GETATTR] = "getattr", |
99 |
|
[CCS_MAC_FILE_MKDIR] = "mkdir", |
100 |
|
[CCS_MAC_FILE_RMDIR] = "rmdir", |
101 |
|
[CCS_MAC_FILE_MKFIFO] = "mkfifo", |
102 |
|
[CCS_MAC_FILE_MKSOCK] = "mksock", |
103 |
|
[CCS_MAC_FILE_TRUNCATE] = "truncate", |
104 |
|
[CCS_MAC_FILE_SYMLINK] = "symlink", |
105 |
|
[CCS_MAC_FILE_MKBLOCK] = "mkblock", |
106 |
|
[CCS_MAC_FILE_MKCHAR] = "mkchar", |
107 |
|
[CCS_MAC_FILE_LINK] = "link", |
108 |
|
[CCS_MAC_FILE_RENAME] = "rename", |
109 |
|
[CCS_MAC_FILE_CHMOD] = "chmod", |
110 |
|
[CCS_MAC_FILE_CHOWN] = "chown", |
111 |
|
[CCS_MAC_FILE_CHGRP] = "chgrp", |
112 |
|
[CCS_MAC_FILE_IOCTL] = "ioctl", |
113 |
|
[CCS_MAC_FILE_CHROOT] = "chroot", |
114 |
|
[CCS_MAC_FILE_MOUNT] = "mount", |
115 |
|
[CCS_MAC_FILE_UMOUNT] = "unmount", |
116 |
|
[CCS_MAC_FILE_PIVOT_ROOT] = "pivot_root", |
117 |
|
/* CONFIG::misc group */ |
118 |
|
[CCS_MAC_ENVIRON] = "env", |
119 |
|
/* CONFIG::network group */ |
120 |
|
[CCS_MAC_NETWORK_INET_STREAM_BIND] = "inet_stream_bind", |
121 |
|
[CCS_MAC_NETWORK_INET_STREAM_LISTEN] = "inet_stream_listen", |
122 |
|
[CCS_MAC_NETWORK_INET_STREAM_CONNECT] = "inet_stream_connect", |
123 |
|
[CCS_MAC_NETWORK_INET_STREAM_ACCEPT] = "inet_stream_accept", |
124 |
|
[CCS_MAC_NETWORK_INET_DGRAM_BIND] = "inet_dgram_bind", |
125 |
|
[CCS_MAC_NETWORK_INET_DGRAM_SEND] = "inet_dgram_send", |
126 |
|
[CCS_MAC_NETWORK_INET_DGRAM_RECV] = "inet_dgram_recv", |
127 |
|
[CCS_MAC_NETWORK_INET_RAW_BIND] = "inet_raw_bind", |
128 |
|
[CCS_MAC_NETWORK_INET_RAW_SEND] = "inet_raw_send", |
129 |
|
[CCS_MAC_NETWORK_INET_RAW_RECV] = "inet_raw_recv", |
130 |
|
[CCS_MAC_NETWORK_UNIX_STREAM_BIND] = "unix_stream_bind", |
131 |
|
[CCS_MAC_NETWORK_UNIX_STREAM_LISTEN] = "unix_stream_listen", |
132 |
|
[CCS_MAC_NETWORK_UNIX_STREAM_CONNECT] = "unix_stream_connect", |
133 |
|
[CCS_MAC_NETWORK_UNIX_STREAM_ACCEPT] = "unix_stream_accept", |
134 |
|
[CCS_MAC_NETWORK_UNIX_DGRAM_BIND] = "unix_dgram_bind", |
135 |
|
[CCS_MAC_NETWORK_UNIX_DGRAM_SEND] = "unix_dgram_send", |
136 |
|
[CCS_MAC_NETWORK_UNIX_DGRAM_RECV] = "unix_dgram_recv", |
137 |
|
[CCS_MAC_NETWORK_UNIX_SEQPACKET_BIND] = "unix_seqpacket_bind", |
138 |
|
[CCS_MAC_NETWORK_UNIX_SEQPACKET_LISTEN] = "unix_seqpacket_listen", |
139 |
|
[CCS_MAC_NETWORK_UNIX_SEQPACKET_CONNECT] = "unix_seqpacket_connect", |
140 |
|
[CCS_MAC_NETWORK_UNIX_SEQPACKET_ACCEPT] = "unix_seqpacket_accept", |
141 |
|
/* CONFIG::ipc group */ |
142 |
|
[CCS_MAC_SIGNAL] = "signal", |
143 |
|
/* CONFIG::capability group */ |
144 |
|
[CCS_MAC_CAPABILITY_USE_ROUTE_SOCKET] = "use_route", |
145 |
|
[CCS_MAC_CAPABILITY_USE_PACKET_SOCKET] = "use_packet", |
146 |
|
[CCS_MAC_CAPABILITY_SYS_REBOOT] = "SYS_REBOOT", |
147 |
|
[CCS_MAC_CAPABILITY_SYS_VHANGUP] = "SYS_VHANGUP", |
148 |
|
[CCS_MAC_CAPABILITY_SYS_SETTIME] = "SYS_TIME", |
149 |
|
[CCS_MAC_CAPABILITY_SYS_NICE] = "SYS_NICE", |
150 |
|
[CCS_MAC_CAPABILITY_SYS_SETHOSTNAME] = "SYS_SETHOSTNAME", |
151 |
|
[CCS_MAC_CAPABILITY_USE_KERNEL_MODULE] = "use_kernel_module", |
152 |
|
[CCS_MAC_CAPABILITY_SYS_KEXEC_LOAD] = "SYS_KEXEC_LOAD", |
153 |
|
[CCS_MAC_CAPABILITY_SYS_PTRACE] = "SYS_PTRACE", |
154 |
|
/* CONFIG group */ |
155 |
|
[CCS_MAX_MAC_INDEX + CCS_MAC_CATEGORY_FILE] = "file", |
156 |
|
[CCS_MAX_MAC_INDEX + CCS_MAC_CATEGORY_NETWORK] = "network", |
157 |
|
[CCS_MAX_MAC_INDEX + CCS_MAC_CATEGORY_MISC] = "misc", |
158 |
|
[CCS_MAX_MAC_INDEX + CCS_MAC_CATEGORY_IPC] = "ipc", |
159 |
|
[CCS_MAX_MAC_INDEX + CCS_MAC_CATEGORY_CAPABILITY] = "capability", |
160 |
}; |
}; |
161 |
|
|
162 |
/* Profile version. Currently only 20090903 is defined. */ |
/* String table for path operation. */ |
163 |
static unsigned int ccs_profile_version; |
const char * const ccs_path_keyword[CCS_MAX_PATH_OPERATION] = { |
164 |
|
[CCS_TYPE_EXECUTE] = "execute", |
165 |
|
[CCS_TYPE_READ] = "read", |
166 |
|
[CCS_TYPE_WRITE] = "write", |
167 |
|
[CCS_TYPE_APPEND] = "append", |
168 |
|
[CCS_TYPE_UNLINK] = "unlink", |
169 |
|
[CCS_TYPE_GETATTR] = "getattr", |
170 |
|
[CCS_TYPE_RMDIR] = "rmdir", |
171 |
|
[CCS_TYPE_TRUNCATE] = "truncate", |
172 |
|
[CCS_TYPE_SYMLINK] = "symlink", |
173 |
|
[CCS_TYPE_CHROOT] = "chroot", |
174 |
|
[CCS_TYPE_UMOUNT] = "unmount", |
175 |
|
}; |
176 |
|
|
177 |
|
/* String table for socket's operation. */ |
178 |
|
const char * const ccs_socket_keyword[CCS_MAX_NETWORK_OPERATION] = { |
179 |
|
[CCS_NETWORK_BIND] = "bind", |
180 |
|
[CCS_NETWORK_LISTEN] = "listen", |
181 |
|
[CCS_NETWORK_CONNECT] = "connect", |
182 |
|
[CCS_NETWORK_ACCEPT] = "accept", |
183 |
|
[CCS_NETWORK_SEND] = "send", |
184 |
|
[CCS_NETWORK_RECV] = "recv", |
185 |
|
}; |
186 |
|
|
187 |
/* Profile table. Memory is allocated as needed. */ |
/* String table for categories. */ |
188 |
static struct ccs_profile *ccs_profile_ptr[CCS_MAX_PROFILES]; |
static const char * const ccs_category_keywords[CCS_MAX_MAC_CATEGORY_INDEX] = { |
189 |
|
[CCS_MAC_CATEGORY_FILE] = "file", |
190 |
|
[CCS_MAC_CATEGORY_NETWORK] = "network", |
191 |
|
[CCS_MAC_CATEGORY_MISC] = "misc", |
192 |
|
[CCS_MAC_CATEGORY_IPC] = "ipc", |
193 |
|
[CCS_MAC_CATEGORY_CAPABILITY] = "capability", |
194 |
|
}; |
195 |
|
|
196 |
/* String table for functionality that takes 4 modes. */ |
/* String table for conditions. */ |
197 |
static const char *ccs_mode_4[4] = { |
const char * const ccs_condition_keyword[CCS_MAX_CONDITION_KEYWORD] = { |
198 |
"disabled", "learning", "permissive", "enforcing" |
[CCS_TASK_UID] = "task.uid", |
199 |
|
[CCS_TASK_EUID] = "task.euid", |
200 |
|
[CCS_TASK_SUID] = "task.suid", |
201 |
|
[CCS_TASK_FSUID] = "task.fsuid", |
202 |
|
[CCS_TASK_GID] = "task.gid", |
203 |
|
[CCS_TASK_EGID] = "task.egid", |
204 |
|
[CCS_TASK_SGID] = "task.sgid", |
205 |
|
[CCS_TASK_FSGID] = "task.fsgid", |
206 |
|
[CCS_TASK_PID] = "task.pid", |
207 |
|
[CCS_TASK_PPID] = "task.ppid", |
208 |
|
[CCS_EXEC_ARGC] = "exec.argc", |
209 |
|
[CCS_EXEC_ENVC] = "exec.envc", |
210 |
|
[CCS_TYPE_IS_SOCKET] = "socket", |
211 |
|
[CCS_TYPE_IS_SYMLINK] = "symlink", |
212 |
|
[CCS_TYPE_IS_FILE] = "file", |
213 |
|
[CCS_TYPE_IS_BLOCK_DEV] = "block", |
214 |
|
[CCS_TYPE_IS_DIRECTORY] = "directory", |
215 |
|
[CCS_TYPE_IS_CHAR_DEV] = "char", |
216 |
|
[CCS_TYPE_IS_FIFO] = "fifo", |
217 |
|
[CCS_MODE_SETUID] = "setuid", |
218 |
|
[CCS_MODE_SETGID] = "setgid", |
219 |
|
[CCS_MODE_STICKY] = "sticky", |
220 |
|
[CCS_MODE_OWNER_READ] = "owner_read", |
221 |
|
[CCS_MODE_OWNER_WRITE] = "owner_write", |
222 |
|
[CCS_MODE_OWNER_EXECUTE] = "owner_execute", |
223 |
|
[CCS_MODE_GROUP_READ] = "group_read", |
224 |
|
[CCS_MODE_GROUP_WRITE] = "group_write", |
225 |
|
[CCS_MODE_GROUP_EXECUTE] = "group_execute", |
226 |
|
[CCS_MODE_OTHERS_READ] = "others_read", |
227 |
|
[CCS_MODE_OTHERS_WRITE] = "others_write", |
228 |
|
[CCS_MODE_OTHERS_EXECUTE] = "others_execute", |
229 |
|
[CCS_TASK_TYPE] = "task.type", |
230 |
|
[CCS_TASK_EXECUTE_HANDLER] = "execute_handler", |
231 |
|
[CCS_EXEC_REALPATH] = "exec.realpath", |
232 |
|
[CCS_SYMLINK_TARGET] = "symlink.target", |
233 |
|
[CCS_PATH1_UID] = "path1.uid", |
234 |
|
[CCS_PATH1_GID] = "path1.gid", |
235 |
|
[CCS_PATH1_INO] = "path1.ino", |
236 |
|
[CCS_PATH1_MAJOR] = "path1.major", |
237 |
|
[CCS_PATH1_MINOR] = "path1.minor", |
238 |
|
[CCS_PATH1_PERM] = "path1.perm", |
239 |
|
[CCS_PATH1_TYPE] = "path1.type", |
240 |
|
[CCS_PATH1_DEV_MAJOR] = "path1.dev_major", |
241 |
|
[CCS_PATH1_DEV_MINOR] = "path1.dev_minor", |
242 |
|
[CCS_PATH2_UID] = "path2.uid", |
243 |
|
[CCS_PATH2_GID] = "path2.gid", |
244 |
|
[CCS_PATH2_INO] = "path2.ino", |
245 |
|
[CCS_PATH2_MAJOR] = "path2.major", |
246 |
|
[CCS_PATH2_MINOR] = "path2.minor", |
247 |
|
[CCS_PATH2_PERM] = "path2.perm", |
248 |
|
[CCS_PATH2_TYPE] = "path2.type", |
249 |
|
[CCS_PATH2_DEV_MAJOR] = "path2.dev_major", |
250 |
|
[CCS_PATH2_DEV_MINOR] = "path2.dev_minor", |
251 |
|
[CCS_PATH1_PARENT_UID] = "path1.parent.uid", |
252 |
|
[CCS_PATH1_PARENT_GID] = "path1.parent.gid", |
253 |
|
[CCS_PATH1_PARENT_INO] = "path1.parent.ino", |
254 |
|
[CCS_PATH1_PARENT_PERM] = "path1.parent.perm", |
255 |
|
[CCS_PATH2_PARENT_UID] = "path2.parent.uid", |
256 |
|
[CCS_PATH2_PARENT_GID] = "path2.parent.gid", |
257 |
|
[CCS_PATH2_PARENT_INO] = "path2.parent.ino", |
258 |
|
[CCS_PATH2_PARENT_PERM] = "path2.parent.perm", |
259 |
}; |
}; |
260 |
|
|
261 |
/* String table for /proc/ccs/profile */ |
/* String table for PREFERENCE keyword. */ |
262 |
static const char *ccs_mac_keywords[CCS_MAX_MAC_INDEX + |
static const char * const ccs_pref_keywords[CCS_MAX_PREF] = { |
263 |
CCS_MAX_CAPABILITY_INDEX + |
[CCS_PREF_MAX_AUDIT_LOG] = "max_audit_log", |
264 |
CCS_MAX_MAC_CATEGORY_INDEX] = { |
[CCS_PREF_MAX_LEARNING_ENTRY] = "max_learning_entry", |
265 |
[CCS_MAC_FILE_EXECUTE] |
[CCS_PREF_ENFORCING_PENALTY] = "enforcing_penalty", |
|
= "file::execute", |
|
|
[CCS_MAC_FILE_OPEN] |
|
|
= "file::open", |
|
|
[CCS_MAC_FILE_CREATE] |
|
|
= "file::create", |
|
|
[CCS_MAC_FILE_UNLINK] |
|
|
= "file::unlink", |
|
|
[CCS_MAC_FILE_MKDIR] |
|
|
= "file::mkdir", |
|
|
[CCS_MAC_FILE_RMDIR] |
|
|
= "file::rmdir", |
|
|
[CCS_MAC_FILE_MKFIFO] |
|
|
= "file::mkfifo", |
|
|
[CCS_MAC_FILE_MKSOCK] |
|
|
= "file::mksock", |
|
|
[CCS_MAC_FILE_TRUNCATE] |
|
|
= "file::truncate", |
|
|
[CCS_MAC_FILE_SYMLINK] |
|
|
= "file::symlink", |
|
|
[CCS_MAC_FILE_REWRITE] |
|
|
= "file::rewrite", |
|
|
[CCS_MAC_FILE_MKBLOCK] |
|
|
= "file::mkblock", |
|
|
[CCS_MAC_FILE_MKCHAR] |
|
|
= "file::mkchar", |
|
|
[CCS_MAC_FILE_LINK] |
|
|
= "file::link", |
|
|
[CCS_MAC_FILE_RENAME] |
|
|
= "file::rename", |
|
|
[CCS_MAC_FILE_CHMOD] |
|
|
= "file::chmod", |
|
|
[CCS_MAC_FILE_CHOWN] |
|
|
= "file::chown", |
|
|
[CCS_MAC_FILE_CHGRP] |
|
|
= "file::chgrp", |
|
|
[CCS_MAC_FILE_IOCTL] |
|
|
= "file::ioctl", |
|
|
[CCS_MAC_FILE_CHROOT] |
|
|
= "file::chroot", |
|
|
[CCS_MAC_FILE_MOUNT] |
|
|
= "file::mount", |
|
|
[CCS_MAC_FILE_UMOUNT] |
|
|
= "file::umount", |
|
|
[CCS_MAC_FILE_PIVOT_ROOT] |
|
|
= "file::pivot_root", |
|
|
[CCS_MAC_FILE_TRANSIT] |
|
|
= "file::transit", |
|
|
[CCS_MAC_ENVIRON] |
|
|
= "misc::env", |
|
|
[CCS_MAC_NETWORK_UDP_BIND] |
|
|
= "network::inet_udp_bind", |
|
|
[CCS_MAC_NETWORK_UDP_CONNECT] |
|
|
= "network::inet_udp_connect", |
|
|
[CCS_MAC_NETWORK_TCP_BIND] |
|
|
= "network::inet_tcp_bind", |
|
|
[CCS_MAC_NETWORK_TCP_LISTEN] |
|
|
= "network::inet_tcp_listen", |
|
|
[CCS_MAC_NETWORK_TCP_CONNECT] |
|
|
= "network::inet_tcp_connect", |
|
|
[CCS_MAC_NETWORK_TCP_ACCEPT] |
|
|
= "network::inet_tcp_accept", |
|
|
[CCS_MAC_NETWORK_RAW_BIND] |
|
|
= "network::inet_raw_bind", |
|
|
[CCS_MAC_NETWORK_RAW_CONNECT] |
|
|
= "network::inet_raw_connect", |
|
|
[CCS_MAC_SIGNAL] |
|
|
= "ipc::signal", |
|
|
[CCS_MAX_MAC_INDEX + CCS_INET_STREAM_SOCKET_CREATE] |
|
|
= "capability::inet_tcp_create", |
|
|
[CCS_MAX_MAC_INDEX + CCS_INET_STREAM_SOCKET_LISTEN] |
|
|
= "capability::inet_tcp_listen", |
|
|
[CCS_MAX_MAC_INDEX + CCS_INET_STREAM_SOCKET_CONNECT] |
|
|
= "capability::inet_tcp_connect", |
|
|
[CCS_MAX_MAC_INDEX + CCS_USE_INET_DGRAM_SOCKET] |
|
|
= "capability::use_inet_udp", |
|
|
[CCS_MAX_MAC_INDEX + CCS_USE_INET_RAW_SOCKET] |
|
|
= "capability::use_inet_ip", |
|
|
[CCS_MAX_MAC_INDEX + CCS_USE_ROUTE_SOCKET] |
|
|
= "capability::use_route", |
|
|
[CCS_MAX_MAC_INDEX + CCS_USE_PACKET_SOCKET] |
|
|
= "capability::use_packet", |
|
|
[CCS_MAX_MAC_INDEX + CCS_SYS_MOUNT] |
|
|
= "capability::SYS_MOUNT", |
|
|
[CCS_MAX_MAC_INDEX + CCS_SYS_UMOUNT] |
|
|
= "capability::SYS_UMOUNT", |
|
|
[CCS_MAX_MAC_INDEX + CCS_SYS_REBOOT] |
|
|
= "capability::SYS_REBOOT", |
|
|
[CCS_MAX_MAC_INDEX + CCS_SYS_CHROOT] |
|
|
= "capability::SYS_CHROOT", |
|
|
[CCS_MAX_MAC_INDEX + CCS_SYS_KILL] |
|
|
= "capability::SYS_KILL", |
|
|
[CCS_MAX_MAC_INDEX + CCS_SYS_VHANGUP] |
|
|
= "capability::SYS_VHANGUP", |
|
|
[CCS_MAX_MAC_INDEX + CCS_SYS_SETTIME] |
|
|
= "capability::SYS_TIME", |
|
|
[CCS_MAX_MAC_INDEX + CCS_SYS_NICE] |
|
|
= "capability::SYS_NICE", |
|
|
[CCS_MAX_MAC_INDEX + CCS_SYS_SETHOSTNAME] |
|
|
= "capability::SYS_SETHOSTNAME", |
|
|
[CCS_MAX_MAC_INDEX + CCS_USE_KERNEL_MODULE] |
|
|
= "capability::use_kernel_module", |
|
|
[CCS_MAX_MAC_INDEX + CCS_CREATE_FIFO] |
|
|
= "capability::create_fifo", |
|
|
[CCS_MAX_MAC_INDEX + CCS_CREATE_BLOCK_DEV] |
|
|
= "capability::create_block_dev", |
|
|
[CCS_MAX_MAC_INDEX + CCS_CREATE_CHAR_DEV] |
|
|
= "capability::create_char_dev", |
|
|
[CCS_MAX_MAC_INDEX + CCS_CREATE_UNIX_SOCKET] |
|
|
= "capability::create_unix_socket", |
|
|
[CCS_MAX_MAC_INDEX + CCS_SYS_LINK] |
|
|
= "capability::SYS_LINK", |
|
|
[CCS_MAX_MAC_INDEX + CCS_SYS_SYMLINK] |
|
|
= "capability::SYS_SYMLINK", |
|
|
[CCS_MAX_MAC_INDEX + CCS_SYS_RENAME] |
|
|
= "capability::SYS_RENAME", |
|
|
[CCS_MAX_MAC_INDEX + CCS_SYS_UNLINK] |
|
|
= "capability::SYS_UNLINK", |
|
|
[CCS_MAX_MAC_INDEX + CCS_SYS_CHMOD] |
|
|
= "capability::SYS_CHMOD", |
|
|
[CCS_MAX_MAC_INDEX + CCS_SYS_CHOWN] |
|
|
= "capability::SYS_CHOWN", |
|
|
[CCS_MAX_MAC_INDEX + CCS_SYS_IOCTL] |
|
|
= "capability::SYS_IOCTL", |
|
|
[CCS_MAX_MAC_INDEX + CCS_SYS_KEXEC_LOAD] |
|
|
= "capability::SYS_KEXEC_LOAD", |
|
|
[CCS_MAX_MAC_INDEX + CCS_SYS_PIVOT_ROOT] |
|
|
= "capability::SYS_PIVOT_ROOT", |
|
|
[CCS_MAX_MAC_INDEX + CCS_SYS_PTRACE] |
|
|
= "capability::SYS_PTRACE", |
|
|
[CCS_MAX_MAC_INDEX + CCS_CONCEAL_MOUNT] |
|
|
= "capability::conceal_mount", |
|
|
[CCS_MAX_MAC_INDEX + CCS_MAX_CAPABILITY_INDEX |
|
|
+ CCS_MAC_CATEGORY_FILE] = "file", |
|
|
[CCS_MAX_MAC_INDEX + CCS_MAX_CAPABILITY_INDEX |
|
|
+ CCS_MAC_CATEGORY_NETWORK] = "network", |
|
|
[CCS_MAX_MAC_INDEX + CCS_MAX_CAPABILITY_INDEX |
|
|
+ CCS_MAC_CATEGORY_MISC] = "misc", |
|
|
[CCS_MAX_MAC_INDEX + CCS_MAX_CAPABILITY_INDEX |
|
|
+ CCS_MAC_CATEGORY_IPC] = "ipc", |
|
|
[CCS_MAX_MAC_INDEX + CCS_MAX_CAPABILITY_INDEX |
|
|
+ CCS_MAC_CATEGORY_CAPABILITY] = "capability", |
|
266 |
}; |
}; |
267 |
|
|
268 |
/* Permit policy management by non-root user? */ |
/* Permit policy management by non-root user? */ |
269 |
static bool ccs_manage_by_non_root; |
static bool ccs_manage_by_non_root; |
270 |
|
|
271 |
/** |
/** |
272 |
* ccs_cap2keyword - Convert capability operation to capability name. |
* ccs_yesno - Return "yes" or "no". |
273 |
* |
* |
274 |
* @operation: The capability index. |
* @value: Bool value. |
275 |
* |
* |
276 |
* Returns the name of the specified capability's name. |
* Returns "yes" if @value is not 0, "no" otherwise. |
277 |
*/ |
*/ |
278 |
const char *ccs_cap2keyword(const u8 operation) |
const char *ccs_yesno(const unsigned int value) |
279 |
{ |
{ |
280 |
return operation < CCS_MAX_CAPABILITY_INDEX |
return value ? "yes" : "no"; |
|
? ccs_mac_keywords[CCS_MAX_MAC_INDEX + operation] + 12 : NULL; |
|
281 |
} |
} |
282 |
|
|
283 |
|
/* Prototype for ccs_addprintf(). */ |
284 |
|
static void ccs_addprintf(char *buffer, int len, const char *fmt, ...) |
285 |
|
__attribute__ ((format(printf, 3, 4))); |
286 |
|
|
287 |
/** |
/** |
288 |
* ccs_yesno - Return "yes" or "no". |
* ccs_addprintf - strncat()-like-snprintf(). |
289 |
* |
* |
290 |
* @value: Bool value. |
* @buffer: Buffer to write to. Must be '\0'-terminated. |
291 |
|
* @len: Size of @buffer. |
292 |
|
* @fmt: The printf()'s format string, followed by parameters. |
293 |
|
* |
294 |
|
* Returns nothing. |
295 |
*/ |
*/ |
296 |
static const char *ccs_yesno(const unsigned int value) |
static void ccs_addprintf(char *buffer, int len, const char *fmt, ...) |
297 |
{ |
{ |
298 |
return value ? "yes" : "no"; |
va_list args; |
299 |
|
const int pos = strlen(buffer); |
300 |
|
va_start(args, fmt); |
301 |
|
vsnprintf(buffer + pos, len - pos - 1, fmt, args); |
302 |
|
va_end(args); |
303 |
} |
} |
304 |
|
|
305 |
/** |
/** |
306 |
* ccs_io_printf - Transactional printf() to "struct ccs_io_buffer" structure. |
* ccs_flush - Flush queued string to userspace's buffer. |
307 |
* |
* |
308 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
|
* @fmt: The printf()'s format string, followed by parameters. |
|
309 |
* |
* |
310 |
* Returns true on success, false otherwise. |
* Returns true if all data was flushed, false otherwise. |
311 |
|
*/ |
312 |
|
static bool ccs_flush(struct ccs_io_buffer *head) |
313 |
|
{ |
314 |
|
while (head->r.w_pos) { |
315 |
|
const char *w = head->r.w[0]; |
316 |
|
size_t len = strlen(w); |
317 |
|
if (len) { |
318 |
|
if (len > head->read_user_buf_avail) |
319 |
|
len = head->read_user_buf_avail; |
320 |
|
if (!len) |
321 |
|
return false; |
322 |
|
if (copy_to_user(head->read_user_buf, w, len)) |
323 |
|
return false; |
324 |
|
head->read_user_buf_avail -= len; |
325 |
|
head->read_user_buf += len; |
326 |
|
w += len; |
327 |
|
} |
328 |
|
head->r.w[0] = w; |
329 |
|
if (*w) |
330 |
|
return false; |
331 |
|
/* Add '\0' for audit logs and query. */ |
332 |
|
if (head->type == CCS_AUDIT || head->type == CCS_QUERY) { |
333 |
|
if (!head->read_user_buf_avail || |
334 |
|
copy_to_user(head->read_user_buf, "", 1)) |
335 |
|
return false; |
336 |
|
head->read_user_buf_avail--; |
337 |
|
head->read_user_buf++; |
338 |
|
} |
339 |
|
head->r.w_pos--; |
340 |
|
for (len = 0; len < head->r.w_pos; len++) |
341 |
|
head->r.w[len] = head->r.w[len + 1]; |
342 |
|
} |
343 |
|
head->r.avail = 0; |
344 |
|
return true; |
345 |
|
} |
346 |
|
|
347 |
|
/** |
348 |
|
* ccs_set_string - Queue string to "struct ccs_io_buffer" structure. |
349 |
* |
* |
350 |
* The snprintf() will truncate, but ccs_io_printf() won't. |
* @head: Pointer to "struct ccs_io_buffer". |
351 |
|
* @string: String to print. |
352 |
|
* |
353 |
|
* Returns nothing. |
354 |
|
* |
355 |
|
* Note that @string has to be kept valid until @head is kfree()d. |
356 |
|
* This means that char[] allocated on stack memory cannot be passed to |
357 |
|
* this function. Use ccs_io_printf() for char[] allocated on stack memory. |
358 |
*/ |
*/ |
359 |
bool ccs_io_printf(struct ccs_io_buffer *head, const char *fmt, ...) |
static void ccs_set_string(struct ccs_io_buffer *head, const char *string) |
360 |
|
{ |
361 |
|
if (head->r.w_pos < CCS_MAX_IO_READ_QUEUE) { |
362 |
|
head->r.w[head->r.w_pos++] = string; |
363 |
|
ccs_flush(head); |
364 |
|
} else |
365 |
|
printk(KERN_WARNING "Too many words in a line.\n"); |
366 |
|
} |
367 |
|
|
368 |
|
/* Prototype for ccs_io_printf(). */ |
369 |
|
static void ccs_io_printf(struct ccs_io_buffer *head, const char *fmt, ...) |
370 |
|
__attribute__ ((format(printf, 2, 3))); |
371 |
|
|
372 |
|
/** |
373 |
|
* ccs_io_printf - printf() to "struct ccs_io_buffer" structure. |
374 |
|
* |
375 |
|
* @head: Pointer to "struct ccs_io_buffer". |
376 |
|
* @fmt: The printf()'s format string, followed by parameters. |
377 |
|
* |
378 |
|
* Returns nothing. |
379 |
|
*/ |
380 |
|
static void ccs_io_printf(struct ccs_io_buffer *head, const char *fmt, ...) |
381 |
{ |
{ |
382 |
va_list args; |
va_list args; |
383 |
int len; |
size_t len; |
384 |
int pos = head->read_avail; |
size_t pos = head->r.avail; |
385 |
int size = head->readbuf_size - pos; |
int size = head->readbuf_size - pos; |
386 |
if (size <= 0) |
if (size <= 0) |
387 |
return false; |
return; |
388 |
va_start(args, fmt); |
va_start(args, fmt); |
389 |
len = vsnprintf(head->read_buf + pos, size, fmt, args); |
len = vsnprintf(head->read_buf + pos, size, fmt, args) + 1; |
390 |
va_end(args); |
va_end(args); |
391 |
if (pos + len >= head->readbuf_size) |
if (pos + len >= head->readbuf_size) { |
392 |
return false; |
printk(KERN_WARNING "Too many words in a line.\n"); |
393 |
head->read_avail += len; |
return; |
394 |
return true; |
} |
395 |
|
head->r.avail += len; |
396 |
|
ccs_set_string(head, head->read_buf + pos); |
397 |
} |
} |
398 |
|
|
399 |
/** |
/** |
400 |
* ccs_find_or_assign_new_profile - Create a new profile. |
* ccs_set_space - Put a space to "struct ccs_io_buffer" structure. |
401 |
* |
* |
402 |
|
* @head: Pointer to "struct ccs_io_buffer". |
403 |
|
* |
404 |
|
* Returns nothing. |
405 |
|
*/ |
406 |
|
static void ccs_set_space(struct ccs_io_buffer *head) |
407 |
|
{ |
408 |
|
ccs_set_string(head, " "); |
409 |
|
} |
410 |
|
|
411 |
|
/** |
412 |
|
* ccs_set_lf - Put a line feed to "struct ccs_io_buffer" structure. |
413 |
|
* |
414 |
|
* @head: Pointer to "struct ccs_io_buffer". |
415 |
|
* |
416 |
|
* Returns nothing. |
417 |
|
*/ |
418 |
|
static bool ccs_set_lf(struct ccs_io_buffer *head) |
419 |
|
{ |
420 |
|
ccs_set_string(head, "\n"); |
421 |
|
return !head->r.w_pos; |
422 |
|
} |
423 |
|
|
424 |
|
/** |
425 |
|
* ccs_set_slash - Put a shash to "struct ccs_io_buffer" structure. |
426 |
|
* |
427 |
|
* @head: Pointer to "struct ccs_io_buffer". |
428 |
|
* |
429 |
|
* Returns nothing. |
430 |
|
*/ |
431 |
|
static void ccs_set_slash(struct ccs_io_buffer *head) |
432 |
|
{ |
433 |
|
ccs_set_string(head, "/"); |
434 |
|
} |
435 |
|
|
436 |
|
/* List of namespaces. */ |
437 |
|
LIST_HEAD(ccs_namespace_list); |
438 |
|
/* True if namespace other than ccs_kernel_namespace is defined. */ |
439 |
|
static bool ccs_namespace_enabled; |
440 |
|
|
441 |
|
/** |
442 |
|
* ccs_init_policy_namespace - Initialize namespace. |
443 |
|
* |
444 |
|
* @ns: Pointer to "struct ccs_policy_namespace". |
445 |
|
* |
446 |
|
* Returns nothing. |
447 |
|
*/ |
448 |
|
void ccs_init_policy_namespace(struct ccs_policy_namespace *ns) |
449 |
|
{ |
450 |
|
unsigned int idx; |
451 |
|
for (idx = 0; idx < CCS_MAX_ACL_GROUPS; idx++) |
452 |
|
INIT_LIST_HEAD(&ns->acl_group[idx]); |
453 |
|
for (idx = 0; idx < CCS_MAX_GROUP; idx++) |
454 |
|
INIT_LIST_HEAD(&ns->group_list[idx]); |
455 |
|
for (idx = 0; idx < CCS_MAX_POLICY; idx++) |
456 |
|
INIT_LIST_HEAD(&ns->policy_list[idx]); |
457 |
|
ns->profile_version = 20100903; |
458 |
|
ccs_namespace_enabled = !list_empty(&ccs_namespace_list); |
459 |
|
list_add_tail_rcu(&ns->namespace_list, &ccs_namespace_list); |
460 |
|
} |
461 |
|
|
462 |
|
/** |
463 |
|
* ccs_print_namespace - Print namespace header. |
464 |
|
* |
465 |
|
* @head: Pointer to "struct ccs_io_buffer". |
466 |
|
* |
467 |
|
* Returns nothing. |
468 |
|
*/ |
469 |
|
static void ccs_print_namespace(struct ccs_io_buffer *head) |
470 |
|
{ |
471 |
|
if (!ccs_namespace_enabled) |
472 |
|
return; |
473 |
|
ccs_set_string(head, |
474 |
|
container_of(head->r.ns, struct ccs_policy_namespace, |
475 |
|
namespace_list)->name); |
476 |
|
ccs_set_space(head); |
477 |
|
} |
478 |
|
|
479 |
|
/** |
480 |
|
* ccs_assign_profile - Create a new profile. |
481 |
|
* |
482 |
|
* @ns: Pointer to "struct ccs_policy_namespace". |
483 |
* @profile: Profile number to create. |
* @profile: Profile number to create. |
484 |
* |
* |
485 |
* Returns pointer to "struct ccs_profile" on success, NULL otherwise. |
* Returns pointer to "struct ccs_profile" on success, NULL otherwise. |
486 |
*/ |
*/ |
487 |
static struct ccs_profile *ccs_find_or_assign_new_profile(const unsigned int |
static struct ccs_profile *ccs_assign_profile(struct ccs_policy_namespace *ns, |
488 |
profile) |
const unsigned int profile) |
489 |
{ |
{ |
490 |
struct ccs_profile *ptr; |
struct ccs_profile *ptr; |
491 |
struct ccs_profile *entry; |
struct ccs_profile *entry; |
492 |
if (profile >= CCS_MAX_PROFILES) |
if (profile >= CCS_MAX_PROFILES) |
493 |
return NULL; |
return NULL; |
494 |
ptr = ccs_profile_ptr[profile]; |
ptr = ns->profile_ptr[profile]; |
495 |
if (ptr) |
if (ptr) |
496 |
return ptr; |
return ptr; |
497 |
entry = kzalloc(sizeof(*entry), CCS_GFP_FLAGS); |
entry = kzalloc(sizeof(*entry), CCS_GFP_FLAGS); |
498 |
mutex_lock(&ccs_policy_lock); |
if (mutex_lock_interruptible(&ccs_policy_lock)) |
499 |
ptr = ccs_profile_ptr[profile]; |
goto out; |
500 |
|
ptr = ns->profile_ptr[profile]; |
501 |
if (!ptr && ccs_memory_ok(entry, sizeof(*entry))) { |
if (!ptr && ccs_memory_ok(entry, sizeof(*entry))) { |
502 |
ptr = entry; |
ptr = entry; |
|
ptr->audit = &ccs_default_profile.preference; |
|
|
ptr->learning = &ccs_default_profile.preference; |
|
|
ptr->permissive = &ccs_default_profile.preference; |
|
|
ptr->enforcing = &ccs_default_profile.preference; |
|
503 |
ptr->default_config = CCS_CONFIG_DISABLED | |
ptr->default_config = CCS_CONFIG_DISABLED | |
504 |
CCS_CONFIG_WANT_GRANT_LOG | CCS_CONFIG_WANT_REJECT_LOG; |
CCS_CONFIG_WANT_GRANT_LOG | CCS_CONFIG_WANT_REJECT_LOG; |
505 |
memset(ptr->config, CCS_CONFIG_USE_DEFAULT, |
memset(ptr->config, CCS_CONFIG_USE_DEFAULT, |
506 |
sizeof(ptr->config)); |
sizeof(ptr->config)); |
507 |
|
ptr->pref[CCS_PREF_MAX_AUDIT_LOG] = |
508 |
|
CONFIG_CCSECURITY_MAX_AUDIT_LOG; |
509 |
|
ptr->pref[CCS_PREF_MAX_LEARNING_ENTRY] = |
510 |
|
CONFIG_CCSECURITY_MAX_ACCEPT_ENTRY; |
511 |
mb(); /* Avoid out-of-order execution. */ |
mb(); /* Avoid out-of-order execution. */ |
512 |
ccs_profile_ptr[profile] = ptr; |
ns->profile_ptr[profile] = ptr; |
513 |
entry = NULL; |
entry = NULL; |
514 |
} |
} |
515 |
mutex_unlock(&ccs_policy_lock); |
mutex_unlock(&ccs_policy_lock); |
516 |
|
out: |
517 |
kfree(entry); |
kfree(entry); |
518 |
return ptr; |
return ptr; |
519 |
} |
} |
520 |
|
|
521 |
/** |
/** |
522 |
* ccs_check_profile - Check all profiles currently assigned to domains are defined. |
* ccs_check_profile - Check all profiles currently assigned to domains are defined. |
523 |
|
* |
524 |
|
* Returns nothing. |
525 |
*/ |
*/ |
526 |
static void ccs_check_profile(void) |
static void ccs_check_profile(void) |
527 |
{ |
{ |
528 |
struct ccs_domain_info *domain; |
struct ccs_domain_info *domain; |
529 |
|
const int idx = ccs_read_lock(); |
530 |
ccs_policy_loaded = true; |
ccs_policy_loaded = true; |
531 |
list_for_each_entry_rcu(domain, &ccs_domain_list, list) { |
printk(KERN_INFO "CCSecurity: 1.8.2+ 2011/07/07\n"); |
532 |
|
list_for_each_entry_srcu(domain, &ccs_domain_list, list, &ccs_ss) { |
533 |
const u8 profile = domain->profile; |
const u8 profile = domain->profile; |
534 |
if (ccs_profile_ptr[profile]) |
const struct ccs_policy_namespace *ns = domain->ns; |
535 |
|
if (ns->profile_version != 20100903) |
536 |
|
printk(KERN_ERR |
537 |
|
"Profile version %u is not supported.\n", |
538 |
|
ns->profile_version); |
539 |
|
else if (!ns->profile_ptr[profile]) |
540 |
|
printk(KERN_ERR |
541 |
|
"Profile %u (used by '%s') is not defined.\n", |
542 |
|
profile, domain->domainname->name); |
543 |
|
else |
544 |
continue; |
continue; |
545 |
panic("Profile %u (used by '%s') not defined.\n", |
printk(KERN_ERR |
546 |
profile, domain->domainname->name); |
"Userland tools for TOMOYO 1.8 must be installed and " |
547 |
|
"policy must be initialized.\n"); |
548 |
|
printk(KERN_ERR "Please see http://tomoyo.sourceforge.jp/1.8/ " |
549 |
|
"for more information.\n"); |
550 |
|
panic("STOP!"); |
551 |
} |
} |
552 |
if (ccs_profile_version != 20090903) |
ccs_read_unlock(idx); |
|
panic("Profile version %u is not supported.\n", |
|
|
ccs_profile_version); |
|
|
printk(KERN_INFO "CCSecurity: 1.7.2-pre 2010/03/08\n"); |
|
553 |
printk(KERN_INFO "Mandatory Access Control activated.\n"); |
printk(KERN_INFO "Mandatory Access Control activated.\n"); |
554 |
} |
} |
555 |
|
|
562 |
*/ |
*/ |
563 |
struct ccs_profile *ccs_profile(const u8 profile) |
struct ccs_profile *ccs_profile(const u8 profile) |
564 |
{ |
{ |
565 |
struct ccs_profile *ptr = ccs_profile_ptr[profile]; |
static struct ccs_profile ccs_null_profile; |
566 |
if (!ccs_policy_loaded) |
struct ccs_profile *ptr = ccs_current_namespace()-> |
567 |
return &ccs_default_profile; |
profile_ptr[profile]; |
568 |
BUG_ON(!ptr); |
if (!ptr) |
569 |
|
ptr = &ccs_null_profile; |
570 |
return ptr; |
return ptr; |
571 |
} |
} |
572 |
|
|
573 |
/** |
/** |
574 |
* ccs_write_profile - Write profile table. |
* ccs_find_yesno - Find values for specified keyword. |
575 |
* |
* |
576 |
* @head: Pointer to "struct ccs_io_buffer". |
* @string: String to check. |
577 |
|
* @find: Name of keyword. |
578 |
* |
* |
579 |
* Returns 0 on success, negative value otherwise. |
* Returns 1 if "@find=yes" was found, 0 if "@find=no" was found, -1 otherwise. |
580 |
*/ |
*/ |
581 |
static int ccs_write_profile(struct ccs_io_buffer *head) |
static s8 ccs_find_yesno(const char *string, const char *find) |
582 |
{ |
{ |
583 |
char *data = head->write_buf; |
const char *cp = strstr(string, find); |
584 |
unsigned int i; |
if (cp) { |
585 |
int value; |
cp += strlen(find); |
586 |
int mode; |
if (!strncmp(cp, "=yes", 4)) |
587 |
u8 config; |
return 1; |
588 |
bool use_default = false; |
else if (!strncmp(cp, "=no", 3)) |
|
char *cp; |
|
|
struct ccs_profile *profile; |
|
|
if (sscanf(data, "PROFILE_VERSION=%u", &ccs_profile_version) == 1) |
|
|
return 0; |
|
|
i = simple_strtoul(data, &cp, 10); |
|
|
if (data == cp) { |
|
|
profile = &ccs_default_profile; |
|
|
} else { |
|
|
if (*cp != '-') |
|
|
return -EINVAL; |
|
|
data = cp + 1; |
|
|
profile = ccs_find_or_assign_new_profile(i); |
|
|
if (!profile) |
|
|
return -EINVAL; |
|
|
} |
|
|
cp = strchr(data, '='); |
|
|
if (!cp) |
|
|
return -EINVAL; |
|
|
*cp++ = '\0'; |
|
|
if (profile != &ccs_default_profile) |
|
|
use_default = strstr(cp, "use_default") != NULL; |
|
|
if (strstr(cp, "verbose=yes")) |
|
|
value = 1; |
|
|
else if (strstr(cp, "verbose=no")) |
|
|
value = 0; |
|
|
else |
|
|
value = -1; |
|
|
if (!strcmp(data, "PREFERENCE::audit")) { |
|
|
#ifdef CONFIG_CCSECURITY_AUDIT |
|
|
char *cp2; |
|
|
#endif |
|
|
if (use_default) { |
|
|
profile->audit = &ccs_default_profile.preference; |
|
|
return 0; |
|
|
} |
|
|
profile->audit = &profile->preference; |
|
|
#ifdef CONFIG_CCSECURITY_AUDIT |
|
|
cp2 = strstr(cp, "max_grant_log="); |
|
|
if (cp2) |
|
|
sscanf(cp2 + 14, "%u", |
|
|
&profile->preference.audit_max_grant_log); |
|
|
cp2 = strstr(cp, "max_reject_log="); |
|
|
if (cp2) |
|
|
sscanf(cp2 + 15, "%u", |
|
|
&profile->preference.audit_max_reject_log); |
|
|
#endif |
|
|
if (strstr(cp, "task_info=yes")) |
|
|
profile->preference.audit_task_info = true; |
|
|
else if (strstr(cp, "task_info=no")) |
|
|
profile->preference.audit_task_info = false; |
|
|
if (strstr(cp, "path_info=yes")) |
|
|
profile->preference.audit_path_info = true; |
|
|
else if (strstr(cp, "path_info=no")) |
|
|
profile->preference.audit_path_info = false; |
|
|
return 0; |
|
|
} |
|
|
if (!strcmp(data, "PREFERENCE::enforcing")) { |
|
|
char *cp2; |
|
|
if (use_default) { |
|
|
profile->enforcing = &ccs_default_profile.preference; |
|
|
return 0; |
|
|
} |
|
|
profile->enforcing = &profile->preference; |
|
|
if (value >= 0) |
|
|
profile->preference.enforcing_verbose = value; |
|
|
cp2 = strstr(cp, "penalty="); |
|
|
if (cp2) |
|
|
sscanf(cp2 + 8, "%u", |
|
|
&profile->preference.enforcing_penalty); |
|
|
return 0; |
|
|
} |
|
|
if (!strcmp(data, "PREFERENCE::permissive")) { |
|
|
if (use_default) { |
|
|
profile->permissive = &ccs_default_profile.preference; |
|
|
return 0; |
|
|
} |
|
|
profile->permissive = &profile->preference; |
|
|
if (value >= 0) |
|
|
profile->preference.permissive_verbose = value; |
|
|
return 0; |
|
|
} |
|
|
if (!strcmp(data, "PREFERENCE::learning")) { |
|
|
char *cp2; |
|
|
if (use_default) { |
|
|
profile->learning = &ccs_default_profile.preference; |
|
589 |
return 0; |
return 0; |
|
} |
|
|
profile->learning = &profile->preference; |
|
|
if (value >= 0) |
|
|
profile->preference.learning_verbose = value; |
|
|
cp2 = strstr(cp, "max_entry="); |
|
|
if (cp2) |
|
|
sscanf(cp2 + 10, "%u", |
|
|
&profile->preference.learning_max_entry); |
|
|
if (strstr(cp, "exec.realpath=yes")) |
|
|
profile->preference.learning_exec_realpath = true; |
|
|
else if (strstr(cp, "exec.realpath=no")) |
|
|
profile->preference.learning_exec_realpath = false; |
|
|
if (strstr(cp, "exec.argv0=yes")) |
|
|
profile->preference.learning_exec_argv0 = true; |
|
|
else if (strstr(cp, "exec.argv0=no")) |
|
|
profile->preference.learning_exec_argv0 = false; |
|
|
if (strstr(cp, "symlink.target=yes")) |
|
|
profile->preference.learning_symlink_target = true; |
|
|
else if (strstr(cp, "symlink.target=no")) |
|
|
profile->preference.learning_symlink_target = false; |
|
|
return 0; |
|
590 |
} |
} |
591 |
if (profile == &ccs_default_profile) |
return -1; |
592 |
return -EINVAL; |
} |
593 |
if (!strcmp(data, "COMMENT")) { |
|
594 |
const struct ccs_path_info *old_comment = profile->comment; |
/** |
595 |
profile->comment = ccs_get_name(cp); |
* ccs_set_uint - Set value for specified preference. |
596 |
ccs_put_name(old_comment); |
* |
597 |
return 0; |
* @i: Pointer to "unsigned int". |
598 |
} |
* @string: String to check. |
599 |
if (!strcmp(data, "CONFIG")) { |
* @find: Name of keyword. |
600 |
i = CCS_MAX_MAC_INDEX + CCS_MAX_CAPABILITY_INDEX |
* |
601 |
+ CCS_MAX_MAC_CATEGORY_INDEX; |
* Returns nothing. |
602 |
|
*/ |
603 |
|
static void ccs_set_uint(unsigned int *i, const char *string, const char *find) |
604 |
|
{ |
605 |
|
const char *cp = strstr(string, find); |
606 |
|
if (cp) |
607 |
|
sscanf(cp + strlen(find), "=%u", i); |
608 |
|
} |
609 |
|
|
610 |
|
/** |
611 |
|
* ccs_set_mode - Set mode for specified profile. |
612 |
|
* |
613 |
|
* @name: Name of functionality. |
614 |
|
* @value: Mode for @name. |
615 |
|
* @profile: Pointer to "struct ccs_profile". |
616 |
|
* |
617 |
|
* Returns 0 on success, negative value otherwise. |
618 |
|
*/ |
619 |
|
static int ccs_set_mode(char *name, const char *value, |
620 |
|
struct ccs_profile *profile) |
621 |
|
{ |
622 |
|
u8 i; |
623 |
|
u8 config; |
624 |
|
if (!strcmp(name, "CONFIG")) { |
625 |
|
i = CCS_MAX_MAC_INDEX + CCS_MAX_MAC_CATEGORY_INDEX; |
626 |
config = profile->default_config; |
config = profile->default_config; |
627 |
} else if (ccs_str_starts(&data, "CONFIG::")) { |
} else if (ccs_str_starts(&name, "CONFIG::")) { |
628 |
config = 0; |
config = 0; |
629 |
for (i = 0; i < CCS_MAX_MAC_INDEX + CCS_MAX_CAPABILITY_INDEX |
for (i = 0; i < CCS_MAX_MAC_INDEX + CCS_MAX_MAC_CATEGORY_INDEX; |
630 |
+ CCS_MAX_MAC_CATEGORY_INDEX; i++) { |
i++) { |
631 |
if (strcmp(data, ccs_mac_keywords[i])) |
int len = 0; |
632 |
|
if (i < CCS_MAX_MAC_INDEX) { |
633 |
|
const u8 c = ccs_index2category[i]; |
634 |
|
const char *category = |
635 |
|
ccs_category_keywords[c]; |
636 |
|
len = strlen(category); |
637 |
|
if (strncmp(name, category, len) || |
638 |
|
name[len++] != ':' || name[len++] != ':') |
639 |
|
continue; |
640 |
|
} |
641 |
|
if (strcmp(name + len, ccs_mac_keywords[i])) |
642 |
continue; |
continue; |
643 |
config = profile->config[i]; |
config = profile->config[i]; |
644 |
break; |
break; |
645 |
} |
} |
646 |
if (i == CCS_MAX_MAC_INDEX + CCS_MAX_CAPABILITY_INDEX |
if (i == CCS_MAX_MAC_INDEX + CCS_MAX_MAC_CATEGORY_INDEX) |
|
+ CCS_MAX_MAC_CATEGORY_INDEX) |
|
647 |
return -EINVAL; |
return -EINVAL; |
648 |
} else { |
} else { |
649 |
return -EINVAL; |
return -EINVAL; |
650 |
} |
} |
651 |
if (use_default) { |
if (strstr(value, "use_default")) { |
652 |
config = CCS_CONFIG_USE_DEFAULT; |
config = CCS_CONFIG_USE_DEFAULT; |
653 |
} else { |
} else { |
654 |
for (mode = 3; mode >= 0; mode--) |
u8 mode; |
655 |
if (strstr(cp, ccs_mode_4[mode])) |
for (mode = 0; mode < CCS_CONFIG_MAX_MODE; mode++) |
656 |
|
if (strstr(value, ccs_mode[mode])) |
657 |
/* |
/* |
658 |
* Update lower 3 bits in order to distinguish |
* Update lower 3 bits in order to distinguish |
659 |
* 'config' from 'CCS_CONFIG_USE_DEAFULT'. |
* 'config' from 'CCS_CONFIG_USE_DEAFULT'. |
660 |
*/ |
*/ |
661 |
config = (config & ~7) | mode; |
config = (config & ~7) | mode; |
|
#ifdef CONFIG_CCSECURITY_AUDIT |
|
662 |
if (config != CCS_CONFIG_USE_DEFAULT) { |
if (config != CCS_CONFIG_USE_DEFAULT) { |
663 |
if (strstr(cp, "grant_log=yes")) |
switch (ccs_find_yesno(value, "grant_log")) { |
664 |
|
case 1: |
665 |
config |= CCS_CONFIG_WANT_GRANT_LOG; |
config |= CCS_CONFIG_WANT_GRANT_LOG; |
666 |
else if (strstr(cp, "grant_log=no")) |
break; |
667 |
|
case 0: |
668 |
config &= ~CCS_CONFIG_WANT_GRANT_LOG; |
config &= ~CCS_CONFIG_WANT_GRANT_LOG; |
669 |
if (strstr(cp, "reject_log=yes")) |
break; |
670 |
|
} |
671 |
|
switch (ccs_find_yesno(value, "reject_log")) { |
672 |
|
case 1: |
673 |
config |= CCS_CONFIG_WANT_REJECT_LOG; |
config |= CCS_CONFIG_WANT_REJECT_LOG; |
674 |
else if (strstr(cp, "reject_log=no")) |
break; |
675 |
|
case 0: |
676 |
config &= ~CCS_CONFIG_WANT_REJECT_LOG; |
config &= ~CCS_CONFIG_WANT_REJECT_LOG; |
677 |
|
break; |
678 |
|
} |
679 |
} |
} |
|
#endif |
|
680 |
} |
} |
681 |
if (i < CCS_MAX_MAC_INDEX + CCS_MAX_CAPABILITY_INDEX |
if (i < CCS_MAX_MAC_INDEX + CCS_MAX_MAC_CATEGORY_INDEX) |
|
+ CCS_MAX_MAC_CATEGORY_INDEX) |
|
682 |
profile->config[i] = config; |
profile->config[i] = config; |
683 |
else if (config != CCS_CONFIG_USE_DEFAULT) |
else if (config != CCS_CONFIG_USE_DEFAULT) |
684 |
profile->default_config = config; |
profile->default_config = config; |
686 |
} |
} |
687 |
|
|
688 |
/** |
/** |
689 |
|
* ccs_write_profile - Write profile table. |
690 |
|
* |
691 |
|
* @head: Pointer to "struct ccs_io_buffer". |
692 |
|
* |
693 |
|
* Returns 0 on success, negative value otherwise. |
694 |
|
*/ |
695 |
|
static int ccs_write_profile(struct ccs_io_buffer *head) |
696 |
|
{ |
697 |
|
char *data = head->write_buf; |
698 |
|
unsigned int i; |
699 |
|
char *cp; |
700 |
|
struct ccs_profile *profile; |
701 |
|
if (sscanf(data, "PROFILE_VERSION=%u", &head->w.ns->profile_version) |
702 |
|
== 1) |
703 |
|
return 0; |
704 |
|
i = simple_strtoul(data, &cp, 10); |
705 |
|
if (*cp != '-') |
706 |
|
return -EINVAL; |
707 |
|
data = cp + 1; |
708 |
|
profile = ccs_assign_profile(head->w.ns, i); |
709 |
|
if (!profile) |
710 |
|
return -EINVAL; |
711 |
|
cp = strchr(data, '='); |
712 |
|
if (!cp) |
713 |
|
return -EINVAL; |
714 |
|
*cp++ = '\0'; |
715 |
|
if (!strcmp(data, "COMMENT")) { |
716 |
|
static DEFINE_SPINLOCK(lock); |
717 |
|
const struct ccs_path_info *new_comment = ccs_get_name(cp); |
718 |
|
const struct ccs_path_info *old_comment; |
719 |
|
if (!new_comment) |
720 |
|
return -ENOMEM; |
721 |
|
spin_lock(&lock); |
722 |
|
old_comment = profile->comment; |
723 |
|
profile->comment = new_comment; |
724 |
|
spin_unlock(&lock); |
725 |
|
ccs_put_name(old_comment); |
726 |
|
return 0; |
727 |
|
} |
728 |
|
if (!strcmp(data, "PREFERENCE")) { |
729 |
|
for (i = 0; i < CCS_MAX_PREF; i++) |
730 |
|
ccs_set_uint(&profile->pref[i], cp, |
731 |
|
ccs_pref_keywords[i]); |
732 |
|
return 0; |
733 |
|
} |
734 |
|
return ccs_set_mode(data, cp, profile); |
735 |
|
} |
736 |
|
|
737 |
|
/** |
738 |
|
* ccs_print_config - Print mode for specified functionality. |
739 |
|
* |
740 |
|
* @head: Pointer to "struct ccs_io_buffer". |
741 |
|
* @config: Mode for that functionality. |
742 |
|
* |
743 |
|
* Returns nothing. |
744 |
|
* |
745 |
|
* Caller prints functionality's name. |
746 |
|
*/ |
747 |
|
static void ccs_print_config(struct ccs_io_buffer *head, const u8 config) |
748 |
|
{ |
749 |
|
ccs_io_printf(head, "={ mode=%s grant_log=%s reject_log=%s }\n", |
750 |
|
ccs_mode[config & 3], |
751 |
|
ccs_yesno(config & CCS_CONFIG_WANT_GRANT_LOG), |
752 |
|
ccs_yesno(config & CCS_CONFIG_WANT_REJECT_LOG)); |
753 |
|
} |
754 |
|
|
755 |
|
/** |
756 |
* ccs_read_profile - Read profile table. |
* ccs_read_profile - Read profile table. |
757 |
* |
* |
758 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
759 |
|
* |
760 |
|
* Returns nothing. |
761 |
*/ |
*/ |
762 |
static void ccs_read_profile(struct ccs_io_buffer *head) |
static void ccs_read_profile(struct ccs_io_buffer *head) |
763 |
{ |
{ |
764 |
int index; |
u8 index; |
765 |
if (head->read_eof) |
struct ccs_policy_namespace *ns = container_of(head->r.ns, typeof(*ns), |
766 |
|
namespace_list); |
767 |
|
const struct ccs_profile *profile; |
768 |
|
if (head->r.eof) |
769 |
return; |
return; |
770 |
if (head->read_bit) |
next: |
771 |
goto body; |
index = head->r.index; |
772 |
ccs_io_printf(head, "PROFILE_VERSION=%s\n", "20090903"); |
profile = ns->profile_ptr[index]; |
773 |
ccs_io_printf(head, "PREFERENCE::audit={ " |
switch (head->r.step) { |
774 |
#ifdef CONFIG_CCSECURITY_AUDIT |
case 0: |
775 |
"max_grant_log=%u max_reject_log=%u " |
ccs_print_namespace(head); |
776 |
#endif |
ccs_io_printf(head, "PROFILE_VERSION=%u\n", |
777 |
"task_info=%s path_info=%s }\n", |
ns->profile_version); |
778 |
#ifdef CONFIG_CCSECURITY_AUDIT |
head->r.step++; |
779 |
ccs_default_profile.preference.audit_max_grant_log, |
break; |
780 |
ccs_default_profile.preference.audit_max_reject_log, |
case 1: |
781 |
#endif |
for ( ; head->r.index < CCS_MAX_PROFILES; head->r.index++) |
782 |
ccs_yesno(ccs_default_profile.preference. |
if (ns->profile_ptr[head->r.index]) |
783 |
audit_task_info), |
break; |
784 |
ccs_yesno(ccs_default_profile.preference. |
if (head->r.index == CCS_MAX_PROFILES) { |
785 |
audit_path_info)); |
head->r.eof = true; |
786 |
ccs_io_printf(head, "PREFERENCE::learning={ verbose=%s max_entry=%u " |
return; |
787 |
"exec.realpath=%s exec.argv0=%s symlink.target=%s }\n", |
} |
788 |
ccs_yesno(ccs_default_profile.preference. |
head->r.step++; |
789 |
learning_verbose), |
break; |
790 |
ccs_default_profile.preference.learning_max_entry, |
case 2: |
791 |
ccs_yesno(ccs_default_profile.preference. |
{ |
792 |
learning_exec_realpath), |
u8 i; |
793 |
ccs_yesno(ccs_default_profile.preference. |
const struct ccs_path_info *comment = profile->comment; |
794 |
learning_exec_argv0), |
ccs_print_namespace(head); |
795 |
ccs_yesno(ccs_default_profile.preference. |
ccs_io_printf(head, "%u-COMMENT=", index); |
796 |
learning_symlink_target)); |
ccs_set_string(head, comment ? comment->name : ""); |
797 |
ccs_io_printf(head, "PREFERENCE::permissive={ verbose=%s }\n", |
ccs_set_lf(head); |
798 |
ccs_yesno(ccs_default_profile.preference. |
ccs_print_namespace(head); |
799 |
permissive_verbose)); |
ccs_io_printf(head, "%u-PREFERENCE={ ", index); |
800 |
ccs_io_printf(head, "PREFERENCE::enforcing={ verbose=%s penalty=%u " |
for (i = 0; i < CCS_MAX_PREF; i++) |
801 |
"}\n", |
ccs_io_printf(head, "%s=%u ", |
802 |
ccs_yesno(ccs_default_profile.preference. |
ccs_pref_keywords[i], |
803 |
enforcing_verbose), |
profile->pref[i]); |
804 |
ccs_default_profile.preference.enforcing_penalty); |
ccs_set_string(head, "}\n"); |
805 |
head->read_bit = 1; |
head->r.step++; |
806 |
body: |
} |
807 |
for (index = head->read_step; index < CCS_MAX_PROFILES; index++) { |
break; |
808 |
bool done; |
case 3: |
809 |
u8 config; |
{ |
810 |
int i; |
ccs_print_namespace(head); |
811 |
int pos; |
ccs_io_printf(head, "%u-%s", index, "CONFIG"); |
812 |
const struct ccs_profile *profile = ccs_profile_ptr[index]; |
ccs_print_config(head, profile->default_config); |
813 |
const struct ccs_path_info *comment; |
head->r.bit = 0; |
814 |
head->read_step = index; |
head->r.step++; |
815 |
if (!profile) |
} |
816 |
continue; |
break; |
817 |
pos = head->read_avail; |
case 4: |
818 |
comment = profile->comment; |
for ( ; head->r.bit < CCS_MAX_MAC_INDEX |
819 |
done = ccs_io_printf(head, "%u-COMMENT=%s\n", index, |
+ CCS_MAX_MAC_CATEGORY_INDEX; head->r.bit++) { |
820 |
comment ? comment->name : ""); |
const u8 i = head->r.bit; |
821 |
if (!done) |
const u8 config = profile->config[i]; |
|
goto out; |
|
|
config = profile->default_config; |
|
|
#ifdef CONFIG_CCSECURITY_AUDIT |
|
|
if (!ccs_io_printf(head, "%u-CONFIG={ mode=%s grant_log=%s " |
|
|
"reject_log=%s }\n", index, |
|
|
ccs_mode_4[config & 3], |
|
|
ccs_yesno(config & |
|
|
CCS_CONFIG_WANT_GRANT_LOG), |
|
|
ccs_yesno(config & |
|
|
CCS_CONFIG_WANT_REJECT_LOG))) |
|
|
goto out; |
|
|
#else |
|
|
if (!ccs_io_printf(head, "%u-CONFIG={ mode=%s }\n", index, |
|
|
ccs_mode_4[config & 3])) |
|
|
goto out; |
|
|
#endif |
|
|
for (i = 0; i < CCS_MAX_MAC_INDEX + CCS_MAX_CAPABILITY_INDEX |
|
|
+ CCS_MAX_MAC_CATEGORY_INDEX; i++) { |
|
|
#ifdef CONFIG_CCSECURITY_AUDIT |
|
|
const char *g; |
|
|
const char *r; |
|
|
#endif |
|
|
config = profile->config[i]; |
|
822 |
if (config == CCS_CONFIG_USE_DEFAULT) |
if (config == CCS_CONFIG_USE_DEFAULT) |
823 |
continue; |
continue; |
824 |
#ifdef CONFIG_CCSECURITY_AUDIT |
ccs_print_namespace(head); |
825 |
g = ccs_yesno(config & CCS_CONFIG_WANT_GRANT_LOG); |
if (i < CCS_MAX_MAC_INDEX) |
826 |
r = ccs_yesno(config & CCS_CONFIG_WANT_REJECT_LOG); |
ccs_io_printf(head, "%u-CONFIG::%s::%s", index, |
827 |
if (!ccs_io_printf(head, "%u-CONFIG::%s={ mode=%s " |
ccs_category_keywords |
828 |
"grant_log=%s reject_log=%s }\n", |
[ccs_index2category[i]], |
829 |
index, ccs_mac_keywords[i], |
ccs_mac_keywords[i]); |
830 |
ccs_mode_4[config & 3], g, r)) |
else |
831 |
goto out; |
ccs_io_printf(head, "%u-CONFIG::%s", index, |
832 |
#else |
ccs_mac_keywords[i]); |
833 |
if (!ccs_io_printf(head, "%u-CONFIG::%s={ mode=%s }\n", |
ccs_print_config(head, config); |
834 |
index, ccs_mac_keywords[i], |
head->r.bit++; |
835 |
ccs_mode_4[config & 3])) |
break; |
836 |
goto out; |
} |
837 |
#endif |
if (head->r.bit == CCS_MAX_MAC_INDEX |
838 |
|
+ CCS_MAX_MAC_CATEGORY_INDEX) { |
839 |
|
head->r.index++; |
840 |
|
head->r.step = 1; |
841 |
} |
} |
|
if (profile->audit != &ccs_default_profile.preference && |
|
|
!ccs_io_printf(head, "%u-PREFERENCE::audit={ " |
|
|
#ifdef CONFIG_CCSECURITY_AUDIT |
|
|
"max_grant_log=%u max_reject_log=%u " |
|
|
#endif |
|
|
"task_info=%s path_info=%s }\n", index, |
|
|
#ifdef CONFIG_CCSECURITY_AUDIT |
|
|
profile->preference.audit_max_grant_log, |
|
|
profile->preference.audit_max_reject_log, |
|
|
#endif |
|
|
ccs_yesno(profile->preference. |
|
|
audit_task_info), |
|
|
ccs_yesno(profile->preference. |
|
|
audit_path_info))) |
|
|
goto out; |
|
|
if (profile->learning != &ccs_default_profile.preference && |
|
|
!ccs_io_printf(head, "%u-PREFERENCE::learning={ " |
|
|
"verbose=%s max_entry=%u exec.realpath=%s " |
|
|
"exec.argv0=%s symlink.target=%s }\n", |
|
|
index, |
|
|
ccs_yesno(profile->preference. |
|
|
learning_verbose), |
|
|
profile->preference.learning_max_entry, |
|
|
ccs_yesno(profile->preference. |
|
|
learning_exec_realpath), |
|
|
ccs_yesno(profile->preference. |
|
|
learning_exec_argv0), |
|
|
ccs_yesno(profile->preference. |
|
|
learning_symlink_target))) |
|
|
goto out; |
|
|
if (profile->permissive != &ccs_default_profile.preference && |
|
|
!ccs_io_printf(head, "%u-PREFERENCE::permissive={ " |
|
|
"verbose=%s }\n", index, |
|
|
ccs_yesno(profile->preference. |
|
|
permissive_verbose))) |
|
|
goto out; |
|
|
if (profile->enforcing != &ccs_default_profile.preference && |
|
|
!ccs_io_printf(head, "%u-PREFERENCE::enforcing={ " |
|
|
"verbose=%s penalty=%u }\n", index, |
|
|
ccs_yesno(profile->preference. |
|
|
enforcing_verbose), |
|
|
profile->preference.enforcing_penalty)) |
|
|
goto out; |
|
|
continue; |
|
|
out: |
|
|
head->read_avail = pos; |
|
842 |
break; |
break; |
843 |
} |
} |
844 |
if (index == CCS_MAX_PROFILES) |
if (ccs_flush(head)) |
845 |
head->read_eof = true; |
goto next; |
846 |
} |
} |
847 |
|
|
848 |
/* The list for "struct ccs_policy_manager_entry". */ |
/** |
849 |
LIST_HEAD(ccs_policy_manager_list); |
* ccs_same_manager - Check for duplicated "struct ccs_manager" entry. |
850 |
|
* |
851 |
|
* @a: Pointer to "struct ccs_acl_head". |
852 |
|
* @b: Pointer to "struct ccs_acl_head". |
853 |
|
* |
854 |
|
* Returns true if @a == @b, false otherwise. |
855 |
|
*/ |
856 |
|
static bool ccs_same_manager(const struct ccs_acl_head *a, |
857 |
|
const struct ccs_acl_head *b) |
858 |
|
{ |
859 |
|
return container_of(a, struct ccs_manager, head)->manager |
860 |
|
== container_of(b, struct ccs_manager, head)->manager; |
861 |
|
} |
862 |
|
|
863 |
/** |
/** |
864 |
* ccs_update_manager_entry - Add a manager entry. |
* ccs_update_manager_entry - Add a manager entry. |
868 |
* |
* |
869 |
* Returns 0 on success, negative value otherwise. |
* Returns 0 on success, negative value otherwise. |
870 |
*/ |
*/ |
871 |
static int ccs_update_manager_entry(const char *manager, const bool is_delete) |
static inline int ccs_update_manager_entry(const char *manager, |
872 |
|
const bool is_delete) |
873 |
{ |
{ |
874 |
struct ccs_policy_manager_entry *ptr; |
struct ccs_manager e = { }; |
875 |
struct ccs_policy_manager_entry e = { }; |
struct ccs_acl_param param = { |
876 |
|
/* .ns = &ccs_kernel_namespace, */ |
877 |
|
.is_delete = is_delete, |
878 |
|
.list = &ccs_kernel_namespace.policy_list[CCS_ID_MANAGER], |
879 |
|
}; |
880 |
int error = is_delete ? -ENOENT : -ENOMEM; |
int error = is_delete ? -ENOENT : -ENOMEM; |
881 |
if (ccs_is_domain_def(manager)) { |
if (ccs_domain_def(manager)) { |
882 |
if (!ccs_is_correct_domain(manager)) |
if (!ccs_correct_domain(manager)) |
883 |
return -EINVAL; |
return -EINVAL; |
884 |
e.is_domain = true; |
e.is_domain = true; |
885 |
} else { |
} else { |
886 |
if (!ccs_is_correct_path(manager, 1, -1, -1)) |
if (!ccs_correct_path(manager)) |
887 |
return -EINVAL; |
return -EINVAL; |
888 |
} |
} |
889 |
e.manager = ccs_get_name(manager); |
e.manager = ccs_get_name(manager); |
890 |
if (!e.manager) |
if (e.manager) { |
891 |
return -ENOMEM; |
error = ccs_update_policy(&e.head, sizeof(e), ¶m, |
892 |
mutex_lock(&ccs_policy_lock); |
ccs_same_manager); |
893 |
list_for_each_entry_rcu(ptr, &ccs_policy_manager_list, list) { |
ccs_put_name(e.manager); |
|
if (ptr->manager != e.manager) |
|
|
continue; |
|
|
ptr->is_deleted = is_delete; |
|
|
error = 0; |
|
|
break; |
|
894 |
} |
} |
|
if (!is_delete && error) { |
|
|
struct ccs_policy_manager_entry *entry = |
|
|
ccs_commit_ok(&e, sizeof(e)); |
|
|
if (entry) { |
|
|
list_add_tail_rcu(&entry->list, |
|
|
&ccs_policy_manager_list); |
|
|
error = 0; |
|
|
} |
|
|
} |
|
|
mutex_unlock(&ccs_policy_lock); |
|
|
ccs_put_name(e.manager); |
|
895 |
return error; |
return error; |
896 |
} |
} |
897 |
|
|
898 |
/** |
/** |
899 |
* ccs_write_manager_policy - Write manager policy. |
* ccs_write_manager - Write manager policy. |
900 |
* |
* |
901 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
902 |
* |
* |
903 |
* Returns 0 on success, negative value otherwise. |
* Returns 0 on success, negative value otherwise. |
904 |
*/ |
*/ |
905 |
static int ccs_write_manager_policy(struct ccs_io_buffer *head) |
static int ccs_write_manager(struct ccs_io_buffer *head) |
906 |
{ |
{ |
907 |
char *data = head->write_buf; |
const char *data = head->write_buf; |
|
bool is_delete = ccs_str_starts(&data, CCS_KEYWORD_DELETE); |
|
908 |
if (!strcmp(data, "manage_by_non_root")) { |
if (!strcmp(data, "manage_by_non_root")) { |
909 |
ccs_manage_by_non_root = !is_delete; |
ccs_manage_by_non_root = !head->w.is_delete; |
910 |
return 0; |
return 0; |
911 |
} |
} |
912 |
return ccs_update_manager_entry(data, is_delete); |
return ccs_update_manager_entry(data, head->w.is_delete); |
913 |
} |
} |
914 |
|
|
915 |
/** |
/** |
916 |
* ccs_read_manager_policy - Read manager policy. |
* ccs_read_manager - Read manager policy. |
917 |
* |
* |
918 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
919 |
* |
* |
920 |
|
* Returns nothing. |
921 |
|
* |
922 |
* Caller holds ccs_read_lock(). |
* Caller holds ccs_read_lock(). |
923 |
*/ |
*/ |
924 |
static void ccs_read_manager_policy(struct ccs_io_buffer *head) |
static void ccs_read_manager(struct ccs_io_buffer *head) |
925 |
{ |
{ |
926 |
struct list_head *pos; |
if (head->r.eof) |
|
if (head->read_eof) |
|
927 |
return; |
return; |
928 |
list_for_each_cookie(pos, head->read_var2, &ccs_policy_manager_list) { |
list_for_each_cookie(head->r.acl, &ccs_kernel_namespace. |
929 |
struct ccs_policy_manager_entry *ptr; |
policy_list[CCS_ID_MANAGER]) { |
930 |
ptr = list_entry(pos, struct ccs_policy_manager_entry, list); |
struct ccs_manager *ptr = |
931 |
if (ptr->is_deleted) |
list_entry(head->r.acl, typeof(*ptr), head.list); |
932 |
|
if (ptr->head.is_deleted) |
933 |
continue; |
continue; |
934 |
if (!ccs_io_printf(head, "%s\n", ptr->manager->name)) |
if (!ccs_flush(head)) |
935 |
return; |
return; |
936 |
|
ccs_set_string(head, ptr->manager->name); |
937 |
|
ccs_set_lf(head); |
938 |
} |
} |
939 |
head->read_eof = true; |
head->r.eof = true; |
940 |
} |
} |
941 |
|
|
942 |
/** |
/** |
943 |
* ccs_is_policy_manager - Check whether the current process is a policy manager. |
* ccs_manager - Check whether the current process is a policy manager. |
944 |
* |
* |
945 |
* Returns true if the current process is permitted to modify policy |
* Returns true if the current process is permitted to modify policy |
946 |
* via /proc/ccs/ interface. |
* via /proc/ccs/ interface. |
947 |
* |
* |
948 |
* Caller holds ccs_read_lock(). |
* Caller holds ccs_read_lock(). |
949 |
*/ |
*/ |
950 |
static bool ccs_is_policy_manager(void) |
static bool ccs_manager(void) |
951 |
{ |
{ |
952 |
struct ccs_policy_manager_entry *ptr; |
struct ccs_manager *ptr; |
953 |
const char *exe; |
const char *exe; |
954 |
struct task_struct *task = current; |
struct ccs_security *task = ccs_current_security(); |
955 |
const struct ccs_path_info *domainname |
const struct ccs_path_info *domainname |
956 |
= ccs_current_domain()->domainname; |
= ccs_current_domain()->domainname; |
957 |
bool found = false; |
bool found = false; |
958 |
if (!ccs_policy_loaded) |
if (!ccs_policy_loaded) |
959 |
return true; |
return true; |
960 |
if (task->ccs_flags & CCS_TASK_IS_POLICY_MANAGER) |
if (task->ccs_flags & CCS_TASK_IS_MANAGER) |
961 |
return true; |
return true; |
962 |
if (!ccs_manage_by_non_root && (current_uid() || current_euid())) |
if (!ccs_manage_by_non_root && (current_uid() || current_euid())) |
963 |
return false; |
return false; |
|
list_for_each_entry_rcu(ptr, &ccs_policy_manager_list, list) { |
|
|
if (!ptr->is_deleted && ptr->is_domain |
|
|
&& !ccs_pathcmp(domainname, ptr->manager)) { |
|
|
/* Set manager flag. */ |
|
|
task->ccs_flags |= CCS_TASK_IS_POLICY_MANAGER; |
|
|
return true; |
|
|
} |
|
|
} |
|
964 |
exe = ccs_get_exe(); |
exe = ccs_get_exe(); |
965 |
if (!exe) |
list_for_each_entry_srcu(ptr, &ccs_kernel_namespace. |
966 |
return false; |
policy_list[CCS_ID_MANAGER], head.list, |
967 |
list_for_each_entry_rcu(ptr, &ccs_policy_manager_list, list) { |
&ccs_ss) { |
968 |
if (!ptr->is_deleted && !ptr->is_domain |
if (ptr->head.is_deleted) |
969 |
&& !strcmp(exe, ptr->manager->name)) { |
continue; |
970 |
found = true; |
if (ptr->is_domain) { |
971 |
/* Set manager flag. */ |
if (ccs_pathcmp(domainname, ptr->manager)) |
972 |
task->ccs_flags |= CCS_TASK_IS_POLICY_MANAGER; |
continue; |
973 |
break; |
} else { |
974 |
|
if (!exe || strcmp(exe, ptr->manager->name)) |
975 |
|
continue; |
976 |
} |
} |
977 |
|
/* Set manager flag. */ |
978 |
|
task->ccs_flags |= CCS_TASK_IS_MANAGER; |
979 |
|
found = true; |
980 |
|
break; |
981 |
} |
} |
982 |
if (!found) { /* Reduce error messages. */ |
if (!found) { /* Reduce error messages. */ |
983 |
static pid_t ccs_last_pid; |
static pid_t ccs_last_pid; |
993 |
} |
} |
994 |
|
|
995 |
/** |
/** |
996 |
* ccs_find_condition_part - Find condition part from the statement. |
* ccs_select_domain - Parse select command. |
|
* |
|
|
* @data: String to parse. |
|
|
* |
|
|
* Returns pointer to the condition part if it was found in the statement, |
|
|
* NULL otherwise. |
|
|
*/ |
|
|
static char *ccs_find_condition_part(char *data) |
|
|
{ |
|
|
char *cp = strstr(data, " if "); |
|
|
if (cp) { |
|
|
while (1) { |
|
|
char *cp2 = strstr(cp + 3, " if "); |
|
|
if (!cp2) |
|
|
break; |
|
|
cp = cp2; |
|
|
} |
|
|
*cp++ = '\0'; |
|
|
} else { |
|
|
cp = strstr(data, " ; set "); |
|
|
if (cp) |
|
|
*cp++ = '\0'; |
|
|
} |
|
|
return cp; |
|
|
} |
|
|
|
|
|
/** |
|
|
* ccs_is_select_one - Parse select command. |
|
997 |
* |
* |
998 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
999 |
* @data: String to parse. |
* @data: String to parse. |
1002 |
* |
* |
1003 |
* Caller holds ccs_read_lock(). |
* Caller holds ccs_read_lock(). |
1004 |
*/ |
*/ |
1005 |
static bool ccs_is_select_one(struct ccs_io_buffer *head, const char *data) |
static bool ccs_select_domain(struct ccs_io_buffer *head, const char *data) |
1006 |
{ |
{ |
1007 |
unsigned int pid; |
unsigned int pid; |
1008 |
struct ccs_domain_info *domain = NULL; |
struct ccs_domain_info *domain = NULL; |
1009 |
bool global_pid = false; |
bool global_pid = false; |
1010 |
if (!strcmp(data, "allow_execute")) { |
if (strncmp(data, "select ", 7)) |
1011 |
head->read_execute_only = true; |
return false; |
1012 |
return true; |
data += 7; |
|
} |
|
1013 |
if (sscanf(data, "pid=%u", &pid) == 1 || |
if (sscanf(data, "pid=%u", &pid) == 1 || |
1014 |
(global_pid = true, sscanf(data, "global-pid=%u", &pid) == 1)) { |
(global_pid = true, sscanf(data, "global-pid=%u", &pid) == 1)) { |
1015 |
struct task_struct *p; |
struct task_struct *p; |
1027 |
domain = ccs_task_domain(p); |
domain = ccs_task_domain(p); |
1028 |
ccs_tasklist_unlock(); |
ccs_tasklist_unlock(); |
1029 |
} else if (!strncmp(data, "domain=", 7)) { |
} else if (!strncmp(data, "domain=", 7)) { |
1030 |
if (ccs_is_domain_def(data + 7)) |
if (*(data + 7) == '<') |
1031 |
domain = ccs_find_domain(data + 7); |
domain = ccs_find_domain(data + 7); |
1032 |
} else |
} else |
1033 |
return false; |
return false; |
1034 |
head->write_var1 = domain; |
head->w.domain = domain; |
1035 |
/* Accessing read_buf is safe because head->io_sem is held. */ |
/* Accessing read_buf is safe because head->io_sem is held. */ |
1036 |
if (!head->read_buf) |
if (!head->read_buf) |
1037 |
return true; /* Do nothing if open(O_WRONLY). */ |
return true; /* Do nothing if open(O_WRONLY). */ |
1038 |
head->read_avail = 0; |
memset(&head->r, 0, sizeof(head->r)); |
1039 |
|
head->r.print_this_domain_only = true; |
1040 |
|
if (domain) |
1041 |
|
head->r.domain = &domain->list; |
1042 |
|
else |
1043 |
|
head->r.eof = true; |
1044 |
ccs_io_printf(head, "# select %s\n", data); |
ccs_io_printf(head, "# select %s\n", data); |
1045 |
head->read_single_domain = true; |
if (domain && domain->is_deleted) |
1046 |
head->read_eof = !domain; |
ccs_set_string(head, "# This is a deleted domain.\n"); |
|
if (domain) { |
|
|
struct ccs_domain_info *d; |
|
|
head->read_var1 = NULL; |
|
|
list_for_each_entry_rcu(d, &ccs_domain_list, list) { |
|
|
if (d == domain) |
|
|
break; |
|
|
head->read_var1 = &d->list; |
|
|
} |
|
|
head->read_var2 = NULL; |
|
|
head->read_bit = 0; |
|
|
head->read_step = 0; |
|
|
if (domain->is_deleted) |
|
|
ccs_io_printf(head, "# This is a deleted domain.\n"); |
|
|
} |
|
1047 |
return true; |
return true; |
1048 |
} |
} |
1049 |
|
|
|
static int ccs_write_domain_policy2(char *data, struct ccs_domain_info *domain, |
|
|
struct ccs_condition *cond, |
|
|
const bool is_delete) |
|
|
{ |
|
|
if (ccs_str_starts(&data, CCS_KEYWORD_ALLOW_CAPABILITY)) |
|
|
return ccs_write_capability_policy(data, domain, cond, |
|
|
is_delete); |
|
|
if (ccs_str_starts(&data, CCS_KEYWORD_ALLOW_NETWORK)) |
|
|
return ccs_write_network_policy(data, domain, cond, is_delete); |
|
|
if (ccs_str_starts(&data, CCS_KEYWORD_ALLOW_SIGNAL)) |
|
|
return ccs_write_signal_policy(data, domain, cond, is_delete); |
|
|
if (ccs_str_starts(&data, CCS_KEYWORD_ALLOW_ENV)) |
|
|
return ccs_write_env_policy(data, domain, cond, is_delete); |
|
|
if (ccs_str_starts(&data, CCS_KEYWORD_ALLOW_MOUNT)) |
|
|
return ccs_write_mount_policy(data, domain, cond, is_delete); |
|
|
return ccs_write_file_policy(data, domain, cond, is_delete); |
|
|
} |
|
|
|
|
|
/** |
|
|
* ccs_write_domain_policy - Write domain policy. |
|
|
* |
|
|
* @head: Pointer to "struct ccs_io_buffer". |
|
|
* |
|
|
* Returns 0 on success, negative value otherwise. |
|
|
*/ |
|
|
static int ccs_write_domain_policy(struct ccs_io_buffer *head) |
|
|
{ |
|
|
char *data = head->write_buf; |
|
|
struct ccs_domain_info *domain = head->write_var1; |
|
|
bool is_delete = false; |
|
|
bool is_select = false; |
|
|
unsigned int profile; |
|
|
struct ccs_condition *cond = NULL; |
|
|
char *cp; |
|
|
int error; |
|
|
if (ccs_str_starts(&data, CCS_KEYWORD_DELETE)) |
|
|
is_delete = true; |
|
|
else if (ccs_str_starts(&data, CCS_KEYWORD_SELECT)) |
|
|
is_select = true; |
|
|
if (is_select && ccs_is_select_one(head, data)) |
|
|
return 0; |
|
|
/* Don't allow updating policies by non manager programs. */ |
|
|
if (!ccs_is_policy_manager()) |
|
|
return -EPERM; |
|
|
if (ccs_is_domain_def(data)) { |
|
|
domain = NULL; |
|
|
if (is_delete) |
|
|
ccs_delete_domain(data); |
|
|
else if (is_select) |
|
|
domain = ccs_find_domain(data); |
|
|
else |
|
|
domain = ccs_find_or_assign_new_domain(data, 0); |
|
|
head->write_var1 = domain; |
|
|
return 0; |
|
|
} |
|
|
if (!domain) |
|
|
return -EINVAL; |
|
|
|
|
|
if (sscanf(data, CCS_KEYWORD_USE_PROFILE "%u", &profile) == 1 |
|
|
&& profile < CCS_MAX_PROFILES) { |
|
|
if (!ccs_policy_loaded || ccs_profile_ptr[(u8) profile]) |
|
|
domain->profile = (u8) profile; |
|
|
return 0; |
|
|
} |
|
|
if (!strcmp(data, CCS_KEYWORD_IGNORE_GLOBAL_ALLOW_READ)) { |
|
|
domain->ignore_global_allow_read = !is_delete; |
|
|
return 0; |
|
|
} |
|
|
if (!strcmp(data, CCS_KEYWORD_IGNORE_GLOBAL_ALLOW_ENV)) { |
|
|
domain->ignore_global_allow_env = !is_delete; |
|
|
return 0; |
|
|
} |
|
|
if (!strcmp(data, CCS_KEYWORD_QUOTA_EXCEEDED)) { |
|
|
domain->quota_warned = !is_delete; |
|
|
return 0; |
|
|
} |
|
|
if (!strcmp(data, CCS_KEYWORD_TRANSITION_FAILED)) { |
|
|
domain->domain_transition_failed = !is_delete; |
|
|
return 0; |
|
|
} |
|
|
cp = ccs_find_condition_part(data); |
|
|
if (cp) { |
|
|
cond = ccs_get_condition(cp); |
|
|
if (!cond) |
|
|
return -EINVAL; |
|
|
} |
|
|
error = ccs_write_domain_policy2(data, domain, cond, is_delete); |
|
|
if (cond) |
|
|
ccs_put_condition(cond); |
|
|
return error; |
|
|
} |
|
|
|
|
1050 |
/** |
/** |
1051 |
* ccs_print_name_union - Print a ccs_name_union. |
* ccs_same_handler_acl - Check for duplicated "struct ccs_handler_acl" entry. |
1052 |
* |
* |
1053 |
* @head: Pointer to "struct ccs_io_buffer". |
* @a: Pointer to "struct ccs_acl_info". |
1054 |
* @ptr: Pointer to "struct ccs_name_union". |
* @b: Pointer to "struct ccs_acl_info". |
1055 |
* |
* |
1056 |
* Returns true on success, false otherwise. |
* Returns true if @a == @b, false otherwise. |
1057 |
*/ |
*/ |
1058 |
static bool ccs_print_name_union(struct ccs_io_buffer *head, |
static bool ccs_same_handler_acl(const struct ccs_acl_info *a, |
1059 |
const struct ccs_name_union *ptr) |
const struct ccs_acl_info *b) |
1060 |
{ |
{ |
1061 |
int pos = head->read_avail; |
const struct ccs_handler_acl *p1 = container_of(a, typeof(*p1), head); |
1062 |
if (pos && head->read_buf[pos - 1] == ' ') |
const struct ccs_handler_acl *p2 = container_of(b, typeof(*p2), head); |
1063 |
head->read_avail--; |
return p1->handler == p2->handler; |
|
if (ptr->is_group) |
|
|
return ccs_io_printf(head, " @%s", |
|
|
ptr->group->group_name->name); |
|
|
return ccs_io_printf(head, " %s", ptr->filename->name); |
|
1064 |
} |
} |
1065 |
|
|
1066 |
/** |
/** |
1067 |
* ccs_print_name_union_quoted - Print a ccs_name_union with double quotes. |
* ccs_same_task_acl - Check for duplicated "struct ccs_task_acl" entry. |
1068 |
* |
* |
1069 |
* @head: Pointer to "struct ccs_io_buffer". |
* @a: Pointer to "struct ccs_acl_info". |
1070 |
* @ptr: Pointer to "struct ccs_name_union". |
* @b: Pointer to "struct ccs_acl_info". |
1071 |
* |
* |
1072 |
* Returns true on success, false otherwise. |
* Returns true if @a == @b, false otherwise. |
1073 |
*/ |
*/ |
1074 |
static bool ccs_print_name_union_quoted(struct ccs_io_buffer *head, |
static bool ccs_same_task_acl(const struct ccs_acl_info *a, |
1075 |
const struct ccs_name_union *ptr) |
const struct ccs_acl_info *b) |
1076 |
{ |
{ |
1077 |
if (ptr->is_group) |
const struct ccs_task_acl *p1 = container_of(a, typeof(*p1), head); |
1078 |
return ccs_io_printf(head, "@%s", |
const struct ccs_task_acl *p2 = container_of(b, typeof(*p2), head); |
1079 |
ptr->group->group_name->name); |
return p1->domainname == p2->domainname; |
|
return ccs_io_printf(head, "\"%s\"", ptr->filename->name); |
|
1080 |
} |
} |
1081 |
|
|
1082 |
/** |
/** |
1083 |
* ccs_print_number_union_common - Print a ccs_number_union. |
* ccs_write_task - Update task related list. |
|
* |
|
|
* @head: Pointer to "struct ccs_io_buffer". |
|
|
* @ptr: Pointer to "struct ccs_number_union". |
|
|
* @need_space: True if a space character is needed. |
|
1084 |
* |
* |
1085 |
* Returns true on success, false otherwise. |
* @param: Pointer to "struct ccs_acl_param". |
|
*/ |
|
|
static bool ccs_print_number_union_common(struct ccs_io_buffer *head, |
|
|
const struct ccs_number_union *ptr, |
|
|
const bool need_space) |
|
|
{ |
|
|
unsigned long min; |
|
|
unsigned long max; |
|
|
u8 min_type; |
|
|
u8 max_type; |
|
|
if (need_space && !ccs_io_printf(head, " ")) |
|
|
return false; |
|
|
if (ptr->is_group) |
|
|
return ccs_io_printf(head, "@%s", |
|
|
ptr->group->group_name->name); |
|
|
min_type = ptr->min_type; |
|
|
max_type = ptr->max_type; |
|
|
min = ptr->values[0]; |
|
|
max = ptr->values[1]; |
|
|
switch (min_type) { |
|
|
case CCS_VALUE_TYPE_HEXADECIMAL: |
|
|
if (!ccs_io_printf(head, "0x%lX", min)) |
|
|
return false; |
|
|
break; |
|
|
case CCS_VALUE_TYPE_OCTAL: |
|
|
if (!ccs_io_printf(head, "0%lo", min)) |
|
|
return false; |
|
|
break; |
|
|
default: |
|
|
if (!ccs_io_printf(head, "%lu", min)) |
|
|
return false; |
|
|
break; |
|
|
} |
|
|
if (min == max && min_type == max_type) |
|
|
return true; |
|
|
switch (max_type) { |
|
|
case CCS_VALUE_TYPE_HEXADECIMAL: |
|
|
return ccs_io_printf(head, "-0x%lX", max); |
|
|
case CCS_VALUE_TYPE_OCTAL: |
|
|
return ccs_io_printf(head, "-0%lo", max); |
|
|
default: |
|
|
return ccs_io_printf(head, "-%lu", max); |
|
|
} |
|
|
} |
|
|
|
|
|
/** |
|
|
* ccs_print_number_union - Print a ccs_number_union. |
|
1086 |
* |
* |
1087 |
* @head: Pointer to "struct ccs_io_buffer". |
* Returns 0 on success, negative value otherwise. |
|
* @ptr: Pointer to "struct ccs_number_union". |
|
1088 |
* |
* |
1089 |
* Returns true on success, false otherwise. |
* Caller holds ccs_read_lock(). |
1090 |
*/ |
*/ |
1091 |
bool ccs_print_number_union(struct ccs_io_buffer *head, |
static int ccs_write_task(struct ccs_acl_param *param) |
|
const struct ccs_number_union *ptr) |
|
1092 |
{ |
{ |
1093 |
return ccs_print_number_union_common(head, ptr, true); |
int error; |
1094 |
|
const bool is_auto = ccs_str_starts(¶m->data, |
1095 |
|
"auto_domain_transition "); |
1096 |
|
if (!is_auto && !ccs_str_starts(¶m->data, |
1097 |
|
"manual_domain_transition ")) { |
1098 |
|
struct ccs_handler_acl e = { }; |
1099 |
|
char *handler; |
1100 |
|
if (ccs_str_starts(¶m->data, "auto_execute_handler ")) |
1101 |
|
e.head.type = CCS_TYPE_AUTO_EXECUTE_HANDLER; |
1102 |
|
else if (ccs_str_starts(¶m->data, |
1103 |
|
"denied_execute_handler ")) |
1104 |
|
e.head.type = CCS_TYPE_DENIED_EXECUTE_HANDLER; |
1105 |
|
else |
1106 |
|
return -EINVAL; |
1107 |
|
handler = ccs_read_token(param); |
1108 |
|
if (!ccs_correct_path(handler)) |
1109 |
|
return -EINVAL; |
1110 |
|
e.handler = ccs_get_name(handler); |
1111 |
|
if (!e.handler) |
1112 |
|
return -ENOMEM; |
1113 |
|
if (e.handler->is_patterned) |
1114 |
|
error = -EINVAL; /* No patterns allowed. */ |
1115 |
|
else |
1116 |
|
error = ccs_update_domain(&e.head, sizeof(e), param, |
1117 |
|
ccs_same_handler_acl, NULL); |
1118 |
|
ccs_put_name(e.handler); |
1119 |
|
} else { |
1120 |
|
struct ccs_task_acl e = { |
1121 |
|
.head.type = is_auto ? |
1122 |
|
CCS_TYPE_AUTO_TASK_ACL : CCS_TYPE_MANUAL_TASK_ACL, |
1123 |
|
.domainname = ccs_get_domainname(param), |
1124 |
|
}; |
1125 |
|
if (!e.domainname) |
1126 |
|
error = -EINVAL; |
1127 |
|
else |
1128 |
|
error = ccs_update_domain(&e.head, sizeof(e), param, |
1129 |
|
ccs_same_task_acl, NULL); |
1130 |
|
ccs_put_name(e.domainname); |
1131 |
|
} |
1132 |
|
return error; |
1133 |
} |
} |
1134 |
|
|
1135 |
/** |
/** |
1136 |
* ccs_print_number_union_nospace - Print a ccs_number_union without a space character. |
* ccs_write_domain2 - Write domain policy. |
1137 |
* |
* |
1138 |
* @head: Pointer to "struct ccs_io_buffer". |
* @ns: Pointer to "struct ccs_policy_namespace". |
1139 |
* @ptr: Pointer to "struct ccs_number_union". |
* @list: Pointer to "struct list_head". |
1140 |
* |
* @data: Policy to be interpreted. |
1141 |
* Returns true on success, false otherwise. |
* @is_delete: True if it is a delete request. |
|
*/ |
|
|
static bool ccs_print_number_union_nospace(struct ccs_io_buffer *head, |
|
|
const struct ccs_number_union *ptr) |
|
|
{ |
|
|
return ccs_print_number_union_common(head, ptr, false); |
|
|
} |
|
|
|
|
|
/** |
|
|
* ccs_print_condition - Print condition part. |
|
1142 |
* |
* |
1143 |
* @head: Pointer to "struct ccs_io_buffer". |
* Returns 0 on success, negative value otherwise. |
|
* @cond: Pointer to "struct ccs_condition". May be NULL. |
|
1144 |
* |
* |
1145 |
* Returns true on success, false otherwise. |
* Caller holds ccs_read_lock(). |
1146 |
*/ |
*/ |
1147 |
static bool ccs_print_condition(struct ccs_io_buffer *head, |
static int ccs_write_domain2(struct ccs_policy_namespace *ns, |
1148 |
const struct ccs_condition *cond) |
struct list_head *list, char *data, |
1149 |
{ |
const bool is_delete) |
1150 |
const struct ccs_condition_element *condp; |
{ |
1151 |
const struct ccs_number_union *numbers_p; |
struct ccs_acl_param param = { |
1152 |
const struct ccs_name_union *names_p; |
.ns = ns, |
1153 |
const struct ccs_argv_entry *argv; |
.list = list, |
1154 |
const struct ccs_envp_entry *envp; |
.data = data, |
1155 |
u16 condc; |
.is_delete = is_delete, |
1156 |
u16 i; |
}; |
1157 |
u16 j; |
static const struct { |
1158 |
char buffer[32]; |
const char *keyword; |
1159 |
if (!cond) |
int (*write) (struct ccs_acl_param *); |
1160 |
goto no_condition; |
} ccs_callback[7] = { |
1161 |
condc = cond->condc; |
{ "file ", ccs_write_file }, |
1162 |
condp = (const struct ccs_condition_element *) (cond + 1); |
{ "network inet ", ccs_write_inet_network }, |
1163 |
numbers_p = (const struct ccs_number_union *) (condp + condc); |
{ "network unix ", ccs_write_unix_network }, |
1164 |
names_p = (const struct ccs_name_union *) |
{ "misc ", ccs_write_misc }, |
1165 |
(numbers_p + cond->numbers_count); |
{ "capability ", ccs_write_capability }, |
1166 |
argv = (const struct ccs_argv_entry *) (names_p + cond->names_count); |
{ "ipc signal ", ccs_write_ipc }, |
1167 |
envp = (const struct ccs_envp_entry *) (argv + cond->argc); |
{ "task ", ccs_write_task }, |
1168 |
memset(buffer, 0, sizeof(buffer)); |
}; |
1169 |
if (condc && !ccs_io_printf(head, "%s", " if")) |
u8 i; |
1170 |
goto out; |
for (i = 0; i < 7; i++) { |
1171 |
for (i = 0; i < condc; i++) { |
if (!ccs_str_starts(¶m.data, ccs_callback[i].keyword)) |
|
const u8 match = condp->equals; |
|
|
const u8 left = condp->left; |
|
|
const u8 right = condp->right; |
|
|
condp++; |
|
|
switch (left) { |
|
|
case CCS_ARGV_ENTRY: |
|
|
if (!ccs_io_printf(head, " exec.argv[%u]%s\"%s\"", |
|
|
argv->index, argv->is_not ? |
|
|
"!=" : "=", argv->value->name)) |
|
|
goto out; |
|
|
argv++; |
|
|
continue; |
|
|
case CCS_ENVP_ENTRY: |
|
|
if (!ccs_io_printf(head, " exec.envp[\"%s\"]%s", |
|
|
envp->name->name, envp->is_not ? |
|
|
"!=" : "=")) |
|
|
goto out; |
|
|
if (envp->value) { |
|
|
if (!ccs_io_printf(head, "\"%s\"", |
|
|
envp->value->name)) |
|
|
goto out; |
|
|
} else { |
|
|
if (!ccs_io_printf(head, "NULL")) |
|
|
goto out; |
|
|
} |
|
|
envp++; |
|
|
continue; |
|
|
case CCS_NUMBER_UNION: |
|
|
if (!ccs_print_number_union(head, numbers_p++)) |
|
|
goto out; |
|
|
break; |
|
|
default: |
|
|
if (left >= CCS_MAX_CONDITION_KEYWORD) |
|
|
goto out; |
|
|
if (!ccs_io_printf(head, " %s", |
|
|
ccs_condition_keyword[left])) |
|
|
goto out; |
|
|
break; |
|
|
} |
|
|
if (!ccs_io_printf(head, "%s", match ? "=" : "!=")) |
|
|
goto out; |
|
|
switch (right) { |
|
|
case CCS_NAME_UNION: |
|
|
if (!ccs_print_name_union_quoted(head, names_p++)) |
|
|
goto out; |
|
|
break; |
|
|
case CCS_NUMBER_UNION: |
|
|
if (!ccs_print_number_union_nospace(head, numbers_p++)) |
|
|
goto out; |
|
|
break; |
|
|
default: |
|
|
if (right >= CCS_MAX_CONDITION_KEYWORD) |
|
|
goto out; |
|
|
if (!ccs_io_printf(head, "%s", |
|
|
ccs_condition_keyword[right])) |
|
|
goto out; |
|
|
break; |
|
|
} |
|
|
} |
|
|
i = cond->post_state[3]; |
|
|
if (!i) |
|
|
goto no_condition; |
|
|
if (!ccs_io_printf(head, " ; set")) |
|
|
goto out; |
|
|
for (j = 0; j < 3; j++) { |
|
|
if (!(i & (1 << j))) |
|
1172 |
continue; |
continue; |
1173 |
if (!ccs_io_printf(head, " task.state[%u]=%u", j, |
return ccs_callback[i].write(¶m); |
|
cond->post_state[j])) |
|
|
goto out; |
|
1174 |
} |
} |
1175 |
no_condition: |
return -EINVAL; |
|
if (ccs_io_printf(head, "\n")) |
|
|
return true; |
|
|
out: |
|
|
return false; |
|
1176 |
} |
} |
1177 |
|
|
1178 |
/** |
/** |
1179 |
* ccs_print_path_acl - Print a path ACL entry. |
* ccs_delete_domain - Delete a domain. |
1180 |
* |
* |
1181 |
* @head: Pointer to "struct ccs_io_buffer". |
* @domainname: The name of domain. |
|
* @ptr: Pointer to "struct ccs_path_acl". |
|
|
* @cond: Pointer to "struct ccs_condition". May be NULL. |
|
1182 |
* |
* |
1183 |
* Returns true on success, false otherwise. |
* Returns 0. |
1184 |
*/ |
*/ |
1185 |
static bool ccs_print_path_acl(struct ccs_io_buffer *head, |
static int ccs_delete_domain(char *domainname) |
|
struct ccs_path_acl *ptr, |
|
|
const struct ccs_condition *cond) |
|
1186 |
{ |
{ |
1187 |
int pos; |
struct ccs_domain_info *domain; |
1188 |
u8 bit; |
struct ccs_path_info name; |
1189 |
const u16 perm = ptr->perm; |
name.name = domainname; |
1190 |
for (bit = head->read_bit; bit < CCS_MAX_PATH_OPERATION; bit++) { |
ccs_fill_path_info(&name); |
1191 |
if (!(perm & (1 << bit))) |
if (mutex_lock_interruptible(&ccs_policy_lock)) |
1192 |
continue; |
return 0; |
1193 |
if (head->read_execute_only && bit != CCS_TYPE_EXECUTE |
/* Is there an active domain? */ |
1194 |
&& bit != CCS_TYPE_TRANSIT) |
list_for_each_entry_srcu(domain, &ccs_domain_list, list, &ccs_ss) { |
1195 |
|
/* Never delete ccs_kernel_domain. */ |
1196 |
|
if (domain == &ccs_kernel_domain) |
1197 |
continue; |
continue; |
1198 |
/* Print "read/write" instead of "read" and "write". */ |
if (domain->is_deleted || |
1199 |
if ((bit == CCS_TYPE_READ || bit == CCS_TYPE_WRITE) |
ccs_pathcmp(domain->domainname, &name)) |
|
&& (perm & (1 << CCS_TYPE_READ_WRITE))) |
|
1200 |
continue; |
continue; |
1201 |
pos = head->read_avail; |
domain->is_deleted = true; |
1202 |
if (!ccs_io_printf(head, "allow_%s", ccs_path2keyword(bit)) || |
break; |
|
!ccs_print_name_union(head, &ptr->name) || |
|
|
!ccs_print_condition(head, cond)) { |
|
|
head->read_bit = bit; |
|
|
head->read_avail = pos; |
|
|
return false; |
|
|
} |
|
1203 |
} |
} |
1204 |
head->read_bit = 0; |
mutex_unlock(&ccs_policy_lock); |
1205 |
return true; |
return 0; |
1206 |
} |
} |
1207 |
|
|
1208 |
/** |
/* String table for domain flags. */ |
1209 |
* ccs_print_path_number3_acl - Print a path_number3 ACL entry. |
const char * const ccs_dif[CCS_MAX_DOMAIN_INFO_FLAGS] = { |
1210 |
* |
[CCS_DIF_QUOTA_WARNED] = "quota_exceeded\n", |
1211 |
* @head: Pointer to "struct ccs_io_buffer". |
[CCS_DIF_TRANSITION_FAILED] = "transition_failed\n", |
1212 |
* @ptr: Pointer to "struct ccs_path_number3_acl". |
}; |
|
* @cond: Pointer to "struct ccs_condition". May be NULL. |
|
|
* |
|
|
* Returns true on success, false otherwise. |
|
|
*/ |
|
|
static bool ccs_print_path_number3_acl(struct ccs_io_buffer *head, |
|
|
struct ccs_path_number3_acl *ptr, |
|
|
const struct ccs_condition *cond) |
|
|
{ |
|
|
int pos; |
|
|
u8 bit; |
|
|
const u16 perm = ptr->perm; |
|
|
for (bit = head->read_bit; bit < CCS_MAX_PATH_NUMBER3_OPERATION; |
|
|
bit++) { |
|
|
if (!(perm & (1 << bit))) |
|
|
continue; |
|
|
pos = head->read_avail; |
|
|
if (!ccs_io_printf(head, "allow_%s", |
|
|
ccs_path_number32keyword(bit)) || |
|
|
!ccs_print_name_union(head, &ptr->name) || |
|
|
!ccs_print_number_union(head, &ptr->mode) || |
|
|
!ccs_print_number_union(head, &ptr->major) || |
|
|
!ccs_print_number_union(head, &ptr->minor) || |
|
|
!ccs_print_condition(head, cond)) { |
|
|
head->read_bit = bit; |
|
|
head->read_avail = pos; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
head->read_bit = 0; |
|
|
return true; |
|
|
} |
|
1213 |
|
|
1214 |
/** |
/** |
1215 |
* ccs_print_path2_acl - Print a path2 ACL entry. |
* ccs_write_domain - Write domain policy. |
1216 |
* |
* |
1217 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
|
* @ptr: Pointer to "struct ccs_path2_acl". |
|
|
* @cond: Pointer to "struct ccs_condition". May be NULL. |
|
|
* |
|
|
* Returns true on success, false otherwise. |
|
|
*/ |
|
|
static bool ccs_print_path2_acl(struct ccs_io_buffer *head, |
|
|
struct ccs_path2_acl *ptr, |
|
|
const struct ccs_condition *cond) |
|
|
{ |
|
|
int pos; |
|
|
u8 bit; |
|
|
const u8 perm = ptr->perm; |
|
|
for (bit = head->read_bit; bit < CCS_MAX_PATH2_OPERATION; bit++) { |
|
|
if (!(perm & (1 << bit))) |
|
|
continue; |
|
|
pos = head->read_avail; |
|
|
if (!ccs_io_printf(head, "allow_%s", |
|
|
ccs_path22keyword(bit)) || |
|
|
!ccs_print_name_union(head, &ptr->name1) || |
|
|
!ccs_print_name_union(head, &ptr->name2) || |
|
|
!ccs_print_condition(head, cond)) { |
|
|
head->read_bit = bit; |
|
|
head->read_avail = pos; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
head->read_bit = 0; |
|
|
return true; |
|
|
} |
|
|
|
|
|
/** |
|
|
* ccs_print_path_number_acl - Print a path_number ACL entry. |
|
1218 |
* |
* |
1219 |
* @head: Pointer to "struct ccs_io_buffer". |
* Returns 0 on success, negative value otherwise. |
|
* @ptr: Pointer to "struct ccs_path_number_acl". |
|
|
* @cond: Pointer to "struct ccs_condition". May be NULL. |
|
1220 |
* |
* |
1221 |
* Returns true on success, false otherwise. |
* Caller holds ccs_read_lock(). |
1222 |
*/ |
*/ |
1223 |
static bool ccs_print_path_number_acl(struct ccs_io_buffer *head, |
static int ccs_write_domain(struct ccs_io_buffer *head) |
|
struct ccs_path_number_acl *ptr, |
|
|
const struct ccs_condition *cond) |
|
1224 |
{ |
{ |
1225 |
int pos; |
char *data = head->write_buf; |
1226 |
u8 bit; |
struct ccs_policy_namespace *ns; |
1227 |
const u8 perm = ptr->perm; |
struct ccs_domain_info *domain = head->w.domain; |
1228 |
for (bit = head->read_bit; bit < CCS_MAX_PATH_NUMBER_OPERATION; |
const bool is_delete = head->w.is_delete; |
1229 |
bit++) { |
const bool is_select = !is_delete && ccs_str_starts(&data, "select "); |
1230 |
if (!(perm & (1 << bit))) |
unsigned int profile; |
1231 |
|
if (*data == '<') { |
1232 |
|
domain = NULL; |
1233 |
|
if (is_delete) |
1234 |
|
ccs_delete_domain(data); |
1235 |
|
else if (is_select) |
1236 |
|
domain = ccs_find_domain(data); |
1237 |
|
else |
1238 |
|
domain = ccs_assign_domain(data, false); |
1239 |
|
head->w.domain = domain; |
1240 |
|
return 0; |
1241 |
|
} |
1242 |
|
if (!domain) |
1243 |
|
return -EINVAL; |
1244 |
|
ns = domain->ns; |
1245 |
|
if (sscanf(data, "use_profile %u\n", &profile) == 1 |
1246 |
|
&& profile < CCS_MAX_PROFILES) { |
1247 |
|
if (!ccs_policy_loaded || ns->profile_ptr[(u8) profile]) |
1248 |
|
if (!is_delete) |
1249 |
|
domain->profile = (u8) profile; |
1250 |
|
return 0; |
1251 |
|
} |
1252 |
|
if (sscanf(data, "use_group %u\n", &profile) == 1 |
1253 |
|
&& profile < CCS_MAX_ACL_GROUPS) { |
1254 |
|
if (!is_delete) |
1255 |
|
domain->group = (u8) profile; |
1256 |
|
return 0; |
1257 |
|
} |
1258 |
|
for (profile = 0; profile < CCS_MAX_DOMAIN_INFO_FLAGS; profile++) { |
1259 |
|
const char *cp = ccs_dif[profile]; |
1260 |
|
if (strncmp(data, cp, strlen(cp) - 1)) |
1261 |
continue; |
continue; |
1262 |
pos = head->read_avail; |
domain->flags[profile] = !is_delete; |
1263 |
if (!ccs_io_printf(head, "allow_%s", |
return 0; |
|
ccs_path_number2keyword(bit)) || |
|
|
!ccs_print_name_union(head, &ptr->name) || |
|
|
!ccs_print_number_union(head, &ptr->number) || |
|
|
!ccs_print_condition(head, cond)) { |
|
|
head->read_bit = bit; |
|
|
head->read_avail = pos; |
|
|
return false; |
|
|
} |
|
1264 |
} |
} |
1265 |
head->read_bit = 0; |
return ccs_write_domain2(ns, &domain->acl_info_list, data, is_delete); |
|
return true; |
|
1266 |
} |
} |
1267 |
|
|
1268 |
/** |
/** |
1269 |
* ccs_print_env_acl - Print an evironment variable name's ACL entry. |
* ccs_print_name_union - Print a ccs_name_union. |
1270 |
* |
* |
1271 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1272 |
* @ptr: Pointer to "struct ccs_env_acl". |
* @ptr: Pointer to "struct ccs_name_union". |
|
* @cond: Pointer to "struct ccs_condition". May be NULL. |
|
1273 |
* |
* |
1274 |
* Returns true on success, false otherwise. |
* Returns nothing. |
1275 |
*/ |
*/ |
1276 |
static bool ccs_print_env_acl(struct ccs_io_buffer *head, |
static void ccs_print_name_union(struct ccs_io_buffer *head, |
1277 |
struct ccs_env_acl *ptr, |
const struct ccs_name_union *ptr) |
1278 |
const struct ccs_condition *cond) |
{ |
1279 |
{ |
ccs_set_space(head); |
1280 |
const int pos = head->read_avail; |
if (ptr->group) { |
1281 |
if (!ccs_io_printf(head, CCS_KEYWORD_ALLOW_ENV "%s", ptr->env->name) || |
ccs_set_string(head, "@"); |
1282 |
!ccs_print_condition(head, cond)) { |
ccs_set_string(head, ptr->group->group_name->name); |
1283 |
head->read_avail = pos; |
} else { |
1284 |
return false; |
ccs_set_string(head, ptr->filename->name); |
1285 |
} |
} |
|
return true; |
|
1286 |
} |
} |
1287 |
|
|
1288 |
/** |
/** |
1289 |
* ccs_print_capability_acl - Print a capability ACL entry. |
* ccs_print_name_union_quoted - Print a ccs_name_union with a quote. |
1290 |
* |
* |
1291 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1292 |
* @ptr: Pointer to "struct ccs_capability_acl". |
* @ptr: Pointer to "struct ccs_name_union". |
|
* @cond: Pointer to "struct ccs_condition". May be NULL. |
|
1293 |
* |
* |
1294 |
* Returns true on success, false otherwise. |
* Returns nothing. |
1295 |
*/ |
*/ |
1296 |
static bool ccs_print_capability_acl(struct ccs_io_buffer *head, |
static void ccs_print_name_union_quoted(struct ccs_io_buffer *head, |
1297 |
struct ccs_capability_acl *ptr, |
const struct ccs_name_union *ptr) |
1298 |
const struct ccs_condition *cond) |
{ |
1299 |
{ |
if (ptr->group) { |
1300 |
const int pos = head->read_avail; |
ccs_set_string(head, "@"); |
1301 |
if (!ccs_io_printf(head, CCS_KEYWORD_ALLOW_CAPABILITY "%s", |
ccs_set_string(head, ptr->group->group_name->name); |
1302 |
ccs_cap2keyword(ptr->operation)) || |
} else { |
1303 |
!ccs_print_condition(head, cond)) { |
ccs_set_string(head, "\""); |
1304 |
head->read_avail = pos; |
ccs_set_string(head, ptr->filename->name); |
1305 |
return false; |
ccs_set_string(head, "\""); |
1306 |
} |
} |
|
return true; |
|
1307 |
} |
} |
1308 |
|
|
1309 |
/** |
/** |
1310 |
* ccs_print_ipv4_entry - Print IPv4 address of a network ACL entry. |
* ccs_print_number_union_nospace - Print a ccs_number_union without a space. |
1311 |
* |
* |
1312 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1313 |
* @ptr: Pointer to "struct ccs_ip_network_acl". |
* @ptr: Pointer to "struct ccs_number_union". |
1314 |
* |
* |
1315 |
* Returns true on success, false otherwise. |
* Returns nothing. |
1316 |
*/ |
*/ |
1317 |
static bool ccs_print_ipv4_entry(struct ccs_io_buffer *head, |
static void ccs_print_number_union_nospace(struct ccs_io_buffer *head, |
1318 |
struct ccs_ip_network_acl *ptr) |
const struct ccs_number_union *ptr) |
1319 |
{ |
{ |
1320 |
const u32 min_address = ptr->address.ipv4.min; |
if (ptr->group) { |
1321 |
const u32 max_address = ptr->address.ipv4.max; |
ccs_set_string(head, "@"); |
1322 |
if (!ccs_io_printf(head, "%u.%u.%u.%u", HIPQUAD(min_address))) |
ccs_set_string(head, ptr->group->group_name->name); |
1323 |
return false; |
} else { |
1324 |
if (min_address != max_address |
int i; |
1325 |
&& !ccs_io_printf(head, "-%u.%u.%u.%u", HIPQUAD(max_address))) |
unsigned long min = ptr->values[0]; |
1326 |
return false; |
const unsigned long max = ptr->values[1]; |
1327 |
return true; |
u8 min_type = ptr->value_type[0]; |
1328 |
|
const u8 max_type = ptr->value_type[1]; |
1329 |
|
char buffer[128]; |
1330 |
|
buffer[0] = '\0'; |
1331 |
|
for (i = 0; i < 2; i++) { |
1332 |
|
switch (min_type) { |
1333 |
|
case CCS_VALUE_TYPE_HEXADECIMAL: |
1334 |
|
ccs_addprintf(buffer, sizeof(buffer), "0x%lX", |
1335 |
|
min); |
1336 |
|
break; |
1337 |
|
case CCS_VALUE_TYPE_OCTAL: |
1338 |
|
ccs_addprintf(buffer, sizeof(buffer), "0%lo", |
1339 |
|
min); |
1340 |
|
break; |
1341 |
|
default: |
1342 |
|
ccs_addprintf(buffer, sizeof(buffer), "%lu", |
1343 |
|
min); |
1344 |
|
break; |
1345 |
|
} |
1346 |
|
if (min == max && min_type == max_type) |
1347 |
|
break; |
1348 |
|
ccs_addprintf(buffer, sizeof(buffer), "-"); |
1349 |
|
min_type = max_type; |
1350 |
|
min = max; |
1351 |
|
} |
1352 |
|
ccs_io_printf(head, "%s", buffer); |
1353 |
|
} |
1354 |
} |
} |
1355 |
|
|
1356 |
/** |
/** |
1357 |
* ccs_print_ipv6_entry - Print IPv6 address of a network ACL entry. |
* ccs_print_number_union - Print a ccs_number_union. |
1358 |
* |
* |
1359 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1360 |
* @ptr: Pointer to "struct ccs_ip_network_acl". |
* @ptr: Pointer to "struct ccs_number_union". |
1361 |
* |
* |
1362 |
* Returns true on success, false otherwise. |
* Returns nothing. |
1363 |
*/ |
*/ |
1364 |
static bool ccs_print_ipv6_entry(struct ccs_io_buffer *head, |
static void ccs_print_number_union(struct ccs_io_buffer *head, |
1365 |
struct ccs_ip_network_acl *ptr) |
const struct ccs_number_union *ptr) |
1366 |
{ |
{ |
1367 |
char buf[64]; |
ccs_set_space(head); |
1368 |
const struct in6_addr *min_address = ptr->address.ipv6.min; |
ccs_print_number_union_nospace(head, ptr); |
|
const struct in6_addr *max_address = ptr->address.ipv6.max; |
|
|
ccs_print_ipv6(buf, sizeof(buf), min_address); |
|
|
if (!ccs_io_printf(head, "%s", buf)) |
|
|
return false; |
|
|
if (min_address != max_address) { |
|
|
ccs_print_ipv6(buf, sizeof(buf), max_address); |
|
|
if (!ccs_io_printf(head, "-%s", buf)) |
|
|
return false; |
|
|
} |
|
|
return true; |
|
1369 |
} |
} |
1370 |
|
|
1371 |
/** |
/** |
1372 |
* ccs_print_network_acl - Print a network ACL entry. |
* ccs_print_condition - Print condition part. |
1373 |
* |
* |
1374 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1375 |
* @ptr: Pointer to "struct ccs_ip_network_acl". |
* @cond: Pointer to "struct ccs_condition". |
|
* @cond: Pointer to "struct ccs_condition". May be NULL. |
|
1376 |
* |
* |
1377 |
* Returns true on success, false otherwise. |
* Returns true on success, false otherwise. |
1378 |
*/ |
*/ |
1379 |
static bool ccs_print_network_acl(struct ccs_io_buffer *head, |
static bool ccs_print_condition(struct ccs_io_buffer *head, |
1380 |
struct ccs_ip_network_acl *ptr, |
const struct ccs_condition *cond) |
|
const struct ccs_condition *cond) |
|
1381 |
{ |
{ |
1382 |
int pos; |
switch (head->r.cond_step) { |
1383 |
u8 bit; |
case 0: |
1384 |
const u16 perm = ptr->perm; |
head->r.cond_index = 0; |
1385 |
for (bit = head->read_bit; bit < CCS_MAX_NETWORK_OPERATION; bit++) { |
head->r.cond_step++; |
1386 |
if (!(perm & (1 << bit))) |
/* fall through */ |
1387 |
continue; |
case 1: |
1388 |
pos = head->read_avail; |
{ |
1389 |
if (!ccs_io_printf(head, CCS_KEYWORD_ALLOW_NETWORK "%s ", |
const u16 condc = cond->condc; |
1390 |
ccs_net2keyword(bit))) |
const struct ccs_condition_element *condp = |
1391 |
goto out; |
(typeof(condp)) (cond + 1); |
1392 |
switch (ptr->address_type) { |
const struct ccs_number_union *numbers_p = |
1393 |
case CCS_IP_ADDRESS_TYPE_ADDRESS_GROUP: |
(typeof(numbers_p)) (condp + condc); |
1394 |
if (!ccs_io_printf(head, "@%s", ptr->address.group-> |
const struct ccs_name_union *names_p = |
1395 |
group_name->name)) |
(typeof(names_p)) |
1396 |
goto out; |
(numbers_p + cond->numbers_count); |
1397 |
break; |
const struct ccs_argv *argv = |
1398 |
case CCS_IP_ADDRESS_TYPE_IPv4: |
(typeof(argv)) (names_p + cond->names_count); |
1399 |
if (!ccs_print_ipv4_entry(head, ptr)) |
const struct ccs_envp *envp = |
1400 |
goto out; |
(typeof(envp)) (argv + cond->argc); |
1401 |
break; |
u16 skip; |
1402 |
case CCS_IP_ADDRESS_TYPE_IPv6: |
for (skip = 0; skip < head->r.cond_index; skip++) { |
1403 |
if (!ccs_print_ipv6_entry(head, ptr)) |
const u8 left = condp->left; |
1404 |
goto out; |
const u8 right = condp->right; |
1405 |
|
condp++; |
1406 |
|
switch (left) { |
1407 |
|
case CCS_ARGV_ENTRY: |
1408 |
|
argv++; |
1409 |
|
continue; |
1410 |
|
case CCS_ENVP_ENTRY: |
1411 |
|
envp++; |
1412 |
|
continue; |
1413 |
|
case CCS_NUMBER_UNION: |
1414 |
|
numbers_p++; |
1415 |
|
break; |
1416 |
|
} |
1417 |
|
switch (right) { |
1418 |
|
case CCS_NAME_UNION: |
1419 |
|
names_p++; |
1420 |
|
break; |
1421 |
|
case CCS_NUMBER_UNION: |
1422 |
|
numbers_p++; |
1423 |
|
break; |
1424 |
|
} |
1425 |
|
} |
1426 |
|
while (head->r.cond_index < condc) { |
1427 |
|
const u8 match = condp->equals; |
1428 |
|
const u8 left = condp->left; |
1429 |
|
const u8 right = condp->right; |
1430 |
|
if (!ccs_flush(head)) |
1431 |
|
return false; |
1432 |
|
condp++; |
1433 |
|
head->r.cond_index++; |
1434 |
|
ccs_set_space(head); |
1435 |
|
switch (left) { |
1436 |
|
case CCS_ARGV_ENTRY: |
1437 |
|
ccs_io_printf(head, |
1438 |
|
"exec.argv[%lu]%s=\"", |
1439 |
|
argv->index, |
1440 |
|
argv->is_not ? "!" : ""); |
1441 |
|
ccs_set_string(head, |
1442 |
|
argv->value->name); |
1443 |
|
ccs_set_string(head, "\""); |
1444 |
|
argv++; |
1445 |
|
continue; |
1446 |
|
case CCS_ENVP_ENTRY: |
1447 |
|
ccs_set_string(head, "exec.envp[\""); |
1448 |
|
ccs_set_string(head, envp->name->name); |
1449 |
|
ccs_io_printf(head, "\"]%s=", |
1450 |
|
envp->is_not ? "!" : ""); |
1451 |
|
if (envp->value) { |
1452 |
|
ccs_set_string(head, "\""); |
1453 |
|
ccs_set_string(head, envp-> |
1454 |
|
value->name); |
1455 |
|
ccs_set_string(head, "\""); |
1456 |
|
} else { |
1457 |
|
ccs_set_string(head, "NULL"); |
1458 |
|
} |
1459 |
|
envp++; |
1460 |
|
continue; |
1461 |
|
case CCS_NUMBER_UNION: |
1462 |
|
ccs_print_number_union_nospace |
1463 |
|
(head, numbers_p++); |
1464 |
|
break; |
1465 |
|
default: |
1466 |
|
ccs_set_string(head, |
1467 |
|
ccs_condition_keyword[left]); |
1468 |
|
break; |
1469 |
|
} |
1470 |
|
ccs_set_string(head, match ? "=" : "!="); |
1471 |
|
switch (right) { |
1472 |
|
case CCS_NAME_UNION: |
1473 |
|
ccs_print_name_union_quoted |
1474 |
|
(head, names_p++); |
1475 |
|
break; |
1476 |
|
case CCS_NUMBER_UNION: |
1477 |
|
ccs_print_number_union_nospace |
1478 |
|
(head, numbers_p++); |
1479 |
|
break; |
1480 |
|
default: |
1481 |
|
ccs_set_string(head, |
1482 |
|
ccs_condition_keyword[right]); |
1483 |
|
break; |
1484 |
|
} |
1485 |
|
} |
1486 |
|
} |
1487 |
|
head->r.cond_step++; |
1488 |
|
/* fall through */ |
1489 |
|
case 2: |
1490 |
|
if (!ccs_flush(head)) |
1491 |
break; |
break; |
1492 |
|
head->r.cond_step++; |
1493 |
|
/* fall through */ |
1494 |
|
case 3: |
1495 |
|
if (cond->grant_log != CCS_GRANTLOG_AUTO) |
1496 |
|
ccs_io_printf(head, " grant_log=%s", |
1497 |
|
ccs_yesno(cond->grant_log == |
1498 |
|
CCS_GRANTLOG_YES)); |
1499 |
|
if (cond->transit) { |
1500 |
|
const char *name = cond->transit->name; |
1501 |
|
ccs_set_string(head, " auto_domain_transition=\""); |
1502 |
|
ccs_set_string(head, name); |
1503 |
|
ccs_set_string(head, "\""); |
1504 |
} |
} |
1505 |
if (!ccs_print_number_union(head, &ptr->port) || |
ccs_set_lf(head); |
1506 |
!ccs_print_condition(head, cond)) |
return true; |
|
goto out; |
|
1507 |
} |
} |
|
head->read_bit = 0; |
|
|
return true; |
|
|
out: |
|
|
head->read_bit = bit; |
|
|
head->read_avail = pos; |
|
1508 |
return false; |
return false; |
1509 |
} |
} |
1510 |
|
|
1511 |
/** |
/** |
1512 |
* ccs_print_signal_acl - Print a signal ACL entry. |
* ccs_set_group - Print "acl_group " header keyword and category name. |
1513 |
* |
* |
1514 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1515 |
* @ptr: Pointer to "struct signale_acl". |
* @category: Category name. |
|
* @cond: Pointer to "struct ccs_condition". May be NULL. |
|
1516 |
* |
* |
1517 |
* Returns true on success, false otherwise. |
* Returns nothing. |
1518 |
*/ |
*/ |
1519 |
static bool ccs_print_signal_acl(struct ccs_io_buffer *head, |
static void ccs_set_group(struct ccs_io_buffer *head, const char *category) |
|
struct ccs_signal_acl *ptr, |
|
|
const struct ccs_condition *cond) |
|
|
{ |
|
|
const int pos = head->read_avail; |
|
|
if (!ccs_io_printf(head, CCS_KEYWORD_ALLOW_SIGNAL "%u %s", |
|
|
ptr->sig, ptr->domainname->name) || |
|
|
!ccs_print_condition(head, cond)) { |
|
|
head->read_avail = pos; |
|
|
return false; |
|
|
} |
|
|
return true; |
|
|
} |
|
|
|
|
|
/** |
|
|
* ccs_print_execute_handler_record - Print an execute handler ACL entry. |
|
|
* |
|
|
* @head: Pointer to "struct ccs_io_buffer". |
|
|
* @keyword: Name of the keyword. |
|
|
* @ptr: Pointer to "struct ccs_execute_handler_record". |
|
|
* |
|
|
* Returns true on success, false otherwise. |
|
|
*/ |
|
|
static bool ccs_print_execute_handler_record(struct ccs_io_buffer *head, |
|
|
const char *keyword, |
|
|
struct ccs_execute_handler_record * |
|
|
ptr) |
|
1520 |
{ |
{ |
1521 |
return ccs_io_printf(head, "%s %s\n", keyword, ptr->handler->name); |
if (head->type == CCS_EXCEPTIONPOLICY) { |
1522 |
|
ccs_print_namespace(head); |
1523 |
|
ccs_io_printf(head, "acl_group %u ", head->r.acl_group_index); |
1524 |
|
} |
1525 |
|
ccs_set_string(head, category); |
1526 |
} |
} |
1527 |
|
|
1528 |
/** |
/** |
1529 |
* ccs_print_mount_acl - Print a mount ACL entry. |
* ccs_print_entry - Print an ACL entry. |
1530 |
* |
* |
1531 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1532 |
* @ptr: Pointer to "struct ccs_mount_acl". |
* @acl: Pointer to an ACL entry. |
|
* @cond: Pointer to "struct ccs_condition". May be NULL. |
|
1533 |
* |
* |
1534 |
* Returns true on success, false otherwise. |
* Returns true on success, false otherwise. |
1535 |
*/ |
*/ |
1536 |
static bool ccs_print_mount_acl(struct ccs_io_buffer *head, |
static bool ccs_print_entry(struct ccs_io_buffer *head, |
1537 |
struct ccs_mount_acl *ptr, |
const struct ccs_acl_info *acl) |
|
const struct ccs_condition *cond) |
|
1538 |
{ |
{ |
1539 |
const int pos = head->read_avail; |
const u8 acl_type = acl->type; |
1540 |
if (!ccs_io_printf(head, CCS_KEYWORD_ALLOW_MOUNT) || |
const bool may_trigger_transition = acl->cond && acl->cond->transit; |
1541 |
!ccs_print_name_union(head, &ptr->dev_name) || |
bool first = true; |
1542 |
!ccs_print_name_union(head, &ptr->dir_name) || |
u8 bit; |
1543 |
!ccs_print_name_union(head, &ptr->fs_type) || |
if (head->r.print_cond_part) |
1544 |
!ccs_print_number_union(head, &ptr->flags) || |
goto print_cond_part; |
1545 |
!ccs_print_condition(head, cond)) { |
if (acl->is_deleted) |
1546 |
head->read_avail = pos; |
return true; |
1547 |
|
if (!ccs_flush(head)) |
1548 |
return false; |
return false; |
1549 |
|
else if (acl_type == CCS_TYPE_PATH_ACL) { |
1550 |
|
struct ccs_path_acl *ptr |
1551 |
|
= container_of(acl, typeof(*ptr), head); |
1552 |
|
const u16 perm = ptr->perm; |
1553 |
|
for (bit = 0; bit < CCS_MAX_PATH_OPERATION; bit++) { |
1554 |
|
if (!(perm & (1 << bit))) |
1555 |
|
continue; |
1556 |
|
if (head->r.print_transition_related_only && |
1557 |
|
bit != CCS_TYPE_EXECUTE && !may_trigger_transition) |
1558 |
|
continue; |
1559 |
|
if (first) { |
1560 |
|
ccs_set_group(head, "file "); |
1561 |
|
first = false; |
1562 |
|
} else { |
1563 |
|
ccs_set_slash(head); |
1564 |
|
} |
1565 |
|
ccs_set_string(head, ccs_path_keyword[bit]); |
1566 |
|
} |
1567 |
|
if (first) |
1568 |
|
return true; |
1569 |
|
ccs_print_name_union(head, &ptr->name); |
1570 |
|
} else if (acl_type == CCS_TYPE_AUTO_EXECUTE_HANDLER || |
1571 |
|
acl_type == CCS_TYPE_DENIED_EXECUTE_HANDLER) { |
1572 |
|
struct ccs_handler_acl *ptr |
1573 |
|
= container_of(acl, typeof(*ptr), head); |
1574 |
|
ccs_set_group(head, "task "); |
1575 |
|
ccs_set_string(head, acl_type == CCS_TYPE_AUTO_EXECUTE_HANDLER |
1576 |
|
? "auto_execute_handler " : |
1577 |
|
"denied_execute_handler "); |
1578 |
|
ccs_set_string(head, ptr->handler->name); |
1579 |
|
} else if (acl_type == CCS_TYPE_AUTO_TASK_ACL || |
1580 |
|
acl_type == CCS_TYPE_MANUAL_TASK_ACL) { |
1581 |
|
struct ccs_task_acl *ptr = |
1582 |
|
container_of(acl, typeof(*ptr), head); |
1583 |
|
ccs_set_group(head, "task "); |
1584 |
|
ccs_set_string(head, acl_type == CCS_TYPE_AUTO_TASK_ACL ? |
1585 |
|
"auto_domain_transition " : |
1586 |
|
"manual_domain_transition "); |
1587 |
|
ccs_set_string(head, ptr->domainname->name); |
1588 |
|
} else if (head->r.print_transition_related_only && |
1589 |
|
!may_trigger_transition) { |
1590 |
|
return true; |
1591 |
|
} else if (acl_type == CCS_TYPE_MKDEV_ACL) { |
1592 |
|
struct ccs_mkdev_acl *ptr = |
1593 |
|
container_of(acl, typeof(*ptr), head); |
1594 |
|
const u8 perm = ptr->perm; |
1595 |
|
for (bit = 0; bit < CCS_MAX_MKDEV_OPERATION; bit++) { |
1596 |
|
if (!(perm & (1 << bit))) |
1597 |
|
continue; |
1598 |
|
if (first) { |
1599 |
|
ccs_set_group(head, "file "); |
1600 |
|
first = false; |
1601 |
|
} else { |
1602 |
|
ccs_set_slash(head); |
1603 |
|
} |
1604 |
|
ccs_set_string(head, ccs_mac_keywords |
1605 |
|
[ccs_pnnn2mac[bit]]); |
1606 |
|
} |
1607 |
|
if (first) |
1608 |
|
return true; |
1609 |
|
ccs_print_name_union(head, &ptr->name); |
1610 |
|
ccs_print_number_union(head, &ptr->mode); |
1611 |
|
ccs_print_number_union(head, &ptr->major); |
1612 |
|
ccs_print_number_union(head, &ptr->minor); |
1613 |
|
} else if (acl_type == CCS_TYPE_PATH2_ACL) { |
1614 |
|
struct ccs_path2_acl *ptr = |
1615 |
|
container_of(acl, typeof(*ptr), head); |
1616 |
|
const u8 perm = ptr->perm; |
1617 |
|
for (bit = 0; bit < CCS_MAX_PATH2_OPERATION; bit++) { |
1618 |
|
if (!(perm & (1 << bit))) |
1619 |
|
continue; |
1620 |
|
if (first) { |
1621 |
|
ccs_set_group(head, "file "); |
1622 |
|
first = false; |
1623 |
|
} else { |
1624 |
|
ccs_set_slash(head); |
1625 |
|
} |
1626 |
|
ccs_set_string(head, ccs_mac_keywords |
1627 |
|
[ccs_pp2mac[bit]]); |
1628 |
|
} |
1629 |
|
if (first) |
1630 |
|
return true; |
1631 |
|
ccs_print_name_union(head, &ptr->name1); |
1632 |
|
ccs_print_name_union(head, &ptr->name2); |
1633 |
|
} else if (acl_type == CCS_TYPE_PATH_NUMBER_ACL) { |
1634 |
|
struct ccs_path_number_acl *ptr = |
1635 |
|
container_of(acl, typeof(*ptr), head); |
1636 |
|
const u8 perm = ptr->perm; |
1637 |
|
for (bit = 0; bit < CCS_MAX_PATH_NUMBER_OPERATION; bit++) { |
1638 |
|
if (!(perm & (1 << bit))) |
1639 |
|
continue; |
1640 |
|
if (first) { |
1641 |
|
ccs_set_group(head, "file "); |
1642 |
|
first = false; |
1643 |
|
} else { |
1644 |
|
ccs_set_slash(head); |
1645 |
|
} |
1646 |
|
ccs_set_string(head, ccs_mac_keywords |
1647 |
|
[ccs_pn2mac[bit]]); |
1648 |
|
} |
1649 |
|
if (first) |
1650 |
|
return true; |
1651 |
|
ccs_print_name_union(head, &ptr->name); |
1652 |
|
ccs_print_number_union(head, &ptr->number); |
1653 |
|
} else if (acl_type == CCS_TYPE_ENV_ACL) { |
1654 |
|
struct ccs_env_acl *ptr = |
1655 |
|
container_of(acl, typeof(*ptr), head); |
1656 |
|
ccs_set_group(head, "misc env "); |
1657 |
|
ccs_set_string(head, ptr->env->name); |
1658 |
|
} else if (acl_type == CCS_TYPE_CAPABILITY_ACL) { |
1659 |
|
struct ccs_capability_acl *ptr = |
1660 |
|
container_of(acl, typeof(*ptr), head); |
1661 |
|
ccs_set_group(head, "capability "); |
1662 |
|
ccs_set_string(head, ccs_mac_keywords |
1663 |
|
[ccs_c2mac[ptr->operation]]); |
1664 |
|
} else if (acl_type == CCS_TYPE_INET_ACL) { |
1665 |
|
struct ccs_inet_acl *ptr = |
1666 |
|
container_of(acl, typeof(*ptr), head); |
1667 |
|
const u8 perm = ptr->perm; |
1668 |
|
for (bit = 0; bit < CCS_MAX_NETWORK_OPERATION; bit++) { |
1669 |
|
if (!(perm & (1 << bit))) |
1670 |
|
continue; |
1671 |
|
if (first) { |
1672 |
|
ccs_set_group(head, "network inet "); |
1673 |
|
ccs_set_string(head, ccs_proto_keyword |
1674 |
|
[ptr->protocol]); |
1675 |
|
ccs_set_space(head); |
1676 |
|
first = false; |
1677 |
|
} else { |
1678 |
|
ccs_set_slash(head); |
1679 |
|
} |
1680 |
|
ccs_set_string(head, ccs_socket_keyword[bit]); |
1681 |
|
} |
1682 |
|
if (first) |
1683 |
|
return true; |
1684 |
|
ccs_set_space(head); |
1685 |
|
if (ptr->address.group) { |
1686 |
|
ccs_set_string(head, "@"); |
1687 |
|
ccs_set_string(head, |
1688 |
|
ptr->address.group->group_name->name); |
1689 |
|
} else { |
1690 |
|
char buf[128]; |
1691 |
|
ccs_print_ip(buf, sizeof(buf), &ptr->address); |
1692 |
|
ccs_io_printf(head, "%s", buf); |
1693 |
|
} |
1694 |
|
ccs_print_number_union(head, &ptr->port); |
1695 |
|
} else if (acl_type == CCS_TYPE_UNIX_ACL) { |
1696 |
|
struct ccs_unix_acl *ptr = |
1697 |
|
container_of(acl, typeof(*ptr), head); |
1698 |
|
const u8 perm = ptr->perm; |
1699 |
|
for (bit = 0; bit < CCS_MAX_NETWORK_OPERATION; bit++) { |
1700 |
|
if (!(perm & (1 << bit))) |
1701 |
|
continue; |
1702 |
|
if (first) { |
1703 |
|
ccs_set_group(head, "network unix "); |
1704 |
|
ccs_set_string(head, ccs_proto_keyword |
1705 |
|
[ptr->protocol]); |
1706 |
|
ccs_set_space(head); |
1707 |
|
first = false; |
1708 |
|
} else { |
1709 |
|
ccs_set_slash(head); |
1710 |
|
} |
1711 |
|
ccs_set_string(head, ccs_socket_keyword[bit]); |
1712 |
|
} |
1713 |
|
if (first) |
1714 |
|
return true; |
1715 |
|
ccs_print_name_union(head, &ptr->name); |
1716 |
|
} else if (acl_type == CCS_TYPE_SIGNAL_ACL) { |
1717 |
|
struct ccs_signal_acl *ptr = |
1718 |
|
container_of(acl, typeof(*ptr), head); |
1719 |
|
ccs_set_group(head, "ipc signal "); |
1720 |
|
ccs_print_number_union_nospace(head, &ptr->sig); |
1721 |
|
ccs_set_space(head); |
1722 |
|
ccs_set_string(head, ptr->domainname->name); |
1723 |
|
} else if (acl_type == CCS_TYPE_MOUNT_ACL) { |
1724 |
|
struct ccs_mount_acl *ptr = |
1725 |
|
container_of(acl, typeof(*ptr), head); |
1726 |
|
ccs_set_group(head, "file mount"); |
1727 |
|
ccs_print_name_union(head, &ptr->dev_name); |
1728 |
|
ccs_print_name_union(head, &ptr->dir_name); |
1729 |
|
ccs_print_name_union(head, &ptr->fs_type); |
1730 |
|
ccs_print_number_union(head, &ptr->flags); |
1731 |
|
} |
1732 |
|
if (acl->cond) { |
1733 |
|
head->r.print_cond_part = true; |
1734 |
|
head->r.cond_step = 0; |
1735 |
|
if (!ccs_flush(head)) |
1736 |
|
return false; |
1737 |
|
print_cond_part: |
1738 |
|
if (!ccs_print_condition(head, acl->cond)) |
1739 |
|
return false; |
1740 |
|
head->r.print_cond_part = false; |
1741 |
|
} else { |
1742 |
|
ccs_set_lf(head); |
1743 |
} |
} |
1744 |
return true; |
return true; |
1745 |
} |
} |
1746 |
|
|
1747 |
/** |
/** |
1748 |
* ccs_print_entry - Print an ACL entry. |
* ccs_read_domain2 - Read domain policy. |
1749 |
* |
* |
1750 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1751 |
* @ptr: Pointer to an ACL entry. |
* @list: Pointer to "struct list_head". |
1752 |
* |
* |
1753 |
* Returns true on success, false otherwise. |
* Returns true on success, false otherwise. |
1754 |
|
* |
1755 |
|
* Caller holds ccs_read_lock(). |
1756 |
*/ |
*/ |
1757 |
static bool ccs_print_entry(struct ccs_io_buffer *head, |
static bool ccs_read_domain2(struct ccs_io_buffer *head, |
1758 |
struct ccs_acl_info *ptr) |
struct list_head *list) |
1759 |
{ |
{ |
1760 |
const struct ccs_condition *cond = ptr->cond; |
list_for_each_cookie(head->r.acl, list) { |
1761 |
const u8 acl_type = ptr->type; |
struct ccs_acl_info *ptr = |
1762 |
if (ptr->is_deleted) |
list_entry(head->r.acl, typeof(*ptr), list); |
1763 |
return true; |
if (!ccs_print_entry(head, ptr)) |
1764 |
if (acl_type == CCS_TYPE_PATH_ACL) { |
return false; |
|
struct ccs_path_acl *acl |
|
|
= container_of(ptr, struct ccs_path_acl, head); |
|
|
return ccs_print_path_acl(head, acl, cond); |
|
|
} |
|
|
if (acl_type == CCS_TYPE_EXECUTE_HANDLER) { |
|
|
struct ccs_execute_handler_record *acl |
|
|
= container_of(ptr, struct ccs_execute_handler_record, |
|
|
head); |
|
|
const char *keyword = CCS_KEYWORD_EXECUTE_HANDLER; |
|
|
return ccs_print_execute_handler_record(head, keyword, acl); |
|
|
} |
|
|
if (acl_type == CCS_TYPE_DENIED_EXECUTE_HANDLER) { |
|
|
struct ccs_execute_handler_record *acl |
|
|
= container_of(ptr, struct ccs_execute_handler_record, |
|
|
head); |
|
|
const char *keyword = CCS_KEYWORD_DENIED_EXECUTE_HANDLER; |
|
|
return ccs_print_execute_handler_record(head, keyword, acl); |
|
|
} |
|
|
if (head->read_execute_only) |
|
|
return true; |
|
|
if (acl_type == CCS_TYPE_PATH_NUMBER3_ACL) { |
|
|
struct ccs_path_number3_acl *acl |
|
|
= container_of(ptr, struct ccs_path_number3_acl, head); |
|
|
return ccs_print_path_number3_acl(head, acl, cond); |
|
|
} |
|
|
if (acl_type == CCS_TYPE_PATH2_ACL) { |
|
|
struct ccs_path2_acl *acl |
|
|
= container_of(ptr, struct ccs_path2_acl, head); |
|
|
return ccs_print_path2_acl(head, acl, cond); |
|
|
} |
|
|
if (acl_type == CCS_TYPE_PATH_NUMBER_ACL) { |
|
|
struct ccs_path_number_acl *acl |
|
|
= container_of(ptr, struct ccs_path_number_acl, head); |
|
|
return ccs_print_path_number_acl(head, acl, cond); |
|
|
} |
|
|
if (acl_type == CCS_TYPE_ENV_ACL) { |
|
|
struct ccs_env_acl *acl |
|
|
= container_of(ptr, struct ccs_env_acl, head); |
|
|
return ccs_print_env_acl(head, acl, cond); |
|
|
} |
|
|
if (acl_type == CCS_TYPE_CAPABILITY_ACL) { |
|
|
struct ccs_capability_acl *acl |
|
|
= container_of(ptr, struct ccs_capability_acl, head); |
|
|
return ccs_print_capability_acl(head, acl, cond); |
|
|
} |
|
|
if (acl_type == CCS_TYPE_IP_NETWORK_ACL) { |
|
|
struct ccs_ip_network_acl *acl |
|
|
= container_of(ptr, struct ccs_ip_network_acl, head); |
|
|
return ccs_print_network_acl(head, acl, cond); |
|
|
} |
|
|
if (acl_type == CCS_TYPE_SIGNAL_ACL) { |
|
|
struct ccs_signal_acl *acl |
|
|
= container_of(ptr, struct ccs_signal_acl, head); |
|
|
return ccs_print_signal_acl(head, acl, cond); |
|
|
} |
|
|
if (acl_type == CCS_TYPE_MOUNT_ACL) { |
|
|
struct ccs_mount_acl *acl |
|
|
= container_of(ptr, struct ccs_mount_acl, head); |
|
|
return ccs_print_mount_acl(head, acl, cond); |
|
1765 |
} |
} |
1766 |
BUG(); /* This must not happen. */ |
head->r.acl = NULL; |
1767 |
return false; |
return true; |
1768 |
} |
} |
1769 |
|
|
1770 |
/** |
/** |
1771 |
* ccs_read_domain_policy - Read domain policy. |
* ccs_read_domain - Read domain policy. |
1772 |
* |
* |
1773 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1774 |
* |
* |
1775 |
|
* Returns nothing. |
1776 |
|
* |
1777 |
* Caller holds ccs_read_lock(). |
* Caller holds ccs_read_lock(). |
1778 |
*/ |
*/ |
1779 |
static void ccs_read_domain_policy(struct ccs_io_buffer *head) |
static void ccs_read_domain(struct ccs_io_buffer *head) |
1780 |
{ |
{ |
1781 |
struct list_head *dpos; |
if (head->r.eof) |
1782 |
struct list_head *apos; |
return; |
1783 |
if (head->read_eof) |
list_for_each_cookie(head->r.domain, &ccs_domain_list) { |
1784 |
return; |
struct ccs_domain_info *domain = |
1785 |
if (head->read_step == 0) |
list_entry(head->r.domain, typeof(*domain), list); |
1786 |
head->read_step = 1; |
switch (head->r.step) { |
1787 |
list_for_each_cookie(dpos, head->read_var1, &ccs_domain_list) { |
u8 i; |
1788 |
struct ccs_domain_info *domain; |
case 0: |
1789 |
const char *quota_exceeded = ""; |
if (domain->is_deleted && |
1790 |
const char *transition_failed = ""; |
!head->r.print_this_domain_only) |
1791 |
const char *ignore_global_allow_read = ""; |
continue; |
1792 |
const char *ignore_global_allow_env = ""; |
/* Print domainname and flags. */ |
1793 |
domain = list_entry(dpos, struct ccs_domain_info, list); |
ccs_set_string(head, domain->domainname->name); |
1794 |
if (head->read_step != 1) |
ccs_set_lf(head); |
1795 |
goto acl_loop; |
ccs_io_printf(head, "use_profile %u\n", |
1796 |
if (domain->is_deleted && !head->read_single_domain) |
domain->profile); |
1797 |
continue; |
ccs_io_printf(head, "use_group %u\n", domain->group); |
1798 |
/* Print domainname and flags. */ |
for (i = 0; i < CCS_MAX_DOMAIN_INFO_FLAGS; i++) |
1799 |
if (domain->quota_warned) |
if (domain->flags[i]) |
1800 |
quota_exceeded = CCS_KEYWORD_QUOTA_EXCEEDED "\n"; |
ccs_set_string(head, ccs_dif[i]); |
1801 |
if (domain->domain_transition_failed) |
head->r.step++; |
1802 |
transition_failed = CCS_KEYWORD_TRANSITION_FAILED "\n"; |
ccs_set_lf(head); |
1803 |
if (domain->ignore_global_allow_read) |
/* fall through */ |
1804 |
ignore_global_allow_read |
case 1: |
1805 |
= CCS_KEYWORD_IGNORE_GLOBAL_ALLOW_READ "\n"; |
if (!ccs_read_domain2(head, &domain->acl_info_list)) |
|
if (domain->ignore_global_allow_env) |
|
|
ignore_global_allow_env |
|
|
= CCS_KEYWORD_IGNORE_GLOBAL_ALLOW_ENV "\n"; |
|
|
if (!ccs_io_printf(head, "%s\n" CCS_KEYWORD_USE_PROFILE "%u\n" |
|
|
"%s%s%s%s\n", domain->domainname->name, |
|
|
domain->profile, quota_exceeded, |
|
|
transition_failed, |
|
|
ignore_global_allow_read, |
|
|
ignore_global_allow_env)) |
|
|
return; |
|
|
head->read_step = 2; |
|
|
acl_loop: |
|
|
if (head->read_step == 3) |
|
|
goto tail_mark; |
|
|
/* Print ACL entries in the domain. */ |
|
|
list_for_each_cookie(apos, head->read_var2, |
|
|
&domain->acl_info_list) { |
|
|
struct ccs_acl_info *ptr |
|
|
= list_entry(apos, struct ccs_acl_info, list); |
|
|
if (!ccs_print_entry(head, ptr)) |
|
1806 |
return; |
return; |
1807 |
|
head->r.step++; |
1808 |
|
if (!ccs_set_lf(head)) |
1809 |
|
return; |
1810 |
|
/* fall through */ |
1811 |
|
case 2: |
1812 |
|
head->r.step = 0; |
1813 |
|
if (head->r.print_this_domain_only) |
1814 |
|
goto done; |
1815 |
} |
} |
|
head->read_step = 3; |
|
|
tail_mark: |
|
|
if (!ccs_io_printf(head, "\n")) |
|
|
return; |
|
|
head->read_step = 1; |
|
|
if (head->read_single_domain) |
|
|
break; |
|
1816 |
} |
} |
1817 |
head->read_eof = true; |
done: |
1818 |
|
head->r.eof = true; |
1819 |
} |
} |
1820 |
|
|
1821 |
/** |
/** |
1845 |
if (profile >= CCS_MAX_PROFILES) |
if (profile >= CCS_MAX_PROFILES) |
1846 |
return -EINVAL; |
return -EINVAL; |
1847 |
domain = ccs_find_domain(cp + 1); |
domain = ccs_find_domain(cp + 1); |
1848 |
if (domain && (!ccs_policy_loaded || ccs_profile_ptr[(u8) profile])) |
if (domain && (!ccs_policy_loaded || |
1849 |
|
domain->ns->profile_ptr[(u8) profile])) |
1850 |
domain->profile = (u8) profile; |
domain->profile = (u8) profile; |
1851 |
return 0; |
return 0; |
1852 |
} |
} |
1856 |
* |
* |
1857 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1858 |
* |
* |
1859 |
|
* Returns nothing. |
1860 |
|
* |
1861 |
* This is equivalent to doing |
* This is equivalent to doing |
1862 |
* |
* |
1863 |
* grep -A 1 '^<kernel>' /proc/ccs/domain_policy | |
* grep -A 1 '^<kernel>' /proc/ccs/domain_policy | |
1869 |
*/ |
*/ |
1870 |
static void ccs_read_domain_profile(struct ccs_io_buffer *head) |
static void ccs_read_domain_profile(struct ccs_io_buffer *head) |
1871 |
{ |
{ |
1872 |
struct list_head *pos; |
if (head->r.eof) |
|
if (head->read_eof) |
|
1873 |
return; |
return; |
1874 |
list_for_each_cookie(pos, head->read_var1, &ccs_domain_list) { |
list_for_each_cookie(head->r.domain, &ccs_domain_list) { |
1875 |
struct ccs_domain_info *domain; |
struct ccs_domain_info *domain = |
1876 |
domain = list_entry(pos, struct ccs_domain_info, list); |
list_entry(head->r.domain, typeof(*domain), list); |
1877 |
if (domain->is_deleted) |
if (domain->is_deleted) |
1878 |
continue; |
continue; |
1879 |
if (!ccs_io_printf(head, "%u %s\n", domain->profile, |
if (!ccs_flush(head)) |
|
domain->domainname->name)) |
|
1880 |
return; |
return; |
1881 |
|
ccs_io_printf(head, "%u ", domain->profile); |
1882 |
|
ccs_set_string(head, domain->domainname->name); |
1883 |
|
ccs_set_lf(head); |
1884 |
} |
} |
1885 |
head->read_eof = true; |
head->r.eof = true; |
1886 |
} |
} |
1887 |
|
|
1888 |
/** |
/** |
1889 |
* ccs_write_pid: Specify PID to obtain domainname. |
* ccs_write_pid - Specify PID to obtain domainname. |
1890 |
* |
* |
1891 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1892 |
* |
* |
1894 |
*/ |
*/ |
1895 |
static int ccs_write_pid(struct ccs_io_buffer *head) |
static int ccs_write_pid(struct ccs_io_buffer *head) |
1896 |
{ |
{ |
1897 |
head->read_eof = false; |
head->r.eof = false; |
1898 |
return 0; |
return 0; |
1899 |
} |
} |
1900 |
|
|
1920 |
u32 ccs_flags = 0; |
u32 ccs_flags = 0; |
1921 |
/* Accessing write_buf is safe because head->io_sem is held. */ |
/* Accessing write_buf is safe because head->io_sem is held. */ |
1922 |
if (!buf) { |
if (!buf) { |
1923 |
head->read_eof = true; |
head->r.eof = true; |
1924 |
return; /* Do nothing if open(O_RDONLY). */ |
return; /* Do nothing if open(O_RDONLY). */ |
1925 |
} |
} |
1926 |
if (head->read_avail || head->read_eof) |
if (head->r.w_pos || head->r.eof) |
1927 |
return; |
return; |
1928 |
head->read_eof = true; |
head->r.eof = true; |
1929 |
if (ccs_str_starts(&buf, "info ")) |
if (ccs_str_starts(&buf, "info ")) |
1930 |
task_info = true; |
task_info = true; |
1931 |
if (ccs_str_starts(&buf, "global-pid ")) |
if (ccs_str_starts(&buf, "global-pid ")) |
1942 |
#endif |
#endif |
1943 |
if (p) { |
if (p) { |
1944 |
domain = ccs_task_domain(p); |
domain = ccs_task_domain(p); |
1945 |
ccs_flags = p->ccs_flags; |
ccs_flags = ccs_task_flags(p); |
1946 |
} |
} |
1947 |
ccs_tasklist_unlock(); |
ccs_tasklist_unlock(); |
1948 |
if (!domain) |
if (!domain) |
1949 |
return; |
return; |
1950 |
if (!task_info) |
if (!task_info) { |
1951 |
ccs_io_printf(head, "%u %u %s", pid, domain->profile, |
ccs_io_printf(head, "%u %u ", pid, domain->profile); |
1952 |
domain->domainname->name); |
ccs_set_string(head, domain->domainname->name); |
1953 |
else |
} else { |
1954 |
ccs_io_printf(head, "%u manager=%s execute_handler=%s " |
ccs_io_printf(head, "%u manager=%s execute_handler=%s ", pid, |
|
"state[0]=%u state[1]=%u state[2]=%u", pid, |
|
1955 |
ccs_yesno(ccs_flags & |
ccs_yesno(ccs_flags & |
1956 |
CCS_TASK_IS_POLICY_MANAGER), |
CCS_TASK_IS_MANAGER), |
1957 |
ccs_yesno(ccs_flags & |
ccs_yesno(ccs_flags & |
1958 |
CCS_TASK_IS_EXECUTE_HANDLER), |
CCS_TASK_IS_EXECUTE_HANDLER)); |
1959 |
(u8) (ccs_flags >> 24), |
} |
|
(u8) (ccs_flags >> 16), |
|
|
(u8) (ccs_flags >> 8)); |
|
1960 |
} |
} |
1961 |
|
|
1962 |
|
/* String table for domain transition control keywords. */ |
1963 |
|
static const char * const ccs_transition_type[CCS_MAX_TRANSITION_TYPE] = { |
1964 |
|
[CCS_TRANSITION_CONTROL_NO_RESET] = "no_reset_domain ", |
1965 |
|
[CCS_TRANSITION_CONTROL_RESET] = "reset_domain ", |
1966 |
|
[CCS_TRANSITION_CONTROL_NO_INITIALIZE] = "no_initialize_domain ", |
1967 |
|
[CCS_TRANSITION_CONTROL_INITIALIZE] = "initialize_domain ", |
1968 |
|
[CCS_TRANSITION_CONTROL_NO_KEEP] = "no_keep_domain ", |
1969 |
|
[CCS_TRANSITION_CONTROL_KEEP] = "keep_domain ", |
1970 |
|
}; |
1971 |
|
|
1972 |
|
/* String table for grouping keywords. */ |
1973 |
|
static const char * const ccs_group_name[CCS_MAX_GROUP] = { |
1974 |
|
[CCS_PATH_GROUP] = "path_group ", |
1975 |
|
[CCS_NUMBER_GROUP] = "number_group ", |
1976 |
|
[CCS_ADDRESS_GROUP] = "address_group ", |
1977 |
|
}; |
1978 |
|
|
1979 |
/** |
/** |
1980 |
* ccs_write_exception_policy - Write exception policy. |
* ccs_write_exception - Write exception policy. |
1981 |
* |
* |
1982 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1983 |
* |
* |
1984 |
* Returns 0 on success, negative value otherwise. |
* Returns 0 on success, negative value otherwise. |
1985 |
*/ |
*/ |
1986 |
static int ccs_write_exception_policy(struct ccs_io_buffer *head) |
static int ccs_write_exception(struct ccs_io_buffer *head) |
1987 |
{ |
{ |
1988 |
char *data = head->write_buf; |
const bool is_delete = head->w.is_delete; |
1989 |
bool is_delete = ccs_str_starts(&data, CCS_KEYWORD_DELETE); |
struct ccs_acl_param param = { |
1990 |
if (ccs_str_starts(&data, CCS_KEYWORD_KEEP_DOMAIN)) |
.ns = head->w.ns, |
1991 |
return ccs_write_domain_keeper_policy(data, false, is_delete); |
.is_delete = is_delete, |
1992 |
if (ccs_str_starts(&data, CCS_KEYWORD_NO_KEEP_DOMAIN)) |
.data = head->write_buf, |
1993 |
return ccs_write_domain_keeper_policy(data, true, is_delete); |
}; |
1994 |
if (ccs_str_starts(&data, CCS_KEYWORD_INITIALIZE_DOMAIN)) |
u8 i; |
1995 |
return ccs_write_domain_initializer_policy(data, false, |
if (ccs_str_starts(¶m.data, "aggregator ")) |
1996 |
is_delete); |
return ccs_write_aggregator(¶m); |
1997 |
if (ccs_str_starts(&data, CCS_KEYWORD_NO_INITIALIZE_DOMAIN)) |
if (ccs_str_starts(¶m.data, "deny_autobind ")) |
1998 |
return ccs_write_domain_initializer_policy(data, true, |
return ccs_write_reserved_port(¶m); |
1999 |
is_delete); |
for (i = 0; i < CCS_MAX_TRANSITION_TYPE; i++) |
2000 |
if (ccs_str_starts(&data, CCS_KEYWORD_AGGREGATOR)) |
if (ccs_str_starts(¶m.data, ccs_transition_type[i])) |
2001 |
return ccs_write_aggregator_policy(data, is_delete); |
return ccs_write_transition_control(¶m, i); |
2002 |
if (ccs_str_starts(&data, CCS_KEYWORD_ALLOW_READ)) |
for (i = 0; i < CCS_MAX_GROUP; i++) |
2003 |
return ccs_write_globally_readable_policy(data, is_delete); |
if (ccs_str_starts(¶m.data, ccs_group_name[i])) |
2004 |
if (ccs_str_starts(&data, CCS_KEYWORD_ALLOW_ENV)) |
return ccs_write_group(¶m, i); |
2005 |
return ccs_write_globally_usable_env_policy(data, is_delete); |
if (ccs_str_starts(¶m.data, "acl_group ")) { |
2006 |
if (ccs_str_starts(&data, CCS_KEYWORD_FILE_PATTERN)) |
unsigned int group; |
2007 |
return ccs_write_pattern_policy(data, is_delete); |
char *data; |
2008 |
if (ccs_str_starts(&data, CCS_KEYWORD_PATH_GROUP)) |
group = simple_strtoul(param.data, &data, 10); |
2009 |
return ccs_write_path_group_policy(data, is_delete); |
if (group < CCS_MAX_ACL_GROUPS && *data++ == ' ') |
2010 |
if (ccs_str_starts(&data, CCS_KEYWORD_NUMBER_GROUP)) |
return ccs_write_domain2(head->w.ns, |
2011 |
return ccs_write_number_group_policy(data, is_delete); |
&head->w.ns->acl_group[group], |
2012 |
if (ccs_str_starts(&data, CCS_KEYWORD_DENY_REWRITE)) |
data, is_delete); |
2013 |
return ccs_write_no_rewrite_policy(data, is_delete); |
} |
|
if (ccs_str_starts(&data, CCS_KEYWORD_ADDRESS_GROUP)) |
|
|
return ccs_write_address_group_policy(data, is_delete); |
|
|
if (ccs_str_starts(&data, CCS_KEYWORD_DENY_AUTOBIND)) |
|
|
return ccs_write_reserved_port_policy(data, is_delete); |
|
2014 |
return -EINVAL; |
return -EINVAL; |
2015 |
} |
} |
2016 |
|
|
2017 |
/** |
/** |
2018 |
* ccs_read_exception_policy - Read exception policy. |
* ccs_read_group - Read "struct ccs_path_group"/"struct ccs_number_group"/"struct ccs_address_group" list. |
2019 |
* |
* |
2020 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
2021 |
|
* @idx: Index number. |
2022 |
|
* |
2023 |
|
* Returns true on success, false otherwise. |
2024 |
* |
* |
2025 |
* Caller holds ccs_read_lock(). |
* Caller holds ccs_read_lock(). |
2026 |
*/ |
*/ |
2027 |
static void ccs_read_exception_policy(struct ccs_io_buffer *head) |
static bool ccs_read_group(struct ccs_io_buffer *head, const int idx) |
2028 |
{ |
{ |
2029 |
if (head->read_eof) |
struct ccs_policy_namespace *ns = container_of(head->r.ns, typeof(*ns), |
2030 |
return; |
namespace_list); |
2031 |
switch (head->read_step) { |
struct list_head *list = &ns->group_list[idx]; |
2032 |
case 0: |
list_for_each_cookie(head->r.group, list) { |
2033 |
head->read_var2 = NULL; |
struct ccs_group *group = |
2034 |
head->read_step = 1; |
list_entry(head->r.group, typeof(*group), head.list); |
2035 |
case 1: |
list_for_each_cookie(head->r.acl, &group->member_list) { |
2036 |
if (!ccs_read_domain_keeper_policy(head)) |
struct ccs_acl_head *ptr = |
2037 |
break; |
list_entry(head->r.acl, typeof(*ptr), list); |
2038 |
head->read_var2 = NULL; |
if (ptr->is_deleted) |
2039 |
head->read_step = 2; |
continue; |
2040 |
case 2: |
if (!ccs_flush(head)) |
2041 |
if (!ccs_read_globally_readable_policy(head)) |
return false; |
2042 |
break; |
ccs_print_namespace(head); |
2043 |
head->read_var2 = NULL; |
ccs_set_string(head, ccs_group_name[idx]); |
2044 |
head->read_step = 3; |
ccs_set_string(head, group->group_name->name); |
2045 |
case 3: |
if (idx == CCS_PATH_GROUP) { |
2046 |
if (!ccs_read_globally_usable_env_policy(head)) |
ccs_set_space(head); |
2047 |
break; |
ccs_set_string(head, container_of |
2048 |
head->read_var2 = NULL; |
(ptr, struct ccs_path_group, |
2049 |
head->read_step = 4; |
head)->member_name->name); |
2050 |
case 4: |
} else if (idx == CCS_NUMBER_GROUP) { |
2051 |
if (!ccs_read_domain_initializer_policy(head)) |
ccs_print_number_union(head, &container_of |
2052 |
break; |
(ptr, struct ccs_number_group, |
2053 |
head->read_var2 = NULL; |
head)->number); |
2054 |
head->read_step = 6; |
} else if (idx == CCS_ADDRESS_GROUP) { |
2055 |
case 6: |
char buffer[128]; |
2056 |
if (!ccs_read_aggregator_policy(head)) |
struct ccs_address_group *member = |
2057 |
break; |
container_of(ptr, typeof(*member), |
2058 |
head->read_var2 = NULL; |
head); |
2059 |
head->read_step = 7; |
ccs_print_ip(buffer, sizeof(buffer), |
2060 |
case 7: |
&member->address); |
2061 |
if (!ccs_read_file_pattern(head)) |
ccs_io_printf(head, " %s", buffer); |
2062 |
break; |
} |
2063 |
head->read_var2 = NULL; |
ccs_set_lf(head); |
2064 |
head->read_step = 8; |
} |
2065 |
case 8: |
head->r.acl = NULL; |
|
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; |
|
2066 |
} |
} |
2067 |
|
head->r.group = NULL; |
2068 |
|
return true; |
2069 |
} |
} |
2070 |
|
|
2071 |
/** |
/** |
2072 |
* ccs_get_argv0 - Get argv[0]. |
* ccs_read_policy - Read "struct ccs_..._entry" list. |
2073 |
* |
* |
2074 |
* @ee: Pointer to "struct ccs_execve_entry". |
* @head: Pointer to "struct ccs_io_buffer". |
2075 |
|
* @idx: Index number. |
2076 |
* |
* |
2077 |
* Returns true on success, false otherwise. |
* Returns true on success, false otherwise. |
2078 |
|
* |
2079 |
|
* Caller holds ccs_read_lock(). |
2080 |
*/ |
*/ |
2081 |
static bool ccs_get_argv0(struct ccs_execve_entry *ee) |
static bool ccs_read_policy(struct ccs_io_buffer *head, const int idx) |
2082 |
{ |
{ |
2083 |
struct linux_binprm *bprm = ee->bprm; |
struct ccs_policy_namespace *ns = container_of(head->r.ns, typeof(*ns), |
2084 |
char *arg_ptr = ee->tmp; |
namespace_list); |
2085 |
int arg_len = 0; |
struct list_head *list = &ns->policy_list[idx]; |
2086 |
unsigned long pos = bprm->p; |
list_for_each_cookie(head->r.acl, list) { |
2087 |
int offset = pos % PAGE_SIZE; |
struct ccs_acl_head *acl = |
2088 |
bool done = false; |
container_of(head->r.acl, typeof(*acl), list); |
2089 |
if (!bprm->argc) |
if (acl->is_deleted) |
2090 |
goto out; |
continue; |
2091 |
while (1) { |
if (head->r.print_transition_related_only && |
2092 |
if (!ccs_dump_page(bprm, pos, &ee->dump)) |
idx != CCS_ID_TRANSITION_CONTROL) |
2093 |
goto out; |
continue; |
2094 |
pos += PAGE_SIZE - offset; |
if (!ccs_flush(head)) |
2095 |
/* Read. */ |
return false; |
2096 |
while (offset < PAGE_SIZE) { |
switch (idx) { |
2097 |
const char *kaddr = ee->dump.data; |
case CCS_ID_TRANSITION_CONTROL: |
2098 |
const unsigned char c = kaddr[offset++]; |
{ |
2099 |
if (c && arg_len < CCS_EXEC_TMPSIZE - 10) { |
struct ccs_transition_control *ptr = |
2100 |
if (c == '\\') { |
container_of(acl, typeof(*ptr), head); |
2101 |
arg_ptr[arg_len++] = '\\'; |
ccs_print_namespace(head); |
2102 |
arg_ptr[arg_len++] = '\\'; |
ccs_set_string(head, |
2103 |
} else if (c > ' ' && c < 127) { |
ccs_transition_type[ptr->type]); |
2104 |
arg_ptr[arg_len++] = c; |
ccs_set_string(head, ptr->program ? |
2105 |
} else { |
ptr->program->name : "any"); |
2106 |
arg_ptr[arg_len++] = '\\'; |
ccs_set_string(head, " from "); |
2107 |
arg_ptr[arg_len++] = (c >> 6) + '0'; |
ccs_set_string(head, ptr->domainname ? |
2108 |
arg_ptr[arg_len++] |
ptr->domainname->name : "any"); |
2109 |
= ((c >> 3) & 7) + '0'; |
} |
2110 |
arg_ptr[arg_len++] = (c & 7) + '0'; |
break; |
2111 |
} |
case CCS_ID_AGGREGATOR: |
2112 |
} else { |
{ |
2113 |
arg_ptr[arg_len] = '\0'; |
struct ccs_aggregator *ptr = |
2114 |
done = true; |
container_of(acl, typeof(*ptr), head); |
2115 |
break; |
ccs_print_namespace(head); |
2116 |
|
ccs_set_string(head, "aggregator "); |
2117 |
|
ccs_set_string(head, ptr->original_name->name); |
2118 |
|
ccs_set_space(head); |
2119 |
|
ccs_set_string(head, |
2120 |
|
ptr->aggregated_name->name); |
2121 |
|
} |
2122 |
|
break; |
2123 |
|
case CCS_ID_RESERVEDPORT: |
2124 |
|
{ |
2125 |
|
struct ccs_reserved *ptr = |
2126 |
|
container_of(acl, typeof(*ptr), head); |
2127 |
|
ccs_print_namespace(head); |
2128 |
|
ccs_set_string(head, "deny_autobind "); |
2129 |
|
ccs_print_number_union_nospace(head, |
2130 |
|
&ptr->port); |
2131 |
} |
} |
|
} |
|
|
offset = 0; |
|
|
if (done) |
|
2132 |
break; |
break; |
2133<
| |