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