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

Subversion リポジトリの参照

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1507 - (show annotations) (download) (as text)
Tue Sep 2 06:45:13 2008 UTC (15 years, 9 months ago) by kumaneko
File MIME type: text/x-csrc
File size: 3674 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.5.5 2008/09/03
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 extern const char *ccs_log_level;
26
27 /***** The structure for chroot restrictions. *****/
28
29 struct chroot_entry {
30 struct chroot_entry *next;
31 const struct path_info *dir;
32 int is_deleted;
33 };
34
35 /************************* CHROOT RESTRICTION HANDLER *************************/
36
37 static struct chroot_entry *chroot_list = NULL;
38
39 static int AddChrootACL(const char *dir, const int is_delete)
40 {
41 struct chroot_entry *new_entry, *ptr;
42 const struct path_info *saved_dir;
43 static DECLARE_MUTEX(lock);
44 int error = -ENOMEM;
45 if (!IsCorrectPath(dir, 1, 0, 1, __FUNCTION__)) return -EINVAL;
46 if ((saved_dir = SaveName(dir)) == NULL) return -ENOMEM;
47 down(&lock);
48 for (ptr = chroot_list; ptr; ptr = ptr->next) {
49 if (ptr->dir == saved_dir) {
50 ptr->is_deleted = is_delete;
51 error = 0;
52 goto out;
53 }
54 }
55 if (is_delete) {
56 error = -ENOENT;
57 goto out;
58 }
59 if ((new_entry = alloc_element(sizeof(*new_entry))) == NULL) goto out;
60 new_entry->dir = saved_dir;
61 mb(); /* Avoid out-of-order execution. */
62 if ((ptr = chroot_list) != NULL) {
63 while (ptr->next) ptr = ptr->next; ptr->next = new_entry;
64 } else {
65 chroot_list = new_entry;
66 }
67 error = 0;
68 printk("%sAllow chroot() to %s\n", ccs_log_level, dir);
69 out:
70 up(&lock);
71 return error;
72 }
73
74 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)
75 #define PATH_or_NAMEIDATA path
76 #else
77 #define PATH_or_NAMEIDATA nameidata
78 #endif
79 int CheckChRootPermission(struct PATH_or_NAMEIDATA *path)
80 {
81 int error = -EPERM;
82 char *root_name;
83 if (!CheckCCSFlags(CCS_SAKURA_RESTRICT_CHROOT)) return 0;
84 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25) && LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 26)
85 root_name = realpath_from_dentry(path->path.dentry, path->path.mnt);
86 #else
87 root_name = realpath_from_dentry(path->dentry, path->mnt);
88 #endif
89 if (root_name) {
90 struct path_info dir;
91 dir.name = root_name;
92 fill_path_info(&dir);
93 if (dir.is_dir) {
94 struct chroot_entry *ptr;
95 for (ptr = chroot_list; ptr; ptr = ptr->next) {
96 if (ptr->is_deleted) continue;
97 if (PathMatchesToPattern(&dir, ptr->dir)) {
98 error = 0;
99 break;
100 }
101 }
102 }
103 }
104 if (error) {
105 const int is_enforce = CheckCCSEnforce(CCS_SAKURA_RESTRICT_CHROOT);
106 const char *exename = GetEXE();
107 printk("SAKURA-%s: chroot %s (pid=%d:exe=%s): Permission denied.\n", GetMSG(is_enforce), root_name, current->pid, exename);
108 if (is_enforce && CheckSupervisor("# %s is requesting\nchroot %s\n", exename, root_name) == 0) error = 0;
109 if (exename) ccs_free(exename);
110 if (!is_enforce && CheckCCSAccept(CCS_SAKURA_RESTRICT_CHROOT, NULL) && root_name) {
111 AddChrootACL(root_name, 0);
112 UpdateCounter(CCS_UPDATES_COUNTER_SYSTEM_POLICY);
113 }
114 if (!is_enforce) error = 0;
115 }
116 ccs_free(root_name);
117 return error;
118 }
119
120 int AddChrootPolicy(char *data, const int is_delete)
121 {
122 return AddChrootACL(data, is_delete);
123 }
124
125 int ReadChrootPolicy(struct io_buffer *head)
126 {
127 struct chroot_entry *ptr = head->read_var2;
128 if (!ptr) ptr = chroot_list;
129 while (ptr) {
130 head->read_var2 = ptr;
131 if (ptr->is_deleted == 0 && io_printf(head, KEYWORD_ALLOW_CHROOT "%s\n", ptr->dir->name)) break;
132 ptr = ptr->next;
133 }
134 return ptr ? -ENOMEM : 0;
135 }
136
137 /***** SAKURA Linux end. *****/

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