1 |
diff -ubBpEr linux-2.4.34/Documentation/Configure.help linux-2.4.34-ccs/Documentation/Configure.help |
2 |
--- linux-2.4.34/Documentation/Configure.help 2007-03-03 10:49:54.000000000 +0900 |
3 |
+++ linux-2.4.34-ccs/Documentation/Configure.help 2007-03-08 16:32:35.000000000 +0900 |
4 |
@@ -29075,6 +29075,222 @@ CONFIG_SOUND_WM97XX |
5 |
|
6 |
If unsure, say N. |
7 |
|
8 |
+CONFIG_SAKURA |
9 |
+ Say Y here to support the Domain-Free Mandatory Access Control. |
10 |
+ |
11 |
+ SAKURA stands for |
12 |
+ "Security Advancement Know-how Upon Read-only Approach". |
13 |
+ As the name shows, SAKURA was originally a methodology to make |
14 |
+ root fs read-only to avoid tampering the system files. |
15 |
+ But now, SAKURA is not only a methodology but also a kernel patch |
16 |
+ that improves the system security with less effort. |
17 |
+ |
18 |
+ SAKURA can restrict operations that affect systemwide. |
19 |
+ |
20 |
+CONFIG_SAKURA_RESTRICT_MOUNT |
21 |
+ This option allows you to restrict combinations of |
22 |
+ (type, device, dir) that the system can mount. |
23 |
+ |
24 |
+ For example, the WWW contents are stored at /var/www directory |
25 |
+ in a HDD, if tmpfs is mounted on /var/www by an attacker, |
26 |
+ the WWW contents will be hidden. |
27 |
+ You can prevent the attacker from mounting tmpfs on /var/www |
28 |
+ with this option. |
29 |
+ |
30 |
+CONFIG_SAKURA_RESTRICT_CHROOT |
31 |
+ This option allows you to restrict directories |
32 |
+ that the system can chroot to. |
33 |
+ |
34 |
+ If an attacker can chroot to arbitrary directories, |
35 |
+ the attacker can create a directory tree with malicious programs |
36 |
+ under a writable directory |
37 |
+ and execute them after chroot to that directory. |
38 |
+ You can prevent the attacker with this option. |
39 |
+ |
40 |
+ This option becomes more powerful if either root fs is read-only |
41 |
+ or mandatory file access controls are enforced. |
42 |
+ |
43 |
+CONFIG_SAKURA_RESTRICT_UNMOUNT |
44 |
+ This option allows you to reject unmount requests |
45 |
+ for specific directories. |
46 |
+ |
47 |
+ For example, many programs refer /proc, |
48 |
+ so if /proc is unmounted by an attacker, |
49 |
+ the system will go wrong. |
50 |
+ You can prevent the attacker from unmounting |
51 |
+ /proc with this option. |
52 |
+ |
53 |
+CONFIG_SAKURA_DENY_CONCEAL_MOUNT |
54 |
+ This option allows you to prevent mount requests |
55 |
+ that conceals existing mounts. |
56 |
+ |
57 |
+ For example, if tmpfs is mounted on /dev or /dev/shm |
58 |
+ when /dev/shm is already mounted, the files in /dev/shm |
59 |
+ will be hidden. |
60 |
+ You can prevent such cases with this option. |
61 |
+ |
62 |
+CONFIG_SAKURA_DENY_PIVOT_ROOT |
63 |
+ This option allows you to disable pivot_root |
64 |
+ after /sbin/init starts. |
65 |
+ |
66 |
+ In most systems, pivot_root is not used |
67 |
+ after /sbin/init starts. |
68 |
+ |
69 |
+CONFIG_SAKURA_RESTRICT_AUTOBIND |
70 |
+ This option allows you to prevent specific local ports |
71 |
+ from being assigned by automatic port assignment function |
72 |
+ (which is called by "bind() with port = 0" or |
73 |
+ "connect() without bind()"). |
74 |
+ |
75 |
+ For example, some proxy server uses port 8080, so this port |
76 |
+ should not be assigned by automatic port assignment function. |
77 |
+ |
78 |
+ You can create a single local ports range |
79 |
+ for automatic port assignment function |
80 |
+ via /proc/sys/net/ipv4/ip_local_port_range . |
81 |
+ This option allows you to divide the single range into multiple. |
82 |
+ |
83 |
+CONFIG_TOMOYO |
84 |
+ Say Y here to support the Domain-Based Mandatory Access Control. |
85 |
+ |
86 |
+ TOMOYO stands for "Task Oriented Management Obviates Your Onus". |
87 |
+ TOMOYO is intended to provide the Domain-Based MAC |
88 |
+ utilizing task_struct. |
89 |
+ |
90 |
+ The word "domain" in TOMOYO is a class that a process |
91 |
+ (i.e. task_struct) belong to. |
92 |
+ The domain of a process changes whenever the process |
93 |
+ executes a program. |
94 |
+ This allows you to classify at the finest level. |
95 |
+ The access permission is granted to domains, not to processes. |
96 |
+ Policy is defined as "Which domain can access to which resource.". |
97 |
+ There is no concept of "user id" nor "role" like RBAC. |
98 |
+ |
99 |
+ The biggest feature of TOMOYO is that TOMOYO has "accept mode". |
100 |
+ The accept mode can automatically generate policy definition, |
101 |
+ and dramatically reduces the policy definition labors. |
102 |
+ |
103 |
+ TOMOYO is much simpler and easier than SELinux. |
104 |
+ |
105 |
+ TOMOYO is applicable to figuring out the system's behavior, for |
106 |
+ TOMOYO uses the canonicalized absolute pathnames and |
107 |
+ TreeView style domain transitions. |
108 |
+ |
109 |
+ You can make custom root fs with minimum files |
110 |
+ to run minimum applications with TOMOYO. |
111 |
+ |
112 |
+CONFIG_TOMOYO_MAX_ACCEPT_ENTRY |
113 |
+ This is the default value for maximal ACL entries |
114 |
+ that are automatically appended into policy at "accept mode". |
115 |
+ Some programs access thousands of objects, so running |
116 |
+ such programs in "accept mode" dulls the system response |
117 |
+ and consumes much memory. |
118 |
+ This is the safeguard for such programs. |
119 |
+ |
120 |
+CONFIG_TOMOYO_MAC_FOR_FILE |
121 |
+ Say Y here to support the MAC for file access. |
122 |
+ |
123 |
+ This is the main feature of TOMOYO. |
124 |
+ If you don't say Y to this option, |
125 |
+ you can't improve the system security. |
126 |
+ |
127 |
+CONFIG_TOMOYO_MAC_FOR_ARGV0 |
128 |
+ Say Y here to support the MAC for argv0. |
129 |
+ |
130 |
+ The domain transition is done based on filename passed to do_execve(), |
131 |
+ while the behavior is defined based on argv[0]. |
132 |
+ There is no problem if the filename is argv[0]-unaware application. |
133 |
+ But if argv[0]-aware, passing malicious argv[0] may cause |
134 |
+ unexpected behavior. |
135 |
+ This option allows you to prevent unexpected argv[0]. |
136 |
+ |
137 |
+CONFIG_TOMOYO_MAC_FOR_NETWORK |
138 |
+ Say Y here to support the MAC for network address and port usage. |
139 |
+ |
140 |
+ This option allows you to restrict IP address and port numbers |
141 |
+ that a domain can use. |
142 |
+ For example, you can use this option to allow SSH server to |
143 |
+ "bind to TCP port 22 on address 10.0.0.1" |
144 |
+ "listen to TCP port 22 on address 10.0.0.1" |
145 |
+ "accept from TCP port between 1024 and 65535 on address |
146 |
+ between 10.0.0.3 and 10.0.0.254" |
147 |
+ "communicate with UDP port 53 of address 10.0.0.2" |
148 |
+ using the following policy. |
149 |
+ |
150 |
+ allow_bind TCP 10.0.0.1 22 |
151 |
+ allow_listen TCP 10.0.0.1 22 |
152 |
+ allow_accept TCP 10.0.0.3-10.0.0.254 1024-65535 |
153 |
+ allow_connect UDP 10.0.0.2 53 |
154 |
+ |
155 |
+CONFIG_TOMOYO_MAC_FOR_SIGNAL |
156 |
+ Say Y here to support the MAC for signal delivery. |
157 |
+ |
158 |
+ This option allows you to restrict |
159 |
+ the combination of (signal number, destination domain) |
160 |
+ that a domain can deliver. |
161 |
+ |
162 |
+ Without this option, any process that are running as root |
163 |
+ can kill arbitrary processes. |
164 |
+ |
165 |
+CONFIG_TOMOYO_MAC_FOR_CAPABILITY |
166 |
+ Say Y here to support the MAC for capabilities. |
167 |
+ |
168 |
+ The capabilities in TOMOYO are not the Linux (POSIX) capabilities. |
169 |
+ The capabilities in TOMOYO are the boolean flags of system calls |
170 |
+ that a domain can call. |
171 |
+ |
172 |
+ You should say Y to this option, for the policy syntax can't |
173 |
+ distinguish regular files, FIFOs, unix domain sockets, |
174 |
+ symbolic links and device files. |
175 |
+ This option allows you to restrict type of files |
176 |
+ that a domain can create using mknod. |
177 |
+ |
178 |
+CONFIG_TOMOYO_AUDIT |
179 |
+ If you enable this option, you can read |
180 |
+ access grant logs and access reject logs via |
181 |
+ /proc/ccs/info/grant_log and /proc/ccs/info/reject_log . |
182 |
+ If you don't need these logs you can disable this option. |
183 |
+ |
184 |
+CONFIG_TOMOYO_MAX_GRANT_LOG |
185 |
+ This is the default value for maximal entries for |
186 |
+ access grant logs that the kernel can hold on memory. |
187 |
+ You can read the log via /proc/ccs/info/grant_log. |
188 |
+ If you don't need access grant logs, |
189 |
+ you may set this value to 0. |
190 |
+ |
191 |
+CONFIG_TOMOYO_MAX_REJECT_LOG |
192 |
+ This is the default value for maximal entries for |
193 |
+ access reject logs that the kernel can hold on memory. |
194 |
+ You can read the log via /proc/ccs/info/reject_log. |
195 |
+ If you don't need access reject logs, |
196 |
+ you may set this value to 0. |
197 |
+ |
198 |
+CONFIG_SYAORAN |
199 |
+ Say Y or M here to support the Tamper-Proof Device Filesystem. |
200 |
+ |
201 |
+ SYAORAN stands for |
202 |
+ "Simple Yet All-important Object Realizing Abiding Nexus". |
203 |
+ SYAORAN is a filesystem for /dev with Mandatory Access Control. |
204 |
+ |
205 |
+ SAKURA can make root fs read-only, but the system can't work |
206 |
+ if /dev is read-only. Therefore you need to mount a writable |
207 |
+ filesystem (such as tmpfs) for /dev if root fs is read-only. |
208 |
+ |
209 |
+ But the writable /dev means that files on /dev might be tampered. |
210 |
+ For example, if /dev/null is deleted and re-created as a symbolic |
211 |
+ link to /dev/hda by an attacker, the contents of the IDE HDD |
212 |
+ will be destroyed at a blow. |
213 |
+ |
214 |
+ Also, TOMOYO controls file access by pathnames, |
215 |
+ not by security labels. |
216 |
+ Therefore /dev/null, for example, might be tampered |
217 |
+ if a process have write permission to /dev/null . |
218 |
+ |
219 |
+ SYAORAN can ensure /dev/null is a character device file |
220 |
+ with major=1 minor=3. |
221 |
+ |
222 |
+ You can use SAKURA to make /dev not unmountable. |
223 |
+ |
224 |
# |
225 |
# A couple of things I keep forgetting: |
226 |
# capitalize: AppleTalk, Ethernet, DOS, DMA, FAT, FTP, Internet, |
227 |
diff -ubBpEr linux-2.4.34/Makefile linux-2.4.34-ccs/Makefile |
228 |
--- linux-2.4.34/Makefile 2007-03-03 10:49:54.000000000 +0900 |
229 |
+++ linux-2.4.34-ccs/Makefile 2007-03-03 10:55:24.000000000 +0900 |
230 |
@@ -1,7 +1,7 @@ |
231 |
VERSION = 2 |
232 |
PATCHLEVEL = 4 |
233 |
SUBLEVEL = 34 |
234 |
-EXTRAVERSION = |
235 |
+EXTRAVERSION = -ccs |
236 |
|
237 |
KERNELRELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION) |
238 |
|
239 |
diff -ubBpEr linux-2.4.34/fs/Config.in linux-2.4.34-ccs/fs/Config.in |
240 |
--- linux-2.4.34/fs/Config.in 2007-03-03 10:49:54.000000000 +0900 |
241 |
+++ linux-2.4.34-ccs/fs/Config.in 2007-03-03 10:55:24.000000000 +0900 |
242 |
@@ -176,4 +176,7 @@ comment 'Partition Types' |
243 |
source fs/partitions/Config.in |
244 |
endmenu |
245 |
source fs/nls/Config.in |
246 |
+ |
247 |
+source fs/Config.ccs.in |
248 |
+ |
249 |
endmenu |
250 |
diff -ubBpEr linux-2.4.34/fs/Makefile linux-2.4.34-ccs/fs/Makefile |
251 |
--- linux-2.4.34/fs/Makefile 2007-03-03 10:49:54.000000000 +0900 |
252 |
+++ linux-2.4.34-ccs/fs/Makefile 2007-03-03 10:55:24.000000000 +0900 |
253 |
@@ -80,5 +80,5 @@ obj-$(CONFIG_BINFMT_ELF) += binfmt_elf.o |
254 |
# persistent filesystems |
255 |
obj-y += $(join $(subdir-y),$(subdir-y:%=/%.o)) |
256 |
|
257 |
- |
258 |
+include Makefile-2.4.ccs |
259 |
include $(TOPDIR)/Rules.make |
260 |
diff -ubBpEr linux-2.4.34/fs/attr.c linux-2.4.34-ccs/fs/attr.c |
261 |
--- linux-2.4.34/fs/attr.c 2007-03-03 11:38:51.000000000 +0900 |
262 |
+++ linux-2.4.34-ccs/fs/attr.c 2007-03-03 11:38:51.000000000 +0900 |
263 |
@@ -12,6 +12,9 @@ |
264 |
#include <linux/dnotify.h> |
265 |
#include <linux/fcntl.h> |
266 |
#include <linux/quotaops.h> |
267 |
+/***** TOMOYO Linux start. *****/ |
268 |
+#include <linux/tomoyo.h> |
269 |
+/***** TOMOYO Linux end. *****/ |
270 |
|
271 |
/* Taken over from the old code... */ |
272 |
|
273 |
@@ -127,6 +130,10 @@ int notify_change(struct dentry * dentry |
274 |
attr->ia_atime = now; |
275 |
if (!(ia_valid & ATTR_MTIME_SET)) |
276 |
attr->ia_mtime = now; |
277 |
+ /***** TOMOYO Linux start. *****/ |
278 |
+ if ((ia_valid & ATTR_MODE) && CheckCapabilityACL(TOMOYO_SYS_CHMOD)) return -EPERM; |
279 |
+ if ((ia_valid & (ATTR_UID | ATTR_GID)) && CheckCapabilityACL(TOMOYO_SYS_CHOWN)) return -EPERM; |
280 |
+ /***** TOMOYO Linux end. *****/ |
281 |
|
282 |
lock_kernel(); |
283 |
if (inode->i_op && inode->i_op->setattr) |
284 |
diff -ubBpEr linux-2.4.34/fs/exec.c linux-2.4.34-ccs/fs/exec.c |
285 |
--- linux-2.4.34/fs/exec.c 2007-03-03 11:38:51.000000000 +0900 |
286 |
+++ linux-2.4.34-ccs/fs/exec.c 2007-03-06 10:05:18.000000000 +0900 |
287 |
@@ -48,6 +48,10 @@ |
288 |
#include <linux/kmod.h> |
289 |
#endif |
290 |
|
291 |
+/***** TOMOYO Linux start. *****/ |
292 |
+#include <linux/tomoyo.h> |
293 |
+/***** TOMOYO Linux end. *****/ |
294 |
+ |
295 |
int core_uses_pid; |
296 |
char core_pattern[65] = "core"; |
297 |
int core_setuid_ok = 0; |
298 |
@@ -125,6 +129,11 @@ asmlinkage long sys_uselib(const char * |
299 |
if (error) |
300 |
goto exit; |
301 |
|
302 |
+ /***** TOMOYO Linux start. *****/ |
303 |
+ error = CheckOpenPermission(nd.dentry, nd.mnt, 01); /* 01 means "read". */ |
304 |
+ if (error) goto exit; |
305 |
+ /***** TOMOYO Linux end. *****/ |
306 |
+ |
307 |
file = dentry_open(nd.dentry, nd.mnt, O_RDONLY); |
308 |
error = PTR_ERR(file); |
309 |
if (IS_ERR(file)) |
310 |
@@ -389,6 +398,9 @@ struct file *open_exec(const char *name) |
311 |
int err = permission(inode, MAY_EXEC); |
312 |
if (!err && !(inode->i_mode & 0111)) |
313 |
err = -EACCES; |
314 |
+ /***** TOMOYO Linux start. *****/ |
315 |
+ if (!err && (current->tomoyo_flags & TOMOYO_CHECK_READ_FOR_OPEN_EXEC)) err = CheckOpenPermission(nd.dentry, nd.mnt, 01); /* 01 means "read". */ |
316 |
+ /***** TOMOYO Linux end. *****/ |
317 |
file = ERR_PTR(err); |
318 |
if (!err) { |
319 |
file = dentry_open(nd.dentry, nd.mnt, O_RDONLY); |
320 |
@@ -978,7 +990,8 @@ int do_execve(char * filename, char ** a |
321 |
if (retval < 0) |
322 |
goto out; |
323 |
|
324 |
- retval = search_binary_handler(&bprm,regs); |
325 |
+ retval = search_binary_handler_with_transition(&bprm,regs); |
326 |
+ |
327 |
if (retval >= 0) |
328 |
/* execve success */ |
329 |
return retval; |
330 |
diff -ubBpEr linux-2.4.34/fs/fcntl.c linux-2.4.34-ccs/fs/fcntl.c |
331 |
--- linux-2.4.34/fs/fcntl.c 2007-03-03 11:38:51.000000000 +0900 |
332 |
+++ linux-2.4.34-ccs/fs/fcntl.c 2007-03-03 11:38:51.000000000 +0900 |
333 |
@@ -16,6 +16,9 @@ |
334 |
#include <asm/poll.h> |
335 |
#include <asm/siginfo.h> |
336 |
#include <asm/uaccess.h> |
337 |
+/***** TOMOYO Linux start. *****/ |
338 |
+#include <linux/tomoyo.h> |
339 |
+/***** TOMOYO Linux end. *****/ |
340 |
|
341 |
extern int sock_fcntl (struct file *, unsigned int cmd, unsigned long arg); |
342 |
extern int fcntl_setlease(unsigned int fd, struct file *filp, long arg); |
343 |
@@ -214,6 +217,10 @@ static int setfl(int fd, struct file * f |
344 |
if (!(arg & O_APPEND) && IS_APPEND(inode)) |
345 |
return -EPERM; |
346 |
|
347 |
+ /***** TOMOYO Linux start. *****/ |
348 |
+ if (!(arg & O_APPEND) && CheckReWritePermission(filp)) return -EPERM; |
349 |
+ /***** TOMOYO Linux end. *****/ |
350 |
+ |
351 |
/* Did FASYNC state change? */ |
352 |
if ((arg ^ filp->f_flags) & FASYNC) { |
353 |
if (filp->f_op && filp->f_op->fasync) { |
354 |
diff -ubBpEr linux-2.4.34/fs/ioctl.c linux-2.4.34-ccs/fs/ioctl.c |
355 |
--- linux-2.4.34/fs/ioctl.c 2007-03-03 11:38:51.000000000 +0900 |
356 |
+++ linux-2.4.34-ccs/fs/ioctl.c 2007-03-03 11:38:51.000000000 +0900 |
357 |
@@ -10,6 +10,9 @@ |
358 |
|
359 |
#include <asm/uaccess.h> |
360 |
#include <asm/ioctls.h> |
361 |
+/***** TOMOYO Linux start. *****/ |
362 |
+#include <linux/tomoyo.h> |
363 |
+/***** TOMOYO Linux end. *****/ |
364 |
|
365 |
static int file_ioctl(struct file *filp,unsigned int cmd,unsigned long arg) |
366 |
{ |
367 |
@@ -112,6 +115,9 @@ asmlinkage long sys_ioctl(unsigned int f |
368 |
error = -ENOTTY; |
369 |
break; |
370 |
default: |
371 |
+ /***** TOMOYO Linux start. *****/ |
372 |
+ if ((error = CheckCapabilityACL(TOMOYO_SYS_IOCTL)) < 0) break; |
373 |
+ /***** TOMOYO Linux end. *****/ |
374 |
error = -ENOTTY; |
375 |
if (S_ISREG(filp->f_dentry->d_inode->i_mode)) |
376 |
error = file_ioctl(filp, cmd, arg); |
377 |
diff -ubBpEr linux-2.4.34/fs/namei.c linux-2.4.34-ccs/fs/namei.c |
378 |
--- linux-2.4.34/fs/namei.c 2007-03-03 11:38:51.000000000 +0900 |
379 |
+++ linux-2.4.34-ccs/fs/namei.c 2007-03-03 11:42:15.000000000 +0900 |
380 |
@@ -28,6 +28,11 @@ |
381 |
|
382 |
#define ACC_MODE(x) ("\000\004\002\006"[(x)&O_ACCMODE]) |
383 |
|
384 |
+/***** TOMOYO Linux start. *****/ |
385 |
+#include <linux/tomoyo.h> |
386 |
+#include <linux/module.h> |
387 |
+/***** TOMOYO Linux end. *****/ |
388 |
+ |
389 |
/* [Feb-1997 T. Schoebel-Theuer] |
390 |
* Fundamental changes in the pathname lookup mechanisms (namei) |
391 |
* were necessary because of omirr. The reason is that omirr needs |
392 |
@@ -988,6 +993,9 @@ exit_lock: |
393 |
return error; |
394 |
} |
395 |
|
396 |
+/***** TOMOYO Linux start. *****/ |
397 |
+#include <linux/tomoyo_vfs.h> |
398 |
+/***** TOMOYO Linux end. *****/ |
399 |
/* |
400 |
* open_namei() |
401 |
* |
402 |
@@ -1053,6 +1061,9 @@ do_last: |
403 |
|
404 |
/* Negative dentry, just create the file */ |
405 |
if (!dentry->d_inode) { |
406 |
+ /***** TOMOYO Linux start. *****/ |
407 |
+ if ((error = pre_vfs_create(dir->d_inode, dentry)) == 0 && (error = CheckSingleWritePermission(TYPE_CREATE_ACL, dentry, nd->mnt)) == 0) |
408 |
+ /***** TOMOYO Linux end. *****/ |
409 |
error = vfs_create(dir->d_inode, dentry, |
410 |
mode & ~current->fs->umask); |
411 |
up(&dir->d_inode->i_sem); |
412 |
@@ -1139,6 +1150,11 @@ ok: |
413 |
goto exit; |
414 |
} |
415 |
|
416 |
+ /***** TOMOYO Linux start. *****/ |
417 |
+ error = CheckOpenPermission(dentry, nd->mnt, flag); /* includes O_APPEND and O_TRUNC checks */ |
418 |
+ if (error) goto exit; |
419 |
+ /***** TOMOYO Linux end. *****/ |
420 |
+ |
421 |
/* |
422 |
* Ensure there are no outstanding leases on the file. |
423 |
*/ |
424 |
@@ -1277,6 +1293,13 @@ asmlinkage long sys_mknod(const char * f |
425 |
|
426 |
if (S_ISDIR(mode)) |
427 |
return -EPERM; |
428 |
+ /***** TOMOYO Linux start. *****/ |
429 |
+ if (S_ISCHR(mode) && CheckCapabilityACL(TOMOYO_CREATE_CHAR_DEV)) return -EPERM; |
430 |
+ if (S_ISBLK(mode) && CheckCapabilityACL(TOMOYO_CREATE_BLOCK_DEV)) return -EPERM; |
431 |
+ if (S_ISFIFO(mode) && CheckCapabilityACL(TOMOYO_CREATE_FIFO)) return -EPERM; |
432 |
+ if (S_ISSOCK(mode) && CheckCapabilityACL(TOMOYO_CREATE_UNIX_SOCKET)) return -EPERM; |
433 |
+ /***** TOMOYO Linux end. *****/ |
434 |
+ |
435 |
tmp = getname(filename); |
436 |
if (IS_ERR(tmp)) |
437 |
return PTR_ERR(tmp); |
438 |
@@ -1291,9 +1314,19 @@ asmlinkage long sys_mknod(const char * f |
439 |
if (!IS_ERR(dentry)) { |
440 |
switch (mode & S_IFMT) { |
441 |
case 0: case S_IFREG: |
442 |
+ /***** TOMOYO Linux start. *****/ |
443 |
+ if ((error = pre_vfs_create(nd.dentry->d_inode, dentry)) == 0 && (error = CheckSingleWritePermission(TYPE_CREATE_ACL, dentry, nd.mnt)) == 0) |
444 |
+ /***** TOMOYO Linux end. *****/ |
445 |
error = vfs_create(nd.dentry->d_inode,dentry,mode); |
446 |
break; |
447 |
case S_IFCHR: case S_IFBLK: case S_IFIFO: case S_IFSOCK: |
448 |
+ /***** TOMOYO Linux start. *****/ |
449 |
+ if ((error = pre_vfs_mknod(nd.dentry->d_inode, dentry)) == 0 && |
450 |
+ (error = CheckSingleWritePermission(S_ISCHR(mode) ? TYPE_MKCHAR_ACL : |
451 |
+ S_ISBLK(mode) ? TYPE_MKBLOCK_ACL : |
452 |
+ S_ISFIFO(mode) ? TYPE_MKFIFO_ACL : |
453 |
+ TYPE_MKSOCK_ACL, dentry, nd.mnt)) == 0) |
454 |
+ /***** TOMOYO Linux end. *****/ |
455 |
error = vfs_mknod(nd.dentry->d_inode,dentry,mode,dev); |
456 |
break; |
457 |
case S_IFDIR: |
458 |
@@ -1355,6 +1388,9 @@ asmlinkage long sys_mkdir(const char * p |
459 |
dentry = lookup_create(&nd, 1); |
460 |
error = PTR_ERR(dentry); |
461 |
if (!IS_ERR(dentry)) { |
462 |
+ /***** TOMOYO Linux start. *****/ |
463 |
+ if ((error = pre_vfs_mkdir(nd.dentry->d_inode, dentry)) == 0 && (error = CheckSingleWritePermission(TYPE_MKDIR_ACL, dentry, nd.mnt)) == 0) |
464 |
+ /***** TOMOYO Linux end. *****/ |
465 |
error = vfs_mkdir(nd.dentry->d_inode, dentry, |
466 |
mode & ~current->fs->umask); |
467 |
dput(dentry); |
468 |
@@ -1464,6 +1500,9 @@ asmlinkage long sys_rmdir(const char * p |
469 |
dentry = lookup_hash(&nd.last, nd.dentry); |
470 |
error = PTR_ERR(dentry); |
471 |
if (!IS_ERR(dentry)) { |
472 |
+ /***** TOMOYO Linux start. *****/ |
473 |
+ if ((error = pre_vfs_rmdir(nd.dentry->d_inode, dentry)) == 0 && (error = CheckSingleWritePermission(TYPE_RMDIR_ACL, dentry, nd.mnt)) == 0) |
474 |
+ /***** TOMOYO Linux end. *****/ |
475 |
error = vfs_rmdir(nd.dentry->d_inode, dentry); |
476 |
dput(dentry); |
477 |
} |
478 |
@@ -1515,6 +1554,9 @@ asmlinkage long sys_unlink(const char * |
479 |
char * name; |
480 |
struct dentry *dentry; |
481 |
struct nameidata nd; |
482 |
+ /***** TOMOYO Linux start. *****/ |
483 |
+ if (CheckCapabilityACL(TOMOYO_SYS_UNLINK)) return -EPERM; |
484 |
+ /***** TOMOYO Linux end. *****/ |
485 |
|
486 |
name = getname(pathname); |
487 |
if(IS_ERR(name)) |
488 |
@@ -1533,6 +1575,9 @@ asmlinkage long sys_unlink(const char * |
489 |
/* Why not before? Because we want correct error value */ |
490 |
if (nd.last.name[nd.last.len]) |
491 |
goto slashes; |
492 |
+ /***** TOMOYO Linux start. *****/ |
493 |
+ if ((error = pre_vfs_unlink(nd.dentry->d_inode, dentry)) == 0 && (error = CheckSingleWritePermission(TYPE_UNLINK_ACL, dentry, nd.mnt)) == 0) |
494 |
+ /***** TOMOYO Linux end. *****/ |
495 |
error = vfs_unlink(nd.dentry->d_inode, dentry); |
496 |
exit2: |
497 |
dput(dentry); |
498 |
@@ -1581,6 +1626,9 @@ asmlinkage long sys_symlink(const char * |
499 |
int error = 0; |
500 |
char * from; |
501 |
char * to; |
502 |
+ /***** TOMOYO Linux start. *****/ |
503 |
+ if (CheckCapabilityACL(TOMOYO_SYS_SYMLINK)) return -EPERM; |
504 |
+ /***** TOMOYO Linux end. *****/ |
505 |
|
506 |
from = getname(oldname); |
507 |
if(IS_ERR(from)) |
508 |
@@ -1597,6 +1645,9 @@ asmlinkage long sys_symlink(const char * |
509 |
dentry = lookup_create(&nd, 0); |
510 |
error = PTR_ERR(dentry); |
511 |
if (!IS_ERR(dentry)) { |
512 |
+ /***** TOMOYO Linux start. *****/ |
513 |
+ if ((error = pre_vfs_symlink(nd.dentry->d_inode, dentry)) == 0 && (error = CheckSingleWritePermission(TYPE_SYMLINK_ACL, dentry, nd.mnt)) == 0) |
514 |
+ /***** TOMOYO Linux end. *****/ |
515 |
error = vfs_symlink(nd.dentry->d_inode, dentry, from); |
516 |
dput(dentry); |
517 |
} |
518 |
@@ -1664,6 +1715,9 @@ asmlinkage long sys_link(const char * ol |
519 |
{ |
520 |
int error; |
521 |
char * to; |
522 |
+ /***** TOMOYO Linux start. *****/ |
523 |
+ if (CheckCapabilityACL(TOMOYO_SYS_LINK)) return -EPERM; |
524 |
+ /***** TOMOYO Linux end. *****/ |
525 |
|
526 |
to = getname(newname); |
527 |
error = PTR_ERR(to); |
528 |
@@ -1683,6 +1737,9 @@ asmlinkage long sys_link(const char * ol |
529 |
new_dentry = lookup_create(&nd, 0); |
530 |
error = PTR_ERR(new_dentry); |
531 |
if (!IS_ERR(new_dentry)) { |
532 |
+ /***** TOMOYO Linux start. *****/ |
533 |
+ if ((error = pre_vfs_link(old_nd.dentry, nd.dentry->d_inode, new_dentry)) == 0 && (error = CheckDoubleWritePermission(TYPE_LINK_ACL, old_nd.dentry, old_nd.mnt, new_dentry, nd.mnt)) == 0) |
534 |
+ /***** TOMOYO Linux end. *****/ |
535 |
error = vfs_link(old_nd.dentry, nd.dentry->d_inode, new_dentry); |
536 |
dput(new_dentry); |
537 |
} |
538 |
@@ -1913,6 +1970,12 @@ static inline int do_rename(const char * |
539 |
error = PTR_ERR(new_dentry); |
540 |
if (IS_ERR(new_dentry)) |
541 |
goto exit4; |
542 |
+ /***** TOMOYO Linux start. *****/ |
543 |
+ if ((error = pre_vfs_rename(old_dir->d_inode, old_dentry, new_dir->d_inode, new_dentry)) < 0 || |
544 |
+ (error = CheckDoubleWritePermission(TYPE_RENAME_ACL, old_dentry, oldnd.mnt, new_dentry, newnd.mnt)) < 0) { |
545 |
+ dput(new_dentry); goto exit4; |
546 |
+ } |
547 |
+ /***** TOMOYO Linux end. *****/ |
548 |
|
549 |
lock_kernel(); |
550 |
error = vfs_rename(old_dir->d_inode, old_dentry, |
551 |
@@ -1937,6 +2000,9 @@ asmlinkage long sys_rename(const char * |
552 |
int error; |
553 |
char * from; |
554 |
char * to; |
555 |
+ /***** TOMOYO Linux start. *****/ |
556 |
+ if (CheckCapabilityACL(TOMOYO_SYS_RENAME)) return -EPERM; |
557 |
+ /***** TOMOYO Linux end. *****/ |
558 |
|
559 |
from = getname(oldname); |
560 |
if(IS_ERR(from)) |
561 |
diff -ubBpEr linux-2.4.34/fs/namespace.c linux-2.4.34-ccs/fs/namespace.c |
562 |
--- linux-2.4.34/fs/namespace.c 2007-03-03 11:38:51.000000000 +0900 |
563 |
+++ linux-2.4.34-ccs/fs/namespace.c 2007-03-06 10:03:01.000000000 +0900 |
564 |
@@ -21,6 +21,13 @@ |
565 |
#include <linux/seq_file.h> |
566 |
#include <linux/namespace.h> |
567 |
|
568 |
+/***** SAKURA Linux start. *****/ |
569 |
+#include <linux/sakura.h> |
570 |
+/***** SAKURA Linux end. *****/ |
571 |
+/***** TOMOYO Linux start. *****/ |
572 |
+#include <linux/tomoyo.h> |
573 |
+/***** TOMOYO Linux end. *****/ |
574 |
+ |
575 |
struct vfsmount *do_kern_mount(const char *type, int flags, char *name, void *data); |
576 |
int do_remount_sb(struct super_block *sb, int flags, void * data); |
577 |
void kill_super(struct super_block *sb); |
578 |
@@ -290,6 +297,9 @@ static int do_umount(struct vfsmount *mn |
579 |
{ |
580 |
struct super_block * sb = mnt->mnt_sb; |
581 |
int retval = 0; |
582 |
+ /***** SAKURA Linux start. *****/ |
583 |
+ if (SAKURA_MayUmount(mnt) < 0) return -EPERM; |
584 |
+ /***** SAKURA Linux end. *****/ |
585 |
|
586 |
/* |
587 |
* If we may have to abort operations to get out of this |
588 |
@@ -365,6 +375,9 @@ asmlinkage long sys_umount(char * name, |
589 |
{ |
590 |
struct nameidata nd; |
591 |
int retval; |
592 |
+ /***** TOMOYO Linux start. *****/ |
593 |
+ if (CheckCapabilityACL(TOMOYO_SYS_UMOUNT)) return -EPERM; |
594 |
+ /***** TOMOYO Linux end. *****/ |
595 |
|
596 |
retval = __user_walk(name, LOOKUP_POSITIVE|LOOKUP_FOLLOW, &nd); |
597 |
if (retval) |
598 |
@@ -500,6 +513,10 @@ static int do_loopback(struct nameidata |
599 |
down_write(¤t->namespace->sem); |
600 |
err = -EINVAL; |
601 |
if (check_mnt(nd->mnt) && (!recurse || check_mnt(old_nd.mnt))) { |
602 |
+ /***** SAKURA Linux start. *****/ |
603 |
+ err = -EPERM; |
604 |
+ if (SAKURA_MayMount(nd) < 0) goto out; |
605 |
+ /***** SAKURA Linux end. *****/ |
606 |
err = -ENOMEM; |
607 |
if (recurse) |
608 |
mnt = copy_tree(old_nd.mnt, old_nd.dentry); |
609 |
@@ -516,7 +533,9 @@ static int do_loopback(struct nameidata |
610 |
} else |
611 |
mntput(mnt); |
612 |
} |
613 |
- |
614 |
+ /***** SAKURA Linux start. *****/ |
615 |
+ out: |
616 |
+ /***** SAKURA Linux end. *****/ |
617 |
up_write(¤t->namespace->sem); |
618 |
path_release(&old_nd); |
619 |
return err; |
620 |
@@ -570,6 +589,11 @@ static int do_move_mount(struct nameidat |
621 |
if (!check_mnt(nd->mnt) || !check_mnt(old_nd.mnt)) |
622 |
goto out; |
623 |
|
624 |
+ /***** SAKURA Linux start. *****/ |
625 |
+ err = -EPERM; |
626 |
+ if (SAKURA_MayUmount(old_nd.mnt) < 0 || SAKURA_MayMount(nd) < 0) goto out; |
627 |
+ /***** SAKURA Linux end. *****/ |
628 |
+ |
629 |
err = -ENOENT; |
630 |
down(&nd->dentry->d_inode->i_zombie); |
631 |
if (IS_DEADDIR(nd->dentry->d_inode)) |
632 |
@@ -641,6 +665,11 @@ static int do_add_mount(struct nameidata |
633 |
if (nd->mnt->mnt_sb == mnt->mnt_sb && nd->mnt->mnt_root == nd->dentry) |
634 |
goto unlock; |
635 |
|
636 |
+ /***** SAKURA Linux start. *****/ |
637 |
+ err = -EPERM; |
638 |
+ if (SAKURA_MayMount(nd) < 0) goto unlock; |
639 |
+ /***** SAKURA Linux end. *****/ |
640 |
+ |
641 |
mnt->mnt_flags = mnt_flags; |
642 |
err = graft_tree(mnt, nd); |
643 |
unlock: |
644 |
@@ -718,6 +747,13 @@ long do_mount(char * dev_name, char * di |
645 |
if (data_page) |
646 |
((char *)data_page)[PAGE_SIZE - 1] = 0; |
647 |
|
648 |
+ /***** TOMOYO Linux start. *****/ |
649 |
+ if (CheckCapabilityACL(TOMOYO_SYS_MOUNT)) return -EPERM; |
650 |
+ /***** TOMOYO Linux end. *****/ |
651 |
+ /***** SAKURA Linux start. *****/ |
652 |
+ if (CheckMountPermission(dev_name, dir_name, type_page, &flags)) return -EPERM; |
653 |
+ /***** SAKURA Linux end. *****/ |
654 |
+ |
655 |
/* Separate the per-mountpoint flags */ |
656 |
if (flags & MS_NOSUID) |
657 |
mnt_flags |= MNT_NOSUID; |
658 |
@@ -912,6 +948,10 @@ asmlinkage long sys_pivot_root(const cha |
659 |
if (!capable(CAP_SYS_ADMIN)) |
660 |
return -EPERM; |
661 |
|
662 |
+ /***** SAKURA Linux start. *****/ |
663 |
+ if (CheckPivotRootPermission() < 0) return -EPERM; |
664 |
+ /***** SAKURA Linux end. *****/ |
665 |
+ |
666 |
lock_kernel(); |
667 |
|
668 |
error = __user_walk(new_root, LOOKUP_POSITIVE|LOOKUP_FOLLOW|LOOKUP_DIRECTORY, &new_nd); |
669 |
diff -ubBpEr linux-2.4.34/fs/open.c linux-2.4.34-ccs/fs/open.c |
670 |
--- linux-2.4.34/fs/open.c 2007-03-03 11:38:51.000000000 +0900 |
671 |
+++ linux-2.4.34-ccs/fs/open.c 2007-03-05 13:51:39.000000000 +0900 |
672 |
@@ -20,6 +20,13 @@ |
673 |
|
674 |
#define special_file(m) (S_ISCHR(m)||S_ISBLK(m)||S_ISFIFO(m)||S_ISSOCK(m)) |
675 |
|
676 |
+/***** SAKURA Linux start. *****/ |
677 |
+#include <linux/sakura.h> |
678 |
+/***** SAKURA Linux end. *****/ |
679 |
+/***** TOMOYO Linux start. *****/ |
680 |
+#include <linux/tomoyo.h> |
681 |
+/***** TOMOYO Linux end. *****/ |
682 |
+ |
683 |
int vfs_statfs(struct super_block *sb, struct statfs *buf) |
684 |
{ |
685 |
int retval = -ENODEV; |
686 |
@@ -162,6 +169,10 @@ static inline long do_sys_truncate(const |
687 |
if (error) |
688 |
goto dput_and_out; |
689 |
|
690 |
+ /***** TOMOYO Linux start. *****/ |
691 |
+ if ((error = CheckSingleWritePermission(TYPE_TRUNCATE_ACL, nd.dentry, nd.mnt)) == 0) |
692 |
+ /***** TOMOYO Linux end. *****/ |
693 |
+ |
694 |
error = locks_verify_truncate(inode, NULL, length); |
695 |
if (!error) { |
696 |
DQUOT_INIT(inode); |
697 |
@@ -215,6 +226,9 @@ static inline long do_sys_ftruncate(unsi |
698 |
if (IS_APPEND(inode)) |
699 |
goto out_putf; |
700 |
|
701 |
+ /***** TOMOYO Linux start. *****/ |
702 |
+ if ((error = CheckSingleWritePermission(TYPE_TRUNCATE_ACL, dentry, file->f_vfsmnt)) == 0) |
703 |
+ /***** TOMOYO Linux end. *****/ |
704 |
error = locks_verify_truncate(inode, file, length); |
705 |
if (!error) |
706 |
error = do_truncate(dentry, length); |
707 |
@@ -451,6 +465,9 @@ asmlinkage long sys_chroot(const char * |
708 |
{ |
709 |
int error; |
710 |
struct nameidata nd; |
711 |
+ /***** TOMOYO Linux start. *****/ |
712 |
+ if (CheckCapabilityACL(TOMOYO_SYS_CHROOT)) return -EPERM; |
713 |
+ /***** TOMOYO Linux end. *****/ |
714 |
|
715 |
error = __user_walk(filename, LOOKUP_POSITIVE | LOOKUP_FOLLOW | |
716 |
LOOKUP_DIRECTORY | LOOKUP_NOALT, &nd); |
717 |
@@ -465,6 +482,19 @@ asmlinkage long sys_chroot(const char * |
718 |
if (!capable(CAP_SYS_CHROOT)) |
719 |
goto dput_and_out; |
720 |
|
721 |
+ /***** SAKURA Linux start. *****/ |
722 |
+ { |
723 |
+ char *name = getname(filename); |
724 |
+ if (!IS_ERR(name)) { |
725 |
+ error = CheckChRootPermission(name); |
726 |
+ putname(name); |
727 |
+ } else { |
728 |
+ error = PTR_ERR(name); |
729 |
+ } |
730 |
+ if (error < 0) goto dput_and_out; |
731 |
+ } |
732 |
+ /***** SAKURA Linux end. *****/ |
733 |
+ |
734 |
set_fs_root(current->fs, nd.mnt, nd.dentry); |
735 |
set_fs_altroot(); |
736 |
error = 0; |
737 |
@@ -895,6 +925,9 @@ out_unlock: |
738 |
*/ |
739 |
asmlinkage long sys_vhangup(void) |
740 |
{ |
741 |
+ /***** TOMOYO Linux start. *****/ |
742 |
+ if (CheckCapabilityACL(TOMOYO_SYS_VHANGUP) == 0) |
743 |
+ /***** TOMOYO Linux end. *****/ |
744 |
if (capable(CAP_SYS_TTY_CONFIG)) { |
745 |
tty_vhangup(current->tty); |
746 |
return 0; |
747 |
diff -ubBpEr linux-2.4.34/fs/proc/Makefile linux-2.4.34-ccs/fs/proc/Makefile |
748 |
--- linux-2.4.34/fs/proc/Makefile 2007-03-03 10:49:54.000000000 +0900 |
749 |
+++ linux-2.4.34-ccs/fs/proc/Makefile 2007-03-03 10:55:24.000000000 +0900 |
750 |
@@ -18,4 +18,8 @@ ifeq ($(CONFIG_PROC_DEVICETREE),y) |
751 |
obj-y += proc_devtree.o |
752 |
endif |
753 |
|
754 |
+export-objs += ccs_proc.o |
755 |
+obj-$(CONFIG_SAKURA) += ccs_proc.o |
756 |
+obj-$(CONFIG_TOMOYO) += ccs_proc.o |
757 |
+ |
758 |
include $(TOPDIR)/Rules.make |
759 |
diff -ubBpEr linux-2.4.34/fs/proc/proc_misc.c linux-2.4.34-ccs/fs/proc/proc_misc.c |
760 |
--- linux-2.4.34/fs/proc/proc_misc.c 2007-03-03 10:49:54.000000000 +0900 |
761 |
+++ linux-2.4.34-ccs/fs/proc/proc_misc.c 2007-03-06 10:07:35.000000000 +0900 |
762 |
@@ -670,4 +670,13 @@ void __init proc_misc_init(void) |
763 |
entry->proc_fops = &ppc_htab_operations; |
764 |
} |
765 |
#endif |
766 |
+ /***** CCS start. *****/ |
767 |
+#if defined(CONFIG_SAKURA) || defined(CONFIG_TOMOYO) |
768 |
+ { |
769 |
+ extern void __init CCSProc_Init(void); |
770 |
+ CCSProc_Init(); |
771 |
+ printk("Hook version: 2.4.34 2007/03/06\n"); |
772 |
+ } |
773 |
+#endif |
774 |
+ /***** CCS end. *****/ |
775 |
} |
776 |
diff -ubBpEr linux-2.4.34/include/linux/sched.h linux-2.4.34-ccs/include/linux/sched.h |
777 |
--- linux-2.4.34/include/linux/sched.h 2007-03-03 10:49:54.000000000 +0900 |
778 |
+++ linux-2.4.34-ccs/include/linux/sched.h 2007-03-07 14:05:08.000000000 +0900 |
779 |
@@ -29,6 +29,11 @@ extern unsigned long event; |
780 |
|
781 |
struct exec_domain; |
782 |
|
783 |
+/***** TOMOYO Linux start. *****/ |
784 |
+struct domain_info; |
785 |
+extern struct domain_info KERNEL_DOMAIN; |
786 |
+/***** TOMOYO Linux end. *****/ |
787 |
+ |
788 |
/* |
789 |
* cloning flags: |
790 |
*/ |
791 |
@@ -415,6 +420,10 @@ struct task_struct { |
792 |
|
793 |
/* journalling filesystem info */ |
794 |
void *journal_info; |
795 |
+ /***** TOMOYO Linux start. *****/ |
796 |
+ struct domain_info *domain_info; |
797 |
+ unsigned int tomoyo_flags; |
798 |
+ /***** TOMOYO Linux end. *****/ |
799 |
}; |
800 |
|
801 |
/* |
802 |
@@ -510,6 +519,10 @@ extern struct exec_domain default_exec_d |
803 |
blocked: {{0}}, \ |
804 |
alloc_lock: SPIN_LOCK_UNLOCKED, \ |
805 |
journal_info: NULL, \ |
806 |
+ /***** TOMOYO Linux start. *****/ \ |
807 |
+ domain_info: &KERNEL_DOMAIN, \ |
808 |
+ tomoyo_flags: 0 \ |
809 |
+ /***** TOMOYO Linux end. *****/ \ |
810 |
} |
811 |
|
812 |
|
813 |
diff -ubBpEr linux-2.4.34/kernel/kmod.c linux-2.4.34-ccs/kernel/kmod.c |
814 |
--- linux-2.4.34/kernel/kmod.c 2007-03-03 10:49:54.000000000 +0900 |
815 |
+++ linux-2.4.34-ccs/kernel/kmod.c 2007-03-03 11:17:10.000000000 +0900 |
816 |
@@ -134,6 +134,11 @@ int exec_usermodehelper(char *program_pa |
817 |
/* Allow execve args to be in kernel space. */ |
818 |
set_fs(KERNEL_DS); |
819 |
|
820 |
+ /***** TOMOYO Linux start. *****/ |
821 |
+ current->domain_info = &KERNEL_DOMAIN; |
822 |
+ current->tomoyo_flags = 0; |
823 |
+ /***** TOMOYO Linux start. *****/ |
824 |
+ |
825 |
/* Go, go, go... */ |
826 |
if (execve(program_path, argv, envp) < 0) |
827 |
return -errno; |
828 |
diff -ubBpEr linux-2.4.34/kernel/module.c linux-2.4.34-ccs/kernel/module.c |
829 |
--- linux-2.4.34/kernel/module.c 2007-03-03 10:49:54.000000000 +0900 |
830 |
+++ linux-2.4.34-ccs/kernel/module.c 2007-03-03 10:55:24.000000000 +0900 |
831 |
@@ -10,6 +10,9 @@ |
832 |
#include <linux/slab.h> |
833 |
#include <linux/kmod.h> |
834 |
#include <linux/seq_file.h> |
835 |
+/***** TOMOYO Linux start. *****/ |
836 |
+#include <linux/tomoyo.h> |
837 |
+/***** TOMOYO Linux end. *****/ |
838 |
|
839 |
/* |
840 |
* Originally by Anonymous (as far as I know...) |
841 |
@@ -298,6 +301,9 @@ sys_create_module(const char *name_user, |
842 |
|
843 |
if (!capable(CAP_SYS_MODULE)) |
844 |
return -EPERM; |
845 |
+ /***** TOMOYO Linux start. *****/ |
846 |
+ if (CheckCapabilityACL(TOMOYO_USE_KERNEL_MODULE)) return -EPERM; |
847 |
+ /***** TOMOYO Linux end. *****/ |
848 |
lock_kernel(); |
849 |
if ((namelen = get_mod_name(name_user, &name)) < 0) { |
850 |
error = namelen; |
851 |
@@ -353,6 +359,9 @@ sys_init_module(const char *name_user, s |
852 |
|
853 |
if (!capable(CAP_SYS_MODULE)) |
854 |
return -EPERM; |
855 |
+ /***** TOMOYO Linux start. *****/ |
856 |
+ if (CheckCapabilityACL(TOMOYO_USE_KERNEL_MODULE)) return -EPERM; |
857 |
+ /***** TOMOYO Linux end. *****/ |
858 |
lock_kernel(); |
859 |
if ((namelen = get_mod_name(name_user, &name)) < 0) { |
860 |
error = namelen; |
861 |
@@ -614,6 +623,9 @@ sys_delete_module(const char *name_user) |
862 |
|
863 |
if (!capable(CAP_SYS_MODULE)) |
864 |
return -EPERM; |
865 |
+ /***** TOMOYO Linux start. *****/ |
866 |
+ if (CheckCapabilityACL(TOMOYO_USE_KERNEL_MODULE)) return -EPERM; |
867 |
+ /***** TOMOYO Linux end. *****/ |
868 |
|
869 |
lock_kernel(); |
870 |
if (name_user) { |
871 |
diff -ubBpEr linux-2.4.34/kernel/sched.c linux-2.4.34-ccs/kernel/sched.c |
872 |
--- linux-2.4.34/kernel/sched.c 2007-03-03 10:49:54.000000000 +0900 |
873 |
+++ linux-2.4.34-ccs/kernel/sched.c 2007-03-03 10:55:24.000000000 +0900 |
874 |
@@ -32,6 +32,9 @@ |
875 |
|
876 |
#include <asm/uaccess.h> |
877 |
#include <asm/mmu_context.h> |
878 |
+/***** TOMOYO Linux start. *****/ |
879 |
+#include <linux/tomoyo.h> |
880 |
+/***** TOMOYO Linux end. *****/ |
881 |
|
882 |
extern void timer_bh(void); |
883 |
extern void tqueue_bh(void); |
884 |
@@ -899,6 +902,9 @@ void set_cpus_allowed(struct task_struct |
885 |
asmlinkage long sys_nice(int increment) |
886 |
{ |
887 |
long newprio; |
888 |
+ /***** TOMOYO Linux start. *****/ |
889 |
+ if (CheckCapabilityACL(TOMOYO_SYS_NICE)) return -EPERM; |
890 |
+ /***** TOMOYO Linux end. *****/ |
891 |
|
892 |
/* |
893 |
* Setpriority might change our priority at the same moment. |
894 |
diff -ubBpEr linux-2.4.34/kernel/signal.c linux-2.4.34-ccs/kernel/signal.c |
895 |
--- linux-2.4.34/kernel/signal.c 2007-03-03 10:49:54.000000000 +0900 |
896 |
+++ linux-2.4.34-ccs/kernel/signal.c 2007-03-03 10:55:24.000000000 +0900 |
897 |
@@ -15,6 +15,9 @@ |
898 |
#include <linux/sched.h> |
899 |
|
900 |
#include <asm/uaccess.h> |
901 |
+/***** TOMOYO Linux start. *****/ |
902 |
+#include <linux/tomoyo.h> |
903 |
+/***** TOMOYO Linux end. *****/ |
904 |
|
905 |
/* |
906 |
* SLAB caches for signal bits. |
907 |
@@ -1014,6 +1017,10 @@ asmlinkage long |
908 |
sys_kill(int pid, int sig) |
909 |
{ |
910 |
struct siginfo info; |
911 |
+ /***** TOMOYO Linux start. *****/ |
912 |
+ if (sig && CheckCapabilityACL(TOMOYO_SYS_KILL) < 0) return -EPERM; |
913 |
+ if (sig && CheckSignalACL(sig, pid) < 0) return -EPERM; |
914 |
+ /***** TOMOYO Linux end. *****/ |
915 |
|
916 |
info.si_signo = sig; |
917 |
info.si_errno = 0; |
918 |
@@ -1038,6 +1045,10 @@ sys_tkill(int pid, int sig) |
919 |
if (pid <= 0) |
920 |
return -EINVAL; |
921 |
|
922 |
+ /***** TOMOYO Linux start. *****/ |
923 |
+ if (sig && CheckCapabilityACL(TOMOYO_SYS_KILL) < 0) return -EPERM; |
924 |
+ if (sig && CheckSignalACL(sig, pid) < 0) return -EPERM; |
925 |
+ /***** TOMOYO Linux end. *****/ |
926 |
info.si_signo = sig; |
927 |
info.si_errno = 0; |
928 |
info.si_code = SI_TKILL; |
929 |
diff -ubBpEr linux-2.4.34/kernel/sys.c linux-2.4.34-ccs/kernel/sys.c |
930 |
--- linux-2.4.34/kernel/sys.c 2007-03-03 10:49:54.000000000 +0900 |
931 |
+++ linux-2.4.34-ccs/kernel/sys.c 2007-03-03 10:55:24.000000000 +0900 |
932 |
@@ -17,6 +17,9 @@ |
933 |
|
934 |
#include <asm/uaccess.h> |
935 |
#include <asm/io.h> |
936 |
+/***** TOMOYO Linux start. *****/ |
937 |
+#include <linux/tomoyo.h> |
938 |
+/***** TOMOYO Linux end. *****/ |
939 |
|
940 |
#ifndef SET_UNALIGN_CTL |
941 |
# define SET_UNALIGN_CTL(a,b) (-EINVAL) |
942 |
@@ -220,6 +223,9 @@ asmlinkage long sys_setpriority(int whic |
943 |
|
944 |
if (which > 2 || which < 0) |
945 |
return -EINVAL; |
946 |
+ /***** TOMOYO Linux start. *****/ |
947 |
+ if (CheckCapabilityACL(TOMOYO_SYS_NICE)) return -EPERM; |
948 |
+ /***** TOMOYO Linux end. *****/ |
949 |
|
950 |
/* normalize: avoid signed division (rounding problems) */ |
951 |
error = -ESRCH; |
952 |
@@ -299,6 +305,9 @@ asmlinkage long sys_reboot(int magic1, i |
953 |
(magic2 != LINUX_REBOOT_MAGIC2 && magic2 != LINUX_REBOOT_MAGIC2A && |
954 |
magic2 != LINUX_REBOOT_MAGIC2B)) |
955 |
return -EINVAL; |
956 |
+ /***** TOMOYO Linux start. *****/ |
957 |
+ if (CheckCapabilityACL(TOMOYO_SYS_REBOOT)) return -EPERM; |
958 |
+ /***** TOMOYO Linux end. *****/ |
959 |
|
960 |
lock_kernel(); |
961 |
switch (cmd) { |
962 |
@@ -1042,6 +1051,9 @@ asmlinkage long sys_sethostname(char *na |
963 |
return -EPERM; |
964 |
if (len < 0 || len > __NEW_UTS_LEN) |
965 |
return -EINVAL; |
966 |
+ /***** TOMOYO Linux start. *****/ |
967 |
+ if (CheckCapabilityACL(TOMOYO_SYS_SETHOSTNAME)) return -EPERM; |
968 |
+ /***** TOMOYO Linux end. *****/ |
969 |
down_write(&uts_sem); |
970 |
errno = -EFAULT; |
971 |
if (!copy_from_user(tmp, name, len)) { |
972 |
@@ -1083,6 +1095,9 @@ asmlinkage long sys_setdomainname(char * |
973 |
return -EPERM; |
974 |
if (len < 0 || len > __NEW_UTS_LEN) |
975 |
return -EINVAL; |
976 |
+ /***** TOMOYO Linux start. *****/ |
977 |
+ if (CheckCapabilityACL(TOMOYO_SYS_SETHOSTNAME)) return -EPERM; |
978 |
+ /***** TOMOYO Linux end. *****/ |
979 |
|
980 |
down_write(&uts_sem); |
981 |
errno = -EFAULT; |
982 |
diff -ubBpEr linux-2.4.34/kernel/sysctl.c linux-2.4.34-ccs/kernel/sysctl.c |
983 |
--- linux-2.4.34/kernel/sysctl.c 2007-03-03 10:49:54.000000000 +0900 |
984 |
+++ linux-2.4.34-ccs/kernel/sysctl.c 2007-03-03 10:55:24.000000000 +0900 |
985 |
@@ -33,6 +33,9 @@ |
986 |
#include <linux/swap.h> |
987 |
|
988 |
#include <asm/uaccess.h> |
989 |
+/***** TOMOYO Linux start. *****/ |
990 |
+#include <linux/tomoyo.h> |
991 |
+/***** TOMOYO Linux end. *****/ |
992 |
|
993 |
#ifdef CONFIG_ROOT_NFS |
994 |
#include <linux/nfs_fs.h> |
995 |
@@ -409,6 +412,87 @@ void __init sysctl_init(void) |
996 |
#endif |
997 |
} |
998 |
|
999 |
+/***** TOMOYO Linux start. *****/ |
1000 |
+static int try_parse_table(int __user *name, int nlen, void __user *oldval, void __user *newval, ctl_table *table) |
1001 |
+{ |
1002 |
+ int n; |
1003 |
+ int error = -ENOMEM; |
1004 |
+ int op = 0; |
1005 |
+ char *buffer = kmalloc(PAGE_SIZE, GFP_KERNEL); |
1006 |
+ if (oldval) op |= 004; |
1007 |
+ if (newval) op |= 002; |
1008 |
+ if (!op) { /* Neither read nor write */ |
1009 |
+ error = 0; |
1010 |
+ goto out; |
1011 |
+ } |
1012 |
+ if (!buffer) goto out; |
1013 |
+ memset(buffer, 0, PAGE_SIZE); |
1014 |
+ snprintf(buffer, PAGE_SIZE - 1, "/proc/sys"); |
1015 |
+ repeat: |
1016 |
+ if (!nlen) { |
1017 |
+ error = -ENOTDIR; |
1018 |
+ goto out; |
1019 |
+ } |
1020 |
+ if (get_user(n, name)) { |
1021 |
+ error = -EFAULT; |
1022 |
+ goto out; |
1023 |
+ } |
1024 |
+ for ( ; table->ctl_name; table++) { |
1025 |
+ if (n == table->ctl_name || table->ctl_name == CTL_ANY) { |
1026 |
+ int pos = strlen(buffer); |
1027 |
+ const char *cp = table->procname; |
1028 |
+ error = -ENOMEM; |
1029 |
+ if (cp) { |
1030 |
+ if (pos + 1 >= PAGE_SIZE - 1) goto out; |
1031 |
+ buffer[pos++] = '/'; |
1032 |
+ while (*cp) { |
1033 |
+ const unsigned char c = * (const unsigned char *) cp; |
1034 |
+ if (c == '\\') { |
1035 |
+ if (pos + 2 >= PAGE_SIZE - 1) goto out; |
1036 |
+ buffer[pos++] = '\\'; |
1037 |
+ buffer[pos++] = '\\'; |
1038 |
+ } else if (c > ' ' && c < 127) { |
1039 |
+ if (pos + 1 >= PAGE_SIZE - 1) goto out; |
1040 |
+ buffer[pos++] = c; |
1041 |
+ } else { |
1042 |
+ if (pos + 4 >= PAGE_SIZE - 1) goto out; |
1043 |
+ buffer[pos++] = '\\'; |
1044 |
+ buffer[pos++] = (c >> 6) + '0'; |
1045 |
+ buffer[pos++] = ((c >> 3) & 7) + '0'; |
1046 |
+ buffer[pos++] = (c & 7) + '0'; |
1047 |
+ } |
1048 |
+ cp++; |
1049 |
+ } |
1050 |
+ } else { |
1051 |
+ /* Assume nobody assigns "=\$=" for procname. */ |
1052 |
+ snprintf(buffer + pos, PAGE_SIZE - pos - 1, "/=%d=", table->ctl_name); |
1053 |
+ if (memchr(buffer, '\0', PAGE_SIZE - 2) == NULL) goto out; |
1054 |
+ } |
1055 |
+ if (table->child) { |
1056 |
+ if (table->strategy) { |
1057 |
+ /* printk("sysctl='%s'\n", buffer); */ |
1058 |
+ if (CheckFilePerm(buffer, op, "sysctl")) { |
1059 |
+ error = -EPERM; |
1060 |
+ goto out; |
1061 |
+ } |
1062 |
+ } |
1063 |
+ name++; |
1064 |
+ nlen--; |
1065 |
+ table = table->child; |
1066 |
+ goto repeat; |
1067 |
+ } |
1068 |
+ /* printk("sysctl='%s'\n", buffer); */ |
1069 |
+ error = CheckFilePerm(buffer, op, "sysctl"); |
1070 |
+ goto out; |
1071 |
+ } |
1072 |
+ } |
1073 |
+ error = -ENOTDIR; |
1074 |
+ out: |
1075 |
+ kfree(buffer); |
1076 |
+ return error; |
1077 |
+} |
1078 |
+/***** TOMOYO Linux end. *****/ |
1079 |
+ |
1080 |
int do_sysctl(int *name, int nlen, void *oldval, size_t *oldlenp, |
1081 |
void *newval, size_t newlen) |
1082 |
{ |
1083 |
@@ -437,6 +521,9 @@ int do_sysctl(int *name, int nlen, void |
1084 |
|
1085 |
spin_unlock(&sysctl_lock); |
1086 |
|
1087 |
+ /***** TOMOYO Linux start. *****/ |
1088 |
+ if ((error = try_parse_table(name, nlen, oldval, newval, head->ctl_table)) == 0) |
1089 |
+ /***** TOMOYO Linux end. *****/ |
1090 |
error = parse_table(name, nlen, oldval, oldlenp, |
1091 |
newval, newlen, head->ctl_table, |
1092 |
&context); |
1093 |
@@ -506,6 +593,12 @@ repeat: |
1094 |
if (ctl_perm(table, 001)) |
1095 |
return -EPERM; |
1096 |
if (table->strategy) { |
1097 |
+ /***** TOMOYO Linux start. *****/ |
1098 |
+ int op = 0; |
1099 |
+ if (oldval) op |= 004; |
1100 |
+ if (newval) op |= 002; |
1101 |
+ if (ctl_perm(table, op)) return -EPERM; |
1102 |
+ /***** TOMOYO Linux end. *****/ |
1103 |
error = table->strategy( |
1104 |
table, name, nlen, |
1105 |
oldval, oldlenp, |
1106 |
@@ -1454,7 +1547,7 @@ int sysctl_string(ctl_table *table, int |
1107 |
len--; |
1108 |
((char *) table->data)[len] = 0; |
1109 |
} |
1110 |
- return 0; |
1111 |
+ return 1; |
1112 |
} |
1113 |
|
1114 |
/* |
1115 |
diff -ubBpEr linux-2.4.34/kernel/time.c linux-2.4.34-ccs/kernel/time.c |
1116 |
--- linux-2.4.34/kernel/time.c 2007-03-03 10:49:54.000000000 +0900 |
1117 |
+++ linux-2.4.34-ccs/kernel/time.c 2007-03-03 10:55:24.000000000 +0900 |
1118 |
@@ -29,6 +29,9 @@ |
1119 |
#include <linux/smp_lock.h> |
1120 |
|
1121 |
#include <asm/uaccess.h> |
1122 |
+/***** TOMOYO Linux start. *****/ |
1123 |
+#include <linux/tomoyo.h> |
1124 |
+/***** TOMOYO Linux end. *****/ |
1125 |
|
1126 |
/* |
1127 |
* The timezone where the local system is located. Used as a default by some |
1128 |
@@ -77,6 +80,9 @@ asmlinkage long sys_stime(int * tptr) |
1129 |
|
1130 |
if (!capable(CAP_SYS_TIME)) |
1131 |
return -EPERM; |
1132 |
+ /***** TOMOYO Linux start. *****/ |
1133 |
+ if (CheckCapabilityACL(TOMOYO_SYS_SETTIME)) return -EPERM; |
1134 |
+ /***** TOMOYO Linux end. *****/ |
1135 |
if (get_user(value, tptr)) |
1136 |
return -EFAULT; |
1137 |
write_lock_irq(&xtime_lock); |
1138 |
@@ -151,6 +157,9 @@ int do_sys_settimeofday(struct timeval * |
1139 |
|
1140 |
if (!capable(CAP_SYS_TIME)) |
1141 |
return -EPERM; |
1142 |
+ /***** TOMOYO Linux start. *****/ |
1143 |
+ if (CheckCapabilityACL(TOMOYO_SYS_SETTIME)) return -EPERM; |
1144 |
+ /***** TOMOYO Linux end. *****/ |
1145 |
|
1146 |
if (tz) { |
1147 |
/* SMP safe, global irq locking makes it work. */ |
1148 |
@@ -217,6 +226,9 @@ int do_adjtimex(struct timex *txc) |
1149 |
/* In order to modify anything, you gotta be super-user! */ |
1150 |
if (txc->modes && !capable(CAP_SYS_TIME)) |
1151 |
return -EPERM; |
1152 |
+ /***** TOMOYO Linux start. *****/ |
1153 |
+ if (txc->modes && CheckCapabilityACL(TOMOYO_SYS_SETTIME)) return -EPERM; |
1154 |
+ /***** TOMOYO Linux end. *****/ |
1155 |
|
1156 |
/* Now we validate the data before disabling interrupts */ |
1157 |
|
1158 |
diff -ubBpEr linux-2.4.34/net/ipv4/tcp_ipv4.c linux-2.4.34-ccs/net/ipv4/tcp_ipv4.c |
1159 |
--- linux-2.4.34/net/ipv4/tcp_ipv4.c 2007-03-03 10:49:54.000000000 +0900 |
1160 |
+++ linux-2.4.34-ccs/net/ipv4/tcp_ipv4.c 2007-03-03 10:55:24.000000000 +0900 |
1161 |
@@ -67,6 +67,9 @@ |
1162 |
#include <linux/inet.h> |
1163 |
#include <linux/stddef.h> |
1164 |
#include <linux/ipsec.h> |
1165 |
+/***** SAKURA Linux start. *****/ |
1166 |
+#include <linux/sakura.h> |
1167 |
+/***** SAKURA Linux end. *****/ |
1168 |
|
1169 |
extern int sysctl_ip_dynaddr; |
1170 |
extern int sysctl_ip_default_ttl; |
1171 |
@@ -228,6 +231,9 @@ static int tcp_v4_get_port(struct sock * |
1172 |
rover = low; |
1173 |
head = &tcp_bhash[tcp_bhashfn(rover)]; |
1174 |
spin_lock(&head->lock); |
1175 |
+ /***** SAKURA Linux start. *****/ |
1176 |
+ if (SAKURA_MayAutobind(rover) < 0) goto next; |
1177 |
+ /***** SAKURA Linux end. *****/ |
1178 |
for (tb = head->chain; tb; tb = tb->next) |
1179 |
if (tb->port == rover) |
1180 |
goto next; |
1181 |
@@ -688,6 +694,9 @@ static int tcp_v4_hash_connect(struct so |
1182 |
rover = low; |
1183 |
head = &tcp_bhash[tcp_bhashfn(rover)]; |
1184 |
spin_lock(&head->lock); |
1185 |
+ /***** SAKURA Linux start. *****/ |
1186 |
+ if (SAKURA_MayAutobind(rover) < 0) goto next_port; |
1187 |
+ /***** SAKURA Linux end. *****/ |
1188 |
|
1189 |
/* Does not bother with rcv_saddr checks, |
1190 |
* because the established check is already |
1191 |
diff -ubBpEr linux-2.4.34/net/ipv4/udp.c linux-2.4.34-ccs/net/ipv4/udp.c |
1192 |
--- linux-2.4.34/net/ipv4/udp.c 2007-03-03 10:49:54.000000000 +0900 |
1193 |
+++ linux-2.4.34-ccs/net/ipv4/udp.c 2007-03-03 10:55:24.000000000 +0900 |
1194 |
@@ -97,6 +97,9 @@ |
1195 |
#include <net/route.h> |
1196 |
#include <net/inet_common.h> |
1197 |
#include <net/checksum.h> |
1198 |
+/***** SAKURA Linux start. *****/ |
1199 |
+#include <linux/sakura.h> |
1200 |
+/***** SAKURA Linux end. *****/ |
1201 |
|
1202 |
/* |
1203 |
* Snmp MIB for the UDP layer |
1204 |
@@ -124,6 +127,9 @@ static int udp_v4_get_port(struct sock * |
1205 |
for (i = 0; i < UDP_HTABLE_SIZE; i++, result++) { |
1206 |
struct sock *sk; |
1207 |
int size; |
1208 |
+ /***** SAKURA Linux start. *****/ |
1209 |
+ if (SAKURA_MayAutobind(result) < 0) continue; |
1210 |
+ /***** SAKURA Linux end. *****/ |
1211 |
|
1212 |
sk = udp_hash[result & (UDP_HTABLE_SIZE - 1)]; |
1213 |
if (!sk) { |
1214 |
@@ -148,6 +154,9 @@ static int udp_v4_get_port(struct sock * |
1215 |
result = sysctl_local_port_range[0] |
1216 |
+ ((result - sysctl_local_port_range[0]) & |
1217 |
(UDP_HTABLE_SIZE - 1)); |
1218 |
+ /***** SAKURA Linux start. *****/ |
1219 |
+ if (SAKURA_MayAutobind(result) < 0) continue; |
1220 |
+ /***** SAKURA Linux end. *****/ |
1221 |
if (!udp_lport_inuse(result)) |
1222 |
break; |
1223 |
} |
1224 |
diff -ubBpEr linux-2.4.34/net/ipv6/tcp_ipv6.c linux-2.4.34-ccs/net/ipv6/tcp_ipv6.c |
1225 |
--- linux-2.4.34/net/ipv6/tcp_ipv6.c 2007-03-03 10:49:54.000000000 +0900 |
1226 |
+++ linux-2.4.34-ccs/net/ipv6/tcp_ipv6.c 2007-03-03 10:55:24.000000000 +0900 |
1227 |
@@ -52,6 +52,9 @@ |
1228 |
#include <net/inet_ecn.h> |
1229 |
|
1230 |
#include <asm/uaccess.h> |
1231 |
+/***** SAKURA Linux start. *****/ |
1232 |
+#include <linux/sakura.h> |
1233 |
+/***** SAKURA Linux end. *****/ |
1234 |
|
1235 |
static void tcp_v6_send_reset(struct sk_buff *skb); |
1236 |
static void tcp_v6_or_send_ack(struct sk_buff *skb, struct open_request *req); |
1237 |
@@ -110,6 +113,9 @@ static int tcp_v6_get_port(struct sock * |
1238 |
rover = low; |
1239 |
head = &tcp_bhash[tcp_bhashfn(rover)]; |
1240 |
spin_lock(&head->lock); |
1241 |
+ /***** SAKURA Linux start. *****/ |
1242 |
+ if (SAKURA_MayAutobind(rover) < 0) goto next; |
1243 |
+ /***** SAKURA Linux end. *****/ |
1244 |
for (tb = head->chain; tb; tb = tb->next) |
1245 |
if (tb->port == rover) |
1246 |
goto next; |
1247 |
diff -ubBpEr linux-2.4.34/net/ipv6/udp.c linux-2.4.34-ccs/net/ipv6/udp.c |
1248 |
--- linux-2.4.34/net/ipv6/udp.c 2007-03-03 10:49:54.000000000 +0900 |
1249 |
+++ linux-2.4.34-ccs/net/ipv6/udp.c 2007-03-03 10:55:24.000000000 +0900 |
1250 |
@@ -50,6 +50,9 @@ |
1251 |
#include <net/inet_common.h> |
1252 |
|
1253 |
#include <net/checksum.h> |
1254 |
+/***** SAKURA Linux start. *****/ |
1255 |
+#include <linux/sakura.h> |
1256 |
+/***** SAKURA Linux end. *****/ |
1257 |
|
1258 |
struct udp_mib udp_stats_in6[NR_CPUS*2]; |
1259 |
|
1260 |
@@ -70,6 +73,9 @@ static int udp_v6_get_port(struct sock * |
1261 |
for (i = 0; i < UDP_HTABLE_SIZE; i++, result++) { |
1262 |
struct sock *sk; |
1263 |
int size; |
1264 |
+ /***** SAKURA Linux start. *****/ |
1265 |
+ if (SAKURA_MayAutobind(result) < 0) continue; |
1266 |
+ /***** SAKURA Linux end. *****/ |
1267 |
|
1268 |
sk = udp_hash[result & (UDP_HTABLE_SIZE - 1)]; |
1269 |
if (!sk) { |
1270 |
@@ -94,6 +100,9 @@ static int udp_v6_get_port(struct sock * |
1271 |
result = sysctl_local_port_range[0] |
1272 |
+ ((result - sysctl_local_port_range[0]) & |
1273 |
(UDP_HTABLE_SIZE - 1)); |
1274 |
+ /***** SAKURA Linux start. *****/ |
1275 |
+ if (SAKURA_MayAutobind(result) < 0) continue; |
1276 |
+ /***** SAKURA Linux end. *****/ |
1277 |
if (!udp_lport_inuse(result)) |
1278 |
break; |
1279 |
} |
1280 |
diff -ubBpEr linux-2.4.34/net/socket.c linux-2.4.34-ccs/net/socket.c |
1281 |
--- linux-2.4.34/net/socket.c 2007-03-03 10:49:54.000000000 +0900 |
1282 |
+++ linux-2.4.34-ccs/net/socket.c 2007-03-03 10:55:24.000000000 +0900 |
1283 |
@@ -84,6 +84,10 @@ |
1284 |
#include <net/sock.h> |
1285 |
#include <net/scm.h> |
1286 |
#include <linux/netfilter.h> |
1287 |
+/***** TOMOYO Linux start. *****/ |
1288 |
+#include <linux/tomoyo.h> |
1289 |
+#include <linux/tomoyo_socket.h> |
1290 |
+/***** TOMOYO Linux end. *****/ |
1291 |
|
1292 |
static int sock_no_open(struct inode *irrelevant, struct file *dontcare); |
1293 |
static ssize_t sock_read(struct file *file, char *buf, |
1294 |
@@ -501,7 +505,9 @@ int sock_sendmsg(struct socket *sock, st |
1295 |
{ |
1296 |
int err; |
1297 |
struct scm_cookie scm; |
1298 |
- |
1299 |
+ /***** TOMOYO Linux start. *****/ |
1300 |
+ if ((err = CheckSocketSendMsgPermission(sock, (struct sockaddr *) msg->msg_name, msg->msg_namelen)) == 0) |
1301 |
+ /***** TOMOYO Linux start. *****/ |
1302 |
err = scm_send(sock, msg, &scm); |
1303 |
if (err >= 0) { |
1304 |
err = sock->ops->sendmsg(sock, msg, size, &scm); |
1305 |
@@ -519,6 +525,11 @@ int sock_recvmsg(struct socket *sock, st |
1306 |
size = sock->ops->recvmsg(sock, msg, size, flags, &scm); |
1307 |
if (size >= 0) |
1308 |
scm_recv(sock, msg, &scm, flags); |
1309 |
+ /***** TOMOYO Linux start. *****/ |
1310 |
+ if (size >= 0 && CheckSocketRecvMsgPermission(sock, (struct sockaddr *) msg->msg_name, msg->msg_namelen)) { |
1311 |
+ size = -EAGAIN; /* Hope less harmful than -EPERM. */ |
1312 |
+ } |
1313 |
+ /***** TOMOYO Linux end. *****/ |
1314 |
|
1315 |
return size; |
1316 |
} |
1317 |
@@ -847,7 +858,9 @@ int sock_create(int family, int type, in |
1318 |
} |
1319 |
family = PF_PACKET; |
1320 |
} |
1321 |
- |
1322 |
+ /***** TOMOYO Linux start. *****/ |
1323 |
+ if ((i = CheckSocketCreatePermission(family, type, protocol)) < 0) return i; |
1324 |
+ /***** TOMOYO Linux end. *****/ |
1325 |
#if defined(CONFIG_KMOD) && defined(CONFIG_NET) |
1326 |
/* Attempt to load a protocol module if the find failed. |
1327 |
* |
1328 |
@@ -1003,6 +1016,9 @@ asmlinkage long sys_bind(int fd, struct |
1329 |
if((sock = sockfd_lookup(fd,&err))!=NULL) |
1330 |
{ |
1331 |
if((err=move_addr_to_kernel(umyaddr,addrlen,address))>=0) |
1332 |
+ /***** TOMOYO Linux start. *****/ |
1333 |
+ if ((err = CheckSocketBindPermission(sock, (struct sockaddr *) address, addrlen)) == 0) |
1334 |
+ /***** TOMOYO Linux end. *****/ |
1335 |
err = sock->ops->bind(sock, (struct sockaddr *)address, addrlen); |
1336 |
sockfd_put(sock); |
1337 |
} |
1338 |
@@ -1026,6 +1042,9 @@ asmlinkage long sys_listen(int fd, int b |
1339 |
if ((sock = sockfd_lookup(fd, &err)) != NULL) { |
1340 |
if ((unsigned) backlog > sysctl_somaxconn) |
1341 |
backlog = sysctl_somaxconn; |
1342 |
+ /***** TOMOYO Linux start. *****/ |
1343 |
+ if ((err = CheckSocketListenPermission(sock)) == 0) |
1344 |
+ /***** TOMOYO Linux end. *****/ |
1345 |
err=sock->ops->listen(sock, backlog); |
1346 |
sockfd_put(sock); |
1347 |
} |
1348 |
@@ -1066,6 +1085,12 @@ asmlinkage long sys_accept(int fd, struc |
1349 |
if (err < 0) |
1350 |
goto out_release; |
1351 |
|
1352 |
+ /***** TOMOYO Linux start. *****/ |
1353 |
+ if (CheckSocketAcceptPermission(newsock, (struct sockaddr *) address)) { |
1354 |
+ err = -ECONNABORTED; /* Hope less harmful than -EPERM. */ |
1355 |
+ goto out_release; |
1356 |
+ } |
1357 |
+ /***** TOMOYO Linux end. *****/ |
1358 |
if (upeer_sockaddr) { |
1359 |
if(newsock->ops->getname(newsock, (struct sockaddr *)address, &len, 2)<0) { |
1360 |
err = -ECONNABORTED; |
1361 |
@@ -1116,6 +1141,9 @@ asmlinkage long sys_connect(int fd, stru |
1362 |
err = move_addr_to_kernel(uservaddr, addrlen, address); |
1363 |
if (err < 0) |
1364 |
goto out_put; |
1365 |
+ /***** TOMOYO Linux start. *****/ |
1366 |
+ if ((err = CheckSocketConnectPermission(sock, (struct sockaddr *) address, addrlen)) == 0) |
1367 |
+ /***** TOMOYO Linux end. *****/ |
1368 |
err = sock->ops->connect(sock, (struct sockaddr *) address, addrlen, |
1369 |
sock->file->f_flags); |
1370 |
out_put: |
1371 |
diff -ubBpEr linux-2.4.34/net/unix/af_unix.c linux-2.4.34-ccs/net/unix/af_unix.c |
1372 |
--- linux-2.4.34/net/unix/af_unix.c 2007-03-03 11:38:54.000000000 +0900 |
1373 |
+++ linux-2.4.34-ccs/net/unix/af_unix.c 2007-03-05 13:22:32.000000000 +0900 |
1374 |
@@ -111,6 +111,9 @@ |
1375 |
#include <linux/rtnetlink.h> |
1376 |
|
1377 |
#include <asm/checksum.h> |
1378 |
+/***** TOMOYO Linux start. *****/ |
1379 |
+#include <linux/tomoyo.h> |
1380 |
+/***** TOMOYO Linux end. *****/ |
1381 |
|
1382 |
int sysctl_unix_max_dgram_qlen = 10; |
1383 |
|
1384 |
@@ -645,6 +648,10 @@ static int unix_bind(struct socket *sock |
1385 |
err = unix_autobind(sock); |
1386 |
goto out; |
1387 |
} |
1388 |
+ /***** TOMOYO Linux start. *****/ |
1389 |
+ err = -EPERM; |
1390 |
+ if (sunaddr->sun_path[0] && CheckCapabilityACL(TOMOYO_CREATE_UNIX_SOCKET)) goto out; |
1391 |
+ /***** TOMOYO Linux end. *****/ |
1392 |
|
1393 |
err = unix_mkname(sunaddr, addr_len, &hash); |
1394 |
if (err < 0) |
1395 |
@@ -709,6 +716,9 @@ static int unix_bind(struct socket *sock |
1396 |
* All right, let's create it. |
1397 |
*/ |
1398 |
mode = S_IFSOCK | (sock->inode->i_mode & ~current->fs->umask); |
1399 |
+ /***** TOMOYO Linux start. *****/ |
1400 |
+ if ((err = pre_vfs_mknod(nd.dentry->d_inode, dentry)) == 0 && (err = CheckSingleWritePermission(TYPE_MKSOCK_ACL, dentry, nd.mnt)) == 0) |
1401 |
+ /***** TOMOYO Linux end. *****/ |
1402 |
err = vfs_mknod(nd.dentry->d_inode, dentry, mode, 0); |
1403 |
if (err) |
1404 |
goto out_mknod_dput; |