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

Subversion リポジトリの参照

Annotation of /trunk/1.6.x/ccs-patch/fs/sakura_chroot.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1498 - (hide annotations) (download) (as text)
Fri Aug 29 12:08:57 2008 UTC (15 years, 8 months ago) by kumaneko
File MIME type: text/x-csrc
File size: 4786 byte(s)
1.5.5-rc/1.6.4-rc
1 kumaneko 111 /*
2     * fs/sakura_chroot.c
3     *
4     * Implementation of the Domain-Free Mandatory Access Control.
5     *
6 kumaneko 852 * Copyright (C) 2005-2008 NTT DATA CORPORATION
7 kumaneko 111 *
8 kumaneko 1498 * Version: 1.6.4-rc 2008/08/29
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    
15     #include <linux/ccs_common.h>
16     #include <linux/sakura.h>
17     #include <linux/realpath.h>
18 kumaneko 1052 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 0)
19 kumaneko 141 #include <linux/namei.h>
20     #else
21     #include <linux/fs.h>
22     #endif
23 kumaneko 111
24 kumaneko 1052 /* Structure for "allow_chroot" keyword. */
25 kumaneko 214 struct chroot_entry {
26 kumaneko 722 struct list1_head list;
27 kumaneko 111 const struct path_info *dir;
28 kumaneko 621 bool is_deleted;
29 kumaneko 214 };
30 kumaneko 111
31 kumaneko 1052 /* The list for "struct chroot_entry". */
32 kumaneko 722 static LIST1_HEAD(chroot_list);
33 kumaneko 111
34 kumaneko 1052 /**
35     * update_chroot_acl - Update "struct chroot_entry" list.
36     *
37     * @dir: The name of directory.
38     * @is_delete: True if it is a delete request.
39     *
40     * Returns 0 on success, negative value otherwise.
41     */
42     static int update_chroot_acl(const char *dir, const bool is_delete)
43 kumaneko 111 {
44 kumaneko 1064 struct chroot_entry *new_entry;
45     struct chroot_entry *ptr;
46 kumaneko 111 const struct path_info *saved_dir;
47 kumaneko 652 static DEFINE_MUTEX(lock);
48 kumaneko 111 int error = -ENOMEM;
49 kumaneko 1052 if (!ccs_is_correct_path(dir, 1, 0, 1, __func__))
50     return -EINVAL;
51     saved_dir = ccs_save_name(dir);
52     if (!saved_dir)
53     return -ENOMEM;
54 kumaneko 652 mutex_lock(&lock);
55 kumaneko 722 list1_for_each_entry(ptr, &chroot_list, list) {
56 kumaneko 1064 if (ptr->dir != saved_dir)
57     continue;
58     ptr->is_deleted = is_delete;
59     error = 0;
60     goto out;
61 kumaneko 111 }
62     if (is_delete) {
63     error = -ENOENT;
64     goto out;
65     }
66 kumaneko 1052 new_entry = ccs_alloc_element(sizeof(*new_entry));
67     if (!new_entry)
68     goto out;
69 kumaneko 111 new_entry->dir = saved_dir;
70 kumaneko 722 list1_add_tail_mb(&new_entry->list, &chroot_list);
71 kumaneko 111 error = 0;
72 kumaneko 1052 printk(KERN_CONT "%sAllow chroot() to %s\n", ccs_log_level, dir);
73 kumaneko 111 out:
74 kumaneko 652 mutex_unlock(&lock);
75 kumaneko 1064 ccs_update_counter(CCS_UPDATES_COUNTER_SYSTEM_POLICY);
76 kumaneko 111 return error;
77     }
78    
79 kumaneko 1052 /**
80     * print_error - Print error message.
81     *
82     * @root_name: Requested directory name.
83     * @mode: Access control mode.
84     *
85     * Returns 0 if @mode is not enforcing mode or permitted by the administrator's
86     * decision, negative value otherwise.
87     */
88 kumaneko 1064 static int print_error(const char *root_name, const u8 mode)
89 kumaneko 111 {
90 kumaneko 1064 int error;
91 kumaneko 1052 const bool is_enforce = (mode == 3);
92     const char *exename = ccs_get_exe();
93     printk(KERN_WARNING "SAKURA-%s: chroot %s (pid=%d:exe=%s): "
94     "Permission denied.\n", ccs_get_msg(is_enforce),
95     root_name, current->pid, exename);
96 kumaneko 1064 if (is_enforce)
97 kumaneko 1260 error = ccs_check_supervisor(NULL, "# %s is requesting\n"
98 kumaneko 1064 "chroot %s\n", exename, root_name);
99     else
100 kumaneko 1052 error = 0;
101     if (exename)
102     ccs_free(exename);
103 kumaneko 1064 if (mode == 1 && root_name)
104     update_chroot_acl(root_name, false);
105 kumaneko 1052 return error;
106     }
107    
108 kumaneko 1425 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)
109     #define PATH_or_NAMEIDATA path
110     #else
111     #define PATH_or_NAMEIDATA nameidata
112     #endif
113 kumaneko 1052 /**
114     * ccs_check_chroot_permission - Check permission for chroot().
115     *
116 kumaneko 1425 * @path: Pointer to "struct path" (for 2.6.27 and later).
117     * Pointer to "struct nameidata" (for 2.6.26 and earlier).
118 kumaneko 1052 *
119     * Returns 0 on success, negative value otherwise.
120     */
121 kumaneko 1425 int ccs_check_chroot_permission(struct PATH_or_NAMEIDATA *path)
122 kumaneko 1052 {
123 kumaneko 141 int error = -EPERM;
124     char *root_name;
125 kumaneko 1052 const u8 mode = ccs_check_flags(CCS_SAKURA_RESTRICT_CHROOT);
126     if (!mode)
127     return 0;
128 kumaneko 1468 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25) && LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 26)
129 kumaneko 1425 root_name = ccs_realpath_from_dentry(path->path.dentry, path->path.mnt);
130 kumaneko 990 #else
131 kumaneko 1425 root_name = ccs_realpath_from_dentry(path->dentry, path->mnt);
132 kumaneko 990 #endif
133 kumaneko 141 if (root_name) {
134 kumaneko 111 struct path_info dir;
135 kumaneko 141 dir.name = root_name;
136 kumaneko 1052 ccs_fill_path_info(&dir);
137 kumaneko 111 if (dir.is_dir) {
138 kumaneko 214 struct chroot_entry *ptr;
139 kumaneko 722 list1_for_each_entry(ptr, &chroot_list, list) {
140 kumaneko 1052 if (ptr->is_deleted)
141     continue;
142 kumaneko 1064 if (!ccs_path_matches_pattern(&dir, ptr->dir))
143     continue;
144     error = 0;
145     break;
146 kumaneko 111 }
147     }
148     }
149 kumaneko 1052 if (error)
150 kumaneko 1064 error = print_error(root_name, mode);
151 kumaneko 141 ccs_free(root_name);
152     return error;
153 kumaneko 111 }
154    
155 kumaneko 1052 /**
156     * ccs_write_chroot_policy - Write "struct chroot_entry" list.
157     *
158     * @data: String to parse.
159     * @is_delete: True if it is a delete request.
160     *
161     * Returns 0 on success, negative value otherwise.
162     */
163     int ccs_write_chroot_policy(char *data, const bool is_delete)
164 kumaneko 111 {
165 kumaneko 1052 return update_chroot_acl(data, is_delete);
166 kumaneko 111 }
167    
168 kumaneko 1052 /**
169 kumaneko 1054 * ccs_read_chroot_policy - Read "struct chroot_entry" list.
170 kumaneko 1052 *
171     * @head: Pointer to "struct ccs_io_buffer".
172     *
173     * Returns true on success, false otherwise.
174     */
175     bool ccs_read_chroot_policy(struct ccs_io_buffer *head)
176 kumaneko 111 {
177 kumaneko 722 struct list1_head *pos;
178     list1_for_each_cookie(pos, head->read_var2, &chroot_list) {
179 kumaneko 708 struct chroot_entry *ptr;
180 kumaneko 722 ptr = list1_entry(pos, struct chroot_entry, list);
181 kumaneko 1052 if (ptr->is_deleted)
182     continue;
183     if (!ccs_io_printf(head, KEYWORD_ALLOW_CHROOT "%s\n",
184     ptr->dir->name))
185     goto out;
186 kumaneko 111 }
187 kumaneko 1052 return true;
188     out:
189     return false;
190 kumaneko 111 }

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