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

Subversion リポジトリの参照

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 744 - (hide annotations) (download) (as text)
Mon Dec 3 04:44:12 2007 UTC (16 years, 5 months ago) by kumaneko
Original Path: trunk/1.5.x/ccs-patch.tmp/fs/tomoyo_signal.c
File MIME type: text/x-csrc
File size: 5210 byte(s)


1 kumaneko 111 /*
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 kumaneko 731 * Version: 1.5.2-pre 2007/11/27
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 kumaneko 652 extern struct mutex domain_acl_lock;
26 kumaneko 111
27     /************************* AUDIT FUNCTIONS *************************/
28    
29 kumaneko 621 static int AuditSignalLog(const int signal, const struct path_info *dest_domain, const bool 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 621 static int AddSignalEntry(const int sig, const char *dest_pattern, struct domain_info *domain, const struct condition_list *condition, const bool is_delete)
43 kumaneko 111 {
44     struct acl_info *ptr;
45 kumaneko 708 struct signal_acl_record *acl;
46 kumaneko 111 const struct path_info *saved_dest_pattern;
47     const u16 hash = sig;
48     int error = -ENOMEM;
49     if (!domain) return -EINVAL;
50     if (!dest_pattern || !IsCorrectDomain(dest_pattern, __FUNCTION__)) return -EINVAL;
51     if ((saved_dest_pattern = SaveName(dest_pattern)) == NULL) return -ENOMEM;
52 kumaneko 652 mutex_lock(&domain_acl_lock);
53 kumaneko 514 if (!is_delete) {
54 kumaneko 722 list1_for_each_entry(ptr, &domain->acl_info_list, list) {
55 kumaneko 712 acl = container_of(ptr, struct signal_acl_record, head);
56 kumaneko 708 if (ptr->type == TYPE_SIGNAL_ACL && acl->sig == hash && ptr->cond == condition) {
57     if (!pathcmp(acl->domainname, saved_dest_pattern)) {
58 kumaneko 111 ptr->is_deleted = 0;
59     /* Found. Nothing to do. */
60     error = 0;
61 kumaneko 708 goto out;
62 kumaneko 111 }
63     }
64     }
65 kumaneko 708 /* Not found. Append it to the tail. */
66     if ((acl = alloc_element(sizeof(*acl))) == NULL) goto out;
67     acl->head.type = TYPE_SIGNAL_ACL;
68     acl->sig = hash;
69     acl->head.cond = condition;
70     acl->domainname = saved_dest_pattern;
71     error = AddDomainACL(domain, &acl->head);
72 kumaneko 111 } else {
73     error = -ENOENT;
74 kumaneko 722 list1_for_each_entry(ptr, &domain->acl_info_list, list) {
75 kumaneko 712 acl = container_of(ptr, struct signal_acl_record, head);
76 kumaneko 708 if (ptr->type != TYPE_SIGNAL_ACL || ptr->is_deleted || acl->sig != hash || ptr->cond != condition) continue;
77     if (pathcmp(acl->domainname, saved_dest_pattern)) continue;
78 kumaneko 111 error = DelDomainACL(ptr);
79     break;
80     }
81     }
82 kumaneko 708 out: ;
83 kumaneko 652 mutex_unlock(&domain_acl_lock);
84 kumaneko 111 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 kumaneko 621 const bool is_enforce = CheckCCSEnforce(CCS_TOMOYO_MAC_FOR_SIGNAL);
95 kumaneko 708 bool found = 0;
96 kumaneko 111 if (!CheckCCSFlags(CCS_TOMOYO_MAC_FOR_SIGNAL)) return 0;
97     if (!sig) return 0; /* No check for NULL signal. */
98     if (current->pid == pid) {
99     AuditSignalLog(sig, domain->domainname, 1);
100     return 0; /* No check for self. */
101     }
102     { /* Simplified checking. */
103     struct task_struct *p = NULL;
104     read_lock(&tasklist_lock);
105     if (pid > 0) p = find_task_by_pid((pid_t) pid);
106     else if (pid == 0) p = current;
107     else if (pid == -1) dest = &KERNEL_DOMAIN;
108     else p = find_task_by_pid((pid_t) -pid);
109     if (p) dest = p->domain_info;
110     read_unlock(&tasklist_lock);
111     if (!dest) return 0; /* I can't find destinatioin. */
112     }
113     if (domain == dest) {
114     AuditSignalLog(sig, dest->domainname, 1);
115     return 0;
116     }
117     dest_pattern = dest->domainname->name;
118 kumaneko 722 list1_for_each_entry(ptr, &domain->acl_info_list, list) {
119 kumaneko 708 struct signal_acl_record *acl;
120 kumaneko 712 acl = container_of(ptr, struct signal_acl_record, head);
121 kumaneko 708 if (ptr->type == TYPE_SIGNAL_ACL && ptr->is_deleted == 0 && acl->sig == hash && CheckCondition(ptr->cond, NULL) == 0) {
122     const int len = acl->domainname->total_len;
123     if (strncmp(acl->domainname->name, dest_pattern, len) == 0 && (dest_pattern[len] == ' ' || dest_pattern[len] == '\0')) {
124     found = 1;
125     break;
126     }
127 kumaneko 111 }
128     }
129 kumaneko 708 AuditSignalLog(sig, dest->domainname, found);
130     if (found) return 0;
131 kumaneko 111 if (TomoyoVerboseMode()) {
132     printk("TOMOYO-%s: Signal %d to %s denied for %s\n", GetMSG(is_enforce), sig, GetLastName(dest), GetLastName(domain));
133     }
134     if (is_enforce) return CheckSupervisor("%s\n" KEYWORD_ALLOW_SIGNAL "%d %s\n", domain->domainname->name, sig, dest_pattern);
135 kumaneko 514 if (CheckCCSAccept(CCS_TOMOYO_MAC_FOR_SIGNAL, domain)) AddSignalEntry(sig, dest_pattern, domain, NULL, 0);
136 kumaneko 111 return 0;
137     }
138 kumaneko 223 EXPORT_SYMBOL(CheckSignalACL);
139 kumaneko 111
140 kumaneko 621 int AddSignalPolicy(char *data, struct domain_info *domain, const struct condition_list *condition, const bool is_delete)
141 kumaneko 111 {
142     int sig;
143     char *domainname = strchr(data, ' ');
144     if (sscanf(data, "%d", &sig) == 1 && domainname && IsDomainDef(domainname + 1)) {
145 kumaneko 514 return AddSignalEntry(sig, domainname + 1, domain, condition, is_delete);
146 kumaneko 111 }
147     return -EINVAL;
148     }
149    
150     /***** TOMOYO Linux end. *****/

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