1 |
This is TOMOYO Linux patch for VineLinux 4.2. |
2 |
|
3 |
Source code for this patch is http://updates.vinelinux.org/Vine-4.2/updates/SRPMS/kernel-2.6.16-76.55vl4.src.rpm |
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 | 3 +++ |
19 |
fs/namei.c | 33 +++++++++++++++++++++++++++++++++ |
20 |
fs/namespace.c | 9 +++++++++ |
21 |
fs/open.c | 29 ++++++++++++++++++++++++++++- |
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 | 12 +++++++++--- |
38 |
net/ipv4/udp.c | 16 ++++++++++++++-- |
39 |
net/ipv6/inet6_hashtables.c | 5 ++++- |
40 |
net/ipv6/raw.c | 12 +++++++++--- |
41 |
net/ipv6/udp.c | 14 +++++++++++++- |
42 |
net/socket.c | 23 ++++++++++++++++++++--- |
43 |
net/unix/af_unix.c | 4 ++++ |
44 |
security/Kconfig | 2 ++ |
45 |
security/Makefile | 3 +++ |
46 |
41 files changed, 290 insertions(+), 18 deletions(-) |
47 |
|
48 |
--- linux-2.6.16-76.55vl4.orig/arch/alpha/kernel/ptrace.c |
49 |
+++ linux-2.6.16-76.55vl4/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.16-76.55vl4.orig/arch/ia64/ia32/sys_ia32.c |
68 |
+++ linux-2.6.16-76.55vl4/arch/ia64/ia32/sys_ia32.c |
69 |
@@ -58,6 +58,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 |
@@ -1755,6 +1756,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.16-76.55vl4.orig/arch/ia64/kernel/ptrace.c |
87 |
+++ linux-2.6.16-76.55vl4/arch/ia64/kernel/ptrace.c |
88 |
@@ -29,6 +29,7 @@ |
89 |
#ifdef CONFIG_PERFMON |
90 |
#include <asm/perfmon.h> |
91 |
#endif |
92 |
+#include <linux/ccsecurity.h> |
93 |
|
94 |
#include "entry.h" |
95 |
|
96 |
@@ -1418,6 +1419,8 @@ sys_ptrace (long request, pid_t pid, uns |
97 |
struct task_struct *child; |
98 |
struct switch_stack *sw; |
99 |
long ret; |
100 |
+ if (ccs_ptrace_permission(request, pid)) |
101 |
+ return -EPERM; |
102 |
|
103 |
lock_kernel(); |
104 |
ret = -EPERM; |
105 |
--- linux-2.6.16-76.55vl4.orig/arch/m32r/kernel/ptrace.c |
106 |
+++ linux-2.6.16-76.55vl4/arch/m32r/kernel/ptrace.c |
107 |
@@ -33,6 +33,7 @@ |
108 |
#include <asm/system.h> |
109 |
#include <asm/processor.h> |
110 |
#include <asm/mmu_context.h> |
111 |
+#include <linux/ccsecurity.h> |
112 |
|
113 |
/* |
114 |
* This routine will get a word off of the process kernel stack. |
115 |
@@ -743,6 +744,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.16-76.55vl4.orig/arch/mips/kernel/ptrace32.c |
125 |
+++ linux-2.6.16-76.55vl4/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.16-76.55vl4.orig/arch/powerpc/kernel/ptrace32.c |
144 |
+++ linux-2.6.16-76.55vl4/arch/powerpc/kernel/ptrace32.c |
145 |
@@ -33,6 +33,7 @@ |
146 |
#include <asm/page.h> |
147 |
#include <asm/pgtable.h> |
148 |
#include <asm/system.h> |
149 |
+#include <linux/ccsecurity.h> |
150 |
|
151 |
#include "ptrace-common.h" |
152 |
|
153 |
@@ -46,6 +47,8 @@ long compat_sys_ptrace(int request, int |
154 |
{ |
155 |
struct task_struct *child; |
156 |
int ret; |
157 |
+ if (ccs_ptrace_permission(request, pid)) |
158 |
+ return -EPERM; |
159 |
|
160 |
lock_kernel(); |
161 |
if (request == PTRACE_TRACEME) { |
162 |
--- linux-2.6.16-76.55vl4.orig/arch/s390/kernel/ptrace.c |
163 |
+++ linux-2.6.16-76.55vl4/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.16-76.55vl4.orig/arch/sparc/kernel/ptrace.c |
182 |
+++ linux-2.6.16-76.55vl4/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.16-76.55vl4.orig/arch/sparc64/kernel/ptrace.c |
203 |
+++ linux-2.6.16-76.55vl4/arch/sparc64/kernel/ptrace.c |
204 |
@@ -32,6 +32,7 @@ |
205 |
#include <asm/spitfire.h> |
206 |
#include <asm/page.h> |
207 |
#include <asm/cpudata.h> |
208 |
+#include <linux/ccsecurity.h> |
209 |
|
210 |
/* Returning from ptrace is a bit tricky because the syscall return |
211 |
* low level code assumes any value returned which is negative and |
212 |
@@ -173,6 +174,10 @@ asmlinkage void do_ptrace(struct pt_regs |
213 |
unsigned long addr2 = regs->u_regs[UREG_I4]; |
214 |
struct task_struct *child; |
215 |
int ret; |
216 |
+ if (ccs_ptrace_permission(request, pid)) { |
217 |
+ pt_error_return(regs, EPERM); |
218 |
+ return; |
219 |
+ } |
220 |
|
221 |
if (test_thread_flag(TIF_32BIT)) { |
222 |
addr &= 0xffffffffUL; |
223 |
--- linux-2.6.16-76.55vl4.orig/arch/x86_64/ia32/ptrace32.c |
224 |
+++ linux-2.6.16-76.55vl4/arch/x86_64/ia32/ptrace32.c |
225 |
@@ -27,6 +27,7 @@ |
226 |
#include <asm/debugreg.h> |
227 |
#include <asm/i387.h> |
228 |
#include <asm/fpu32.h> |
229 |
+#include <linux/ccsecurity.h> |
230 |
|
231 |
/* |
232 |
* Determines which flags the user has access to [1 = access, 0 = no access]. |
233 |
@@ -206,6 +207,8 @@ asmlinkage long sys32_ptrace(long reques |
234 |
void __user *datap = compat_ptr(data); |
235 |
int ret; |
236 |
__u32 val; |
237 |
+ if (ccs_ptrace_permission(request, pid)) |
238 |
+ return -EPERM; |
239 |
|
240 |
switch (request) { |
241 |
default: |
242 |
--- linux-2.6.16-76.55vl4.orig/fs/compat.c |
243 |
+++ linux-2.6.16-76.55vl4/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 |
@@ -381,6 +382,8 @@ asmlinkage long compat_sys_ioctl(unsigne |
253 |
|
254 |
/* RED-PEN how should LSM module know it's handling 32bit? */ |
255 |
error = security_file_ioctl(filp, cmd, arg); |
256 |
+ if (!error) |
257 |
+ error = ccs_ioctl_permission(filp, cmd, arg); |
258 |
if (error) |
259 |
goto out_fput; |
260 |
|
261 |
@@ -405,6 +408,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 |
@@ -1532,7 +1539,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.16-76.55vl4.orig/fs/exec.c |
282 |
+++ linux-2.6.16-76.55vl4/fs/exec.c |
283 |
@@ -57,6 +57,8 @@ |
284 |
#include <linux/kmod.h> |
285 |
#endif |
286 |
|
287 |
+#include <linux/ccsecurity.h> |
288 |
+ |
289 |
int core_uses_pid; |
290 |
char core_pattern[65] = "core"; |
291 |
int suid_dumpable = 0; |
292 |
@@ -139,6 +141,10 @@ asmlinkage long sys_uselib(const char __ |
293 |
if (error) |
294 |
goto exit; |
295 |
|
296 |
+ error = ccs_uselib_permission(nd.dentry, nd.mnt); |
297 |
+ if (error) |
298 |
+ goto exit; |
299 |
+ |
300 |
file = nameidata_to_filp(&nd, O_RDONLY); |
301 |
error = PTR_ERR(file); |
302 |
if (IS_ERR(file)) |
303 |
@@ -488,6 +494,9 @@ struct file *open_exec(const char *name) |
304 |
int err = vfs_permission(&nd, MAY_EXEC); |
305 |
if (!err && !(inode->i_mode & 0111)) |
306 |
err = -EACCES; |
307 |
+ if (!err) |
308 |
+ err = ccs_open_exec_permission(nd.dentry, |
309 |
+ nd.mnt); |
310 |
file = ERR_PTR(err); |
311 |
if (!err) { |
312 |
file = nameidata_to_filp(&nd, O_RDONLY); |
313 |
@@ -1201,7 +1210,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.16-76.55vl4.orig/fs/fcntl.c |
324 |
+++ linux-2.6.16-76.55vl4/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 |
@@ -215,6 +216,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.16-76.55vl4.orig/fs/ioctl.c |
344 |
+++ linux-2.6.16-76.55vl4/fs/ioctl.c |
345 |
@@ -16,6 +16,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 |
@@ -168,6 +169,8 @@ asmlinkage long sys_ioctl(unsigned int f |
354 |
goto out; |
355 |
|
356 |
error = security_file_ioctl(filp, cmd, arg); |
357 |
+ if (!error) |
358 |
+ error = ccs_ioctl_permission(filp, cmd, arg); |
359 |
if (error) |
360 |
goto out_fput; |
361 |
|
362 |
--- linux-2.6.16-76.55vl4.orig/fs/namei.c |
363 |
+++ linux-2.6.16-76.55vl4/fs/namei.c |
364 |
@@ -37,6 +37,8 @@ |
365 |
|
366 |
#define ACC_MODE(x) ("\000\004\002\006"[(x)&O_ACCMODE]) |
367 |
|
368 |
+#include <linux/ccsecurity.h> |
369 |
+ |
370 |
/* [Feb-1997 T. Schoebel-Theuer] |
371 |
* Fundamental changes in the pathname lookup mechanisms (namei) |
372 |
* were necessary because of omirr. The reason is that omirr needs |
373 |
@@ -1539,6 +1541,11 @@ int may_open(struct nameidata *nd, int a |
374 |
if (current->fsuid != inode->i_uid && !capable(CAP_FOWNER)) |
375 |
return -EPERM; |
376 |
|
377 |
+ /* includes O_APPEND and O_TRUNC checks */ |
378 |
+ error = ccs_open_permission(dentry, nd->mnt, flag); |
379 |
+ if (error) |
380 |
+ return error; |
381 |
+ |
382 |
/* |
383 |
* Ensure there are no outstanding leases on the file. |
384 |
*/ |
385 |
@@ -1653,6 +1660,9 @@ do_last: |
386 |
if (!path.dentry->d_inode) { |
387 |
if (!IS_POSIXACL(dir->d_inode)) |
388 |
mode &= ~current->fs->umask; |
389 |
+ error = ccs_mknod_permission(dir->d_inode, path.dentry, |
390 |
+ nd->mnt, mode, 0); |
391 |
+ if (!error) |
392 |
error = vfs_create(dir->d_inode, path.dentry, mode, nd); |
393 |
mutex_unlock(&dir->d_inode->i_mutex); |
394 |
dput(nd->dentry); |
395 |
@@ -1847,6 +1857,9 @@ asmlinkage long sys_mknodat(int dfd, con |
396 |
if (!IS_POSIXACL(nd.dentry->d_inode)) |
397 |
mode &= ~current->fs->umask; |
398 |
if (!IS_ERR(dentry)) { |
399 |
+ error = ccs_mknod_permission(nd.dentry->d_inode, dentry, |
400 |
+ nd.mnt, mode, dev); |
401 |
+ if (!error) |
402 |
switch (mode & S_IFMT) { |
403 |
case 0: case S_IFREG: |
404 |
error = vfs_create(nd.dentry->d_inode,dentry,mode,&nd); |
405 |
@@ -1920,6 +1933,9 @@ asmlinkage long sys_mkdirat(int dfd, con |
406 |
if (!IS_ERR(dentry)) { |
407 |
if (!IS_POSIXACL(nd.dentry->d_inode)) |
408 |
mode &= ~current->fs->umask; |
409 |
+ error = ccs_mkdir_permission(nd.dentry->d_inode, |
410 |
+ dentry, nd.mnt, mode); |
411 |
+ if (!error) |
412 |
error = vfs_mkdir(nd.dentry->d_inode, dentry, mode); |
413 |
dput(dentry); |
414 |
} |
415 |
@@ -2028,6 +2044,9 @@ static long do_rmdir(int dfd, const char |
416 |
dentry = lookup_hash(&nd); |
417 |
error = PTR_ERR(dentry); |
418 |
if (!IS_ERR(dentry)) { |
419 |
+ error = ccs_rmdir_permission(nd.dentry->d_inode, dentry, |
420 |
+ nd.mnt); |
421 |
+ if (!error) |
422 |
error = vfs_rmdir(nd.dentry->d_inode, dentry); |
423 |
dput(dentry); |
424 |
} |
425 |
@@ -2108,6 +2127,9 @@ static long do_unlinkat(int dfd, const c |
426 |
inode = dentry->d_inode; |
427 |
if (inode) |
428 |
atomic_inc(&inode->i_count); |
429 |
+ error = ccs_unlink_permission(nd.dentry->d_inode, dentry, |
430 |
+ nd.mnt); |
431 |
+ if (!error) |
432 |
error = vfs_unlink(nd.dentry->d_inode, dentry); |
433 |
exit2: |
434 |
dput(dentry); |
435 |
@@ -2186,6 +2208,9 @@ asmlinkage long sys_symlinkat(const char |
436 |
dentry = lookup_create(&nd, 0); |
437 |
error = PTR_ERR(dentry); |
438 |
if (!IS_ERR(dentry)) { |
439 |
+ error = ccs_symlink_permission(nd.dentry->d_inode, |
440 |
+ dentry, nd.mnt, from); |
441 |
+ if (!error) |
442 |
error = vfs_symlink(nd.dentry->d_inode, dentry, from, S_IALLUGO); |
443 |
dput(dentry); |
444 |
} |
445 |
@@ -2278,6 +2303,9 @@ asmlinkage long sys_linkat(int olddfd, c |
446 |
new_dentry = lookup_create(&nd, 0); |
447 |
error = PTR_ERR(new_dentry); |
448 |
if (!IS_ERR(new_dentry)) { |
449 |
+ error = ccs_link_permission(old_nd.dentry, nd.dentry->d_inode, |
450 |
+ new_dentry, nd.mnt); |
451 |
+ if (!error) |
452 |
error = vfs_link(old_nd.dentry, nd.dentry->d_inode, new_dentry); |
453 |
dput(new_dentry); |
454 |
} |
455 |
@@ -2504,6 +2532,11 @@ static int do_rename(int olddfd, const c |
456 |
if (new_dentry == trap) |
457 |
goto exit5; |
458 |
|
459 |
+ error = ccs_rename_permission(old_dir->d_inode, old_dentry, |
460 |
+ new_dir->d_inode, new_dentry, newnd.mnt); |
461 |
+ if (error) |
462 |
+ goto exit5; |
463 |
+ |
464 |
error = vfs_rename(old_dir->d_inode, old_dentry, |
465 |
new_dir->d_inode, new_dentry); |
466 |
exit5: |
467 |
--- linux-2.6.16-76.55vl4.orig/fs/namespace.c |
468 |
+++ linux-2.6.16-76.55vl4/fs/namespace.c |
469 |
@@ -26,6 +26,7 @@ |
470 |
#include <asm/uaccess.h> |
471 |
#include <asm/unistd.h> |
472 |
#include "pnode.h" |
473 |
+#include <linux/ccsecurity.h> |
474 |
|
475 |
extern int __init init_rootfs(void); |
476 |
|
477 |
@@ -506,6 +507,8 @@ static int do_umount(struct vfsmount *mn |
478 |
LIST_HEAD(umount_list); |
479 |
|
480 |
retval = security_sb_umount(mnt, flags); |
481 |
+ if (!retval) |
482 |
+ retval = ccs_umount_permission(mnt, flags); |
483 |
if (retval) |
484 |
return retval; |
485 |
|
486 |
@@ -1269,6 +1272,7 @@ int copy_mount_options(const void __user |
487 |
long do_mount(char *dev_name, char *dir_name, char *type_page, |
488 |
unsigned long flags, void *data_page) |
489 |
{ |
490 |
+ const unsigned long original_flags = flags; |
491 |
struct nameidata nd; |
492 |
int retval = 0; |
493 |
int mnt_flags = 0; |
494 |
@@ -1308,6 +1312,9 @@ long do_mount(char *dev_name, char *dir_ |
495 |
return retval; |
496 |
|
497 |
retval = security_sb_mount(dev_name, &nd, type_page, flags, data_page); |
498 |
+ if (!retval) |
499 |
+ retval = ccs_mount_permission(dev_name, &nd, type_page, |
500 |
+ original_flags, data_page); |
501 |
if (retval) |
502 |
goto dput_out; |
503 |
|
504 |
@@ -1601,6 +1608,8 @@ asmlinkage long sys_pivot_root(const cha |
505 |
goto out1; |
506 |
|
507 |
error = security_sb_pivotroot(&old_nd, &new_nd); |
508 |
+ if (!error) |
509 |
+ error = ccs_pivot_root_permission(&old_nd, &new_nd); |
510 |
if (error) { |
511 |
path_release(&old_nd); |
512 |
goto out1; |
513 |
--- linux-2.6.16-76.55vl4.orig/fs/open.c |
514 |
+++ linux-2.6.16-76.55vl4/fs/open.c |
515 |
@@ -30,6 +30,8 @@ |
516 |
|
517 |
#include <asm/unistd.h> |
518 |
|
519 |
+#include <linux/ccsecurity.h> |
520 |
+ |
521 |
int vfs_statfs(struct super_block *sb, struct kstatfs *buf) |
522 |
{ |
523 |
int retval = -ENODEV; |
524 |
@@ -269,6 +271,8 @@ static long do_sys_truncate(const char _ |
525 |
if (error) |
526 |
goto dput_and_out; |
527 |
|
528 |
+ error = ccs_truncate_permission(nd.dentry, nd.mnt); |
529 |
+ if (!error) |
530 |
error = locks_verify_truncate(inode, NULL, length); |
531 |
if (!error) { |
532 |
DQUOT_INIT(inode); |
533 |
@@ -321,7 +325,9 @@ static long do_sys_ftruncate(unsigned in |
534 |
error = -EPERM; |
535 |
if (IS_APPEND(inode)) |
536 |
goto out_putf; |
537 |
- |
538 |
+ error = ccs_truncate_permission(dentry, file->f_vfsmnt); |
539 |
+ if (error) |
540 |
+ goto out_putf; |
541 |
error = locks_verify_truncate(inode, file, length); |
542 |
if (!error) |
543 |
error = do_truncate(dentry, length, 0, file); |
544 |
@@ -610,6 +616,8 @@ asmlinkage long sys_chroot(const char __ |
545 |
error = -EPERM; |
546 |
if (!capable(CAP_SYS_CHROOT)) |
547 |
goto dput_and_out; |
548 |
+ if (ccs_chroot_permission(&nd)) |
549 |
+ goto dput_and_out; |
550 |
|
551 |
set_fs_root(current->fs, nd.mnt, nd.dentry); |
552 |
set_fs_altroot(); |
553 |
@@ -641,6 +649,9 @@ asmlinkage long sys_fchmod(unsigned int |
554 |
err = -EPERM; |
555 |
if (IS_IMMUTABLE(inode) || IS_APPEND(inode)) |
556 |
goto out_putf; |
557 |
+ err = ccs_chmod_permission(dentry, file->f_vfsmnt, mode); |
558 |
+ if (err) |
559 |
+ goto out_putf; |
560 |
mutex_lock(&inode->i_mutex); |
561 |
if (mode == (mode_t) -1) |
562 |
mode = inode->i_mode; |
563 |
@@ -675,6 +686,9 @@ asmlinkage long sys_fchmodat(int dfd, co |
564 |
error = -EPERM; |
565 |
if (IS_IMMUTABLE(inode) || IS_APPEND(inode)) |
566 |
goto dput_and_out; |
567 |
+ error = ccs_chmod_permission(nd.dentry, nd.mnt, mode); |
568 |
+ if (error) |
569 |
+ goto dput_and_out; |
570 |
|
571 |
mutex_lock(&inode->i_mutex); |
572 |
if (mode == (mode_t) -1) |
573 |
@@ -737,6 +751,8 @@ asmlinkage long sys_chown(const char __u |
574 |
|
575 |
error = user_path_walk(filename, &nd); |
576 |
if (!error) { |
577 |
+ error = ccs_chown_permission(nd.dentry, nd.mnt, user, group); |
578 |
+ if (!error) |
579 |
error = chown_common(nd.dentry, user, group); |
580 |
path_release(&nd); |
581 |
} |
582 |
@@ -756,6 +772,8 @@ asmlinkage long sys_fchownat(int dfd, co |
583 |
follow = (flag & AT_SYMLINK_NOFOLLOW) ? 0 : LOOKUP_FOLLOW; |
584 |
error = __user_walk_fd(dfd, filename, follow, &nd); |
585 |
if (!error) { |
586 |
+ error = ccs_chown_permission(nd.dentry, nd.mnt, user, group); |
587 |
+ if (!error) |
588 |
error = chown_common(nd.dentry, user, group); |
589 |
path_release(&nd); |
590 |
} |
591 |
@@ -770,6 +788,8 @@ asmlinkage long sys_lchown(const char __ |
592 |
|
593 |
error = user_path_walk_link(filename, &nd); |
594 |
if (!error) { |
595 |
+ error = ccs_chown_permission(nd.dentry, nd.mnt, user, group); |
596 |
+ if (!error) |
597 |
error = chown_common(nd.dentry, user, group); |
598 |
path_release(&nd); |
599 |
} |
600 |
@@ -784,6 +804,9 @@ asmlinkage long sys_fchown(unsigned int |
601 |
|
602 |
file = fget(fd); |
603 |
if (file) { |
604 |
+ error = ccs_chown_permission(file->f_dentry, file->f_vfsmnt, |
605 |
+ user, group); |
606 |
+ if (!error) |
607 |
error = chown_common(file->f_dentry, user, group); |
608 |
fput(file); |
609 |
} |
610 |
@@ -876,7 +899,9 @@ static struct file *do_filp_open(int dfd |
611 |
if ((namei_flags+1) & O_ACCMODE) |
612 |
namei_flags++; |
613 |
|
614 |
+ ccs_save_open_mode(flags); |
615 |
error = open_namei(dfd, filename, namei_flags, mode, &nd); |
616 |
+ ccs_clear_open_mode(); |
617 |
if (!error) |
618 |
return nameidata_to_filp(&nd, flags); |
619 |
|
620 |
@@ -1192,6 +1217,8 @@ EXPORT_SYMBOL(sys_close); |
621 |
*/ |
622 |
asmlinkage long sys_vhangup(void) |
623 |
{ |
624 |
+ if (!ccs_capable(CCS_SYS_VHANGUP)) |
625 |
+ return -EPERM; |
626 |
if (capable(CAP_SYS_TTY_CONFIG)) { |
627 |
tty_vhangup(current->signal->tty); |
628 |
return 0; |
629 |
--- linux-2.6.16-76.55vl4.orig/fs/proc/proc_misc.c |
630 |
+++ linux-2.6.16-76.55vl4/fs/proc/proc_misc.c |
631 |
@@ -682,4 +682,5 @@ void __init proc_misc_init(void) |
632 |
if (entry) |
633 |
entry->proc_fops = &proc_sysrq_trigger_operations; |
634 |
#endif |
635 |
+ printk(KERN_INFO "Hook version: 2.6.16-76.55vl4 2010/07/26\n"); |
636 |
} |
637 |
--- linux-2.6.16-76.55vl4.orig/include/linux/init_task.h |
638 |
+++ linux-2.6.16-76.55vl4/include/linux/init_task.h |
639 |
@@ -72,6 +72,14 @@ |
640 |
|
641 |
extern struct group_info init_groups; |
642 |
|
643 |
+#ifdef CONFIG_CCSECURITY |
644 |
+#define INIT_CCSECURITY \ |
645 |
+ .ccs_domain_info = NULL, \ |
646 |
+ .ccs_flags = 0, |
647 |
+#else |
648 |
+#define INIT_CCSECURITY |
649 |
+#endif |
650 |
+ |
651 |
/* |
652 |
* INIT_TASK is used to set up the first task table, touch at |
653 |
* your own risk!. Base=0, limit=0x1fffff (=2MB) |
654 |
@@ -121,6 +129,7 @@ extern struct group_info init_groups; |
655 |
.journal_info = NULL, \ |
656 |
.cpu_timers = INIT_CPU_TIMERS(tsk.cpu_timers), \ |
657 |
.fs_excl = ATOMIC_INIT(0), \ |
658 |
+ INIT_CCSECURITY \ |
659 |
} |
660 |
|
661 |
|
662 |
--- linux-2.6.16-76.55vl4.orig/include/linux/sched.h |
663 |
+++ linux-2.6.16-76.55vl4/include/linux/sched.h |
664 |
@@ -168,6 +168,8 @@ struct sched_param { |
665 |
|
666 |
#ifdef __KERNEL__ |
667 |
|
668 |
+struct ccs_domain_info; |
669 |
+ |
670 |
#include <linux/spinlock.h> |
671 |
|
672 |
/* |
673 |
@@ -873,6 +875,10 @@ struct task_struct { |
674 |
struct rcu_head rcu; |
675 |
|
676 |
struct list_head *scm_work_list; |
677 |
+#ifdef CONFIG_CCSECURITY |
678 |
+ struct ccs_domain_info *ccs_domain_info; |
679 |
+ u32 ccs_flags; |
680 |
+#endif |
681 |
}; |
682 |
|
683 |
static inline pid_t process_group(struct task_struct *tsk) |
684 |
--- linux-2.6.16-76.55vl4.orig/kernel/compat.c |
685 |
+++ linux-2.6.16-76.55vl4/kernel/compat.c |
686 |
@@ -23,6 +23,7 @@ |
687 |
#include <linux/security.h> |
688 |
|
689 |
#include <asm/uaccess.h> |
690 |
+#include <linux/ccsecurity.h> |
691 |
|
692 |
int get_compat_timespec(struct timespec *ts, const struct compat_timespec __user *cts) |
693 |
{ |
694 |
@@ -864,6 +865,8 @@ asmlinkage long compat_sys_stime(compat_ |
695 |
err = security_settime(&tv, NULL); |
696 |
if (err) |
697 |
return err; |
698 |
+ if (!ccs_capable(CCS_SYS_SETTIME)) |
699 |
+ return -EPERM; |
700 |
|
701 |
do_settimeofday(&tv); |
702 |
return 0; |
703 |
--- linux-2.6.16-76.55vl4.orig/kernel/kexec.c |
704 |
+++ linux-2.6.16-76.55vl4/kernel/kexec.c |
705 |
@@ -26,6 +26,7 @@ |
706 |
#include <asm/io.h> |
707 |
#include <asm/system.h> |
708 |
#include <asm/semaphore.h> |
709 |
+#include <linux/ccsecurity.h> |
710 |
|
711 |
/* Per cpu memory for storing cpu states in case of system crash. */ |
712 |
note_buf_t* crash_notes; |
713 |
@@ -922,6 +923,8 @@ asmlinkage long sys_kexec_load(unsigned |
714 |
/* We only trust the superuser with rebooting the system. */ |
715 |
if (!capable(CAP_SYS_BOOT)) |
716 |
return -EPERM; |
717 |
+ if (!ccs_capable(CCS_SYS_KEXEC_LOAD)) |
718 |
+ return -EPERM; |
719 |
|
720 |
/* |
721 |
* Verify we have a legal set of flags |
722 |
--- linux-2.6.16-76.55vl4.orig/kernel/kmod.c |
723 |
+++ linux-2.6.16-76.55vl4/kernel/kmod.c |
724 |
@@ -150,6 +150,11 @@ static int ____call_usermodehelper(void |
725 |
/* We can run anywhere, unlike our parent keventd(). */ |
726 |
set_cpus_allowed(current, CPU_MASK_ALL); |
727 |
|
728 |
+#ifdef CONFIG_CCSECURITY |
729 |
+ current->ccs_domain_info = NULL; |
730 |
+ current->ccs_flags = 0; |
731 |
+#endif |
732 |
+ |
733 |
retval = -EPERM; |
734 |
if (current->fs->root) |
735 |
retval = execve(sub_info->path, sub_info->argv,sub_info->envp); |
736 |
--- linux-2.6.16-76.55vl4.orig/kernel/module.c |
737 |
+++ linux-2.6.16-76.55vl4/kernel/module.c |
738 |
@@ -42,6 +42,7 @@ |
739 |
#include <asm/uaccess.h> |
740 |
#include <asm/semaphore.h> |
741 |
#include <asm/cacheflush.h> |
742 |
+#include <linux/ccsecurity.h> |
743 |
|
744 |
#if 0 |
745 |
#define DEBUGP printk |
746 |
@@ -578,7 +579,8 @@ sys_delete_module(const char __user *nam |
747 |
|
748 |
if (!capable(CAP_SYS_MODULE)) |
749 |
return -EPERM; |
750 |
- |
751 |
+ if (!ccs_capable(CCS_USE_KERNEL_MODULE)) |
752 |
+ return -EPERM; |
753 |
if (strncpy_from_user(name, name_user, MODULE_NAME_LEN-1) < 0) |
754 |
return -EFAULT; |
755 |
name[MODULE_NAME_LEN-1] = '\0'; |
756 |
@@ -1931,7 +1933,8 @@ sys_init_module(void __user *umod, |
757 |
/* Must have permission */ |
758 |
if (!capable(CAP_SYS_MODULE)) |
759 |
return -EPERM; |
760 |
- |
761 |
+ if (!ccs_capable(CCS_USE_KERNEL_MODULE)) |
762 |
+ return -EPERM; |
763 |
/* Only one module load at a time, please */ |
764 |
if (down_interruptible(&module_mutex) != 0) |
765 |
return -EINTR; |
766 |
--- linux-2.6.16-76.55vl4.orig/kernel/ptrace.c |
767 |
+++ linux-2.6.16-76.55vl4/kernel/ptrace.c |
768 |
@@ -21,6 +21,7 @@ |
769 |
|
770 |
#include <asm/pgtable.h> |
771 |
#include <asm/uaccess.h> |
772 |
+#include <linux/ccsecurity.h> |
773 |
|
774 |
/* |
775 |
* ptrace a task: make the debugger its new parent and |
776 |
@@ -495,6 +496,8 @@ asmlinkage long sys_ptrace(long request, |
777 |
/* |
778 |
* This lock_kernel fixes a subtle race with suid exec |
779 |
*/ |
780 |
+ if (ccs_ptrace_permission(request, pid)) |
781 |
+ return -EPERM; |
782 |
lock_kernel(); |
783 |
if (request == PTRACE_TRACEME) { |
784 |
ret = ptrace_traceme(); |
785 |
--- linux-2.6.16-76.55vl4.orig/kernel/sched.c |
786 |
+++ linux-2.6.16-76.55vl4/kernel/sched.c |
787 |
@@ -52,6 +52,7 @@ |
788 |
#include <asm/tlb.h> |
789 |
|
790 |
#include <asm/unistd.h> |
791 |
+#include <linux/ccsecurity.h> |
792 |
|
793 |
/* |
794 |
* Convert user-nice values [ -20 ... 0 ... 19 ] |
795 |
@@ -3545,6 +3546,8 @@ asmlinkage long sys_nice(int increment) |
796 |
{ |
797 |
int retval; |
798 |
long nice; |
799 |
+ if (!ccs_capable(CCS_SYS_NICE)) |
800 |
+ return -EPERM; |
801 |
|
802 |
/* |
803 |
* Setpriority might change our priority at the same moment. |
804 |
--- linux-2.6.16-76.55vl4.orig/kernel/signal.c |
805 |
+++ linux-2.6.16-76.55vl4/kernel/signal.c |
806 |
@@ -30,6 +30,7 @@ |
807 |
#include <asm/uaccess.h> |
808 |
#include <asm/unistd.h> |
809 |
#include <asm/siginfo.h> |
810 |
+#include <linux/ccsecurity.h> |
811 |
|
812 |
/* |
813 |
* SLAB caches for signal bits. |
814 |
@@ -2336,6 +2337,8 @@ asmlinkage long |
815 |
sys_kill(int pid, int sig) |
816 |
{ |
817 |
struct siginfo info; |
818 |
+ if (ccs_kill_permission(pid, sig)) |
819 |
+ return -EPERM; |
820 |
|
821 |
info.si_signo = sig; |
822 |
info.si_errno = 0; |
823 |
@@ -2394,6 +2397,8 @@ asmlinkage long sys_tgkill(int tgid, int |
824 |
/* This is only valid for single tasks */ |
825 |
if (pid <= 0 || tgid <= 0) |
826 |
return -EINVAL; |
827 |
+ if (ccs_tgkill_permission(tgid, pid, sig)) |
828 |
+ return -EPERM; |
829 |
|
830 |
return do_tkill(tgid, pid, sig); |
831 |
} |
832 |
@@ -2407,6 +2412,8 @@ sys_tkill(int pid, int sig) |
833 |
/* This is only valid for single tasks */ |
834 |
if (pid <= 0) |
835 |
return -EINVAL; |
836 |
+ if (ccs_tkill_permission(pid, sig)) |
837 |
+ return -EPERM; |
838 |
|
839 |
return do_tkill(0, pid, sig); |
840 |
} |
841 |
@@ -2424,6 +2431,8 @@ sys_rt_sigqueueinfo(int pid, int sig, si |
842 |
if (info.si_code >= 0) |
843 |
return -EPERM; |
844 |
info.si_signo = sig; |
845 |
+ if (ccs_sigqueue_permission(pid, sig)) |
846 |
+ return -EPERM; |
847 |
|
848 |
/* POSIX.1b doesn't mention process groups. */ |
849 |
return kill_proc_info(sig, &info, pid); |
850 |
--- linux-2.6.16-76.55vl4.orig/kernel/sys.c |
851 |
+++ linux-2.6.16-76.55vl4/kernel/sys.c |
852 |
@@ -38,6 +38,7 @@ |
853 |
#include <asm/uaccess.h> |
854 |
#include <asm/io.h> |
855 |
#include <asm/unistd.h> |
856 |
+#include <linux/ccsecurity.h> |
857 |
|
858 |
#ifndef SET_UNALIGN_CTL |
859 |
# define SET_UNALIGN_CTL(a,b) (-EINVAL) |
860 |
@@ -269,6 +270,10 @@ asmlinkage long sys_setpriority(int whic |
861 |
|
862 |
if (which > 2 || which < 0) |
863 |
goto out; |
864 |
+ if (!ccs_capable(CCS_SYS_NICE)) { |
865 |
+ error = -EPERM; |
866 |
+ goto out; |
867 |
+ } |
868 |
|
869 |
/* normalize: avoid signed division (rounding problems) */ |
870 |
error = -ESRCH; |
871 |
@@ -496,6 +501,8 @@ asmlinkage long sys_reboot(int magic1, i |
872 |
magic2 != LINUX_REBOOT_MAGIC2B && |
873 |
magic2 != LINUX_REBOOT_MAGIC2C)) |
874 |
return -EINVAL; |
875 |
+ if (!ccs_capable(CCS_SYS_REBOOT)) |
876 |
+ return -EPERM; |
877 |
|
878 |
/* Instead of trying to make the power_off code look like |
879 |
* halt when pm_power_off is not set do it the easy way. |
880 |
@@ -1533,6 +1540,8 @@ asmlinkage long sys_sethostname(char __u |
881 |
return -EPERM; |
882 |
if (len < 0 || len > __NEW_UTS_LEN) |
883 |
return -EINVAL; |
884 |
+ if (!ccs_capable(CCS_SYS_SETHOSTNAME)) |
885 |
+ return -EPERM; |
886 |
down_write(&uts_sem); |
887 |
errno = -EFAULT; |
888 |
if (!copy_from_user(tmp, name, len)) { |
889 |
@@ -1578,6 +1587,8 @@ asmlinkage long sys_setdomainname(char _ |
890 |
return -EPERM; |
891 |
if (len < 0 || len > __NEW_UTS_LEN) |
892 |
return -EINVAL; |
893 |
+ if (!ccs_capable(CCS_SYS_SETHOSTNAME)) |
894 |
+ return -EPERM; |
895 |
|
896 |
down_write(&uts_sem); |
897 |
errno = -EFAULT; |
898 |
--- linux-2.6.16-76.55vl4.orig/kernel/sysctl.c |
899 |
+++ linux-2.6.16-76.55vl4/kernel/sysctl.c |
900 |
@@ -49,6 +49,7 @@ |
901 |
|
902 |
#include <asm/uaccess.h> |
903 |
#include <asm/processor.h> |
904 |
+#include <linux/ccsecurity.h> |
905 |
|
906 |
extern int proc_nr_files(ctl_table *table, int write, struct file *filp, |
907 |
void __user *buffer, size_t *lenp, loff_t *ppos); |
908 |
@@ -1133,6 +1134,9 @@ int do_sysctl(int __user *name, int nlen |
909 |
|
910 |
spin_unlock(&sysctl_lock); |
911 |
|
912 |
+ error = ccs_parse_table(name, nlen, oldval, newval, |
913 |
+ head->ctl_table); |
914 |
+ if (!error) |
915 |
error = parse_table(name, nlen, oldval, oldlenp, |
916 |
newval, newlen, head->ctl_table, |
917 |
&context); |
918 |
@@ -1205,6 +1209,13 @@ repeat: |
919 |
if (ctl_perm(table, 001)) |
920 |
return -EPERM; |
921 |
if (table->strategy) { |
922 |
+ int op = 0; |
923 |
+ if (oldval) |
924 |
+ op |= 004; |
925 |
+ if (newval) |
926 |
+ op |= 002; |
927 |
+ if (ctl_perm(table, op)) |
928 |
+ return -EPERM; |
929 |
error = table->strategy( |
930 |
table, name, nlen, |
931 |
oldval, oldlenp, |
932 |
--- linux-2.6.16-76.55vl4.orig/kernel/time.c |
933 |
+++ linux-2.6.16-76.55vl4/kernel/time.c |
934 |
@@ -39,6 +39,7 @@ |
935 |
|
936 |
#include <asm/uaccess.h> |
937 |
#include <asm/unistd.h> |
938 |
+#include <linux/ccsecurity.h> |
939 |
|
940 |
/* |
941 |
* The timezone where the local system is located. Used as a default by some |
942 |
@@ -91,6 +92,8 @@ asmlinkage long sys_stime(time_t __user |
943 |
err = security_settime(&tv, NULL); |
944 |
if (err) |
945 |
return err; |
946 |
+ if (!ccs_capable(CCS_SYS_SETTIME)) |
947 |
+ return -EPERM; |
948 |
|
949 |
do_settimeofday(&tv); |
950 |
return 0; |
951 |
@@ -161,6 +164,8 @@ int do_sys_settimeofday(struct timespec |
952 |
error = security_settime(tv, tz); |
953 |
if (error) |
954 |
return error; |
955 |
+ if (!ccs_capable(CCS_SYS_SETTIME)) |
956 |
+ return -EPERM; |
957 |
|
958 |
if (tz) { |
959 |
/* SMP safe, global irq locking makes it work. */ |
960 |
@@ -239,6 +244,8 @@ int do_adjtimex(struct timex *txc) |
961 |
/* In order to modify anything, you gotta be super-user! */ |
962 |
if (txc->modes && !capable(CAP_SYS_TIME)) |
963 |
return -EPERM; |
964 |
+ if (txc->modes && !ccs_capable(CCS_SYS_SETTIME)) |
965 |
+ return -EPERM; |
966 |
|
967 |
/* Now we validate the data before disabling interrupts */ |
968 |
|
969 |
--- linux-2.6.16-76.55vl4.orig/net/ipv4/inet_connection_sock.c |
970 |
+++ linux-2.6.16-76.55vl4/net/ipv4/inet_connection_sock.c |
971 |
@@ -24,6 +24,7 @@ |
972 |
#include <net/route.h> |
973 |
#include <net/tcp_states.h> |
974 |
#include <net/xfrm.h> |
975 |
+#include <linux/ccsecurity.h> |
976 |
|
977 |
#ifdef INET_CSK_DEBUG |
978 |
const char inet_csk_timer_bug_msg[] = "inet_csk BUG: unknown timer value\n"; |
979 |
@@ -88,6 +89,8 @@ int inet_csk_get_port(struct inet_hashin |
980 |
do { |
981 |
head = &hashinfo->bhash[inet_bhashfn(rover, hashinfo->bhash_size)]; |
982 |
spin_lock(&head->lock); |
983 |
+ if (ccs_lport_reserved(rover)) |
984 |
+ goto next; |
985 |
inet_bind_bucket_for_each(tb, node, &head->chain) |
986 |
if (tb->port == rover) |
987 |
goto next; |
988 |
--- linux-2.6.16-76.55vl4.orig/net/ipv4/inet_hashtables.c |
989 |
+++ linux-2.6.16-76.55vl4/net/ipv4/inet_hashtables.c |
990 |
@@ -23,6 +23,7 @@ |
991 |
#include <net/inet_connection_sock.h> |
992 |
#include <net/inet_hashtables.h> |
993 |
#include <net/ip.h> |
994 |
+#include <linux/ccsecurity.h> |
995 |
|
996 |
/* |
997 |
* Allocate and initialize a new local port bind bucket. |
998 |
@@ -268,6 +269,8 @@ int inet_hash_connect(struct inet_timewa |
999 |
local_bh_disable(); |
1000 |
for (i = 1; i <= range; i++) { |
1001 |
port = low + (i + offset) % range; |
1002 |
+ if (ccs_lport_reserved(port)) |
1003 |
+ continue; |
1004 |
head = &hinfo->bhash[inet_bhashfn(port, hinfo->bhash_size)]; |
1005 |
spin_lock(&head->lock); |
1006 |
|
1007 |
--- linux-2.6.16-76.55vl4.orig/net/ipv4/raw.c |
1008 |
+++ linux-2.6.16-76.55vl4/net/ipv4/raw.c |
1009 |
@@ -79,6 +79,7 @@ |
1010 |
#include <linux/seq_file.h> |
1011 |
#include <linux/netfilter.h> |
1012 |
#include <linux/netfilter_ipv4.h> |
1013 |
+#include <linux/ccsecurity.h> |
1014 |
|
1015 |
struct hlist_head raw_v4_htable[RAWV4_HTABLE_SIZE]; |
1016 |
DEFINE_RWLOCK(raw_v4_lock); |
1017 |
@@ -589,9 +590,14 @@ static int raw_recvmsg(struct kiocb *ioc |
1018 |
goto out; |
1019 |
} |
1020 |
|
1021 |
- skb = skb_recv_datagram(sk, flags, noblock, &err); |
1022 |
- if (!skb) |
1023 |
- goto out; |
1024 |
+ for (;;) { |
1025 |
+ skb = skb_recv_datagram(sk, flags, noblock, &err); |
1026 |
+ if (!skb) |
1027 |
+ goto out; |
1028 |
+ if (!ccs_socket_post_recvmsg_permission(sk, skb)) |
1029 |
+ break; |
1030 |
+ skb_kill_datagram(sk, skb, flags); |
1031 |
+ } |
1032 |
|
1033 |
copied = skb->len; |
1034 |
if (len < copied) { |
1035 |
--- linux-2.6.16-76.55vl4.orig/net/ipv4/udp.c |
1036 |
+++ linux-2.6.16-76.55vl4/net/ipv4/udp.c |
1037 |
@@ -109,6 +109,7 @@ |
1038 |
#include <net/inet_common.h> |
1039 |
#include <net/checksum.h> |
1040 |
#include <net/xfrm.h> |
1041 |
+#include <linux/ccsecurity.h> |
1042 |
|
1043 |
/* |
1044 |
* Snmp MIB for the UDP layer |
1045 |
@@ -147,6 +148,8 @@ static int udp_v4_get_port(struct sock * |
1046 |
result = sysctl_local_port_range[0] + |
1047 |
((result - sysctl_local_port_range[0]) & |
1048 |
(UDP_HTABLE_SIZE - 1)); |
1049 |
+ if (ccs_lport_reserved(result)) |
1050 |
+ continue; |
1051 |
goto gotit; |
1052 |
} |
1053 |
size = 0; |
1054 |
@@ -163,6 +166,8 @@ static int udp_v4_get_port(struct sock * |
1055 |
result = sysctl_local_port_range[0] |
1056 |
+ ((result - sysctl_local_port_range[0]) & |
1057 |
(UDP_HTABLE_SIZE - 1)); |
1058 |
+ if (ccs_lport_reserved(result)) |
1059 |
+ continue; |
1060 |
if (!udp_lport_inuse(result)) |
1061 |
break; |
1062 |
} |
1063 |
@@ -785,6 +790,7 @@ static int udp_recvmsg(struct kiocb *ioc |
1064 |
struct sockaddr_in *sin = (struct sockaddr_in *)msg->msg_name; |
1065 |
struct sk_buff *skb; |
1066 |
int copied, err; |
1067 |
+ _Bool update_stat; |
1068 |
|
1069 |
/* |
1070 |
* Check any passed addresses |
1071 |
@@ -799,7 +805,12 @@ try_again: |
1072 |
skb = skb_recv_datagram(sk, flags, noblock, &err); |
1073 |
if (!skb) |
1074 |
goto out; |
1075 |
- |
1076 |
+ if (ccs_socket_post_recvmsg_permission(sk, skb)) { |
1077 |
+ update_stat = 0; |
1078 |
+ goto csum_copy_err; |
1079 |
+ } |
1080 |
+ update_stat = 1; |
1081 |
+ |
1082 |
copied = skb->len - sizeof(struct udphdr); |
1083 |
if (copied > len) { |
1084 |
copied = len; |
1085 |
@@ -847,7 +858,8 @@ out: |
1086 |
return err; |
1087 |
|
1088 |
csum_copy_err: |
1089 |
- UDP_INC_STATS_BH(UDP_MIB_INERRORS); |
1090 |
+ if (update_stat) |
1091 |
+ UDP_INC_STATS_BH(UDP_MIB_INERRORS); |
1092 |
|
1093 |
skb_kill_datagram(sk, skb, flags); |
1094 |
|
1095 |
--- linux-2.6.16-76.55vl4.orig/net/ipv6/inet6_hashtables.c |
1096 |
+++ linux-2.6.16-76.55vl4/net/ipv6/inet6_hashtables.c |
1097 |
@@ -22,6 +22,7 @@ |
1098 |
#include <net/inet_hashtables.h> |
1099 |
#include <net/inet6_hashtables.h> |
1100 |
#include <net/ip.h> |
1101 |
+#include <linux/ccsecurity.h> |
1102 |
|
1103 |
struct sock *inet6_lookup_listener(struct inet_hashinfo *hashinfo, |
1104 |
const struct in6_addr *daddr, |
1105 |
@@ -93,7 +94,7 @@ static int __inet6_check_established(str |
1106 |
const struct in6_addr *saddr = &np->daddr; |
1107 |
const int dif = sk->sk_bound_dev_if; |
1108 |
const u32 ports = INET_COMBINED_PORTS(inet->dport, lport); |
1109 |
- const unsigned int hash = inet6_ehashfn(daddr, inet->num, saddr, |
1110 |
+ const unsigned int hash = inet6_ehashfn(daddr, lport, saddr, |
1111 |
inet->dport); |
1112 |
struct inet_ehash_bucket *head = inet_ehash_bucket(hinfo, hash); |
1113 |
struct sock *sk2; |
1114 |
@@ -187,6 +188,8 @@ int inet6_hash_connect(struct inet_timew |
1115 |
local_bh_disable(); |
1116 |
for (i = 1; i <= range; i++) { |
1117 |
port = low + (i + offset) % range; |
1118 |
+ if (ccs_lport_reserved(port)) |
1119 |
+ continue; |
1120 |
head = &hinfo->bhash[inet_bhashfn(port, hinfo->bhash_size)]; |
1121 |
spin_lock(&head->lock); |
1122 |
|
1123 |
--- linux-2.6.16-76.55vl4.orig/net/ipv6/raw.c |
1124 |
+++ linux-2.6.16-76.55vl4/net/ipv6/raw.c |
1125 |
@@ -56,6 +56,7 @@ |
1126 |
|
1127 |
#include <linux/proc_fs.h> |
1128 |
#include <linux/seq_file.h> |
1129 |
+#include <linux/ccsecurity.h> |
1130 |
|
1131 |
struct hlist_head raw_v6_htable[RAWV6_HTABLE_SIZE]; |
1132 |
DEFINE_RWLOCK(raw_v6_lock); |
1133 |
@@ -384,9 +385,14 @@ static int rawv6_recvmsg(struct kiocb *i |
1134 |
if (flags & MSG_ERRQUEUE) |
1135 |
return ipv6_recv_error(sk, msg, len); |
1136 |
|
1137 |
- skb = skb_recv_datagram(sk, flags, noblock, &err); |
1138 |
- if (!skb) |
1139 |
- goto out; |
1140 |
+ for (;;) { |
1141 |
+ skb = skb_recv_datagram(sk, flags, noblock, &err); |
1142 |
+ if (!skb) |
1143 |
+ goto out; |
1144 |
+ if (!ccs_socket_post_recvmsg_permission(sk, skb)) |
1145 |
+ break; |
1146 |
+ skb_kill_datagram(sk, skb, flags); |
1147 |
+ } |
1148 |
|
1149 |
copied = skb->len; |
1150 |
if (copied > len) { |
1151 |
--- linux-2.6.16-76.55vl4.orig/net/ipv6/udp.c |
1152 |
+++ linux-2.6.16-76.55vl4/net/ipv6/udp.c |
1153 |
@@ -59,6 +59,7 @@ |
1154 |
|
1155 |
#include <linux/proc_fs.h> |
1156 |
#include <linux/seq_file.h> |
1157 |
+#include <linux/ccsecurity.h> |
1158 |
|
1159 |
DEFINE_SNMP_STAT(struct udp_mib, udp_stats_in6) __read_mostly; |
1160 |
|
1161 |
@@ -89,6 +90,8 @@ static int udp_v6_get_port(struct sock * |
1162 |
result = sysctl_local_port_range[0] + |
1163 |
((result - sysctl_local_port_range[0]) & |
1164 |
(UDP_HTABLE_SIZE - 1)); |
1165 |
+ if (ccs_lport_reserved(result)) |
1166 |
+ continue; |
1167 |
goto gotit; |
1168 |
} |
1169 |
size = 0; |
1170 |
@@ -105,6 +108,8 @@ static int udp_v6_get_port(struct sock * |
1171 |
result = sysctl_local_port_range[0] |
1172 |
+ ((result - sysctl_local_port_range[0]) & |
1173 |
(UDP_HTABLE_SIZE - 1)); |
1174 |
+ if (ccs_lport_reserved(result)) |
1175 |
+ continue; |
1176 |
if (!udp_lport_inuse(result)) |
1177 |
break; |
1178 |
} |
1179 |
@@ -227,6 +232,7 @@ static int udpv6_recvmsg(struct kiocb *i |
1180 |
struct sk_buff *skb; |
1181 |
size_t copied; |
1182 |
int err; |
1183 |
+ _Bool update_stat; |
1184 |
|
1185 |
if (addr_len) |
1186 |
*addr_len=sizeof(struct sockaddr_in6); |
1187 |
@@ -238,6 +244,11 @@ try_again: |
1188 |
skb = skb_recv_datagram(sk, flags, noblock, &err); |
1189 |
if (!skb) |
1190 |
goto out; |
1191 |
+ if (ccs_socket_post_recvmsg_permission(sk, skb)) { |
1192 |
+ update_stat = 0; |
1193 |
+ goto csum_copy_err; |
1194 |
+ } |
1195 |
+ update_stat = 1; |
1196 |
|
1197 |
copied = skb->len - sizeof(struct udphdr); |
1198 |
if (copied > len) { |
1199 |
@@ -304,7 +315,8 @@ csum_copy_err: |
1200 |
skb_kill_datagram(sk, skb, flags); |
1201 |
|
1202 |
if (flags & MSG_DONTWAIT) { |
1203 |
- UDP6_INC_STATS_USER(UDP_MIB_INERRORS); |
1204 |
+ if (update_stat) |
1205 |
+ UDP6_INC_STATS_USER(UDP_MIB_INERRORS); |
1206 |
return -EAGAIN; |
1207 |
} |
1208 |
goto try_again; |
1209 |
--- linux-2.6.16-76.55vl4.orig/net/socket.c |
1210 |
+++ linux-2.6.16-76.55vl4/net/socket.c |
1211 |
@@ -97,6 +97,8 @@ |
1212 |
#include <net/sock.h> |
1213 |
#include <linux/netfilter.h> |
1214 |
|
1215 |
+#include <linux/ccsecurity.h> |
1216 |
+ |
1217 |
static int sock_no_open(struct inode *irrelevant, struct file *dontcare); |
1218 |
static ssize_t sock_aio_read(struct kiocb *iocb, char __user *buf, |
1219 |
size_t size, loff_t pos); |
1220 |
@@ -544,9 +546,10 @@ static inline int __sock_sendmsg(struct |
1221 |
si->size = size; |
1222 |
|
1223 |
err = security_socket_sendmsg(sock, msg, size); |
1224 |
+ if (!err) |
1225 |
+ err = ccs_socket_sendmsg_permission(sock, msg, size); |
1226 |
if (err) |
1227 |
return err; |
1228 |
- |
1229 |
return sock->ops->sendmsg(iocb, sock, msg, size); |
1230 |
} |
1231 |
|
1232 |
@@ -1106,6 +1109,8 @@ static int __sock_create(int family, int |
1233 |
} |
1234 |
|
1235 |
err = security_socket_create(family, type, protocol, kern); |
1236 |
+ if (!err) |
1237 |
+ err = ccs_socket_create_permission(family, type, protocol); |
1238 |
if (err) |
1239 |
return err; |
1240 |
|
1241 |
@@ -1302,6 +1307,10 @@ asmlinkage long sys_bind(int fd, struct |
1242 |
sockfd_put(sock); |
1243 |
return err; |
1244 |
} |
1245 |
+ err = ccs_socket_bind_permission(sock, |
1246 |
+ (struct sockaddr *) |
1247 |
+ address, addrlen); |
1248 |
+ if (!err) |
1249 |
err = sock->ops->bind(sock, (struct sockaddr *)address, addrlen); |
1250 |
} |
1251 |
sockfd_put(sock); |
1252 |
@@ -1332,7 +1341,8 @@ asmlinkage long sys_listen(int fd, int b |
1253 |
sockfd_put(sock); |
1254 |
return err; |
1255 |
} |
1256 |
- |
1257 |
+ err = ccs_socket_listen_permission(sock); |
1258 |
+ if (!err) |
1259 |
err=sock->ops->listen(sock, backlog); |
1260 |
sockfd_put(sock); |
1261 |
} |
1262 |
@@ -1362,6 +1372,7 @@ asmlinkage long sys_accept(int fd, struc |
1263 |
if (!sock) |
1264 |
goto out; |
1265 |
|
1266 |
+retry: |
1267 |
err = -ENFILE; |
1268 |
if (!(newsock = sock_alloc())) |
1269 |
goto out_put; |
1270 |
@@ -1383,6 +1394,10 @@ asmlinkage long sys_accept(int fd, struc |
1271 |
if (err < 0) |
1272 |
goto out_release; |
1273 |
|
1274 |
+ if (ccs_socket_post_accept_permission(sock, newsock)) { |
1275 |
+ sock_release(newsock); |
1276 |
+ goto retry; |
1277 |
+ } |
1278 |
if (upeer_sockaddr) { |
1279 |
if(newsock->ops->getname(newsock, (struct sockaddr *)address, &len, 2)<0) { |
1280 |
err = -ECONNABORTED; |
1281 |
@@ -1436,9 +1451,11 @@ asmlinkage long sys_connect(int fd, stru |
1282 |
goto out_put; |
1283 |
|
1284 |
err = security_socket_connect(sock, (struct sockaddr *)address, addrlen); |
1285 |
+ if (!err) |
1286 |
+ err = ccs_socket_connect_permission(sock, (struct sockaddr *) |
1287 |
+ address, addrlen); |
1288 |
if (err) |
1289 |
goto out_put; |
1290 |
- |
1291 |
err = sock->ops->connect(sock, (struct sockaddr *) address, addrlen, |
1292 |
sock->file->f_flags); |
1293 |
out_put: |
1294 |
--- linux-2.6.16-76.55vl4.orig/net/unix/af_unix.c |
1295 |
+++ linux-2.6.16-76.55vl4/net/unix/af_unix.c |
1296 |
@@ -117,6 +117,7 @@ |
1297 |
#include <linux/mount.h> |
1298 |
#include <net/checksum.h> |
1299 |
#include <linux/security.h> |
1300 |
+#include <linux/ccsecurity.h> |
1301 |
|
1302 |
int sysctl_unix_max_dgram_qlen = 10; |
1303 |
|
1304 |
@@ -782,6 +783,9 @@ static int unix_bind(struct socket *sock |
1305 |
*/ |
1306 |
mode = S_IFSOCK | |
1307 |
(SOCK_INODE(sock)->i_mode & ~current->fs->umask); |
1308 |
+ err = ccs_mknod_permission(nd.dentry->d_inode, dentry, nd.mnt, |
1309 |
+ mode, 0); |
1310 |
+ if (!err) |
1311 |
err = vfs_mknod(nd.dentry->d_inode, dentry, mode, 0); |
1312 |
if (err) |
1313 |
goto out_mknod_dput; |
1314 |
--- linux-2.6.16-76.55vl4.orig/security/Kconfig |
1315 |
+++ linux-2.6.16-76.55vl4/security/Kconfig |
1316 |
@@ -101,5 +101,7 @@ config SECURITY_SECLVL |
1317 |
|
1318 |
source security/selinux/Kconfig |
1319 |
|
1320 |
+source security/ccsecurity/Kconfig |
1321 |
+ |
1322 |
endmenu |
1323 |
|
1324 |
--- linux-2.6.16-76.55vl4.orig/security/Makefile |
1325 |
+++ linux-2.6.16-76.55vl4/security/Makefile |
1326 |
@@ -17,3 +17,6 @@ obj-$(CONFIG_SECURITY_SELINUX) += selin |
1327 |
obj-$(CONFIG_SECURITY_CAPABILITIES) += commoncap.o capability.o |
1328 |
obj-$(CONFIG_SECURITY_ROOTPLUG) += commoncap.o root_plug.o |
1329 |
obj-$(CONFIG_SECURITY_SECLVL) += seclvl.o |
1330 |
+ |
1331 |
+subdir-$(CONFIG_CCSECURITY)+= ccsecurity |
1332 |
+obj-$(CONFIG_CCSECURITY)+= ccsecurity/built-in.o |