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

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