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

Subversion リポジトリの参照

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 856 - (show annotations) (download) (as text)
Thu Jan 3 07:16:18 2008 UTC (16 years, 4 months ago) by kumaneko
File MIME type: text/x-csrc
File size: 5614 byte(s)
Change internal structure.
1 /*
2 * fs/tomoyo_exec.c
3 *
4 * Implementation of the Domain-Based Mandatory Access Control.
5 *
6 * Copyright (C) 2005-2008 NTT DATA CORPORATION
7 *
8 * Version: 1.5.3-pre 2008/01/03
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 extern struct mutex domain_acl_lock;
23
24 /************************* AUDIT FUNCTIONS *************************/
25
26 static int AuditArgv0Log(const struct path_info *filename, const char *argv0, const bool is_granted, const u8 profile, const u8 mode)
27 {
28 char *buf;
29 int len;
30 if (CanSaveAuditLog(is_granted) < 0) return -ENOMEM;
31 len = filename->total_len + strlen(argv0) + 8;
32 if ((buf = InitAuditLog(&len, profile, mode)) == NULL) return -ENOMEM;
33 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 static int AddArgv0Entry(const char *filename, const char *argv0, struct domain_info *domain, const struct condition_list *condition, const bool is_delete)
40 {
41 struct acl_info *ptr;
42 struct argv0_acl_record *acl;
43 struct argv0_acl_record_with_condition *p;
44 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 mutex_lock(&domain_acl_lock);
49 if (!is_delete) {
50 list1_for_each_entry(ptr, &domain->acl_info_list, list) {
51 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 }
64 if (acl->filename != saved_filename || acl->argv0 != saved_argv0) continue;
65 ptr->is_deleted = 0;
66 /* Found. Nothing to do. */
67 error = 0;
68 goto out;
69 }
70 /* Not found. Append it to the tail. */
71 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 acl->filename = saved_filename;
81 acl->argv0 = saved_argv0;
82 error = AddDomainACL(domain, &acl->head);
83 } else {
84 error = -ENOENT;
85 list1_for_each_entry(ptr, &domain->acl_info_list, list) {
86 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 if (ptr->is_deleted || acl->filename != saved_filename || acl->argv0 != saved_argv0) continue;
100 error = DelDomainACL(ptr);
101 break;
102 }
103 }
104 out: ;
105 mutex_unlock(&domain_acl_lock);
106 return error;
107 }
108
109 static int CheckArgv0ACL(const struct path_info *filename, const char *argv0_)
110 {
111 const struct domain_info *domain = current->domain_info;
112 int error = -EPERM;
113 struct acl_info *ptr;
114 struct path_info argv0;
115 argv0.name = argv0_;
116 fill_path_info(&argv0);
117 list1_for_each_entry(ptr, &domain->acl_info_list, list) {
118 struct argv0_acl_record *acl;
119 struct argv0_acl_record_with_condition *p;
120 const struct condition_list *cond;
121 switch (ptr->type) {
122 default:
123 continue;
124 case TYPE_ARGV0_ACL:
125 acl = container_of(ptr, struct argv0_acl_record, head);
126 cond = NULL;
127 break;
128 case TYPE_ARGV0_ACL_WITH_CONDITION:
129 p = container_of(ptr, struct argv0_acl_record_with_condition, record.head);
130 acl = &p->record;
131 cond = p->condition;
132 break;
133 }
134 if (ptr->is_deleted || !CheckCondition(cond, NULL) ||
135 !PathMatchesToPattern(filename, acl->filename) ||
136 !PathMatchesToPattern(&argv0, acl->argv0)) continue;
137 error = 0;
138 break;
139 }
140 return error;
141 }
142
143 int CheckArgv0Perm(const struct path_info *filename, const char *argv0)
144 {
145 int error = 0;
146 struct domain_info * const domain = current->domain_info;
147 const u8 profile = domain->profile;
148 const u8 mode = CheckCCSFlags(CCS_TOMOYO_MAC_FOR_ARGV0);
149 const bool is_enforce = (mode == 3);
150 if (!filename || !argv0 || !*argv0) return 0;
151 error = CheckArgv0ACL(filename, argv0);
152 AuditArgv0Log(filename, argv0, !error, profile, mode);
153 if (!error) return 0;
154 if (TomoyoVerboseMode()) {
155 printk("TOMOYO-%s: Run %s as %s denied for %s\n", GetMSG(is_enforce), filename->name, argv0, GetLastName(domain));
156 }
157 if (is_enforce) return CheckSupervisor("%s\n" KEYWORD_ALLOW_ARGV0 "%s %s\n", domain->domainname->name, filename->name, argv0);
158 else if (mode == 1 && CheckDomainQuota(domain)) AddArgv0Entry(filename->name, argv0, domain, NULL, 0);
159 return 0;
160 }
161
162 int AddArgv0Policy(char *data, struct domain_info *domain, const struct condition_list *condition, const bool is_delete)
163 {
164 char *argv0 = strchr(data, ' ');
165 if (!argv0) return -EINVAL;
166 *argv0++ = '\0';
167 return AddArgv0Entry(data, argv0, domain, condition, is_delete);
168 }
169
170 /***** TOMOYO Linux end. *****/

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