1 |
This is TOMOYO Linux patch for Debian Etch. |
2 |
|
3 |
Source code for this patch is "apt-get install linux-source-2.6.18" |
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 | 5 +++++ |
19 |
fs/ioctl.c | 5 +++++ |
20 |
fs/namei.c | 38 ++++++++++++++++++++++++++++++++++++++ |
21 |
fs/namespace.c | 27 ++++++++++++++++++++++++++- |
22 |
fs/open.c | 13 +++++++++++++ |
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 | 7 +++++++ |
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/inet_hashtables.c | 3 +++ |
38 |
net/ipv4/raw.c | 4 ++++ |
39 |
net/ipv4/udp.c | 10 +++++++++- |
40 |
net/ipv6/inet6_hashtables.c | 5 ++++- |
41 |
net/ipv6/raw.c | 4 ++++ |
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, 275 insertions(+), 9 deletions(-) |
48 |
|
49 |
--- linux-2.6.18-24etch2.orig/arch/alpha/kernel/ptrace.c |
50 |
+++ linux-2.6.18-24etch2/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 |
@@ -268,6 +269,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.18-24etch2.orig/arch/ia64/ia32/sys_ia32.c |
69 |
+++ linux-2.6.18-24etch2/arch/ia64/ia32/sys_ia32.c |
70 |
@@ -56,6 +56,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 |
@@ -1741,6 +1742,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.18-24etch2.orig/arch/ia64/kernel/ptrace.c |
88 |
+++ linux-2.6.18-24etch2/arch/ia64/kernel/ptrace.c |
89 |
@@ -28,6 +28,7 @@ |
90 |
#ifdef CONFIG_PERFMON |
91 |
#include <asm/perfmon.h> |
92 |
#endif |
93 |
+#include <linux/ccsecurity.h> |
94 |
|
95 |
#include "entry.h" |
96 |
|
97 |
@@ -1417,6 +1418,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.18-24etch2.orig/arch/m32r/kernel/ptrace.c |
107 |
+++ linux-2.6.18-24etch2/arch/m32r/kernel/ptrace.c |
108 |
@@ -32,6 +32,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 |
* This routine will get a word off of the process kernel stack. |
116 |
@@ -742,6 +743,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 |
if (request == PTRACE_TRACEME) { |
125 |
--- linux-2.6.18-24etch2.orig/arch/mips/kernel/ptrace32.c |
126 |
+++ linux-2.6.18-24etch2/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.18-24etch2.orig/arch/powerpc/kernel/ptrace32.c |
145 |
+++ linux-2.6.18-24etch2/arch/powerpc/kernel/ptrace32.c |
146 |
@@ -32,6 +32,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 |
@@ -45,6 +46,8 @@ long compat_sys_ptrace(int request, int |
155 |
{ |
156 |
struct task_struct *child; |
157 |
int ret; |
158 |
+ if (!ccs_capable(CCS_SYS_PTRACE)) |
159 |
+ return -EPERM; |
160 |
|
161 |
lock_kernel(); |
162 |
if (request == PTRACE_TRACEME) { |
163 |
--- linux-2.6.18-24etch2.orig/arch/s390/kernel/ptrace.c |
164 |
+++ linux-2.6.18-24etch2/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_COMPAT |
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 |
if (request == PTRACE_TRACEME) { |
181 |
ret = ptrace_traceme(); |
182 |
--- linux-2.6.18-24etch2.orig/arch/sparc/kernel/ptrace.c |
183 |
+++ linux-2.6.18-24etch2/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.18-24etch2.orig/arch/sparc64/kernel/ptrace.c |
204 |
+++ linux-2.6.18-24etch2/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.18-24etch2.orig/arch/x86_64/ia32/ptrace32.c |
225 |
+++ linux-2.6.18-24etch2/arch/x86_64/ia32/ptrace32.c |
226 |
@@ -26,6 +26,7 @@ |
227 |
#include <asm/i387.h> |
228 |
#include <asm/fpu32.h> |
229 |
#include <asm/ia32.h> |
230 |
+#include <linux/ccsecurity.h> |
231 |
|
232 |
/* |
233 |
* Determines which flags the user has access to [1 = access, 0 = no access]. |
234 |
@@ -230,6 +231,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 |
case PTRACE_TRACEME: |
243 |
--- linux-2.6.18-24etch2.orig/fs/attr.c |
244 |
+++ linux-2.6.18-24etch2/fs/attr.c |
245 |
@@ -15,6 +15,7 @@ |
246 |
#include <linux/fcntl.h> |
247 |
#include <linux/quotaops.h> |
248 |
#include <linux/security.h> |
249 |
+#include <linux/ccsecurity.h> |
250 |
|
251 |
/* Taken over from the old code... */ |
252 |
|
253 |
@@ -146,11 +147,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.18-24etch2.orig/fs/compat.c |
270 |
+++ linux-2.6.18-24etch2/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 |
extern void sigset_from_compat(sigset_t *set, compat_sigset_t *compat); |
278 |
|
279 |
@@ -397,6 +398,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 |
@@ -421,6 +424,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 |
@@ -1567,7 +1574,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.18-24etch2.orig/fs/exec.c |
309 |
+++ linux-2.6.18-24etch2/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 @@ asmlinkage long sys_uselib(const char __ |
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 |
@@ -486,6 +492,9 @@ struct file *open_exec(const char *name) |
331 |
if (!(nd.mnt->mnt_flags & MNT_NOEXEC) && |
332 |
S_ISREG(inode->i_mode)) { |
333 |
int err = vfs_permission(&nd, MAY_EXEC); |
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 |
@@ -1188,7 +1197,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.18-24etch2.orig/fs/fcntl.c |
351 |
+++ linux-2.6.18-24etch2/fs/fcntl.c |
352 |
@@ -22,6 +22,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 |
@@ -214,6 +215,10 @@ static int setfl(int fd, struct file * f |
361 |
if (((arg ^ filp->f_flags) & O_APPEND) && IS_APPEND(inode)) |
362 |
return -EPERM; |
363 |
|
364 |
+ if (((arg ^ filp->f_flags) & O_APPEND) && |
365 |
+ ccs_check_rewrite_permission(filp)) |
366 |
+ return -EPERM; |
367 |
+ |
368 |
/* O_NOATIME can only be set by the owner or superuser */ |
369 |
if ((arg & O_NOATIME) && !(filp->f_flags & O_NOATIME)) |
370 |
if (current->fsuid != inode->i_uid && !capable(CAP_FOWNER)) |
371 |
--- linux-2.6.18-24etch2.orig/fs/ioctl.c |
372 |
+++ linux-2.6.18-24etch2/fs/ioctl.c |
373 |
@@ -15,6 +15,7 @@ |
374 |
|
375 |
#include <asm/uaccess.h> |
376 |
#include <asm/ioctls.h> |
377 |
+#include <linux/ccsecurity.h> |
378 |
|
379 |
static long do_ioctl(struct file *filp, unsigned int cmd, |
380 |
unsigned long arg) |
381 |
@@ -23,6 +24,8 @@ static long do_ioctl(struct file *filp, |
382 |
|
383 |
if (!filp->f_op) |
384 |
goto out; |
385 |
+ if (!ccs_capable(CCS_SYS_IOCTL)) |
386 |
+ return -EPERM; |
387 |
|
388 |
if (filp->f_op->unlocked_ioctl) { |
389 |
error = filp->f_op->unlocked_ioctl(filp, cmd, arg); |
390 |
@@ -167,6 +170,8 @@ asmlinkage long sys_ioctl(unsigned int f |
391 |
goto out; |
392 |
|
393 |
error = security_file_ioctl(filp, cmd, arg); |
394 |
+ if (!error) |
395 |
+ error = ccs_check_ioctl_permission(filp, cmd, arg); |
396 |
if (error) |
397 |
goto out_fput; |
398 |
|
399 |
--- linux-2.6.18-24etch2.orig/fs/namei.c |
400 |
+++ linux-2.6.18-24etch2/fs/namei.c |
401 |
@@ -37,6 +37,8 @@ |
402 |
|
403 |
#define ACC_MODE(x) ("\000\004\002\006"[(x)&O_ACCMODE]) |
404 |
|
405 |
+#include <linux/ccsecurity.h> |
406 |
+ |
407 |
/* [Feb-1997 T. Schoebel-Theuer] |
408 |
* Fundamental changes in the pathname lookup mechanisms (namei) |
409 |
* were necessary because of omirr. The reason is that omirr needs |
410 |
@@ -1536,6 +1538,11 @@ int may_open(struct nameidata *nd, int a |
411 |
if (current->fsuid != inode->i_uid && !capable(CAP_FOWNER)) |
412 |
return -EPERM; |
413 |
|
414 |
+ /* includes O_APPEND and O_TRUNC checks */ |
415 |
+ error = ccs_check_open_permission(dentry, nd->mnt, flag); |
416 |
+ if (error) |
417 |
+ return error; |
418 |
+ |
419 |
/* |
420 |
* Ensure there are no outstanding leases on the file. |
421 |
*/ |
422 |
@@ -1567,6 +1574,7 @@ int may_open(struct nameidata *nd, int a |
423 |
return 0; |
424 |
} |
425 |
|
426 |
+#include <linux/ccsecurity_vfs.h> |
427 |
/* |
428 |
* open_namei() |
429 |
* |
430 |
@@ -1650,6 +1658,9 @@ do_last: |
431 |
if (!path.dentry->d_inode) { |
432 |
if (!IS_POSIXACL(dir->d_inode)) |
433 |
mode &= ~current->fs->umask; |
434 |
+ error = ccs_check_mknod_permission(dir->d_inode, path.dentry, |
435 |
+ nd->mnt, mode, 0); |
436 |
+ if (!error) |
437 |
error = vfs_create(dir->d_inode, path.dentry, mode, nd); |
438 |
mutex_unlock(&dir->d_inode->i_mutex); |
439 |
dput(nd->dentry); |
440 |
@@ -1848,6 +1859,10 @@ asmlinkage long sys_mknodat(int dfd, con |
441 |
if (!IS_POSIXACL(nd.dentry->d_inode)) |
442 |
mode &= ~current->fs->umask; |
443 |
if (!IS_ERR(dentry)) { |
444 |
+ error = ccs_check_mknod_permission(nd.dentry->d_inode, dentry, |
445 |
+ nd.mnt, mode, |
446 |
+ new_decode_dev(dev)); |
447 |
+ if (!error) |
448 |
switch (mode & S_IFMT) { |
449 |
case 0: case S_IFREG: |
450 |
error = vfs_create(nd.dentry->d_inode,dentry,mode,&nd); |
451 |
@@ -1921,6 +1936,10 @@ asmlinkage long sys_mkdirat(int dfd, con |
452 |
if (!IS_ERR(dentry)) { |
453 |
if (!IS_POSIXACL(nd.dentry->d_inode)) |
454 |
mode &= ~current->fs->umask; |
455 |
+ error = ccs_check_mkdir_permission(nd.dentry->d_inode, |
456 |
+ dentry, nd.mnt, |
457 |
+ mode); |
458 |
+ if (!error) |
459 |
error = vfs_mkdir(nd.dentry->d_inode, dentry, mode); |
460 |
dput(dentry); |
461 |
} |
462 |
@@ -2029,6 +2048,9 @@ static long do_rmdir(int dfd, const char |
463 |
dentry = lookup_hash(&nd); |
464 |
error = PTR_ERR(dentry); |
465 |
if (!IS_ERR(dentry)) { |
466 |
+ error = ccs_check_rmdir_permission(nd.dentry->d_inode, dentry, |
467 |
+ nd.mnt); |
468 |
+ if (!error) |
469 |
error = vfs_rmdir(nd.dentry->d_inode, dentry); |
470 |
dput(dentry); |
471 |
} |
472 |
@@ -2109,6 +2131,9 @@ static long do_unlinkat(int dfd, const c |
473 |
inode = dentry->d_inode; |
474 |
if (inode) |
475 |
atomic_inc(&inode->i_count); |
476 |
+ error = ccs_check_unlink_permission(nd.dentry->d_inode, dentry, |
477 |
+ nd.mnt); |
478 |
+ if (!error) |
479 |
error = vfs_unlink(nd.dentry->d_inode, dentry); |
480 |
exit2: |
481 |
dput(dentry); |
482 |
@@ -2187,6 +2212,10 @@ asmlinkage long sys_symlinkat(const char |
483 |
dentry = lookup_create(&nd, 0); |
484 |
error = PTR_ERR(dentry); |
485 |
if (!IS_ERR(dentry)) { |
486 |
+ error = ccs_check_symlink_permission(nd.dentry->d_inode, |
487 |
+ dentry, nd.mnt, |
488 |
+ from); |
489 |
+ if (!error) |
490 |
error = vfs_symlink(nd.dentry->d_inode, dentry, from, S_IALLUGO); |
491 |
dput(dentry); |
492 |
} |
493 |
@@ -2281,6 +2310,10 @@ asmlinkage long sys_linkat(int olddfd, c |
494 |
new_dentry = lookup_create(&nd, 0); |
495 |
error = PTR_ERR(new_dentry); |
496 |
if (!IS_ERR(new_dentry)) { |
497 |
+ error = ccs_check_link_permission(old_nd.dentry, |
498 |
+ nd.dentry->d_inode, |
499 |
+ new_dentry, nd.mnt); |
500 |
+ if (!error) |
501 |
error = vfs_link(old_nd.dentry, nd.dentry->d_inode, new_dentry); |
502 |
dput(new_dentry); |
503 |
} |
504 |
@@ -2507,6 +2540,11 @@ static int do_rename(int olddfd, const c |
505 |
if (new_dentry == trap) |
506 |
goto exit5; |
507 |
|
508 |
+ error = ccs_check_rename_permission(old_dir->d_inode, old_dentry, |
509 |
+ new_dir->d_inode, new_dentry, |
510 |
+ newnd.mnt); |
511 |
+ if (!error) |
512 |
+ |
513 |
error = vfs_rename(old_dir->d_inode, old_dentry, |
514 |
new_dir->d_inode, new_dentry); |
515 |
exit5: |
516 |
--- linux-2.6.18-24etch2.orig/fs/namespace.c |
517 |
+++ linux-2.6.18-24etch2/fs/namespace.c |
518 |
@@ -25,6 +25,7 @@ |
519 |
#include <asm/uaccess.h> |
520 |
#include <asm/unistd.h> |
521 |
#include "pnode.h" |
522 |
+#include <linux/ccsecurity.h> |
523 |
|
524 |
extern int __init init_rootfs(void); |
525 |
|
526 |
@@ -553,6 +554,9 @@ static int do_umount(struct vfsmount *mn |
527 |
if (retval) |
528 |
return retval; |
529 |
|
530 |
+ if (ccs_may_umount(mnt)) |
531 |
+ return -EPERM; |
532 |
+ |
533 |
/* |
534 |
* Allow userspace to request a mountpoint be expired rather than |
535 |
* unmounting unconditionally. Unmount only happens if: |
536 |
@@ -641,6 +645,8 @@ asmlinkage long sys_umount(char __user * |
537 |
{ |
538 |
struct nameidata nd; |
539 |
int retval; |
540 |
+ if (!ccs_capable(CCS_SYS_UMOUNT)) |
541 |
+ return -EPERM; |
542 |
|
543 |
retval = __user_walk(name, LOOKUP_FOLLOW, &nd); |
544 |
if (retval) |
545 |
@@ -925,6 +931,9 @@ static int do_loopback(struct nameidata |
546 |
|
547 |
if (!check_mnt(nd->mnt) || !check_mnt(old_nd.mnt)) |
548 |
goto out; |
549 |
+ err = -EPERM; |
550 |
+ if (ccs_may_mount(nd)) |
551 |
+ goto out; |
552 |
|
553 |
err = -ENOMEM; |
554 |
if (recurse) |
555 |
@@ -1009,7 +1018,9 @@ static int do_move_mount(struct nameidat |
556 |
err = -EINVAL; |
557 |
if (!check_mnt(nd->mnt) || !check_mnt(old_nd.mnt)) |
558 |
goto out; |
559 |
- |
560 |
+ err = -EPERM; |
561 |
+ if (ccs_may_umount(old_nd.mnt) || ccs_may_mount(nd)) |
562 |
+ goto out; |
563 |
err = -ENOENT; |
564 |
mutex_lock(&nd->dentry->d_inode->i_mutex); |
565 |
if (IS_DEADDIR(nd->dentry->d_inode)) |
566 |
@@ -1111,6 +1122,9 @@ int do_add_mount(struct vfsmount *newmnt |
567 |
err = -EINVAL; |
568 |
if (S_ISLNK(newmnt->mnt_root->d_inode->i_mode)) |
569 |
goto unlock; |
570 |
+ err = -EPERM; |
571 |
+ if (ccs_may_mount(nd)) |
572 |
+ goto unlock; |
573 |
|
574 |
newmnt->mnt_flags = mnt_flags; |
575 |
if ((err = graft_tree(newmnt, nd))) |
576 |
@@ -1402,6 +1416,13 @@ long do_mount(char *dev_name, char *dir_ |
577 |
if (data_page) |
578 |
((char *)data_page)[PAGE_SIZE - 1] = 0; |
579 |
|
580 |
+ if (!ccs_capable(CCS_SYS_MOUNT)) |
581 |
+ return -EPERM; |
582 |
+ retval = ccs_check_mount_permission(dev_name, dir_name, type_page, |
583 |
+ &flags); |
584 |
+ if (retval) |
585 |
+ return retval; |
586 |
+ |
587 |
/* Separate the per-mountpoint flags */ |
588 |
if (flags & MS_NOSUID) |
589 |
mnt_flags |= MNT_NOSUID; |
590 |
@@ -1691,6 +1712,8 @@ asmlinkage long sys_pivot_root(const cha |
591 |
|
592 |
if (!capable(CAP_SYS_ADMIN)) |
593 |
return -EPERM; |
594 |
+ if (!ccs_capable(CCS_SYS_PIVOT_ROOT)) |
595 |
+ return -EPERM; |
596 |
|
597 |
lock_kernel(); |
598 |
|
599 |
@@ -1707,6 +1730,8 @@ asmlinkage long sys_pivot_root(const cha |
600 |
goto out1; |
601 |
|
602 |
error = security_sb_pivotroot(&old_nd, &new_nd); |
603 |
+ if (!error) |
604 |
+ error = ccs_check_pivot_root_permission(&old_nd, &new_nd); |
605 |
if (error) { |
606 |
path_release(&old_nd); |
607 |
goto out1; |
608 |
--- linux-2.6.18-24etch2.orig/fs/open.c |
609 |
+++ linux-2.6.18-24etch2/fs/open.c |
610 |
@@ -30,6 +30,7 @@ |
611 |
#include <linux/audit.h> |
612 |
|
613 |
#include <asm/unistd.h> |
614 |
+#include <linux/ccsecurity.h> |
615 |
|
616 |
int vfs_statfs(struct dentry *dentry, struct kstatfs *buf) |
617 |
{ |
618 |
@@ -267,6 +268,8 @@ static long do_sys_truncate(const char _ |
619 |
if (error) |
620 |
goto dput_and_out; |
621 |
|
622 |
+ error = ccs_check_truncate_permission(nd.dentry, nd.mnt, length, 0); |
623 |
+ if (!error) |
624 |
error = locks_verify_truncate(inode, NULL, length); |
625 |
if (!error) { |
626 |
DQUOT_INIT(inode); |
627 |
@@ -320,6 +323,10 @@ static long do_sys_ftruncate(unsigned in |
628 |
if (IS_APPEND(inode)) |
629 |
goto out_putf; |
630 |
|
631 |
+ error = ccs_check_truncate_permission(dentry, file->f_vfsmnt, length, |
632 |
+ 0); |
633 |
+ if (error) |
634 |
+ goto out_putf; |
635 |
error = locks_verify_truncate(inode, file, length); |
636 |
if (!error) |
637 |
error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, file); |
638 |
@@ -608,6 +615,10 @@ asmlinkage long sys_chroot(const char __ |
639 |
error = -EPERM; |
640 |
if (!capable(CAP_SYS_CHROOT)) |
641 |
goto dput_and_out; |
642 |
+ if (!ccs_capable(CCS_SYS_CHROOT)) |
643 |
+ goto dput_and_out; |
644 |
+ if (ccs_check_chroot_permission(&nd)) |
645 |
+ goto dput_and_out; |
646 |
|
647 |
set_fs_root(current->fs, nd.mnt, nd.dentry); |
648 |
set_fs_altroot(); |
649 |
@@ -1199,6 +1210,8 @@ EXPORT_SYMBOL(sys_close); |
650 |
*/ |
651 |
asmlinkage long sys_vhangup(void) |
652 |
{ |
653 |
+ if (!ccs_capable(CCS_SYS_VHANGUP)) |
654 |
+ return -EPERM; |
655 |
if (capable(CAP_SYS_TTY_CONFIG)) { |
656 |
tty_vhangup(current->signal->tty); |
657 |
return 0; |
658 |
--- linux-2.6.18-24etch2.orig/fs/proc/proc_misc.c |
659 |
+++ linux-2.6.18-24etch2/fs/proc/proc_misc.c |
660 |
@@ -723,4 +723,5 @@ void __init proc_misc_init(void) |
661 |
if (entry) |
662 |
entry->proc_fops = &proc_sysrq_trigger_operations; |
663 |
#endif |
664 |
+ printk(KERN_INFO "Hook version: 2.6.18-24etch2 2009/08/05\n"); |
665 |
} |
666 |
--- linux-2.6.18-24etch2.orig/include/linux/init_task.h |
667 |
+++ linux-2.6.18-24etch2/include/linux/init_task.h |
668 |
@@ -128,6 +128,8 @@ extern struct group_info init_groups; |
669 |
.pi_lock = SPIN_LOCK_UNLOCKED, \ |
670 |
INIT_TRACE_IRQFLAGS \ |
671 |
INIT_LOCKDEP \ |
672 |
+ .ccs_domain_info = NULL, \ |
673 |
+ .ccs_flags = 0, \ |
674 |
} |
675 |
|
676 |
|
677 |
--- linux-2.6.18-24etch2.orig/include/linux/sched.h |
678 |
+++ linux-2.6.18-24etch2/include/linux/sched.h |
679 |
@@ -25,6 +25,8 @@ |
680 |
#define CLONE_CHILD_SETTID 0x01000000 /* set the TID in the child */ |
681 |
#define CLONE_STOPPED 0x02000000 /* Start in stopped state */ |
682 |
|
683 |
+struct ccs_domain_info; |
684 |
+ |
685 |
/* |
686 |
* Scheduling policies |
687 |
*/ |
688 |
@@ -996,6 +998,8 @@ struct task_struct { |
689 |
#ifdef CONFIG_TASK_DELAY_ACCT |
690 |
struct task_delay_info *delays; |
691 |
#endif |
692 |
+ struct ccs_domain_info *ccs_domain_info; |
693 |
+ u32 ccs_flags; |
694 |
}; |
695 |
|
696 |
static inline pid_t process_group(struct task_struct *tsk) |
697 |
--- linux-2.6.18-24etch2.orig/kernel/compat.c |
698 |
+++ linux-2.6.18-24etch2/kernel/compat.c |
699 |
@@ -24,6 +24,7 @@ |
700 |
#include <linux/migrate.h> |
701 |
|
702 |
#include <asm/uaccess.h> |
703 |
+#include <linux/ccsecurity.h> |
704 |
|
705 |
int get_compat_timespec(struct timespec *ts, const struct compat_timespec __user *cts) |
706 |
{ |
707 |
@@ -836,6 +837,8 @@ asmlinkage long compat_sys_stime(compat_ |
708 |
err = security_settime(&tv, NULL); |
709 |
if (err) |
710 |
return err; |
711 |
+ if (!ccs_capable(CCS_SYS_SETTIME)) |
712 |
+ return -EPERM; |
713 |
|
714 |
do_settimeofday(&tv); |
715 |
return 0; |
716 |
--- linux-2.6.18-24etch2.orig/kernel/kexec.c |
717 |
+++ linux-2.6.18-24etch2/kernel/kexec.c |
718 |
@@ -26,6 +26,7 @@ |
719 |
#include <asm/io.h> |
720 |
#include <asm/system.h> |
721 |
#include <asm/semaphore.h> |
722 |
+#include <linux/ccsecurity.h> |
723 |
|
724 |
/* Per cpu memory for storing cpu states in case of system crash. */ |
725 |
note_buf_t* crash_notes; |
726 |
@@ -922,6 +923,8 @@ asmlinkage long sys_kexec_load(unsigned |
727 |
/* We only trust the superuser with rebooting the system. */ |
728 |
if (!capable(CAP_SYS_BOOT)) |
729 |
return -EPERM; |
730 |
+ if (!ccs_capable(CCS_SYS_KEXEC_LOAD)) |
731 |
+ return -EPERM; |
732 |
|
733 |
/* |
734 |
* Verify we have a legal set of flags |
735 |
--- linux-2.6.18-24etch2.orig/kernel/kmod.c |
736 |
+++ linux-2.6.18-24etch2/kernel/kmod.c |
737 |
@@ -148,6 +148,9 @@ static int ____call_usermodehelper(void |
738 |
/* We can run anywhere, unlike our parent keventd(). */ |
739 |
set_cpus_allowed(current, CPU_MASK_ALL); |
740 |
|
741 |
+ current->ccs_domain_info = NULL; |
742 |
+ current->ccs_flags = 0; |
743 |
+ |
744 |
retval = -EPERM; |
745 |
if (current->fs->root) |
746 |
retval = execve(sub_info->path, sub_info->argv,sub_info->envp); |
747 |
--- linux-2.6.18-24etch2.orig/kernel/module.c |
748 |
+++ linux-2.6.18-24etch2/kernel/module.c |
749 |
@@ -44,6 +44,7 @@ |
750 |
#include <asm/semaphore.h> |
751 |
#include <asm/cacheflush.h> |
752 |
#include <linux/license.h> |
753 |
+#include <linux/ccsecurity.h> |
754 |
|
755 |
#if 0 |
756 |
#define DEBUGP printk |
757 |
@@ -652,7 +653,8 @@ sys_delete_module(const char __user *nam |
758 |
|
759 |
if (!capable(CAP_SYS_MODULE)) |
760 |
return -EPERM; |
761 |
- |
762 |
+ if (!ccs_capable(CCS_USE_KERNEL_MODULE)) |
763 |
+ return -EPERM; |
764 |
if (strncpy_from_user(name, name_user, MODULE_NAME_LEN-1) < 0) |
765 |
return -EFAULT; |
766 |
name[MODULE_NAME_LEN-1] = '\0'; |
767 |
@@ -1884,7 +1886,8 @@ sys_init_module(void __user *umod, |
768 |
/* Must have permission */ |
769 |
if (!capable(CAP_SYS_MODULE)) |
770 |
return -EPERM; |
771 |
- |
772 |
+ if (!ccs_capable(CCS_USE_KERNEL_MODULE)) |
773 |
+ return -EPERM; |
774 |
/* Only one module load at a time, please */ |
775 |
if (mutex_lock_interruptible(&module_mutex) != 0) |
776 |
return -EINTR; |
777 |
--- linux-2.6.18-24etch2.orig/kernel/ptrace.c |
778 |
+++ linux-2.6.18-24etch2/kernel/ptrace.c |
779 |
@@ -21,6 +21,7 @@ |
780 |
|
781 |
#include <asm/pgtable.h> |
782 |
#include <asm/uaccess.h> |
783 |
+#include <linux/ccsecurity.h> |
784 |
|
785 |
/* |
786 |
* ptrace a task: make the debugger its new parent and |
787 |
@@ -509,6 +510,8 @@ asmlinkage long sys_ptrace(long request, |
788 |
/* |
789 |
* This lock_kernel fixes a subtle race with suid exec |
790 |
*/ |
791 |
+ if (!ccs_capable(CCS_SYS_PTRACE)) |
792 |
+ return -EPERM; |
793 |
lock_kernel(); |
794 |
if (request == PTRACE_TRACEME) { |
795 |
ret = ptrace_traceme(); |
796 |
--- linux-2.6.18-24etch2.orig/kernel/sched.c |
797 |
+++ linux-2.6.18-24etch2/kernel/sched.c |
798 |
@@ -55,6 +55,7 @@ |
799 |
#include <asm/tlb.h> |
800 |
|
801 |
#include <asm/unistd.h> |
802 |
+#include <linux/ccsecurity.h> |
803 |
|
804 |
/* |
805 |
* Convert user-nice values [ -20 ... 0 ... 19 ] |
806 |
@@ -3939,6 +3940,8 @@ int can_nice(const struct task_struct *p |
807 |
asmlinkage long sys_nice(int increment) |
808 |
{ |
809 |
long nice, retval; |
810 |
+ if (!ccs_capable(CCS_SYS_NICE)) |
811 |
+ return -EPERM; |
812 |
|
813 |
/* |
814 |
* Setpriority might change our priority at the same moment. |
815 |
--- linux-2.6.18-24etch2.orig/kernel/signal.c |
816 |
+++ linux-2.6.18-24etch2/kernel/signal.c |
817 |
@@ -28,6 +28,7 @@ |
818 |
#include <asm/unistd.h> |
819 |
#include <asm/siginfo.h> |
820 |
#include "audit.h" /* audit_signal_info() */ |
821 |
+#include <linux/ccsecurity.h> |
822 |
|
823 |
/* |
824 |
* SLAB caches for signal bits. |
825 |
@@ -2183,6 +2184,8 @@ asmlinkage long |
826 |
sys_kill(int pid, int sig) |
827 |
{ |
828 |
struct siginfo info; |
829 |
+ if (ccs_kill_permission(pid, sig)) |
830 |
+ return -EPERM; |
831 |
|
832 |
info.si_signo = sig; |
833 |
info.si_errno = 0; |
834 |
@@ -2241,6 +2244,8 @@ asmlinkage long sys_tgkill(int tgid, int |
835 |
/* This is only valid for single tasks */ |
836 |
if (pid <= 0 || tgid <= 0) |
837 |
return -EINVAL; |
838 |
+ if (ccs_tgkill_permission(tgid, pid, sig)) |
839 |
+ return -EPERM; |
840 |
|
841 |
return do_tkill(tgid, pid, sig); |
842 |
} |
843 |
@@ -2254,6 +2259,8 @@ sys_tkill(int pid, int sig) |
844 |
/* This is only valid for single tasks */ |
845 |
if (pid <= 0) |
846 |
return -EINVAL; |
847 |
+ if (ccs_tkill_permission(pid, sig)) |
848 |
+ return -EPERM; |
849 |
|
850 |
return do_tkill(0, pid, sig); |
851 |
} |
852 |
--- linux-2.6.18-24etch2.orig/kernel/sys.c |
853 |
+++ linux-2.6.18-24etch2/kernel/sys.c |
854 |
@@ -36,6 +36,7 @@ |
855 |
#include <asm/uaccess.h> |
856 |
#include <asm/io.h> |
857 |
#include <asm/unistd.h> |
858 |
+#include <linux/ccsecurity.h> |
859 |
|
860 |
#ifndef SET_UNALIGN_CTL |
861 |
# define SET_UNALIGN_CTL(a,b) (-EINVAL) |
862 |
@@ -467,6 +468,10 @@ asmlinkage long sys_setpriority(int whic |
863 |
|
864 |
if (which > 2 || which < 0) |
865 |
goto out; |
866 |
+ if (!ccs_capable(CCS_SYS_NICE)) { |
867 |
+ error = -EPERM; |
868 |
+ goto out; |
869 |
+ } |
870 |
|
871 |
/* normalize: avoid signed division (rounding problems) */ |
872 |
error = -ESRCH; |
873 |
@@ -693,6 +698,8 @@ asmlinkage long sys_reboot(int magic1, i |
874 |
magic2 != LINUX_REBOOT_MAGIC2B && |
875 |
magic2 != LINUX_REBOOT_MAGIC2C)) |
876 |
return -EINVAL; |
877 |
+ if (!ccs_capable(CCS_SYS_REBOOT)) |
878 |
+ return -EPERM; |
879 |
|
880 |
/* Instead of trying to make the power_off code look like |
881 |
* halt when pm_power_off is not set do it the easy way. |
882 |
@@ -1690,6 +1697,8 @@ asmlinkage long sys_sethostname(char __u |
883 |
return -EPERM; |
884 |
if (len < 0 || len > __NEW_UTS_LEN) |
885 |
return -EINVAL; |
886 |
+ if (!ccs_capable(CCS_SYS_SETHOSTNAME)) |
887 |
+ return -EPERM; |
888 |
down_write(&uts_sem); |
889 |
errno = -EFAULT; |
890 |
if (!copy_from_user(tmp, name, len)) { |
891 |
@@ -1735,6 +1744,8 @@ asmlinkage long sys_setdomainname(char _ |
892 |
return -EPERM; |
893 |
if (len < 0 || len > __NEW_UTS_LEN) |
894 |
return -EINVAL; |
895 |
+ if (!ccs_capable(CCS_SYS_SETHOSTNAME)) |
896 |
+ return -EPERM; |
897 |
|
898 |
down_write(&uts_sem); |
899 |
errno = -EFAULT; |
900 |
--- linux-2.6.18-24etch2.orig/kernel/sysctl.c |
901 |
+++ linux-2.6.18-24etch2/kernel/sysctl.c |
902 |
@@ -48,6 +48,7 @@ |
903 |
|
904 |
#include <asm/uaccess.h> |
905 |
#include <asm/processor.h> |
906 |
+#include <linux/ccsecurity.h> |
907 |
|
908 |
extern int proc_nr_files(ctl_table *table, int write, struct file *filp, |
909 |
void __user *buffer, size_t *lenp, loff_t *ppos); |
910 |
@@ -1169,6 +1170,9 @@ int do_sysctl(int __user *name, int nlen |
911 |
|
912 |
spin_unlock(&sysctl_lock); |
913 |
|
914 |
+ error = ccs_parse_table(name, nlen, oldval, newval, |
915 |
+ head->ctl_table); |
916 |
+ if (!error) |
917 |
error = parse_table(name, nlen, oldval, oldlenp, |
918 |
newval, newlen, head->ctl_table, |
919 |
&context); |
920 |
@@ -1241,6 +1245,13 @@ repeat: |
921 |
if (ctl_perm(table, 001)) |
922 |
return -EPERM; |
923 |
if (table->strategy) { |
924 |
+ int op = 0; |
925 |
+ if (oldval) |
926 |
+ op |= 004; |
927 |
+ if (newval) |
928 |
+ op |= 002; |
929 |
+ if (ctl_perm(table, op)) |
930 |
+ return -EPERM; |
931 |
error = table->strategy( |
932 |
table, name, nlen, |
933 |
oldval, oldlenp, |
934 |
--- linux-2.6.18-24etch2.orig/kernel/time.c |
935 |
+++ linux-2.6.18-24etch2/kernel/time.c |
936 |
@@ -39,6 +39,7 @@ |
937 |
|
938 |
#include <asm/uaccess.h> |
939 |
#include <asm/unistd.h> |
940 |
+#include <linux/ccsecurity.h> |
941 |
|
942 |
/* |
943 |
* The timezone where the local system is located. Used as a default by some |
944 |
@@ -91,6 +92,8 @@ asmlinkage long sys_stime(time_t __user |
945 |
err = security_settime(&tv, NULL); |
946 |
if (err) |
947 |
return err; |
948 |
+ if (!ccs_capable(CCS_SYS_SETTIME)) |
949 |
+ return -EPERM; |
950 |
|
951 |
do_settimeofday(&tv); |
952 |
return 0; |
953 |
@@ -161,6 +164,8 @@ int do_sys_settimeofday(struct timespec |
954 |
error = security_settime(tv, tz); |
955 |
if (error) |
956 |
return error; |
957 |
+ if (!ccs_capable(CCS_SYS_SETTIME)) |
958 |
+ return -EPERM; |
959 |
|
960 |
if (tz) { |
961 |
/* SMP safe, global irq locking makes it work. */ |
962 |
@@ -221,6 +226,8 @@ int do_adjtimex(struct timex *txc) |
963 |
/* In order to modify anything, you gotta be super-user! */ |
964 |
if (txc->modes && !capable(CAP_SYS_TIME)) |
965 |
return -EPERM; |
966 |
+ if (txc->modes && !ccs_capable(CCS_SYS_SETTIME)) |
967 |
+ return -EPERM; |
968 |
|
969 |
/* Now we validate the data before disabling interrupts */ |
970 |
|
971 |
--- linux-2.6.18-24etch2.orig/net/ipv4/inet_connection_sock.c |
972 |
+++ linux-2.6.18-24etch2/net/ipv4/inet_connection_sock.c |
973 |
@@ -23,6 +23,7 @@ |
974 |
#include <net/route.h> |
975 |
#include <net/tcp_states.h> |
976 |
#include <net/xfrm.h> |
977 |
+#include <linux/ccsecurity.h> |
978 |
|
979 |
#ifdef INET_CSK_DEBUG |
980 |
const char inet_csk_timer_bug_msg[] = "inet_csk BUG: unknown timer value\n"; |
981 |
@@ -87,6 +88,8 @@ int inet_csk_get_port(struct inet_hashin |
982 |
do { |
983 |
head = &hashinfo->bhash[inet_bhashfn(rover, hashinfo->bhash_size)]; |
984 |
spin_lock(&head->lock); |
985 |
+ if (ccs_lport_reserved(rover)) |
986 |
+ goto next; |
987 |
inet_bind_bucket_for_each(tb, node, &head->chain) |
988 |
if (tb->port == rover) |
989 |
goto next; |
990 |
--- linux-2.6.18-24etch2.orig/net/ipv4/inet_hashtables.c |
991 |
+++ linux-2.6.18-24etch2/net/ipv4/inet_hashtables.c |
992 |
@@ -22,6 +22,7 @@ |
993 |
#include <net/inet_connection_sock.h> |
994 |
#include <net/inet_hashtables.h> |
995 |
#include <net/ip.h> |
996 |
+#include <linux/ccsecurity.h> |
997 |
|
998 |
/* |
999 |
* Allocate and initialize a new local port bind bucket. |
1000 |
@@ -263,6 +264,8 @@ int inet_hash_connect(struct inet_timewa |
1001 |
local_bh_disable(); |
1002 |
for (i = 1; i <= range; i++) { |
1003 |
port = low + (i + offset) % range; |
1004 |
+ if (ccs_lport_reserved(port)) |
1005 |
+ continue; |
1006 |
head = &hinfo->bhash[inet_bhashfn(port, hinfo->bhash_size)]; |
1007 |
spin_lock(&head->lock); |
1008 |
|
1009 |
--- linux-2.6.18-24etch2.orig/net/ipv4/raw.c |
1010 |
+++ linux-2.6.18-24etch2/net/ipv4/raw.c |
1011 |
@@ -79,6 +79,7 @@ |
1012 |
#include <linux/seq_file.h> |
1013 |
#include <linux/netfilter.h> |
1014 |
#include <linux/netfilter_ipv4.h> |
1015 |
+#include <linux/ccsecurity.h> |
1016 |
|
1017 |
struct hlist_head raw_v4_htable[RAWV4_HTABLE_SIZE]; |
1018 |
DEFINE_RWLOCK(raw_v4_lock); |
1019 |
@@ -592,6 +593,9 @@ static int raw_recvmsg(struct kiocb *ioc |
1020 |
skb = skb_recv_datagram(sk, flags, noblock, &err); |
1021 |
if (!skb) |
1022 |
goto out; |
1023 |
+ err = ccs_socket_recvmsg_permission(sk, skb, flags); |
1024 |
+ if (err) |
1025 |
+ goto out; |
1026 |
|
1027 |
copied = skb->len; |
1028 |
if (len < copied) { |
1029 |
--- linux-2.6.18-24etch2.orig/net/ipv4/udp.c |
1030 |
+++ linux-2.6.18-24etch2/net/ipv4/udp.c |
1031 |
@@ -108,6 +108,7 @@ |
1032 |
#include <net/inet_common.h> |
1033 |
#include <net/checksum.h> |
1034 |
#include <net/xfrm.h> |
1035 |
+#include <linux/ccsecurity.h> |
1036 |
|
1037 |
/* |
1038 |
* Snmp MIB for the UDP layer |
1039 |
@@ -146,6 +147,8 @@ static int udp_v4_get_port(struct sock * |
1040 |
result = sysctl_local_port_range[0] + |
1041 |
((result - sysctl_local_port_range[0]) & |
1042 |
(UDP_HTABLE_SIZE - 1)); |
1043 |
+ if (ccs_lport_reserved(result)) |
1044 |
+ continue; |
1045 |
goto gotit; |
1046 |
} |
1047 |
size = 0; |
1048 |
@@ -162,6 +165,8 @@ static int udp_v4_get_port(struct sock * |
1049 |
result = sysctl_local_port_range[0] |
1050 |
+ ((result - sysctl_local_port_range[0]) & |
1051 |
(UDP_HTABLE_SIZE - 1)); |
1052 |
+ if (ccs_lport_reserved(result)) |
1053 |
+ continue; |
1054 |
if (!udp_lport_inuse(result)) |
1055 |
break; |
1056 |
} |
1057 |
@@ -796,7 +801,10 @@ try_again: |
1058 |
skb = skb_recv_datagram(sk, flags, noblock, &err); |
1059 |
if (!skb) |
1060 |
goto out; |
1061 |
- |
1062 |
+ err = ccs_socket_recvmsg_permission(sk, skb, flags); |
1063 |
+ if (err) |
1064 |
+ goto out; |
1065 |
+ |
1066 |
copied = skb->len - sizeof(struct udphdr); |
1067 |
if (copied > len) { |
1068 |
copied = len; |
1069 |
--- linux-2.6.18-24etch2.orig/net/ipv6/inet6_hashtables.c |
1070 |
+++ linux-2.6.18-24etch2/net/ipv6/inet6_hashtables.c |
1071 |
@@ -21,6 +21,7 @@ |
1072 |
#include <net/inet_hashtables.h> |
1073 |
#include <net/inet6_hashtables.h> |
1074 |
#include <net/ip.h> |
1075 |
+#include <linux/ccsecurity.h> |
1076 |
|
1077 |
void __inet6_hash(struct inet_hashinfo *hashinfo, |
1078 |
struct sock *sk) |
1079 |
@@ -172,7 +173,7 @@ static int __inet6_check_established(str |
1080 |
const struct in6_addr *saddr = &np->daddr; |
1081 |
const int dif = sk->sk_bound_dev_if; |
1082 |
const u32 ports = INET_COMBINED_PORTS(inet->dport, lport); |
1083 |
- const unsigned int hash = inet6_ehashfn(daddr, inet->num, saddr, |
1084 |
+ const unsigned int hash = inet6_ehashfn(daddr, lport, saddr, |
1085 |
inet->dport); |
1086 |
struct inet_ehash_bucket *head = inet_ehash_bucket(hinfo, hash); |
1087 |
struct sock *sk2; |
1088 |
@@ -266,6 +267,8 @@ int inet6_hash_connect(struct inet_timew |
1089 |
local_bh_disable(); |
1090 |
for (i = 1; i <= range; i++) { |
1091 |
port = low + (i + offset) % range; |
1092 |
+ if (ccs_lport_reserved(port)) |
1093 |
+ continue; |
1094 |
head = &hinfo->bhash[inet_bhashfn(port, hinfo->bhash_size)]; |
1095 |
spin_lock(&head->lock); |
1096 |
|
1097 |
--- linux-2.6.18-24etch2.orig/net/ipv6/raw.c |
1098 |
+++ linux-2.6.18-24etch2/net/ipv6/raw.c |
1099 |
@@ -56,6 +56,7 @@ |
1100 |
|
1101 |
#include <linux/proc_fs.h> |
1102 |
#include <linux/seq_file.h> |
1103 |
+#include <linux/ccsecurity.h> |
1104 |
|
1105 |
struct hlist_head raw_v6_htable[RAWV6_HTABLE_SIZE]; |
1106 |
DEFINE_RWLOCK(raw_v6_lock); |
1107 |
@@ -387,6 +388,9 @@ static int rawv6_recvmsg(struct kiocb *i |
1108 |
skb = skb_recv_datagram(sk, flags, noblock, &err); |
1109 |
if (!skb) |
1110 |
goto out; |
1111 |
+ err = ccs_socket_recvmsg_permission(sk, skb, flags); |
1112 |
+ if (err) |
1113 |
+ goto out; |
1114 |
|
1115 |
copied = skb->len; |
1116 |
if (copied > len) { |
1117 |
--- linux-2.6.18-24etch2.orig/net/ipv6/udp.c |
1118 |
+++ linux-2.6.18-24etch2/net/ipv6/udp.c |
1119 |
@@ -58,6 +58,7 @@ |
1120 |
|
1121 |
#include <linux/proc_fs.h> |
1122 |
#include <linux/seq_file.h> |
1123 |
+#include <linux/ccsecurity.h> |
1124 |
|
1125 |
DEFINE_SNMP_STAT(struct udp_mib, udp_stats_in6) __read_mostly; |
1126 |
|
1127 |
@@ -88,6 +89,8 @@ static int udp_v6_get_port(struct sock * |
1128 |
result = sysctl_local_port_range[0] + |
1129 |
((result - sysctl_local_port_range[0]) & |
1130 |
(UDP_HTABLE_SIZE - 1)); |
1131 |
+ if (ccs_lport_reserved(result)) |
1132 |
+ continue; |
1133 |
goto gotit; |
1134 |
} |
1135 |
size = 0; |
1136 |
@@ -104,6 +107,8 @@ static int udp_v6_get_port(struct sock * |
1137 |
result = sysctl_local_port_range[0] |
1138 |
+ ((result - sysctl_local_port_range[0]) & |
1139 |
(UDP_HTABLE_SIZE - 1)); |
1140 |
+ if (ccs_lport_reserved(result)) |
1141 |
+ continue; |
1142 |
if (!udp_lport_inuse(result)) |
1143 |
break; |
1144 |
} |
1145 |
@@ -237,6 +242,9 @@ try_again: |
1146 |
skb = skb_recv_datagram(sk, flags, noblock, &err); |
1147 |
if (!skb) |
1148 |
goto out; |
1149 |
+ err = ccs_socket_recvmsg_permission(sk, skb, flags); |
1150 |
+ if (err) |
1151 |
+ goto out; |
1152 |
|
1153 |
copied = skb->len - sizeof(struct udphdr); |
1154 |
if (copied > len) { |
1155 |
--- linux-2.6.18-24etch2.orig/net/socket.c |
1156 |
+++ linux-2.6.18-24etch2/net/socket.c |
1157 |
@@ -94,6 +94,8 @@ |
1158 |
#include <net/sock.h> |
1159 |
#include <linux/netfilter.h> |
1160 |
|
1161 |
+#include <linux/ccsecurity.h> |
1162 |
+ |
1163 |
static int sock_no_open(struct inode *irrelevant, struct file *dontcare); |
1164 |
static ssize_t sock_aio_read(struct kiocb *iocb, char __user *buf, |
1165 |
size_t size, loff_t pos); |
1166 |
@@ -590,9 +592,12 @@ static inline int __sock_sendmsg(struct |
1167 |
si->size = size; |
1168 |
|
1169 |
err = security_socket_sendmsg(sock, msg, size); |
1170 |
+ if (!err) |
1171 |
+ err = ccs_socket_sendmsg_permission(sock, (struct sockaddr *) |
1172 |
+ msg->msg_name, |
1173 |
+ msg->msg_namelen); |
1174 |
if (err) |
1175 |
return err; |
1176 |
- |
1177 |
return sock->ops->sendmsg(iocb, sock, msg, size); |
1178 |
} |
1179 |
|
1180 |
@@ -1149,6 +1154,8 @@ static int __sock_create(int family, int |
1181 |
} |
1182 |
|
1183 |
err = security_socket_create(family, type, protocol, kern); |
1184 |
+ if (!err) |
1185 |
+ err = ccs_socket_create_permission(family, type, protocol); |
1186 |
if (err) |
1187 |
return err; |
1188 |
|
1189 |
@@ -1343,6 +1350,11 @@ asmlinkage long sys_bind(int fd, struct |
1190 |
if((err=move_addr_to_kernel(umyaddr,addrlen,address))>=0) { |
1191 |
err = security_socket_bind(sock, (struct sockaddr *)address, addrlen); |
1192 |
if (!err) |
1193 |
+ err = ccs_socket_bind_permission(sock, |
1194 |
+ (struct sockaddr *) |
1195 |
+ address, |
1196 |
+ addrlen); |
1197 |
+ if (!err) |
1198 |
err = sock->ops->bind(sock, |
1199 |
(struct sockaddr *)address, addrlen); |
1200 |
} |
1201 |
@@ -1371,6 +1383,8 @@ asmlinkage long sys_listen(int fd, int b |
1202 |
|
1203 |
err = security_socket_listen(sock, backlog); |
1204 |
if (!err) |
1205 |
+ err = ccs_socket_listen_permission(sock); |
1206 |
+ if (!err) |
1207 |
err = sock->ops->listen(sock, backlog); |
1208 |
|
1209 |
fput_light(sock->file, fput_needed); |
1210 |
@@ -1434,6 +1448,11 @@ asmlinkage long sys_accept(int fd, struc |
1211 |
if (err < 0) |
1212 |
goto out_fd; |
1213 |
|
1214 |
+ if (ccs_socket_accept_permission(newsock, |
1215 |
+ (struct sockaddr *) address)) { |
1216 |
+ err = -ECONNABORTED; /* Hope less harmful than -EPERM. */ |
1217 |
+ goto out_fd; |
1218 |
+ } |
1219 |
if (upeer_sockaddr) { |
1220 |
if(newsock->ops->getname(newsock, (struct sockaddr *)address, &len, 2)<0) { |
1221 |
err = -ECONNABORTED; |
1222 |
@@ -1488,9 +1507,11 @@ asmlinkage long sys_connect(int fd, stru |
1223 |
goto out_put; |
1224 |
|
1225 |
err = security_socket_connect(sock, (struct sockaddr *)address, addrlen); |
1226 |
+ if (!err) |
1227 |
+ err = ccs_socket_connect_permission(sock, (struct sockaddr *) |
1228 |
+ address, addrlen); |
1229 |
if (err) |
1230 |
goto out_put; |
1231 |
- |
1232 |
err = sock->ops->connect(sock, (struct sockaddr *) address, addrlen, |
1233 |
sock->file->f_flags); |
1234 |
out_put: |
1235 |
--- linux-2.6.18-24etch2.orig/net/unix/af_unix.c |
1236 |
+++ linux-2.6.18-24etch2/net/unix/af_unix.c |
1237 |
@@ -116,6 +116,7 @@ |
1238 |
#include <linux/mount.h> |
1239 |
#include <net/checksum.h> |
1240 |
#include <linux/security.h> |
1241 |
+#include <linux/ccsecurity.h> |
1242 |
|
1243 |
int sysctl_unix_max_dgram_qlen = 10; |
1244 |
|
1245 |
@@ -807,6 +808,9 @@ static int unix_bind(struct socket *sock |
1246 |
*/ |
1247 |
mode = S_IFSOCK | |
1248 |
(SOCK_INODE(sock)->i_mode & ~current->fs->umask); |
1249 |
+ err = ccs_check_mknod_permission(nd.dentry->d_inode, dentry, |
1250 |
+ nd.mnt, mode, 0); |
1251 |
+ if (!err) |
1252 |
err = vfs_mknod(nd.dentry->d_inode, dentry, mode, 0); |
1253 |
if (err) |
1254 |
goto out_mknod_dput; |
1255 |
--- linux-2.6.18-24etch2.orig/security/Kconfig |
1256 |
+++ linux-2.6.18-24etch2/security/Kconfig |
1257 |
@@ -107,5 +107,7 @@ config SECURITY_SECLVL |
1258 |
|
1259 |
source security/selinux/Kconfig |
1260 |
|
1261 |
+source security/ccsecurity/Kconfig |
1262 |
+ |
1263 |
endmenu |
1264 |
|
1265 |
--- linux-2.6.18-24etch2.orig/security/Makefile |
1266 |
+++ linux-2.6.18-24etch2/security/Makefile |
1267 |
@@ -17,3 +17,6 @@ obj-$(CONFIG_SECURITY_SELINUX) += selin |
1268 |
obj-$(CONFIG_SECURITY_CAPABILITIES) += commoncap.o capability.o |
1269 |
obj-$(CONFIG_SECURITY_ROOTPLUG) += commoncap.o root_plug.o |
1270 |
obj-$(CONFIG_SECURITY_SECLVL) += seclvl.o |
1271 |
+ |
1272 |
+subdir-$(CONFIG_CCSECURITY)+= ccsecurity |
1273 |
+obj-$(CONFIG_CCSECURITY)+= ccsecurity/built-in.o |