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