Open-Source-Software-Entwicklung und Downloads

Browse Subversion Repository

Annotation of /trunk/1.6.x/ccs-patch/fs/tomoyo_exec.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: 5635 byte(s)


1 kumaneko 111 /*
2     * fs/tomoyo_exec.c
3     *
4     * Implementation of the Domain-Based Mandatory Access Control.
5     *
6 kumaneko 851 * Copyright (C) 2005-2008 NTT DATA CORPORATION
7 kumaneko 111 *
8 kumaneko 898 * Version: 1.6.0-pre 2008/01/04
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 kumaneko 652 extern struct mutex domain_acl_lock;
23 kumaneko 111
24     /************************* AUDIT FUNCTIONS *************************/
25    
26 kumaneko 851 static int AuditArgv0Log(const struct path_info *filename, const char *argv0, const bool is_granted, const u8 profile, const u8 mode)
27 kumaneko 111 {
28     char *buf;
29     int len;
30     if (CanSaveAuditLog(is_granted) < 0) return -ENOMEM;
31     len = filename->total_len + strlen(argv0) + 8;
32 kumaneko 815 if ((buf = InitAuditLog(&len, profile, mode)) == NULL) return -ENOMEM;
33 kumaneko 111 snprintf(buf + strlen(buf), len - strlen(buf) - 1, KEYWORD_ALLOW_ARGV0 "%s %s\n", filename->name, argv0);
34     return WriteAuditLog(buf, is_granted);
35     }
36    
37     /************************* ARGV0 MISMATCH HANDLER *************************/
38    
39 kumaneko 621 static int AddArgv0Entry(const char *filename, const char *argv0, struct domain_info *domain, const struct condition_list *condition, const bool is_delete)
40 kumaneko 111 {
41     struct acl_info *ptr;
42 kumaneko 708 struct argv0_acl_record *acl;
43 kumaneko 856 struct argv0_acl_record_with_condition *p;
44 kumaneko 111 const struct path_info *saved_filename, *saved_argv0;
45     int error = -ENOMEM;
46     if (!IsCorrectPath(filename, 1, 0, -1, __FUNCTION__) || !IsCorrectPath(argv0, -1, 0, -1, __FUNCTION__) || strchr(argv0, '/')) return -EINVAL;
47     if ((saved_filename = SaveName(filename)) == NULL || (saved_argv0 = SaveName(argv0)) == NULL) return -ENOMEM;
48 kumaneko 652 mutex_lock(&domain_acl_lock);
49 kumaneko 514 if (!is_delete) {
50 kumaneko 722 list1_for_each_entry(ptr, &domain->acl_info_list, list) {
51 kumaneko 856 switch (ptr->type) {
52     case TYPE_ARGV0_ACL:
53     if (condition) continue;
54     acl = container_of(ptr, struct argv0_acl_record, head);
55     break;
56     case TYPE_ARGV0_ACL_WITH_CONDITION:
57     p = container_of(ptr, struct argv0_acl_record_with_condition, record.head);
58     if (p->condition != condition) continue;
59     acl = &p->record;
60     break;
61     default:
62     continue;
63 kumaneko 111 }
64 kumaneko 856 if (acl->filename != saved_filename || acl->argv0 != saved_argv0) continue;
65 kumaneko 860 acl->is_deleted = 0;
66 kumaneko 856 /* Found. Nothing to do. */
67     error = 0;
68     goto out;
69 kumaneko 111 }
70 kumaneko 708 /* Not found. Append it to the tail. */
71 kumaneko 856 if (condition) {
72     if ((p = alloc_element(sizeof(*p))) == NULL) goto out;
73     acl = &p->record;
74     p->condition = condition;
75     acl->head.type = TYPE_ARGV0_ACL_WITH_CONDITION;
76     } else {
77     if ((acl = alloc_element(sizeof(*acl))) == NULL) goto out;
78     acl->head.type = TYPE_ARGV0_ACL;
79     }
80 kumaneko 708 acl->filename = saved_filename;
81     acl->argv0 = saved_argv0;
82     error = AddDomainACL(domain, &acl->head);
83 kumaneko 111 } else {
84     error = -ENOENT;
85 kumaneko 722 list1_for_each_entry(ptr, &domain->acl_info_list, list) {
86 kumaneko 856 switch (ptr->type) {
87     case TYPE_ARGV0_ACL:
88     if (condition) continue;
89     acl = container_of(ptr, struct argv0_acl_record, head);
90     break;
91     case TYPE_ARGV0_ACL_WITH_CONDITION:
92     p = container_of(ptr, struct argv0_acl_record_with_condition, record.head);
93     if (p->condition != condition) continue;
94     acl = &p->record;
95     break;
96     default:
97     continue;
98     }
99 kumaneko 860 if (acl->is_deleted || acl->filename != saved_filename || acl->argv0 != saved_argv0) continue;
100     acl->is_deleted = 1;
101     error = DelDomainACL();
102 kumaneko 111 break;
103     }
104     }
105 kumaneko 708 out: ;
106 kumaneko 652 mutex_unlock(&domain_acl_lock);
107 kumaneko 111 return error;
108     }
109    
110     static int CheckArgv0ACL(const struct path_info *filename, const char *argv0_)
111     {
112     const struct domain_info *domain = current->domain_info;
113     int error = -EPERM;
114     struct acl_info *ptr;
115     struct path_info argv0;
116     argv0.name = argv0_;
117     fill_path_info(&argv0);
118 kumaneko 722 list1_for_each_entry(ptr, &domain->acl_info_list, list) {
119 kumaneko 708 struct argv0_acl_record *acl;
120 kumaneko 856 struct argv0_acl_record_with_condition *p;
121     const struct condition_list *cond;
122     switch (ptr->type) {
123     default:
124     continue;
125     case TYPE_ARGV0_ACL:
126     acl = container_of(ptr, struct argv0_acl_record, head);
127     cond = NULL;
128 kumaneko 111 break;
129 kumaneko 856 case TYPE_ARGV0_ACL_WITH_CONDITION:
130     p = container_of(ptr, struct argv0_acl_record_with_condition, record.head);
131     acl = &p->record;
132     cond = p->condition;
133     break;
134 kumaneko 111 }
135 kumaneko 860 if (acl->is_deleted || !CheckCondition(cond, NULL) ||
136 kumaneko 856 !PathMatchesToPattern(filename, acl->filename) ||
137     !PathMatchesToPattern(&argv0, acl->argv0)) continue;
138     error = 0;
139     break;
140 kumaneko 111 }
141     return error;
142     }
143    
144     int CheckArgv0Perm(const struct path_info *filename, const char *argv0)
145     {
146     int error = 0;
147 kumaneko 815 struct domain_info * const domain = current->domain_info;
148     const u8 profile = domain->profile;
149 kumaneko 851 const u8 mode = CheckCCSFlags(CCS_TOMOYO_MAC_FOR_ARGV0);
150 kumaneko 856 const bool is_enforce = (mode == 3);
151 kumaneko 142 if (!filename || !argv0 || !*argv0) return 0;
152 kumaneko 111 error = CheckArgv0ACL(filename, argv0);
153 kumaneko 815 AuditArgv0Log(filename, argv0, !error, profile, mode);
154 kumaneko 856 if (!error) return 0;
155     if (TomoyoVerboseMode()) {
156     printk("TOMOYO-%s: Run %s as %s denied for %s\n", GetMSG(is_enforce), filename->name, argv0, GetLastName(domain));
157 kumaneko 111 }
158 kumaneko 856 if (is_enforce) return CheckSupervisor("%s\n" KEYWORD_ALLOW_ARGV0 "%s %s\n", domain->domainname->name, filename->name, argv0);
159     else if (mode == 1 && CheckDomainQuota(domain)) AddArgv0Entry(filename->name, argv0, domain, NULL, 0);
160     return 0;
161 kumaneko 111 }
162    
163 kumaneko 621 int AddArgv0Policy(char *data, struct domain_info *domain, const struct condition_list *condition, const bool is_delete)
164 kumaneko 111 {
165     char *argv0 = strchr(data, ' ');
166     if (!argv0) return -EINVAL;
167     *argv0++ = '\0';
168 kumaneko 514 return AddArgv0Entry(data, argv0, domain, condition, is_delete);
169 kumaneko 111 }
170    
171     /***** TOMOYO Linux end. *****/

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