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 1015 - (show annotations) (download) (as text)
Tue Mar 4 04:04:39 2008 UTC (16 years, 3 months ago) by kumaneko
File MIME type: text/x-csrc
File size: 4552 byte(s)


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.6.0-pre 2008/03/04
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 /************************* AUDIT FUNCTIONS *************************/
21
22 static int AuditArgv0Log(const struct path_info *filename, const char *argv0, const bool is_granted, const u8 profile, const u8 mode)
23 {
24 char *buf;
25 int len;
26 if (CanSaveAuditLog(is_granted) < 0) return -ENOMEM;
27 len = filename->total_len + strlen(argv0) + 8;
28 if ((buf = InitAuditLog(&len, profile, mode, NULL)) == NULL) return -ENOMEM;
29 snprintf(buf + strlen(buf), len - strlen(buf) - 1, KEYWORD_ALLOW_ARGV0 "%s %s\n", filename->name, argv0);
30 return WriteAuditLog(buf, is_granted);
31 }
32
33 /************************* ARGV0 MISMATCH HANDLER *************************/
34
35 static int AddArgv0Entry(const char *filename, const char *argv0, struct domain_info *domain, const struct condition_list *condition, const bool is_delete)
36 {
37 struct acl_info *ptr;
38 struct argv0_acl_record *acl;
39 const struct path_info *saved_filename, *saved_argv0;
40 int error = -ENOMEM;
41 if (!IsCorrectPath(filename, 1, 0, -1, __FUNCTION__) || !IsCorrectPath(argv0, -1, 0, -1, __FUNCTION__) || strchr(argv0, '/')) return -EINVAL;
42 if ((saved_filename = SaveName(filename)) == NULL || (saved_argv0 = SaveName(argv0)) == NULL) return -ENOMEM;
43 mutex_lock(&domain_acl_lock);
44 if (!is_delete) {
45 list1_for_each_entry(ptr, &domain->acl_info_list, list) {
46 if ((ptr->type & ~(ACL_DELETED | ACL_WITH_CONDITION)) != TYPE_ARGV0_ACL) continue;
47 if (GetConditionPart(ptr) != condition) continue;
48 acl = container_of(ptr, struct argv0_acl_record, head);
49 if (acl->filename != saved_filename || acl->argv0 != saved_argv0) continue;
50 error = AddDomainACL(NULL, ptr);
51 goto out;
52 }
53 /* Not found. Append it to the tail. */
54 if ((acl = alloc_acl_element(TYPE_ARGV0_ACL, condition)) == NULL) goto out;
55 acl->filename = saved_filename;
56 acl->argv0 = saved_argv0;
57 error = AddDomainACL(domain, &acl->head);
58 } else {
59 error = -ENOENT;
60 list1_for_each_entry(ptr, &domain->acl_info_list, list) {
61 if ((ptr->type & ~ACL_WITH_CONDITION) != TYPE_ARGV0_ACL) continue;
62 if (GetConditionPart(ptr) != condition) continue;
63 acl = container_of(ptr, struct argv0_acl_record, head);
64 if (acl->filename != saved_filename || acl->argv0 != saved_argv0) continue;
65 error = DelDomainACL(ptr);
66 break;
67 }
68 }
69 out: ;
70 mutex_unlock(&domain_acl_lock);
71 return error;
72 }
73
74 static int CheckArgv0ACL(const struct path_info *filename, const char *argv0_)
75 {
76 const struct domain_info *domain = current->domain_info;
77 int error = -EPERM;
78 struct acl_info *ptr;
79 struct path_info argv0;
80 argv0.name = argv0_;
81 fill_path_info(&argv0);
82 list1_for_each_entry(ptr, &domain->acl_info_list, list) {
83 struct argv0_acl_record *acl;
84 if ((ptr->type & ~ACL_WITH_CONDITION) != TYPE_ARGV0_ACL) continue;
85 acl = container_of(ptr, struct argv0_acl_record, head);
86 if (!CheckCondition(ptr, NULL) ||
87 !PathMatchesToPattern(filename, acl->filename) ||
88 !PathMatchesToPattern(&argv0, acl->argv0)) continue;
89 UpdateCondition(ptr);
90 error = 0;
91 break;
92 }
93 return error;
94 }
95
96 int CheckArgv0Perm(const struct path_info *filename, const char *argv0)
97 {
98 int error = 0;
99 struct domain_info * const domain = current->domain_info;
100 const u8 profile = domain->profile;
101 const u8 mode = CheckCCSFlags(CCS_TOMOYO_MAC_FOR_ARGV0);
102 const bool is_enforce = (mode == 3);
103 if (!filename || !argv0 || !*argv0) return 0;
104 error = CheckArgv0ACL(filename, argv0);
105 AuditArgv0Log(filename, argv0, !error, profile, mode);
106 if (!error) return 0;
107 if (TomoyoVerboseMode()) {
108 printk("TOMOYO-%s: Run %s as %s denied for %s\n", GetMSG(is_enforce), filename->name, argv0, GetLastName(domain));
109 }
110 if (is_enforce) return CheckSupervisor("%s\n" KEYWORD_ALLOW_ARGV0 "%s %s\n", domain->domainname->name, filename->name, argv0);
111 else if (mode == 1 && CheckDomainQuota(domain)) AddArgv0Entry(filename->name, argv0, domain, NULL, 0);
112 return 0;
113 }
114
115 int AddArgv0Policy(char *data, struct domain_info *domain, const struct condition_list *condition, const bool is_delete)
116 {
117 char *argv0 = strchr(data, ' ');
118 if (!argv0) return -EINVAL;
119 *argv0++ = '\0';
120 return AddArgv0Entry(data, argv0, domain, condition, is_delete);
121 }
122
123 /***** TOMOYO Linux end. *****/

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