3 |
* |
* |
4 |
* Copyright (C) 2005-2010 NTT DATA CORPORATION |
* Copyright (C) 2005-2010 NTT DATA CORPORATION |
5 |
* |
* |
6 |
* Version: 1.8.0-pre 2010/08/01 |
* Version: 1.8.0-pre 2010/10/18 |
7 |
* |
* |
8 |
* This file is applicable to both 2.4.30 and 2.6.11 and later. |
* This file is applicable to both 2.4.30 and 2.6.11 and later. |
9 |
* See README.ccs for ChangeLog. |
* See README.ccs for ChangeLog. |
12 |
|
|
13 |
#include "internal.h" |
#include "internal.h" |
14 |
|
|
15 |
static struct ccs_profile ccs_default_profile = { |
/* Profile version. Currently only 20100903 is defined. */ |
|
#ifdef CONFIG_CCSECURITY_AUDIT |
|
|
.preference.audit_max_grant_log = CONFIG_CCSECURITY_MAX_GRANT_LOG, |
|
|
.preference.audit_max_reject_log = CONFIG_CCSECURITY_MAX_REJECT_LOG, |
|
|
#endif |
|
|
.preference.audit_task_info = true, |
|
|
.preference.audit_path_info = true, |
|
|
.preference.enforcing_penalty = 0, |
|
|
.preference.learning_max_entry = CONFIG_CCSECURITY_MAX_ACCEPT_ENTRY, |
|
|
.preference.learning_exec_realpath = true, |
|
|
.preference.learning_exec_argv0 = true, |
|
|
.preference.learning_symlink_target = true, |
|
|
}; |
|
|
|
|
|
/* Profile version. Currently only 20090903 is defined. */ |
|
16 |
static unsigned int ccs_profile_version; |
static unsigned int ccs_profile_version; |
17 |
|
|
18 |
/* Profile table. Memory is allocated as needed. */ |
/* Profile table. Memory is allocated as needed. */ |
19 |
static struct ccs_profile *ccs_profile_ptr[CCS_MAX_PROFILES]; |
static struct ccs_profile *ccs_profile_ptr[CCS_MAX_PROFILES]; |
20 |
|
|
21 |
/* String table for functionality that takes 4 modes. */ |
/* String table for operation mode. */ |
22 |
const char *ccs_mode[CCS_CONFIG_MAX_MODE] = { |
const char * const ccs_mode[CCS_CONFIG_MAX_MODE] = { |
23 |
[CCS_CONFIG_DISABLED] = "disabled", |
[CCS_CONFIG_DISABLED] = "disabled", |
24 |
[CCS_CONFIG_LEARNING] = "learning", |
[CCS_CONFIG_LEARNING] = "learning", |
25 |
[CCS_CONFIG_PERMISSIVE] = "permissive", |
[CCS_CONFIG_PERMISSIVE] = "permissive", |
26 |
[CCS_CONFIG_ENFORCING] = "enforcing" |
[CCS_CONFIG_ENFORCING] = "enforcing" |
27 |
|
}; |
28 |
|
|
29 |
|
/* String table for /proc/ccs/profile interface. */ |
30 |
|
const char * const ccs_mac_keywords[CCS_MAX_MAC_INDEX |
31 |
|
+ CCS_MAX_MAC_CATEGORY_INDEX] = { |
32 |
|
/* CONFIG::file group */ |
33 |
|
[CCS_MAC_FILE_EXECUTE] = "execute", |
34 |
|
[CCS_MAC_FILE_OPEN] = "open", |
35 |
|
[CCS_MAC_FILE_CREATE] = "create", |
36 |
|
[CCS_MAC_FILE_UNLINK] = "unlink", |
37 |
|
[CCS_MAC_FILE_MKDIR] = "mkdir", |
38 |
|
[CCS_MAC_FILE_RMDIR] = "rmdir", |
39 |
|
[CCS_MAC_FILE_MKFIFO] = "mkfifo", |
40 |
|
[CCS_MAC_FILE_MKSOCK] = "mksock", |
41 |
|
[CCS_MAC_FILE_TRUNCATE] = "truncate", |
42 |
|
[CCS_MAC_FILE_SYMLINK] = "symlink", |
43 |
|
[CCS_MAC_FILE_MKBLOCK] = "mkblock", |
44 |
|
[CCS_MAC_FILE_MKCHAR] = "mkchar", |
45 |
|
[CCS_MAC_FILE_LINK] = "link", |
46 |
|
[CCS_MAC_FILE_RENAME] = "rename", |
47 |
|
[CCS_MAC_FILE_CHMOD] = "chmod", |
48 |
|
[CCS_MAC_FILE_CHOWN] = "chown", |
49 |
|
[CCS_MAC_FILE_CHGRP] = "chgrp", |
50 |
|
[CCS_MAC_FILE_IOCTL] = "ioctl", |
51 |
|
[CCS_MAC_FILE_CHROOT] = "chroot", |
52 |
|
[CCS_MAC_FILE_MOUNT] = "mount", |
53 |
|
[CCS_MAC_FILE_UMOUNT] = "unmount", |
54 |
|
[CCS_MAC_FILE_PIVOT_ROOT] = "pivot_root", |
55 |
|
/* CONFIG::misc group */ |
56 |
|
[CCS_MAC_ENVIRON] = "env", |
57 |
|
/* CONFIG::network group */ |
58 |
|
[CCS_MAC_NETWORK_INET_STREAM_BIND] = "inet_stream_bind", |
59 |
|
[CCS_MAC_NETWORK_INET_STREAM_LISTEN] = "inet_stream_listen", |
60 |
|
[CCS_MAC_NETWORK_INET_STREAM_CONNECT] = "inet_stream_connect", |
61 |
|
[CCS_MAC_NETWORK_INET_STREAM_ACCEPT] = "inet_stream_accept", |
62 |
|
[CCS_MAC_NETWORK_INET_DGRAM_BIND] = "inet_dgram_bind", |
63 |
|
[CCS_MAC_NETWORK_INET_DGRAM_SEND] = "inet_dgram_send", |
64 |
|
[CCS_MAC_NETWORK_INET_DGRAM_RECV] = "inet_dgram_recv", |
65 |
|
[CCS_MAC_NETWORK_INET_RAW_BIND] = "inet_raw_bind", |
66 |
|
[CCS_MAC_NETWORK_INET_RAW_SEND] = "inet_raw_send", |
67 |
|
[CCS_MAC_NETWORK_INET_RAW_RECV] = "inet_raw_recv", |
68 |
|
[CCS_MAC_NETWORK_UNIX_STREAM_BIND] = "unix_stream_bind", |
69 |
|
[CCS_MAC_NETWORK_UNIX_STREAM_LISTEN] = "unix_stream_listen", |
70 |
|
[CCS_MAC_NETWORK_UNIX_STREAM_CONNECT] = "unix_stream_connect", |
71 |
|
[CCS_MAC_NETWORK_UNIX_STREAM_ACCEPT] = "unix_stream_accept", |
72 |
|
[CCS_MAC_NETWORK_UNIX_DGRAM_BIND] = "unix_dgram_bind", |
73 |
|
[CCS_MAC_NETWORK_UNIX_DGRAM_SEND] = "unix_dgram_send", |
74 |
|
[CCS_MAC_NETWORK_UNIX_DGRAM_RECV] = "unix_dgram_recv", |
75 |
|
[CCS_MAC_NETWORK_UNIX_SEQPACKET_BIND] = "unix_seqpacket_bind", |
76 |
|
[CCS_MAC_NETWORK_UNIX_SEQPACKET_LISTEN] = "unix_seqpacket_listen", |
77 |
|
[CCS_MAC_NETWORK_UNIX_SEQPACKET_CONNECT] = "unix_seqpacket_connect", |
78 |
|
[CCS_MAC_NETWORK_UNIX_SEQPACKET_ACCEPT] = "unix_seqpacket_accept", |
79 |
|
/* CONFIG::ipc group */ |
80 |
|
[CCS_MAC_SIGNAL] = "signal", |
81 |
|
/* CONFIG::capability group */ |
82 |
|
[CCS_MAC_CAPABILITY_USE_ROUTE_SOCKET] = "use_route", |
83 |
|
[CCS_MAC_CAPABILITY_USE_PACKET_SOCKET] = "use_packet", |
84 |
|
[CCS_MAC_CAPABILITY_SYS_REBOOT] = "SYS_REBOOT", |
85 |
|
[CCS_MAC_CAPABILITY_SYS_VHANGUP] = "SYS_VHANGUP", |
86 |
|
[CCS_MAC_CAPABILITY_SYS_SETTIME] = "SYS_TIME", |
87 |
|
[CCS_MAC_CAPABILITY_SYS_NICE] = "SYS_NICE", |
88 |
|
[CCS_MAC_CAPABILITY_SYS_SETHOSTNAME] = "SYS_SETHOSTNAME", |
89 |
|
[CCS_MAC_CAPABILITY_USE_KERNEL_MODULE] = "use_kernel_module", |
90 |
|
[CCS_MAC_CAPABILITY_SYS_KEXEC_LOAD] = "SYS_KEXEC_LOAD", |
91 |
|
[CCS_MAC_CAPABILITY_SYS_PTRACE] = "SYS_PTRACE", |
92 |
|
/* CONFIG group */ |
93 |
|
[CCS_MAX_MAC_INDEX + CCS_MAC_CATEGORY_FILE] = "file", |
94 |
|
[CCS_MAX_MAC_INDEX + CCS_MAC_CATEGORY_NETWORK] = "network", |
95 |
|
[CCS_MAX_MAC_INDEX + CCS_MAC_CATEGORY_MISC] = "misc", |
96 |
|
[CCS_MAX_MAC_INDEX + CCS_MAC_CATEGORY_IPC] = "ipc", |
97 |
|
[CCS_MAX_MAC_INDEX + CCS_MAC_CATEGORY_CAPABILITY] = "capability", |
98 |
|
}; |
99 |
|
|
100 |
|
/* String table for path operation. */ |
101 |
|
const char * const ccs_path_keyword[CCS_MAX_PATH_OPERATION] = { |
102 |
|
[CCS_TYPE_EXECUTE] = "execute", |
103 |
|
[CCS_TYPE_READ] = "read", |
104 |
|
[CCS_TYPE_WRITE] = "write", |
105 |
|
[CCS_TYPE_APPEND] = "append", |
106 |
|
[CCS_TYPE_UNLINK] = "unlink", |
107 |
|
[CCS_TYPE_RMDIR] = "rmdir", |
108 |
|
[CCS_TYPE_TRUNCATE] = "truncate", |
109 |
|
[CCS_TYPE_SYMLINK] = "symlink", |
110 |
|
[CCS_TYPE_CHROOT] = "chroot", |
111 |
|
[CCS_TYPE_UMOUNT] = "unmount", |
112 |
|
}; |
113 |
|
|
114 |
|
/* String table for categories. */ |
115 |
|
static const char * const ccs_category_keywords[CCS_MAX_MAC_CATEGORY_INDEX] = { |
116 |
|
[CCS_MAC_CATEGORY_FILE] = "file", |
117 |
|
[CCS_MAC_CATEGORY_NETWORK] = "network", |
118 |
|
[CCS_MAC_CATEGORY_MISC] = "misc", |
119 |
|
[CCS_MAC_CATEGORY_IPC] = "ipc", |
120 |
|
[CCS_MAC_CATEGORY_CAPABILITY] = "capability", |
121 |
}; |
}; |
122 |
|
|
123 |
/* String table for /proc/ccs/profile */ |
/* String table for conditions. */ |
124 |
static const char *ccs_mac_keywords[CCS_MAX_MAC_INDEX + |
const char * const ccs_condition_keyword[CCS_MAX_CONDITION_KEYWORD] = { |
125 |
CCS_MAX_CAPABILITY_INDEX + |
[CCS_TASK_UID] = "task.uid", |
126 |
CCS_MAX_MAC_CATEGORY_INDEX] = { |
[CCS_TASK_EUID] = "task.euid", |
127 |
[CCS_MAC_FILE_EXECUTE] |
[CCS_TASK_SUID] = "task.suid", |
128 |
= "file::execute", |
[CCS_TASK_FSUID] = "task.fsuid", |
129 |
[CCS_MAC_FILE_OPEN] |
[CCS_TASK_GID] = "task.gid", |
130 |
= "file::open", |
[CCS_TASK_EGID] = "task.egid", |
131 |
[CCS_MAC_FILE_CREATE] |
[CCS_TASK_SGID] = "task.sgid", |
132 |
= "file::create", |
[CCS_TASK_FSGID] = "task.fsgid", |
133 |
[CCS_MAC_FILE_UNLINK] |
[CCS_TASK_PID] = "task.pid", |
134 |
= "file::unlink", |
[CCS_TASK_PPID] = "task.ppid", |
135 |
[CCS_MAC_FILE_MKDIR] |
[CCS_EXEC_ARGC] = "exec.argc", |
136 |
= "file::mkdir", |
[CCS_EXEC_ENVC] = "exec.envc", |
137 |
[CCS_MAC_FILE_RMDIR] |
[CCS_TYPE_IS_SOCKET] = "socket", |
138 |
= "file::rmdir", |
[CCS_TYPE_IS_SYMLINK] = "symlink", |
139 |
[CCS_MAC_FILE_MKFIFO] |
[CCS_TYPE_IS_FILE] = "file", |
140 |
= "file::mkfifo", |
[CCS_TYPE_IS_BLOCK_DEV] = "block", |
141 |
[CCS_MAC_FILE_MKSOCK] |
[CCS_TYPE_IS_DIRECTORY] = "directory", |
142 |
= "file::mksock", |
[CCS_TYPE_IS_CHAR_DEV] = "char", |
143 |
[CCS_MAC_FILE_TRUNCATE] |
[CCS_TYPE_IS_FIFO] = "fifo", |
144 |
= "file::truncate", |
[CCS_MODE_SETUID] = "setuid", |
145 |
[CCS_MAC_FILE_SYMLINK] |
[CCS_MODE_SETGID] = "setgid", |
146 |
= "file::symlink", |
[CCS_MODE_STICKY] = "sticky", |
147 |
[CCS_MAC_FILE_MKBLOCK] |
[CCS_MODE_OWNER_READ] = "owner_read", |
148 |
= "file::mkblock", |
[CCS_MODE_OWNER_WRITE] = "owner_write", |
149 |
[CCS_MAC_FILE_MKCHAR] |
[CCS_MODE_OWNER_EXECUTE] = "owner_execute", |
150 |
= "file::mkchar", |
[CCS_MODE_GROUP_READ] = "group_read", |
151 |
[CCS_MAC_FILE_LINK] |
[CCS_MODE_GROUP_WRITE] = "group_write", |
152 |
= "file::link", |
[CCS_MODE_GROUP_EXECUTE] = "group_execute", |
153 |
[CCS_MAC_FILE_RENAME] |
[CCS_MODE_OTHERS_READ] = "others_read", |
154 |
= "file::rename", |
[CCS_MODE_OTHERS_WRITE] = "others_write", |
155 |
[CCS_MAC_FILE_CHMOD] |
[CCS_MODE_OTHERS_EXECUTE] = "others_execute", |
156 |
= "file::chmod", |
[CCS_TASK_TYPE] = "task.type", |
157 |
[CCS_MAC_FILE_CHOWN] |
[CCS_TASK_EXECUTE_HANDLER] = "execute_handler", |
158 |
= "file::chown", |
[CCS_EXEC_REALPATH] = "exec.realpath", |
159 |
[CCS_MAC_FILE_CHGRP] |
[CCS_SYMLINK_TARGET] = "symlink.target", |
160 |
= "file::chgrp", |
[CCS_PATH1_UID] = "path1.uid", |
161 |
[CCS_MAC_FILE_IOCTL] |
[CCS_PATH1_GID] = "path1.gid", |
162 |
= "file::ioctl", |
[CCS_PATH1_INO] = "path1.ino", |
163 |
[CCS_MAC_FILE_CHROOT] |
[CCS_PATH1_MAJOR] = "path1.major", |
164 |
= "file::chroot", |
[CCS_PATH1_MINOR] = "path1.minor", |
165 |
[CCS_MAC_FILE_MOUNT] |
[CCS_PATH1_PERM] = "path1.perm", |
166 |
= "file::mount", |
[CCS_PATH1_TYPE] = "path1.type", |
167 |
[CCS_MAC_FILE_UMOUNT] |
[CCS_PATH1_DEV_MAJOR] = "path1.dev_major", |
168 |
= "file::umount", |
[CCS_PATH1_DEV_MINOR] = "path1.dev_minor", |
169 |
[CCS_MAC_FILE_PIVOT_ROOT] |
[CCS_PATH2_UID] = "path2.uid", |
170 |
= "file::pivot_root", |
[CCS_PATH2_GID] = "path2.gid", |
171 |
[CCS_MAC_FILE_TRANSIT] |
[CCS_PATH2_INO] = "path2.ino", |
172 |
= "file::transit", |
[CCS_PATH2_MAJOR] = "path2.major", |
173 |
[CCS_MAC_ENVIRON] |
[CCS_PATH2_MINOR] = "path2.minor", |
174 |
= "misc::env", |
[CCS_PATH2_PERM] = "path2.perm", |
175 |
[CCS_MAC_NETWORK_INET_TCP_BIND] |
[CCS_PATH2_TYPE] = "path2.type", |
176 |
= "network::inet_tcp_bind", |
[CCS_PATH2_DEV_MAJOR] = "path2.dev_major", |
177 |
[CCS_MAC_NETWORK_INET_TCP_LISTEN] |
[CCS_PATH2_DEV_MINOR] = "path2.dev_minor", |
178 |
= "network::inet_tcp_listen", |
[CCS_PATH1_PARENT_UID] = "path1.parent.uid", |
179 |
[CCS_MAC_NETWORK_INET_TCP_CONNECT] |
[CCS_PATH1_PARENT_GID] = "path1.parent.gid", |
180 |
= "network::inet_tcp_connect", |
[CCS_PATH1_PARENT_INO] = "path1.parent.ino", |
181 |
[CCS_MAC_NETWORK_INET_TCP_ACCEPT] |
[CCS_PATH1_PARENT_PERM] = "path1.parent.perm", |
182 |
= "network::inet_tcp_accept", |
[CCS_PATH2_PARENT_UID] = "path2.parent.uid", |
183 |
[CCS_MAC_NETWORK_INET_UDP_BIND] |
[CCS_PATH2_PARENT_GID] = "path2.parent.gid", |
184 |
= "network::inet_udp_bind", |
[CCS_PATH2_PARENT_INO] = "path2.parent.ino", |
185 |
[CCS_MAC_NETWORK_INET_UDP_SEND] |
[CCS_PATH2_PARENT_PERM] = "path2.parent.perm", |
186 |
= "network::inet_udp_send", |
}; |
187 |
[CCS_MAC_NETWORK_INET_UDP_RECV] |
|
188 |
= "network::inet_udp_recv", |
/* String table for PREFERENCE keyword. */ |
189 |
[CCS_MAC_NETWORK_INET_RAW_BIND] |
static const char * const ccs_pref_keywords[CCS_MAX_PREF] = { |
190 |
= "network::inet_raw_bind", |
[CCS_PREF_MAX_GRANT_LOG] = "max_grant_log", |
191 |
[CCS_MAC_NETWORK_INET_RAW_SEND] |
[CCS_PREF_MAX_REJECT_LOG] = "max_reject_log", |
192 |
= "network::inet_raw_send", |
[CCS_PREF_MAX_LEARNING_ENTRY] = "max_learning_entry", |
193 |
[CCS_MAC_NETWORK_INET_RAW_RECV] |
[CCS_PREF_ENFORCING_PENALTY] = "enforcing_penalty", |
|
= "network::inet_raw_recv", |
|
|
[CCS_MAC_NETWORK_UNIX_STREAM_BIND] |
|
|
= "network::unix_stream_bind", |
|
|
[CCS_MAC_NETWORK_UNIX_STREAM_LISTEN] |
|
|
= "network::unix_stream_listen", |
|
|
[CCS_MAC_NETWORK_UNIX_STREAM_CONNECT] |
|
|
= "network::unix_stream_connect", |
|
|
[CCS_MAC_NETWORK_UNIX_STREAM_ACCEPT] |
|
|
= "network::unix_stream_accept", |
|
|
[CCS_MAC_NETWORK_UNIX_DGRAM_BIND] |
|
|
= "network::unix_dgram_bind", |
|
|
[CCS_MAC_NETWORK_UNIX_DGRAM_SEND] |
|
|
= "network::unix_dgram_send", |
|
|
[CCS_MAC_NETWORK_UNIX_DGRAM_RECV] |
|
|
= "network::unix_dgram_recv", |
|
|
[CCS_MAC_NETWORK_UNIX_SEQPACKET_BIND] |
|
|
= "network::unix_seqpacket_bind", |
|
|
[CCS_MAC_NETWORK_UNIX_SEQPACKET_LISTEN] |
|
|
= "network::unix_seqpacket_listen", |
|
|
[CCS_MAC_NETWORK_UNIX_SEQPACKET_CONNECT] |
|
|
= "network::unix_seqpacket_connect", |
|
|
[CCS_MAC_NETWORK_UNIX_SEQPACKET_ACCEPT] |
|
|
= "network::unix_seqpacket_accept", |
|
|
[CCS_MAC_SIGNAL] |
|
|
= "ipc::signal", |
|
|
[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_REBOOT] |
|
|
= "capability::SYS_REBOOT", |
|
|
[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_SYS_KEXEC_LOAD] |
|
|
= "capability::SYS_KEXEC_LOAD", |
|
|
[CCS_MAX_MAC_INDEX + CCS_SYS_PTRACE] |
|
|
= "capability::SYS_PTRACE", |
|
|
[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", |
|
194 |
}; |
}; |
195 |
|
|
196 |
/* Permit policy management by non-root user? */ |
/* Permit policy management by non-root user? */ |
197 |
static bool ccs_manage_by_non_root; |
static bool ccs_manage_by_non_root; |
198 |
|
|
199 |
/** |
/** |
|
* ccs_cap2keyword - Convert capability operation to capability name. |
|
|
* |
|
|
* @operation: The capability index. |
|
|
* |
|
|
* Returns the name of the specified capability's name. |
|
|
*/ |
|
|
const char *ccs_cap2keyword(const u8 operation) |
|
|
{ |
|
|
return operation < CCS_MAX_CAPABILITY_INDEX |
|
|
? ccs_mac_keywords[CCS_MAX_MAC_INDEX + operation] + 12 : NULL; |
|
|
} |
|
|
|
|
|
/** |
|
200 |
* ccs_yesno - Return "yes" or "no". |
* ccs_yesno - Return "yes" or "no". |
201 |
* |
* |
202 |
* @value: Bool value. |
* @value: Bool value. |
203 |
|
* |
204 |
|
* Returns "yes" if @value is not 0, "no" otherwise. |
205 |
*/ |
*/ |
206 |
static const char *ccs_yesno(const unsigned int value) |
static const char *ccs_yesno(const unsigned int value) |
207 |
{ |
{ |
208 |
return value ? "yes" : "no"; |
return value ? "yes" : "no"; |
209 |
} |
} |
210 |
|
|
211 |
|
/* Prototype fpr ccs_addprintf(). */ |
212 |
|
static void ccs_addprintf(char *buffer, int len, const char *fmt, ...) |
213 |
|
__attribute__ ((format(printf, 3, 4))); |
214 |
|
|
215 |
|
/** |
216 |
|
* ccs_addprintf - snprint()-like-strncat(). |
217 |
|
* |
218 |
|
* @buffer: Buffer to write to. Must be '\0'-terminated. |
219 |
|
* @len: Size of @buffer. |
220 |
|
* @fmt: The printf()'s format string, followed by parameters. |
221 |
|
* |
222 |
|
* Returns nothing. |
223 |
|
*/ |
224 |
static void ccs_addprintf(char *buffer, int len, const char *fmt, ...) |
static void ccs_addprintf(char *buffer, int len, const char *fmt, ...) |
225 |
{ |
{ |
226 |
va_list args; |
va_list args; |
233 |
/** |
/** |
234 |
* ccs_flush - Flush queued string to userspace's buffer. |
* ccs_flush - Flush queued string to userspace's buffer. |
235 |
* |
* |
236 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
237 |
* |
* |
238 |
* Returns true if all data was flushed, false otherwise. |
* Returns true if all data was flushed, false otherwise. |
239 |
*/ |
*/ |
282 |
* Note that @string has to be kept valid until @head is kfree()d. |
* Note that @string has to be kept valid until @head is kfree()d. |
283 |
* This means that char[] allocated on stack memory cannot be passed to |
* This means that char[] allocated on stack memory cannot be passed to |
284 |
* this function. Use ccs_io_printf() for char[] allocated on stack memory. |
* this function. Use ccs_io_printf() for char[] allocated on stack memory. |
285 |
|
* |
286 |
|
* Returns nothing. |
287 |
*/ |
*/ |
288 |
static void ccs_set_string(struct ccs_io_buffer *head, const char *string) |
static void ccs_set_string(struct ccs_io_buffer *head, const char *string) |
289 |
{ |
{ |
299 |
* |
* |
300 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
301 |
* @fmt: The printf()'s format string, followed by parameters. |
* @fmt: The printf()'s format string, followed by parameters. |
302 |
|
* |
303 |
|
* Returns nothing. |
304 |
*/ |
*/ |
305 |
void ccs_io_printf(struct ccs_io_buffer *head, const char *fmt, ...) |
void ccs_io_printf(struct ccs_io_buffer *head, const char *fmt, ...) |
306 |
{ |
{ |
321 |
ccs_set_string(head, head->read_buf + pos); |
ccs_set_string(head, head->read_buf + pos); |
322 |
} |
} |
323 |
|
|
324 |
|
/** |
325 |
|
* ccs_set_space - Put a space to "struct ccs_io_buffer" structure. |
326 |
|
* |
327 |
|
* @head: Pointer to "struct ccs_io_buffer". |
328 |
|
* |
329 |
|
* Returns nothing. |
330 |
|
*/ |
331 |
static void ccs_set_space(struct ccs_io_buffer *head) |
static void ccs_set_space(struct ccs_io_buffer *head) |
332 |
{ |
{ |
333 |
ccs_set_string(head, " "); |
ccs_set_string(head, " "); |
334 |
} |
} |
335 |
|
|
336 |
|
/** |
337 |
|
* ccs_set_lf - Put a line feed to "struct ccs_io_buffer" structure. |
338 |
|
* |
339 |
|
* @head: Pointer to "struct ccs_io_buffer". |
340 |
|
* |
341 |
|
* Returns nothing. |
342 |
|
*/ |
343 |
static bool ccs_set_lf(struct ccs_io_buffer *head) |
static bool ccs_set_lf(struct ccs_io_buffer *head) |
344 |
{ |
{ |
345 |
ccs_set_string(head, "\n"); |
ccs_set_string(head, "\n"); |
369 |
if (!ptr && ccs_memory_ok(entry, sizeof(*entry))) { |
if (!ptr && ccs_memory_ok(entry, sizeof(*entry))) { |
370 |
ptr = entry; |
ptr = entry; |
371 |
ptr->default_config = CCS_CONFIG_DISABLED | |
ptr->default_config = CCS_CONFIG_DISABLED | |
|
CCS_CONFIG_VERBOSE | |
|
372 |
CCS_CONFIG_WANT_GRANT_LOG | CCS_CONFIG_WANT_REJECT_LOG; |
CCS_CONFIG_WANT_GRANT_LOG | CCS_CONFIG_WANT_REJECT_LOG; |
373 |
memset(ptr->config, CCS_CONFIG_USE_DEFAULT, |
memset(ptr->config, CCS_CONFIG_USE_DEFAULT, |
374 |
sizeof(ptr->config)); |
sizeof(ptr->config)); |
375 |
|
ptr->pref[CCS_PREF_MAX_GRANT_LOG] = |
376 |
|
CONFIG_CCSECURITY_MAX_GRANT_LOG; |
377 |
|
ptr->pref[CCS_PREF_MAX_REJECT_LOG] = |
378 |
|
CONFIG_CCSECURITY_MAX_REJECT_LOG; |
379 |
|
ptr->pref[CCS_PREF_MAX_LEARNING_ENTRY] = |
380 |
|
CONFIG_CCSECURITY_MAX_ACCEPT_ENTRY; |
381 |
mb(); /* Avoid out-of-order execution. */ |
mb(); /* Avoid out-of-order execution. */ |
382 |
ccs_profile_ptr[profile] = ptr; |
ccs_profile_ptr[profile] = ptr; |
383 |
entry = NULL; |
entry = NULL; |
384 |
} |
} |
385 |
mutex_unlock(&ccs_policy_lock); |
mutex_unlock(&ccs_policy_lock); |
386 |
out: |
out: |
387 |
kfree(entry); |
kfree(entry); |
388 |
return ptr; |
return ptr; |
389 |
} |
} |
390 |
|
|
391 |
/** |
/** |
392 |
* ccs_check_profile - Check all profiles currently assigned to domains are defined. |
* ccs_check_profile - Check all profiles currently assigned to domains are defined. |
393 |
|
* |
394 |
|
* Returns nothing. |
395 |
*/ |
*/ |
396 |
static void ccs_check_profile(void) |
static void ccs_check_profile(void) |
397 |
{ |
{ |
398 |
struct ccs_domain_info *domain; |
struct ccs_domain_info *domain; |
399 |
const int idx = ccs_read_lock(); |
const int idx = ccs_read_lock(); |
400 |
ccs_policy_loaded = true; |
ccs_policy_loaded = true; |
401 |
list_for_each_entry_rcu(domain, &ccs_domain_list, list) { |
list_for_each_entry_srcu(domain, &ccs_domain_list, list, &ccs_ss) { |
402 |
const u8 profile = domain->profile; |
const u8 profile = domain->profile; |
403 |
if (ccs_profile_ptr[profile]) |
if (ccs_profile_ptr[profile]) |
404 |
continue; |
continue; |
405 |
|
printk(KERN_ERR "You need to define profile %u before using it.\n", |
406 |
|
profile); |
407 |
|
printk(KERN_ERR "Please see http://tomoyo.sourceforge.jp/1.8/ " |
408 |
|
"for more information.\n"); |
409 |
panic("Profile %u (used by '%s') not defined.\n", |
panic("Profile %u (used by '%s') not defined.\n", |
410 |
profile, domain->domainname->name); |
profile, domain->domainname->name); |
411 |
} |
} |
412 |
ccs_read_unlock(idx); |
ccs_read_unlock(idx); |
413 |
if (ccs_profile_version != 20090903) |
if (ccs_profile_version != 20100903) { |
414 |
|
printk(KERN_ERR "You need to install userland programs for " |
415 |
|
"TOMOYO 1.8 and initialize policy configuration.\n"); |
416 |
|
printk(KERN_ERR "Please see http://tomoyo.sourceforge.jp/1.8/ " |
417 |
|
"for more information.\n"); |
418 |
panic("Profile version %u is not supported.\n", |
panic("Profile version %u is not supported.\n", |
419 |
ccs_profile_version); |
ccs_profile_version); |
420 |
printk(KERN_INFO "CCSecurity: 1.8.0-pre 2010/08/01\n"); |
} |
421 |
|
printk(KERN_INFO "CCSecurity: 1.8.0-pre 2010/10/18\n"); |
422 |
printk(KERN_INFO "Mandatory Access Control activated.\n"); |
printk(KERN_INFO "Mandatory Access Control activated.\n"); |
423 |
} |
} |
424 |
|
|
431 |
*/ |
*/ |
432 |
struct ccs_profile *ccs_profile(const u8 profile) |
struct ccs_profile *ccs_profile(const u8 profile) |
433 |
{ |
{ |
434 |
|
static struct ccs_profile ccs_null_profile; |
435 |
struct ccs_profile *ptr = ccs_profile_ptr[profile]; |
struct ccs_profile *ptr = ccs_profile_ptr[profile]; |
436 |
if (!ccs_policy_loaded) |
if (!ptr) |
437 |
return &ccs_default_profile; |
ptr = &ccs_null_profile; |
|
BUG_ON(!ptr); |
|
438 |
return ptr; |
return ptr; |
439 |
} |
} |
440 |
|
|
441 |
|
/** |
442 |
|
* ccs_find_yesno - Find values for specified keyword. |
443 |
|
* |
444 |
|
* @string: String to check. |
445 |
|
* @find: Name of keyword. |
446 |
|
* |
447 |
|
* Returns 1 if "@find=yes" was found, 0 if "@find=no" was found, -1 otherwise. |
448 |
|
*/ |
449 |
static s8 ccs_find_yesno(const char *string, const char *find) |
static s8 ccs_find_yesno(const char *string, const char *find) |
450 |
{ |
{ |
451 |
const char *cp = strstr(string, find); |
const char *cp = strstr(string, find); |
459 |
return -1; |
return -1; |
460 |
} |
} |
461 |
|
|
462 |
static void ccs_set_bool(bool *b, const char *string, const char *find) |
/** |
463 |
{ |
* ccs_set_uint - Set value for specified preference. |
464 |
switch (ccs_find_yesno(string, find)) { |
* |
465 |
case 1: |
* @i: Pointer to "unsigned int". |
466 |
*b = true; |
* @string: String to check. |
467 |
break; |
* @find: Name of keyword. |
468 |
case 0: |
* |
469 |
*b = false; |
* Returns nothing. |
470 |
break; |
*/ |
|
} |
|
|
} |
|
|
|
|
471 |
static void ccs_set_uint(unsigned int *i, const char *string, const char *find) |
static void ccs_set_uint(unsigned int *i, const char *string, const char *find) |
472 |
{ |
{ |
473 |
const char *cp = strstr(string, find); |
const char *cp = strstr(string, find); |
475 |
sscanf(cp + strlen(find), "=%u", i); |
sscanf(cp + strlen(find), "=%u", i); |
476 |
} |
} |
477 |
|
|
478 |
static void ccs_set_pref(const char *name, const char *value, |
/** |
479 |
struct ccs_profile *profile) |
* ccs_set_mode - Set mode for specified profile. |
480 |
{ |
* |
481 |
if (!strcmp(name, "audit")) { |
* @name: Name of functionality. |
482 |
#ifdef CONFIG_CCSECURITY_AUDIT |
* @value: Mode for @name. |
483 |
ccs_set_uint(&profile->preference.audit_max_grant_log, value, |
* @profile: Pointer to "struct ccs_profile". |
484 |
"max_grant_log"); |
* |
485 |
ccs_set_uint(&profile->preference.audit_max_reject_log, value, |
* Returns 0 on success, negative value otherwise. |
486 |
"max_reject_log"); |
*/ |
|
#endif |
|
|
ccs_set_bool(&profile->preference.audit_task_info, value, |
|
|
"task_info"); |
|
|
ccs_set_bool(&profile->preference.audit_path_info, value, |
|
|
"path_info"); |
|
|
return; |
|
|
} |
|
|
if (!strcmp(name, "enforcing")) { |
|
|
ccs_set_uint(&profile->preference.enforcing_penalty, value, |
|
|
"penalty"); |
|
|
return; |
|
|
} |
|
|
if (!strcmp(name, "learning")) { |
|
|
ccs_set_uint(&profile->preference.learning_max_entry, value, |
|
|
"max_entry"); |
|
|
ccs_set_bool(&profile->preference.learning_exec_realpath, |
|
|
value, "exec.realpath"); |
|
|
ccs_set_bool(&profile->preference.learning_exec_argv0, value, |
|
|
"exec.argv0"); |
|
|
ccs_set_bool(&profile->preference.learning_symlink_target, |
|
|
value, "symlink.target"); |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
487 |
static int ccs_set_mode(char *name, const char *value, |
static int ccs_set_mode(char *name, const char *value, |
488 |
struct ccs_profile *profile) |
struct ccs_profile *profile) |
489 |
{ |
{ |
490 |
u8 i; |
u8 i; |
491 |
u8 config; |
u8 config; |
492 |
if (!strcmp(name, "CONFIG")) { |
if (!strcmp(name, "CONFIG")) { |
493 |
i = CCS_MAX_MAC_INDEX + CCS_MAX_CAPABILITY_INDEX |
i = CCS_MAX_MAC_INDEX + CCS_MAX_MAC_CATEGORY_INDEX; |
|
+ CCS_MAX_MAC_CATEGORY_INDEX; |
|
494 |
config = profile->default_config; |
config = profile->default_config; |
495 |
} else if (ccs_str_starts(&name, "CONFIG::")) { |
} else if (ccs_str_starts(&name, "CONFIG::")) { |
496 |
config = 0; |
config = 0; |
497 |
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; |
498 |
+ CCS_MAX_MAC_CATEGORY_INDEX; i++) { |
i++) { |
499 |
if (strcmp(name, ccs_mac_keywords[i])) |
int len = 0; |
500 |
|
if (i < CCS_MAX_MAC_INDEX) { |
501 |
|
const u8 c = ccs_index2category[i]; |
502 |
|
const char *category = |
503 |
|
ccs_category_keywords[c]; |
504 |
|
len = strlen(category); |
505 |
|
if (strncmp(name, category, len) || |
506 |
|
name[len++] != ':' || name[len++] != ':') |
507 |
|
continue; |
508 |
|
} |
509 |
|
if (strcmp(name + len, ccs_mac_keywords[i])) |
510 |
continue; |
continue; |
511 |
config = profile->config[i]; |
config = profile->config[i]; |
512 |
break; |
break; |
513 |
} |
} |
514 |
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) |
|
515 |
return -EINVAL; |
return -EINVAL; |
516 |
} else { |
} else { |
517 |
return -EINVAL; |
return -EINVAL; |
528 |
*/ |
*/ |
529 |
config = (config & ~7) | mode; |
config = (config & ~7) | mode; |
530 |
if (config != CCS_CONFIG_USE_DEFAULT) { |
if (config != CCS_CONFIG_USE_DEFAULT) { |
|
switch (ccs_find_yesno(value, "verbose")) { |
|
|
case 1: |
|
|
config |= CCS_CONFIG_VERBOSE; |
|
|
break; |
|
|
case 0: |
|
|
config &= ~CCS_CONFIG_VERBOSE; |
|
|
break; |
|
|
} |
|
|
#ifdef CONFIG_CCSECURITY_AUDIT |
|
531 |
switch (ccs_find_yesno(value, "grant_log")) { |
switch (ccs_find_yesno(value, "grant_log")) { |
532 |
case 1: |
case 1: |
533 |
config |= CCS_CONFIG_WANT_GRANT_LOG; |
config |= CCS_CONFIG_WANT_GRANT_LOG; |
544 |
config &= ~CCS_CONFIG_WANT_REJECT_LOG; |
config &= ~CCS_CONFIG_WANT_REJECT_LOG; |
545 |
break; |
break; |
546 |
} |
} |
|
#endif |
|
547 |
} |
} |
548 |
} |
} |
549 |
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) |
|
550 |
profile->config[i] = config; |
profile->config[i] = config; |
551 |
else if (config != CCS_CONFIG_USE_DEFAULT) |
else if (config != CCS_CONFIG_USE_DEFAULT) |
552 |
profile->default_config = config; |
profile->default_config = config; |
579 |
if (!cp) |
if (!cp) |
580 |
return -EINVAL; |
return -EINVAL; |
581 |
*cp++ = '\0'; |
*cp++ = '\0'; |
|
if (ccs_str_starts(&data, "PREFERENCE::")) { |
|
|
ccs_set_pref(data, cp, profile); |
|
|
return 0; |
|
|
} |
|
582 |
if (!strcmp(data, "COMMENT")) { |
if (!strcmp(data, "COMMENT")) { |
583 |
const struct ccs_path_info *old_comment = profile->comment; |
const struct ccs_path_info *old_comment = profile->comment; |
584 |
profile->comment = ccs_get_name(cp); |
profile->comment = ccs_get_name(cp); |
585 |
ccs_put_name(old_comment); |
ccs_put_name(old_comment); |
586 |
return 0; |
return 0; |
587 |
} |
} |
588 |
|
if (!strcmp(data, "PREFERENCE")) { |
589 |
|
for (i = 0; i < CCS_MAX_PREF; i++) |
590 |
|
ccs_set_uint(&profile->pref[i], cp, |
591 |
|
ccs_pref_keywords[i]); |
592 |
|
return 0; |
593 |
|
} |
594 |
return ccs_set_mode(data, cp, profile); |
return ccs_set_mode(data, cp, profile); |
595 |
} |
} |
596 |
|
|
597 |
static void ccs_print_preference(struct ccs_io_buffer *head, const int index) |
/** |
598 |
{ |
* ccs_print_config - Print mode for specified functionality. |
599 |
struct ccs_profile *profile = ccs_profile_ptr[index]; |
* |
600 |
struct ccs_preference *pref = &profile->preference; |
* @head: Pointer to "struct ccs_io_buffer". |
601 |
ccs_io_printf(head, "%u-PREFERENCE::%s={ " |
* @config: Mode for that functionality. |
602 |
#ifdef CONFIG_CCSECURITY_AUDIT |
* |
603 |
"max_grant_log=%u max_reject_log=%u " |
* Returns nothing. |
604 |
#endif |
* |
605 |
"task_info=%s path_info=%s }\n", index, |
* Caller prints functionality's name. |
606 |
"audit", |
*/ |
|
#ifdef CONFIG_CCSECURITY_AUDIT |
|
|
pref->audit_max_grant_log, |
|
|
pref->audit_max_reject_log, |
|
|
#endif |
|
|
ccs_yesno(pref->audit_task_info), |
|
|
ccs_yesno(pref->audit_path_info)); |
|
|
ccs_io_printf(head, "%u-PREFERENCE::%s={ " |
|
|
"max_entry=%u exec.realpath=%s " |
|
|
"exec.argv0=%s symlink.target=%s }\n", |
|
|
index, "learning", |
|
|
pref->learning_max_entry, |
|
|
ccs_yesno(pref->learning_exec_realpath), |
|
|
ccs_yesno(pref->learning_exec_argv0), |
|
|
ccs_yesno(pref->learning_symlink_target)); |
|
|
ccs_io_printf(head, "%u-PREFERENCE::%s={ penalty=%u }\n", index, |
|
|
"enforcing", pref->enforcing_penalty); |
|
|
} |
|
|
|
|
607 |
static void ccs_print_config(struct ccs_io_buffer *head, const u8 config) |
static void ccs_print_config(struct ccs_io_buffer *head, const u8 config) |
608 |
{ |
{ |
609 |
ccs_io_printf(head, "={ mode=%s verbose=%s", ccs_mode[config & 3], |
ccs_io_printf(head, "={ mode=%s grant_log=%s reject_log=%s }\n", |
610 |
ccs_yesno(config & CCS_CONFIG_VERBOSE)); |
ccs_mode[config & 3], |
|
#ifdef CONFIG_CCSECURITY_AUDIT |
|
|
ccs_io_printf(head, " grant_log=%s reject_log=%s", |
|
611 |
ccs_yesno(config & CCS_CONFIG_WANT_GRANT_LOG), |
ccs_yesno(config & CCS_CONFIG_WANT_GRANT_LOG), |
612 |
ccs_yesno(config & CCS_CONFIG_WANT_REJECT_LOG)); |
ccs_yesno(config & CCS_CONFIG_WANT_REJECT_LOG)); |
|
#endif |
|
|
ccs_set_string(head, " }\n"); |
|
613 |
} |
} |
614 |
|
|
615 |
/** |
/** |
621 |
{ |
{ |
622 |
u8 index; |
u8 index; |
623 |
const struct ccs_profile *profile; |
const struct ccs_profile *profile; |
624 |
next: |
next: |
625 |
index = head->r.index; |
index = head->r.index; |
626 |
profile = ccs_profile_ptr[index]; |
profile = ccs_profile_ptr[index]; |
627 |
switch (head->r.step) { |
switch (head->r.step) { |
628 |
case 0: |
case 0: |
629 |
ccs_io_printf(head, "PROFILE_VERSION=%s\n", "20090903"); |
ccs_io_printf(head, "PROFILE_VERSION=%s\n", "20100903"); |
630 |
head->r.step++; |
head->r.step++; |
631 |
break; |
break; |
632 |
case 1: |
case 1: |
640 |
break; |
break; |
641 |
case 2: |
case 2: |
642 |
{ |
{ |
643 |
|
u8 i; |
644 |
const struct ccs_path_info *comment = profile->comment; |
const struct ccs_path_info *comment = profile->comment; |
645 |
ccs_io_printf(head, "%u-COMMENT=", index); |
ccs_io_printf(head, "%u-COMMENT=", index); |
646 |
ccs_set_string(head, comment ? comment->name : ""); |
ccs_set_string(head, comment ? comment->name : ""); |
647 |
ccs_set_lf(head); |
ccs_set_lf(head); |
648 |
|
ccs_io_printf(head, "%u-PREFERENCE={ ", index); |
649 |
|
for (i = 0; i < CCS_MAX_PREF; i++) |
650 |
|
ccs_io_printf(head, "%s=%u ", |
651 |
|
ccs_pref_keywords[i], |
652 |
|
profile->pref[i]); |
653 |
|
ccs_set_string(head, " }\n"); |
654 |
head->r.step++; |
head->r.step++; |
655 |
} |
} |
656 |
break; |
break; |
664 |
break; |
break; |
665 |
case 4: |
case 4: |
666 |
for ( ; head->r.bit < CCS_MAX_MAC_INDEX |
for ( ; head->r.bit < CCS_MAX_MAC_INDEX |
|
+ CCS_MAX_CAPABILITY_INDEX |
|
667 |
+ CCS_MAX_MAC_CATEGORY_INDEX; head->r.bit++) { |
+ CCS_MAX_MAC_CATEGORY_INDEX; head->r.bit++) { |
668 |
const u8 i = head->r.bit; |
const u8 i = head->r.bit; |
669 |
const u8 config = profile->config[i]; |
const u8 config = profile->config[i]; |
670 |
if (config == CCS_CONFIG_USE_DEFAULT) |
if (config == CCS_CONFIG_USE_DEFAULT) |
671 |
continue; |
continue; |
672 |
ccs_io_printf(head, "%u-%s%s", index, "CONFIG::", |
if (i < CCS_MAX_MAC_INDEX) |
673 |
ccs_mac_keywords[i]); |
ccs_io_printf(head, "%u-CONFIG::%s::%s", index, |
674 |
|
ccs_category_keywords |
675 |
|
[ccs_index2category[i]], |
676 |
|
ccs_mac_keywords[i]); |
677 |
|
else |
678 |
|
ccs_io_printf(head, "%u-CONFIG::%s", index, |
679 |
|
ccs_mac_keywords[i]); |
680 |
ccs_print_config(head, config); |
ccs_print_config(head, config); |
681 |
head->r.bit++; |
head->r.bit++; |
682 |
break; |
break; |
683 |
} |
} |
684 |
if (head->r.bit == CCS_MAX_MAC_INDEX |
if (head->r.bit == CCS_MAX_MAC_INDEX |
|
+ CCS_MAX_CAPABILITY_INDEX |
|
685 |
+ CCS_MAX_MAC_CATEGORY_INDEX) { |
+ CCS_MAX_MAC_CATEGORY_INDEX) { |
|
ccs_print_preference(head, index); |
|
686 |
head->r.index++; |
head->r.index++; |
687 |
head->r.step = 1; |
head->r.step = 1; |
688 |
} |
} |
692 |
goto next; |
goto next; |
693 |
} |
} |
694 |
|
|
695 |
|
/** |
696 |
|
* ccs_same_manager - Check for duplicated "struct ccs_manager" entry. |
697 |
|
* |
698 |
|
* @a: Pointer to "struct ccs_acl_head". |
699 |
|
* @b: Pointer to "struct ccs_acl_head". |
700 |
|
* |
701 |
|
* Returns true if @a and @b are duplicated, false otherwise. |
702 |
|
*/ |
703 |
static bool ccs_same_manager(const struct ccs_acl_head *a, |
static bool ccs_same_manager(const struct ccs_acl_head *a, |
704 |
const struct ccs_acl_head *b) |
const struct ccs_acl_head *b) |
705 |
{ |
{ |
747 |
static int ccs_write_manager(struct ccs_io_buffer *head) |
static int ccs_write_manager(struct ccs_io_buffer *head) |
748 |
{ |
{ |
749 |
char *data = head->write_buf; |
char *data = head->write_buf; |
750 |
bool is_delete = ccs_str_starts(&data, CCS_KEYWORD_DELETE); |
bool is_delete = ccs_str_starts(&data, "delete "); |
751 |
if (!strcmp(data, "manage_by_non_root")) { |
if (!strcmp(data, "manage_by_non_root")) { |
752 |
ccs_manage_by_non_root = !is_delete; |
ccs_manage_by_non_root = !is_delete; |
753 |
return 0; |
return 0; |
791 |
{ |
{ |
792 |
struct ccs_manager *ptr; |
struct ccs_manager *ptr; |
793 |
const char *exe; |
const char *exe; |
794 |
struct task_struct *task = current; |
struct ccs_security *task = ccs_current_security(); |
795 |
const struct ccs_path_info *domainname |
const struct ccs_path_info *domainname |
796 |
= ccs_current_domain()->domainname; |
= ccs_current_domain()->domainname; |
797 |
bool found = false; |
bool found = false; |
802 |
if (!ccs_manage_by_non_root && (current_uid() || current_euid())) |
if (!ccs_manage_by_non_root && (current_uid() || current_euid())) |
803 |
return false; |
return false; |
804 |
exe = ccs_get_exe(); |
exe = ccs_get_exe(); |
805 |
list_for_each_entry_rcu(ptr, &ccs_policy_list[CCS_ID_MANAGER], |
list_for_each_entry_srcu(ptr, &ccs_policy_list[CCS_ID_MANAGER], |
806 |
head.list) { |
head.list, &ccs_ss) { |
807 |
if (ptr->head.is_deleted) |
if (ptr->head.is_deleted) |
808 |
continue; |
continue; |
809 |
if (ptr->is_domain) { |
if (ptr->is_domain) { |
832 |
} |
} |
833 |
|
|
834 |
/** |
/** |
|
* ccs_find_condition_part - Find condition part from the statement. |
|
|
* |
|
|
* @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) |
|
|
cp = strstr(data, " ; set "); |
|
|
if (cp) |
|
|
*cp++ = '\0'; |
|
|
return cp; |
|
|
} |
|
|
|
|
|
/** |
|
835 |
* ccs_select_one - Parse select command. |
* ccs_select_one - Parse select command. |
836 |
* |
* |
837 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
887 |
return true; |
return true; |
888 |
} |
} |
889 |
|
|
890 |
|
/** |
891 |
|
* ccs_same_handler_acl - Check for duplicated "struct ccs_handler_acl" entry. |
892 |
|
* |
893 |
|
* @a: Pointer to "struct ccs_acl_info". |
894 |
|
* @b: Pointer to "struct ccs_acl_info". |
895 |
|
* |
896 |
|
* Returns true if @a and @b are duplicated, false otherwise. |
897 |
|
*/ |
898 |
|
static bool ccs_same_handler_acl(const struct ccs_acl_info *a, |
899 |
|
const struct ccs_acl_info *b) |
900 |
|
{ |
901 |
|
const struct ccs_handler_acl *p1 = container_of(a, typeof(*p1), head); |
902 |
|
const struct ccs_handler_acl *p2 = container_of(b, typeof(*p2), head); |
903 |
|
return p1->handler == p2->handler; |
904 |
|
} |
905 |
|
|
906 |
|
/** |
907 |
|
* ccs_same_task_acl - Check for duplicated "struct ccs_task_acl" entry. |
908 |
|
* |
909 |
|
* @a: Pointer to "struct ccs_acl_info". |
910 |
|
* @b: Pointer to "struct ccs_acl_info". |
911 |
|
* |
912 |
|
* Returns true if @a and @b are duplicated, false otherwise. |
913 |
|
*/ |
914 |
|
static bool ccs_same_task_acl(const struct ccs_acl_info *a, |
915 |
|
const struct ccs_acl_info *b) |
916 |
|
{ |
917 |
|
const struct ccs_task_acl *p1 = container_of(a, typeof(*p1), head); |
918 |
|
const struct ccs_task_acl *p2 = container_of(b, typeof(*p2), head); |
919 |
|
return p1->domainname == p2->domainname; |
920 |
|
} |
921 |
|
|
922 |
|
/** |
923 |
|
* ccs_write_task - Update task related list. |
924 |
|
* |
925 |
|
* @param: Pointer to "struct ccs_acl_param". |
926 |
|
* |
927 |
|
* Returns 0 on success, negative value otherwise. |
928 |
|
*/ |
929 |
|
static int ccs_write_task(struct ccs_acl_param *param) |
930 |
|
{ |
931 |
|
int error; |
932 |
|
const bool is_auto = ccs_str_starts(¶m->data, |
933 |
|
"auto_domain_transition "); |
934 |
|
if (!is_auto && !ccs_str_starts(¶m->data, |
935 |
|
"manual_domain_transition ")) { |
936 |
|
struct ccs_handler_acl e = { }; |
937 |
|
char *handler; |
938 |
|
if (ccs_str_starts(¶m->data, "auto_execute_handler ")) |
939 |
|
e.head.type = CCS_TYPE_AUTO_EXECUTE_HANDLER; |
940 |
|
else if (ccs_str_starts(¶m->data, |
941 |
|
"denied_execute_handler ")) |
942 |
|
e.head.type = CCS_TYPE_DENIED_EXECUTE_HANDLER; |
943 |
|
else |
944 |
|
return -EINVAL; |
945 |
|
handler = ccs_read_token(param); |
946 |
|
if (!ccs_correct_path(handler)) |
947 |
|
return -EINVAL; |
948 |
|
e.handler = ccs_get_name(handler); |
949 |
|
if (!e.handler) |
950 |
|
return -ENOMEM; |
951 |
|
if (e.handler->is_patterned) |
952 |
|
error = -EINVAL; /* No patterns allowed. */ |
953 |
|
else |
954 |
|
error = ccs_update_domain(&e.head, sizeof(e), param, |
955 |
|
ccs_same_handler_acl, NULL); |
956 |
|
ccs_put_name(e.handler); |
957 |
|
} else { |
958 |
|
struct ccs_task_acl e = { |
959 |
|
.head.type = is_auto ? |
960 |
|
CCS_TYPE_AUTO_TASK_ACL : CCS_TYPE_MANUAL_TASK_ACL, |
961 |
|
.domainname = ccs_get_domainname(param), |
962 |
|
}; |
963 |
|
if (!e.domainname) |
964 |
|
error = -EINVAL; |
965 |
|
else |
966 |
|
error = ccs_update_domain(&e.head, sizeof(e), param, |
967 |
|
ccs_same_task_acl, NULL); |
968 |
|
ccs_put_name(e.domainname); |
969 |
|
} |
970 |
|
return error; |
971 |
|
} |
972 |
|
|
973 |
|
/** |
974 |
|
* ccs_write_domain2 - Write domain policy. |
975 |
|
* |
976 |
|
* @data: Policy to be interpreted. |
977 |
|
* @domain: Pointer to "struct ccs_domain_info". |
978 |
|
* @is_delete: True if it is a delete request. |
979 |
|
* |
980 |
|
* Returns 0 on success, negative value otherwise. |
981 |
|
*/ |
982 |
static int ccs_write_domain2(char *data, struct ccs_domain_info *domain, |
static int ccs_write_domain2(char *data, struct ccs_domain_info *domain, |
983 |
const bool is_delete) |
const bool is_delete) |
984 |
{ |
{ |
985 |
|
struct ccs_acl_param param = { |
986 |
|
.data = data, |
987 |
|
.domain = domain, |
988 |
|
.is_delete = is_delete, |
989 |
|
}; |
990 |
static const struct { |
static const struct { |
991 |
const char *keyword; |
const char *keyword; |
992 |
int (*write) (char *, struct ccs_domain_info *, |
int (*write) (struct ccs_acl_param *); |
993 |
struct ccs_condition *, const bool); |
} ccs_callback[7] = { |
994 |
} ccs_callback[5] = { |
{ "file ", ccs_write_file }, |
995 |
{ "network inet ", ccs_write_inet_network }, |
{ "network inet ", ccs_write_inet_network }, |
996 |
{ "network unix ", ccs_write_unix_network }, |
{ "network unix ", ccs_write_unix_network }, |
997 |
{ "misc ", ccs_write_misc }, |
{ "misc ", ccs_write_misc }, |
998 |
{ "capability ", ccs_write_capability }, |
{ "capability ", ccs_write_capability }, |
999 |
{ "ipc ", ccs_write_ipc }, |
{ "ipc ", ccs_write_ipc }, |
1000 |
|
{ "task ", ccs_write_task }, |
1001 |
}; |
}; |
|
int (*write) (char *, struct ccs_domain_info *, struct ccs_condition *, |
|
|
const bool) = ccs_write_file; |
|
|
int error; |
|
1002 |
u8 i; |
u8 i; |
1003 |
struct ccs_condition *cond = NULL; |
for (i = 0; i < 7; i++) { |
1004 |
char *cp = ccs_find_condition_part(data); |
if (!ccs_str_starts(¶m.data, ccs_callback[i].keyword)) |
|
if (cp) { |
|
|
cond = ccs_get_condition(cp); |
|
|
if (!cond) |
|
|
return -EINVAL; |
|
|
} |
|
|
for (i = 0; i < 5; i++) { |
|
|
if (!ccs_str_starts(&data, ccs_callback[i].keyword)) |
|
1005 |
continue; |
continue; |
1006 |
write = ccs_callback[i].write; |
return ccs_callback[i].write(¶m); |
|
break; |
|
1007 |
} |
} |
1008 |
error = write(data, domain, cond, is_delete); |
return -EINVAL; |
|
if (cond) |
|
|
ccs_put_condition(cond); |
|
|
return error; |
|
1009 |
} |
} |
1010 |
|
|
1011 |
static const char *ccs_dif[CCS_MAX_DOMAIN_INFO_FLAGS] = { |
/* String table for domain flags. */ |
1012 |
[CCS_DIF_QUOTA_WARNED] = CCS_KEYWORD_QUOTA_EXCEEDED "\n", |
const char * const ccs_dif[CCS_MAX_DOMAIN_INFO_FLAGS] = { |
1013 |
[CCS_DIF_TRANSITION_FAILED] = CCS_KEYWORD_TRANSITION_FAILED "\n" |
[CCS_DIF_QUOTA_WARNED] = "quota_exceeded\n", |
1014 |
|
[CCS_DIF_TRANSITION_FAILED] = "transition_failed\n", |
1015 |
}; |
}; |
1016 |
|
|
1017 |
/** |
/** |
1018 |
* ccs_write_domain - Write domain policy. |
* ccs_write_domain - Write domain policy. |
1019 |
* |
* |
1028 |
bool is_delete = false; |
bool is_delete = false; |
1029 |
bool is_select = false; |
bool is_select = false; |
1030 |
unsigned int profile; |
unsigned int profile; |
1031 |
if (ccs_str_starts(&data, CCS_KEYWORD_DELETE)) |
if (ccs_str_starts(&data, "delete ")) |
1032 |
is_delete = true; |
is_delete = true; |
1033 |
else if (ccs_str_starts(&data, CCS_KEYWORD_SELECT)) |
else if (ccs_str_starts(&data, "select ")) |
1034 |
is_select = true; |
is_select = true; |
1035 |
if (is_select && ccs_select_one(head, data)) |
if (is_select && ccs_select_one(head, data)) |
1036 |
return 0; |
return 0; |
1051 |
if (!domain) |
if (!domain) |
1052 |
return -EINVAL; |
return -EINVAL; |
1053 |
|
|
1054 |
if (sscanf(data, CCS_KEYWORD_USE_PROFILE "%u", &profile) == 1 |
if (sscanf(data, "use_profile %u\n", &profile) == 1 |
1055 |
&& profile < CCS_MAX_PROFILES) { |
&& profile < CCS_MAX_PROFILES) { |
1056 |
if (!ccs_policy_loaded || ccs_profile_ptr[(u8) profile]) |
if (!ccs_policy_loaded || ccs_profile_ptr[(u8) profile]) |
1057 |
domain->profile = (u8) profile; |
domain->profile = (u8) profile; |
1058 |
return 0; |
return 0; |
1059 |
} |
} |
1060 |
if (sscanf(data, CCS_KEYWORD_USE_GROUP "%u", &profile) == 1 |
if (sscanf(data, "use_group %u\n", &profile) == 1 |
1061 |
&& profile < CCS_MAX_ACL_GROUPS) { |
&& profile < CCS_MAX_ACL_GROUPS) { |
1062 |
domain->group = (u8) profile; |
domain->group = (u8) profile; |
1063 |
return 0; |
return 0; |
1077 |
* |
* |
1078 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1079 |
* @ptr: Pointer to "struct ccs_name_union". |
* @ptr: Pointer to "struct ccs_name_union". |
1080 |
|
* |
1081 |
|
* Returns nothing. |
1082 |
*/ |
*/ |
1083 |
static void ccs_print_name_union(struct ccs_io_buffer *head, |
static void ccs_print_name_union(struct ccs_io_buffer *head, |
1084 |
const struct ccs_name_union *ptr) |
const struct ccs_name_union *ptr) |
1103 |
* |
* |
1104 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1105 |
* @ptr: Pointer to "struct ccs_number_union". |
* @ptr: Pointer to "struct ccs_number_union". |
1106 |
|
* |
1107 |
|
* Returns nothing. |
1108 |
*/ |
*/ |
1109 |
static void ccs_print_number_union(struct ccs_io_buffer *head, |
static void ccs_print_number_union(struct ccs_io_buffer *head, |
1110 |
const struct ccs_number_union *ptr) |
const struct ccs_number_union *ptr) |
1160 |
{ |
{ |
1161 |
switch (head->r.cond_step) { |
switch (head->r.cond_step) { |
1162 |
case 0: |
case 0: |
1163 |
{ |
head->r.cond_index = 0; |
1164 |
if (cond->condc) |
head->r.cond_step++; |
|
ccs_set_string(head, " if"); |
|
|
head->r.cond_index = 0; |
|
|
head->r.cond_step++; |
|
|
} |
|
1165 |
/* fall through */ |
/* fall through */ |
1166 |
case 1: |
case 1: |
1167 |
{ |
{ |
1270 |
head->r.cond_step++; |
head->r.cond_step++; |
1271 |
/* fall through */ |
/* fall through */ |
1272 |
case 3: |
case 3: |
1273 |
{ |
if (cond->grant_log != CCS_GRANTLOG_AUTO) |
1274 |
u8 j; |
ccs_io_printf(head, " grant_log=%s", |
1275 |
const u8 i = cond->post_state[3]; |
ccs_yesno(cond->grant_log == |
1276 |
if (i) |
CCS_GRANTLOG_YES)); |
1277 |
ccs_set_string(head, " ; set"); |
if (cond->transit) { |
1278 |
for (j = 0; j < 3; j++) |
ccs_set_string(head, " auto_domain_transitition=\""); |
1279 |
if ((i & (1 << j))) |
ccs_set_string(head, cond->transit->name); |
1280 |
ccs_io_printf(head, |
ccs_set_string(head, "\""); |
|
" task.state[%u]=%u", j, |
|
|
cond->post_state[j]); |
|
|
if (i & (1 << 4)) |
|
|
ccs_io_printf(head, " audit=%s", |
|
|
ccs_yesno(cond->post_state[4])); |
|
1281 |
} |
} |
1282 |
ccs_set_lf(head); |
ccs_set_lf(head); |
1283 |
return true; |
return true; |
1301 |
return bit; |
return bit; |
1302 |
} |
} |
1303 |
|
|
1304 |
|
/** |
1305 |
|
* ccs_set_group - Print "acl_group " header keyword. |
1306 |
|
* |
1307 |
|
* @head: Pointer to "struct ccs_io_buffer". |
1308 |
|
* |
1309 |
|
* Returns nothing. |
1310 |
|
*/ |
1311 |
static void ccs_set_group(struct ccs_io_buffer *head) |
static void ccs_set_group(struct ccs_io_buffer *head) |
1312 |
{ |
{ |
1313 |
if (head->type == CCS_EXCEPTIONPOLICY) |
if (head->type == CCS_EXCEPTIONPOLICY) |
1331 |
goto print_cond_part; |
goto print_cond_part; |
1332 |
if (acl->is_deleted) |
if (acl->is_deleted) |
1333 |
return true; |
return true; |
1334 |
next: |
next: |
1335 |
bit = head->r.bit; |
bit = head->r.bit; |
1336 |
if (!ccs_flush(head)) |
if (!ccs_flush(head)) |
1337 |
return false; |
return false; |
1343 |
if (!(perm & (1 << bit))) |
if (!(perm & (1 << bit))) |
1344 |
continue; |
continue; |
1345 |
if (head->r.print_execute_only && |
if (head->r.print_execute_only && |
1346 |
bit != CCS_TYPE_EXECUTE && bit != CCS_TYPE_TRANSIT) |
bit != CCS_TYPE_EXECUTE |
1347 |
|
/* && bit != CCS_TYPE_TRANSIT */) |
1348 |
continue; |
continue; |
1349 |
break; |
break; |
1350 |
} |
} |
1354 |
ccs_set_string(head, "file "); |
ccs_set_string(head, "file "); |
1355 |
ccs_set_string(head, ccs_path_keyword[bit]); |
ccs_set_string(head, ccs_path_keyword[bit]); |
1356 |
ccs_print_name_union(head, &ptr->name); |
ccs_print_name_union(head, &ptr->name); |
1357 |
} else if (acl_type == CCS_TYPE_EXECUTE_HANDLER || |
} else if (acl_type == CCS_TYPE_AUTO_EXECUTE_HANDLER || |
1358 |
acl_type == CCS_TYPE_DENIED_EXECUTE_HANDLER) { |
acl_type == CCS_TYPE_DENIED_EXECUTE_HANDLER) { |
1359 |
struct ccs_execute_handler *ptr |
struct ccs_handler_acl *ptr |
1360 |
= container_of(acl, typeof(*ptr), head); |
= container_of(acl, typeof(*ptr), head); |
1361 |
ccs_set_group(head); |
ccs_set_group(head); |
1362 |
ccs_io_printf(head, "%s ", |
ccs_set_string(head, "task "); |
1363 |
acl_type == CCS_TYPE_EXECUTE_HANDLER ? |
ccs_set_string(head, acl_type == CCS_TYPE_AUTO_EXECUTE_HANDLER |
1364 |
CCS_KEYWORD_EXECUTE_HANDLER : |
? "auto_execute_handler " : |
1365 |
CCS_KEYWORD_DENIED_EXECUTE_HANDLER); |
"denied_execute_handler "); |
1366 |
ccs_set_string(head, ptr->handler->name); |
ccs_set_string(head, ptr->handler->name); |
1367 |
|
} else if (acl_type == CCS_TYPE_AUTO_TASK_ACL || |
1368 |
|
acl_type == CCS_TYPE_MANUAL_TASK_ACL) { |
1369 |
|
struct ccs_task_acl *ptr = |
1370 |
|
container_of(acl, typeof(*ptr), head); |
1371 |
|
ccs_set_group(head); |
1372 |
|
ccs_set_string(head, "task "); |
1373 |
|
ccs_set_string(head, acl_type == CCS_TYPE_AUTO_TASK_ACL ? |
1374 |
|
"auto_domain_transition " : |
1375 |
|
"manual_domain_transition "); |
1376 |
|
ccs_set_string(head, ptr->domainname->name); |
1377 |
} else if (head->r.print_execute_only) { |
} else if (head->r.print_execute_only) { |
1378 |
return true; |
return true; |
1379 |
} else if (acl_type == CCS_TYPE_MKDEV_ACL) { |
} else if (acl_type == CCS_TYPE_MKDEV_ACL) { |
1384 |
goto done; |
goto done; |
1385 |
ccs_set_group(head); |
ccs_set_group(head); |
1386 |
ccs_set_string(head, "file "); |
ccs_set_string(head, "file "); |
1387 |
ccs_set_string(head, ccs_mkdev_keyword[bit]); |
ccs_set_string(head, ccs_mac_keywords[ccs_pnnn2mac[bit]]); |
1388 |
ccs_print_name_union(head, &ptr->name); |
ccs_print_name_union(head, &ptr->name); |
1389 |
ccs_print_number_union(head, &ptr->mode); |
ccs_print_number_union(head, &ptr->mode); |
1390 |
ccs_print_number_union(head, &ptr->major); |
ccs_print_number_union(head, &ptr->major); |
1397 |
goto done; |
goto done; |
1398 |
ccs_set_group(head); |
ccs_set_group(head); |
1399 |
ccs_set_string(head, "file "); |
ccs_set_string(head, "file "); |
1400 |
ccs_set_string(head, ccs_path2_keyword[bit]); |
ccs_set_string(head, ccs_mac_keywords[ccs_pp2mac[bit]]); |
1401 |
ccs_print_name_union(head, &ptr->name1); |
ccs_print_name_union(head, &ptr->name1); |
1402 |
ccs_print_name_union(head, &ptr->name2); |
ccs_print_name_union(head, &ptr->name2); |
1403 |
} else if (acl_type == CCS_TYPE_PATH_NUMBER_ACL) { |
} else if (acl_type == CCS_TYPE_PATH_NUMBER_ACL) { |
1408 |
goto done; |
goto done; |
1409 |
ccs_set_group(head); |
ccs_set_group(head); |
1410 |
ccs_set_string(head, "file "); |
ccs_set_string(head, "file "); |
1411 |
ccs_set_string(head, ccs_path_number_keyword[bit]); |
ccs_set_string(head, ccs_mac_keywords[ccs_pn2mac[bit]]); |
1412 |
ccs_print_name_union(head, &ptr->name); |
ccs_print_name_union(head, &ptr->name); |
1413 |
ccs_print_number_union(head, &ptr->number); |
ccs_print_number_union(head, &ptr->number); |
1414 |
} else if (acl_type == CCS_TYPE_ENV_ACL) { |
} else if (acl_type == CCS_TYPE_ENV_ACL) { |
1422 |
container_of(acl, typeof(*ptr), head); |
container_of(acl, typeof(*ptr), head); |
1423 |
ccs_set_group(head); |
ccs_set_group(head); |
1424 |
ccs_set_string(head, "capability "); |
ccs_set_string(head, "capability "); |
1425 |
ccs_set_string(head, ccs_cap2keyword(ptr->operation)); |
ccs_set_string(head, |
1426 |
|
ccs_mac_keywords[ccs_c2mac[ptr->operation]]); |
1427 |
} else if (acl_type == CCS_TYPE_INET_ACL) { |
} else if (acl_type == CCS_TYPE_INET_ACL) { |
1428 |
struct ccs_inet_acl *ptr = |
struct ccs_inet_acl *ptr = |
1429 |
container_of(acl, typeof(*ptr), head); |
container_of(acl, typeof(*ptr), head); |
1432 |
goto done; |
goto done; |
1433 |
ccs_set_group(head); |
ccs_set_group(head); |
1434 |
ccs_set_string(head, "network inet "); |
ccs_set_string(head, "network inet "); |
1435 |
ccs_set_string(head, ccs_inet_keyword[ptr->protocol]); |
ccs_set_string(head, ccs_proto_keyword[ptr->protocol]); |
1436 |
ccs_set_space(head); |
ccs_set_space(head); |
1437 |
ccs_set_string(head, ccs_net_keyword[bit]); |
ccs_set_string(head, ccs_socket_keyword[bit]); |
1438 |
ccs_set_space(head); |
ccs_set_space(head); |
1439 |
switch (ptr->address_type) { |
switch (ptr->address_type) { |
1440 |
char buf[128]; |
char buf[128]; |
1463 |
goto done; |
goto done; |
1464 |
ccs_set_group(head); |
ccs_set_group(head); |
1465 |
ccs_set_string(head, "network unix "); |
ccs_set_string(head, "network unix "); |
1466 |
ccs_set_string(head, ccs_unix_keyword[ptr->protocol]); |
ccs_set_string(head, ccs_proto_keyword[ptr->protocol]); |
1467 |
ccs_set_space(head); |
ccs_set_space(head); |
1468 |
ccs_set_string(head, ccs_net_keyword[bit]); |
ccs_set_string(head, ccs_socket_keyword[bit]); |
1469 |
ccs_print_name_union(head, &ptr->name); |
ccs_print_name_union(head, &ptr->name); |
1470 |
} else if (acl_type == CCS_TYPE_SIGNAL_ACL) { |
} else if (acl_type == CCS_TYPE_SIGNAL_ACL) { |
1471 |
struct ccs_signal_acl *ptr = |
struct ccs_signal_acl *ptr = |
1490 |
head->r.cond_step = 0; |
head->r.cond_step = 0; |
1491 |
if (!ccs_flush(head)) |
if (!ccs_flush(head)) |
1492 |
return false; |
return false; |
1493 |
print_cond_part: |
print_cond_part: |
1494 |
if (!ccs_print_condition(head, acl->cond)) |
if (!ccs_print_condition(head, acl->cond)) |
1495 |
return false; |
return false; |
1496 |
head->r.print_cond_part = false; |
head->r.print_cond_part = false; |
1506 |
case CCS_TYPE_UNIX_ACL: |
case CCS_TYPE_UNIX_ACL: |
1507 |
goto next; |
goto next; |
1508 |
} |
} |
1509 |
done: |
done: |
1510 |
head->r.bit = 0; |
head->r.bit = 0; |
1511 |
return true; |
return true; |
1512 |
} |
} |
1516 |
* |
* |
1517 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
1518 |
* @domain: Pointer to "struct ccs_domain_info". |
* @domain: Pointer to "struct ccs_domain_info". |
1519 |
|
* @index: Index number. |
1520 |
* |
* |
1521 |
* Caller holds ccs_read_lock(). |
* Caller holds ccs_read_lock(). |
1522 |
* |
* |
1523 |
* Returns true on success, false otherwise. |
* Returns true on success, false otherwise. |
1524 |
*/ |
*/ |
1525 |
static bool ccs_read_domain2(struct ccs_io_buffer *head, |
static bool ccs_read_domain2(struct ccs_io_buffer *head, |
1526 |
struct ccs_domain_info *domain) |
struct ccs_domain_info *domain, |
1527 |
|
const u8 index) |
1528 |
{ |
{ |
1529 |
list_for_each_cookie(head->r.acl, &domain->acl_info_list) { |
list_for_each_cookie(head->r.acl, &domain->acl_info_list[index]) { |
1530 |
struct ccs_acl_info *ptr = |
struct ccs_acl_info *ptr = |
1531 |
list_entry(head->r.acl, typeof(*ptr), list); |
list_entry(head->r.acl, typeof(*ptr), list); |
1532 |
if (!ccs_print_entry(head, ptr)) |
if (!ccs_print_entry(head, ptr)) |
1559 |
/* Print domainname and flags. */ |
/* Print domainname and flags. */ |
1560 |
ccs_set_string(head, domain->domainname->name); |
ccs_set_string(head, domain->domainname->name); |
1561 |
ccs_set_lf(head); |
ccs_set_lf(head); |
1562 |
ccs_io_printf(head, CCS_KEYWORD_USE_PROFILE "%u\n", |
ccs_io_printf(head, "use_profile %u\n", |
1563 |
domain->profile); |
domain->profile); |
1564 |
ccs_io_printf(head, CCS_KEYWORD_USE_GROUP "%u\n", |
ccs_io_printf(head, "use_group %u\n", domain->group); |
|
domain->group); |
|
1565 |
for (i = 0; i < CCS_MAX_DOMAIN_INFO_FLAGS; i++) |
for (i = 0; i < CCS_MAX_DOMAIN_INFO_FLAGS; i++) |
1566 |
if (domain->flags[i]) |
if (domain->flags[i]) |
1567 |
ccs_set_string(head, ccs_dif[i]); |
ccs_set_string(head, ccs_dif[i]); |
1569 |
ccs_set_lf(head); |
ccs_set_lf(head); |
1570 |
/* fall through */ |
/* fall through */ |
1571 |
case 1: |
case 1: |
1572 |
if (!ccs_read_domain2(head, domain)) |
if (!ccs_read_domain2(head, domain, 0)) |
1573 |
|
return; |
1574 |
|
head->r.step++; |
1575 |
|
/* fall through */ |
1576 |
|
case 2: |
1577 |
|
if (!ccs_read_domain2(head, domain, 1)) |
1578 |
return; |
return; |
1579 |
head->r.step++; |
head->r.step++; |
1580 |
if (!ccs_set_lf(head)) |
if (!ccs_set_lf(head)) |
1581 |
return; |
return; |
1582 |
/* fall through */ |
/* fall through */ |
1583 |
case 2: |
case 3: |
1584 |
head->r.step = 0; |
head->r.step = 0; |
1585 |
if (head->r.print_this_domain_only) |
if (head->r.print_this_domain_only) |
1586 |
goto done; |
goto done; |
1587 |
} |
} |
1588 |
} |
} |
1589 |
done: |
done: |
1590 |
head->r.eof = true; |
head->r.eof = true; |
1591 |
} |
} |
1592 |
|
|
1711 |
#endif |
#endif |
1712 |
if (p) { |
if (p) { |
1713 |
domain = ccs_task_domain(p); |
domain = ccs_task_domain(p); |
1714 |
ccs_flags = p->ccs_flags; |
ccs_flags = ccs_task_flags(p); |
1715 |
} |
} |
1716 |
ccs_tasklist_unlock(); |
ccs_tasklist_unlock(); |
1717 |
if (!domain) |
if (!domain) |
1720 |
ccs_io_printf(head, "%u %u ", pid, domain->profile); |
ccs_io_printf(head, "%u %u ", pid, domain->profile); |
1721 |
ccs_set_string(head, domain->domainname->name); |
ccs_set_string(head, domain->domainname->name); |
1722 |
} else { |
} else { |
1723 |
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, |
|
1724 |
ccs_yesno(ccs_flags & |
ccs_yesno(ccs_flags & |
1725 |
CCS_TASK_IS_MANAGER), |
CCS_TASK_IS_MANAGER), |
1726 |
ccs_yesno(ccs_flags & |
ccs_yesno(ccs_flags & |
1727 |
CCS_TASK_IS_EXECUTE_HANDLER), |
CCS_TASK_IS_EXECUTE_HANDLER)); |
|
(u8) (ccs_flags >> 24), |
|
|
(u8) (ccs_flags >> 16), |
|
|
(u8) (ccs_flags >> 8)); |
|
1728 |
} |
} |
1729 |
} |
} |
1730 |
|
|
1731 |
static const char *ccs_transition_type[CCS_MAX_TRANSITION_TYPE] = { |
/* String table for domain transition control keywords. */ |
1732 |
[CCS_TRANSITION_CONTROL_NO_INITIALIZE] |
static const char * const ccs_transition_type[CCS_MAX_TRANSITION_TYPE] = { |
1733 |
= CCS_KEYWORD_NO_INITIALIZE_DOMAIN, |
[CCS_TRANSITION_CONTROL_NO_INITIALIZE] = "no_initialize_domain ", |
1734 |
[CCS_TRANSITION_CONTROL_INITIALIZE] = CCS_KEYWORD_INITIALIZE_DOMAIN, |
[CCS_TRANSITION_CONTROL_INITIALIZE] = "initialize_domain ", |
1735 |
[CCS_TRANSITION_CONTROL_NO_KEEP] = CCS_KEYWORD_NO_KEEP_DOMAIN, |
[CCS_TRANSITION_CONTROL_NO_KEEP] = "no_keep_domain ", |
1736 |
[CCS_TRANSITION_CONTROL_KEEP] = CCS_KEYWORD_KEEP_DOMAIN |
[CCS_TRANSITION_CONTROL_KEEP] = "keep_domain ", |
1737 |
}; |
}; |
1738 |
|
|
1739 |
static const char *ccs_group_name[CCS_MAX_GROUP] = { |
/* String table for grouping keywords. */ |
1740 |
[CCS_PATH_GROUP] = CCS_KEYWORD_PATH_GROUP, |
static const char * const ccs_group_name[CCS_MAX_GROUP] = { |
1741 |
[CCS_NUMBER_GROUP] = CCS_KEYWORD_NUMBER_GROUP, |
[CCS_PATH_GROUP] = "path_group ", |
1742 |
[CCS_ADDRESS_GROUP] = CCS_KEYWORD_ADDRESS_GROUP |
[CCS_NUMBER_GROUP] = "number_group ", |
1743 |
|
[CCS_ADDRESS_GROUP] = "address_group ", |
1744 |
}; |
}; |
1745 |
|
|
1746 |
/** |
/** |
1753 |
static int ccs_write_exception(struct ccs_io_buffer *head) |
static int ccs_write_exception(struct ccs_io_buffer *head) |
1754 |
{ |
{ |
1755 |
char *data = head->write_buf; |
char *data = head->write_buf; |
1756 |
const bool is_delete = ccs_str_starts(&data, CCS_KEYWORD_DELETE); |
const bool is_delete = ccs_str_starts(&data, "delete "); |
1757 |
u8 i; |
u8 i; |
1758 |
static const struct { |
static const struct { |
1759 |
const char *keyword; |
const char *keyword; |
1760 |
int (*write) (char *, const bool); |
int (*write) (char *, const bool); |
1761 |
} ccs_callback[3] = { |
} ccs_callback[2] = { |
1762 |
{ CCS_KEYWORD_AGGREGATOR, ccs_write_aggregator }, |
{ "aggregator ", ccs_write_aggregator }, |
1763 |
{ CCS_KEYWORD_FILE_PATTERN, ccs_write_pattern }, |
{ "deny_autobind ", ccs_write_reserved_port }, |
|
{ CCS_KEYWORD_DENY_AUTOBIND, ccs_write_reserved_port } |
|
1764 |
}; |
}; |
1765 |
for (i = 0; i < 3; i++) |
for (i = 0; i < 2; i++) |
1766 |
if (ccs_str_starts(&data, ccs_callback[i].keyword)) |
if (ccs_str_starts(&data, ccs_callback[i].keyword)) |
1767 |
return ccs_callback[i].write(data, is_delete); |
return ccs_callback[i].write(data, is_delete); |
1768 |
for (i = 0; i < CCS_MAX_TRANSITION_TYPE; i++) |
for (i = 0; i < CCS_MAX_TRANSITION_TYPE; i++) |
1817 |
head)->member_name->name); |
head)->member_name->name); |
1818 |
} else if (idx == CCS_NUMBER_GROUP) { |
} else if (idx == CCS_NUMBER_GROUP) { |
1819 |
ccs_print_number_union(head, &container_of |
ccs_print_number_union(head, &container_of |
1820 |
(ptr, struct ccs_number_group, |
(ptr, struct ccs_number_group, |
1821 |
head)->number); |
head)->number); |
1822 |
} else if (idx == CCS_ADDRESS_GROUP) { |
} else if (idx == CCS_ADDRESS_GROUP) { |
1823 |
char buffer[128]; |
char buffer[128]; |
1824 |
struct ccs_address_group *member = |
struct ccs_address_group *member = |
1879 |
{ |
{ |
1880 |
struct ccs_aggregator *ptr = |
struct ccs_aggregator *ptr = |
1881 |
container_of(acl, typeof(*ptr), head); |
container_of(acl, typeof(*ptr), head); |
1882 |
ccs_set_string(head, CCS_KEYWORD_AGGREGATOR); |
ccs_set_string(head, "aggregator "); |
1883 |
ccs_set_string(head, ptr->original_name->name); |
ccs_set_string(head, ptr->original_name->name); |
1884 |
ccs_set_space(head); |
ccs_set_space(head); |
1885 |
ccs_set_string(head, |
ccs_set_string(head, |
1886 |
ptr->aggregated_name->name); |
ptr->aggregated_name->name); |
1887 |
} |
} |
1888 |
break; |
break; |
|
case CCS_ID_PATTERN: |
|
|
{ |
|
|
struct ccs_pattern *ptr = |
|
|
container_of(acl, typeof(*ptr), head); |
|
|
ccs_set_string(head, CCS_KEYWORD_FILE_PATTERN); |
|
|
ccs_set_string(head, ptr->pattern->name); |
|
|
} |
|
|
break; |
|
1889 |
case CCS_ID_RESERVEDPORT: |
case CCS_ID_RESERVEDPORT: |
1890 |
{ |
{ |
1891 |
struct ccs_reserved *ptr = |
struct ccs_reserved *ptr = |
1892 |
container_of(acl, typeof(*ptr), head); |
container_of(acl, typeof(*ptr), head); |
1893 |
const u16 min_port = ptr->min_port; |
const u16 min_port = ptr->min_port; |
1894 |
const u16 max_port = ptr->max_port; |
const u16 max_port = ptr->max_port; |
1895 |
ccs_set_string(head, |
ccs_set_string(head, "deny_autobind "); |
|
CCS_KEYWORD_DENY_AUTOBIND); |
|
1896 |
ccs_io_printf(head, "%u", min_port); |
ccs_io_printf(head, "%u", min_port); |
1897 |
if (min_port != max_port) |
if (min_port != max_port) |
1898 |
ccs_io_printf(head, "-%u", max_port); |
ccs_io_printf(head, "-%u", max_port); |
1929 |
if (head->r.step < CCS_MAX_POLICY + CCS_MAX_GROUP) |
if (head->r.step < CCS_MAX_POLICY + CCS_MAX_GROUP) |
1930 |
return; |
return; |
1931 |
while (head->r.step < CCS_MAX_POLICY + CCS_MAX_GROUP |
while (head->r.step < CCS_MAX_POLICY + CCS_MAX_GROUP |
1932 |
+ CCS_MAX_ACL_GROUPS) { |
+ CCS_MAX_ACL_GROUPS * 2) { |
1933 |
head->r.group_index = head->r.step - CCS_MAX_POLICY |
head->r.group_index = (head->r.step - CCS_MAX_POLICY |
1934 |
- CCS_MAX_GROUP; |
- CCS_MAX_GROUP) / 2; |
1935 |
if (!ccs_read_domain2(head, |
if (!ccs_read_domain2(head, |
1936 |
&ccs_acl_group[head->r.group_index])) |
&ccs_acl_group[head->r.group_index], |
1937 |
|
head->r.step & 1)) |
1938 |
return; |
return; |
1939 |
head->r.step++; |
head->r.step++; |
1940 |
} |
} |
1941 |
head->r.eof = true; |
head->r.eof = true; |
1942 |
} |
} |
1943 |
|
|
1944 |
/* Wait queue for ccs_query_list. */ |
/* Wait queue for kernel -> userspace notification. */ |
1945 |
static DECLARE_WAIT_QUEUE_HEAD(ccs_query_wait); |
static DECLARE_WAIT_QUEUE_HEAD(ccs_query_wait); |
1946 |
|
/* Wait queue for userspace -> kernel notification. */ |
1947 |
|
static DECLARE_WAIT_QUEUE_HEAD(ccs_answer_wait); |
1948 |
|
|
1949 |
/* Lock for manipulating ccs_query_list. */ |
/* Lock for manipulating ccs_query_list. */ |
1950 |
static DEFINE_SPINLOCK(ccs_query_list_lock); |
static DEFINE_SPINLOCK(ccs_query_list_lock); |
1957 |
unsigned int serial; |
unsigned int serial; |
1958 |
int timer; |
int timer; |
1959 |
int answer; |
int answer; |
1960 |
|
u8 retry; |
1961 |
}; |
}; |
1962 |
|
|
1963 |
/* The list for "struct ccs_query". */ |
/* The list for "struct ccs_query". */ |
1966 |
/* Number of "struct file" referring /proc/ccs/query interface. */ |
/* Number of "struct file" referring /proc/ccs/query interface. */ |
1967 |
static atomic_t ccs_query_observers = ATOMIC_INIT(0); |
static atomic_t ccs_query_observers = ATOMIC_INIT(0); |
1968 |
|
|
1969 |
static void ccs_truncate(char *str) |
/** |
1970 |
|
* ccs_truncate - Truncate a line. |
1971 |
|
* |
1972 |
|
* @str: String to truncate. |
1973 |
|
* |
1974 |
|
* Returns length of truncated @str. |
1975 |
|
*/ |
1976 |
|
static int ccs_truncate(char *str) |
1977 |
{ |
{ |
1978 |
while (* (unsigned char *) str > (unsigned char) ' ') |
char *start = str; |
1979 |
|
while (*(unsigned char *) str > (unsigned char) ' ') |
1980 |
str++; |
str++; |
1981 |
*str = '\0'; |
*str = '\0'; |
1982 |
|
return strlen(start) + 1; |
1983 |
|
} |
1984 |
|
|
1985 |
|
/** |
1986 |
|
* ccs_add_entry - Add an ACL to current thread's domain. Used by learning mode. |
1987 |
|
* |
1988 |
|
* @header: Lines containing ACL. |
1989 |
|
* |
1990 |
|
* Returns nothing. |
1991 |
|
*/ |
1992 |
|
static void ccs_add_entry(char *header) |
1993 |
|
{ |
1994 |
|
char *buffer; |
1995 |
|
char *realpath = NULL; |
1996 |
|
char *argv0 = NULL; |
1997 |
|
char *symlink = NULL; |
1998 |
|
char *handler; |
1999 |
|
char *cp = strchr(header, '\n'); |
2000 |
|
int len; |
2001 |
|
if (!cp) |
2002 |
|
return; |
2003 |
|
cp = strchr(cp + 1, '\n'); |
2004 |
|
if (!cp) |
2005 |
|
return; |
2006 |
|
*cp++ = '\0'; |
2007 |
|
len = strlen(cp) + 1; |
2008 |
|
/* strstr() will return NULL if ordering is wrong. */ |
2009 |
|
if (*cp == 'f') { |
2010 |
|
argv0 = strstr(header, " argv[]={ \""); |
2011 |
|
if (argv0) { |
2012 |
|
argv0 += 10; |
2013 |
|
len += ccs_truncate(argv0) + 14; |
2014 |
|
} |
2015 |
|
realpath = strstr(header, " exec={ realpath=\""); |
2016 |
|
if (realpath) { |
2017 |
|
realpath += 8; |
2018 |
|
len += ccs_truncate(realpath) + 6; |
2019 |
|
} |
2020 |
|
symlink = strstr(header, " symlink.target=\""); |
2021 |
|
if (symlink) |
2022 |
|
len += ccs_truncate(symlink + 1) + 1; |
2023 |
|
} |
2024 |
|
handler = strstr(header, "type=execute_handler"); |
2025 |
|
if (handler) |
2026 |
|
len += ccs_truncate(handler) + 6; |
2027 |
|
buffer = kmalloc(len, CCS_GFP_FLAGS); |
2028 |
|
if (!buffer) |
2029 |
|
return; |
2030 |
|
snprintf(buffer, len - 1, "%s", cp); |
2031 |
|
if (handler) |
2032 |
|
ccs_addprintf(buffer, len, " task.%s", handler); |
2033 |
|
if (realpath) |
2034 |
|
ccs_addprintf(buffer, len, " exec.%s", realpath); |
2035 |
|
if (argv0) |
2036 |
|
ccs_addprintf(buffer, len, " exec.argv[0]=%s", argv0); |
2037 |
|
if (symlink) |
2038 |
|
ccs_addprintf(buffer, len, "%s", symlink); |
2039 |
|
ccs_normalize_line(buffer); |
2040 |
|
if (!ccs_write_domain2(buffer, ccs_current_domain(), false)) |
2041 |
|
ccs_update_stat(CCS_STAT_POLICY_UPDATES); |
2042 |
|
kfree(buffer); |
2043 |
} |
} |
2044 |
|
|
2045 |
/** |
/** |
2056 |
int ccs_supervisor(struct ccs_request_info *r, const char *fmt, ...) |
int ccs_supervisor(struct ccs_request_info *r, const char *fmt, ...) |
2057 |
{ |
{ |
2058 |
va_list args; |
va_list args; |
2059 |
int error = -EPERM; |
int error; |
|
int pos; |
|
2060 |
int len; |
int len; |
2061 |
static unsigned int ccs_serial; |
static unsigned int ccs_serial; |
2062 |
struct ccs_query *entry = NULL; |
struct ccs_query entry = { }; |
2063 |
bool quota_exceeded = false; |
bool quota_exceeded = false; |
|
char *header; |
|
|
struct ccs_domain_info * const domain = ccs_current_domain(); |
|
2064 |
va_start(args, fmt); |
va_start(args, fmt); |
2065 |
len = vsnprintf((char *) &pos, sizeof(pos) - 1, fmt, args) + 80; |
len = vsnprintf((char *) &len, 1, fmt, args) + 1; |
2066 |
va_end(args); |
va_end(args); |
2067 |
if (r->mode == CCS_CONFIG_LEARNING) { |
/* Write /proc/ccs/grant_log or /proc/ccs/reject_log . */ |
2068 |
char *buffer; |
va_start(args, fmt); |
2069 |
char *realpath = NULL; |
ccs_write_log2(r, len, fmt, args); |
2070 |
char *argv0 = NULL; |
va_end(args); |
2071 |
char *symlink = NULL; |
/* Nothing more to do if granted. */ |
2072 |
char *handler = NULL; |
if (r->granted) |
|
const struct ccs_preference *pref; |
|
|
if (!ccs_domain_quota_ok(r)) |
|
|
return 0; |
|
|
header = ccs_init_log(&len, r); |
|
|
if (!header) |
|
|
return 0; |
|
|
pref = &ccs_profile(r->profile)->preference; |
|
|
/* strstr() will return NULL if ordering is wrong. */ |
|
|
if (r->param_type == CCS_TYPE_PATH_ACL && |
|
|
r->param.path.operation == CCS_TYPE_EXECUTE) { |
|
|
if (pref->learning_exec_argv0) { |
|
|
argv0 = strstr(header, " argv[]={ \""); |
|
|
if (argv0) { |
|
|
argv0 += 10; |
|
|
ccs_truncate(argv0); |
|
|
} |
|
|
} |
|
|
if (pref->learning_exec_realpath) { |
|
|
realpath = strstr(header, |
|
|
" exec={ realpath=\""); |
|
|
if (realpath) { |
|
|
realpath += 8; |
|
|
ccs_truncate(realpath); |
|
|
} |
|
|
} |
|
|
} else if (r->param_type == CCS_TYPE_PATH_ACL && |
|
|
r->param.path.operation == CCS_TYPE_SYMLINK && |
|
|
pref->learning_symlink_target) { |
|
|
symlink = strstr(header, " symlink.target=\""); |
|
|
if (symlink) |
|
|
ccs_truncate(symlink + 1); |
|
|
} |
|
|
handler = strstr(header, "type=execute_handler"); |
|
|
if (handler) |
|
|
ccs_truncate(handler); |
|
|
buffer = kmalloc(len, CCS_GFP_FLAGS); |
|
|
if (buffer) { |
|
|
va_start(args, fmt); |
|
|
vsnprintf(buffer, len - 1, fmt, args); |
|
|
va_end(args); |
|
|
if (handler || realpath || argv0 || symlink) { |
|
|
ccs_addprintf(buffer, len, " if"); |
|
|
if (handler) |
|
|
ccs_addprintf(buffer, len, " task.%s", |
|
|
handler); |
|
|
if (realpath) |
|
|
ccs_addprintf(buffer, len, " exec.%s", |
|
|
realpath); |
|
|
if (argv0) |
|
|
ccs_addprintf(buffer, len, |
|
|
" exec.argv[0]=%s", |
|
|
argv0); |
|
|
if (symlink) |
|
|
ccs_addprintf(buffer, len, "%s", |
|
|
symlink); |
|
|
} |
|
|
ccs_normalize_line(buffer); |
|
|
ccs_write_domain2(buffer, domain, false); |
|
|
kfree(buffer); |
|
|
} |
|
|
kfree(header); |
|
|
return 0; |
|
|
} |
|
|
if (r->mode != CCS_CONFIG_ENFORCING) |
|
2073 |
return 0; |
return 0; |
2074 |
if (!atomic_read(&ccs_query_observers)) { |
if (r->mode) |
2075 |
|
ccs_update_stat(r->mode); |
2076 |
|
switch (r->mode) { |
2077 |
int i; |
int i; |
2078 |
if (current->ccs_flags & CCS_DONT_SLEEP_ON_ENFORCE_ERROR) |
struct ccs_profile *p; |
2079 |
return -EPERM; |
case CCS_CONFIG_ENFORCING: |
2080 |
for (i = 0; i < ccs_profile(domain->profile)->preference. |
error = -EPERM; |
2081 |
enforcing_penalty; i++) { |
if (atomic_read(&ccs_query_observers)) |
2082 |
|
break; |
2083 |
|
if (ccs_current_flags() & CCS_DONT_SLEEP_ON_ENFORCE_ERROR) |
2084 |
|
goto out; |
2085 |
|
p = ccs_profile(r->profile); |
2086 |
|
/* Check enforcing_penalty parameter. */ |
2087 |
|
for (i = 0; i < p->pref[CCS_PREF_ENFORCING_PENALTY]; i++) { |
2088 |
set_current_state(TASK_INTERRUPTIBLE); |
set_current_state(TASK_INTERRUPTIBLE); |
2089 |
schedule_timeout(HZ / 10); |
schedule_timeout(HZ / 10); |
2090 |
} |
} |
|
return -EPERM; |
|
|
} |
|
|
header = ccs_init_log(&len, r); |
|
|
if (!header) |
|
2091 |
goto out; |
goto out; |
2092 |
entry = kzalloc(sizeof(*entry), CCS_GFP_FLAGS); |
case CCS_CONFIG_LEARNING: |
2093 |
if (!entry) |
error = 0; |
2094 |
|
/* Check mac_learning_entry parameter. */ |
2095 |
|
if (ccs_domain_quota_ok(r)) |
2096 |
|
break; |
2097 |
|
/* fall through */ |
2098 |
|
default: |
2099 |
|
return 0; |
2100 |
|
} |
2101 |
|
/* Get message. */ |
2102 |
|
va_start(args, fmt); |
2103 |
|
entry.query = ccs_init_log(r, len, fmt, args); |
2104 |
|
va_end(args); |
2105 |
|
if (!entry.query) |
2106 |
goto out; |
goto out; |
2107 |
len = ccs_round2(len); |
entry.query_len = strlen(entry.query) + 1; |
2108 |
entry->query = kzalloc(len, CCS_GFP_FLAGS); |
if (!error) { |
2109 |
if (!entry->query) |
ccs_add_entry(entry.query); |
2110 |
goto out; |
goto out; |
2111 |
|
} |
2112 |
|
len = ccs_round2(entry.query_len); |
2113 |
spin_lock(&ccs_query_list_lock); |
spin_lock(&ccs_query_list_lock); |
2114 |
if (ccs_quota_for_query && ccs_query_memory_size + len + |
if (ccs_memory_quota[CCS_MEMORY_QUERY] && |
2115 |
sizeof(*entry) >= ccs_quota_for_query) { |
ccs_memory_used[CCS_MEMORY_QUERY] + len |
2116 |
|
>= ccs_memory_quota[CCS_MEMORY_QUERY]) { |
2117 |
quota_exceeded = true; |
quota_exceeded = true; |
2118 |
} else { |
} else { |
2119 |
ccs_query_memory_size += len + sizeof(*entry); |
entry.serial = ccs_serial++; |
2120 |
entry->serial = ccs_serial++; |
entry.retry = r->retry; |
2121 |
|
ccs_memory_used[CCS_MEMORY_QUERY] += len; |
2122 |
|
list_add_tail(&entry.list, &ccs_query_list); |
2123 |
} |
} |
2124 |
spin_unlock(&ccs_query_list_lock); |
spin_unlock(&ccs_query_list_lock); |
2125 |
if (quota_exceeded) |
if (quota_exceeded) |
2126 |
goto out; |
goto out; |
|
pos = snprintf(entry->query, len - 1, "Q%u-%hu\n%s", |
|
|
entry->serial, r->retry, header); |
|
|
kfree(header); |
|
|
header = NULL; |
|
|
va_start(args, fmt); |
|
|
vsnprintf(entry->query + pos, len - 1 - pos, fmt, args); |
|
|
entry->query_len = strlen(entry->query) + 1; |
|
|
va_end(args); |
|
|
spin_lock(&ccs_query_list_lock); |
|
|
list_add_tail(&entry->list, &ccs_query_list); |
|
|
spin_unlock(&ccs_query_list_lock); |
|
2127 |
/* Give 10 seconds for supervisor's opinion. */ |
/* Give 10 seconds for supervisor's opinion. */ |
2128 |
for (entry->timer = 0; |
while (entry.timer < 10) { |
2129 |
atomic_read(&ccs_query_observers) && entry->timer < 100; |
wake_up_all(&ccs_query_wait); |
2130 |
entry->timer++) { |
if (wait_event_interruptible_timeout |
2131 |
wake_up(&ccs_query_wait); |
(ccs_answer_wait, entry.answer || |
2132 |
set_current_state(TASK_INTERRUPTIBLE); |
!atomic_read(&ccs_query_observers), HZ)) |
|
schedule_timeout(HZ / 10); |
|
|
if (entry->answer) |
|
2133 |
break; |
break; |
2134 |
|
else |
2135 |
|
entry.timer++; |
2136 |
} |
} |
2137 |
spin_lock(&ccs_query_list_lock); |
spin_lock(&ccs_query_list_lock); |
2138 |
list_del(&entry->list); |
list_del(&entry.list); |
2139 |
ccs_query_memory_size -= len + sizeof(*entry); |
ccs_memory_used[CCS_MEMORY_QUERY] -= len; |
2140 |
spin_unlock(&ccs_query_list_lock); |
spin_unlock(&ccs_query_list_lock); |
2141 |
switch (entry->answer) { |
switch (entry.answer) { |
2142 |
case 3: /* Asked to retry by administrator. */ |
case 3: /* Asked to retry by administrator. */ |
2143 |
error = CCS_RETRY_REQUEST; |
error = CCS_RETRY_REQUEST; |
2144 |
r->retry++; |
r->retry++; |
2147 |
/* Granted by administrator. */ |
/* Granted by administrator. */ |
2148 |
error = 0; |
error = 0; |
2149 |
break; |
break; |
|
case 0: |
|
|
/* Timed out. */ |
|
|
break; |
|
2150 |
default: |
default: |
2151 |
/* Rejected by administrator. */ |
/* Timed out or rejected by administrator. */ |
2152 |
break; |
break; |
2153 |
} |
} |
2154 |
out: |
out: |
2155 |
if (entry) |
kfree(entry.query); |
|
kfree(entry->query); |
|
|
kfree(entry); |
|
|
kfree(header); |
|
2156 |
return error; |
return error; |
2157 |
} |
} |
2158 |
|
|
2195 |
* ccs_read_query - Read access requests which violated policy in enforcing mode. |
* ccs_read_query - Read access requests which violated policy in enforcing mode. |
2196 |
* |
* |
2197 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
2198 |
|
* |
2199 |
|
* Returns nothing. |
2200 |
*/ |
*/ |
2201 |
static void ccs_read_query(struct ccs_io_buffer *head) |
static void ccs_read_query(struct ccs_io_buffer *head) |
2202 |
{ |
{ |
2225 |
head->r.query_index = 0; |
head->r.query_index = 0; |
2226 |
return; |
return; |
2227 |
} |
} |
2228 |
buf = kzalloc(len, CCS_GFP_FLAGS); |
buf = kzalloc(len + 32, CCS_GFP_FLAGS); |
2229 |
if (!buf) |
if (!buf) |
2230 |
return; |
return; |
2231 |
pos = 0; |
pos = 0; |
2241 |
* can change, but I don't care. |
* can change, but I don't care. |
2242 |
*/ |
*/ |
2243 |
if (len == ptr->query_len) |
if (len == ptr->query_len) |
2244 |
memmove(buf, ptr->query, len); |
snprintf(buf, len + 32, "Q%u-%hu\n%s", ptr->serial, |
2245 |
|
ptr->retry, ptr->query); |
2246 |
break; |
break; |
2247 |
} |
} |
2248 |
spin_unlock(&ccs_query_list_lock); |
spin_unlock(&ccs_query_list_lock); |
2286 |
break; |
break; |
2287 |
} |
} |
2288 |
spin_unlock(&ccs_query_list_lock); |
spin_unlock(&ccs_query_list_lock); |
2289 |
|
wake_up_all(&ccs_answer_wait); |
2290 |
return 0; |
return 0; |
2291 |
} |
} |
2292 |
|
|
2294 |
* ccs_read_version: Get version. |
* ccs_read_version: Get version. |
2295 |
* |
* |
2296 |
* @head: Pointer to "struct ccs_io_buffer". |
* @head: Pointer to "struct ccs_io_buffer". |
2297 |
|
* |
2298 |
|
* Returns nothing. |
2299 |
*/ |
*/ |
2300 |
static void ccs_read_version(struct ccs_io_buffer *head) |
static void ccs_read_version(struct ccs_io_buffer *head) |
2301 |
{ |
{ |
2306 |
} |
} |
2307 |
|
|
2308 |
/** |
/** |
|
* ccs_read_self_domain - Get the current process's domainname. |
|
|
* |
|
|
* @head: Pointer to "struct ccs_io_buffer". |
|
|
*/ |
|
|
static void ccs_read_self_domain(struct ccs_io_buffer *head) |
|
|
{ |
|
|
if (head->r.eof) |
|
|
return; |
|
|
/* |
|
|
* ccs_current_domain()->domainname != NULL because every process |
|
|
* belongs to a domain and the domain's name cannot be NULL. |
|
|
*/ |
|
|
ccs_io_printf(head, "%s", ccs_current_domain()->domainname->name); |
|
|
head->r.eof = true; |
|
|
} |
|
|
|
|
|
/** |
|
2309 |
* ccs_open_control - open() for /proc/ccs/ interface. |
* ccs_open_control - open() for /proc/ccs/ interface. |
2310 |
* |
* |
2311 |
* @type: Type of interface. |
* @type: Type of interface. |
2329 |
head->write = ccs_write_exception; |
head->write = ccs_write_exception; |
2330 |
head->read = ccs_read_exception; |
head->read = ccs_read_exception; |
2331 |
break; |
break; |
|
#ifdef CONFIG_CCSECURITY_AUDIT |
|
2332 |
case CCS_GRANTLOG: /* /proc/ccs/grant_log */ |
case CCS_GRANTLOG: /* /proc/ccs/grant_log */ |
2333 |
case CCS_REJECTLOG: /* /proc/ccs/reject_log */ |
case CCS_REJECTLOG: /* /proc/ccs/reject_log */ |
2334 |
head->poll = ccs_poll_log; |
head->poll = ccs_poll_log; |
2335 |
head->read = ccs_read_log; |
head->read = ccs_read_log; |
2336 |
break; |
break; |
|
#endif |
|
|
case CCS_SELFDOMAIN: /* /proc/ccs/self_domain */ |
|
|
head->read = ccs_read_self_domain; |
|
|
break; |
|
2337 |
case CCS_DOMAIN_STATUS: /* /proc/ccs/.domain_status */ |
case CCS_DOMAIN_STATUS: /* /proc/ccs/.domain_status */ |
2338 |
head->write = ccs_write_domain_profile; |
head->write = ccs_write_domain_profile; |
2339 |
head->read = ccs_read_domain_profile; |
head->read = ccs_read_domain_profile; |
2340 |
break; |
break; |
2341 |
case CCS_EXECUTE_HANDLER: /* /proc/ccs/.execute_handler */ |
case CCS_EXECUTE_HANDLER: /* /proc/ccs/.execute_handler */ |
2342 |
/* Allow execute_handler to read process's status. */ |
/* Allow execute_handler to read process's status. */ |
2343 |
if (!(current->ccs_flags & CCS_TASK_IS_EXECUTE_HANDLER)) { |
if (!(ccs_current_flags() & CCS_TASK_IS_EXECUTE_HANDLER)) { |
2344 |
kfree(head); |
kfree(head); |
2345 |
return -EPERM; |
return -EPERM; |
2346 |
} |
} |
2404 |
return -ENOMEM; |
return -ENOMEM; |
2405 |
} |
} |
2406 |
} |
} |
|
if (type != CCS_QUERY && |
|
|
type != CCS_GRANTLOG && type != CCS_REJECTLOG) |
|
|
head->reader_idx = ccs_lock(); |
|
|
file->private_data = head; |
|
|
/* |
|
|
* Call the handler now if the file is /proc/ccs/self_domain |
|
|
* so that the user can use "cat < /proc/ccs/self_domain" to |
|
|
* know the current process's domainname. |
|
|
*/ |
|
|
if (type == CCS_SELFDOMAIN) |
|
|
ccs_read_control(file, NULL, 0); |
|
2407 |
/* |
/* |
2408 |
* If the file is /proc/ccs/query , increment the observer counter. |
* If the file is /proc/ccs/query , increment the observer counter. |
2409 |
* The obserber counter is used by ccs_supervisor() to see if |
* The obserber counter is used by ccs_supervisor() to see if |
2410 |
* there is some process monitoring /proc/ccs/query. |
* there is some process monitoring /proc/ccs/query. |
2411 |
*/ |
*/ |
2412 |
else if (type == CCS_QUERY) |
if (type == CCS_QUERY) |
2413 |
atomic_inc(&ccs_query_observers); |
atomic_inc(&ccs_query_observers); |
2414 |
|
else if (type != CCS_GRANTLOG && type != CCS_REJECTLOG) |
2415 |
|
head->reader_idx = ccs_lock(); |
2416 |
|
file->private_data = head; |
2417 |
return 0; |
return 0; |
2418 |
} |
} |
2419 |
|
|
2423 |
* @file: Pointer to "struct file". |
* @file: Pointer to "struct file". |
2424 |
* @wait: Pointer to "poll_table". |
* @wait: Pointer to "poll_table". |
2425 |
* |
* |
2426 |
|
* Returns return value of poll(). |
2427 |
|
* |
2428 |
* Waits for read readiness. |
* Waits for read readiness. |
2429 |
* /proc/ccs/query is handled by /usr/sbin/ccs-queryd and |
* /proc/ccs/query is handled by /usr/sbin/ccs-queryd and |
2430 |
* /proc/ccs/grant_log and /proc/ccs/reject_log are handled by |
* /proc/ccs/grant_log and /proc/ccs/reject_log are handled by |
2531 |
cp0[head->w.avail - 1] = '\0'; |
cp0[head->w.avail - 1] = '\0'; |
2532 |
head->w.avail = 0; |
head->w.avail = 0; |
2533 |
ccs_normalize_line(cp0); |
ccs_normalize_line(cp0); |
2534 |
head->write(head); |
if (head->write(head)) |
2535 |
|
continue; |
2536 |
|
switch (head->type) { |
2537 |
|
case CCS_DOMAINPOLICY: |
2538 |
|
case CCS_EXCEPTIONPOLICY: |
2539 |
|
case CCS_DOMAIN_STATUS: |
2540 |
|
case CCS_MEMINFO: |
2541 |
|
case CCS_PROFILE: |
2542 |
|
case CCS_MANAGER: |
2543 |
|
ccs_update_stat(CCS_STAT_POLICY_UPDATES); |
2544 |
|
} |
2545 |
} |
} |
2546 |
ccs_read_unlock(idx); |
ccs_read_unlock(idx); |
2547 |
mutex_unlock(&head->io_sem); |
mutex_unlock(&head->io_sem); |
2563 |
/* |
/* |
2564 |
* If the file is /proc/ccs/query , decrement the observer counter. |
* If the file is /proc/ccs/query , decrement the observer counter. |
2565 |
*/ |
*/ |
2566 |
if (type == CCS_QUERY) |
if (type == CCS_QUERY) { |
2567 |
atomic_dec(&ccs_query_observers); |
if (atomic_dec_and_test(&ccs_query_observers)) |
2568 |
if (type != CCS_QUERY && |
wake_up_all(&ccs_answer_wait); |
2569 |
type != CCS_GRANTLOG && type != CCS_REJECTLOG) |
} else if (type != CCS_GRANTLOG && type != CCS_REJECTLOG) |
2570 |
ccs_unlock(head->reader_idx); |
ccs_unlock(head->reader_idx); |
2571 |
/* Release memory used for policy I/O. */ |
/* Release memory used for policy I/O. */ |
2572 |
kfree(head->read_buf); |
kfree(head->read_buf); |
2581 |
return 0; |
return 0; |
2582 |
} |
} |
2583 |
|
|
2584 |
|
/** |
2585 |
|
* ccs_policy_io_init - Register hooks for policy I/O. |
2586 |
|
* |
2587 |
|
* Returns nothing. |
2588 |
|
*/ |
2589 |
void __init ccs_policy_io_init(void) |
void __init ccs_policy_io_init(void) |
2590 |
{ |
{ |
2591 |
ccsecurity_ops.check_profile = ccs_check_profile; |
ccsecurity_ops.check_profile = ccs_check_profile; |