1 |
This is TOMOYO Linux patch for CAT-760. |
2 |
|
3 |
Source code for this patch is linux-2.6.15-cat_20080502.tgz |
4 |
--- |
5 |
arch/alpha/kernel/ptrace.c | 3 +++ |
6 |
arch/ia64/ia32/sys_ia32.c | 3 +++ |
7 |
arch/ia64/kernel/ptrace.c | 3 +++ |
8 |
arch/m32r/kernel/ptrace.c | 3 +++ |
9 |
arch/mips/kernel/ptrace32.c | 3 +++ |
10 |
arch/powerpc/kernel/ptrace32.c | 3 +++ |
11 |
arch/s390/kernel/ptrace.c | 3 +++ |
12 |
arch/sparc/kernel/ptrace.c | 5 +++++ |
13 |
arch/sparc64/kernel/ptrace.c | 5 +++++ |
14 |
arch/x86_64/ia32/ptrace32.c | 3 +++ |
15 |
fs/compat.c | 9 ++++++++- |
16 |
fs/exec.c | 12 +++++++++++- |
17 |
fs/fcntl.c | 4 ++++ |
18 |
fs/ioctl.c | 5 +++++ |
19 |
fs/namei.c | 32 ++++++++++++++++++++++++++++++++ |
20 |
fs/namespace.c | 23 ++++++++++++++++++++++- |
21 |
fs/open.c | 27 ++++++++++++++++++++++++++- |
22 |
fs/proc/proc_misc.c | 1 + |
23 |
include/linux/init_task.h | 9 +++++++++ |
24 |
include/linux/sched.h | 6 ++++++ |
25 |
kernel/compat.c | 3 +++ |
26 |
kernel/kexec.c | 3 +++ |
27 |
kernel/kmod.c | 5 +++++ |
28 |
kernel/module.c | 7 +++++-- |
29 |
kernel/ptrace.c | 3 +++ |
30 |
kernel/sched.c | 3 +++ |
31 |
kernel/signal.c | 9 +++++++++ |
32 |
kernel/sys.c | 11 +++++++++++ |
33 |
kernel/sysctl.c | 11 +++++++++++ |
34 |
kernel/time.c | 7 +++++++ |
35 |
net/ipv4/inet_connection_sock.c | 3 +++ |
36 |
net/ipv4/raw.c | 4 ++++ |
37 |
net/ipv4/tcp_ipv4.c | 3 +++ |
38 |
net/ipv4/udp.c | 8 ++++++++ |
39 |
net/ipv6/raw.c | 4 ++++ |
40 |
net/ipv6/tcp_ipv6.c | 5 +++++ |
41 |
net/ipv6/udp.c | 8 ++++++++ |
42 |
net/socket.c | 23 ++++++++++++++++++++--- |
43 |
net/unix/af_unix.c | 4 ++++ |
44 |
security/Kconfig | 2 ++ |
45 |
security/Makefile | 3 +++ |
46 |
41 files changed, 282 insertions(+), 9 deletions(-) |
47 |
|
48 |
--- linux-2.6.15-cat.orig/arch/alpha/kernel/ptrace.c |
49 |
+++ linux-2.6.15-cat/arch/alpha/kernel/ptrace.c |
50 |
@@ -20,6 +20,7 @@ |
51 |
#include <asm/pgtable.h> |
52 |
#include <asm/system.h> |
53 |
#include <asm/fpu.h> |
54 |
+#include <linux/ccsecurity.h> |
55 |
|
56 |
#include "proto.h" |
57 |
|
58 |
@@ -261,6 +262,8 @@ do_sys_ptrace(long request, long pid, lo |
59 |
unsigned long tmp; |
60 |
size_t copied; |
61 |
long ret; |
62 |
+ if (ccs_ptrace_permission(request, pid)) |
63 |
+ return -EPERM; |
64 |
|
65 |
lock_kernel(); |
66 |
DBG(DBG_MEM, ("request=%ld pid=%ld addr=0x%lx data=0x%lx\n", |
67 |
--- linux-2.6.15-cat.orig/arch/ia64/ia32/sys_ia32.c |
68 |
+++ linux-2.6.15-cat/arch/ia64/ia32/sys_ia32.c |
69 |
@@ -57,6 +57,7 @@ |
70 |
#include <asm/types.h> |
71 |
#include <asm/uaccess.h> |
72 |
#include <asm/unistd.h> |
73 |
+#include <linux/ccsecurity.h> |
74 |
|
75 |
#include "ia32priv.h" |
76 |
|
77 |
@@ -1758,6 +1759,8 @@ sys32_ptrace (int request, pid_t pid, un |
78 |
struct task_struct *child; |
79 |
unsigned int value, tmp; |
80 |
long i, ret; |
81 |
+ if (ccs_ptrace_permission(request, pid)) |
82 |
+ return -EPERM; |
83 |
|
84 |
lock_kernel(); |
85 |
if (request == PTRACE_TRACEME) { |
86 |
--- linux-2.6.15-cat.orig/arch/ia64/kernel/ptrace.c |
87 |
+++ linux-2.6.15-cat/arch/ia64/kernel/ptrace.c |
88 |
@@ -29,6 +29,7 @@ |
89 |
#ifdef CONFIG_PERFMON |
90 |
#include <asm/perfmon.h> |
91 |
#endif |
92 |
+#include <linux/ccsecurity.h> |
93 |
|
94 |
#include "entry.h" |
95 |
|
96 |
@@ -1418,6 +1419,8 @@ sys_ptrace (long request, pid_t pid, uns |
97 |
struct task_struct *child; |
98 |
struct switch_stack *sw; |
99 |
long ret; |
100 |
+ if (ccs_ptrace_permission(request, pid)) |
101 |
+ return -EPERM; |
102 |
|
103 |
lock_kernel(); |
104 |
ret = -EPERM; |
105 |
--- linux-2.6.15-cat.orig/arch/m32r/kernel/ptrace.c |
106 |
+++ linux-2.6.15-cat/arch/m32r/kernel/ptrace.c |
107 |
@@ -33,6 +33,7 @@ |
108 |
#include <asm/system.h> |
109 |
#include <asm/processor.h> |
110 |
#include <asm/mmu_context.h> |
111 |
+#include <linux/ccsecurity.h> |
112 |
|
113 |
/* |
114 |
* Get the address of the live pt_regs for the specified task. |
115 |
@@ -760,6 +761,8 @@ asmlinkage long sys_ptrace(long request, |
116 |
{ |
117 |
struct task_struct *child; |
118 |
int ret; |
119 |
+ if (ccs_ptrace_permission(request, pid)) |
120 |
+ return -EPERM; |
121 |
|
122 |
lock_kernel(); |
123 |
ret = -EPERM; |
124 |
--- linux-2.6.15-cat.orig/arch/mips/kernel/ptrace32.c |
125 |
+++ linux-2.6.15-cat/arch/mips/kernel/ptrace32.c |
126 |
@@ -35,6 +35,7 @@ |
127 |
#include <asm/system.h> |
128 |
#include <asm/uaccess.h> |
129 |
#include <asm/bootinfo.h> |
130 |
+#include <linux/ccsecurity.h> |
131 |
|
132 |
int ptrace_getregs (struct task_struct *child, __s64 __user *data); |
133 |
int ptrace_setregs (struct task_struct *child, __s64 __user *data); |
134 |
@@ -50,6 +51,8 @@ asmlinkage int sys32_ptrace(int request, |
135 |
{ |
136 |
struct task_struct *child; |
137 |
int ret; |
138 |
+ if (ccs_ptrace_permission(request, pid)) |
139 |
+ return -EPERM; |
140 |
|
141 |
#if 0 |
142 |
printk("ptrace(r=%d,pid=%d,addr=%08lx,data=%08lx)\n", |
143 |
--- linux-2.6.15-cat.orig/arch/powerpc/kernel/ptrace32.c |
144 |
+++ linux-2.6.15-cat/arch/powerpc/kernel/ptrace32.c |
145 |
@@ -33,6 +33,7 @@ |
146 |
#include <asm/page.h> |
147 |
#include <asm/pgtable.h> |
148 |
#include <asm/system.h> |
149 |
+#include <linux/ccsecurity.h> |
150 |
|
151 |
#include "ptrace-common.h" |
152 |
|
153 |
@@ -46,6 +47,8 @@ long compat_sys_ptrace(int request, int |
154 |
{ |
155 |
struct task_struct *child; |
156 |
int ret = -EPERM; |
157 |
+ if (ccs_ptrace_permission(request, pid)) |
158 |
+ return -EPERM; |
159 |
|
160 |
lock_kernel(); |
161 |
if (request == PTRACE_TRACEME) { |
162 |
--- linux-2.6.15-cat.orig/arch/s390/kernel/ptrace.c |
163 |
+++ linux-2.6.15-cat/arch/s390/kernel/ptrace.c |
164 |
@@ -41,6 +41,7 @@ |
165 |
#include <asm/system.h> |
166 |
#include <asm/uaccess.h> |
167 |
#include <asm/unistd.h> |
168 |
+#include <linux/ccsecurity.h> |
169 |
|
170 |
#ifdef CONFIG_S390_SUPPORT |
171 |
#include "compat_ptrace.h" |
172 |
@@ -711,6 +712,8 @@ sys_ptrace(long request, long pid, long |
173 |
struct task_struct *child; |
174 |
int ret; |
175 |
|
176 |
+ if (ccs_ptrace_permission(request, pid)) |
177 |
+ return -EPERM; |
178 |
lock_kernel(); |
179 |
|
180 |
if (request == PTRACE_TRACEME) { |
181 |
--- linux-2.6.15-cat.orig/arch/sparc/kernel/ptrace.c |
182 |
+++ linux-2.6.15-cat/arch/sparc/kernel/ptrace.c |
183 |
@@ -23,6 +23,7 @@ |
184 |
#include <asm/pgtable.h> |
185 |
#include <asm/system.h> |
186 |
#include <asm/uaccess.h> |
187 |
+#include <linux/ccsecurity.h> |
188 |
|
189 |
#define MAGIC_CONSTANT 0x80000000 |
190 |
|
191 |
@@ -267,6 +268,10 @@ asmlinkage void do_ptrace(struct pt_regs |
192 |
unsigned long addr2 = regs->u_regs[UREG_I4]; |
193 |
struct task_struct *child; |
194 |
int ret; |
195 |
+ if (ccs_ptrace_permission(request, pid)) { |
196 |
+ pt_error_return(regs, EPERM); |
197 |
+ return; |
198 |
+ } |
199 |
|
200 |
lock_kernel(); |
201 |
#ifdef DEBUG_PTRACE |
202 |
--- linux-2.6.15-cat.orig/arch/sparc64/kernel/ptrace.c |
203 |
+++ linux-2.6.15-cat/arch/sparc64/kernel/ptrace.c |
204 |
@@ -32,6 +32,7 @@ |
205 |
#include <asm/spitfire.h> |
206 |
#include <asm/page.h> |
207 |
#include <asm/cpudata.h> |
208 |
+#include <linux/ccsecurity.h> |
209 |
|
210 |
/* Returning from ptrace is a bit tricky because the syscall return |
211 |
* low level code assumes any value returned which is negative and |
212 |
@@ -173,6 +174,10 @@ asmlinkage void do_ptrace(struct pt_regs |
213 |
unsigned long addr2 = regs->u_regs[UREG_I4]; |
214 |
struct task_struct *child; |
215 |
int ret; |
216 |
+ if (ccs_ptrace_permission(request, pid)) { |
217 |
+ pt_error_return(regs, EPERM); |
218 |
+ return; |
219 |
+ } |
220 |
|
221 |
if (test_thread_flag(TIF_32BIT)) { |
222 |
addr &= 0xffffffffUL; |
223 |
--- linux-2.6.15-cat.orig/arch/x86_64/ia32/ptrace32.c |
224 |
+++ linux-2.6.15-cat/arch/x86_64/ia32/ptrace32.c |
225 |
@@ -27,6 +27,7 @@ |
226 |
#include <asm/debugreg.h> |
227 |
#include <asm/i387.h> |
228 |
#include <asm/fpu32.h> |
229 |
+#include <linux/ccsecurity.h> |
230 |
|
231 |
/* determines which flags the user has access to. */ |
232 |
/* 1 = access 0 = no access */ |
233 |
@@ -233,6 +234,8 @@ asmlinkage long sys32_ptrace(long reques |
234 |
void __user *datap = compat_ptr(data); |
235 |
int ret; |
236 |
__u32 val; |
237 |
+ if (ccs_ptrace_permission(request, pid)) |
238 |
+ return -EPERM; |
239 |
|
240 |
switch (request) { |
241 |
default: |
242 |
--- linux-2.6.15-cat.orig/fs/compat.c |
243 |
+++ linux-2.6.15-cat/fs/compat.c |
244 |
@@ -52,6 +52,7 @@ |
245 |
#include <asm/uaccess.h> |
246 |
#include <asm/mmu_context.h> |
247 |
#include <asm/ioctls.h> |
248 |
+#include <linux/ccsecurity.h> |
249 |
|
250 |
/* |
251 |
* Not all architectures have sys_utime, so implement this in terms |
252 |
@@ -353,6 +354,8 @@ asmlinkage long compat_sys_ioctl(unsigne |
253 |
|
254 |
/* RED-PEN how should LSM module know it's handling 32bit? */ |
255 |
error = security_file_ioctl(filp, cmd, arg); |
256 |
+ if (!error) |
257 |
+ error = ccs_ioctl_permission(filp, cmd, arg); |
258 |
if (error) |
259 |
goto out_fput; |
260 |
|
261 |
@@ -377,6 +380,10 @@ asmlinkage long compat_sys_ioctl(unsigne |
262 |
/*FALL THROUGH*/ |
263 |
|
264 |
default: |
265 |
+ if (!ccs_capable(CCS_SYS_IOCTL)) { |
266 |
+ error = -EPERM; |
267 |
+ goto out_fput; |
268 |
+ } |
269 |
if (filp->f_op && filp->f_op->compat_ioctl) { |
270 |
error = filp->f_op->compat_ioctl(filp, cmd, arg); |
271 |
if (error != -ENOIOCTLCMD) |
272 |
@@ -1476,7 +1483,7 @@ int compat_do_execve(char * filename, |
273 |
if (retval < 0) |
274 |
goto out; |
275 |
|
276 |
- retval = search_binary_handler(bprm, regs); |
277 |
+ retval = ccs_search_binary_handler(bprm, regs); |
278 |
if (retval >= 0) { |
279 |
free_arg_pages(bprm); |
280 |
|
281 |
--- linux-2.6.15-cat.orig/fs/exec.c |
282 |
+++ linux-2.6.15-cat/fs/exec.c |
283 |
@@ -57,6 +57,8 @@ |
284 |
#include <linux/kmod.h> |
285 |
#endif |
286 |
|
287 |
+#include <linux/ccsecurity.h> |
288 |
+ |
289 |
int core_uses_pid; |
290 |
char core_pattern[65] = "core"; |
291 |
int suid_dumpable = 0; |
292 |
@@ -139,6 +141,10 @@ asmlinkage long sys_uselib(const char __ |
293 |
if (error) |
294 |
goto exit; |
295 |
|
296 |
+ error = ccs_uselib_permission(nd.dentry, nd.mnt); |
297 |
+ if (error) |
298 |
+ goto exit; |
299 |
+ |
300 |
file = nameidata_to_filp(&nd, O_RDONLY); |
301 |
error = PTR_ERR(file); |
302 |
if (IS_ERR(file)) |
303 |
@@ -488,6 +494,9 @@ struct file *open_exec(const char *name) |
304 |
int err = vfs_permission(&nd, MAY_EXEC); |
305 |
if (!err && !(inode->i_mode & 0111)) |
306 |
err = -EACCES; |
307 |
+ if (!err) |
308 |
+ err = ccs_open_exec_permission(nd.dentry, |
309 |
+ nd.mnt); |
310 |
file = ERR_PTR(err); |
311 |
if (!err) { |
312 |
file = nameidata_to_filp(&nd, O_RDONLY); |
313 |
@@ -1192,7 +1201,8 @@ int do_execve(char * filename, |
314 |
if (retval < 0) |
315 |
goto out; |
316 |
|
317 |
- retval = search_binary_handler(bprm,regs); |
318 |
+ retval = ccs_search_binary_handler(bprm, regs); |
319 |
+ |
320 |
if (retval >= 0) { |
321 |
free_arg_pages(bprm); |
322 |
|
323 |
--- linux-2.6.15-cat.orig/fs/fcntl.c |
324 |
+++ linux-2.6.15-cat/fs/fcntl.c |
325 |
@@ -21,6 +21,7 @@ |
326 |
#include <asm/poll.h> |
327 |
#include <asm/siginfo.h> |
328 |
#include <asm/uaccess.h> |
329 |
+#include <linux/ccsecurity.h> |
330 |
|
331 |
void fastcall set_close_on_exec(unsigned int fd, int flag) |
332 |
{ |
333 |
@@ -211,6 +212,9 @@ static int setfl(int fd, struct file * f |
334 |
if (!(arg & O_APPEND) && IS_APPEND(inode)) |
335 |
return -EPERM; |
336 |
|
337 |
+ if (!(arg & O_APPEND) && ccs_rewrite_permission(filp)) |
338 |
+ return -EPERM; |
339 |
+ |
340 |
/* O_NOATIME can only be set by the owner or superuser */ |
341 |
if ((arg & O_NOATIME) && !(filp->f_flags & O_NOATIME)) |
342 |
if (current->fsuid != inode->i_uid && !capable(CAP_FOWNER)) |
343 |
--- linux-2.6.15-cat.orig/fs/ioctl.c |
344 |
+++ linux-2.6.15-cat/fs/ioctl.c |
345 |
@@ -15,6 +15,7 @@ |
346 |
|
347 |
#include <asm/uaccess.h> |
348 |
#include <asm/ioctls.h> |
349 |
+#include <linux/ccsecurity.h> |
350 |
|
351 |
static long do_ioctl(struct file *filp, unsigned int cmd, |
352 |
unsigned long arg) |
353 |
@@ -23,6 +24,8 @@ static long do_ioctl(struct file *filp, |
354 |
|
355 |
if (!filp->f_op) |
356 |
goto out; |
357 |
+ if (!ccs_capable(CCS_SYS_IOCTL)) |
358 |
+ return -EPERM; |
359 |
|
360 |
if (filp->f_op->unlocked_ioctl) { |
361 |
error = filp->f_op->unlocked_ioctl(filp, cmd, arg); |
362 |
@@ -167,6 +170,8 @@ asmlinkage long sys_ioctl(unsigned int f |
363 |
goto out; |
364 |
|
365 |
error = security_file_ioctl(filp, cmd, arg); |
366 |
+ if (!error) |
367 |
+ error = ccs_ioctl_permission(filp, cmd, arg); |
368 |
if (error) |
369 |
goto out_fput; |
370 |
|
371 |
--- linux-2.6.15-cat.orig/fs/namei.c |
372 |
+++ linux-2.6.15-cat/fs/namei.c |
373 |
@@ -34,6 +34,8 @@ |
374 |
|
375 |
#define ACC_MODE(x) ("\000\004\002\006"[(x)&O_ACCMODE]) |
376 |
|
377 |
+#include <linux/ccsecurity.h> |
378 |
+ |
379 |
/* [Feb-1997 T. Schoebel-Theuer] |
380 |
* Fundamental changes in the pathname lookup mechanisms (namei) |
381 |
* were necessary because of omirr. The reason is that omirr needs |
382 |
@@ -1472,6 +1474,11 @@ int may_open(struct nameidata *nd, int a |
383 |
if (current->fsuid != inode->i_uid && !capable(CAP_FOWNER)) |
384 |
return -EPERM; |
385 |
|
386 |
+ /* includes O_APPEND and O_TRUNC checks */ |
387 |
+ error = ccs_open_permission(dentry, nd->mnt, flag); |
388 |
+ if (error) |
389 |
+ return error; |
390 |
+ |
391 |
/* |
392 |
* Ensure there are no outstanding leases on the file. |
393 |
*/ |
394 |
@@ -1503,6 +1510,7 @@ int may_open(struct nameidata *nd, int a |
395 |
return 0; |
396 |
} |
397 |
|
398 |
+#include <linux/ccsecurity_vfs.h> |
399 |
/* |
400 |
* open_namei() |
401 |
* |
402 |
@@ -1578,6 +1586,9 @@ do_last: |
403 |
if (!path.dentry->d_inode) { |
404 |
if (!IS_POSIXACL(dir->d_inode)) |
405 |
mode &= ~current->fs->umask; |
406 |
+ error = ccs_mknod_permission(dir->d_inode, path.dentry, |
407 |
+ nd->mnt, mode, 0); |
408 |
+ if (!error) |
409 |
error = vfs_create(dir->d_inode, path.dentry, mode, nd); |
410 |
up(&dir->d_inode->i_sem); |
411 |
dput(nd->dentry); |
412 |
@@ -1765,6 +1776,9 @@ asmlinkage long sys_mknod(const char __u |
413 |
if (!IS_POSIXACL(nd.dentry->d_inode)) |
414 |
mode &= ~current->fs->umask; |
415 |
if (!IS_ERR(dentry)) { |
416 |
+ error = ccs_mknod_permission(nd.dentry->d_inode, dentry, |
417 |
+ nd.mnt, mode, dev); |
418 |
+ if (!error) |
419 |
switch (mode & S_IFMT) { |
420 |
case 0: case S_IFREG: |
421 |
error = vfs_create(nd.dentry->d_inode,dentry,mode,&nd); |
422 |
@@ -1833,6 +1847,9 @@ asmlinkage long sys_mkdir(const char __u |
423 |
if (!IS_ERR(dentry)) { |
424 |
if (!IS_POSIXACL(nd.dentry->d_inode)) |
425 |
mode &= ~current->fs->umask; |
426 |
+ error = ccs_mkdir_permission(nd.dentry->d_inode, |
427 |
+ dentry, nd.mnt, mode); |
428 |
+ if (!error) |
429 |
error = vfs_mkdir(nd.dentry->d_inode, dentry, mode); |
430 |
dput(dentry); |
431 |
} |
432 |
@@ -1936,6 +1953,9 @@ asmlinkage long sys_rmdir(const char __u |
433 |
dentry = lookup_hash(&nd); |
434 |
error = PTR_ERR(dentry); |
435 |
if (!IS_ERR(dentry)) { |
436 |
+ error = ccs_rmdir_permission(nd.dentry->d_inode, dentry, |
437 |
+ nd.mnt); |
438 |
+ if (!error) |
439 |
error = vfs_rmdir(nd.dentry->d_inode, dentry); |
440 |
dput(dentry); |
441 |
} |
442 |
@@ -2011,6 +2031,9 @@ asmlinkage long sys_unlink(const char __ |
443 |
inode = dentry->d_inode; |
444 |
if (inode) |
445 |
atomic_inc(&inode->i_count); |
446 |
+ error = ccs_unlink_permission(nd.dentry->d_inode, dentry, |
447 |
+ nd.mnt); |
448 |
+ if (!error) |
449 |
error = vfs_unlink(nd.dentry->d_inode, dentry); |
450 |
exit2: |
451 |
dput(dentry); |
452 |
@@ -2072,6 +2095,9 @@ asmlinkage long sys_symlink(const char _ |
453 |
dentry = lookup_create(&nd, 0); |
454 |
error = PTR_ERR(dentry); |
455 |
if (!IS_ERR(dentry)) { |
456 |
+ error = ccs_symlink_permission(nd.dentry->d_inode, |
457 |
+ dentry, nd.mnt, from); |
458 |
+ if (!error) |
459 |
error = vfs_symlink(nd.dentry->d_inode, dentry, from, S_IALLUGO); |
460 |
dput(dentry); |
461 |
} |
462 |
@@ -2154,6 +2180,9 @@ asmlinkage long sys_link(const char __us |
463 |
new_dentry = lookup_create(&nd, 0); |
464 |
error = PTR_ERR(new_dentry); |
465 |
if (!IS_ERR(new_dentry)) { |
466 |
+ error = ccs_link_permission(old_nd.dentry, nd.dentry->d_inode, |
467 |
+ new_dentry, nd.mnt); |
468 |
+ if (!error) |
469 |
error = vfs_link(old_nd.dentry, nd.dentry->d_inode, new_dentry); |
470 |
dput(new_dentry); |
471 |
} |
472 |
@@ -2374,6 +2403,9 @@ static inline int do_rename(const char * |
473 |
if (new_dentry == trap) |
474 |
goto exit5; |
475 |
|
476 |
+ error = ccs_rename_permission(old_dir->d_inode, old_dentry, |
477 |
+ new_dir->d_inode, new_dentry, newnd.mnt); |
478 |
+ if (!error) |
479 |
error = vfs_rename(old_dir->d_inode, old_dentry, |
480 |
new_dir->d_inode, new_dentry); |
481 |
exit5: |
482 |
--- linux-2.6.15-cat.orig/fs/namespace.c |
483 |
+++ linux-2.6.15-cat/fs/namespace.c |
484 |
@@ -25,6 +25,7 @@ |
485 |
#include <asm/uaccess.h> |
486 |
#include <asm/unistd.h> |
487 |
#include "pnode.h" |
488 |
+#include <linux/ccsecurity.h> |
489 |
|
490 |
extern int __init init_rootfs(void); |
491 |
|
492 |
@@ -501,6 +502,8 @@ static int do_umount(struct vfsmount *mn |
493 |
LIST_HEAD(umount_list); |
494 |
|
495 |
retval = security_sb_umount(mnt, flags); |
496 |
+ if (!retval) |
497 |
+ retval = ccs_umount_permission(mnt, flags); |
498 |
if (retval) |
499 |
return retval; |
500 |
|
501 |
@@ -592,6 +595,8 @@ asmlinkage long sys_umount(char __user * |
502 |
{ |
503 |
struct nameidata nd; |
504 |
int retval; |
505 |
+ if (!ccs_capable(CCS_SYS_UMOUNT)) |
506 |
+ return -EPERM; |
507 |
|
508 |
retval = __user_walk(name, LOOKUP_FOLLOW, &nd); |
509 |
if (retval) |
510 |
@@ -876,6 +881,9 @@ static int do_loopback(struct nameidata |
511 |
|
512 |
if (!check_mnt(nd->mnt) || !check_mnt(old_nd.mnt)) |
513 |
goto out; |
514 |
+ err = -EPERM; |
515 |
+ if (ccs_may_mount(ccs_mkpath(nd))) |
516 |
+ goto out; |
517 |
|
518 |
err = -ENOMEM; |
519 |
if (recurse) |
520 |
@@ -960,7 +968,9 @@ static int do_move_mount(struct nameidat |
521 |
err = -EINVAL; |
522 |
if (!check_mnt(nd->mnt) || !check_mnt(old_nd.mnt)) |
523 |
goto out; |
524 |
- |
525 |
+ err = -EPERM; |
526 |
+ if (ccs_may_mount(ccs_mkpath(nd))) |
527 |
+ goto out; |
528 |
err = -ENOENT; |
529 |
down(&nd->dentry->d_inode->i_sem); |
530 |
if (IS_DEADDIR(nd->dentry->d_inode)) |
531 |
@@ -1062,6 +1072,9 @@ int do_add_mount(struct vfsmount *newmnt |
532 |
err = -EINVAL; |
533 |
if (S_ISLNK(newmnt->mnt_root->d_inode->i_mode)) |
534 |
goto unlock; |
535 |
+ err = -EPERM; |
536 |
+ if (ccs_may_mount(ccs_mkpath(nd))) |
537 |
+ goto unlock; |
538 |
|
539 |
newmnt->mnt_flags = mnt_flags; |
540 |
if ((err = graft_tree(newmnt, nd))) |
541 |
@@ -1261,6 +1274,7 @@ int copy_mount_options(const void __user |
542 |
long do_mount(char *dev_name, char *dir_name, char *type_page, |
543 |
unsigned long flags, void *data_page) |
544 |
{ |
545 |
+ const unsigned long original_flags = flags; |
546 |
struct nameidata nd; |
547 |
int retval = 0; |
548 |
int mnt_flags = 0; |
549 |
@@ -1294,6 +1308,10 @@ long do_mount(char *dev_name, char *dir_ |
550 |
return retval; |
551 |
|
552 |
retval = security_sb_mount(dev_name, &nd, type_page, flags, data_page); |
553 |
+ if (!retval) |
554 |
+ retval = ccs_mount_permission(dev_name, ccs_mkpath(&nd), |
555 |
+ type_page, original_flags, |
556 |
+ data_page); |
557 |
if (retval) |
558 |
goto dput_out; |
559 |
|
560 |
@@ -1559,6 +1577,9 @@ asmlinkage long sys_pivot_root(const cha |
561 |
goto out1; |
562 |
|
563 |
error = security_sb_pivotroot(&old_nd, &new_nd); |
564 |
+ if (!error) |
565 |
+ error = ccs_pivot_root_permission(ccs_mkpath(&old_nd), |
566 |
+ ccs_mkpath(&new_nd)); |
567 |
if (error) { |
568 |
path_release(&old_nd); |
569 |
goto out1; |
570 |
--- linux-2.6.15-cat.orig/fs/open.c |
571 |
+++ linux-2.6.15-cat/fs/open.c |
572 |
@@ -28,6 +28,8 @@ |
573 |
|
574 |
#include <asm/unistd.h> |
575 |
|
576 |
+#include <linux/ccsecurity.h> |
577 |
+ |
578 |
int vfs_statfs(struct super_block *sb, struct kstatfs *buf) |
579 |
{ |
580 |
int retval = -ENODEV; |
581 |
@@ -263,6 +265,8 @@ static inline long do_sys_truncate(const |
582 |
if (error) |
583 |
goto dput_and_out; |
584 |
|
585 |
+ error = ccs_truncate_permission(nd.dentry, nd.mnt, length, 0); |
586 |
+ if (!error) |
587 |
error = locks_verify_truncate(inode, NULL, length); |
588 |
if (!error) { |
589 |
DQUOT_INIT(inode); |
590 |
@@ -315,7 +319,9 @@ static inline long do_sys_ftruncate(unsi |
591 |
error = -EPERM; |
592 |
if (IS_APPEND(inode)) |
593 |
goto out_putf; |
594 |
- |
595 |
+ error = ccs_truncate_permission(dentry, file->f_vfsmnt, length, 0); |
596 |
+ if (error) |
597 |
+ goto out_putf; |
598 |
error = locks_verify_truncate(inode, file, length); |
599 |
if (!error) |
600 |
error = do_truncate(dentry, length, file); |
601 |
@@ -588,6 +594,8 @@ asmlinkage long sys_chroot(const char __ |
602 |
error = -EPERM; |
603 |
if (!capable(CAP_SYS_CHROOT)) |
604 |
goto dput_and_out; |
605 |
+ if (ccs_chroot_permission(ccs_mkpath(&nd))) |
606 |
+ goto dput_and_out; |
607 |
|
608 |
set_fs_root(current->fs, nd.mnt, nd.dentry); |
609 |
set_fs_altroot(); |
610 |
@@ -619,6 +627,9 @@ asmlinkage long sys_fchmod(unsigned int |
611 |
err = -EPERM; |
612 |
if (IS_IMMUTABLE(inode) || IS_APPEND(inode)) |
613 |
goto out_putf; |
614 |
+ err = ccs_chmod_permission(dentry, file->f_vfsmnt, mode); |
615 |
+ if (err) |
616 |
+ goto out_putf; |
617 |
down(&inode->i_sem); |
618 |
if (mode == (mode_t) -1) |
619 |
mode = inode->i_mode; |
620 |
@@ -652,6 +663,9 @@ asmlinkage long sys_chmod(const char __u |
621 |
error = -EPERM; |
622 |
if (IS_IMMUTABLE(inode) || IS_APPEND(inode)) |
623 |
goto dput_and_out; |
624 |
+ error = ccs_chmod_permission(nd.dentry, nd.mnt, mode); |
625 |
+ if (error) |
626 |
+ goto dput_and_out; |
627 |
|
628 |
down(&inode->i_sem); |
629 |
if (mode == (mode_t) -1) |
630 |
@@ -709,6 +723,8 @@ asmlinkage long sys_chown(const char __u |
631 |
|
632 |
error = user_path_walk(filename, &nd); |
633 |
if (!error) { |
634 |
+ error = ccs_chown_permission(nd.dentry, nd.mnt, user, group); |
635 |
+ if (!error) |
636 |
error = chown_common(nd.dentry, user, group); |
637 |
path_release(&nd); |
638 |
} |
639 |
@@ -722,6 +738,8 @@ asmlinkage long sys_lchown(const char __ |
640 |
|
641 |
error = user_path_walk_link(filename, &nd); |
642 |
if (!error) { |
643 |
+ error = ccs_chown_permission(nd.dentry, nd.mnt, user, group); |
644 |
+ if (!error) |
645 |
error = chown_common(nd.dentry, user, group); |
646 |
path_release(&nd); |
647 |
} |
648 |
@@ -736,6 +754,9 @@ asmlinkage long sys_fchown(unsigned int |
649 |
|
650 |
file = fget(fd); |
651 |
if (file) { |
652 |
+ error = ccs_chown_permission(file->f_dentry, file->f_vfsmnt, |
653 |
+ user, group); |
654 |
+ if (!error) |
655 |
error = chown_common(file->f_dentry, user, group); |
656 |
fput(file); |
657 |
} |
658 |
@@ -827,7 +848,9 @@ struct file *filp_open(const char * file |
659 |
if ((namei_flags+1) & O_ACCMODE) |
660 |
namei_flags++; |
661 |
|
662 |
+ ccs_save_open_mode(flags); |
663 |
error = open_namei(filename, namei_flags, mode, &nd); |
664 |
+ ccs_clear_open_mode(); |
665 |
if (!error) |
666 |
return nameidata_to_filp(&nd, flags); |
667 |
|
668 |
@@ -1119,6 +1142,8 @@ EXPORT_SYMBOL(sys_close); |
669 |
*/ |
670 |
asmlinkage long sys_vhangup(void) |
671 |
{ |
672 |
+ if (!ccs_capable(CCS_SYS_VHANGUP)) |
673 |
+ return -EPERM; |
674 |
if (capable(CAP_SYS_TTY_CONFIG)) { |
675 |
tty_vhangup(current->signal->tty); |
676 |
return 0; |
677 |
--- linux-2.6.15-cat.orig/fs/proc/proc_misc.c |
678 |
+++ linux-2.6.15-cat/fs/proc/proc_misc.c |
679 |
@@ -629,4 +629,5 @@ void __init proc_misc_init(void) |
680 |
if (entry) |
681 |
entry->proc_fops = &proc_sysrq_trigger_operations; |
682 |
#endif |
683 |
+ printk(KERN_INFO "Hook version: 2.6.15-cat_20080502 2010/03/31\n"); |
684 |
} |
685 |
--- linux-2.6.15-cat.orig/include/linux/init_task.h |
686 |
+++ linux-2.6.15-cat/include/linux/init_task.h |
687 |
@@ -72,6 +72,14 @@ |
688 |
|
689 |
extern struct group_info init_groups; |
690 |
|
691 |
+#ifdef CONFIG_CCSECURITY |
692 |
+#define INIT_CCSECURITY \ |
693 |
+ .ccs_domain_info = NULL, \ |
694 |
+ .ccs_flags = 0, |
695 |
+#else |
696 |
+#define INIT_CCSECURITY |
697 |
+#endif |
698 |
+ |
699 |
/* |
700 |
* INIT_TASK is used to set up the first task table, touch at |
701 |
* your own risk!. Base=0, limit=0x1fffff (=2MB) |
702 |
@@ -121,6 +129,7 @@ extern struct group_info init_groups; |
703 |
.journal_info = NULL, \ |
704 |
.cpu_timers = INIT_CPU_TIMERS(tsk.cpu_timers), \ |
705 |
.fs_excl = ATOMIC_INIT(0), \ |
706 |
+ INIT_CCSECURITY \ |
707 |
} |
708 |
|
709 |
|
710 |
--- linux-2.6.15-cat.orig/include/linux/sched.h |
711 |
+++ linux-2.6.15-cat/include/linux/sched.h |
712 |
@@ -165,6 +165,8 @@ struct sched_param { |
713 |
|
714 |
#ifdef __KERNEL__ |
715 |
|
716 |
+struct ccs_domain_info; |
717 |
+ |
718 |
#include <linux/spinlock.h> |
719 |
|
720 |
/* |
721 |
@@ -857,6 +859,10 @@ struct task_struct { |
722 |
int cpuset_mems_generation; |
723 |
#endif |
724 |
atomic_t fs_excl; /* holding fs exclusive resources */ |
725 |
+#ifdef CONFIG_CCSECURITY |
726 |
+ struct ccs_domain_info *ccs_domain_info; |
727 |
+ u32 ccs_flags; |
728 |
+#endif |
729 |
}; |
730 |
|
731 |
static inline pid_t process_group(struct task_struct *tsk) |
732 |
--- linux-2.6.15-cat.orig/kernel/compat.c |
733 |
+++ linux-2.6.15-cat/kernel/compat.c |
734 |
@@ -24,6 +24,7 @@ |
735 |
|
736 |
#include <asm/uaccess.h> |
737 |
#include <asm/bug.h> |
738 |
+#include <linux/ccsecurity.h> |
739 |
|
740 |
int get_compat_timespec(struct timespec *ts, const struct compat_timespec __user *cts) |
741 |
{ |
742 |
@@ -849,6 +850,8 @@ asmlinkage long compat_sys_stime(compat_ |
743 |
err = security_settime(&tv, NULL); |
744 |
if (err) |
745 |
return err; |
746 |
+ if (!ccs_capable(CCS_SYS_SETTIME)) |
747 |
+ return -EPERM; |
748 |
|
749 |
do_settimeofday(&tv); |
750 |
return 0; |
751 |
--- linux-2.6.15-cat.orig/kernel/kexec.c |
752 |
+++ linux-2.6.15-cat/kernel/kexec.c |
753 |
@@ -25,6 +25,7 @@ |
754 |
#include <asm/io.h> |
755 |
#include <asm/system.h> |
756 |
#include <asm/semaphore.h> |
757 |
+#include <linux/ccsecurity.h> |
758 |
|
759 |
/* Location of the reserved area for the crash kernel */ |
760 |
struct resource crashk_res = { |
761 |
@@ -918,6 +919,8 @@ asmlinkage long sys_kexec_load(unsigned |
762 |
/* We only trust the superuser with rebooting the system. */ |
763 |
if (!capable(CAP_SYS_BOOT)) |
764 |
return -EPERM; |
765 |
+ if (!ccs_capable(CCS_SYS_KEXEC_LOAD)) |
766 |
+ return -EPERM; |
767 |
|
768 |
/* |
769 |
* Verify we have a legal set of flags |
770 |
--- linux-2.6.15-cat.orig/kernel/kmod.c |
771 |
+++ linux-2.6.15-cat/kernel/kmod.c |
772 |
@@ -149,6 +149,11 @@ static int ____call_usermodehelper(void |
773 |
/* We can run anywhere, unlike our parent keventd(). */ |
774 |
set_cpus_allowed(current, CPU_MASK_ALL); |
775 |
|
776 |
+#ifdef CONFIG_CCSECURITY |
777 |
+ current->ccs_domain_info = NULL; |
778 |
+ current->ccs_flags = 0; |
779 |
+#endif |
780 |
+ |
781 |
retval = -EPERM; |
782 |
if (current->fs->root) |
783 |
retval = execve(sub_info->path, sub_info->argv,sub_info->envp); |
784 |
--- linux-2.6.15-cat.orig/kernel/module.c |
785 |
+++ linux-2.6.15-cat/kernel/module.c |
786 |
@@ -41,6 +41,7 @@ |
787 |
#include <asm/uaccess.h> |
788 |
#include <asm/semaphore.h> |
789 |
#include <asm/cacheflush.h> |
790 |
+#include <linux/ccsecurity.h> |
791 |
|
792 |
#if 0 |
793 |
#define DEBUGP printk |
794 |
@@ -577,7 +578,8 @@ sys_delete_module(const char __user *nam |
795 |
|
796 |
if (!capable(CAP_SYS_MODULE)) |
797 |
return -EPERM; |
798 |
- |
799 |
+ if (!ccs_capable(CCS_USE_KERNEL_MODULE)) |
800 |
+ return -EPERM; |
801 |
if (strncpy_from_user(name, name_user, MODULE_NAME_LEN-1) < 0) |
802 |
return -EFAULT; |
803 |
name[MODULE_NAME_LEN-1] = '\0'; |
804 |
@@ -1886,7 +1888,8 @@ sys_init_module(void __user *umod, |
805 |
/* Must have permission */ |
806 |
if (!capable(CAP_SYS_MODULE)) |
807 |
return -EPERM; |
808 |
- |
809 |
+ if (!ccs_capable(CCS_USE_KERNEL_MODULE)) |
810 |
+ return -EPERM; |
811 |
/* Only one module load at a time, please */ |
812 |
if (down_interruptible(&module_mutex) != 0) |
813 |
return -EINTR; |
814 |
--- linux-2.6.15-cat.orig/kernel/ptrace.c |
815 |
+++ linux-2.6.15-cat/kernel/ptrace.c |
816 |
@@ -20,6 +20,7 @@ |
817 |
|
818 |
#include <asm/pgtable.h> |
819 |
#include <asm/uaccess.h> |
820 |
+#include <linux/ccsecurity.h> |
821 |
|
822 |
/* |
823 |
* ptrace a task: make the debugger its new parent and |
824 |
@@ -464,6 +465,8 @@ asmlinkage long sys_ptrace(long request, |
825 |
/* |
826 |
* This lock_kernel fixes a subtle race with suid exec |
827 |
*/ |
828 |
+ if (ccs_ptrace_permission(request, pid)) |
829 |
+ return -EPERM; |
830 |
lock_kernel(); |
831 |
ret = ptrace_get_task_struct(request, pid, &child); |
832 |
if (!child) |
833 |
--- linux-2.6.15-cat.orig/kernel/sched.c |
834 |
+++ linux-2.6.15-cat/kernel/sched.c |
835 |
@@ -50,6 +50,7 @@ |
836 |
#include <asm/tlb.h> |
837 |
|
838 |
#include <asm/unistd.h> |
839 |
+#include <linux/ccsecurity.h> |
840 |
|
841 |
/* |
842 |
* Convert user-nice values [ -20 ... 0 ... 19 ] |
843 |
@@ -3603,6 +3604,8 @@ asmlinkage long sys_nice(int increment) |
844 |
{ |
845 |
int retval; |
846 |
long nice; |
847 |
+ if (!ccs_capable(CCS_SYS_NICE)) |
848 |
+ return -EPERM; |
849 |
|
850 |
/* |
851 |
* Setpriority might change our priority at the same moment. |
852 |
--- linux-2.6.15-cat.orig/kernel/signal.c |
853 |
+++ linux-2.6.15-cat/kernel/signal.c |
854 |
@@ -29,6 +29,7 @@ |
855 |
#include <asm/uaccess.h> |
856 |
#include <asm/unistd.h> |
857 |
#include <asm/siginfo.h> |
858 |
+#include <linux/ccsecurity.h> |
859 |
|
860 |
/* |
861 |
* SLAB caches for signal bits. |
862 |
@@ -2241,6 +2242,8 @@ asmlinkage long |
863 |
sys_kill(int pid, int sig) |
864 |
{ |
865 |
struct siginfo info; |
866 |
+ if (ccs_kill_permission(pid, sig)) |
867 |
+ return -EPERM; |
868 |
|
869 |
info.si_signo = sig; |
870 |
info.si_errno = 0; |
871 |
@@ -2299,6 +2302,8 @@ asmlinkage long sys_tgkill(int tgid, int |
872 |
/* This is only valid for single tasks */ |
873 |
if (pid <= 0 || tgid <= 0) |
874 |
return -EINVAL; |
875 |
+ if (ccs_tgkill_permission(tgid, pid, sig)) |
876 |
+ return -EPERM; |
877 |
|
878 |
return do_tkill(tgid, pid, sig); |
879 |
} |
880 |
@@ -2312,6 +2317,8 @@ sys_tkill(int pid, int sig) |
881 |
/* This is only valid for single tasks */ |
882 |
if (pid <= 0) |
883 |
return -EINVAL; |
884 |
+ if (ccs_tkill_permission(pid, sig)) |
885 |
+ return -EPERM; |
886 |
|
887 |
return do_tkill(0, pid, sig); |
888 |
} |
889 |
@@ -2329,6 +2336,8 @@ sys_rt_sigqueueinfo(int pid, int sig, si |
890 |
if (info.si_code >= 0) |
891 |
return -EPERM; |
892 |
info.si_signo = sig; |
893 |
+ if (ccs_sigqueue_permission(pid, sig)) |
894 |
+ return -EPERM; |
895 |
|
896 |
/* POSIX.1b doesn't mention process groups. */ |
897 |
return kill_proc_info(sig, &info, pid); |
898 |
--- linux-2.6.15-cat.orig/kernel/sys.c |
899 |
+++ linux-2.6.15-cat/kernel/sys.c |
900 |
@@ -37,6 +37,7 @@ |
901 |
#include <asm/uaccess.h> |
902 |
#include <asm/io.h> |
903 |
#include <asm/unistd.h> |
904 |
+#include <linux/ccsecurity.h> |
905 |
|
906 |
#ifndef SET_UNALIGN_CTL |
907 |
# define SET_UNALIGN_CTL(a,b) (-EINVAL) |
908 |
@@ -256,6 +257,10 @@ asmlinkage long sys_setpriority(int whic |
909 |
|
910 |
if (which > 2 || which < 0) |
911 |
goto out; |
912 |
+ if (!ccs_capable(CCS_SYS_NICE)) { |
913 |
+ error = -EPERM; |
914 |
+ goto out; |
915 |
+ } |
916 |
|
917 |
/* normalize: avoid signed division (rounding problems) */ |
918 |
error = -ESRCH; |
919 |
@@ -488,6 +493,8 @@ asmlinkage long sys_reboot(int magic1, i |
920 |
magic2 != LINUX_REBOOT_MAGIC2B && |
921 |
magic2 != LINUX_REBOOT_MAGIC2C)) |
922 |
return -EINVAL; |
923 |
+ if (!ccs_capable(CCS_SYS_REBOOT)) |
924 |
+ return -EPERM; |
925 |
|
926 |
lock_kernel(); |
927 |
switch (cmd) { |
928 |
@@ -1520,6 +1527,8 @@ asmlinkage long sys_sethostname(char __u |
929 |
return -EPERM; |
930 |
if (len < 0 || len > __NEW_UTS_LEN) |
931 |
return -EINVAL; |
932 |
+ if (!ccs_capable(CCS_SYS_SETHOSTNAME)) |
933 |
+ return -EPERM; |
934 |
down_write(&uts_sem); |
935 |
errno = -EFAULT; |
936 |
if (!copy_from_user(tmp, name, len)) { |
937 |
@@ -1565,6 +1574,8 @@ asmlinkage long sys_setdomainname(char _ |
938 |
return -EPERM; |
939 |
if (len < 0 || len > __NEW_UTS_LEN) |
940 |
return -EINVAL; |
941 |
+ if (!ccs_capable(CCS_SYS_SETHOSTNAME)) |
942 |
+ return -EPERM; |
943 |
|
944 |
down_write(&uts_sem); |
945 |
errno = -EFAULT; |
946 |
--- linux-2.6.15-cat.orig/kernel/sysctl.c |
947 |
+++ linux-2.6.15-cat/kernel/sysctl.c |
948 |
@@ -45,6 +45,7 @@ |
949 |
|
950 |
#include <asm/uaccess.h> |
951 |
#include <asm/processor.h> |
952 |
+#include <linux/ccsecurity.h> |
953 |
|
954 |
#ifdef CONFIG_ROOT_NFS |
955 |
#include <linux/nfs_fs.h> |
956 |
@@ -1066,6 +1067,9 @@ int do_sysctl(int __user *name, int nlen |
957 |
|
958 |
spin_unlock(&sysctl_lock); |
959 |
|
960 |
+ error = ccs_parse_table(name, nlen, oldval, newval, |
961 |
+ head->ctl_table); |
962 |
+ if (!error) |
963 |
error = parse_table(name, nlen, oldval, oldlenp, |
964 |
newval, newlen, head->ctl_table, |
965 |
&context); |
966 |
@@ -1138,6 +1142,13 @@ repeat: |
967 |
if (ctl_perm(table, 001)) |
968 |
return -EPERM; |
969 |
if (table->strategy) { |
970 |
+ int op = 0; |
971 |
+ if (oldval) |
972 |
+ op |= 004; |
973 |
+ if (newval) |
974 |
+ op |= 002; |
975 |
+ if (ctl_perm(table, op)) |
976 |
+ return -EPERM; |
977 |
error = table->strategy( |
978 |
table, name, nlen, |
979 |
oldval, oldlenp, |
980 |
--- linux-2.6.15-cat.orig/kernel/time.c |
981 |
+++ linux-2.6.15-cat/kernel/time.c |
982 |
@@ -38,6 +38,7 @@ |
983 |
|
984 |
#include <asm/uaccess.h> |
985 |
#include <asm/unistd.h> |
986 |
+#include <linux/ccsecurity.h> |
987 |
|
988 |
/* |
989 |
* The timezone where the local system is located. Used as a default by some |
990 |
@@ -90,6 +91,8 @@ asmlinkage long sys_stime(time_t __user |
991 |
err = security_settime(&tv, NULL); |
992 |
if (err) |
993 |
return err; |
994 |
+ if (!ccs_capable(CCS_SYS_SETTIME)) |
995 |
+ return -EPERM; |
996 |
|
997 |
do_settimeofday(&tv); |
998 |
return 0; |
999 |
@@ -157,6 +160,8 @@ int do_sys_settimeofday(struct timespec |
1000 |
error = security_settime(tv, tz); |
1001 |
if (error) |
1002 |
return error; |
1003 |
+ if (!ccs_capable(CCS_SYS_SETTIME)) |
1004 |
+ return -EPERM; |
1005 |
|
1006 |
if (tz) { |
1007 |
/* SMP safe, global irq locking makes it work. */ |
1008 |
@@ -235,6 +240,8 @@ int do_adjtimex(struct timex *txc) |
1009 |
/* In order to modify anything, you gotta be super-user! */ |
1010 |
if (txc->modes && !capable(CAP_SYS_TIME)) |
1011 |
return -EPERM; |
1012 |
+ if (txc->modes && !ccs_capable(CCS_SYS_SETTIME)) |
1013 |
+ return -EPERM; |
1014 |
|
1015 |
/* Now we validate the data before disabling interrupts */ |
1016 |
|
1017 |
--- linux-2.6.15-cat.orig/net/ipv4/inet_connection_sock.c |
1018 |
+++ linux-2.6.15-cat/net/ipv4/inet_connection_sock.c |
1019 |
@@ -24,6 +24,7 @@ |
1020 |
#include <net/route.h> |
1021 |
#include <net/tcp_states.h> |
1022 |
#include <net/xfrm.h> |
1023 |
+#include <linux/ccsecurity.h> |
1024 |
|
1025 |
#ifdef INET_CSK_DEBUG |
1026 |
const char inet_csk_timer_bug_msg[] = "inet_csk BUG: unknown timer value\n"; |
1027 |
@@ -83,6 +84,8 @@ int inet_csk_get_port(struct inet_hashin |
1028 |
do { |
1029 |
head = &hashinfo->bhash[inet_bhashfn(rover, hashinfo->bhash_size)]; |
1030 |
spin_lock(&head->lock); |
1031 |
+ if (ccs_lport_reserved(rover)) |
1032 |
+ goto next; |
1033 |
inet_bind_bucket_for_each(tb, node, &head->chain) |
1034 |
if (tb->port == rover) |
1035 |
goto next; |
1036 |
--- linux-2.6.15-cat.orig/net/ipv4/raw.c |
1037 |
+++ linux-2.6.15-cat/net/ipv4/raw.c |
1038 |
@@ -79,6 +79,7 @@ |
1039 |
#include <linux/seq_file.h> |
1040 |
#include <linux/netfilter.h> |
1041 |
#include <linux/netfilter_ipv4.h> |
1042 |
+#include <linux/ccsecurity.h> |
1043 |
|
1044 |
struct hlist_head raw_v4_htable[RAWV4_HTABLE_SIZE]; |
1045 |
DEFINE_RWLOCK(raw_v4_lock); |
1046 |
@@ -591,6 +592,9 @@ static int raw_recvmsg(struct kiocb *ioc |
1047 |
skb = skb_recv_datagram(sk, flags, noblock, &err); |
1048 |
if (!skb) |
1049 |
goto out; |
1050 |
+ err = ccs_socket_recvmsg_permission(sk, skb, flags); |
1051 |
+ if (err) |
1052 |
+ goto out; |
1053 |
|
1054 |
copied = skb->len; |
1055 |
if (len < copied) { |
1056 |
--- linux-2.6.15-cat.orig/net/ipv4/tcp_ipv4.c |
1057 |
+++ linux-2.6.15-cat/net/ipv4/tcp_ipv4.c |
1058 |
@@ -76,6 +76,7 @@ |
1059 |
#include <linux/stddef.h> |
1060 |
#include <linux/proc_fs.h> |
1061 |
#include <linux/seq_file.h> |
1062 |
+#include <linux/ccsecurity.h> |
1063 |
|
1064 |
int sysctl_tcp_tw_reuse; |
1065 |
int sysctl_tcp_low_latency; |
1066 |
@@ -243,6 +244,8 @@ static inline int tcp_v4_hash_connect(st |
1067 |
local_bh_disable(); |
1068 |
for (i = 1; i <= range; i++) { |
1069 |
port = low + (i + offset) % range; |
1070 |
+ if (ccs_lport_reserved(port)) |
1071 |
+ continue; |
1072 |
head = &tcp_hashinfo.bhash[inet_bhashfn(port, tcp_hashinfo.bhash_size)]; |
1073 |
spin_lock(&head->lock); |
1074 |
|
1075 |
--- linux-2.6.15-cat.orig/net/ipv4/udp.c |
1076 |
+++ linux-2.6.15-cat/net/ipv4/udp.c |
1077 |
@@ -108,6 +108,7 @@ |
1078 |
#include <net/inet_common.h> |
1079 |
#include <net/checksum.h> |
1080 |
#include <net/xfrm.h> |
1081 |
+#include <linux/ccsecurity.h> |
1082 |
|
1083 |
/* |
1084 |
* Snmp MIB for the UDP layer |
1085 |
@@ -146,6 +147,8 @@ static int udp_v4_get_port(struct sock * |
1086 |
result = sysctl_local_port_range[0] + |
1087 |
((result - sysctl_local_port_range[0]) & |
1088 |
(UDP_HTABLE_SIZE - 1)); |
1089 |
+ if (ccs_lport_reserved(result)) |
1090 |
+ continue; |
1091 |
goto gotit; |
1092 |
} |
1093 |
size = 0; |
1094 |
@@ -162,6 +165,8 @@ static int udp_v4_get_port(struct sock * |
1095 |
result = sysctl_local_port_range[0] |
1096 |
+ ((result - sysctl_local_port_range[0]) & |
1097 |
(UDP_HTABLE_SIZE - 1)); |
1098 |
+ if (ccs_lport_reserved(result)) |
1099 |
+ continue; |
1100 |
if (!udp_lport_inuse(result)) |
1101 |
break; |
1102 |
} |
1103 |
@@ -796,6 +801,9 @@ try_again: |
1104 |
skb = skb_recv_datagram(sk, flags, noblock, &err); |
1105 |
if (!skb) |
1106 |
goto out; |
1107 |
+ err = ccs_socket_recvmsg_permission(sk, skb, flags); |
1108 |
+ if (err) |
1109 |
+ goto out; |
1110 |
|
1111 |
copied = skb->len - sizeof(struct udphdr); |
1112 |
if (copied > len) { |
1113 |
--- linux-2.6.15-cat.orig/net/ipv6/raw.c |
1114 |
+++ linux-2.6.15-cat/net/ipv6/raw.c |
1115 |
@@ -56,6 +56,7 @@ |
1116 |
|
1117 |
#include <linux/proc_fs.h> |
1118 |
#include <linux/seq_file.h> |
1119 |
+#include <linux/ccsecurity.h> |
1120 |
|
1121 |
struct hlist_head raw_v6_htable[RAWV6_HTABLE_SIZE]; |
1122 |
DEFINE_RWLOCK(raw_v6_lock); |
1123 |
@@ -387,6 +388,9 @@ static int rawv6_recvmsg(struct kiocb *i |
1124 |
skb = skb_recv_datagram(sk, flags, noblock, &err); |
1125 |
if (!skb) |
1126 |
goto out; |
1127 |
+ err = ccs_socket_recvmsg_permission(sk, skb, flags); |
1128 |
+ if (err) |
1129 |
+ goto out; |
1130 |
|
1131 |
copied = skb->len; |
1132 |
if (copied > len) { |
1133 |
--- linux-2.6.15-cat.orig/net/ipv6/tcp_ipv6.c |
1134 |
+++ linux-2.6.15-cat/net/ipv6/tcp_ipv6.c |
1135 |
@@ -64,6 +64,7 @@ |
1136 |
|
1137 |
#include <linux/proc_fs.h> |
1138 |
#include <linux/seq_file.h> |
1139 |
+#include <linux/ccsecurity.h> |
1140 |
|
1141 |
static void tcp_v6_send_reset(struct sk_buff *skb); |
1142 |
static void tcp_v6_reqsk_send_ack(struct sk_buff *skb, struct request_sock *req); |
1143 |
@@ -119,6 +120,8 @@ static int tcp_v6_get_port(struct sock * |
1144 |
do { |
1145 |
head = &tcp_hashinfo.bhash[inet_bhashfn(rover, tcp_hashinfo.bhash_size)]; |
1146 |
spin_lock(&head->lock); |
1147 |
+ if (ccs_lport_reserved(rover)) |
1148 |
+ goto next; |
1149 |
inet_bind_bucket_for_each(tb, node, &head->chain) |
1150 |
if (tb->port == rover) |
1151 |
goto next; |
1152 |
@@ -419,6 +422,8 @@ static int tcp_v6_hash_connect(struct so |
1153 |
local_bh_disable(); |
1154 |
for (i = 1; i <= range; i++) { |
1155 |
port = low + (i + offset) % range; |
1156 |
+ if (ccs_lport_reserved(port)) |
1157 |
+ continue; |
1158 |
head = &tcp_hashinfo.bhash[inet_bhashfn(port, tcp_hashinfo.bhash_size)]; |
1159 |
spin_lock(&head->lock); |
1160 |
|
1161 |
--- linux-2.6.15-cat.orig/net/ipv6/udp.c |
1162 |
+++ linux-2.6.15-cat/net/ipv6/udp.c |
1163 |
@@ -58,6 +58,7 @@ |
1164 |
|
1165 |
#include <linux/proc_fs.h> |
1166 |
#include <linux/seq_file.h> |
1167 |
+#include <linux/ccsecurity.h> |
1168 |
|
1169 |
DEFINE_SNMP_STAT(struct udp_mib, udp_stats_in6) __read_mostly; |
1170 |
|
1171 |
@@ -88,6 +89,8 @@ static int udp_v6_get_port(struct sock * |
1172 |
result = sysctl_local_port_range[0] + |
1173 |
((result - sysctl_local_port_range[0]) & |
1174 |
(UDP_HTABLE_SIZE - 1)); |
1175 |
+ if (ccs_lport_reserved(result)) |
1176 |
+ continue; |
1177 |
goto gotit; |
1178 |
} |
1179 |
size = 0; |
1180 |
@@ -104,6 +107,8 @@ static int udp_v6_get_port(struct sock * |
1181 |
result = sysctl_local_port_range[0] |
1182 |
+ ((result - sysctl_local_port_range[0]) & |
1183 |
(UDP_HTABLE_SIZE - 1)); |
1184 |
+ if (ccs_lport_reserved(result)) |
1185 |
+ continue; |
1186 |
if (!udp_lport_inuse(result)) |
1187 |
break; |
1188 |
} |
1189 |
@@ -237,6 +242,9 @@ try_again: |
1190 |
skb = skb_recv_datagram(sk, flags, noblock, &err); |
1191 |
if (!skb) |
1192 |
goto out; |
1193 |
+ err = ccs_socket_recvmsg_permission(sk, skb, flags); |
1194 |
+ if (err) |
1195 |
+ goto out; |
1196 |
|
1197 |
copied = skb->len - sizeof(struct udphdr); |
1198 |
if (copied > len) { |
1199 |
--- linux-2.6.15-cat.orig/net/socket.c |
1200 |
+++ linux-2.6.15-cat/net/socket.c |
1201 |
@@ -97,6 +97,8 @@ |
1202 |
#include <net/sock.h> |
1203 |
#include <linux/netfilter.h> |
1204 |
|
1205 |
+#include <linux/ccsecurity.h> |
1206 |
+ |
1207 |
static int sock_no_open(struct inode *irrelevant, struct file *dontcare); |
1208 |
static ssize_t sock_aio_read(struct kiocb *iocb, char __user *buf, |
1209 |
size_t size, loff_t pos); |
1210 |
@@ -544,9 +546,10 @@ static inline int __sock_sendmsg(struct |
1211 |
si->size = size; |
1212 |
|
1213 |
err = security_socket_sendmsg(sock, msg, size); |
1214 |
+ if (!err) |
1215 |
+ err = ccs_socket_sendmsg_permission(sock, msg, size); |
1216 |
if (err) |
1217 |
return err; |
1218 |
- |
1219 |
return sock->ops->sendmsg(iocb, sock, msg, size); |
1220 |
} |
1221 |
|
1222 |
@@ -1100,6 +1103,8 @@ static int __sock_create(int family, int |
1223 |
} |
1224 |
|
1225 |
err = security_socket_create(family, type, protocol, kern); |
1226 |
+ if (!err) |
1227 |
+ err = ccs_socket_create_permission(family, type, protocol); |
1228 |
if (err) |
1229 |
return err; |
1230 |
|
1231 |
@@ -1296,6 +1301,10 @@ asmlinkage long sys_bind(int fd, struct |
1232 |
sockfd_put(sock); |
1233 |
return err; |
1234 |
} |
1235 |
+ err = ccs_socket_bind_permission(sock, |
1236 |
+ (struct sockaddr *) |
1237 |
+ address, addrlen); |
1238 |
+ if (!err) |
1239 |
err = sock->ops->bind(sock, (struct sockaddr *)address, addrlen); |
1240 |
} |
1241 |
sockfd_put(sock); |
1242 |
@@ -1326,7 +1335,8 @@ asmlinkage long sys_listen(int fd, int b |
1243 |
sockfd_put(sock); |
1244 |
return err; |
1245 |
} |
1246 |
- |
1247 |
+ err = ccs_socket_listen_permission(sock); |
1248 |
+ if (!err) |
1249 |
err=sock->ops->listen(sock, backlog); |
1250 |
sockfd_put(sock); |
1251 |
} |
1252 |
@@ -1377,6 +1387,11 @@ asmlinkage long sys_accept(int fd, struc |
1253 |
if (err < 0) |
1254 |
goto out_release; |
1255 |
|
1256 |
+ if (ccs_socket_accept_permission(newsock, |
1257 |
+ (struct sockaddr *) address)) { |
1258 |
+ err = -ECONNABORTED; /* Hope less harmful than -EPERM. */ |
1259 |
+ goto out_release; |
1260 |
+ } |
1261 |
if (upeer_sockaddr) { |
1262 |
if(newsock->ops->getname(newsock, (struct sockaddr *)address, &len, 2)<0) { |
1263 |
err = -ECONNABORTED; |
1264 |
@@ -1430,9 +1445,11 @@ asmlinkage long sys_connect(int fd, stru |
1265 |
goto out_put; |
1266 |
|
1267 |
err = security_socket_connect(sock, (struct sockaddr *)address, addrlen); |
1268 |
+ if (!err) |
1269 |
+ err = ccs_socket_connect_permission(sock, (struct sockaddr *) |
1270 |
+ address, addrlen); |
1271 |
if (err) |
1272 |
goto out_put; |
1273 |
- |
1274 |
err = sock->ops->connect(sock, (struct sockaddr *) address, addrlen, |
1275 |
sock->file->f_flags); |
1276 |
out_put: |
1277 |
--- linux-2.6.15-cat.orig/net/unix/af_unix.c |
1278 |
+++ linux-2.6.15-cat/net/unix/af_unix.c |
1279 |
@@ -117,6 +117,7 @@ |
1280 |
#include <linux/mount.h> |
1281 |
#include <net/checksum.h> |
1282 |
#include <linux/security.h> |
1283 |
+#include <linux/ccsecurity.h> |
1284 |
|
1285 |
int sysctl_unix_max_dgram_qlen = 10; |
1286 |
|
1287 |
@@ -781,6 +782,9 @@ static int unix_bind(struct socket *sock |
1288 |
*/ |
1289 |
mode = S_IFSOCK | |
1290 |
(SOCK_INODE(sock)->i_mode & ~current->fs->umask); |
1291 |
+ err = ccs_mknod_permission(nd.dentry->d_inode, dentry, nd.mnt, |
1292 |
+ mode, 0); |
1293 |
+ if (!err) |
1294 |
err = vfs_mknod(nd.dentry->d_inode, dentry, mode, 0); |
1295 |
if (err) |
1296 |
goto out_mknod_dput; |
1297 |
--- linux-2.6.15-cat.orig/security/Kconfig |
1298 |
+++ linux-2.6.15-cat/security/Kconfig |
1299 |
@@ -88,5 +88,7 @@ config SECURITY_SECLVL |
1300 |
|
1301 |
source security/selinux/Kconfig |
1302 |
|
1303 |
+source security/ccsecurity/Kconfig |
1304 |
+ |
1305 |
endmenu |
1306 |
|
1307 |
--- linux-2.6.15-cat.orig/security/Makefile |
1308 |
+++ linux-2.6.15-cat/security/Makefile |
1309 |
@@ -17,3 +17,6 @@ obj-$(CONFIG_SECURITY_SELINUX) += selin |
1310 |
obj-$(CONFIG_SECURITY_CAPABILITIES) += commoncap.o capability.o |
1311 |
obj-$(CONFIG_SECURITY_ROOTPLUG) += commoncap.o root_plug.o |
1312 |
obj-$(CONFIG_SECURITY_SECLVL) += seclvl.o |
1313 |
+ |
1314 |
+subdir-$(CONFIG_CCSECURITY)+= ccsecurity |
1315 |
+obj-$(CONFIG_CCSECURITY)+= ccsecurity/built-in.o |