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

Subversion リポジトリの参照

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 328 - (show annotations) (download) (as text)
Wed Aug 8 11:12:12 2007 UTC (16 years, 9 months ago) by kumaneko
File MIME type: text/x-csrc
File size: 5665 byte(s)
Remove union from acl_info and add __attribute__((__packed__))
1 /*
2 * fs/tomoyo_signal.c
3 *
4 * Implementation of the Domain-Based Mandatory Access Control.
5 *
6 * Copyright (C) 2005-2007 NTT DATA CORPORATION
7 *
8 * Version: 1.5.0-pre 2007/08/06
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
20 /************************* VARIABLES *************************/
21
22 /* The initial domain. */
23 extern struct domain_info KERNEL_DOMAIN;
24
25 extern struct semaphore domain_acl_lock;
26
27 /************************* AUDIT FUNCTIONS *************************/
28
29 #ifdef CONFIG_TOMOYO_AUDIT
30 static int AuditSignalLog(const int signal, const struct path_info *dest_domain, const int is_granted)
31 {
32 char *buf;
33 int len;
34 if (CanSaveAuditLog(is_granted) < 0) return -ENOMEM;
35 len = dest_domain->total_len;
36 if ((buf = InitAuditLog(&len)) == NULL) return -ENOMEM;
37 snprintf(buf + strlen(buf), len - strlen(buf) - 1, KEYWORD_ALLOW_SIGNAL "%d %s\n", signal, dest_domain->name);
38 return WriteAuditLog(buf, is_granted);
39 }
40 #else
41 static inline void AuditSignalLog(const int signal, const struct path_info *dest_domain, const int is_granted) {}
42 #endif
43
44 /************************* SIGNAL ACL HANDLER *************************/
45
46 static int AddSignalEntry(const int sig, const char *dest_pattern, struct domain_info *domain, const u8 is_add, const struct condition_list *condition)
47 {
48 struct acl_info *ptr;
49 const struct path_info *saved_dest_pattern;
50 const u16 hash = sig;
51 int error = -ENOMEM;
52 if (!domain) return -EINVAL;
53 if (!dest_pattern || !IsCorrectDomain(dest_pattern, __FUNCTION__)) return -EINVAL;
54 if ((saved_dest_pattern = SaveName(dest_pattern)) == NULL) return -ENOMEM;
55 down(&domain_acl_lock);
56 if (is_add) {
57 if ((ptr = domain->first_acl_ptr) == NULL) goto first_entry;
58 while (1) {
59 struct signal_acl_record *new_ptr = (struct signal_acl_record *) ptr;
60 if (ptr->type == TYPE_SIGNAL_ACL && new_ptr->sig == hash && ptr->cond == condition) {
61 if (!pathcmp(new_ptr->domainname, saved_dest_pattern)) {
62 ptr->is_deleted = 0;
63 /* Found. Nothing to do. */
64 error = 0;
65 break;
66 }
67 }
68 if (ptr->next) {
69 ptr = ptr->next;
70 continue;
71 }
72 first_entry: ;
73 if (is_add == 1 && TooManyDomainACL(domain)) break;
74 /* Not found. Append it to the tail. */
75 if ((new_ptr = alloc_element(sizeof(*new_ptr))) == NULL) break;
76 new_ptr->head.type = TYPE_SIGNAL_ACL;
77 new_ptr->sig = hash;
78 new_ptr->head.cond = condition;
79 new_ptr->domainname = saved_dest_pattern;
80 error = AddDomainACL(ptr, domain, (struct acl_info *) new_ptr);
81 break;
82 }
83 } else {
84 error = -ENOENT;
85 for (ptr = domain->first_acl_ptr; ptr; ptr = ptr->next) {
86 struct signal_acl_record *ptr2 = (struct signal_acl_record *) ptr;
87 if (ptr->type != TYPE_SIGNAL_ACL || ptr->is_deleted || ptr2->sig != hash || ptr->cond != condition) continue;
88 if (pathcmp(ptr2->domainname, saved_dest_pattern)) continue;
89 error = DelDomainACL(ptr);
90 break;
91 }
92 }
93 up(&domain_acl_lock);
94 return error;
95 }
96
97 int CheckSignalACL(const int sig, const int pid)
98 {
99 struct domain_info *domain = current->domain_info;
100 struct domain_info *dest = NULL;
101 const char *dest_pattern;
102 struct acl_info *ptr;
103 const u16 hash = sig;
104 const int is_enforce = CheckCCSEnforce(CCS_TOMOYO_MAC_FOR_SIGNAL);
105 if (!CheckCCSFlags(CCS_TOMOYO_MAC_FOR_SIGNAL)) return 0;
106 if (!sig) return 0; /* No check for NULL signal. */
107 if (current->pid == pid) {
108 AuditSignalLog(sig, domain->domainname, 1);
109 return 0; /* No check for self. */
110 }
111 { /* Simplified checking. */
112 struct task_struct *p = NULL;
113 read_lock(&tasklist_lock);
114 if (pid > 0) p = find_task_by_pid((pid_t) pid);
115 else if (pid == 0) p = current;
116 else if (pid == -1) dest = &KERNEL_DOMAIN;
117 else p = find_task_by_pid((pid_t) -pid);
118 if (p) dest = p->domain_info;
119 read_unlock(&tasklist_lock);
120 if (!dest) return 0; /* I can't find destinatioin. */
121 }
122 if (domain == dest) {
123 AuditSignalLog(sig, dest->domainname, 1);
124 return 0;
125 }
126 dest_pattern = dest->domainname->name;
127 for (ptr = domain->first_acl_ptr; ptr; ptr = ptr->next) {
128 struct signal_acl_record *ptr2 = (struct signal_acl_record *) ptr;
129 if (ptr->type == TYPE_SIGNAL_ACL && ptr->is_deleted == 0 && ptr2->sig == hash && CheckCondition(ptr->cond, NULL) == 0) {
130 const int len = ptr2->domainname->total_len;
131 if (strncmp(ptr2->domainname->name, dest_pattern, len) == 0 && (dest_pattern[len] == ' ' || dest_pattern[len] == '\0')) break;
132 }
133 }
134 if (ptr) {
135 AuditSignalLog(sig, dest->domainname, 1);
136 return 0;
137 }
138 if (TomoyoVerboseMode()) {
139 printk("TOMOYO-%s: Signal %d to %s denied for %s\n", GetMSG(is_enforce), sig, GetLastName(dest), GetLastName(domain));
140 }
141 AuditSignalLog(sig, dest->domainname, 0);
142 if (is_enforce) return CheckSupervisor("%s\n" KEYWORD_ALLOW_SIGNAL "%d %s\n", domain->domainname->name, sig, dest_pattern);
143 if (CheckCCSAccept(CCS_TOMOYO_MAC_FOR_SIGNAL)) AddSignalEntry(sig, dest_pattern, domain, 1, NULL);
144 return 0;
145 }
146 EXPORT_SYMBOL(CheckSignalACL);
147
148 int AddSignalPolicy(char *data, struct domain_info *domain, const int is_delete)
149 {
150 int sig;
151 char *domainname = strchr(data, ' ');
152 if (sscanf(data, "%d", &sig) == 1 && domainname && IsDomainDef(domainname + 1)) {
153 const struct condition_list *condition = NULL;
154 const char *cp = FindConditionPart(domainname + 1);
155 if (cp && (condition = FindOrAssignNewCondition(cp)) == NULL) return -EINVAL;
156 return AddSignalEntry(sig, domainname + 1, domain, is_delete ? 0 : -1, condition);
157 }
158 return -EINVAL;
159 }
160
161 /***** TOMOYO Linux end. *****/

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