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/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/inet_hashtables.c | 3 +++ |
37 |
net/ipv4/raw.c | 4 ++++ |
38 |
net/ipv4/udp.c | 10 +++++++++- |
39 |
net/ipv6/inet6_hashtables.c | 5 ++++- |
40 |
net/ipv6/raw.c | 4 ++++ |
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, 284 insertions(+), 9 deletions(-) |
47 |
|
48 |
--- linux-2.6.18-26etch2.orig/arch/alpha/kernel/ptrace.c |
49 |
+++ linux-2.6.18-26etch2/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 |
@@ -268,6 +269,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.18-26etch2.orig/arch/ia64/ia32/sys_ia32.c |
68 |
+++ linux-2.6.18-26etch2/arch/ia64/ia32/sys_ia32.c |
69 |
@@ -56,6 +56,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 |
@@ -1741,6 +1742,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.18-26etch2.orig/arch/ia64/kernel/ptrace.c |
87 |
+++ linux-2.6.18-26etch2/arch/ia64/kernel/ptrace.c |
88 |
@@ -28,6 +28,7 @@ |
89 |
#ifdef CONFIG_PERFMON |
90 |
#include <asm/perfmon.h> |
91 |
#endif |
92 |
+#include <linux/ccsecurity.h> |
93 |
|
94 |
#include "entry.h" |
95 |
|
96 |
@@ -1417,6 +1418,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.18-26etch2.orig/arch/m32r/kernel/ptrace.c |
106 |
+++ linux-2.6.18-26etch2/arch/m32r/kernel/ptrace.c |
107 |
@@ -32,6 +32,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 |
* This routine will get a word off of the process kernel stack. |
115 |
@@ -742,6 +743,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 |
if (request == PTRACE_TRACEME) { |
124 |
--- linux-2.6.18-26etch2.orig/arch/mips/kernel/ptrace32.c |
125 |
+++ linux-2.6.18-26etch2/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.18-26etch2.orig/arch/powerpc/kernel/ptrace32.c |
144 |
+++ linux-2.6.18-26etch2/arch/powerpc/kernel/ptrace32.c |
145 |
@@ -32,6 +32,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 |
@@ -45,6 +46,8 @@ long compat_sys_ptrace(int request, int |
154 |
{ |
155 |
struct task_struct *child; |
156 |
int ret; |
157 |
+ if (ccs_ptrace_permission(request, pid)) |
158 |
+ return -EPERM; |
159 |
|
160 |
lock_kernel(); |
161 |
if (request == PTRACE_TRACEME) { |
162 |
--- linux-2.6.18-26etch2.orig/arch/s390/kernel/ptrace.c |
163 |
+++ linux-2.6.18-26etch2/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_COMPAT |
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 |
if (request == PTRACE_TRACEME) { |
180 |
ret = ptrace_traceme(); |
181 |
--- linux-2.6.18-26etch2.orig/arch/sparc/kernel/ptrace.c |
182 |
+++ linux-2.6.18-26etch2/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.18-26etch2.orig/arch/sparc64/kernel/ptrace.c |
203 |
+++ linux-2.6.18-26etch2/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 |
@@ -176,6 +177,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.18-26etch2.orig/arch/x86_64/ia32/ptrace32.c |
224 |
+++ linux-2.6.18-26etch2/arch/x86_64/ia32/ptrace32.c |
225 |
@@ -26,6 +26,7 @@ |
226 |
#include <asm/i387.h> |
227 |
#include <asm/fpu32.h> |
228 |
#include <asm/ia32.h> |
229 |
+#include <linux/ccsecurity.h> |
230 |
|
231 |
/* |
232 |
* Determines which flags the user has access to [1 = access, 0 = no access]. |
233 |
@@ -230,6 +231,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 |
case PTRACE_TRACEME: |
242 |
--- linux-2.6.18-26etch2.orig/fs/compat.c |
243 |
+++ linux-2.6.18-26etch2/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 |
extern void sigset_from_compat(sigset_t *set, compat_sigset_t *compat); |
251 |
|
252 |
@@ -397,6 +398,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_check_ioctl_permission(filp, cmd, arg); |
258 |
if (error) |
259 |
goto out_fput; |
260 |
|
261 |
@@ -421,6 +424,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 |
@@ -1567,7 +1574,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.18-26etch2.orig/fs/exec.c |
282 |
+++ linux-2.6.18-26etch2/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 |
@@ -486,6 +492,9 @@ struct file *open_exec(const char *name) |
304 |
if (!(nd.mnt->mnt_flags & MNT_NOEXEC) && |
305 |
S_ISREG(inode->i_mode)) { |
306 |
int err = vfs_permission(&nd, MAY_EXEC); |
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 |
@@ -1188,7 +1197,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.18-26etch2.orig/fs/fcntl.c |
324 |
+++ linux-2.6.18-26etch2/fs/fcntl.c |
325 |
@@ -22,6 +22,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 |
@@ -214,6 +215,9 @@ static int setfl(int fd, struct file * f |
334 |
if (((arg ^ filp->f_flags) & O_APPEND) && IS_APPEND(inode)) |
335 |
return -EPERM; |
336 |
|
337 |
+ if (((arg ^ filp->f_flags) & 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.18-26etch2.orig/fs/ioctl.c |
344 |
+++ linux-2.6.18-26etch2/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.18-26etch2.orig/fs/namei.c |
372 |
+++ linux-2.6.18-26etch2/fs/namei.c |
373 |
@@ -37,6 +37,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 |
@@ -1536,6 +1538,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 |
@@ -1567,6 +1574,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 |
@@ -1650,6 +1658,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 |
mutex_unlock(&dir->d_inode->i_mutex); |
411 |
dput(nd->dentry); |
412 |
@@ -1848,6 +1859,9 @@ asmlinkage long sys_mknodat(int dfd, con |
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 |
@@ -1921,6 +1935,9 @@ asmlinkage long sys_mkdirat(int dfd, con |
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 |
@@ -2029,6 +2046,9 @@ static long do_rmdir(int dfd, const char |
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 |
@@ -2109,6 +2129,9 @@ static long do_unlinkat(int dfd, const c |
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 |
@@ -2187,6 +2210,9 @@ asmlinkage long sys_symlinkat(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 |
@@ -2281,6 +2307,9 @@ asmlinkage long sys_linkat(int olddfd, c |
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 |
@@ -2507,6 +2536,9 @@ static int do_rename(int olddfd, const c |
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.18-26etch2.orig/fs/namespace.c |
483 |
+++ linux-2.6.18-26etch2/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 |
@@ -550,6 +551,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 |
@@ -641,6 +644,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 |
@@ -925,6 +930,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 |
@@ -1009,7 +1017,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 |
mutex_lock(&nd->dentry->d_inode->i_mutex); |
530 |
if (IS_DEADDIR(nd->dentry->d_inode)) |
531 |
@@ -1111,6 +1121,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 |
@@ -1384,6 +1397,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 |
@@ -1423,6 +1437,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 |
@@ -1707,6 +1725,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.18-26etch2.orig/fs/open.c |
571 |
+++ linux-2.6.18-26etch2/fs/open.c |
572 |
@@ -30,6 +30,7 @@ |
573 |
#include <linux/audit.h> |
574 |
|
575 |
#include <asm/unistd.h> |
576 |
+#include <linux/ccsecurity.h> |
577 |
|
578 |
int vfs_statfs(struct dentry *dentry, struct kstatfs *buf) |
579 |
{ |
580 |
@@ -267,6 +268,8 @@ static long do_sys_truncate(const char _ |
581 |
if (error) |
582 |
goto dput_and_out; |
583 |
|
584 |
+ error = ccs_truncate_permission(nd.dentry, nd.mnt, length, 0); |
585 |
+ if (!error) |
586 |
error = locks_verify_truncate(inode, NULL, length); |
587 |
if (!error) { |
588 |
DQUOT_INIT(inode); |
589 |
@@ -320,6 +323,9 @@ static long do_sys_ftruncate(unsigned in |
590 |
if (IS_APPEND(inode)) |
591 |
goto out_putf; |
592 |
|
593 |
+ error = ccs_truncate_permission(dentry, file->f_vfsmnt, length, 0); |
594 |
+ if (error) |
595 |
+ goto out_putf; |
596 |
error = locks_verify_truncate(inode, file, length); |
597 |
if (!error) |
598 |
error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, file); |
599 |
@@ -608,6 +614,8 @@ asmlinkage long sys_chroot(const char __ |
600 |
error = -EPERM; |
601 |
if (!capable(CAP_SYS_CHROOT)) |
602 |
goto dput_and_out; |
603 |
+ if (ccs_chroot_permission(ccs_mkpath(&nd))) |
604 |
+ goto dput_and_out; |
605 |
|
606 |
set_fs_root(current->fs, nd.mnt, nd.dentry); |
607 |
set_fs_altroot(); |
608 |
@@ -641,6 +649,9 @@ asmlinkage long sys_fchmod(unsigned int |
609 |
err = -EPERM; |
610 |
if (IS_IMMUTABLE(inode) || IS_APPEND(inode)) |
611 |
goto out_putf; |
612 |
+ err = ccs_chmod_permission(dentry, file->f_vfsmnt, mode); |
613 |
+ if (err) |
614 |
+ goto out_putf; |
615 |
mutex_lock(&inode->i_mutex); |
616 |
if (mode == (mode_t) -1) |
617 |
mode = inode->i_mode; |
618 |
@@ -675,6 +686,9 @@ asmlinkage long sys_fchmodat(int dfd, co |
619 |
error = -EPERM; |
620 |
if (IS_IMMUTABLE(inode) || IS_APPEND(inode)) |
621 |
goto dput_and_out; |
622 |
+ error = ccs_chmod_permission(nd.dentry, nd.mnt, mode); |
623 |
+ if (error) |
624 |
+ goto dput_and_out; |
625 |
|
626 |
mutex_lock(&inode->i_mutex); |
627 |
if (mode == (mode_t) -1) |
628 |
@@ -737,6 +751,8 @@ asmlinkage long sys_chown(const char __u |
629 |
|
630 |
error = user_path_walk(filename, &nd); |
631 |
if (!error) { |
632 |
+ error = ccs_chown_permission(nd.dentry, nd.mnt, user, group); |
633 |
+ if (!error) |
634 |
error = chown_common(nd.dentry, user, group); |
635 |
path_release(&nd); |
636 |
} |
637 |
@@ -756,6 +772,8 @@ asmlinkage long sys_fchownat(int dfd, co |
638 |
follow = (flag & AT_SYMLINK_NOFOLLOW) ? 0 : LOOKUP_FOLLOW; |
639 |
error = __user_walk_fd(dfd, filename, follow, &nd); |
640 |
if (!error) { |
641 |
+ error = ccs_chown_permission(nd.dentry, nd.mnt, user, group); |
642 |
+ if (!error) |
643 |
error = chown_common(nd.dentry, user, group); |
644 |
path_release(&nd); |
645 |
} |
646 |
@@ -770,6 +788,8 @@ asmlinkage long sys_lchown(const char __ |
647 |
|
648 |
error = user_path_walk_link(filename, &nd); |
649 |
if (!error) { |
650 |
+ error = ccs_chown_permission(nd.dentry, nd.mnt, user, group); |
651 |
+ if (!error) |
652 |
error = chown_common(nd.dentry, user, group); |
653 |
path_release(&nd); |
654 |
} |
655 |
@@ -787,6 +807,9 @@ asmlinkage long sys_fchown(unsigned int |
656 |
struct dentry * dentry; |
657 |
dentry = file->f_dentry; |
658 |
audit_inode(NULL, dentry->d_inode); |
659 |
+ error = ccs_chown_permission(dentry, file->f_vfsmnt, user, |
660 |
+ group); |
661 |
+ if (!error) |
662 |
error = chown_common(dentry, user, group); |
663 |
fput(file); |
664 |
} |
665 |
@@ -879,7 +902,9 @@ static struct file *do_filp_open(int dfd |
666 |
if ((namei_flags+1) & O_ACCMODE) |
667 |
namei_flags++; |
668 |
|
669 |
+ ccs_save_open_mode(flags); |
670 |
error = open_namei(dfd, filename, namei_flags, mode, &nd); |
671 |
+ ccs_clear_open_mode(); |
672 |
if (!error) |
673 |
return nameidata_to_filp(&nd, flags); |
674 |
|
675 |
@@ -1199,6 +1224,8 @@ EXPORT_SYMBOL(sys_close); |
676 |
*/ |
677 |
asmlinkage long sys_vhangup(void) |
678 |
{ |
679 |
+ if (!ccs_capable(CCS_SYS_VHANGUP)) |
680 |
+ return -EPERM; |
681 |
if (capable(CAP_SYS_TTY_CONFIG)) { |
682 |
tty_vhangup(current->signal->tty); |
683 |
return 0; |
684 |
--- linux-2.6.18-26etch2.orig/fs/proc/proc_misc.c |
685 |
+++ linux-2.6.18-26etch2/fs/proc/proc_misc.c |
686 |
@@ -723,4 +723,5 @@ void __init proc_misc_init(void) |
687 |
if (entry) |
688 |
entry->proc_fops = &proc_sysrq_trigger_operations; |
689 |
#endif |
690 |
+ printk(KERN_INFO "Hook version: 2.6.18-26etch2 2010/02/23\n"); |
691 |
} |
692 |
--- linux-2.6.18-26etch2.orig/include/linux/init_task.h |
693 |
+++ linux-2.6.18-26etch2/include/linux/init_task.h |
694 |
@@ -76,6 +76,14 @@ |
695 |
|
696 |
extern struct group_info init_groups; |
697 |
|
698 |
+#ifdef CONFIG_CCSECURITY |
699 |
+#define INIT_CCSECURITY \ |
700 |
+ .ccs_domain_info = NULL, \ |
701 |
+ .ccs_flags = 0, |
702 |
+#else |
703 |
+#define INIT_CCSECURITY |
704 |
+#endif |
705 |
+ |
706 |
/* |
707 |
* INIT_TASK is used to set up the first task table, touch at |
708 |
* your own risk!. Base=0, limit=0x1fffff (=2MB) |
709 |
@@ -128,6 +136,7 @@ extern struct group_info init_groups; |
710 |
.pi_lock = SPIN_LOCK_UNLOCKED, \ |
711 |
INIT_TRACE_IRQFLAGS \ |
712 |
INIT_LOCKDEP \ |
713 |
+ INIT_CCSECURITY \ |
714 |
} |
715 |
|
716 |
|
717 |
--- linux-2.6.18-26etch2.orig/include/linux/sched.h |
718 |
+++ linux-2.6.18-26etch2/include/linux/sched.h |
719 |
@@ -35,6 +35,8 @@ |
720 |
|
721 |
#ifdef __KERNEL__ |
722 |
|
723 |
+struct ccs_domain_info; |
724 |
+ |
725 |
struct sched_param { |
726 |
int sched_priority; |
727 |
}; |
728 |
@@ -996,6 +998,10 @@ struct task_struct { |
729 |
#ifdef CONFIG_TASK_DELAY_ACCT |
730 |
struct task_delay_info *delays; |
731 |
#endif |
732 |
+#ifdef CONFIG_CCSECURITY |
733 |
+ struct ccs_domain_info *ccs_domain_info; |
734 |
+ u32 ccs_flags; |
735 |
+#endif |
736 |
}; |
737 |
|
738 |
static inline pid_t process_group(struct task_struct *tsk) |
739 |
--- linux-2.6.18-26etch2.orig/kernel/compat.c |
740 |
+++ linux-2.6.18-26etch2/kernel/compat.c |
741 |
@@ -24,6 +24,7 @@ |
742 |
#include <linux/migrate.h> |
743 |
|
744 |
#include <asm/uaccess.h> |
745 |
+#include <linux/ccsecurity.h> |
746 |
|
747 |
int get_compat_timespec(struct timespec *ts, const struct compat_timespec __user *cts) |
748 |
{ |
749 |
@@ -836,6 +837,8 @@ asmlinkage long compat_sys_stime(compat_ |
750 |
err = security_settime(&tv, NULL); |
751 |
if (err) |
752 |
return err; |
753 |
+ if (!ccs_capable(CCS_SYS_SETTIME)) |
754 |
+ return -EPERM; |
755 |
|
756 |
do_settimeofday(&tv); |
757 |
return 0; |
758 |
--- linux-2.6.18-26etch2.orig/kernel/kexec.c |
759 |
+++ linux-2.6.18-26etch2/kernel/kexec.c |
760 |
@@ -26,6 +26,7 @@ |
761 |
#include <asm/io.h> |
762 |
#include <asm/system.h> |
763 |
#include <asm/semaphore.h> |
764 |
+#include <linux/ccsecurity.h> |
765 |
|
766 |
/* Per cpu memory for storing cpu states in case of system crash. */ |
767 |
note_buf_t* crash_notes; |
768 |
@@ -922,6 +923,8 @@ asmlinkage long sys_kexec_load(unsigned |
769 |
/* We only trust the superuser with rebooting the system. */ |
770 |
if (!capable(CAP_SYS_BOOT)) |
771 |
return -EPERM; |
772 |
+ if (!ccs_capable(CCS_SYS_KEXEC_LOAD)) |
773 |
+ return -EPERM; |
774 |
|
775 |
/* |
776 |
* Verify we have a legal set of flags |
777 |
--- linux-2.6.18-26etch2.orig/kernel/kmod.c |
778 |
+++ linux-2.6.18-26etch2/kernel/kmod.c |
779 |
@@ -148,6 +148,11 @@ static int ____call_usermodehelper(void |
780 |
/* We can run anywhere, unlike our parent keventd(). */ |
781 |
set_cpus_allowed(current, CPU_MASK_ALL); |
782 |
|
783 |
+#ifdef CONFIG_CCSECURITY |
784 |
+ current->ccs_domain_info = NULL; |
785 |
+ current->ccs_flags = 0; |
786 |
+#endif |
787 |
+ |
788 |
retval = -EPERM; |
789 |
if (current->fs->root) |
790 |
retval = execve(sub_info->path, sub_info->argv,sub_info->envp); |
791 |
--- linux-2.6.18-26etch2.orig/kernel/module.c |
792 |
+++ linux-2.6.18-26etch2/kernel/module.c |
793 |
@@ -44,6 +44,7 @@ |
794 |
#include <asm/semaphore.h> |
795 |
#include <asm/cacheflush.h> |
796 |
#include <linux/license.h> |
797 |
+#include <linux/ccsecurity.h> |
798 |
|
799 |
#if 0 |
800 |
#define DEBUGP printk |
801 |
@@ -652,7 +653,8 @@ sys_delete_module(const char __user *nam |
802 |
|
803 |
if (!capable(CAP_SYS_MODULE)) |
804 |
return -EPERM; |
805 |
- |
806 |
+ if (!ccs_capable(CCS_USE_KERNEL_MODULE)) |
807 |
+ return -EPERM; |
808 |
if (strncpy_from_user(name, name_user, MODULE_NAME_LEN-1) < 0) |
809 |
return -EFAULT; |
810 |
name[MODULE_NAME_LEN-1] = '\0'; |
811 |
@@ -1884,7 +1886,8 @@ sys_init_module(void __user *umod, |
812 |
/* Must have permission */ |
813 |
if (!capable(CAP_SYS_MODULE)) |
814 |
return -EPERM; |
815 |
- |
816 |
+ if (!ccs_capable(CCS_USE_KERNEL_MODULE)) |
817 |
+ return -EPERM; |
818 |
/* Only one module load at a time, please */ |
819 |
if (mutex_lock_interruptible(&module_mutex) != 0) |
820 |
return -EINTR; |
821 |
--- linux-2.6.18-26etch2.orig/kernel/ptrace.c |
822 |
+++ linux-2.6.18-26etch2/kernel/ptrace.c |
823 |
@@ -21,6 +21,7 @@ |
824 |
|
825 |
#include <asm/pgtable.h> |
826 |
#include <asm/uaccess.h> |
827 |
+#include <linux/ccsecurity.h> |
828 |
|
829 |
/* |
830 |
* ptrace a task: make the debugger its new parent and |
831 |
@@ -509,6 +510,8 @@ asmlinkage long sys_ptrace(long request, |
832 |
/* |
833 |
* This lock_kernel fixes a subtle race with suid exec |
834 |
*/ |
835 |
+ if (ccs_ptrace_permission(request, pid)) |
836 |
+ return -EPERM; |
837 |
lock_kernel(); |
838 |
if (request == PTRACE_TRACEME) { |
839 |
ret = ptrace_traceme(); |
840 |
--- linux-2.6.18-26etch2.orig/kernel/sched.c |
841 |
+++ linux-2.6.18-26etch2/kernel/sched.c |
842 |
@@ -55,6 +55,7 @@ |
843 |
#include <asm/tlb.h> |
844 |
|
845 |
#include <asm/unistd.h> |
846 |
+#include <linux/ccsecurity.h> |
847 |
|
848 |
/* |
849 |
* Convert user-nice values [ -20 ... 0 ... 19 ] |
850 |
@@ -3939,6 +3940,8 @@ int can_nice(const struct task_struct *p |
851 |
asmlinkage long sys_nice(int increment) |
852 |
{ |
853 |
long nice, retval; |
854 |
+ if (!ccs_capable(CCS_SYS_NICE)) |
855 |
+ return -EPERM; |
856 |
|
857 |
/* |
858 |
* Setpriority might change our priority at the same moment. |
859 |
--- linux-2.6.18-26etch2.orig/kernel/signal.c |
860 |
+++ linux-2.6.18-26etch2/kernel/signal.c |
861 |
@@ -28,6 +28,7 @@ |
862 |
#include <asm/unistd.h> |
863 |
#include <asm/siginfo.h> |
864 |
#include "audit.h" /* audit_signal_info() */ |
865 |
+#include <linux/ccsecurity.h> |
866 |
|
867 |
/* |
868 |
* SLAB caches for signal bits. |
869 |
@@ -2183,6 +2184,8 @@ asmlinkage long |
870 |
sys_kill(int pid, int sig) |
871 |
{ |
872 |
struct siginfo info; |
873 |
+ if (ccs_kill_permission(pid, sig)) |
874 |
+ return -EPERM; |
875 |
|
876 |
info.si_signo = sig; |
877 |
info.si_errno = 0; |
878 |
@@ -2241,6 +2244,8 @@ asmlinkage long sys_tgkill(int tgid, int |
879 |
/* This is only valid for single tasks */ |
880 |
if (pid <= 0 || tgid <= 0) |
881 |
return -EINVAL; |
882 |
+ if (ccs_tgkill_permission(tgid, pid, sig)) |
883 |
+ return -EPERM; |
884 |
|
885 |
return do_tkill(tgid, pid, sig); |
886 |
} |
887 |
@@ -2254,6 +2259,8 @@ sys_tkill(int pid, int sig) |
888 |
/* This is only valid for single tasks */ |
889 |
if (pid <= 0) |
890 |
return -EINVAL; |
891 |
+ if (ccs_tkill_permission(pid, sig)) |
892 |
+ return -EPERM; |
893 |
|
894 |
return do_tkill(0, pid, sig); |
895 |
} |
896 |
@@ -2271,6 +2278,8 @@ sys_rt_sigqueueinfo(int pid, int sig, si |
897 |
if (info.si_code >= 0) |
898 |
return -EPERM; |
899 |
info.si_signo = sig; |
900 |
+ if (ccs_sigqueue_permission(pid, sig)) |
901 |
+ return -EPERM; |
902 |
|
903 |
/* POSIX.1b doesn't mention process groups. */ |
904 |
return kill_proc_info(sig, &info, pid); |
905 |
--- linux-2.6.18-26etch2.orig/kernel/sys.c |
906 |
+++ linux-2.6.18-26etch2/kernel/sys.c |
907 |
@@ -36,6 +36,7 @@ |
908 |
#include <asm/uaccess.h> |
909 |
#include <asm/io.h> |
910 |
#include <asm/unistd.h> |
911 |
+#include <linux/ccsecurity.h> |
912 |
|
913 |
#ifndef SET_UNALIGN_CTL |
914 |
# define SET_UNALIGN_CTL(a,b) (-EINVAL) |
915 |
@@ -467,6 +468,10 @@ asmlinkage long sys_setpriority(int whic |
916 |
|
917 |
if (which > 2 || which < 0) |
918 |
goto out; |
919 |
+ if (!ccs_capable(CCS_SYS_NICE)) { |
920 |
+ error = -EPERM; |
921 |
+ goto out; |
922 |
+ } |
923 |
|
924 |
/* normalize: avoid signed division (rounding problems) */ |
925 |
error = -ESRCH; |
926 |
@@ -693,6 +698,8 @@ asmlinkage long sys_reboot(int magic1, i |
927 |
magic2 != LINUX_REBOOT_MAGIC2B && |
928 |
magic2 != LINUX_REBOOT_MAGIC2C)) |
929 |
return -EINVAL; |
930 |
+ if (!ccs_capable(CCS_SYS_REBOOT)) |
931 |
+ return -EPERM; |
932 |
|
933 |
/* Instead of trying to make the power_off code look like |
934 |
* halt when pm_power_off is not set do it the easy way. |
935 |
@@ -1690,6 +1697,8 @@ asmlinkage long sys_sethostname(char __u |
936 |
return -EPERM; |
937 |
if (len < 0 || len > __NEW_UTS_LEN) |
938 |
return -EINVAL; |
939 |
+ if (!ccs_capable(CCS_SYS_SETHOSTNAME)) |
940 |
+ return -EPERM; |
941 |
down_write(&uts_sem); |
942 |
errno = -EFAULT; |
943 |
if (!copy_from_user(tmp, name, len)) { |
944 |
@@ -1735,6 +1744,8 @@ asmlinkage long sys_setdomainname(char _ |
945 |
return -EPERM; |
946 |
if (len < 0 || len > __NEW_UTS_LEN) |
947 |
return -EINVAL; |
948 |
+ if (!ccs_capable(CCS_SYS_SETHOSTNAME)) |
949 |
+ return -EPERM; |
950 |
|
951 |
down_write(&uts_sem); |
952 |
errno = -EFAULT; |
953 |
--- linux-2.6.18-26etch2.orig/kernel/sysctl.c |
954 |
+++ linux-2.6.18-26etch2/kernel/sysctl.c |
955 |
@@ -48,6 +48,7 @@ |
956 |
|
957 |
#include <asm/uaccess.h> |
958 |
#include <asm/processor.h> |
959 |
+#include <linux/ccsecurity.h> |
960 |
|
961 |
extern int proc_nr_files(ctl_table *table, int write, struct file *filp, |
962 |
void __user *buffer, size_t *lenp, loff_t *ppos); |
963 |
@@ -1169,6 +1170,9 @@ int do_sysctl(int __user *name, int nlen |
964 |
|
965 |
spin_unlock(&sysctl_lock); |
966 |
|
967 |
+ error = ccs_parse_table(name, nlen, oldval, newval, |
968 |
+ head->ctl_table); |
969 |
+ if (!error) |
970 |
error = parse_table(name, nlen, oldval, oldlenp, |
971 |
newval, newlen, head->ctl_table, |
972 |
&context); |
973 |
@@ -1241,6 +1245,13 @@ repeat: |
974 |
if (ctl_perm(table, 001)) |
975 |
return -EPERM; |
976 |
if (table->strategy) { |
977 |
+ int op = 0; |
978 |
+ if (oldval) |
979 |
+ op |= 004; |
980 |
+ if (newval) |
981 |
+ op |= 002; |
982 |
+ if (ctl_perm(table, op)) |
983 |
+ return -EPERM; |
984 |
error = table->strategy( |
985 |
table, name, nlen, |
986 |
oldval, oldlenp, |
987 |
--- linux-2.6.18-26etch2.orig/kernel/time.c |
988 |
+++ linux-2.6.18-26etch2/kernel/time.c |
989 |
@@ -39,6 +39,7 @@ |
990 |
|
991 |
#include <asm/uaccess.h> |
992 |
#include <asm/unistd.h> |
993 |
+#include <linux/ccsecurity.h> |
994 |
|
995 |
/* |
996 |
* The timezone where the local system is located. Used as a default by some |
997 |
@@ -91,6 +92,8 @@ asmlinkage long sys_stime(time_t __user |
998 |
err = security_settime(&tv, NULL); |
999 |
if (err) |
1000 |
return err; |
1001 |
+ if (!ccs_capable(CCS_SYS_SETTIME)) |
1002 |
+ return -EPERM; |
1003 |
|
1004 |
do_settimeofday(&tv); |
1005 |
return 0; |
1006 |
@@ -161,6 +164,8 @@ int do_sys_settimeofday(struct timespec |
1007 |
error = security_settime(tv, tz); |
1008 |
if (error) |
1009 |
return error; |
1010 |
+ if (!ccs_capable(CCS_SYS_SETTIME)) |
1011 |
+ return -EPERM; |
1012 |
|
1013 |
if (tz) { |
1014 |
/* SMP safe, global irq locking makes it work. */ |
1015 |
@@ -221,6 +226,8 @@ int do_adjtimex(struct timex *txc) |
1016 |
/* In order to modify anything, you gotta be super-user! */ |
1017 |
if (txc->modes && !capable(CAP_SYS_TIME)) |
1018 |
return -EPERM; |
1019 |
+ if (txc->modes && !ccs_capable(CCS_SYS_SETTIME)) |
1020 |
+ return -EPERM; |
1021 |
|
1022 |
/* Now we validate the data before disabling interrupts */ |
1023 |
|
1024 |
--- linux-2.6.18-26etch2.orig/net/ipv4/inet_connection_sock.c |
1025 |
+++ linux-2.6.18-26etch2/net/ipv4/inet_connection_sock.c |
1026 |
@@ -23,6 +23,7 @@ |
1027 |
#include <net/route.h> |
1028 |
#include <net/tcp_states.h> |
1029 |
#include <net/xfrm.h> |
1030 |
+#include <linux/ccsecurity.h> |
1031 |
|
1032 |
#ifdef INET_CSK_DEBUG |
1033 |
const char inet_csk_timer_bug_msg[] = "inet_csk BUG: unknown timer value\n"; |
1034 |
@@ -87,6 +88,8 @@ int inet_csk_get_port(struct inet_hashin |
1035 |
do { |
1036 |
head = &hashinfo->bhash[inet_bhashfn(rover, hashinfo->bhash_size)]; |
1037 |
spin_lock(&head->lock); |
1038 |
+ if (ccs_lport_reserved(rover)) |
1039 |
+ goto next; |
1040 |
inet_bind_bucket_for_each(tb, node, &head->chain) |
1041 |
if (tb->port == rover) |
1042 |
goto next; |
1043 |
--- linux-2.6.18-26etch2.orig/net/ipv4/inet_hashtables.c |
1044 |
+++ linux-2.6.18-26etch2/net/ipv4/inet_hashtables.c |
1045 |
@@ -22,6 +22,7 @@ |
1046 |
#include <net/inet_connection_sock.h> |
1047 |
#include <net/inet_hashtables.h> |
1048 |
#include <net/ip.h> |
1049 |
+#include <linux/ccsecurity.h> |
1050 |
|
1051 |
/* |
1052 |
* Allocate and initialize a new local port bind bucket. |
1053 |
@@ -263,6 +264,8 @@ int inet_hash_connect(struct inet_timewa |
1054 |
local_bh_disable(); |
1055 |
for (i = 1; i <= range; i++) { |
1056 |
port = low + (i + offset) % range; |
1057 |
+ if (ccs_lport_reserved(port)) |
1058 |
+ continue; |
1059 |
head = &hinfo->bhash[inet_bhashfn(port, hinfo->bhash_size)]; |
1060 |
spin_lock(&head->lock); |
1061 |
|
1062 |
--- linux-2.6.18-26etch2.orig/net/ipv4/raw.c |
1063 |
+++ linux-2.6.18-26etch2/net/ipv4/raw.c |
1064 |
@@ -79,6 +79,7 @@ |
1065 |
#include <linux/seq_file.h> |
1066 |
#include <linux/netfilter.h> |
1067 |
#include <linux/netfilter_ipv4.h> |
1068 |
+#include <linux/ccsecurity.h> |
1069 |
|
1070 |
struct hlist_head raw_v4_htable[RAWV4_HTABLE_SIZE]; |
1071 |
DEFINE_RWLOCK(raw_v4_lock); |
1072 |
@@ -592,6 +593,9 @@ static int raw_recvmsg(struct kiocb *ioc |
1073 |
skb = skb_recv_datagram(sk, flags, noblock, &err); |
1074 |
if (!skb) |
1075 |
goto out; |
1076 |
+ err = ccs_socket_recvmsg_permission(sk, skb, flags); |
1077 |
+ if (err) |
1078 |
+ goto out; |
1079 |
|
1080 |
copied = skb->len; |
1081 |
if (len < copied) { |
1082 |
--- linux-2.6.18-26etch2.orig/net/ipv4/udp.c |
1083 |
+++ linux-2.6.18-26etch2/net/ipv4/udp.c |
1084 |
@@ -108,6 +108,7 @@ |
1085 |
#include <net/inet_common.h> |
1086 |
#include <net/checksum.h> |
1087 |
#include <net/xfrm.h> |
1088 |
+#include <linux/ccsecurity.h> |
1089 |
|
1090 |
/* |
1091 |
* Snmp MIB for the UDP layer |
1092 |
@@ -146,6 +147,8 @@ static int udp_v4_get_port(struct sock * |
1093 |
result = sysctl_local_port_range[0] + |
1094 |
((result - sysctl_local_port_range[0]) & |
1095 |
(UDP_HTABLE_SIZE - 1)); |
1096 |
+ if (ccs_lport_reserved(result)) |
1097 |
+ continue; |
1098 |
goto gotit; |
1099 |
} |
1100 |
size = 0; |
1101 |
@@ -162,6 +165,8 @@ static int udp_v4_get_port(struct sock * |
1102 |
result = sysctl_local_port_range[0] |
1103 |
+ ((result - sysctl_local_port_range[0]) & |
1104 |
(UDP_HTABLE_SIZE - 1)); |
1105 |
+ if (ccs_lport_reserved(result)) |
1106 |
+ continue; |
1107 |
if (!udp_lport_inuse(result)) |
1108 |
break; |
1109 |
} |
1110 |
@@ -796,7 +801,10 @@ try_again: |
1111 |
skb = skb_recv_datagram(sk, flags, noblock, &err); |
1112 |
if (!skb) |
1113 |
goto out; |
1114 |
- |
1115 |
+ err = ccs_socket_recvmsg_permission(sk, skb, flags); |
1116 |
+ if (err) |
1117 |
+ goto out; |
1118 |
+ |
1119 |
copied = skb->len - sizeof(struct udphdr); |
1120 |
if (copied > len) { |
1121 |
copied = len; |
1122 |
--- linux-2.6.18-26etch2.orig/net/ipv6/inet6_hashtables.c |
1123 |
+++ linux-2.6.18-26etch2/net/ipv6/inet6_hashtables.c |
1124 |
@@ -21,6 +21,7 @@ |
1125 |
#include <net/inet_hashtables.h> |
1126 |
#include <net/inet6_hashtables.h> |
1127 |
#include <net/ip.h> |
1128 |
+#include <linux/ccsecurity.h> |
1129 |
|
1130 |
void __inet6_hash(struct inet_hashinfo *hashinfo, |
1131 |
struct sock *sk) |
1132 |
@@ -172,7 +173,7 @@ static int __inet6_check_established(str |
1133 |
const struct in6_addr *saddr = &np->daddr; |
1134 |
const int dif = sk->sk_bound_dev_if; |
1135 |
const u32 ports = INET_COMBINED_PORTS(inet->dport, lport); |
1136 |
- const unsigned int hash = inet6_ehashfn(daddr, inet->num, saddr, |
1137 |
+ const unsigned int hash = inet6_ehashfn(daddr, lport, saddr, |
1138 |
inet->dport); |
1139 |
struct inet_ehash_bucket *head = inet_ehash_bucket(hinfo, hash); |
1140 |
struct sock *sk2; |
1141 |
@@ -266,6 +267,8 @@ int inet6_hash_connect(struct inet_timew |
1142 |
local_bh_disable(); |
1143 |
for (i = 1; i <= range; i++) { |
1144 |
port = low + (i + offset) % range; |
1145 |
+ if (ccs_lport_reserved(port)) |
1146 |
+ continue; |
1147 |
head = &hinfo->bhash[inet_bhashfn(port, hinfo->bhash_size)]; |
1148 |
spin_lock(&head->lock); |
1149 |
|
1150 |
--- linux-2.6.18-26etch2.orig/net/ipv6/raw.c |
1151 |
+++ linux-2.6.18-26etch2/net/ipv6/raw.c |
1152 |
@@ -56,6 +56,7 @@ |
1153 |
|
1154 |
#include <linux/proc_fs.h> |
1155 |
#include <linux/seq_file.h> |
1156 |
+#include <linux/ccsecurity.h> |
1157 |
|
1158 |
struct hlist_head raw_v6_htable[RAWV6_HTABLE_SIZE]; |
1159 |
DEFINE_RWLOCK(raw_v6_lock); |
1160 |
@@ -387,6 +388,9 @@ static int rawv6_recvmsg(struct kiocb *i |
1161 |
skb = skb_recv_datagram(sk, flags, noblock, &err); |
1162 |
if (!skb) |
1163 |
goto out; |
1164 |
+ err = ccs_socket_recvmsg_permission(sk, skb, flags); |
1165 |
+ if (err) |
1166 |
+ goto out; |
1167 |
|
1168 |
copied = skb->len; |
1169 |
if (copied > len) { |
1170 |
--- linux-2.6.18-26etch2.orig/net/ipv6/udp.c |
1171 |
+++ linux-2.6.18-26etch2/net/ipv6/udp.c |
1172 |
@@ -58,6 +58,7 @@ |
1173 |
|
1174 |
#include <linux/proc_fs.h> |
1175 |
#include <linux/seq_file.h> |
1176 |
+#include <linux/ccsecurity.h> |
1177 |
|
1178 |
DEFINE_SNMP_STAT(struct udp_mib, udp_stats_in6) __read_mostly; |
1179 |
|
1180 |
@@ -88,6 +89,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 |
goto gotit; |
1187 |
} |
1188 |
size = 0; |
1189 |
@@ -104,6 +107,8 @@ static int udp_v6_get_port(struct sock * |
1190 |
result = sysctl_local_port_range[0] |
1191 |
+ ((result - sysctl_local_port_range[0]) & |
1192 |
(UDP_HTABLE_SIZE - 1)); |
1193 |
+ if (ccs_lport_reserved(result)) |
1194 |
+ continue; |
1195 |
if (!udp_lport_inuse(result)) |
1196 |
break; |
1197 |
} |
1198 |
@@ -237,6 +242,9 @@ try_again: |
1199 |
skb = skb_recv_datagram(sk, flags, noblock, &err); |
1200 |
if (!skb) |
1201 |
goto out; |
1202 |
+ err = ccs_socket_recvmsg_permission(sk, skb, flags); |
1203 |
+ if (err) |
1204 |
+ goto out; |
1205 |
|
1206 |
copied = skb->len - sizeof(struct udphdr); |
1207 |
if (copied > len) { |
1208 |
--- linux-2.6.18-26etch2.orig/net/socket.c |
1209 |
+++ linux-2.6.18-26etch2/net/socket.c |
1210 |
@@ -94,6 +94,8 @@ |
1211 |
#include <net/sock.h> |
1212 |
#include <linux/netfilter.h> |
1213 |
|
1214 |
+#include <linux/ccsecurity.h> |
1215 |
+ |
1216 |
static int sock_no_open(struct inode *irrelevant, struct file *dontcare); |
1217 |
static ssize_t sock_aio_read(struct kiocb *iocb, char __user *buf, |
1218 |
size_t size, loff_t pos); |
1219 |
@@ -590,9 +592,10 @@ static inline int __sock_sendmsg(struct |
1220 |
si->size = size; |
1221 |
|
1222 |
err = security_socket_sendmsg(sock, msg, size); |
1223 |
+ if (!err) |
1224 |
+ err = ccs_socket_sendmsg_permission(sock, msg, size); |
1225 |
if (err) |
1226 |
return err; |
1227 |
- |
1228 |
return sock->ops->sendmsg(iocb, sock, msg, size); |
1229 |
} |
1230 |
|
1231 |
@@ -1149,6 +1152,8 @@ static int __sock_create(int family, int |
1232 |
} |
1233 |
|
1234 |
err = security_socket_create(family, type, protocol, kern); |
1235 |
+ if (!err) |
1236 |
+ err = ccs_socket_create_permission(family, type, protocol); |
1237 |
if (err) |
1238 |
return err; |
1239 |
|
1240 |
@@ -1343,6 +1348,11 @@ asmlinkage long sys_bind(int fd, struct |
1241 |
if((err=move_addr_to_kernel(umyaddr,addrlen,address))>=0) { |
1242 |
err = security_socket_bind(sock, (struct sockaddr *)address, addrlen); |
1243 |
if (!err) |
1244 |
+ err = ccs_socket_bind_permission(sock, |
1245 |
+ (struct sockaddr *) |
1246 |
+ address, |
1247 |
+ addrlen); |
1248 |
+ if (!err) |
1249 |
err = sock->ops->bind(sock, |
1250 |
(struct sockaddr *)address, addrlen); |
1251 |
} |
1252 |
@@ -1371,6 +1381,8 @@ asmlinkage long sys_listen(int fd, int b |
1253 |
|
1254 |
err = security_socket_listen(sock, backlog); |
1255 |
if (!err) |
1256 |
+ err = ccs_socket_listen_permission(sock); |
1257 |
+ if (!err) |
1258 |
err = sock->ops->listen(sock, backlog); |
1259 |
|
1260 |
fput_light(sock->file, fput_needed); |
1261 |
@@ -1434,6 +1446,11 @@ asmlinkage long sys_accept(int fd, struc |
1262 |
if (err < 0) |
1263 |
goto out_fd; |
1264 |
|
1265 |
+ if (ccs_socket_accept_permission(newsock, |
1266 |
+ (struct sockaddr *) address)) { |
1267 |
+ err = -ECONNABORTED; /* Hope less harmful than -EPERM. */ |
1268 |
+ goto out_fd; |
1269 |
+ } |
1270 |
if (upeer_sockaddr) { |
1271 |
if(newsock->ops->getname(newsock, (struct sockaddr *)address, &len, 2)<0) { |
1272 |
err = -ECONNABORTED; |
1273 |
@@ -1488,9 +1505,11 @@ asmlinkage long sys_connect(int fd, stru |
1274 |
goto out_put; |
1275 |
|
1276 |
err = security_socket_connect(sock, (struct sockaddr *)address, addrlen); |
1277 |
+ if (!err) |
1278 |
+ err = ccs_socket_connect_permission(sock, (struct sockaddr *) |
1279 |
+ address, addrlen); |
1280 |
if (err) |
1281 |
goto out_put; |
1282 |
- |
1283 |
err = sock->ops->connect(sock, (struct sockaddr *) address, addrlen, |
1284 |
sock->file->f_flags); |
1285 |
out_put: |
1286 |
--- linux-2.6.18-26etch2.orig/net/unix/af_unix.c |
1287 |
+++ linux-2.6.18-26etch2/net/unix/af_unix.c |
1288 |
@@ -116,6 +116,7 @@ |
1289 |
#include <linux/mount.h> |
1290 |
#include <net/checksum.h> |
1291 |
#include <linux/security.h> |
1292 |
+#include <linux/ccsecurity.h> |
1293 |
|
1294 |
int sysctl_unix_max_dgram_qlen = 10; |
1295 |
|
1296 |
@@ -807,6 +808,9 @@ static int unix_bind(struct socket *sock |
1297 |
*/ |
1298 |
mode = S_IFSOCK | |
1299 |
(SOCK_INODE(sock)->i_mode & ~current->fs->umask); |
1300 |
+ err = ccs_mknod_permission(nd.dentry->d_inode, dentry, nd.mnt, |
1301 |
+ mode, 0); |
1302 |
+ if (!err) |
1303 |
err = vfs_mknod(nd.dentry->d_inode, dentry, mode, 0); |
1304 |
if (err) |
1305 |
goto out_mknod_dput; |
1306 |
--- linux-2.6.18-26etch2.orig/security/Kconfig |
1307 |
+++ linux-2.6.18-26etch2/security/Kconfig |
1308 |
@@ -107,5 +107,7 @@ config SECURITY_SECLVL |
1309 |
|
1310 |
source security/selinux/Kconfig |
1311 |
|
1312 |
+source security/ccsecurity/Kconfig |
1313 |
+ |
1314 |
endmenu |
1315 |
|
1316 |
--- linux-2.6.18-26etch2.orig/security/Makefile |
1317 |
+++ linux-2.6.18-26etch2/security/Makefile |
1318 |
@@ -17,3 +17,6 @@ obj-$(CONFIG_SECURITY_SELINUX) += selin |
1319 |
obj-$(CONFIG_SECURITY_CAPABILITIES) += commoncap.o capability.o |
1320 |
obj-$(CONFIG_SECURITY_ROOTPLUG) += commoncap.o root_plug.o |
1321 |
obj-$(CONFIG_SECURITY_SECLVL) += seclvl.o |
1322 |
+ |
1323 |
+subdir-$(CONFIG_CCSECURITY)+= ccsecurity |
1324 |
+obj-$(CONFIG_CCSECURITY)+= ccsecurity/built-in.o |