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