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

Subversion リポジトリの参照

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1032 - (show annotations) (download) (as text)
Tue Mar 11 08:25:41 2008 UTC (16 years, 2 months ago) by kumaneko
File MIME type: text/x-csrc
File size: 3285 byte(s)


1 /*
2 * fs/sakura_chroot.c
3 *
4 * Implementation of the Domain-Free 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 /***** SAKURA Linux start. *****/
15
16 #include <linux/ccs_common.h>
17 #include <linux/sakura.h>
18 #include <linux/realpath.h>
19 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
20 #include <linux/namei.h>
21 #else
22 #include <linux/fs.h>
23 #endif
24
25 /***** The structure for chroot restrictions. *****/
26
27 struct chroot_entry {
28 struct list1_head list;
29 const struct path_info *dir;
30 bool is_deleted;
31 };
32
33 /************************* CHROOT RESTRICTION HANDLER *************************/
34
35 static LIST1_HEAD(chroot_list);
36
37 static int AddChrootACL(const char *dir, const bool is_delete)
38 {
39 struct chroot_entry *new_entry, *ptr;
40 const struct path_info *saved_dir;
41 static DEFINE_MUTEX(lock);
42 int error = -ENOMEM;
43 if (!IsCorrectPath(dir, 1, 0, 1, __FUNCTION__)) return -EINVAL;
44 if ((saved_dir = SaveName(dir)) == NULL) return -ENOMEM;
45 mutex_lock(&lock);
46 list1_for_each_entry(ptr, &chroot_list, list) {
47 if (ptr->dir == saved_dir) {
48 ptr->is_deleted = is_delete;
49 error = 0;
50 goto out;
51 }
52 }
53 if (is_delete) {
54 error = -ENOENT;
55 goto out;
56 }
57 if ((new_entry = alloc_element(sizeof(*new_entry))) == NULL) goto out;
58 new_entry->dir = saved_dir;
59 list1_add_tail_mb(&new_entry->list, &chroot_list);
60 error = 0;
61 printk("%sAllow chroot() to %s\n", ccs_log_level, dir);
62 out:
63 mutex_unlock(&lock);
64 return error;
65 }
66
67 int CheckChRootPermission(struct nameidata *nd)
68 {
69 int error = -EPERM;
70 char *root_name;
71 const u8 mode = CheckCCSFlags(CCS_SAKURA_RESTRICT_CHROOT);
72 if (!mode) return 0;
73 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,25)
74 root_name = realpath_from_dentry(nd->path.dentry, nd->path.mnt);
75 #else
76 root_name = realpath_from_dentry(nd->dentry, nd->mnt);
77 #endif
78 if (root_name) {
79 struct path_info dir;
80 dir.name = root_name;
81 fill_path_info(&dir);
82 if (dir.is_dir) {
83 struct chroot_entry *ptr;
84 list1_for_each_entry(ptr, &chroot_list, list) {
85 if (ptr->is_deleted) continue;
86 if (PathMatchesToPattern(&dir, ptr->dir)) {
87 error = 0;
88 break;
89 }
90 }
91 }
92 }
93 if (error) {
94 const bool is_enforce = (mode == 3);
95 const char *exename = GetEXE();
96 printk("SAKURA-%s: chroot %s (pid=%d:exe=%s): Permission denied.\n", GetMSG(is_enforce), root_name, current->pid, exename);
97 if (is_enforce && CheckSupervisor("# %s is requesting\nchroot %s\n", exename, root_name) == 0) error = 0;
98 if (exename) ccs_free(exename);
99 if (mode == 1 && root_name) {
100 AddChrootACL(root_name, 0);
101 UpdateCounter(CCS_UPDATES_COUNTER_SYSTEM_POLICY);
102 }
103 if (!is_enforce) error = 0;
104 }
105 ccs_free(root_name);
106 return error;
107 }
108
109 int AddChrootPolicy(char *data, const bool is_delete)
110 {
111 return AddChrootACL(data, is_delete);
112 }
113
114 int ReadChrootPolicy(struct io_buffer *head)
115 {
116 struct list1_head *pos;
117 list1_for_each_cookie(pos, head->read_var2, &chroot_list) {
118 struct chroot_entry *ptr;
119 ptr = list1_entry(pos, struct chroot_entry, list);
120 if (ptr->is_deleted) continue;
121 if (io_printf(head, KEYWORD_ALLOW_CHROOT "%s\n", ptr->dir->name)) return -ENOMEM;
122 }
123 return 0;
124 }
125
126 /***** SAKURA Linux end. *****/

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