1 |
kumaneko |
1498 |
This is TOMOYO Linux patch for openSUSE 11.0. |
2 |
|
|
|
3 |
kumaneko |
2073 |
Source code for this patch is http://download.opensuse.org/update/11.0/rpm/i586/kernel-source-2.6.25.20-0.1.i586.rpm |
4 |
kumaneko |
1498 |
--- |
5 |
|
|
arch/ia64/ia32/sys_ia32.c | 9 ++ |
6 |
|
|
arch/mips/kernel/ptrace32.c | 9 ++ |
7 |
|
|
arch/s390/kernel/ptrace.c | 9 ++ |
8 |
|
|
arch/x86/kernel/ptrace.c | 9 ++ |
9 |
|
|
fs/Kconfig | 2 |
10 |
|
|
fs/Makefile | 2 |
11 |
|
|
fs/attr.c | 19 ++++++ |
12 |
|
|
fs/compat.c | 5 + |
13 |
|
|
fs/compat_ioctl.c | 9 ++ |
14 |
|
|
fs/exec.c | 20 ++++++ |
15 |
|
|
fs/fcntl.c | 9 ++ |
16 |
|
|
fs/ioctl.c | 7 ++ |
17 |
|
|
fs/namei.c | 122 ++++++++++++++++++++++++++++++++++++++++ |
18 |
|
|
fs/namespace.c | 49 ++++++++++++++++ |
19 |
|
|
fs/open.c | 29 +++++++++ |
20 |
|
|
fs/proc/Makefile | 3 |
21 |
|
|
fs/proc/proc_misc.c | 5 + |
22 |
|
|
include/linux/init_task.h | 4 + |
23 |
|
|
include/linux/sched.h | 9 ++ |
24 |
|
|
kernel/compat.c | 7 ++ |
25 |
|
|
kernel/kexec.c | 7 ++ |
26 |
|
|
kernel/kmod.c | 5 + |
27 |
|
|
kernel/module.c | 11 +++ |
28 |
|
|
kernel/ptrace.c | 15 ++++ |
29 |
|
|
kernel/sched.c | 7 ++ |
30 |
|
|
kernel/signal.c | 21 ++++++ |
31 |
|
|
kernel/sys.c | 21 ++++++ |
32 |
|
|
kernel/sysctl.c | 95 +++++++++++++++++++++++++++++++ |
33 |
|
|
kernel/time.c | 11 +++ |
34 |
|
|
kernel/time/ntp.c | 7 ++ |
35 |
|
|
net/core/datagram.c | 11 +++ |
36 |
|
|
net/ipv4/inet_connection_sock.c | 7 ++ |
37 |
|
|
net/ipv4/inet_hashtables.c | 7 ++ |
38 |
|
|
net/ipv4/udp.c | 10 +++ |
39 |
|
|
net/socket.c | 41 +++++++++++++ |
40 |
|
|
net/unix/af_unix.c | 15 ++++ |
41 |
kumaneko |
1758 |
36 files changed, 626 insertions(+), 2 deletions(-) |
42 |
kumaneko |
1498 |
|
43 |
kumaneko |
2073 |
--- linux-2.6.25.20-0.1.orig/arch/ia64/ia32/sys_ia32.c |
44 |
|
|
+++ linux-2.6.25.20-0.1/arch/ia64/ia32/sys_ia32.c |
45 |
kumaneko |
1498 |
@@ -50,6 +50,9 @@ |
46 |
|
|
#include <asm/types.h> |
47 |
|
|
#include <asm/uaccess.h> |
48 |
|
|
#include <asm/unistd.h> |
49 |
|
|
+/***** TOMOYO Linux start. *****/ |
50 |
|
|
+#include <linux/tomoyo.h> |
51 |
|
|
+/***** TOMOYO Linux end. *****/ |
52 |
|
|
|
53 |
|
|
#include "ia32priv.h" |
54 |
|
|
|
55 |
|
|
@@ -1753,6 +1756,12 @@ sys32_ptrace (int request, pid_t pid, un |
56 |
|
|
struct task_struct *child; |
57 |
|
|
unsigned int value, tmp; |
58 |
|
|
long i, ret; |
59 |
|
|
+ /***** TOMOYO Linux start. *****/ |
60 |
|
|
+#ifdef TOMOYO_SYS_PTRACE |
61 |
|
|
+ if (!ccs_capable(TOMOYO_SYS_PTRACE)) |
62 |
|
|
+ return -EPERM; |
63 |
|
|
+#endif |
64 |
|
|
+ /***** TOMOYO Linux end. *****/ |
65 |
|
|
|
66 |
|
|
lock_kernel(); |
67 |
|
|
if (request == PTRACE_TRACEME) { |
68 |
kumaneko |
2073 |
--- linux-2.6.25.20-0.1.orig/arch/mips/kernel/ptrace32.c |
69 |
|
|
+++ linux-2.6.25.20-0.1/arch/mips/kernel/ptrace32.c |
70 |
kumaneko |
1498 |
@@ -35,6 +35,9 @@ |
71 |
|
|
#include <asm/system.h> |
72 |
|
|
#include <asm/uaccess.h> |
73 |
|
|
#include <asm/bootinfo.h> |
74 |
|
|
+/***** TOMOYO Linux start. *****/ |
75 |
|
|
+#include <linux/tomoyo.h> |
76 |
|
|
+/***** TOMOYO Linux end. *****/ |
77 |
|
|
|
78 |
|
|
int ptrace_getregs(struct task_struct *child, __s64 __user *data); |
79 |
|
|
int ptrace_setregs(struct task_struct *child, __s64 __user *data); |
80 |
|
|
@@ -50,6 +53,12 @@ asmlinkage int sys32_ptrace(int request, |
81 |
|
|
{ |
82 |
|
|
struct task_struct *child; |
83 |
|
|
int ret; |
84 |
|
|
+ /***** TOMOYO Linux start. *****/ |
85 |
|
|
+#ifdef TOMOYO_SYS_PTRACE |
86 |
|
|
+ if (!ccs_capable(TOMOYO_SYS_PTRACE)) |
87 |
|
|
+ return -EPERM; |
88 |
|
|
+#endif |
89 |
|
|
+ /***** TOMOYO Linux end. *****/ |
90 |
|
|
|
91 |
|
|
#if 0 |
92 |
|
|
printk("ptrace(r=%d,pid=%d,addr=%08lx,data=%08lx)\n", |
93 |
kumaneko |
2073 |
--- linux-2.6.25.20-0.1.orig/arch/s390/kernel/ptrace.c |
94 |
|
|
+++ linux-2.6.25.20-0.1/arch/s390/kernel/ptrace.c |
95 |
kumaneko |
1498 |
@@ -41,6 +41,9 @@ |
96 |
|
|
#include <asm/system.h> |
97 |
|
|
#include <asm/uaccess.h> |
98 |
|
|
#include <asm/unistd.h> |
99 |
|
|
+/***** TOMOYO Linux start. *****/ |
100 |
|
|
+#include <linux/tomoyo.h> |
101 |
|
|
+/***** TOMOYO Linux end. *****/ |
102 |
|
|
|
103 |
|
|
#ifdef CONFIG_COMPAT |
104 |
|
|
#include "compat_ptrace.h" |
105 |
|
|
@@ -698,6 +701,12 @@ sys_ptrace(long request, long pid, long |
106 |
|
|
struct task_struct *child; |
107 |
|
|
int ret; |
108 |
|
|
|
109 |
|
|
+ /***** TOMOYO Linux start. *****/ |
110 |
|
|
+#ifdef TOMOYO_SYS_PTRACE |
111 |
|
|
+ if (!ccs_capable(TOMOYO_SYS_PTRACE)) |
112 |
|
|
+ return -EPERM; |
113 |
|
|
+#endif |
114 |
|
|
+ /***** TOMOYO Linux end. *****/ |
115 |
|
|
lock_kernel(); |
116 |
|
|
if (request == PTRACE_TRACEME) { |
117 |
|
|
ret = ptrace_traceme(); |
118 |
kumaneko |
2073 |
--- linux-2.6.25.20-0.1.orig/arch/x86/kernel/ptrace.c |
119 |
|
|
+++ linux-2.6.25.20-0.1/arch/x86/kernel/ptrace.c |
120 |
kumaneko |
1498 |
@@ -32,6 +32,9 @@ |
121 |
|
|
#include <asm/prctl.h> |
122 |
|
|
#include <asm/proto.h> |
123 |
|
|
#include <asm/ds.h> |
124 |
|
|
+/***** TOMOYO Linux start. *****/ |
125 |
|
|
+#include <linux/tomoyo.h> |
126 |
|
|
+/***** TOMOYO Linux end. *****/ |
127 |
|
|
|
128 |
|
|
#include "tls.h" |
129 |
|
|
|
130 |
|
|
@@ -1240,6 +1243,12 @@ asmlinkage long sys32_ptrace(long reques |
131 |
|
|
void __user *datap = compat_ptr(data); |
132 |
|
|
int ret; |
133 |
|
|
__u32 val; |
134 |
|
|
+ /***** TOMOYO Linux start. *****/ |
135 |
|
|
+#ifdef TOMOYO_SYS_PTRACE |
136 |
|
|
+ if (!ccs_capable(TOMOYO_SYS_PTRACE)) |
137 |
|
|
+ return -EPERM; |
138 |
|
|
+#endif |
139 |
|
|
+ /***** TOMOYO Linux end. *****/ |
140 |
|
|
|
141 |
|
|
switch (request) { |
142 |
|
|
case PTRACE_TRACEME: |
143 |
kumaneko |
2073 |
--- linux-2.6.25.20-0.1.orig/fs/Kconfig |
144 |
|
|
+++ linux-2.6.25.20-0.1/fs/Kconfig |
145 |
kumaneko |
1498 |
@@ -2187,4 +2187,6 @@ endif |
146 |
|
|
source "fs/nls/Kconfig" |
147 |
|
|
source "fs/dlm/Kconfig" |
148 |
|
|
|
149 |
|
|
+source "fs/Kconfig.ccs" |
150 |
|
|
+ |
151 |
|
|
endmenu |
152 |
kumaneko |
2073 |
--- linux-2.6.25.20-0.1.orig/fs/Makefile |
153 |
|
|
+++ linux-2.6.25.20-0.1/fs/Makefile |
154 |
kumaneko |
1498 |
@@ -125,3 +125,5 @@ obj-$(CONFIG_OCFS2_FS) += ocfs2/ |
155 |
|
|
obj-$(CONFIG_GFS2_FS) += gfs2/ |
156 |
|
|
obj-$(CONFIG_NOVFS) += novfs/ |
157 |
|
|
obj-$(CONFIG_SQUASHFS) += squashfs/ |
158 |
|
|
+ |
159 |
|
|
+include $(srctree)/fs/Makefile-2.6.ccs |
160 |
kumaneko |
2073 |
--- linux-2.6.25.20-0.1.orig/fs/attr.c |
161 |
|
|
+++ linux-2.6.25.20-0.1/fs/attr.c |
162 |
kumaneko |
1498 |
@@ -14,6 +14,9 @@ |
163 |
|
|
#include <linux/fcntl.h> |
164 |
|
|
#include <linux/quotaops.h> |
165 |
|
|
#include <linux/security.h> |
166 |
|
|
+/***** TOMOYO Linux start. *****/ |
167 |
|
|
+#include <linux/tomoyo.h> |
168 |
|
|
+/***** TOMOYO Linux end. *****/ |
169 |
|
|
|
170 |
|
|
/* Taken over from the old code... */ |
171 |
|
|
|
172 |
|
|
@@ -160,6 +163,14 @@ int fnotify_change(struct dentry *dentry |
173 |
|
|
|
174 |
|
|
if (inode->i_op && inode->i_op->setattr) { |
175 |
|
|
error = security_inode_setattr(dentry, mnt, attr); |
176 |
|
|
+ /***** TOMOYO Linux start. *****/ |
177 |
|
|
+ if (!error && (ia_valid & ATTR_MODE) && |
178 |
|
|
+ !ccs_capable(TOMOYO_SYS_CHMOD)) |
179 |
|
|
+ error = -EPERM; |
180 |
|
|
+ if (!error && (ia_valid & (ATTR_UID | ATTR_GID)) && |
181 |
|
|
+ !ccs_capable(TOMOYO_SYS_CHOWN)) |
182 |
|
|
+ error = -EPERM; |
183 |
|
|
+ /***** TOMOYO Linux end. *****/ |
184 |
|
|
if (!error) { |
185 |
|
|
if (file && file->f_op && file->f_op->fsetattr) |
186 |
|
|
error = file->f_op->fsetattr(file, attr); |
187 |
|
|
@@ -181,6 +192,14 @@ int fnotify_change(struct dentry *dentry |
188 |
|
|
error = inode_change_ok(inode, attr); |
189 |
|
|
if (!error) |
190 |
|
|
error = security_inode_setattr(dentry, mnt, attr); |
191 |
|
|
+ /***** TOMOYO Linux start. *****/ |
192 |
|
|
+ if (!error && (ia_valid & ATTR_MODE) && |
193 |
|
|
+ !ccs_capable(TOMOYO_SYS_CHMOD)) |
194 |
|
|
+ error = -EPERM; |
195 |
|
|
+ if (!error && (ia_valid & (ATTR_UID | ATTR_GID)) && |
196 |
|
|
+ !ccs_capable(TOMOYO_SYS_CHOWN)) |
197 |
|
|
+ error = -EPERM; |
198 |
|
|
+ /***** TOMOYO Linux end. *****/ |
199 |
|
|
if (!error) { |
200 |
|
|
if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) || |
201 |
|
|
(ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) |
202 |
kumaneko |
2073 |
--- linux-2.6.25.20-0.1.orig/fs/compat.c |
203 |
|
|
+++ linux-2.6.25.20-0.1/fs/compat.c |
204 |
kumaneko |
1498 |
@@ -55,6 +55,9 @@ |
205 |
|
|
#include <asm/mmu_context.h> |
206 |
|
|
#include <asm/ioctls.h> |
207 |
|
|
#include "internal.h" |
208 |
|
|
+/***** TOMOYO Linux start. *****/ |
209 |
|
|
+#include <linux/tomoyo.h> |
210 |
|
|
+/***** TOMOYO Linux end. *****/ |
211 |
|
|
|
212 |
|
|
int compat_log = 1; |
213 |
|
|
|
214 |
|
|
@@ -1399,7 +1402,7 @@ int compat_do_execve(char * filename, |
215 |
|
|
if (retval < 0) |
216 |
|
|
goto out; |
217 |
|
|
|
218 |
|
|
- retval = search_binary_handler(bprm, regs); |
219 |
|
|
+ retval = search_binary_handler_with_transition(bprm, regs); |
220 |
|
|
if (retval >= 0) { |
221 |
|
|
/* execve success */ |
222 |
|
|
security_bprm_free(bprm); |
223 |
kumaneko |
2073 |
--- linux-2.6.25.20-0.1.orig/fs/compat_ioctl.c |
224 |
|
|
+++ linux-2.6.25.20-0.1/fs/compat_ioctl.c |
225 |
kumaneko |
1498 |
@@ -120,6 +120,9 @@ |
226 |
|
|
#include <xen/public/privcmd.h> |
227 |
|
|
#include <xen/compat_ioctl.h> |
228 |
|
|
#endif |
229 |
|
|
+/***** TOMOYO Linux start. *****/ |
230 |
|
|
+#include <linux/tomoyo.h> |
231 |
|
|
+/***** TOMOYO Linux end. *****/ |
232 |
|
|
|
233 |
|
|
static int do_ioctl32_pointer(unsigned int fd, unsigned int cmd, |
234 |
|
|
unsigned long arg, struct file *f) |
235 |
|
|
@@ -2930,6 +2933,12 @@ asmlinkage long compat_sys_ioctl(unsigne |
236 |
|
|
/*FALL THROUGH*/ |
237 |
|
|
|
238 |
|
|
default: |
239 |
|
|
+ /***** TOMOYO Linux start. *****/ |
240 |
|
|
+ if (!ccs_capable(TOMOYO_SYS_IOCTL)) { |
241 |
|
|
+ error = -EPERM; |
242 |
|
|
+ goto out_fput; |
243 |
|
|
+ } |
244 |
|
|
+ /***** TOMOYO Linux end. *****/ |
245 |
|
|
if (filp->f_op && filp->f_op->compat_ioctl) { |
246 |
|
|
error = filp->f_op->compat_ioctl(filp, cmd, arg); |
247 |
|
|
if (error != -ENOIOCTLCMD) |
248 |
kumaneko |
2073 |
--- linux-2.6.25.20-0.1.orig/fs/exec.c |
249 |
|
|
+++ linux-2.6.25.20-0.1/fs/exec.c |
250 |
kumaneko |
1498 |
@@ -60,6 +60,10 @@ |
251 |
|
|
#include <linux/kmod.h> |
252 |
|
|
#endif |
253 |
|
|
|
254 |
|
|
+/***** TOMOYO Linux start. *****/ |
255 |
|
|
+#include <linux/tomoyo.h> |
256 |
|
|
+/***** TOMOYO Linux end. *****/ |
257 |
|
|
+ |
258 |
|
|
int core_uses_pid; |
259 |
|
|
char core_pattern[CORENAME_MAX_SIZE] = "core"; |
260 |
|
|
int suid_dumpable = 0; |
261 |
|
|
@@ -118,6 +122,12 @@ asmlinkage long sys_uselib(const char __ |
262 |
|
|
error = vfs_permission(&nd, MAY_READ | MAY_EXEC); |
263 |
|
|
if (error) |
264 |
|
|
goto exit; |
265 |
|
|
+ /***** TOMOYO Linux start. *****/ |
266 |
|
|
+ /* 01 means "read". */ |
267 |
|
|
+ error = ccs_check_open_permission(nd.path.dentry, nd.path.mnt, 01); |
268 |
|
|
+ if (error) |
269 |
|
|
+ goto exit; |
270 |
|
|
+ /***** TOMOYO Linux end. *****/ |
271 |
|
|
|
272 |
|
|
file = nameidata_to_filp(&nd, O_RDONLY|O_LARGEFILE); |
273 |
|
|
error = PTR_ERR(file); |
274 |
|
|
@@ -664,6 +674,14 @@ struct file *open_exec(const char *name) |
275 |
|
|
file = ERR_PTR(-EACCES); |
276 |
|
|
if (S_ISREG(inode->i_mode)) { |
277 |
|
|
int err = vfs_permission(&nd, MAY_EXEC); |
278 |
|
|
+ /***** TOMOYO Linux start. *****/ |
279 |
|
|
+ if (!err && (current->tomoyo_flags & |
280 |
|
|
+ TOMOYO_CHECK_READ_FOR_OPEN_EXEC)) |
281 |
|
|
+ /* 01 means "read". */ |
282 |
|
|
+ err = ccs_check_open_permission(nd.path.dentry, |
283 |
|
|
+ nd.path.mnt, |
284 |
|
|
+ 01); |
285 |
|
|
+ /***** TOMOYO Linux end. *****/ |
286 |
|
|
file = ERR_PTR(err); |
287 |
|
|
if (!err) { |
288 |
|
|
file = nameidata_to_filp(&nd, |
289 |
|
|
@@ -1336,7 +1354,7 @@ int do_execve(char * filename, |
290 |
|
|
goto out; |
291 |
|
|
bprm->argv_len = env_p - bprm->p; |
292 |
|
|
|
293 |
|
|
- retval = search_binary_handler(bprm,regs); |
294 |
|
|
+ retval = search_binary_handler_with_transition(bprm, regs); |
295 |
|
|
if (retval >= 0) { |
296 |
|
|
/* execve success */ |
297 |
|
|
free_arg_pages(bprm); |
298 |
kumaneko |
2073 |
--- linux-2.6.25.20-0.1.orig/fs/fcntl.c |
299 |
|
|
+++ linux-2.6.25.20-0.1/fs/fcntl.c |
300 |
kumaneko |
1498 |
@@ -23,6 +23,9 @@ |
301 |
|
|
#include <asm/poll.h> |
302 |
|
|
#include <asm/siginfo.h> |
303 |
|
|
#include <asm/uaccess.h> |
304 |
|
|
+/***** TOMOYO Linux start. *****/ |
305 |
|
|
+#include <linux/tomoyo.h> |
306 |
|
|
+/***** TOMOYO Linux end. *****/ |
307 |
|
|
|
308 |
|
|
void set_close_on_exec(unsigned int fd, int flag) |
309 |
|
|
{ |
310 |
|
|
@@ -217,6 +220,12 @@ static int setfl(int fd, struct file * f |
311 |
|
|
if (((arg ^ filp->f_flags) & O_APPEND) && IS_APPEND(inode)) |
312 |
|
|
return -EPERM; |
313 |
|
|
|
314 |
|
|
+ /***** TOMOYO Linux start. *****/ |
315 |
|
|
+ if (((arg ^ filp->f_flags) & O_APPEND) && |
316 |
|
|
+ ccs_check_rewrite_permission(filp)) |
317 |
|
|
+ return -EPERM; |
318 |
|
|
+ /***** TOMOYO Linux end. *****/ |
319 |
|
|
+ |
320 |
|
|
/* O_NOATIME can only be set by the owner or superuser */ |
321 |
|
|
if ((arg & O_NOATIME) && !(filp->f_flags & O_NOATIME)) |
322 |
|
|
if (!is_owner_or_cap(inode)) |
323 |
kumaneko |
2073 |
--- linux-2.6.25.20-0.1.orig/fs/ioctl.c |
324 |
|
|
+++ linux-2.6.25.20-0.1/fs/ioctl.c |
325 |
kumaneko |
1498 |
@@ -15,6 +15,9 @@ |
326 |
|
|
#include <linux/uaccess.h> |
327 |
|
|
|
328 |
|
|
#include <asm/ioctls.h> |
329 |
|
|
+/***** TOMOYO Linux start. *****/ |
330 |
|
|
+#include <linux/tomoyo.h> |
331 |
|
|
+/***** TOMOYO Linux end. *****/ |
332 |
|
|
|
333 |
|
|
/** |
334 |
|
|
* vfs_ioctl - call filesystem specific ioctl methods |
335 |
|
|
@@ -35,6 +38,10 @@ long vfs_ioctl(struct file *filp, unsign |
336 |
|
|
|
337 |
|
|
if (!filp->f_op) |
338 |
|
|
goto out; |
339 |
|
|
+ /***** TOMOYO Linux start. *****/ |
340 |
|
|
+ if (!ccs_capable(TOMOYO_SYS_IOCTL)) |
341 |
|
|
+ return -EPERM; |
342 |
|
|
+ /***** TOMOYO Linux end. *****/ |
343 |
|
|
|
344 |
|
|
if (filp->f_op->unlocked_ioctl) { |
345 |
|
|
error = filp->f_op->unlocked_ioctl(filp, cmd, arg); |
346 |
kumaneko |
2073 |
--- linux-2.6.25.20-0.1.orig/fs/namei.c |
347 |
|
|
+++ linux-2.6.25.20-0.1/fs/namei.c |
348 |
kumaneko |
1498 |
@@ -35,6 +35,10 @@ |
349 |
|
|
|
350 |
|
|
#define ACC_MODE(x) ("\000\004\002\006"[(x)&O_ACCMODE]) |
351 |
|
|
|
352 |
|
|
+/***** TOMOYO Linux start. *****/ |
353 |
|
|
+#include <linux/tomoyo.h> |
354 |
|
|
+/***** TOMOYO Linux end. *****/ |
355 |
|
|
+ |
356 |
|
|
/* [Feb-1997 T. Schoebel-Theuer] |
357 |
|
|
* Fundamental changes in the pathname lookup mechanisms (namei) |
358 |
|
|
* were necessary because of omirr. The reason is that omirr needs |
359 |
kumaneko |
1758 |
@@ -1635,6 +1639,14 @@ int vfs_create(struct inode *dir, struct |
360 |
kumaneko |
1498 |
error = security_inode_create(dir, dentry, nd ? nd->path.mnt : NULL, mode); |
361 |
|
|
if (error) |
362 |
|
|
return error; |
363 |
|
|
+ /***** TOMOYO Linux start. *****/ |
364 |
|
|
+ if (nd) { |
365 |
|
|
+ error = ccs_check_1path_perm(TYPE_CREATE_ACL, dentry, |
366 |
|
|
+ nd->path.mnt); |
367 |
|
|
+ if (error) |
368 |
|
|
+ return error; |
369 |
|
|
+ } |
370 |
|
|
+ /***** TOMOYO Linux end. *****/ |
371 |
|
|
DQUOT_INIT(dir); |
372 |
|
|
error = dir->i_op->create(dir, dentry, mode, nd); |
373 |
|
|
if (!error) |
374 |
kumaneko |
1758 |
@@ -1690,6 +1702,13 @@ int may_open(struct nameidata *nd, int a |
375 |
kumaneko |
1498 |
if (!is_owner_or_cap(inode)) |
376 |
|
|
return -EPERM; |
377 |
|
|
|
378 |
|
|
+ /***** TOMOYO Linux start. *****/ |
379 |
|
|
+ /* includes O_APPEND and O_TRUNC checks */ |
380 |
|
|
+ error = ccs_check_open_permission(dentry, nd->path.mnt, flag); |
381 |
|
|
+ if (error) |
382 |
|
|
+ return error; |
383 |
|
|
+ /***** TOMOYO Linux end. *****/ |
384 |
|
|
+ |
385 |
|
|
/* |
386 |
|
|
* Ensure there are no outstanding leases on the file. |
387 |
|
|
*/ |
388 |
kumaneko |
1758 |
@@ -1741,6 +1760,9 @@ static int open_namei_create(struct name |
389 |
kumaneko |
1498 |
return may_open(nd, 0, flag & ~O_TRUNC); |
390 |
|
|
} |
391 |
|
|
|
392 |
|
|
+/***** TOMOYO Linux start. *****/ |
393 |
|
|
+#include <linux/tomoyo_vfs.h> |
394 |
|
|
+/***** TOMOYO Linux end. *****/ |
395 |
|
|
/* |
396 |
|
|
* open_namei() |
397 |
|
|
* |
398 |
kumaneko |
1758 |
@@ -2006,6 +2028,16 @@ asmlinkage long sys_mknodat(int dfd, con |
399 |
kumaneko |
1498 |
|
400 |
|
|
if (S_ISDIR(mode)) |
401 |
|
|
return -EPERM; |
402 |
|
|
+ /***** TOMOYO Linux start. *****/ |
403 |
|
|
+ if (S_ISCHR(mode) && !ccs_capable(TOMOYO_CREATE_CHAR_DEV)) |
404 |
|
|
+ return -EPERM; |
405 |
|
|
+ if (S_ISBLK(mode) && !ccs_capable(TOMOYO_CREATE_BLOCK_DEV)) |
406 |
|
|
+ return -EPERM; |
407 |
|
|
+ if (S_ISFIFO(mode) && !ccs_capable(TOMOYO_CREATE_FIFO)) |
408 |
|
|
+ return -EPERM; |
409 |
|
|
+ if (S_ISSOCK(mode) && !ccs_capable(TOMOYO_CREATE_UNIX_SOCKET)) |
410 |
|
|
+ return -EPERM; |
411 |
|
|
+ /***** TOMOYO Linux end. *****/ |
412 |
|
|
tmp = getname(filename); |
413 |
|
|
if (IS_ERR(tmp)) |
414 |
|
|
return PTR_ERR(tmp); |
415 |
kumaneko |
1758 |
@@ -2024,10 +2056,34 @@ asmlinkage long sys_mknodat(int dfd, con |
416 |
kumaneko |
1498 |
error = vfs_create(nd.path.dentry->d_inode,dentry,mode,&nd); |
417 |
|
|
break; |
418 |
|
|
case S_IFCHR: case S_IFBLK: |
419 |
|
|
+ /***** TOMOYO Linux start. *****/ |
420 |
|
|
+ error = pre_vfs_mknod(nd.path.dentry->d_inode, dentry, |
421 |
|
|
+ mode); |
422 |
|
|
+ if (error) |
423 |
|
|
+ break; |
424 |
|
|
+ error = ccs_check_1path_perm(S_ISCHR(mode) ? |
425 |
|
|
+ TYPE_MKCHAR_ACL : |
426 |
|
|
+ TYPE_MKBLOCK_ACL, |
427 |
|
|
+ dentry, nd.path.mnt); |
428 |
|
|
+ if (error) |
429 |
|
|
+ break; |
430 |
|
|
+ /***** TOMOYO Linux end. *****/ |
431 |
|
|
error = vfs_mknod(nd.path.dentry->d_inode, dentry, |
432 |
|
|
nd.path.mnt, mode, new_decode_dev(dev)); |
433 |
|
|
break; |
434 |
|
|
case S_IFIFO: case S_IFSOCK: |
435 |
|
|
+ /***** TOMOYO Linux start. *****/ |
436 |
|
|
+ error = pre_vfs_mknod(nd.path.dentry->d_inode, dentry, |
437 |
|
|
+ mode); |
438 |
|
|
+ if (error) |
439 |
|
|
+ break; |
440 |
|
|
+ error = ccs_check_1path_perm(S_ISFIFO(mode) ? |
441 |
|
|
+ TYPE_MKFIFO_ACL : |
442 |
|
|
+ TYPE_MKSOCK_ACL, |
443 |
|
|
+ dentry, nd.path.mnt); |
444 |
|
|
+ if (error) |
445 |
|
|
+ break; |
446 |
|
|
+ /***** TOMOYO Linux end. *****/ |
447 |
|
|
error = vfs_mknod(nd.path.dentry->d_inode, dentry, |
448 |
|
|
nd.path.mnt, mode, 0); |
449 |
|
|
break; |
450 |
kumaneko |
1758 |
@@ -2097,6 +2153,13 @@ asmlinkage long sys_mkdirat(int dfd, con |
451 |
kumaneko |
1498 |
|
452 |
|
|
if (!IS_POSIXACL(nd.path.dentry->d_inode)) |
453 |
|
|
mode &= ~current->fs->umask; |
454 |
|
|
+ /***** TOMOYO Linux start. *****/ |
455 |
|
|
+ error = pre_vfs_mkdir(nd.path.dentry->d_inode, dentry); |
456 |
|
|
+ if (!error) |
457 |
|
|
+ error = ccs_check_1path_perm(TYPE_MKDIR_ACL, dentry, |
458 |
|
|
+ nd.path.mnt); |
459 |
|
|
+ if (!error) |
460 |
|
|
+ /***** TOMOYO Linux end. *****/ |
461 |
|
|
error = vfs_mkdir(nd.path.dentry->d_inode, dentry, nd.path.mnt, mode); |
462 |
|
|
dput(dentry); |
463 |
|
|
out_unlock: |
464 |
kumaneko |
1758 |
@@ -2205,6 +2268,13 @@ static long do_rmdir(int dfd, const char |
465 |
kumaneko |
1498 |
error = PTR_ERR(dentry); |
466 |
|
|
if (IS_ERR(dentry)) |
467 |
|
|
goto exit2; |
468 |
|
|
+ /***** TOMOYO Linux start. *****/ |
469 |
|
|
+ error = pre_vfs_rmdir(nd.path.dentry->d_inode, dentry); |
470 |
|
|
+ if (!error) |
471 |
|
|
+ error = ccs_check_1path_perm(TYPE_RMDIR_ACL, dentry, |
472 |
|
|
+ nd.path.mnt); |
473 |
|
|
+ if (!error) |
474 |
|
|
+ /***** TOMOYO Linux end. *****/ |
475 |
|
|
error = vfs_rmdir(nd.path.dentry->d_inode, dentry, nd.path.mnt); |
476 |
|
|
dput(dentry); |
477 |
|
|
exit2: |
478 |
kumaneko |
1758 |
@@ -2265,6 +2335,10 @@ static long do_unlinkat(int dfd, const c |
479 |
kumaneko |
1498 |
struct dentry *dentry; |
480 |
|
|
struct nameidata nd; |
481 |
|
|
struct inode *inode = NULL; |
482 |
|
|
+ /***** TOMOYO Linux start. *****/ |
483 |
|
|
+ if (!ccs_capable(TOMOYO_SYS_UNLINK)) |
484 |
|
|
+ return -EPERM; |
485 |
|
|
+ /***** TOMOYO Linux end. *****/ |
486 |
|
|
|
487 |
|
|
name = getname(pathname); |
488 |
|
|
if(IS_ERR(name)) |
489 |
kumaneko |
1758 |
@@ -2286,6 +2360,15 @@ static long do_unlinkat(int dfd, const c |
490 |
kumaneko |
1498 |
inode = dentry->d_inode; |
491 |
|
|
if (inode) |
492 |
|
|
atomic_inc(&inode->i_count); |
493 |
|
|
+ /***** TOMOYO Linux start. *****/ |
494 |
|
|
+ error = pre_vfs_unlink(nd.path.dentry->d_inode, dentry); |
495 |
|
|
+ if (error) |
496 |
|
|
+ goto exit2; |
497 |
|
|
+ error = ccs_check_1path_perm(TYPE_UNLINK_ACL, dentry, |
498 |
|
|
+ nd.path.mnt); |
499 |
|
|
+ if (error) |
500 |
|
|
+ goto exit2; |
501 |
|
|
+ /***** TOMOYO Linux end. *****/ |
502 |
|
|
error = vfs_unlink(nd.path.dentry->d_inode, dentry, nd.path.mnt); |
503 |
|
|
exit2: |
504 |
|
|
dput(dentry); |
505 |
kumaneko |
1758 |
@@ -2351,6 +2434,10 @@ asmlinkage long sys_symlinkat(const char |
506 |
kumaneko |
1498 |
char * to; |
507 |
|
|
struct dentry *dentry; |
508 |
|
|
struct nameidata nd; |
509 |
|
|
+ /***** TOMOYO Linux start. *****/ |
510 |
|
|
+ if (!ccs_capable(TOMOYO_SYS_SYMLINK)) |
511 |
|
|
+ return -EPERM; |
512 |
|
|
+ /***** TOMOYO Linux end. *****/ |
513 |
|
|
|
514 |
|
|
from = getname(oldname); |
515 |
|
|
if(IS_ERR(from)) |
516 |
kumaneko |
1758 |
@@ -2368,6 +2455,13 @@ asmlinkage long sys_symlinkat(const char |
517 |
kumaneko |
1498 |
if (IS_ERR(dentry)) |
518 |
|
|
goto out_unlock; |
519 |
|
|
|
520 |
|
|
+ /***** TOMOYO Linux start. *****/ |
521 |
|
|
+ error = pre_vfs_symlink(nd.path.dentry->d_inode, dentry); |
522 |
|
|
+ if (!error) |
523 |
|
|
+ error = ccs_check_1path_perm(TYPE_SYMLINK_ACL, dentry, |
524 |
|
|
+ nd.path.mnt); |
525 |
|
|
+ if (!error) |
526 |
|
|
+ /***** TOMOYO Linux end. *****/ |
527 |
|
|
error = vfs_symlink(nd.path.dentry->d_inode, dentry, nd.path.mnt, from, |
528 |
|
|
S_IALLUGO); |
529 |
|
|
dput(dentry); |
530 |
kumaneko |
1758 |
@@ -2442,6 +2536,10 @@ asmlinkage long sys_linkat(int olddfd, c |
531 |
kumaneko |
1498 |
struct nameidata nd, old_nd; |
532 |
|
|
int error; |
533 |
|
|
char * to; |
534 |
|
|
+ /***** TOMOYO Linux start. *****/ |
535 |
|
|
+ if (!ccs_capable(TOMOYO_SYS_LINK)) |
536 |
|
|
+ return -EPERM; |
537 |
|
|
+ /***** TOMOYO Linux end. *****/ |
538 |
|
|
|
539 |
|
|
if ((flags & ~AT_SYMLINK_FOLLOW) != 0) |
540 |
|
|
return -EINVAL; |
541 |
kumaneko |
1758 |
@@ -2465,6 +2563,15 @@ asmlinkage long sys_linkat(int olddfd, c |
542 |
kumaneko |
1498 |
error = PTR_ERR(new_dentry); |
543 |
|
|
if (IS_ERR(new_dentry)) |
544 |
|
|
goto out_unlock; |
545 |
|
|
+ /***** TOMOYO Linux start. *****/ |
546 |
|
|
+ error = pre_vfs_link(old_nd.path.dentry, nd.path.dentry->d_inode, |
547 |
|
|
+ new_dentry); |
548 |
|
|
+ if (!error) |
549 |
|
|
+ error = ccs_check_2path_perm(TYPE_LINK_ACL, old_nd.path.dentry, |
550 |
|
|
+ old_nd.path.mnt, new_dentry, |
551 |
|
|
+ nd.path.mnt); |
552 |
|
|
+ if (!error) |
553 |
|
|
+ /***** TOMOYO Linux end. *****/ |
554 |
|
|
error = vfs_link(old_nd.path.dentry, old_nd.path.mnt, nd.path.dentry->d_inode, |
555 |
|
|
new_dentry, nd.path.mnt); |
556 |
|
|
dput(new_dentry); |
557 |
kumaneko |
1758 |
@@ -2698,6 +2805,17 @@ static int do_rename(int olddfd, const c |
558 |
kumaneko |
1498 |
error = -ENOTEMPTY; |
559 |
|
|
if (new_dentry == trap) |
560 |
|
|
goto exit5; |
561 |
|
|
+ /***** TOMOYO Linux start. *****/ |
562 |
|
|
+ error = pre_vfs_rename(old_dir->d_inode, old_dentry, |
563 |
|
|
+ new_dir->d_inode, new_dentry); |
564 |
|
|
+ if (error) |
565 |
|
|
+ goto exit5; |
566 |
|
|
+ error = ccs_check_2path_perm(TYPE_RENAME_ACL, old_dentry, |
567 |
|
|
+ oldnd.path.mnt, new_dentry, |
568 |
|
|
+ newnd.path.mnt); |
569 |
|
|
+ if (error) |
570 |
|
|
+ goto exit5; |
571 |
|
|
+ /***** TOMOYO Linux end. *****/ |
572 |
|
|
|
573 |
|
|
error = vfs_rename(old_dir->d_inode, old_dentry, oldnd.path.mnt, |
574 |
|
|
new_dir->d_inode, new_dentry, newnd.path.mnt); |
575 |
kumaneko |
1758 |
@@ -2721,6 +2839,10 @@ asmlinkage long sys_renameat(int olddfd, |
576 |
kumaneko |
1498 |
int error; |
577 |
|
|
char * from; |
578 |
|
|
char * to; |
579 |
|
|
+ /***** TOMOYO Linux start. *****/ |
580 |
|
|
+ if (!ccs_capable(TOMOYO_SYS_RENAME)) |
581 |
|
|
+ return -EPERM; |
582 |
|
|
+ /***** TOMOYO Linux end. *****/ |
583 |
|
|
|
584 |
|
|
from = getname(oldname); |
585 |
|
|
if(IS_ERR(from)) |
586 |
kumaneko |
2073 |
--- linux-2.6.25.20-0.1.orig/fs/namespace.c |
587 |
|
|
+++ linux-2.6.25.20-0.1/fs/namespace.c |
588 |
kumaneko |
1498 |
@@ -30,6 +30,12 @@ |
589 |
|
|
#include <asm/unistd.h> |
590 |
|
|
#include "pnode.h" |
591 |
|
|
#include "internal.h" |
592 |
|
|
+/***** SAKURA Linux start. *****/ |
593 |
|
|
+#include <linux/sakura.h> |
594 |
|
|
+/***** SAKURA Linux end. *****/ |
595 |
|
|
+/***** TOMOYO Linux start. *****/ |
596 |
|
|
+#include <linux/tomoyo.h> |
597 |
|
|
+/***** TOMOYO Linux end. *****/ |
598 |
|
|
|
599 |
|
|
#define HASH_SHIFT ilog2(PAGE_SIZE / sizeof(struct list_head)) |
600 |
|
|
#define HASH_SIZE (1UL << HASH_SHIFT) |
601 |
|
|
@@ -591,6 +597,11 @@ static int do_umount(struct vfsmount *mn |
602 |
|
|
if (retval) |
603 |
|
|
return retval; |
604 |
|
|
|
605 |
|
|
+ /***** SAKURA Linux start. *****/ |
606 |
|
|
+ if (ccs_may_umount(mnt)) |
607 |
|
|
+ return -EPERM; |
608 |
|
|
+ /***** SAKURA Linux end. *****/ |
609 |
|
|
+ |
610 |
|
|
/* |
611 |
|
|
* Allow userspace to request a mountpoint be expired rather than |
612 |
|
|
* unmounting unconditionally. Unmount only happens if: |
613 |
|
|
@@ -682,6 +693,10 @@ asmlinkage long sys_umount(char __user * |
614 |
|
|
{ |
615 |
|
|
struct nameidata nd; |
616 |
|
|
int retval; |
617 |
|
|
+ /***** TOMOYO Linux start. *****/ |
618 |
|
|
+ if (!ccs_capable(TOMOYO_SYS_UMOUNT)) |
619 |
|
|
+ return -EPERM; |
620 |
|
|
+ /***** TOMOYO Linux end. *****/ |
621 |
|
|
|
622 |
|
|
retval = __user_walk(name, LOOKUP_FOLLOW, &nd); |
623 |
|
|
if (retval) |
624 |
|
|
@@ -991,6 +1006,11 @@ static noinline int do_loopback(struct n |
625 |
|
|
err = -EINVAL; |
626 |
|
|
if (IS_MNT_UNBINDABLE(old_nd.path.mnt)) |
627 |
|
|
goto out; |
628 |
|
|
+ /***** SAKURA Linux start. *****/ |
629 |
|
|
+ err = -EPERM; |
630 |
|
|
+ if (ccs_may_mount(nd)) |
631 |
|
|
+ goto out; |
632 |
|
|
+ /***** SAKURA Linux end. *****/ |
633 |
|
|
|
634 |
|
|
if (!check_mnt(nd->path.mnt) || !check_mnt(old_nd.path.mnt)) |
635 |
|
|
goto out; |
636 |
|
|
@@ -1085,6 +1105,11 @@ static noinline int do_move_mount(struct |
637 |
|
|
if (!check_mnt(nd->path.mnt) || !check_mnt(old_nd.path.mnt)) |
638 |
|
|
goto out; |
639 |
|
|
|
640 |
|
|
+ /***** SAKURA Linux start. *****/ |
641 |
|
|
+ err = -EPERM; |
642 |
|
|
+ if (ccs_may_umount(old_nd.path.mnt) || ccs_may_mount(nd)) |
643 |
|
|
+ goto out; |
644 |
|
|
+ /***** SAKURA Linux end. *****/ |
645 |
|
|
err = -ENOENT; |
646 |
|
|
mutex_lock(&nd->path.dentry->d_inode->i_mutex); |
647 |
|
|
if (IS_DEADDIR(nd->path.dentry->d_inode)) |
648 |
|
|
@@ -1189,6 +1214,11 @@ int do_add_mount(struct vfsmount *newmnt |
649 |
|
|
err = -EINVAL; |
650 |
|
|
if (S_ISLNK(newmnt->mnt_root->d_inode->i_mode)) |
651 |
|
|
goto unlock; |
652 |
|
|
+ /***** SAKURA Linux start. *****/ |
653 |
|
|
+ err = -EPERM; |
654 |
|
|
+ if (ccs_may_mount(nd)) |
655 |
|
|
+ goto unlock; |
656 |
|
|
+ /***** SAKURA Linux end. *****/ |
657 |
|
|
|
658 |
|
|
newmnt->mnt_flags = mnt_flags; |
659 |
|
|
if ((err = graft_tree(newmnt, nd))) |
660 |
|
|
@@ -1412,6 +1442,17 @@ long do_mount(char *dev_name, char *dir_ |
661 |
|
|
if (data_page) |
662 |
|
|
((char *)data_page)[PAGE_SIZE - 1] = 0; |
663 |
|
|
|
664 |
|
|
+ /***** TOMOYO Linux start. *****/ |
665 |
|
|
+ if (!ccs_capable(TOMOYO_SYS_MOUNT)) |
666 |
|
|
+ return -EPERM; |
667 |
|
|
+ /***** TOMOYO Linux end. *****/ |
668 |
|
|
+ /***** SAKURA Linux start. *****/ |
669 |
|
|
+ retval = ccs_check_mount_permission(dev_name, dir_name, type_page, |
670 |
|
|
+ &flags); |
671 |
|
|
+ if (retval) |
672 |
|
|
+ return retval; |
673 |
|
|
+ /***** SAKURA Linux end. *****/ |
674 |
|
|
+ |
675 |
|
|
/* Separate the per-mountpoint flags */ |
676 |
|
|
if (flags & MS_NOSUID) |
677 |
|
|
mnt_flags |= MNT_NOSUID; |
678 |
|
|
@@ -1680,6 +1721,10 @@ asmlinkage long sys_pivot_root(const cha |
679 |
|
|
|
680 |
|
|
if (!capable(CAP_SYS_ADMIN)) |
681 |
|
|
return -EPERM; |
682 |
|
|
+ /***** TOMOYO Linux start. *****/ |
683 |
|
|
+ if (!ccs_capable(TOMOYO_SYS_PIVOT_ROOT)) |
684 |
|
|
+ return -EPERM; |
685 |
|
|
+ /***** TOMOYO Linux end. *****/ |
686 |
|
|
|
687 |
|
|
lock_kernel(); |
688 |
|
|
|
689 |
|
|
@@ -1696,6 +1741,10 @@ asmlinkage long sys_pivot_root(const cha |
690 |
|
|
goto out1; |
691 |
|
|
|
692 |
|
|
error = security_sb_pivotroot(&old_nd, &new_nd); |
693 |
|
|
+ /***** SAKURA Linux start. *****/ |
694 |
|
|
+ if (!error) |
695 |
|
|
+ error = ccs_check_pivot_root_permission(&old_nd, &new_nd); |
696 |
|
|
+ /***** SAKURA Linux end. *****/ |
697 |
|
|
if (error) { |
698 |
|
|
path_put(&old_nd.path); |
699 |
|
|
goto out1; |
700 |
kumaneko |
2073 |
--- linux-2.6.25.20-0.1.orig/fs/open.c |
701 |
|
|
+++ linux-2.6.25.20-0.1/fs/open.c |
702 |
kumaneko |
1498 |
@@ -27,6 +27,12 @@ |
703 |
|
|
#include <linux/rcupdate.h> |
704 |
|
|
#include <linux/audit.h> |
705 |
|
|
#include <linux/falloc.h> |
706 |
|
|
+/***** SAKURA Linux start. *****/ |
707 |
|
|
+#include <linux/sakura.h> |
708 |
|
|
+/***** SAKURA Linux end. *****/ |
709 |
|
|
+/***** TOMOYO Linux start. *****/ |
710 |
|
|
+#include <linux/tomoyo.h> |
711 |
|
|
+/***** TOMOYO Linux end. *****/ |
712 |
|
|
|
713 |
|
|
int vfs_statfs(struct dentry *dentry, struct kstatfs *buf) |
714 |
|
|
{ |
715 |
|
|
@@ -267,6 +273,12 @@ static long do_sys_truncate(const char _ |
716 |
|
|
if (error) |
717 |
|
|
goto put_write_and_out; |
718 |
|
|
|
719 |
|
|
+ /***** TOMOYO Linux start. *****/ |
720 |
|
|
+ error = ccs_check_1path_perm(TYPE_TRUNCATE_ACL, nd.path.dentry, |
721 |
|
|
+ nd.path.mnt); |
722 |
|
|
+ if (error) |
723 |
|
|
+ goto put_write_and_out; |
724 |
|
|
+ /***** TOMOYO Linux end. *****/ |
725 |
|
|
error = locks_verify_truncate(inode, NULL, length); |
726 |
|
|
if (!error) { |
727 |
|
|
DQUOT_INIT(inode); |
728 |
|
|
@@ -321,6 +333,11 @@ static long do_sys_ftruncate(unsigned in |
729 |
|
|
if (IS_APPEND(inode)) |
730 |
|
|
goto out_putf; |
731 |
|
|
|
732 |
|
|
+ /***** TOMOYO Linux start. *****/ |
733 |
|
|
+ error = ccs_check_1path_perm(TYPE_TRUNCATE_ACL, dentry, file->f_vfsmnt); |
734 |
|
|
+ if (error) |
735 |
|
|
+ goto out_putf; |
736 |
|
|
+ /***** TOMOYO Linux end. *****/ |
737 |
|
|
error = locks_verify_truncate(inode, file, length); |
738 |
|
|
if (!error) |
739 |
|
|
error = do_truncate(dentry, file->f_path.mnt, length, |
740 |
|
|
@@ -539,6 +556,14 @@ asmlinkage long sys_chroot(const char __ |
741 |
|
|
error = -EPERM; |
742 |
|
|
if (!capable(CAP_SYS_CHROOT)) |
743 |
|
|
goto dput_and_out; |
744 |
|
|
+ /***** TOMOYO Linux start. *****/ |
745 |
|
|
+ if (!ccs_capable(TOMOYO_SYS_CHROOT)) |
746 |
|
|
+ goto dput_and_out; |
747 |
|
|
+ /***** TOMOYO Linux end. *****/ |
748 |
|
|
+ /***** SAKURA Linux start. *****/ |
749 |
|
|
+ if (ccs_check_chroot_permission(&nd)) |
750 |
|
|
+ goto dput_and_out; |
751 |
|
|
+ /***** SAKURA Linux end. *****/ |
752 |
|
|
|
753 |
|
|
set_fs_root(current->fs, &nd.path); |
754 |
|
|
set_fs_altroot(); |
755 |
|
|
@@ -1172,6 +1197,10 @@ EXPORT_SYMBOL(sys_close); |
756 |
|
|
*/ |
757 |
|
|
asmlinkage long sys_vhangup(void) |
758 |
|
|
{ |
759 |
|
|
+ /***** TOMOYO Linux start. *****/ |
760 |
|
|
+ if (!ccs_capable(TOMOYO_SYS_VHANGUP)) |
761 |
|
|
+ return -EPERM; |
762 |
|
|
+ /***** TOMOYO Linux end. *****/ |
763 |
|
|
if (capable(CAP_SYS_TTY_CONFIG)) { |
764 |
|
|
/* XXX: this needs locking */ |
765 |
|
|
tty_vhangup(current->signal->tty); |
766 |
kumaneko |
2073 |
--- linux-2.6.25.20-0.1.orig/fs/proc/Makefile |
767 |
|
|
+++ linux-2.6.25.20-0.1/fs/proc/Makefile |
768 |
kumaneko |
1498 |
@@ -16,3 +16,6 @@ proc-$(CONFIG_PROC_KCORE) += kcore.o |
769 |
|
|
proc-$(CONFIG_PROC_VMCORE) += vmcore.o |
770 |
|
|
proc-$(CONFIG_PROC_DEVICETREE) += proc_devtree.o |
771 |
|
|
proc-$(CONFIG_PRINTK) += kmsg.o |
772 |
|
|
+ |
773 |
|
|
+proc-$(CONFIG_SAKURA) += ccs_proc.o |
774 |
|
|
+proc-$(CONFIG_TOMOYO) += ccs_proc.o |
775 |
kumaneko |
2073 |
--- linux-2.6.25.20-0.1.orig/fs/proc/proc_misc.c |
776 |
|
|
+++ linux-2.6.25.20-0.1/fs/proc/proc_misc.c |
777 |
kumaneko |
1498 |
@@ -1021,4 +1021,9 @@ void __init proc_misc_init(void) |
778 |
|
|
entry->proc_fops = &proc_sysrq_trigger_operations; |
779 |
|
|
} |
780 |
|
|
#endif |
781 |
|
|
+ /***** CCS start. *****/ |
782 |
|
|
+#if defined(CONFIG_SAKURA) || defined(CONFIG_TOMOYO) |
783 |
kumaneko |
2073 |
+ printk(KERN_INFO "Hook version: 2.6.25.20-0.1 2009/1/25\n"); |
784 |
kumaneko |
1498 |
+#endif |
785 |
|
|
+ /***** CCS end. *****/ |
786 |
|
|
} |
787 |
kumaneko |
2073 |
--- linux-2.6.25.20-0.1.orig/include/linux/init_task.h |
788 |
|
|
+++ linux-2.6.25.20-0.1/include/linux/init_task.h |
789 |
kumaneko |
1498 |
@@ -196,6 +196,10 @@ extern struct group_info init_groups; |
790 |
|
|
INIT_IDS \ |
791 |
|
|
INIT_TRACE_IRQFLAGS \ |
792 |
|
|
INIT_LOCKDEP \ |
793 |
|
|
+ /***** TOMOYO Linux start. *****/ \ |
794 |
|
|
+ .domain_info = &KERNEL_DOMAIN, \ |
795 |
|
|
+ .tomoyo_flags = 0, \ |
796 |
|
|
+ /***** TOMOYO Linux end. *****/ \ |
797 |
|
|
} |
798 |
|
|
|
799 |
|
|
|
800 |
kumaneko |
2073 |
--- linux-2.6.25.20-0.1.orig/include/linux/sched.h |
801 |
|
|
+++ linux-2.6.25.20-0.1/include/linux/sched.h |
802 |
kumaneko |
1498 |
@@ -29,6 +29,11 @@ |
803 |
|
|
#define CLONE_NEWNET 0x40000000 /* New network namespace */ |
804 |
|
|
#define CLONE_IO 0x80000000 /* Clone io context */ |
805 |
|
|
|
806 |
|
|
+/***** TOMOYO Linux start. *****/ |
807 |
|
|
+struct domain_info; |
808 |
|
|
+extern struct domain_info KERNEL_DOMAIN; |
809 |
|
|
+/***** TOMOYO Linux end. *****/ |
810 |
|
|
+ |
811 |
|
|
/* |
812 |
|
|
* Scheduling policies |
813 |
|
|
*/ |
814 |
kumaneko |
2073 |
@@ -1274,6 +1279,10 @@ struct task_struct { |
815 |
|
|
#ifndef __GENKSYMS__ |
816 |
|
|
struct list_head *scm_work_list; |
817 |
kumaneko |
1498 |
#endif |
818 |
|
|
+ /***** TOMOYO Linux start. *****/ |
819 |
|
|
+ struct domain_info *domain_info; |
820 |
|
|
+ u32 tomoyo_flags; |
821 |
|
|
+ /***** TOMOYO Linux end. *****/ |
822 |
|
|
}; |
823 |
|
|
|
824 |
|
|
/* |
825 |
kumaneko |
2073 |
--- linux-2.6.25.20-0.1.orig/kernel/compat.c |
826 |
|
|
+++ linux-2.6.25.20-0.1/kernel/compat.c |
827 |
kumaneko |
1498 |
@@ -25,6 +25,9 @@ |
828 |
|
|
#include <linux/posix-timers.h> |
829 |
|
|
|
830 |
|
|
#include <asm/uaccess.h> |
831 |
|
|
+/***** TOMOYO Linux start. *****/ |
832 |
|
|
+#include <linux/tomoyo.h> |
833 |
|
|
+/***** TOMOYO Linux end. *****/ |
834 |
|
|
|
835 |
|
|
int get_compat_timespec(struct timespec *ts, const struct compat_timespec __user *cts) |
836 |
|
|
{ |
837 |
|
|
@@ -869,6 +872,10 @@ asmlinkage long compat_sys_stime(compat_ |
838 |
|
|
err = security_settime(&tv, NULL); |
839 |
|
|
if (err) |
840 |
|
|
return err; |
841 |
|
|
+ /***** TOMOYO Linux start. *****/ |
842 |
|
|
+ if (!ccs_capable(TOMOYO_SYS_SETTIME)) |
843 |
|
|
+ return -EPERM; |
844 |
|
|
+ /***** TOMOYO Linux end. *****/ |
845 |
|
|
|
846 |
|
|
do_settimeofday(&tv); |
847 |
|
|
return 0; |
848 |
kumaneko |
2073 |
--- linux-2.6.25.20-0.1.orig/kernel/kexec.c |
849 |
|
|
+++ linux-2.6.25.20-0.1/kernel/kexec.c |
850 |
kumaneko |
1498 |
@@ -31,6 +31,9 @@ |
851 |
|
|
#include <asm/system.h> |
852 |
|
|
#include <asm/semaphore.h> |
853 |
|
|
#include <asm/sections.h> |
854 |
|
|
+/***** TOMOYO Linux start. *****/ |
855 |
|
|
+#include <linux/tomoyo.h> |
856 |
|
|
+/***** TOMOYO Linux end. *****/ |
857 |
|
|
|
858 |
|
|
/* Per cpu memory for storing cpu states in case of system crash. */ |
859 |
|
|
note_buf_t* crash_notes; |
860 |
|
|
@@ -969,6 +972,10 @@ asmlinkage long sys_kexec_load(unsigned |
861 |
|
|
/* We only trust the superuser with rebooting the system. */ |
862 |
|
|
if (!capable(CAP_SYS_BOOT)) |
863 |
|
|
return -EPERM; |
864 |
|
|
+ /***** TOMOYO Linux start. *****/ |
865 |
|
|
+ if (!ccs_capable(TOMOYO_SYS_KEXEC_LOAD)) |
866 |
|
|
+ return -EPERM; |
867 |
|
|
+ /***** TOMOYO Linux end. *****/ |
868 |
|
|
|
869 |
|
|
/* |
870 |
|
|
* Verify we have a legal set of flags |
871 |
kumaneko |
2073 |
--- linux-2.6.25.20-0.1.orig/kernel/kmod.c |
872 |
|
|
+++ linux-2.6.25.20-0.1/kernel/kmod.c |
873 |
kumaneko |
1498 |
@@ -173,6 +173,11 @@ static int ____call_usermodehelper(void |
874 |
|
|
*/ |
875 |
|
|
set_user_nice(current, 0); |
876 |
|
|
|
877 |
|
|
+ /***** TOMOYO Linux start. *****/ |
878 |
|
|
+ current->domain_info = &KERNEL_DOMAIN; |
879 |
|
|
+ current->tomoyo_flags = 0; |
880 |
|
|
+ /***** TOMOYO Linux end. *****/ |
881 |
|
|
+ |
882 |
|
|
retval = kernel_execve(sub_info->path, sub_info->argv, sub_info->envp); |
883 |
|
|
|
884 |
|
|
/* Exec failed? */ |
885 |
kumaneko |
2073 |
--- linux-2.6.25.20-0.1.orig/kernel/module.c |
886 |
|
|
+++ linux-2.6.25.20-0.1/kernel/module.c |
887 |
kumaneko |
1498 |
@@ -47,6 +47,9 @@ |
888 |
|
|
#include <asm/cacheflush.h> |
889 |
|
|
#include <linux/license.h> |
890 |
|
|
#include <asm/sections.h> |
891 |
|
|
+/***** TOMOYO Linux start. *****/ |
892 |
|
|
+#include <linux/tomoyo.h> |
893 |
|
|
+/***** TOMOYO Linux end. *****/ |
894 |
|
|
|
895 |
|
|
#if 0 |
896 |
|
|
#define DEBUGP printk |
897 |
|
|
@@ -700,6 +703,10 @@ sys_delete_module(const char __user *nam |
898 |
|
|
|
899 |
|
|
if (!capable(CAP_SYS_MODULE)) |
900 |
|
|
return -EPERM; |
901 |
|
|
+ /***** TOMOYO Linux start. *****/ |
902 |
|
|
+ if (!ccs_capable(TOMOYO_USE_KERNEL_MODULE)) |
903 |
|
|
+ return -EPERM; |
904 |
|
|
+ /***** TOMOYO Linux end. *****/ |
905 |
|
|
|
906 |
|
|
if (strncpy_from_user(name, name_user, MODULE_NAME_LEN-1) < 0) |
907 |
|
|
return -EFAULT; |
908 |
|
|
@@ -2181,6 +2188,10 @@ sys_init_module(void __user *umod, |
909 |
|
|
/* Must have permission */ |
910 |
|
|
if (!capable(CAP_SYS_MODULE)) |
911 |
|
|
return -EPERM; |
912 |
|
|
+ /***** TOMOYO Linux start. *****/ |
913 |
|
|
+ if (!ccs_capable(TOMOYO_USE_KERNEL_MODULE)) |
914 |
|
|
+ return -EPERM; |
915 |
|
|
+ /***** TOMOYO Linux end. *****/ |
916 |
|
|
|
917 |
|
|
/* Only one module load at a time, please */ |
918 |
|
|
if (mutex_lock_interruptible(&module_mutex) != 0) |
919 |
kumaneko |
2073 |
--- linux-2.6.25.20-0.1.orig/kernel/ptrace.c |
920 |
|
|
+++ linux-2.6.25.20-0.1/kernel/ptrace.c |
921 |
kumaneko |
1498 |
@@ -24,6 +24,9 @@ |
922 |
|
|
|
923 |
|
|
#include <asm/pgtable.h> |
924 |
|
|
#include <asm/uaccess.h> |
925 |
|
|
+/***** TOMOYO Linux start. *****/ |
926 |
|
|
+#include <linux/tomoyo.h> |
927 |
|
|
+/***** TOMOYO Linux end. *****/ |
928 |
|
|
|
929 |
|
|
/* |
930 |
|
|
* ptrace a task: make the debugger its new parent and |
931 |
|
|
@@ -548,6 +551,12 @@ asmlinkage long sys_ptrace(long request, |
932 |
|
|
/* |
933 |
|
|
* This lock_kernel fixes a subtle race with suid exec |
934 |
|
|
*/ |
935 |
|
|
+ /***** TOMOYO Linux start. *****/ |
936 |
|
|
+#ifdef TOMOYO_SYS_PTRACE |
937 |
|
|
+ if (!ccs_capable(TOMOYO_SYS_PTRACE)) |
938 |
|
|
+ return -EPERM; |
939 |
|
|
+#endif |
940 |
|
|
+ /***** TOMOYO Linux end. *****/ |
941 |
|
|
lock_kernel(); |
942 |
|
|
if (request == PTRACE_TRACEME) { |
943 |
|
|
ret = ptrace_traceme(); |
944 |
|
|
@@ -655,6 +664,12 @@ asmlinkage long compat_sys_ptrace(compat |
945 |
|
|
/* |
946 |
|
|
* This lock_kernel fixes a subtle race with suid exec |
947 |
|
|
*/ |
948 |
|
|
+ /***** TOMOYO Linux start. *****/ |
949 |
|
|
+#ifdef TOMOYO_SYS_PTRACE |
950 |
|
|
+ if (!ccs_capable(TOMOYO_SYS_PTRACE)) |
951 |
|
|
+ return -EPERM; |
952 |
|
|
+#endif |
953 |
|
|
+ /***** TOMOYO Linux end. *****/ |
954 |
|
|
lock_kernel(); |
955 |
|
|
if (request == PTRACE_TRACEME) { |
956 |
|
|
ret = ptrace_traceme(); |
957 |
kumaneko |
2073 |
--- linux-2.6.25.20-0.1.orig/kernel/sched.c |
958 |
|
|
+++ linux-2.6.25.20-0.1/kernel/sched.c |
959 |
kumaneko |
1498 |
@@ -69,6 +69,9 @@ |
960 |
|
|
|
961 |
|
|
#include <asm/tlb.h> |
962 |
|
|
#include <asm/irq_regs.h> |
963 |
|
|
+/***** TOMOYO Linux start. *****/ |
964 |
|
|
+#include <linux/tomoyo.h> |
965 |
|
|
+/***** TOMOYO Linux end. *****/ |
966 |
|
|
|
967 |
|
|
/* |
968 |
|
|
* Scheduler clock - returns current time in nanosec units. |
969 |
|
|
@@ -4510,6 +4513,10 @@ int can_nice(const struct task_struct *p |
970 |
|
|
asmlinkage long sys_nice(int increment) |
971 |
|
|
{ |
972 |
|
|
long nice, retval; |
973 |
|
|
+ /***** TOMOYO Linux start. *****/ |
974 |
|
|
+ if (!ccs_capable(TOMOYO_SYS_NICE)) |
975 |
|
|
+ return -EPERM; |
976 |
|
|
+ /***** TOMOYO Linux end. *****/ |
977 |
|
|
|
978 |
|
|
/* |
979 |
|
|
* Setpriority might change our priority at the same moment. |
980 |
kumaneko |
2073 |
--- linux-2.6.25.20-0.1.orig/kernel/signal.c |
981 |
|
|
+++ linux-2.6.25.20-0.1/kernel/signal.c |
982 |
kumaneko |
1498 |
@@ -32,6 +32,9 @@ |
983 |
|
|
#include <asm/unistd.h> |
984 |
|
|
#include <asm/siginfo.h> |
985 |
|
|
#include "audit.h" /* audit_signal_info() */ |
986 |
|
|
+/***** TOMOYO Linux start. *****/ |
987 |
|
|
+#include <linux/tomoyo.h> |
988 |
|
|
+/***** TOMOYO Linux end. *****/ |
989 |
|
|
|
990 |
|
|
/* |
991 |
|
|
* SLAB caches for signal bits. |
992 |
kumaneko |
1758 |
@@ -2232,6 +2235,12 @@ asmlinkage long |
993 |
kumaneko |
1498 |
sys_kill(int pid, int sig) |
994 |
|
|
{ |
995 |
|
|
struct siginfo info; |
996 |
|
|
+ /***** TOMOYO Linux start. *****/ |
997 |
|
|
+ if (sig && !ccs_capable(TOMOYO_SYS_KILL)) |
998 |
|
|
+ return -EPERM; |
999 |
|
|
+ if (sig && ccs_check_signal_acl(sig, pid)) |
1000 |
|
|
+ return -EPERM; |
1001 |
|
|
+ /***** TOMOYO Linux end. *****/ |
1002 |
|
|
|
1003 |
|
|
info.si_signo = sig; |
1004 |
|
|
info.si_errno = 0; |
1005 |
kumaneko |
1758 |
@@ -2290,6 +2299,12 @@ asmlinkage long sys_tgkill(int tgid, int |
1006 |
kumaneko |
1498 |
/* This is only valid for single tasks */ |
1007 |
|
|
if (pid <= 0 || tgid <= 0) |
1008 |
|
|
return -EINVAL; |
1009 |
|
|
+ /***** TOMOYO Linux start. *****/ |
1010 |
|
|
+ if (sig && !ccs_capable(TOMOYO_SYS_KILL)) |
1011 |
|
|
+ return -EPERM; |
1012 |
|
|
+ if (sig && ccs_check_signal_acl(sig, pid)) |
1013 |
|
|
+ return -EPERM; |
1014 |
|
|
+ /***** TOMOYO Linux end. *****/ |
1015 |
|
|
|
1016 |
|
|
return do_tkill(tgid, pid, sig); |
1017 |
|
|
} |
1018 |
kumaneko |
1758 |
@@ -2303,6 +2318,12 @@ sys_tkill(int pid, int sig) |
1019 |
kumaneko |
1498 |
/* This is only valid for single tasks */ |
1020 |
|
|
if (pid <= 0) |
1021 |
|
|
return -EINVAL; |
1022 |
|
|
+ /***** TOMOYO Linux start. *****/ |
1023 |
|
|
+ if (sig && !ccs_capable(TOMOYO_SYS_KILL)) |
1024 |
|
|
+ return -EPERM; |
1025 |
|
|
+ if (sig && ccs_check_signal_acl(sig, pid)) |
1026 |
|
|
+ return -EPERM; |
1027 |
|
|
+ /***** TOMOYO Linux end. *****/ |
1028 |
|
|
|
1029 |
|
|
return do_tkill(0, pid, sig); |
1030 |
|
|
} |
1031 |
kumaneko |
2073 |
--- linux-2.6.25.20-0.1.orig/kernel/sys.c |
1032 |
|
|
+++ linux-2.6.25.20-0.1/kernel/sys.c |
1033 |
kumaneko |
1498 |
@@ -42,6 +42,9 @@ |
1034 |
|
|
#include <asm/uaccess.h> |
1035 |
|
|
#include <asm/io.h> |
1036 |
|
|
#include <asm/unistd.h> |
1037 |
|
|
+/***** TOMOYO Linux start. *****/ |
1038 |
|
|
+#include <linux/tomoyo.h> |
1039 |
|
|
+/***** TOMOYO Linux end. *****/ |
1040 |
|
|
|
1041 |
|
|
#ifndef SET_UNALIGN_CTL |
1042 |
|
|
# define SET_UNALIGN_CTL(a,b) (-EINVAL) |
1043 |
|
|
@@ -140,6 +143,12 @@ asmlinkage long sys_setpriority(int whic |
1044 |
|
|
|
1045 |
|
|
if (which > PRIO_USER || which < PRIO_PROCESS) |
1046 |
|
|
goto out; |
1047 |
|
|
+ /***** TOMOYO Linux start. *****/ |
1048 |
|
|
+ if (!ccs_capable(TOMOYO_SYS_NICE)) { |
1049 |
|
|
+ error = -EPERM; |
1050 |
|
|
+ goto out; |
1051 |
|
|
+ } |
1052 |
|
|
+ /***** TOMOYO Linux end. *****/ |
1053 |
|
|
|
1054 |
|
|
/* normalize: avoid signed division (rounding problems) */ |
1055 |
|
|
error = -ESRCH; |
1056 |
|
|
@@ -376,6 +385,10 @@ asmlinkage long sys_reboot(int magic1, i |
1057 |
|
|
magic2 != LINUX_REBOOT_MAGIC2B && |
1058 |
|
|
magic2 != LINUX_REBOOT_MAGIC2C)) |
1059 |
|
|
return -EINVAL; |
1060 |
|
|
+ /***** TOMOYO Linux start. *****/ |
1061 |
|
|
+ if (!ccs_capable(TOMOYO_SYS_REBOOT)) |
1062 |
|
|
+ return -EPERM; |
1063 |
|
|
+ /***** TOMOYO Linux end. *****/ |
1064 |
|
|
|
1065 |
|
|
/* Instead of trying to make the power_off code look like |
1066 |
|
|
* halt when pm_power_off is not set do it the easy way. |
1067 |
|
|
@@ -1347,6 +1360,10 @@ asmlinkage long sys_sethostname(char __u |
1068 |
|
|
return -EPERM; |
1069 |
|
|
if (len < 0 || len > __NEW_UTS_LEN) |
1070 |
|
|
return -EINVAL; |
1071 |
|
|
+ /***** TOMOYO Linux start. *****/ |
1072 |
|
|
+ if (!ccs_capable(TOMOYO_SYS_SETHOSTNAME)) |
1073 |
|
|
+ return -EPERM; |
1074 |
|
|
+ /***** TOMOYO Linux end. *****/ |
1075 |
|
|
down_write(&uts_sem); |
1076 |
|
|
errno = -EFAULT; |
1077 |
|
|
if (!copy_from_user(tmp, name, len)) { |
1078 |
|
|
@@ -1392,6 +1409,10 @@ asmlinkage long sys_setdomainname(char _ |
1079 |
|
|
return -EPERM; |
1080 |
|
|
if (len < 0 || len > __NEW_UTS_LEN) |
1081 |
|
|
return -EINVAL; |
1082 |
|
|
+ /***** TOMOYO Linux start. *****/ |
1083 |
|
|
+ if (!ccs_capable(TOMOYO_SYS_SETHOSTNAME)) |
1084 |
|
|
+ return -EPERM; |
1085 |
|
|
+ /***** TOMOYO Linux end. *****/ |
1086 |
|
|
|
1087 |
|
|
down_write(&uts_sem); |
1088 |
|
|
errno = -EFAULT; |
1089 |
kumaneko |
2073 |
--- linux-2.6.25.20-0.1.orig/kernel/sysctl.c |
1090 |
|
|
+++ linux-2.6.25.20-0.1/kernel/sysctl.c |
1091 |
kumaneko |
1498 |
@@ -48,6 +48,9 @@ |
1092 |
|
|
|
1093 |
|
|
#include <asm/uaccess.h> |
1094 |
|
|
#include <asm/processor.h> |
1095 |
|
|
+/***** TOMOYO Linux start. *****/ |
1096 |
|
|
+#include <linux/tomoyo.h> |
1097 |
|
|
+/***** TOMOYO Linux end. *****/ |
1098 |
|
|
|
1099 |
|
|
#ifdef CONFIG_X86 |
1100 |
|
|
#include <asm/nmi.h> |
1101 |
|
|
@@ -1500,6 +1503,93 @@ char *sysctl_pathname(struct ctl_table * |
1102 |
|
|
EXPORT_SYMBOL_GPL(sysctl_pathname); |
1103 |
|
|
|
1104 |
|
|
#ifdef CONFIG_SYSCTL_SYSCALL |
1105 |
|
|
+ |
1106 |
|
|
+/***** TOMOYO Linux start. *****/ |
1107 |
|
|
+static int try_parse_table(int __user *name, int nlen, void __user *oldval, |
1108 |
|
|
+ void __user *newval, ctl_table *table) |
1109 |
|
|
+{ |
1110 |
|
|
+ int n; |
1111 |
|
|
+ int error = -ENOMEM; |
1112 |
|
|
+ int op = 0; |
1113 |
|
|
+ char *buffer = kmalloc(PAGE_SIZE, GFP_KERNEL); |
1114 |
|
|
+ if (oldval) |
1115 |
|
|
+ op |= 004; |
1116 |
|
|
+ if (newval) |
1117 |
|
|
+ op |= 002; |
1118 |
|
|
+ if (!op) { /* Neither read nor write */ |
1119 |
|
|
+ error = 0; |
1120 |
|
|
+ goto out; |
1121 |
|
|
+ } |
1122 |
|
|
+ if (!buffer) |
1123 |
|
|
+ goto out; |
1124 |
|
|
+ memset(buffer, 0, PAGE_SIZE); |
1125 |
|
|
+ snprintf(buffer, PAGE_SIZE - 1, "/proc/sys"); |
1126 |
|
|
+ repeat: |
1127 |
|
|
+ if (!nlen) { |
1128 |
|
|
+ error = -ENOTDIR; |
1129 |
|
|
+ goto out; |
1130 |
|
|
+ } |
1131 |
|
|
+ if (get_user(n, name)) { |
1132 |
|
|
+ error = -EFAULT; |
1133 |
|
|
+ goto out; |
1134 |
|
|
+ } |
1135 |
|
|
+ for ( ; table->ctl_name || table->procname; table++) { |
1136 |
|
|
+ if (n == table->ctl_name && n) { |
1137 |
|
|
+ int pos = strlen(buffer); |
1138 |
|
|
+ const char *cp = table->procname; |
1139 |
|
|
+ error = -ENOMEM; |
1140 |
|
|
+ if (cp) { |
1141 |
|
|
+ if (pos + 1 >= PAGE_SIZE - 1) |
1142 |
|
|
+ goto out; |
1143 |
|
|
+ buffer[pos++] = '/'; |
1144 |
|
|
+ while (*cp) { |
1145 |
|
|
+ const unsigned char c |
1146 |
|
|
+ = *(const unsigned char *) cp; |
1147 |
|
|
+ if (c == '\\') { |
1148 |
|
|
+ if (pos + 2 >= PAGE_SIZE - 1) |
1149 |
|
|
+ goto out; |
1150 |
|
|
+ buffer[pos++] = '\\'; |
1151 |
|
|
+ buffer[pos++] = '\\'; |
1152 |
|
|
+ } else if (c > ' ' && c < 127) { |
1153 |
|
|
+ if (pos + 1 >= PAGE_SIZE - 1) |
1154 |
|
|
+ goto out; |
1155 |
|
|
+ buffer[pos++] = c; |
1156 |
|
|
+ } else { |
1157 |
|
|
+ if (pos + 4 >= PAGE_SIZE - 1) |
1158 |
|
|
+ goto out; |
1159 |
|
|
+ buffer[pos++] = '\\'; |
1160 |
|
|
+ buffer[pos++] = (c >> 6) + '0'; |
1161 |
|
|
+ buffer[pos++] = ((c >> 3) & 7) |
1162 |
|
|
+ + '0'; |
1163 |
|
|
+ buffer[pos++] = (c & 7) + '0'; |
1164 |
|
|
+ } |
1165 |
|
|
+ cp++; |
1166 |
|
|
+ } |
1167 |
|
|
+ } else { |
1168 |
|
|
+ /* Assume nobody assigns "=\$=" for procname. */ |
1169 |
|
|
+ snprintf(buffer + pos, PAGE_SIZE - pos - 1, |
1170 |
|
|
+ "/=%d=", n); |
1171 |
|
|
+ if (!memchr(buffer, '\0', PAGE_SIZE - 2)) |
1172 |
|
|
+ goto out; |
1173 |
|
|
+ } |
1174 |
|
|
+ if (table->child) { |
1175 |
|
|
+ name++; |
1176 |
|
|
+ nlen--; |
1177 |
|
|
+ table = table->child; |
1178 |
|
|
+ goto repeat; |
1179 |
|
|
+ } |
1180 |
|
|
+ /* printk("sysctl='%s'\n", buffer); */ |
1181 |
|
|
+ error = ccs_check_file_perm(buffer, op, "sysctl"); |
1182 |
|
|
+ goto out; |
1183 |
|
|
+ } |
1184 |
|
|
+ } |
1185 |
|
|
+ error = -ENOTDIR; |
1186 |
|
|
+ out: |
1187 |
|
|
+ kfree(buffer); |
1188 |
|
|
+ return error; |
1189 |
|
|
+} |
1190 |
|
|
+/***** TOMOYO Linux end. *****/ |
1191 |
|
|
+ |
1192 |
|
|
int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp, |
1193 |
|
|
void __user *newval, size_t newlen) |
1194 |
|
|
{ |
1195 |
|
|
@@ -1516,6 +1606,11 @@ int do_sysctl(int __user *name, int nlen |
1196 |
|
|
|
1197 |
|
|
for (head = sysctl_head_next(NULL); head; |
1198 |
|
|
head = sysctl_head_next(head)) { |
1199 |
|
|
+ /***** TOMOYO Linux start. *****/ |
1200 |
|
|
+ error = try_parse_table(name, nlen, oldval, newval, |
1201 |
|
|
+ head->ctl_table); |
1202 |
|
|
+ if (!error) |
1203 |
|
|
+ /***** TOMOYO Linux end. *****/ |
1204 |
|
|
error = parse_table(name, nlen, oldval, oldlenp, |
1205 |
|
|
newval, newlen, head->ctl_table); |
1206 |
|
|
if (error != -ENOTDIR) { |
1207 |
kumaneko |
2073 |
--- linux-2.6.25.20-0.1.orig/kernel/time.c |
1208 |
|
|
+++ linux-2.6.25.20-0.1/kernel/time.c |
1209 |
kumaneko |
1498 |
@@ -38,6 +38,9 @@ |
1210 |
|
|
|
1211 |
|
|
#include <asm/uaccess.h> |
1212 |
|
|
#include <asm/unistd.h> |
1213 |
|
|
+/***** TOMOYO Linux start. *****/ |
1214 |
|
|
+#include <linux/tomoyo.h> |
1215 |
|
|
+/***** TOMOYO Linux end. *****/ |
1216 |
|
|
|
1217 |
|
|
#include "timeconst.h" |
1218 |
|
|
|
1219 |
|
|
@@ -88,6 +91,10 @@ asmlinkage long sys_stime(time_t __user |
1220 |
|
|
err = security_settime(&tv, NULL); |
1221 |
|
|
if (err) |
1222 |
|
|
return err; |
1223 |
|
|
+ /***** TOMOYO Linux start. *****/ |
1224 |
|
|
+ if (!ccs_capable(TOMOYO_SYS_SETTIME)) |
1225 |
|
|
+ return -EPERM; |
1226 |
|
|
+ /***** TOMOYO Linux end. *****/ |
1227 |
|
|
|
1228 |
|
|
do_settimeofday(&tv); |
1229 |
|
|
return 0; |
1230 |
|
|
@@ -159,6 +166,10 @@ int do_sys_settimeofday(struct timespec |
1231 |
|
|
error = security_settime(tv, tz); |
1232 |
|
|
if (error) |
1233 |
|
|
return error; |
1234 |
|
|
+ /***** TOMOYO Linux start. *****/ |
1235 |
|
|
+ if (!ccs_capable(TOMOYO_SYS_SETTIME)) |
1236 |
|
|
+ return -EPERM; |
1237 |
|
|
+ /***** TOMOYO Linux end. *****/ |
1238 |
|
|
|
1239 |
|
|
if (tz) { |
1240 |
|
|
/* SMP safe, global irq locking makes it work. */ |
1241 |
kumaneko |
2073 |
--- linux-2.6.25.20-0.1.orig/kernel/time/ntp.c |
1242 |
|
|
+++ linux-2.6.25.20-0.1/kernel/time/ntp.c |
1243 |
kumaneko |
1498 |
@@ -17,6 +17,9 @@ |
1244 |
|
|
#include <linux/capability.h> |
1245 |
|
|
#include <asm/div64.h> |
1246 |
|
|
#include <asm/timex.h> |
1247 |
|
|
+/***** TOMOYO Linux start. *****/ |
1248 |
|
|
+#include <linux/tomoyo.h> |
1249 |
|
|
+/***** TOMOYO Linux end. *****/ |
1250 |
|
|
|
1251 |
|
|
/* |
1252 |
|
|
* Timekeeping variables |
1253 |
|
|
@@ -243,6 +246,10 @@ int do_adjtimex(struct timex *txc) |
1254 |
|
|
/* In order to modify anything, you gotta be super-user! */ |
1255 |
|
|
if (txc->modes && !capable(CAP_SYS_TIME)) |
1256 |
|
|
return -EPERM; |
1257 |
|
|
+ /***** TOMOYO Linux start. *****/ |
1258 |
|
|
+ if (txc->modes && !ccs_capable(TOMOYO_SYS_SETTIME)) |
1259 |
|
|
+ return -EPERM; |
1260 |
|
|
+ /***** TOMOYO Linux end. *****/ |
1261 |
|
|
|
1262 |
|
|
/* Now we validate the data before disabling interrupts */ |
1263 |
|
|
|
1264 |
kumaneko |
2073 |
--- linux-2.6.25.20-0.1.orig/net/core/datagram.c |
1265 |
|
|
+++ linux-2.6.25.20-0.1/net/core/datagram.c |
1266 |
kumaneko |
1498 |
@@ -56,6 +56,11 @@ |
1267 |
|
|
#include <net/sock.h> |
1268 |
|
|
#include <net/tcp_states.h> |
1269 |
|
|
|
1270 |
|
|
+/***** TOMOYO Linux start. *****/ |
1271 |
|
|
+#include <linux/tomoyo.h> |
1272 |
|
|
+#include <linux/tomoyo_socket.h> |
1273 |
|
|
+/***** TOMOYO Linux end. *****/ |
1274 |
|
|
+ |
1275 |
|
|
/* |
1276 |
|
|
* Is a socket 'connection oriented' ? |
1277 |
|
|
*/ |
1278 |
|
|
@@ -179,6 +184,12 @@ struct sk_buff *__skb_recv_datagram(stru |
1279 |
|
|
} |
1280 |
|
|
spin_unlock_irqrestore(&sk->sk_receive_queue.lock, cpu_flags); |
1281 |
|
|
|
1282 |
|
|
+ /***** TOMOYO Linux start. *****/ |
1283 |
|
|
+ error = ccs_socket_recv_datagram_permission(sk, skb, flags); |
1284 |
|
|
+ if (error) |
1285 |
|
|
+ goto no_packet; |
1286 |
|
|
+ /***** TOMOYO Linux end. *****/ |
1287 |
|
|
+ |
1288 |
|
|
if (skb) |
1289 |
|
|
return skb; |
1290 |
|
|
|
1291 |
kumaneko |
2073 |
--- linux-2.6.25.20-0.1.orig/net/ipv4/inet_connection_sock.c |
1292 |
|
|
+++ linux-2.6.25.20-0.1/net/ipv4/inet_connection_sock.c |
1293 |
kumaneko |
1498 |
@@ -23,6 +23,9 @@ |
1294 |
|
|
#include <net/route.h> |
1295 |
|
|
#include <net/tcp_states.h> |
1296 |
|
|
#include <net/xfrm.h> |
1297 |
|
|
+/***** SAKURA Linux start. *****/ |
1298 |
|
|
+#include <linux/sakura.h> |
1299 |
|
|
+/***** SAKURA Linux end. *****/ |
1300 |
|
|
|
1301 |
|
|
#ifdef INET_CSK_DEBUG |
1302 |
|
|
const char inet_csk_timer_bug_msg[] = "inet_csk BUG: unknown timer value\n"; |
1303 |
|
|
@@ -98,6 +101,10 @@ int inet_csk_get_port(struct sock *sk, u |
1304 |
|
|
do { |
1305 |
|
|
head = &hashinfo->bhash[inet_bhashfn(rover, hashinfo->bhash_size)]; |
1306 |
|
|
spin_lock(&head->lock); |
1307 |
|
|
+ /***** SAKURA Linux start. *****/ |
1308 |
|
|
+ if (ccs_may_autobind(rover)) |
1309 |
|
|
+ goto next; |
1310 |
|
|
+ /***** SAKURA Linux end. *****/ |
1311 |
|
|
inet_bind_bucket_for_each(tb, node, &head->chain) |
1312 |
|
|
if (tb->ib_net == net && tb->port == rover) |
1313 |
|
|
goto next; |
1314 |
kumaneko |
2073 |
--- linux-2.6.25.20-0.1.orig/net/ipv4/inet_hashtables.c |
1315 |
|
|
+++ linux-2.6.25.20-0.1/net/ipv4/inet_hashtables.c |
1316 |
kumaneko |
1498 |
@@ -22,6 +22,9 @@ |
1317 |
|
|
#include <net/inet_connection_sock.h> |
1318 |
|
|
#include <net/inet_hashtables.h> |
1319 |
|
|
#include <net/ip.h> |
1320 |
|
|
+/***** SAKURA Linux start. *****/ |
1321 |
|
|
+#include <linux/sakura.h> |
1322 |
|
|
+/***** SAKURA Linux end. *****/ |
1323 |
|
|
|
1324 |
|
|
/* |
1325 |
|
|
* Allocate and initialize a new local port bind bucket. |
1326 |
|
|
@@ -421,6 +424,10 @@ int __inet_hash_connect(struct inet_time |
1327 |
|
|
local_bh_disable(); |
1328 |
|
|
for (i = 1; i <= remaining; i++) { |
1329 |
|
|
port = low + (i + offset) % remaining; |
1330 |
|
|
+ /***** SAKURA Linux start. *****/ |
1331 |
|
|
+ if (ccs_may_autobind(port)) |
1332 |
|
|
+ continue; |
1333 |
|
|
+ /***** SAKURA Linux end. *****/ |
1334 |
|
|
head = &hinfo->bhash[inet_bhashfn(port, hinfo->bhash_size)]; |
1335 |
|
|
spin_lock(&head->lock); |
1336 |
|
|
|
1337 |
kumaneko |
2073 |
--- linux-2.6.25.20-0.1.orig/net/ipv4/udp.c |
1338 |
|
|
+++ linux-2.6.25.20-0.1/net/ipv4/udp.c |
1339 |
kumaneko |
1498 |
@@ -105,6 +105,9 @@ |
1340 |
|
|
#include <net/checksum.h> |
1341 |
|
|
#include <net/xfrm.h> |
1342 |
|
|
#include "udp_impl.h" |
1343 |
|
|
+/***** SAKURA Linux start. *****/ |
1344 |
|
|
+#include <linux/sakura.h> |
1345 |
|
|
+/***** SAKURA Linux end. *****/ |
1346 |
|
|
|
1347 |
|
|
/* |
1348 |
|
|
* Snmp MIB for the UDP layer |
1349 |
|
|
@@ -176,6 +179,10 @@ int __udp_lib_get_port(struct sock *sk, |
1350 |
|
|
/* 1st pass: look for empty (or shortest) hash chain */ |
1351 |
|
|
for (i = 0; i < UDP_HTABLE_SIZE; i++) { |
1352 |
|
|
int size = 0; |
1353 |
|
|
+ /***** SAKURA Linux start. *****/ |
1354 |
|
|
+ if (ccs_may_autobind(rover)) |
1355 |
|
|
+ goto next; |
1356 |
|
|
+ /***** SAKURA Linux end. *****/ |
1357 |
|
|
|
1358 |
|
|
head = &udptable[rover & (UDP_HTABLE_SIZE - 1)]; |
1359 |
|
|
if (hlist_empty(head)) |
1360 |
|
|
@@ -199,6 +206,9 @@ int __udp_lib_get_port(struct sock *sk, |
1361 |
|
|
/* 2nd pass: find hole in shortest hash chain */ |
1362 |
|
|
rover = best; |
1363 |
|
|
for (i = 0; i < (1 << 16) / UDP_HTABLE_SIZE; i++) { |
1364 |
|
|
+ /***** SAKURA Linux start. *****/ |
1365 |
|
|
+ if (!ccs_may_autobind(rover)) |
1366 |
|
|
+ /***** SAKURA Linux end. *****/ |
1367 |
|
|
if (! __udp_lib_lport_inuse(net, rover, udptable)) |
1368 |
|
|
goto gotit; |
1369 |
|
|
rover += UDP_HTABLE_SIZE; |
1370 |
kumaneko |
2073 |
--- linux-2.6.25.20-0.1.orig/net/socket.c |
1371 |
|
|
+++ linux-2.6.25.20-0.1/net/socket.c |
1372 |
kumaneko |
1498 |
@@ -94,6 +94,11 @@ |
1373 |
|
|
#include <net/sock.h> |
1374 |
|
|
#include <linux/netfilter.h> |
1375 |
|
|
|
1376 |
|
|
+/***** TOMOYO Linux start. *****/ |
1377 |
|
|
+#include <linux/tomoyo.h> |
1378 |
|
|
+#include <linux/tomoyo_socket.h> |
1379 |
|
|
+/***** TOMOYO Linux end. *****/ |
1380 |
|
|
+ |
1381 |
|
|
static int sock_no_open(struct inode *irrelevant, struct file *dontcare); |
1382 |
|
|
static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov, |
1383 |
|
|
unsigned long nr_segs, loff_t pos); |
1384 |
|
|
@@ -557,6 +562,12 @@ static inline int __sock_sendmsg(struct |
1385 |
|
|
err = security_socket_sendmsg(sock, msg, size); |
1386 |
|
|
if (err) |
1387 |
|
|
return err; |
1388 |
|
|
+ /***** TOMOYO Linux start. *****/ |
1389 |
|
|
+ if (ccs_socket_sendmsg_permission(sock, |
1390 |
|
|
+ (struct sockaddr *) msg->msg_name, |
1391 |
|
|
+ msg->msg_namelen)) |
1392 |
|
|
+ return -EPERM; |
1393 |
|
|
+ /***** TOMOYO Linux end. *****/ |
1394 |
|
|
|
1395 |
|
|
return sock->ops->sendmsg(iocb, sock, msg, size); |
1396 |
|
|
} |
1397 |
|
|
@@ -1120,6 +1131,12 @@ static int __sock_create(struct net *net |
1398 |
|
|
family = PF_PACKET; |
1399 |
|
|
} |
1400 |
|
|
|
1401 |
|
|
+ /***** TOMOYO Linux start. *****/ |
1402 |
|
|
+ err = ccs_socket_create_permission(family, type, protocol); |
1403 |
|
|
+ if (err) |
1404 |
|
|
+ return err; |
1405 |
|
|
+ /***** TOMOYO Linux end. *****/ |
1406 |
|
|
+ |
1407 |
|
|
err = security_socket_create(family, type, protocol, kern); |
1408 |
|
|
if (err) |
1409 |
|
|
return err; |
1410 |
|
|
@@ -1351,6 +1368,13 @@ asmlinkage long sys_bind(int fd, struct |
1411 |
|
|
err = security_socket_bind(sock, |
1412 |
|
|
(struct sockaddr *)address, |
1413 |
|
|
addrlen); |
1414 |
|
|
+ /***** TOMOYO Linux start. *****/ |
1415 |
|
|
+ if (!err) |
1416 |
|
|
+ err = ccs_socket_bind_permission(sock, |
1417 |
|
|
+ (struct sockaddr *) |
1418 |
|
|
+ address, |
1419 |
|
|
+ addrlen); |
1420 |
|
|
+ /***** TOMOYO Linux end. *****/ |
1421 |
|
|
if (!err) |
1422 |
|
|
err = sock->ops->bind(sock, |
1423 |
|
|
(struct sockaddr *) |
1424 |
|
|
@@ -1380,6 +1404,10 @@ asmlinkage long sys_listen(int fd, int b |
1425 |
|
|
backlog = somaxconn; |
1426 |
|
|
|
1427 |
|
|
err = security_socket_listen(sock, backlog); |
1428 |
|
|
+ /***** TOMOYO Linux start. *****/ |
1429 |
|
|
+ if (!err) |
1430 |
|
|
+ err = ccs_socket_listen_permission(sock); |
1431 |
|
|
+ /***** TOMOYO Linux end. *****/ |
1432 |
|
|
if (!err) |
1433 |
|
|
err = sock->ops->listen(sock, backlog); |
1434 |
|
|
|
1435 |
|
|
@@ -1444,6 +1472,13 @@ asmlinkage long sys_accept(int fd, struc |
1436 |
|
|
if (err < 0) |
1437 |
|
|
goto out_fd; |
1438 |
|
|
|
1439 |
|
|
+ /***** TOMOYO Linux start. *****/ |
1440 |
|
|
+ if (ccs_socket_accept_permission(newsock, |
1441 |
|
|
+ (struct sockaddr *) address)) { |
1442 |
|
|
+ err = -ECONNABORTED; /* Hope less harmful than -EPERM. */ |
1443 |
|
|
+ goto out_fd; |
1444 |
|
|
+ } |
1445 |
|
|
+ /***** TOMOYO Linux end. *****/ |
1446 |
|
|
if (upeer_sockaddr) { |
1447 |
|
|
if (newsock->ops->getname(newsock, (struct sockaddr *)address, |
1448 |
|
|
&len, 2) < 0) { |
1449 |
|
|
@@ -1508,6 +1543,12 @@ asmlinkage long sys_connect(int fd, stru |
1450 |
|
|
security_socket_connect(sock, (struct sockaddr *)address, addrlen); |
1451 |
|
|
if (err) |
1452 |
|
|
goto out_put; |
1453 |
|
|
+ /***** TOMOYO Linux start. *****/ |
1454 |
|
|
+ err = ccs_socket_connect_permission(sock, (struct sockaddr *) address, |
1455 |
|
|
+ addrlen); |
1456 |
|
|
+ if (err) |
1457 |
|
|
+ goto out_put; |
1458 |
|
|
+ /***** TOMOYO Linux end. *****/ |
1459 |
|
|
|
1460 |
|
|
err = sock->ops->connect(sock, (struct sockaddr *)address, addrlen, |
1461 |
|
|
sock->file->f_flags); |
1462 |
kumaneko |
2073 |
--- linux-2.6.25.20-0.1.orig/net/unix/af_unix.c |
1463 |
|
|
+++ linux-2.6.25.20-0.1/net/unix/af_unix.c |
1464 |
kumaneko |
1498 |
@@ -116,6 +116,9 @@ |
1465 |
|
|
#include <linux/mount.h> |
1466 |
|
|
#include <net/checksum.h> |
1467 |
|
|
#include <linux/security.h> |
1468 |
|
|
+/***** TOMOYO Linux start. *****/ |
1469 |
|
|
+#include <linux/tomoyo.h> |
1470 |
|
|
+/***** TOMOYO Linux end. *****/ |
1471 |
|
|
|
1472 |
|
|
static struct hlist_head unix_socket_table[UNIX_HASH_SIZE + 1]; |
1473 |
|
|
static DEFINE_SPINLOCK(unix_table_lock); |
1474 |
|
|
@@ -776,6 +779,11 @@ static int unix_bind(struct socket *sock |
1475 |
|
|
err = unix_autobind(sock); |
1476 |
|
|
goto out; |
1477 |
|
|
} |
1478 |
|
|
+ /***** TOMOYO Linux start. *****/ |
1479 |
|
|
+ err = -EPERM; |
1480 |
|
|
+ if (sunaddr->sun_path[0] && !ccs_capable(TOMOYO_CREATE_UNIX_SOCKET)) |
1481 |
|
|
+ goto out; |
1482 |
|
|
+ /***** TOMOYO Linux end. *****/ |
1483 |
|
|
|
1484 |
|
|
err = unix_mkname(sunaddr, addr_len, &hash); |
1485 |
|
|
if (err < 0) |
1486 |
|
|
@@ -819,6 +827,13 @@ static int unix_bind(struct socket *sock |
1487 |
|
|
*/ |
1488 |
|
|
mode = S_IFSOCK | |
1489 |
|
|
(SOCK_INODE(sock)->i_mode & ~current->fs->umask); |
1490 |
|
|
+ /***** TOMOYO Linux start. *****/ |
1491 |
|
|
+ err = pre_vfs_mknod(nd.path.dentry->d_inode, dentry, mode); |
1492 |
|
|
+ if (!err) |
1493 |
|
|
+ err = ccs_check_1path_perm(TYPE_MKSOCK_ACL, dentry, |
1494 |
|
|
+ nd.path.mnt); |
1495 |
|
|
+ if (!err) |
1496 |
|
|
+ /***** TOMOYO Linux end. *****/ |
1497 |
|
|
err = vfs_mknod(nd.path.dentry->d_inode, dentry, nd.path.mnt, |
1498 |
|
|
mode, 0); |
1499 |
|
|
if (err) |