開發和下載開源軟體

Browse Subversion Repository

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 502 - (show annotations) (download) (as text)
Tue Sep 25 13:33:45 2007 UTC (16 years, 7 months ago) by kumaneko
File MIME type: text/x-csrc
File size: 3222 byte(s)


1 /*
2 * fs/sakura_umount.c
3 *
4 * Implementation of the Domain-Free Mandatory Access Control.
5 *
6 * Copyright (C) 2005-2007 NTT DATA CORPORATION
7 *
8 * Version: 1.5.0 2007/09/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,6,20)
20 #include <linux/mount.h>
21 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
22 #include <linux/namespace.h>
23 #endif
24
25 extern const char *ccs_log_level;
26
27 /***** The structure for unmount restrictions. *****/
28
29 struct no_umount_entry {
30 struct no_umount_entry *next;
31 const struct path_info *dir;
32 int is_deleted;
33 };
34
35 /************************* UMOUNT RESTRICTION HANDLER *************************/
36
37 static struct no_umount_entry *no_umount_list = NULL;
38
39 static int AddNoUmountACL(const char *dir, const int is_delete)
40 {
41 struct no_umount_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 = no_umount_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 = no_umount_list) != NULL) {
63 while (ptr->next) ptr = ptr->next; ptr->next = new_entry;
64 } else {
65 no_umount_list = new_entry;
66 }
67 error = 0;
68 printk("%sDon't allow umount %s\n", ccs_log_level, dir);
69 out:
70 up(&lock);
71 return error;
72 }
73
74 int SAKURA_MayUmount(struct vfsmount *mnt)
75 {
76 int error = -EPERM;
77 const char *dir0;
78 const int is_enforce = CheckCCSEnforce(CCS_SAKURA_RESTRICT_UNMOUNT);
79 if (!CheckCCSFlags(CCS_SAKURA_RESTRICT_UNMOUNT)) return 0;
80 dir0 = realpath_from_dentry(mnt->mnt_root, mnt);
81 if (dir0) {
82 struct no_umount_entry *ptr;
83 struct path_info dir;
84 dir.name = dir0;
85 fill_path_info(&dir);
86 for (ptr = no_umount_list; ptr; ptr = ptr->next) {
87 if (ptr->is_deleted) continue;
88 if (PathMatchesToPattern(&dir, ptr->dir)) break;
89 }
90 if (ptr) {
91 const char *exename = GetEXE();
92 printk("SAKURA-%s: umount %s (pid=%d:exe=%s): Permission denied.\n", GetMSG(is_enforce), dir0, current->pid, exename);
93 if (is_enforce && CheckSupervisor("# %s is requesting\nunmount %s\n", exename, dir0) == 0) error = 0;
94 ccs_free(exename);
95 } else {
96 error = 0;
97 }
98 ccs_free(dir0);
99 }
100 if (!is_enforce) error = 0;
101 return error;
102 }
103 EXPORT_SYMBOL(SAKURA_MayUmount);
104
105 int AddNoUmountPolicy(char *data, const int is_delete)
106 {
107 return AddNoUmountACL(data, is_delete);
108 }
109
110 int ReadNoUmountPolicy(struct io_buffer *head)
111 {
112 struct no_umount_entry *ptr = head->read_var2;
113 if (!ptr) ptr = no_umount_list;
114 while (ptr) {
115 head->read_var2 = ptr;
116 if (ptr->is_deleted == 0 && io_printf(head, KEYWORD_DENY_UNMOUNT "%s\n", ptr->dir->name)) break;
117 ptr = ptr->next;
118 }
119 return ptr ? -ENOMEM : 0;
120 }
121
122 /***** SAKURA Linux end. *****/

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