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

Subversion リポジトリの参照

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 898 - (hide annotations) (download) (as text)
Tue Jan 15 04:44:35 2008 UTC (16 years, 4 months ago) by kumaneko
File MIME type: text/x-csrc
File size: 5431 byte(s)


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

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