8 #include <linux/slab.h>
21 static char *tomoyo_print_bprm(
struct linux_binprm *bprm,
24 static const int tomoyo_buffer_len = 4096 * 2;
29 unsigned long pos = bprm->
p;
31 int argv_count = bprm->
argc;
32 int envp_count = bprm->
envc;
33 bool truncated =
false;
36 len =
snprintf(buffer, tomoyo_buffer_len - 1,
"argv[]={ ");
43 while (argv_count || envp_count) {
49 const char *kaddr = dump->
data;
50 const unsigned char c = kaddr[offset++];
53 if (cp >= buffer + tomoyo_buffer_len - 32) {
56 }
else if (c ==
'\\') {
59 }
else if (c >
' ' && c < 127) {
67 *cp++ = (c >> 6) +
'0';
68 *cp++ = ((c >> 3) & 7) +
'0';
69 *cp++ = (c & 7) +
'0';
74 if (--argv_count == 0) {
85 }
else if (envp_count) {
86 if (--envp_count == 0) {
94 if (!argv_count && !envp_count)
103 snprintf(buffer, tomoyo_buffer_len - 1,
104 "argv[]={ ... } envp[]= { ... }");
115 static inline const char *tomoyo_filetype(
const umode_t mode)
152 static const int tomoyo_buffer_len = 4096;
163 pos =
snprintf(buffer, tomoyo_buffer_len - 1,
164 "#%04u/%02u/%02u %02u:%02u:%02u# profile=%u mode=%s "
165 "granted=%s (global-pid=%u) task={ pid=%u ppid=%u "
166 "uid=%u gid=%u euid=%u egid=%u suid=%u sgid=%u "
167 "fsuid=%u fsgid=%u }",
stamp.year,
stamp.month,
170 tomoyo_sys_getpid(), tomoyo_sys_getppid(),
191 stat = &obj->
stat[
i];
196 tomoyo_buffer_len - 1 - pos,
197 " path%u.parent={ uid=%u gid=%u "
198 "ino=%lu perm=0%o }", (i >> 1) + 1,
201 (
unsigned long)stat->
ino,
205 pos +=
snprintf(buffer + pos, tomoyo_buffer_len - 1 - pos,
206 " path%u={ uid=%u gid=%u ino=%lu major=%u"
207 " minor=%u perm=0%o type=%s", (i >> 1) + 1,
210 (
unsigned long)stat->
ino,
212 mode &
S_IALLUGO, tomoyo_filetype(mode));
216 tomoyo_buffer_len - 1 - pos,
217 " dev_major=%u dev_minor=%u",
220 pos +=
snprintf(buffer + pos, tomoyo_buffer_len - 1 - pos,
224 if (pos < tomoyo_buffer_len - 1)
247 char *bprm_info =
NULL;
249 char *realpath =
NULL;
250 const char *symlink =
NULL;
252 const char *domainname = r->
domain->domainname->name;
253 header = tomoyo_print_header(r);
261 bprm_info = tomoyo_print_bprm(r->
ee->bprm, &r->
ee->dump);
262 if (!realpath || !bprm_info)
266 }
else if (r->
obj && r->
obj->symlink_target) {
267 symlink = r->
obj->symlink_target->name;
269 len += 18 +
strlen(symlink);
271 len = tomoyo_round2(len);
276 pos =
snprintf(buf, len,
"%s", header);
279 pos +=
snprintf(buf + pos, len - pos,
280 " exec={ realpath=\"%s\" argc=%d envc=%d %s }",
281 realpath, bprm->
argc, bprm->
envc, bprm_info);
283 pos +=
snprintf(buf + pos, len - pos,
" symlink.target=\"%s\"",
285 pos +=
snprintf(buf + pos, len - pos,
"\n%s\n", domainname);
286 vsnprintf(buf + pos, len - pos, fmt, args);
311 static unsigned int tomoyo_log_count;
326 const bool is_granted)
337 if (is_granted && matched_acl && matched_acl->
cond &&
365 bool quota_exceeded =
false;
372 entry = kzalloc(
sizeof(*entry),
GFP_NOFS);
378 len = tomoyo_round2(
strlen(buf) + 1);
383 entry->
size = len + tomoyo_round2(
sizeof(*entry));
384 spin_lock(&tomoyo_log_lock);
388 quota_exceeded =
true;
394 spin_unlock(&tomoyo_log_lock);
395 if (quota_exceeded) {
418 len =
vsnprintf((
char *) &len, 1, fmt, args) + 1;
439 spin_lock(&tomoyo_log_lock);
446 spin_unlock(&tomoyo_log_lock);
464 if (tomoyo_log_count)
466 poll_wait(file, &tomoyo_log_wait, wait);
467 if (tomoyo_log_count)