Open-Source-Software-Entwicklung und Downloads

Browse Subversion Repository

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 808 - (show annotations) (download) (as text)
Mon Dec 17 04:06:21 2007 UTC (16 years, 5 months ago) by kumaneko
Original Path: trunk/1.5.x/ccs-patch/fs/tomoyo_exec.c
File MIME type: text/x-csrc
File size: 4518 byte(s)
Remove unused EXPORT_SYMBOL().
1 /*
2 * fs/tomoyo_exec.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.3-pre 2007/12/17
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)
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)) == 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 const struct path_info *saved_filename, *saved_argv0;
44 int error = -ENOMEM;
45 if (!IsCorrectPath(filename, 1, 0, -1, __FUNCTION__) || !IsCorrectPath(argv0, -1, 0, -1, __FUNCTION__) || strchr(argv0, '/')) return -EINVAL;
46 if ((saved_filename = SaveName(filename)) == NULL || (saved_argv0 = SaveName(argv0)) == NULL) return -ENOMEM;
47 mutex_lock(&domain_acl_lock);
48 if (!is_delete) {
49 list1_for_each_entry(ptr, &domain->acl_info_list, list) {
50 acl = container_of(ptr, struct argv0_acl_record, head);
51 if (ptr->type == TYPE_ARGV0_ACL && ptr->cond == condition) {
52 if (acl->filename == saved_filename && acl->argv0 == saved_argv0) {
53 ptr->is_deleted = 0;
54 /* Found. Nothing to do. */
55 error = 0;
56 goto out;
57 }
58 }
59 }
60 /* Not found. Append it to the tail. */
61 if ((acl = alloc_element(sizeof(*acl))) == NULL) goto out;
62 acl->head.type = TYPE_ARGV0_ACL;
63 acl->head.cond = condition;
64 acl->filename = saved_filename;
65 acl->argv0 = saved_argv0;
66 error = AddDomainACL(domain, &acl->head);
67 } else {
68 error = -ENOENT;
69 list1_for_each_entry(ptr, &domain->acl_info_list, list) {
70 acl = container_of(ptr, struct argv0_acl_record, head);
71 if (ptr->type != TYPE_ARGV0_ACL || ptr->is_deleted || ptr->cond != condition) continue;
72 if (acl->filename != saved_filename || acl->argv0 != saved_argv0) continue;
73 error = DelDomainACL(ptr);
74 break;
75 }
76 }
77 out: ;
78 mutex_unlock(&domain_acl_lock);
79 return error;
80 }
81
82 static int CheckArgv0ACL(const struct path_info *filename, const char *argv0_)
83 {
84 const struct domain_info *domain = current->domain_info;
85 int error = -EPERM;
86 struct acl_info *ptr;
87 struct path_info argv0;
88 argv0.name = argv0_;
89 fill_path_info(&argv0);
90 list1_for_each_entry(ptr, &domain->acl_info_list, list) {
91 struct argv0_acl_record *acl;
92 acl = container_of(ptr, struct argv0_acl_record, head);
93 if (ptr->type == TYPE_ARGV0_ACL && ptr->is_deleted == 0 && CheckCondition(ptr->cond, NULL) == 0 &&
94 PathMatchesToPattern(filename, acl->filename) &&
95 PathMatchesToPattern(&argv0, acl->argv0)) {
96 error = 0;
97 break;
98 }
99 }
100 return error;
101 }
102
103 int CheckArgv0Perm(const struct path_info *filename, const char *argv0)
104 {
105 int error = 0;
106 if (!filename || !argv0 || !*argv0) return 0;
107 error = CheckArgv0ACL(filename, argv0);
108 AuditArgv0Log(filename, argv0, !error);
109 if (error) {
110 struct domain_info * const domain = current->domain_info;
111 const bool is_enforce = CheckCCSEnforce(CCS_TOMOYO_MAC_FOR_ARGV0);
112 if (TomoyoVerboseMode()) {
113 printk("TOMOYO-%s: Run %s as %s denied for %s\n", GetMSG(is_enforce), filename->name, argv0, GetLastName(domain));
114 }
115 if (is_enforce) error = CheckSupervisor("%s\n" KEYWORD_ALLOW_ARGV0 "%s %s\n", domain->domainname->name, filename->name, argv0);
116 else if (CheckCCSAccept(CCS_TOMOYO_MAC_FOR_ARGV0, domain)) AddArgv0Entry(filename->name, argv0, domain, NULL, 0);
117 if (!is_enforce) error = 0;
118 }
119 return error;
120 }
121
122 int AddArgv0Policy(char *data, struct domain_info *domain, const struct condition_list *condition, const bool is_delete)
123 {
124 char *argv0 = strchr(data, ' ');
125 if (!argv0) return -EINVAL;
126 *argv0++ = '\0';
127 return AddArgv0Entry(data, argv0, domain, condition, is_delete);
128 }
129
130 /***** TOMOYO Linux end. *****/

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