オープンソース・ソフトウェアの開発とダウンロード

Subversion リポジトリの参照

Contents of /trunk/1.6.x/ccs-patch/fs/tomoyo_signal.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 989 - (show annotations) (download) (as text)
Fri Feb 15 13:33:40 2008 UTC (16 years, 3 months ago) by kumaneko
File MIME type: text/x-csrc
File size: 5466 byte(s)
Add execve() parameter checking.
1 /*
2 * fs/tomoyo_signal.c
3 *
4 * Implementation of the Domain-Based Mandatory Access Control.
5 *
6 * Copyright (C) 2005-2008 NTT DATA CORPORATION
7 *
8 * Version: 1.6.0-pre 2008/02/15
9 *
10 * This file is applicable to both 2.4.30 and 2.6.11 and later.
11 * See README.ccs for ChangeLog.
12 *
13 */
14 /***** TOMOYO Linux start. *****/
15
16 #include <linux/ccs_common.h>
17 #include <linux/tomoyo.h>
18 #include <linux/realpath.h>
19 #include <linux/version.h>
20 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
21 #define find_task_by_pid find_task_by_vpid
22 #endif
23
24 /************************* VARIABLES *************************/
25
26 /* The initial domain. */
27 extern struct domain_info KERNEL_DOMAIN;
28
29 extern struct mutex domain_acl_lock;
30
31 /************************* AUDIT FUNCTIONS *************************/
32
33 static int AuditSignalLog(const int signal, const struct path_info *dest_domain, const bool is_granted, const u8 profile, const u8 mode)
34 {
35 char *buf;
36 int len;
37 if (CanSaveAuditLog(is_granted) < 0) return -ENOMEM;
38 len = dest_domain->total_len;
39 if ((buf = InitAuditLog(&len, profile, mode, NULL)) == NULL) return -ENOMEM;
40 snprintf(buf + strlen(buf), len - strlen(buf) - 1, KEYWORD_ALLOW_SIGNAL "%d %s\n", signal, dest_domain->name);
41 return WriteAuditLog(buf, is_granted);
42 }
43
44 /************************* SIGNAL ACL HANDLER *************************/
45
46 static int AddSignalEntry(const int sig, const char *dest_pattern, struct domain_info *domain, const struct condition_list *condition, const bool is_delete)
47 {
48 struct acl_info *ptr;
49 struct signal_acl_record *acl;
50 const struct path_info *saved_dest_pattern;
51 const u16 hash = sig;
52 int error = -ENOMEM;
53 if (!domain) return -EINVAL;
54 if (!dest_pattern || !IsCorrectDomain(dest_pattern, __FUNCTION__)) return -EINVAL;
55 if ((saved_dest_pattern = SaveName(dest_pattern)) == NULL) return -ENOMEM;
56 mutex_lock(&domain_acl_lock);
57 if (!is_delete) {
58 list1_for_each_entry(ptr, &domain->acl_info_list, list) {
59 if ((ptr->type & ~(ACL_DELETED | ACL_WITH_CONDITION)) != TYPE_SIGNAL_ACL) continue;
60 if (GetConditionPart(ptr) != condition) continue;
61 acl = container_of(ptr, struct signal_acl_record, head);
62 if (acl->sig != hash || pathcmp(acl->domainname, saved_dest_pattern)) continue;
63 error = AddDomainACL(NULL, ptr);
64 goto out;
65 }
66 /* Not found. Append it to the tail. */
67 if ((acl = alloc_acl_element(TYPE_SIGNAL_ACL, condition)) == NULL) goto out;
68 acl->sig = hash;
69 acl->domainname = saved_dest_pattern;
70 error = AddDomainACL(domain, &acl->head);
71 } else {
72 error = -ENOENT;
73 list1_for_each_entry(ptr, &domain->acl_info_list, list) {
74 if ((ptr->type & ~ACL_WITH_CONDITION) != TYPE_SIGNAL_ACL) continue;
75 if (GetConditionPart(ptr) != condition) continue;
76 acl = container_of(ptr, struct signal_acl_record, head);
77 if (acl->sig != hash || pathcmp(acl->domainname, saved_dest_pattern)) continue;
78 error = DelDomainACL(ptr);
79 break;
80 }
81 }
82 out: ;
83 mutex_unlock(&domain_acl_lock);
84 return error;
85 }
86
87 int CheckSignalACL(const int sig, const int pid)
88 {
89 struct domain_info *domain = current->domain_info;
90 struct domain_info *dest = NULL;
91 const char *dest_pattern;
92 struct acl_info *ptr;
93 const u16 hash = sig;
94 const u8 profile = current->domain_info->profile;
95 const u8 mode = CheckCCSFlags(CCS_TOMOYO_MAC_FOR_SIGNAL);
96 const bool is_enforce = (mode == 3);
97 bool found = 0;
98 if (!mode) return 0;
99 if (!sig) return 0; /* No check for NULL signal. */
100 if (current->pid == pid) {
101 AuditSignalLog(sig, domain->domainname, 1, profile, mode);
102 return 0; /* No check for self. */
103 }
104 { /* Simplified checking. */
105 struct task_struct *p = NULL;
106 read_lock(&tasklist_lock);
107 if (pid > 0) p = find_task_by_pid((pid_t) pid);
108 else if (pid == 0) p = current;
109 else if (pid == -1) dest = &KERNEL_DOMAIN;
110 else p = find_task_by_pid((pid_t) -pid);
111 if (p) dest = p->domain_info;
112 read_unlock(&tasklist_lock);
113 if (!dest) return 0; /* I can't find destinatioin. */
114 }
115 if (domain == dest) {
116 AuditSignalLog(sig, dest->domainname, 1, profile, mode);
117 return 0;
118 }
119 dest_pattern = dest->domainname->name;
120 list1_for_each_entry(ptr, &domain->acl_info_list, list) {
121 struct signal_acl_record *acl;
122 if ((ptr->type & ~ACL_WITH_CONDITION) != TYPE_SIGNAL_ACL) continue;
123 acl = container_of(ptr, struct signal_acl_record, head);
124 if (acl->sig == hash && CheckCondition(ptr, NULL)) {
125 const int len = acl->domainname->total_len;
126 if (strncmp(acl->domainname->name, dest_pattern, len)) continue;
127 if (dest_pattern[len] != ' ' && dest_pattern[len] != '\0') continue;
128 found = 1;
129 break;
130 }
131 }
132 AuditSignalLog(sig, dest->domainname, found, profile, mode);
133 if (found) return 0;
134 if (TomoyoVerboseMode()) {
135 printk("TOMOYO-%s: Signal %d to %s denied for %s\n", GetMSG(is_enforce), sig, GetLastName(dest), GetLastName(domain));
136 }
137 if (is_enforce) return CheckSupervisor("%s\n" KEYWORD_ALLOW_SIGNAL "%d %s\n", domain->domainname->name, sig, dest_pattern);
138 else if (mode == 1 && CheckDomainQuota(domain)) AddSignalEntry(sig, dest_pattern, domain, NULL, 0);
139 return 0;
140 }
141
142 int AddSignalPolicy(char *data, struct domain_info *domain, const struct condition_list *condition, const bool is_delete)
143 {
144 int sig;
145 char *domainname = strchr(data, ' ');
146 if (sscanf(data, "%d", &sig) == 1 && domainname && IsDomainDef(domainname + 1)) {
147 return AddSignalEntry(sig, domainname + 1, domain, condition, is_delete);
148 }
149 return -EINVAL;
150 }
151
152 /***** TOMOYO Linux end. *****/

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26