Open-Source-Software-Entwicklung und Downloads

Browse Subversion Repository

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1135 - (show annotations) (download) (as text)
Thu Apr 24 07:34:11 2008 UTC (16 years, 1 month ago) by kumaneko
File MIME type: text/x-csrc
File size: 3199 byte(s)


1 /*
2 * fs/sakura_umount.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.4-rc 2008/04/24
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(); /* Avoid out-of-order execution. */
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
104 int AddNoUmountPolicy(char *data, const int is_delete)
105 {
106 return AddNoUmountACL(data, is_delete);
107 }
108
109 int ReadNoUmountPolicy(struct io_buffer *head)
110 {
111 struct no_umount_entry *ptr = head->read_var2;
112 if (!ptr) ptr = no_umount_list;
113 while (ptr) {
114 head->read_var2 = ptr;
115 if (ptr->is_deleted == 0 && io_printf(head, KEYWORD_DENY_UNMOUNT "%s\n", ptr->dir->name)) break;
116 ptr = ptr->next;
117 }
118 return ptr ? -ENOMEM : 0;
119 }
120
121 /***** SAKURA Linux end. *****/

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