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

Subversion リポジトリの参照

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 224 - (show annotations) (download) (as text)
Sun May 20 03:25:13 2007 UTC (17 years ago) by kumaneko
Original Path: trunk/ccs-patch/fs/sakura_chroot.c
File MIME type: text/x-csrc
File size: 3376 byte(s)


1 /*
2 * fs/sakura_chroot.c
3 *
4 * Implementation of the Domain-Free Mandatory Access Control.
5 *
6 * Copyright (C) 2005-2007 NTT DATA CORPORATION
7 *
8 * Version: 1.4.1-rc1 2007/05/20
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(); /* Instead of using spinlock. */
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 int CheckChRootPermission(struct nameidata *nd)
75 {
76 int error = -EPERM;
77 char *root_name;
78 if (!CheckCCSFlags(CCS_SAKURA_RESTRICT_CHROOT)) return 0;
79 root_name = realpath_from_dentry(nd->dentry, nd->mnt);
80 if (root_name) {
81 struct path_info dir;
82 dir.name = root_name;
83 fill_path_info(&dir);
84 if (dir.is_dir) {
85 struct chroot_entry *ptr;
86 for (ptr = chroot_list; ptr; ptr = ptr->next) {
87 if (ptr->is_deleted) continue;
88 if (PathMatchesToPattern(&dir, ptr->dir)) {
89 error = 0;
90 break;
91 }
92 }
93 }
94 }
95 if (error) {
96 const int is_enforce = CheckCCSEnforce(CCS_SAKURA_RESTRICT_CHROOT);
97 const char *exename = GetEXE();
98 printk("SAKURA-%s: chroot %s (pid=%d:exe=%s): Permission denied.\n", GetMSG(is_enforce), root_name, current->pid, exename);
99 if (is_enforce && CheckSupervisor("# %s is requesting\nchroot %s\n", exename, root_name) == 0) error = 0;
100 if (exename) ccs_free(exename);
101 if (!is_enforce && CheckCCSAccept(CCS_SAKURA_RESTRICT_CHROOT) && root_name) {
102 AddChrootACL(root_name, 0);
103 UpdateCounter(CCS_UPDATES_COUNTER_SYSTEM_POLICY);
104 }
105 if (!is_enforce) error = 0;
106 }
107 ccs_free(root_name);
108 return error;
109 }
110 EXPORT_SYMBOL(CheckChRootPermission);
111
112 int AddChrootPolicy(char *data, const int is_delete)
113 {
114 return AddChrootACL(data, is_delete);
115 }
116
117 int ReadChrootPolicy(struct io_buffer *head)
118 {
119 struct chroot_entry *ptr = head->read_var2;
120 if (!ptr) ptr = chroot_list;
121 while (ptr) {
122 head->read_var2 = ptr;
123 if (ptr->is_deleted == 0 && io_printf(head, KEYWORD_ALLOW_CHROOT "%s\n", ptr->dir->name)) break;
124 ptr = ptr->next;
125 }
126 return ptr ? -ENOMEM : 0;
127 }
128
129 /***** SAKURA Linux end. *****/

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