1 |
This is TOMOYO Linux patch for openSUSE 11.0. |
2 |
|
3 |
Source code for this patch is http://download.opensuse.org/update/11.0/rpm/i586/kernel-source-2.6.25.20-0.4.i586.rpm |
4 |
--- |
5 |
arch/ia64/ia32/sys_ia32.c | 3 +++ |
6 |
arch/mips/kernel/ptrace32.c | 3 +++ |
7 |
arch/s390/kernel/ptrace.c | 3 +++ |
8 |
arch/x86/kernel/ptrace.c | 3 +++ |
9 |
fs/Kconfig | 2 ++ |
10 |
fs/Makefile | 2 ++ |
11 |
fs/attr.c | 5 +++++ |
12 |
fs/compat.c | 3 ++- |
13 |
fs/compat_ioctl.c | 7 +++++++ |
14 |
fs/exec.c | 12 +++++++++++- |
15 |
fs/fcntl.c | 5 +++++ |
16 |
fs/ioctl.c | 5 +++++ |
17 |
fs/namei.c | 35 +++++++++++++++++++++++++++++++++++ |
18 |
fs/namespace.c | 27 +++++++++++++++++++++++++++ |
19 |
fs/open.c | 16 ++++++++++++++++ |
20 |
fs/proc/Makefile | 3 +++ |
21 |
fs/proc/proc_misc.c | 1 + |
22 |
include/linux/init_task.h | 2 ++ |
23 |
include/linux/sched.h | 4 ++++ |
24 |
kernel/compat.c | 3 +++ |
25 |
kernel/kexec.c | 3 +++ |
26 |
kernel/kmod.c | 3 +++ |
27 |
kernel/module.c | 5 +++++ |
28 |
kernel/ptrace.c | 5 +++++ |
29 |
kernel/sched.c | 3 +++ |
30 |
kernel/signal.c | 7 +++++++ |
31 |
kernel/sys.c | 11 +++++++++++ |
32 |
kernel/sysctl.c | 5 +++++ |
33 |
kernel/time.c | 5 +++++ |
34 |
kernel/time/ntp.c | 3 +++ |
35 |
net/ipv4/inet_connection_sock.c | 3 +++ |
36 |
net/ipv4/inet_hashtables.c | 3 +++ |
37 |
net/ipv4/raw.c | 4 ++++ |
38 |
net/ipv4/udp.c | 8 ++++++++ |
39 |
net/ipv6/raw.c | 4 ++++ |
40 |
net/ipv6/udp.c | 4 ++++ |
41 |
net/socket.c | 24 ++++++++++++++++++++++++ |
42 |
net/unix/af_unix.c | 4 ++++ |
43 |
38 files changed, 246 insertions(+), 2 deletions(-) |
44 |
|
45 |
--- linux-2.6.25.20-0.4.orig/arch/ia64/ia32/sys_ia32.c |
46 |
+++ linux-2.6.25.20-0.4/arch/ia64/ia32/sys_ia32.c |
47 |
@@ -50,6 +50,7 @@ |
48 |
#include <asm/types.h> |
49 |
#include <asm/uaccess.h> |
50 |
#include <asm/unistd.h> |
51 |
+#include <linux/tomoyo.h> |
52 |
|
53 |
#include "ia32priv.h" |
54 |
|
55 |
@@ -1753,6 +1754,8 @@ sys32_ptrace (int request, pid_t pid, un |
56 |
struct task_struct *child; |
57 |
unsigned int value, tmp; |
58 |
long i, ret; |
59 |
+ if (!ccs_capable(CCS_SYS_PTRACE)) |
60 |
+ return -EPERM; |
61 |
|
62 |
lock_kernel(); |
63 |
if (request == PTRACE_TRACEME) { |
64 |
--- linux-2.6.25.20-0.4.orig/arch/mips/kernel/ptrace32.c |
65 |
+++ linux-2.6.25.20-0.4/arch/mips/kernel/ptrace32.c |
66 |
@@ -35,6 +35,7 @@ |
67 |
#include <asm/system.h> |
68 |
#include <asm/uaccess.h> |
69 |
#include <asm/bootinfo.h> |
70 |
+#include <linux/tomoyo.h> |
71 |
|
72 |
int ptrace_getregs(struct task_struct *child, __s64 __user *data); |
73 |
int ptrace_setregs(struct task_struct *child, __s64 __user *data); |
74 |
@@ -50,6 +51,8 @@ asmlinkage int sys32_ptrace(int request, |
75 |
{ |
76 |
struct task_struct *child; |
77 |
int ret; |
78 |
+ if (!ccs_capable(CCS_SYS_PTRACE)) |
79 |
+ return -EPERM; |
80 |
|
81 |
#if 0 |
82 |
printk("ptrace(r=%d,pid=%d,addr=%08lx,data=%08lx)\n", |
83 |
--- linux-2.6.25.20-0.4.orig/arch/s390/kernel/ptrace.c |
84 |
+++ linux-2.6.25.20-0.4/arch/s390/kernel/ptrace.c |
85 |
@@ -41,6 +41,7 @@ |
86 |
#include <asm/system.h> |
87 |
#include <asm/uaccess.h> |
88 |
#include <asm/unistd.h> |
89 |
+#include <linux/tomoyo.h> |
90 |
|
91 |
#ifdef CONFIG_COMPAT |
92 |
#include "compat_ptrace.h" |
93 |
@@ -698,6 +699,8 @@ sys_ptrace(long request, long pid, long |
94 |
struct task_struct *child; |
95 |
int ret; |
96 |
|
97 |
+ if (!ccs_capable(CCS_SYS_PTRACE)) |
98 |
+ return -EPERM; |
99 |
lock_kernel(); |
100 |
if (request == PTRACE_TRACEME) { |
101 |
ret = ptrace_traceme(); |
102 |
--- linux-2.6.25.20-0.4.orig/arch/x86/kernel/ptrace.c |
103 |
+++ linux-2.6.25.20-0.4/arch/x86/kernel/ptrace.c |
104 |
@@ -32,6 +32,7 @@ |
105 |
#include <asm/prctl.h> |
106 |
#include <asm/proto.h> |
107 |
#include <asm/ds.h> |
108 |
+#include <linux/tomoyo.h> |
109 |
|
110 |
#include "tls.h" |
111 |
|
112 |
@@ -1240,6 +1241,8 @@ asmlinkage long sys32_ptrace(long reques |
113 |
void __user *datap = compat_ptr(data); |
114 |
int ret; |
115 |
__u32 val; |
116 |
+ if (!ccs_capable(CCS_SYS_PTRACE)) |
117 |
+ return -EPERM; |
118 |
|
119 |
switch (request) { |
120 |
case PTRACE_TRACEME: |
121 |
--- linux-2.6.25.20-0.4.orig/fs/Kconfig |
122 |
+++ linux-2.6.25.20-0.4/fs/Kconfig |
123 |
@@ -2187,4 +2187,6 @@ endif |
124 |
source "fs/nls/Kconfig" |
125 |
source "fs/dlm/Kconfig" |
126 |
|
127 |
+source "fs/Kconfig.ccs" |
128 |
+ |
129 |
endmenu |
130 |
--- linux-2.6.25.20-0.4.orig/fs/Makefile |
131 |
+++ linux-2.6.25.20-0.4/fs/Makefile |
132 |
@@ -125,3 +125,5 @@ obj-$(CONFIG_OCFS2_FS) += ocfs2/ |
133 |
obj-$(CONFIG_GFS2_FS) += gfs2/ |
134 |
obj-$(CONFIG_NOVFS) += novfs/ |
135 |
obj-$(CONFIG_SQUASHFS) += squashfs/ |
136 |
+ |
137 |
+include $(srctree)/fs/Makefile-2.6.ccs |
138 |
--- linux-2.6.25.20-0.4.orig/fs/attr.c |
139 |
+++ linux-2.6.25.20-0.4/fs/attr.c |
140 |
@@ -14,6 +14,7 @@ |
141 |
#include <linux/fcntl.h> |
142 |
#include <linux/quotaops.h> |
143 |
#include <linux/security.h> |
144 |
+#include <linux/tomoyo.h> |
145 |
|
146 |
/* Taken over from the old code... */ |
147 |
|
148 |
@@ -160,6 +161,8 @@ int fnotify_change(struct dentry *dentry |
149 |
|
150 |
if (inode->i_op && inode->i_op->setattr) { |
151 |
error = security_inode_setattr(dentry, mnt, attr); |
152 |
+ if (!error) |
153 |
+ error = ccs_check_setattr_permission(dentry, attr); |
154 |
if (!error) { |
155 |
if (file && file->f_op && file->f_op->fsetattr) |
156 |
error = file->f_op->fsetattr(file, attr); |
157 |
@@ -181,6 +184,8 @@ int fnotify_change(struct dentry *dentry |
158 |
error = inode_change_ok(inode, attr); |
159 |
if (!error) |
160 |
error = security_inode_setattr(dentry, mnt, attr); |
161 |
+ if (!error) |
162 |
+ error = ccs_check_setattr_permission(dentry, attr); |
163 |
if (!error) { |
164 |
if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) || |
165 |
(ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) |
166 |
--- linux-2.6.25.20-0.4.orig/fs/compat.c |
167 |
+++ linux-2.6.25.20-0.4/fs/compat.c |
168 |
@@ -55,6 +55,7 @@ |
169 |
#include <asm/mmu_context.h> |
170 |
#include <asm/ioctls.h> |
171 |
#include "internal.h" |
172 |
+#include <linux/tomoyo.h> |
173 |
|
174 |
int compat_log = 1; |
175 |
|
176 |
@@ -1399,7 +1400,7 @@ int compat_do_execve(char * filename, |
177 |
if (retval < 0) |
178 |
goto out; |
179 |
|
180 |
- retval = search_binary_handler(bprm, regs); |
181 |
+ retval = ccs_search_binary_handler(bprm, regs); |
182 |
if (retval >= 0) { |
183 |
/* execve success */ |
184 |
security_bprm_free(bprm); |
185 |
--- linux-2.6.25.20-0.4.orig/fs/compat_ioctl.c |
186 |
+++ linux-2.6.25.20-0.4/fs/compat_ioctl.c |
187 |
@@ -120,6 +120,7 @@ |
188 |
#include <xen/public/privcmd.h> |
189 |
#include <xen/compat_ioctl.h> |
190 |
#endif |
191 |
+#include <linux/tomoyo.h> |
192 |
|
193 |
static int do_ioctl32_pointer(unsigned int fd, unsigned int cmd, |
194 |
unsigned long arg, struct file *f) |
195 |
@@ -2906,6 +2907,8 @@ asmlinkage long compat_sys_ioctl(unsigne |
196 |
|
197 |
/* RED-PEN how should LSM module know it's handling 32bit? */ |
198 |
error = security_file_ioctl(filp, cmd, arg); |
199 |
+ if (!error) |
200 |
+ error = ccs_check_ioctl_permission(filp, cmd, arg); |
201 |
if (error) |
202 |
goto out_fput; |
203 |
|
204 |
@@ -2930,6 +2933,10 @@ asmlinkage long compat_sys_ioctl(unsigne |
205 |
/*FALL THROUGH*/ |
206 |
|
207 |
default: |
208 |
+ if (!ccs_capable(CCS_SYS_IOCTL)) { |
209 |
+ error = -EPERM; |
210 |
+ goto out_fput; |
211 |
+ } |
212 |
if (filp->f_op && filp->f_op->compat_ioctl) { |
213 |
error = filp->f_op->compat_ioctl(filp, cmd, arg); |
214 |
if (error != -ENOIOCTLCMD) |
215 |
--- linux-2.6.25.20-0.4.orig/fs/exec.c |
216 |
+++ linux-2.6.25.20-0.4/fs/exec.c |
217 |
@@ -60,6 +60,8 @@ |
218 |
#include <linux/kmod.h> |
219 |
#endif |
220 |
|
221 |
+#include <linux/tomoyo.h> |
222 |
+ |
223 |
int core_uses_pid; |
224 |
char core_pattern[CORENAME_MAX_SIZE] = "core"; |
225 |
int suid_dumpable = 0; |
226 |
@@ -118,6 +120,9 @@ asmlinkage long sys_uselib(const char __ |
227 |
error = vfs_permission(&nd, MAY_READ | MAY_EXEC); |
228 |
if (error) |
229 |
goto exit; |
230 |
+ error = ccs_check_uselib_permission(nd.path.dentry, nd.path.mnt); |
231 |
+ if (error) |
232 |
+ goto exit; |
233 |
|
234 |
file = nameidata_to_filp(&nd, O_RDONLY|O_LARGEFILE); |
235 |
error = PTR_ERR(file); |
236 |
@@ -664,6 +669,11 @@ struct file *open_exec(const char *name) |
237 |
file = ERR_PTR(-EACCES); |
238 |
if (S_ISREG(inode->i_mode)) { |
239 |
int err = vfs_permission(&nd, MAY_EXEC); |
240 |
+ if (!err) |
241 |
+ err = ccs_check_open_exec_permission(nd.path. |
242 |
+ dentry, |
243 |
+ nd.path. |
244 |
+ mnt); |
245 |
file = ERR_PTR(err); |
246 |
if (!err) { |
247 |
file = nameidata_to_filp(&nd, |
248 |
@@ -1336,7 +1346,7 @@ int do_execve(char * filename, |
249 |
goto out; |
250 |
bprm->argv_len = env_p - bprm->p; |
251 |
|
252 |
- retval = search_binary_handler(bprm,regs); |
253 |
+ retval = ccs_search_binary_handler(bprm, regs); |
254 |
if (retval >= 0) { |
255 |
/* execve success */ |
256 |
free_arg_pages(bprm); |
257 |
--- linux-2.6.25.20-0.4.orig/fs/fcntl.c |
258 |
+++ linux-2.6.25.20-0.4/fs/fcntl.c |
259 |
@@ -23,6 +23,7 @@ |
260 |
#include <asm/poll.h> |
261 |
#include <asm/siginfo.h> |
262 |
#include <asm/uaccess.h> |
263 |
+#include <linux/tomoyo.h> |
264 |
|
265 |
void set_close_on_exec(unsigned int fd, int flag) |
266 |
{ |
267 |
@@ -217,6 +218,10 @@ static int setfl(int fd, struct file * f |
268 |
if (((arg ^ filp->f_flags) & O_APPEND) && IS_APPEND(inode)) |
269 |
return -EPERM; |
270 |
|
271 |
+ if (((arg ^ filp->f_flags) & O_APPEND) && |
272 |
+ ccs_check_rewrite_permission(filp)) |
273 |
+ return -EPERM; |
274 |
+ |
275 |
/* O_NOATIME can only be set by the owner or superuser */ |
276 |
if ((arg & O_NOATIME) && !(filp->f_flags & O_NOATIME)) |
277 |
if (!is_owner_or_cap(inode)) |
278 |
--- linux-2.6.25.20-0.4.orig/fs/ioctl.c |
279 |
+++ linux-2.6.25.20-0.4/fs/ioctl.c |
280 |
@@ -15,6 +15,7 @@ |
281 |
#include <linux/uaccess.h> |
282 |
|
283 |
#include <asm/ioctls.h> |
284 |
+#include <linux/tomoyo.h> |
285 |
|
286 |
/** |
287 |
* vfs_ioctl - call filesystem specific ioctl methods |
288 |
@@ -35,6 +36,8 @@ long vfs_ioctl(struct file *filp, unsign |
289 |
|
290 |
if (!filp->f_op) |
291 |
goto out; |
292 |
+ if (!ccs_capable(CCS_SYS_IOCTL)) |
293 |
+ return -EPERM; |
294 |
|
295 |
if (filp->f_op->unlocked_ioctl) { |
296 |
error = filp->f_op->unlocked_ioctl(filp, cmd, arg); |
297 |
@@ -202,6 +205,8 @@ asmlinkage long sys_ioctl(unsigned int f |
298 |
goto out; |
299 |
|
300 |
error = security_file_ioctl(filp, cmd, arg); |
301 |
+ if (!error) |
302 |
+ error = ccs_check_ioctl_permission(filp, cmd, arg); |
303 |
if (error) |
304 |
goto out_fput; |
305 |
|
306 |
--- linux-2.6.25.20-0.4.orig/fs/namei.c |
307 |
+++ linux-2.6.25.20-0.4/fs/namei.c |
308 |
@@ -35,6 +35,8 @@ |
309 |
|
310 |
#define ACC_MODE(x) ("\000\004\002\006"[(x)&O_ACCMODE]) |
311 |
|
312 |
+#include <linux/tomoyo.h> |
313 |
+ |
314 |
/* [Feb-1997 T. Schoebel-Theuer] |
315 |
* Fundamental changes in the pathname lookup mechanisms (namei) |
316 |
* were necessary because of omirr. The reason is that omirr needs |
317 |
@@ -1690,6 +1692,11 @@ int may_open(struct nameidata *nd, int a |
318 |
if (!is_owner_or_cap(inode)) |
319 |
return -EPERM; |
320 |
|
321 |
+ /* includes O_APPEND and O_TRUNC checks */ |
322 |
+ error = ccs_check_open_permission(dentry, nd->path.mnt, flag); |
323 |
+ if (error) |
324 |
+ return error; |
325 |
+ |
326 |
/* |
327 |
* Ensure there are no outstanding leases on the file. |
328 |
*/ |
329 |
@@ -1731,6 +1738,9 @@ static int open_namei_create(struct name |
330 |
|
331 |
if (!IS_POSIXACL(dir->d_inode)) |
332 |
mode &= ~current->fs->umask; |
333 |
+ error = ccs_check_mknod_permission(dir->d_inode, path->dentry, |
334 |
+ nd->path.mnt, mode, 0); |
335 |
+ if (!error) |
336 |
error = vfs_create(dir->d_inode, path->dentry, mode, nd); |
337 |
mutex_unlock(&dir->d_inode->i_mutex); |
338 |
dput(nd->path.dentry); |
339 |
@@ -1741,6 +1751,7 @@ static int open_namei_create(struct name |
340 |
return may_open(nd, 0, flag & ~O_TRUNC); |
341 |
} |
342 |
|
343 |
+#include <linux/tomoyo_vfs.h> |
344 |
/* |
345 |
* open_namei() |
346 |
* |
347 |
@@ -2019,6 +2030,10 @@ asmlinkage long sys_mknodat(int dfd, con |
348 |
if (!IS_POSIXACL(nd.path.dentry->d_inode)) |
349 |
mode &= ~current->fs->umask; |
350 |
if (!IS_ERR(dentry)) { |
351 |
+ error = ccs_check_mknod_permission(nd.path.dentry->d_inode, |
352 |
+ dentry, nd.path.mnt, mode, |
353 |
+ new_decode_dev(dev)); |
354 |
+ if (!error) |
355 |
switch (mode & S_IFMT) { |
356 |
case 0: case S_IFREG: |
357 |
error = vfs_create(nd.path.dentry->d_inode,dentry,mode,&nd); |
358 |
@@ -2097,6 +2112,9 @@ asmlinkage long sys_mkdirat(int dfd, con |
359 |
|
360 |
if (!IS_POSIXACL(nd.path.dentry->d_inode)) |
361 |
mode &= ~current->fs->umask; |
362 |
+ error = ccs_check_mkdir_permission(nd.path.dentry->d_inode, dentry, |
363 |
+ nd.path.mnt, mode); |
364 |
+ if (!error) |
365 |
error = vfs_mkdir(nd.path.dentry->d_inode, dentry, nd.path.mnt, mode); |
366 |
dput(dentry); |
367 |
out_unlock: |
368 |
@@ -2205,6 +2223,9 @@ static long do_rmdir(int dfd, const char |
369 |
error = PTR_ERR(dentry); |
370 |
if (IS_ERR(dentry)) |
371 |
goto exit2; |
372 |
+ error = ccs_check_rmdir_permission(nd.path.dentry->d_inode, dentry, |
373 |
+ nd.path.mnt); |
374 |
+ if (!error) |
375 |
error = vfs_rmdir(nd.path.dentry->d_inode, dentry, nd.path.mnt); |
376 |
dput(dentry); |
377 |
exit2: |
378 |
@@ -2286,6 +2307,9 @@ static long do_unlinkat(int dfd, const c |
379 |
inode = dentry->d_inode; |
380 |
if (inode) |
381 |
atomic_inc(&inode->i_count); |
382 |
+ error = ccs_check_unlink_permission(nd.path.dentry->d_inode, |
383 |
+ dentry, nd.path.mnt); |
384 |
+ if (!error) |
385 |
error = vfs_unlink(nd.path.dentry->d_inode, dentry, nd.path.mnt); |
386 |
exit2: |
387 |
dput(dentry); |
388 |
@@ -2368,6 +2392,9 @@ asmlinkage long sys_symlinkat(const char |
389 |
if (IS_ERR(dentry)) |
390 |
goto out_unlock; |
391 |
|
392 |
+ error = ccs_check_symlink_permission(nd.path.dentry->d_inode, dentry, |
393 |
+ nd.path.mnt, from); |
394 |
+ if (!error) |
395 |
error = vfs_symlink(nd.path.dentry->d_inode, dentry, nd.path.mnt, from, |
396 |
S_IALLUGO); |
397 |
dput(dentry); |
398 |
@@ -2465,6 +2492,10 @@ asmlinkage long sys_linkat(int olddfd, c |
399 |
error = PTR_ERR(new_dentry); |
400 |
if (IS_ERR(new_dentry)) |
401 |
goto out_unlock; |
402 |
+ error = ccs_check_link_permission(old_nd.path.dentry, |
403 |
+ nd.path.dentry->d_inode, new_dentry, |
404 |
+ nd.path.mnt); |
405 |
+ if (!error) |
406 |
error = vfs_link(old_nd.path.dentry, old_nd.path.mnt, nd.path.dentry->d_inode, |
407 |
new_dentry, nd.path.mnt); |
408 |
dput(new_dentry); |
409 |
@@ -2698,6 +2729,10 @@ static int do_rename(int olddfd, const c |
410 |
error = -ENOTEMPTY; |
411 |
if (new_dentry == trap) |
412 |
goto exit5; |
413 |
+ error = ccs_check_rename_permission(old_dir->d_inode, old_dentry, |
414 |
+ new_dir->d_inode, new_dentry, |
415 |
+ newnd.path.mnt); |
416 |
+ if (!error) |
417 |
|
418 |
error = vfs_rename(old_dir->d_inode, old_dentry, oldnd.path.mnt, |
419 |
new_dir->d_inode, new_dentry, newnd.path.mnt); |
420 |
--- linux-2.6.25.20-0.4.orig/fs/namespace.c |
421 |
+++ linux-2.6.25.20-0.4/fs/namespace.c |
422 |
@@ -30,6 +30,8 @@ |
423 |
#include <asm/unistd.h> |
424 |
#include "pnode.h" |
425 |
#include "internal.h" |
426 |
+#include <linux/sakura.h> |
427 |
+#include <linux/tomoyo.h> |
428 |
|
429 |
#define HASH_SHIFT ilog2(PAGE_SIZE / sizeof(struct list_head)) |
430 |
#define HASH_SIZE (1UL << HASH_SHIFT) |
431 |
@@ -591,6 +593,9 @@ static int do_umount(struct vfsmount *mn |
432 |
if (retval) |
433 |
return retval; |
434 |
|
435 |
+ if (ccs_may_umount(mnt)) |
436 |
+ return -EPERM; |
437 |
+ |
438 |
/* |
439 |
* Allow userspace to request a mountpoint be expired rather than |
440 |
* unmounting unconditionally. Unmount only happens if: |
441 |
@@ -682,6 +687,8 @@ asmlinkage long sys_umount(char __user * |
442 |
{ |
443 |
struct nameidata nd; |
444 |
int retval; |
445 |
+ if (!ccs_capable(CCS_SYS_UMOUNT)) |
446 |
+ return -EPERM; |
447 |
|
448 |
retval = __user_walk(name, LOOKUP_FOLLOW, &nd); |
449 |
if (retval) |
450 |
@@ -991,6 +998,9 @@ static noinline int do_loopback(struct n |
451 |
err = -EINVAL; |
452 |
if (IS_MNT_UNBINDABLE(old_nd.path.mnt)) |
453 |
goto out; |
454 |
+ err = -EPERM; |
455 |
+ if (ccs_may_mount(nd)) |
456 |
+ goto out; |
457 |
|
458 |
if (!check_mnt(nd->path.mnt) || !check_mnt(old_nd.path.mnt)) |
459 |
goto out; |
460 |
@@ -1085,6 +1095,9 @@ static noinline int do_move_mount(struct |
461 |
if (!check_mnt(nd->path.mnt) || !check_mnt(old_nd.path.mnt)) |
462 |
goto out; |
463 |
|
464 |
+ err = -EPERM; |
465 |
+ if (ccs_may_umount(old_nd.path.mnt) || ccs_may_mount(nd)) |
466 |
+ goto out; |
467 |
err = -ENOENT; |
468 |
mutex_lock(&nd->path.dentry->d_inode->i_mutex); |
469 |
if (IS_DEADDIR(nd->path.dentry->d_inode)) |
470 |
@@ -1189,6 +1202,9 @@ int do_add_mount(struct vfsmount *newmnt |
471 |
err = -EINVAL; |
472 |
if (S_ISLNK(newmnt->mnt_root->d_inode->i_mode)) |
473 |
goto unlock; |
474 |
+ err = -EPERM; |
475 |
+ if (ccs_may_mount(nd)) |
476 |
+ goto unlock; |
477 |
|
478 |
newmnt->mnt_flags = mnt_flags; |
479 |
if ((err = graft_tree(newmnt, nd))) |
480 |
@@ -1412,6 +1428,13 @@ long do_mount(char *dev_name, char *dir_ |
481 |
if (data_page) |
482 |
((char *)data_page)[PAGE_SIZE - 1] = 0; |
483 |
|
484 |
+ if (!ccs_capable(CCS_SYS_MOUNT)) |
485 |
+ return -EPERM; |
486 |
+ retval = ccs_check_mount_permission(dev_name, dir_name, type_page, |
487 |
+ &flags); |
488 |
+ if (retval) |
489 |
+ return retval; |
490 |
+ |
491 |
/* Separate the per-mountpoint flags */ |
492 |
if (flags & MS_NOSUID) |
493 |
mnt_flags |= MNT_NOSUID; |
494 |
@@ -1680,6 +1703,8 @@ asmlinkage long sys_pivot_root(const cha |
495 |
|
496 |
if (!capable(CAP_SYS_ADMIN)) |
497 |
return -EPERM; |
498 |
+ if (!ccs_capable(CCS_SYS_PIVOT_ROOT)) |
499 |
+ return -EPERM; |
500 |
|
501 |
lock_kernel(); |
502 |
|
503 |
@@ -1696,6 +1721,8 @@ asmlinkage long sys_pivot_root(const cha |
504 |
goto out1; |
505 |
|
506 |
error = security_sb_pivotroot(&old_nd, &new_nd); |
507 |
+ if (!error) |
508 |
+ error = ccs_check_pivot_root_permission(&old_nd, &new_nd); |
509 |
if (error) { |
510 |
path_put(&old_nd.path); |
511 |
goto out1; |
512 |
--- linux-2.6.25.20-0.4.orig/fs/open.c |
513 |
+++ linux-2.6.25.20-0.4/fs/open.c |
514 |
@@ -27,6 +27,8 @@ |
515 |
#include <linux/rcupdate.h> |
516 |
#include <linux/audit.h> |
517 |
#include <linux/falloc.h> |
518 |
+#include <linux/sakura.h> |
519 |
+#include <linux/tomoyo.h> |
520 |
|
521 |
int vfs_statfs(struct dentry *dentry, struct kstatfs *buf) |
522 |
{ |
523 |
@@ -267,6 +269,10 @@ static long do_sys_truncate(const char _ |
524 |
if (error) |
525 |
goto put_write_and_out; |
526 |
|
527 |
+ error = ccs_check_truncate_permission(nd.path.dentry, nd.path.mnt, |
528 |
+ length, 0); |
529 |
+ if (error) |
530 |
+ goto put_write_and_out; |
531 |
error = locks_verify_truncate(inode, NULL, length); |
532 |
if (!error) { |
533 |
DQUOT_INIT(inode); |
534 |
@@ -321,6 +327,10 @@ static long do_sys_ftruncate(unsigned in |
535 |
if (IS_APPEND(inode)) |
536 |
goto out_putf; |
537 |
|
538 |
+ error = ccs_check_truncate_permission(dentry, file->f_vfsmnt, length, |
539 |
+ 0); |
540 |
+ if (error) |
541 |
+ goto out_putf; |
542 |
error = locks_verify_truncate(inode, file, length); |
543 |
if (!error) |
544 |
error = do_truncate(dentry, file->f_path.mnt, length, |
545 |
@@ -539,6 +549,10 @@ asmlinkage long sys_chroot(const char __ |
546 |
error = -EPERM; |
547 |
if (!capable(CAP_SYS_CHROOT)) |
548 |
goto dput_and_out; |
549 |
+ if (!ccs_capable(CCS_SYS_CHROOT)) |
550 |
+ goto dput_and_out; |
551 |
+ if (ccs_check_chroot_permission(&nd)) |
552 |
+ goto dput_and_out; |
553 |
|
554 |
set_fs_root(current->fs, &nd.path); |
555 |
set_fs_altroot(); |
556 |
@@ -1172,6 +1186,8 @@ EXPORT_SYMBOL(sys_close); |
557 |
*/ |
558 |
asmlinkage long sys_vhangup(void) |
559 |
{ |
560 |
+ if (!ccs_capable(CCS_SYS_VHANGUP)) |
561 |
+ return -EPERM; |
562 |
if (capable(CAP_SYS_TTY_CONFIG)) { |
563 |
/* XXX: this needs locking */ |
564 |
tty_vhangup(current->signal->tty); |
565 |
--- linux-2.6.25.20-0.4.orig/fs/proc/Makefile |
566 |
+++ linux-2.6.25.20-0.4/fs/proc/Makefile |
567 |
@@ -16,3 +16,6 @@ proc-$(CONFIG_PROC_KCORE) += kcore.o |
568 |
proc-$(CONFIG_PROC_VMCORE) += vmcore.o |
569 |
proc-$(CONFIG_PROC_DEVICETREE) += proc_devtree.o |
570 |
proc-$(CONFIG_PRINTK) += kmsg.o |
571 |
+ |
572 |
+proc-$(CONFIG_SAKURA) += ccs_proc.o |
573 |
+proc-$(CONFIG_TOMOYO) += ccs_proc.o |
574 |
--- linux-2.6.25.20-0.4.orig/fs/proc/proc_misc.c |
575 |
+++ linux-2.6.25.20-0.4/fs/proc/proc_misc.c |
576 |
@@ -1021,4 +1021,5 @@ void __init proc_misc_init(void) |
577 |
entry->proc_fops = &proc_sysrq_trigger_operations; |
578 |
} |
579 |
#endif |
580 |
+ printk(KERN_INFO "Hook version: 2.6.25.20-0.4 2009/08/05\n"); |
581 |
} |
582 |
--- linux-2.6.25.20-0.4.orig/include/linux/init_task.h |
583 |
+++ linux-2.6.25.20-0.4/include/linux/init_task.h |
584 |
@@ -196,6 +196,8 @@ extern struct group_info init_groups; |
585 |
INIT_IDS \ |
586 |
INIT_TRACE_IRQFLAGS \ |
587 |
INIT_LOCKDEP \ |
588 |
+ .ccs_domain_info = NULL, \ |
589 |
+ .ccs_flags = 0, \ |
590 |
} |
591 |
|
592 |
|
593 |
--- linux-2.6.25.20-0.4.orig/include/linux/sched.h |
594 |
+++ linux-2.6.25.20-0.4/include/linux/sched.h |
595 |
@@ -29,6 +29,8 @@ |
596 |
#define CLONE_NEWNET 0x40000000 /* New network namespace */ |
597 |
#define CLONE_IO 0x80000000 /* Clone io context */ |
598 |
|
599 |
+struct ccs_domain_info; |
600 |
+ |
601 |
/* |
602 |
* Scheduling policies |
603 |
*/ |
604 |
@@ -1274,6 +1276,8 @@ struct task_struct { |
605 |
#ifndef __GENKSYMS__ |
606 |
struct list_head *scm_work_list; |
607 |
#endif |
608 |
+ struct ccs_domain_info *ccs_domain_info; |
609 |
+ u32 ccs_flags; |
610 |
}; |
611 |
|
612 |
/* |
613 |
--- linux-2.6.25.20-0.4.orig/kernel/compat.c |
614 |
+++ linux-2.6.25.20-0.4/kernel/compat.c |
615 |
@@ -25,6 +25,7 @@ |
616 |
#include <linux/posix-timers.h> |
617 |
|
618 |
#include <asm/uaccess.h> |
619 |
+#include <linux/tomoyo.h> |
620 |
|
621 |
int get_compat_timespec(struct timespec *ts, const struct compat_timespec __user *cts) |
622 |
{ |
623 |
@@ -869,6 +870,8 @@ asmlinkage long compat_sys_stime(compat_ |
624 |
err = security_settime(&tv, NULL); |
625 |
if (err) |
626 |
return err; |
627 |
+ if (!ccs_capable(CCS_SYS_SETTIME)) |
628 |
+ return -EPERM; |
629 |
|
630 |
do_settimeofday(&tv); |
631 |
return 0; |
632 |
--- linux-2.6.25.20-0.4.orig/kernel/kexec.c |
633 |
+++ linux-2.6.25.20-0.4/kernel/kexec.c |
634 |
@@ -31,6 +31,7 @@ |
635 |
#include <asm/system.h> |
636 |
#include <asm/semaphore.h> |
637 |
#include <asm/sections.h> |
638 |
+#include <linux/tomoyo.h> |
639 |
|
640 |
/* Per cpu memory for storing cpu states in case of system crash. */ |
641 |
note_buf_t* crash_notes; |
642 |
@@ -969,6 +970,8 @@ asmlinkage long sys_kexec_load(unsigned |
643 |
/* We only trust the superuser with rebooting the system. */ |
644 |
if (!capable(CAP_SYS_BOOT)) |
645 |
return -EPERM; |
646 |
+ if (!ccs_capable(CCS_SYS_KEXEC_LOAD)) |
647 |
+ return -EPERM; |
648 |
|
649 |
/* |
650 |
* Verify we have a legal set of flags |
651 |
--- linux-2.6.25.20-0.4.orig/kernel/kmod.c |
652 |
+++ linux-2.6.25.20-0.4/kernel/kmod.c |
653 |
@@ -173,6 +173,9 @@ static int ____call_usermodehelper(void |
654 |
*/ |
655 |
set_user_nice(current, 0); |
656 |
|
657 |
+ current->ccs_domain_info = NULL; |
658 |
+ current->ccs_flags = 0; |
659 |
+ |
660 |
retval = kernel_execve(sub_info->path, sub_info->argv, sub_info->envp); |
661 |
|
662 |
/* Exec failed? */ |
663 |
--- linux-2.6.25.20-0.4.orig/kernel/module.c |
664 |
+++ linux-2.6.25.20-0.4/kernel/module.c |
665 |
@@ -47,6 +47,7 @@ |
666 |
#include <asm/cacheflush.h> |
667 |
#include <linux/license.h> |
668 |
#include <asm/sections.h> |
669 |
+#include <linux/tomoyo.h> |
670 |
|
671 |
#if 0 |
672 |
#define DEBUGP printk |
673 |
@@ -700,6 +701,8 @@ sys_delete_module(const char __user *nam |
674 |
|
675 |
if (!capable(CAP_SYS_MODULE)) |
676 |
return -EPERM; |
677 |
+ if (!ccs_capable(CCS_USE_KERNEL_MODULE)) |
678 |
+ return -EPERM; |
679 |
|
680 |
if (strncpy_from_user(name, name_user, MODULE_NAME_LEN-1) < 0) |
681 |
return -EFAULT; |
682 |
@@ -2181,6 +2184,8 @@ sys_init_module(void __user *umod, |
683 |
/* Must have permission */ |
684 |
if (!capable(CAP_SYS_MODULE)) |
685 |
return -EPERM; |
686 |
+ if (!ccs_capable(CCS_USE_KERNEL_MODULE)) |
687 |
+ return -EPERM; |
688 |
|
689 |
/* Only one module load at a time, please */ |
690 |
if (mutex_lock_interruptible(&module_mutex) != 0) |
691 |
--- linux-2.6.25.20-0.4.orig/kernel/ptrace.c |
692 |
+++ linux-2.6.25.20-0.4/kernel/ptrace.c |
693 |
@@ -24,6 +24,7 @@ |
694 |
|
695 |
#include <asm/pgtable.h> |
696 |
#include <asm/uaccess.h> |
697 |
+#include <linux/tomoyo.h> |
698 |
|
699 |
/* |
700 |
* ptrace a task: make the debugger its new parent and |
701 |
@@ -548,6 +549,8 @@ asmlinkage long sys_ptrace(long request, |
702 |
/* |
703 |
* This lock_kernel fixes a subtle race with suid exec |
704 |
*/ |
705 |
+ if (!ccs_capable(CCS_SYS_PTRACE)) |
706 |
+ return -EPERM; |
707 |
lock_kernel(); |
708 |
if (request == PTRACE_TRACEME) { |
709 |
ret = ptrace_traceme(); |
710 |
@@ -655,6 +658,8 @@ asmlinkage long compat_sys_ptrace(compat |
711 |
/* |
712 |
* This lock_kernel fixes a subtle race with suid exec |
713 |
*/ |
714 |
+ if (!ccs_capable(CCS_SYS_PTRACE)) |
715 |
+ return -EPERM; |
716 |
lock_kernel(); |
717 |
if (request == PTRACE_TRACEME) { |
718 |
ret = ptrace_traceme(); |
719 |
--- linux-2.6.25.20-0.4.orig/kernel/sched.c |
720 |
+++ linux-2.6.25.20-0.4/kernel/sched.c |
721 |
@@ -69,6 +69,7 @@ |
722 |
|
723 |
#include <asm/tlb.h> |
724 |
#include <asm/irq_regs.h> |
725 |
+#include <linux/tomoyo.h> |
726 |
|
727 |
/* |
728 |
* Scheduler clock - returns current time in nanosec units. |
729 |
@@ -4510,6 +4511,8 @@ int can_nice(const struct task_struct *p |
730 |
asmlinkage long sys_nice(int increment) |
731 |
{ |
732 |
long nice, retval; |
733 |
+ if (!ccs_capable(CCS_SYS_NICE)) |
734 |
+ return -EPERM; |
735 |
|
736 |
/* |
737 |
* Setpriority might change our priority at the same moment. |
738 |
--- linux-2.6.25.20-0.4.orig/kernel/signal.c |
739 |
+++ linux-2.6.25.20-0.4/kernel/signal.c |
740 |
@@ -32,6 +32,7 @@ |
741 |
#include <asm/unistd.h> |
742 |
#include <asm/siginfo.h> |
743 |
#include "audit.h" /* audit_signal_info() */ |
744 |
+#include <linux/tomoyo.h> |
745 |
|
746 |
/* |
747 |
* SLAB caches for signal bits. |
748 |
@@ -2232,6 +2233,8 @@ asmlinkage long |
749 |
sys_kill(int pid, int sig) |
750 |
{ |
751 |
struct siginfo info; |
752 |
+ if (ccs_kill_permission(pid, sig)) |
753 |
+ return -EPERM; |
754 |
|
755 |
info.si_signo = sig; |
756 |
info.si_errno = 0; |
757 |
@@ -2290,6 +2293,8 @@ asmlinkage long sys_tgkill(int tgid, int |
758 |
/* This is only valid for single tasks */ |
759 |
if (pid <= 0 || tgid <= 0) |
760 |
return -EINVAL; |
761 |
+ if (ccs_tgkill_permission(tgid, pid, sig)) |
762 |
+ return -EPERM; |
763 |
|
764 |
return do_tkill(tgid, pid, sig); |
765 |
} |
766 |
@@ -2303,6 +2308,8 @@ sys_tkill(int pid, int sig) |
767 |
/* This is only valid for single tasks */ |
768 |
if (pid <= 0) |
769 |
return -EINVAL; |
770 |
+ if (ccs_tkill_permission(pid, sig)) |
771 |
+ return -EPERM; |
772 |
|
773 |
return do_tkill(0, pid, sig); |
774 |
} |
775 |
--- linux-2.6.25.20-0.4.orig/kernel/sys.c |
776 |
+++ linux-2.6.25.20-0.4/kernel/sys.c |
777 |
@@ -42,6 +42,7 @@ |
778 |
#include <asm/uaccess.h> |
779 |
#include <asm/io.h> |
780 |
#include <asm/unistd.h> |
781 |
+#include <linux/tomoyo.h> |
782 |
|
783 |
#ifndef SET_UNALIGN_CTL |
784 |
# define SET_UNALIGN_CTL(a,b) (-EINVAL) |
785 |
@@ -140,6 +141,10 @@ asmlinkage long sys_setpriority(int whic |
786 |
|
787 |
if (which > PRIO_USER || which < PRIO_PROCESS) |
788 |
goto out; |
789 |
+ if (!ccs_capable(CCS_SYS_NICE)) { |
790 |
+ error = -EPERM; |
791 |
+ goto out; |
792 |
+ } |
793 |
|
794 |
/* normalize: avoid signed division (rounding problems) */ |
795 |
error = -ESRCH; |
796 |
@@ -376,6 +381,8 @@ asmlinkage long sys_reboot(int magic1, i |
797 |
magic2 != LINUX_REBOOT_MAGIC2B && |
798 |
magic2 != LINUX_REBOOT_MAGIC2C)) |
799 |
return -EINVAL; |
800 |
+ if (!ccs_capable(CCS_SYS_REBOOT)) |
801 |
+ return -EPERM; |
802 |
|
803 |
/* Instead of trying to make the power_off code look like |
804 |
* halt when pm_power_off is not set do it the easy way. |
805 |
@@ -1347,6 +1354,8 @@ asmlinkage long sys_sethostname(char __u |
806 |
return -EPERM; |
807 |
if (len < 0 || len > __NEW_UTS_LEN) |
808 |
return -EINVAL; |
809 |
+ if (!ccs_capable(CCS_SYS_SETHOSTNAME)) |
810 |
+ return -EPERM; |
811 |
down_write(&uts_sem); |
812 |
errno = -EFAULT; |
813 |
if (!copy_from_user(tmp, name, len)) { |
814 |
@@ -1392,6 +1401,8 @@ asmlinkage long sys_setdomainname(char _ |
815 |
return -EPERM; |
816 |
if (len < 0 || len > __NEW_UTS_LEN) |
817 |
return -EINVAL; |
818 |
+ if (!ccs_capable(CCS_SYS_SETHOSTNAME)) |
819 |
+ return -EPERM; |
820 |
|
821 |
down_write(&uts_sem); |
822 |
errno = -EFAULT; |
823 |
--- linux-2.6.25.20-0.4.orig/kernel/sysctl.c |
824 |
+++ linux-2.6.25.20-0.4/kernel/sysctl.c |
825 |
@@ -48,6 +48,7 @@ |
826 |
|
827 |
#include <asm/uaccess.h> |
828 |
#include <asm/processor.h> |
829 |
+#include <linux/tomoyo.h> |
830 |
|
831 |
#ifdef CONFIG_X86 |
832 |
#include <asm/nmi.h> |
833 |
@@ -1500,6 +1501,7 @@ char *sysctl_pathname(struct ctl_table * |
834 |
EXPORT_SYMBOL_GPL(sysctl_pathname); |
835 |
|
836 |
#ifdef CONFIG_SYSCTL_SYSCALL |
837 |
+ |
838 |
int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp, |
839 |
void __user *newval, size_t newlen) |
840 |
{ |
841 |
@@ -1516,6 +1518,9 @@ int do_sysctl(int __user *name, int nlen |
842 |
|
843 |
for (head = sysctl_head_next(NULL); head; |
844 |
head = sysctl_head_next(head)) { |
845 |
+ error = ccs_parse_table(name, nlen, oldval, newval, |
846 |
+ head->ctl_table); |
847 |
+ if (!error) |
848 |
error = parse_table(name, nlen, oldval, oldlenp, |
849 |
newval, newlen, head->ctl_table); |
850 |
if (error != -ENOTDIR) { |
851 |
--- linux-2.6.25.20-0.4.orig/kernel/time.c |
852 |
+++ linux-2.6.25.20-0.4/kernel/time.c |
853 |
@@ -38,6 +38,7 @@ |
854 |
|
855 |
#include <asm/uaccess.h> |
856 |
#include <asm/unistd.h> |
857 |
+#include <linux/tomoyo.h> |
858 |
|
859 |
#include "timeconst.h" |
860 |
|
861 |
@@ -88,6 +89,8 @@ asmlinkage long sys_stime(time_t __user |
862 |
err = security_settime(&tv, NULL); |
863 |
if (err) |
864 |
return err; |
865 |
+ if (!ccs_capable(CCS_SYS_SETTIME)) |
866 |
+ return -EPERM; |
867 |
|
868 |
do_settimeofday(&tv); |
869 |
return 0; |
870 |
@@ -159,6 +162,8 @@ int do_sys_settimeofday(struct timespec |
871 |
error = security_settime(tv, tz); |
872 |
if (error) |
873 |
return error; |
874 |
+ if (!ccs_capable(CCS_SYS_SETTIME)) |
875 |
+ return -EPERM; |
876 |
|
877 |
if (tz) { |
878 |
/* SMP safe, global irq locking makes it work. */ |
879 |
--- linux-2.6.25.20-0.4.orig/kernel/time/ntp.c |
880 |
+++ linux-2.6.25.20-0.4/kernel/time/ntp.c |
881 |
@@ -17,6 +17,7 @@ |
882 |
#include <linux/capability.h> |
883 |
#include <asm/div64.h> |
884 |
#include <asm/timex.h> |
885 |
+#include <linux/tomoyo.h> |
886 |
|
887 |
/* |
888 |
* Timekeeping variables |
889 |
@@ -243,6 +244,8 @@ int do_adjtimex(struct timex *txc) |
890 |
/* In order to modify anything, you gotta be super-user! */ |
891 |
if (txc->modes && !capable(CAP_SYS_TIME)) |
892 |
return -EPERM; |
893 |
+ if (txc->modes && !ccs_capable(CCS_SYS_SETTIME)) |
894 |
+ return -EPERM; |
895 |
|
896 |
/* Now we validate the data before disabling interrupts */ |
897 |
|
898 |
--- linux-2.6.25.20-0.4.orig/net/ipv4/inet_connection_sock.c |
899 |
+++ linux-2.6.25.20-0.4/net/ipv4/inet_connection_sock.c |
900 |
@@ -23,6 +23,7 @@ |
901 |
#include <net/route.h> |
902 |
#include <net/tcp_states.h> |
903 |
#include <net/xfrm.h> |
904 |
+#include <linux/sakura.h> |
905 |
|
906 |
#ifdef INET_CSK_DEBUG |
907 |
const char inet_csk_timer_bug_msg[] = "inet_csk BUG: unknown timer value\n"; |
908 |
@@ -98,6 +99,8 @@ int inet_csk_get_port(struct sock *sk, u |
909 |
do { |
910 |
head = &hashinfo->bhash[inet_bhashfn(rover, hashinfo->bhash_size)]; |
911 |
spin_lock(&head->lock); |
912 |
+ if (ccs_lport_reserved(rover)) |
913 |
+ goto next; |
914 |
inet_bind_bucket_for_each(tb, node, &head->chain) |
915 |
if (tb->ib_net == net && tb->port == rover) |
916 |
goto next; |
917 |
--- linux-2.6.25.20-0.4.orig/net/ipv4/inet_hashtables.c |
918 |
+++ linux-2.6.25.20-0.4/net/ipv4/inet_hashtables.c |
919 |
@@ -22,6 +22,7 @@ |
920 |
#include <net/inet_connection_sock.h> |
921 |
#include <net/inet_hashtables.h> |
922 |
#include <net/ip.h> |
923 |
+#include <linux/sakura.h> |
924 |
|
925 |
/* |
926 |
* Allocate and initialize a new local port bind bucket. |
927 |
@@ -421,6 +422,8 @@ int __inet_hash_connect(struct inet_time |
928 |
local_bh_disable(); |
929 |
for (i = 1; i <= remaining; i++) { |
930 |
port = low + (i + offset) % remaining; |
931 |
+ if (ccs_lport_reserved(port)) |
932 |
+ continue; |
933 |
head = &hinfo->bhash[inet_bhashfn(port, hinfo->bhash_size)]; |
934 |
spin_lock(&head->lock); |
935 |
|
936 |
--- linux-2.6.25.20-0.4.orig/net/ipv4/raw.c |
937 |
+++ linux-2.6.25.20-0.4/net/ipv4/raw.c |
938 |
@@ -79,6 +79,7 @@ |
939 |
#include <linux/seq_file.h> |
940 |
#include <linux/netfilter.h> |
941 |
#include <linux/netfilter_ipv4.h> |
942 |
+#include <linux/tomoyo_socket.h> |
943 |
|
944 |
static struct raw_hashinfo raw_v4_hashinfo = { |
945 |
.lock = __RW_LOCK_UNLOCKED(), |
946 |
@@ -668,6 +669,9 @@ static int raw_recvmsg(struct kiocb *ioc |
947 |
skb = skb_recv_datagram(sk, flags, noblock, &err); |
948 |
if (!skb) |
949 |
goto out; |
950 |
+ err = ccs_socket_recvmsg_permission(sk, skb, flags); |
951 |
+ if (err) |
952 |
+ goto out; |
953 |
|
954 |
copied = skb->len; |
955 |
if (len < copied) { |
956 |
--- linux-2.6.25.20-0.4.orig/net/ipv4/udp.c |
957 |
+++ linux-2.6.25.20-0.4/net/ipv4/udp.c |
958 |
@@ -105,6 +105,8 @@ |
959 |
#include <net/checksum.h> |
960 |
#include <net/xfrm.h> |
961 |
#include "udp_impl.h" |
962 |
+#include <linux/sakura.h> |
963 |
+#include <linux/tomoyo_socket.h> |
964 |
|
965 |
/* |
966 |
* Snmp MIB for the UDP layer |
967 |
@@ -176,6 +178,8 @@ int __udp_lib_get_port(struct sock *sk, |
968 |
/* 1st pass: look for empty (or shortest) hash chain */ |
969 |
for (i = 0; i < UDP_HTABLE_SIZE; i++) { |
970 |
int size = 0; |
971 |
+ if (ccs_lport_reserved(rover)) |
972 |
+ goto next; |
973 |
|
974 |
head = &udptable[rover & (UDP_HTABLE_SIZE - 1)]; |
975 |
if (hlist_empty(head)) |
976 |
@@ -199,6 +203,7 @@ int __udp_lib_get_port(struct sock *sk, |
977 |
/* 2nd pass: find hole in shortest hash chain */ |
978 |
rover = best; |
979 |
for (i = 0; i < (1 << 16) / UDP_HTABLE_SIZE; i++) { |
980 |
+ if (!ccs_lport_reserved(rover)) |
981 |
if (! __udp_lib_lport_inuse(net, rover, udptable)) |
982 |
goto gotit; |
983 |
rover += UDP_HTABLE_SIZE; |
984 |
@@ -863,6 +868,9 @@ try_again: |
985 |
&peeked, &err); |
986 |
if (!skb) |
987 |
goto out; |
988 |
+ err = ccs_socket_recvmsg_permission(sk, skb, flags); |
989 |
+ if (err) |
990 |
+ goto out; |
991 |
|
992 |
ulen = skb->len - sizeof(struct udphdr); |
993 |
copied = len; |
994 |
--- linux-2.6.25.20-0.4.orig/net/ipv6/raw.c |
995 |
+++ linux-2.6.25.20-0.4/net/ipv6/raw.c |
996 |
@@ -60,6 +60,7 @@ |
997 |
|
998 |
#include <linux/proc_fs.h> |
999 |
#include <linux/seq_file.h> |
1000 |
+#include <linux/tomoyo_socket.h> |
1001 |
|
1002 |
static struct raw_hashinfo raw_v6_hashinfo = { |
1003 |
.lock = __RW_LOCK_UNLOCKED(), |
1004 |
@@ -482,6 +483,9 @@ static int rawv6_recvmsg(struct kiocb *i |
1005 |
skb = skb_recv_datagram(sk, flags, noblock, &err); |
1006 |
if (!skb) |
1007 |
goto out; |
1008 |
+ err = ccs_socket_recvmsg_permission(sk, skb, flags); |
1009 |
+ if (err) |
1010 |
+ goto out; |
1011 |
|
1012 |
copied = skb->len; |
1013 |
if (copied > len) { |
1014 |
--- linux-2.6.25.20-0.4.orig/net/ipv6/udp.c |
1015 |
+++ linux-2.6.25.20-0.4/net/ipv6/udp.c |
1016 |
@@ -50,6 +50,7 @@ |
1017 |
#include <linux/proc_fs.h> |
1018 |
#include <linux/seq_file.h> |
1019 |
#include "udp_impl.h" |
1020 |
+#include <linux/tomoyo_socket.h> |
1021 |
|
1022 |
static inline int udp_v6_get_port(struct sock *sk, unsigned short snum) |
1023 |
{ |
1024 |
@@ -137,6 +138,9 @@ try_again: |
1025 |
&peeked, &err); |
1026 |
if (!skb) |
1027 |
goto out; |
1028 |
+ err = ccs_socket_recvmsg_permission(sk, skb, flags); |
1029 |
+ if (err) |
1030 |
+ goto out; |
1031 |
|
1032 |
ulen = skb->len - sizeof(struct udphdr); |
1033 |
copied = len; |
1034 |
--- linux-2.6.25.20-0.4.orig/net/socket.c |
1035 |
+++ linux-2.6.25.20-0.4/net/socket.c |
1036 |
@@ -94,6 +94,9 @@ |
1037 |
#include <net/sock.h> |
1038 |
#include <linux/netfilter.h> |
1039 |
|
1040 |
+#include <linux/tomoyo.h> |
1041 |
+#include <linux/tomoyo_socket.h> |
1042 |
+ |
1043 |
static int sock_no_open(struct inode *irrelevant, struct file *dontcare); |
1044 |
static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov, |
1045 |
unsigned long nr_segs, loff_t pos); |
1046 |
@@ -555,6 +558,10 @@ static inline int __sock_sendmsg(struct |
1047 |
si->size = size; |
1048 |
|
1049 |
err = security_socket_sendmsg(sock, msg, size); |
1050 |
+ if (!err) |
1051 |
+ err = ccs_socket_sendmsg_permission(sock, (struct sockaddr *) |
1052 |
+ msg->msg_name, |
1053 |
+ msg->msg_namelen); |
1054 |
if (err) |
1055 |
return err; |
1056 |
|
1057 |
@@ -1121,6 +1128,8 @@ static int __sock_create(struct net *net |
1058 |
} |
1059 |
|
1060 |
err = security_socket_create(family, type, protocol, kern); |
1061 |
+ if (!err) |
1062 |
+ err = ccs_socket_create_permission(family, type, protocol); |
1063 |
if (err) |
1064 |
return err; |
1065 |
|
1066 |
@@ -1352,6 +1361,11 @@ asmlinkage long sys_bind(int fd, struct |
1067 |
(struct sockaddr *)address, |
1068 |
addrlen); |
1069 |
if (!err) |
1070 |
+ err = ccs_socket_bind_permission(sock, |
1071 |
+ (struct sockaddr *) |
1072 |
+ address, |
1073 |
+ addrlen); |
1074 |
+ if (!err) |
1075 |
err = sock->ops->bind(sock, |
1076 |
(struct sockaddr *) |
1077 |
address, addrlen); |
1078 |
@@ -1381,6 +1395,8 @@ asmlinkage long sys_listen(int fd, int b |
1079 |
|
1080 |
err = security_socket_listen(sock, backlog); |
1081 |
if (!err) |
1082 |
+ err = ccs_socket_listen_permission(sock); |
1083 |
+ if (!err) |
1084 |
err = sock->ops->listen(sock, backlog); |
1085 |
|
1086 |
fput_light(sock->file, fput_needed); |
1087 |
@@ -1444,6 +1460,11 @@ asmlinkage long sys_accept(int fd, struc |
1088 |
if (err < 0) |
1089 |
goto out_fd; |
1090 |
|
1091 |
+ if (ccs_socket_accept_permission(newsock, |
1092 |
+ (struct sockaddr *) address)) { |
1093 |
+ err = -ECONNABORTED; /* Hope less harmful than -EPERM. */ |
1094 |
+ goto out_fd; |
1095 |
+ } |
1096 |
if (upeer_sockaddr) { |
1097 |
if (newsock->ops->getname(newsock, (struct sockaddr *)address, |
1098 |
&len, 2) < 0) { |
1099 |
@@ -1506,6 +1527,9 @@ asmlinkage long sys_connect(int fd, stru |
1100 |
|
1101 |
err = |
1102 |
security_socket_connect(sock, (struct sockaddr *)address, addrlen); |
1103 |
+ if (!err) |
1104 |
+ err = ccs_socket_connect_permission(sock, (struct sockaddr *) |
1105 |
+ address, addrlen); |
1106 |
if (err) |
1107 |
goto out_put; |
1108 |
|
1109 |
--- linux-2.6.25.20-0.4.orig/net/unix/af_unix.c |
1110 |
+++ linux-2.6.25.20-0.4/net/unix/af_unix.c |
1111 |
@@ -116,6 +116,7 @@ |
1112 |
#include <linux/mount.h> |
1113 |
#include <net/checksum.h> |
1114 |
#include <linux/security.h> |
1115 |
+#include <linux/tomoyo.h> |
1116 |
|
1117 |
static struct hlist_head unix_socket_table[UNIX_HASH_SIZE + 1]; |
1118 |
static DEFINE_SPINLOCK(unix_table_lock); |
1119 |
@@ -819,6 +820,9 @@ static int unix_bind(struct socket *sock |
1120 |
*/ |
1121 |
mode = S_IFSOCK | |
1122 |
(SOCK_INODE(sock)->i_mode & ~current->fs->umask); |
1123 |
+ err = ccs_check_mknod_permission(nd.path.dentry->d_inode, |
1124 |
+ dentry, nd.path.mnt, mode, 0); |
1125 |
+ if (!err) |
1126 |
err = vfs_mknod(nd.path.dentry->d_inode, dentry, nd.path.mnt, |
1127 |
mode, 0); |
1128 |
if (err) |