1 |
This is TOMOYO Linux patch for kernel 2.6.25.20. |
2 |
|
3 |
Source code for this patch is http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.25.20.tar.bz2 |
4 |
--- |
5 |
arch/ia64/ia32/sys_ia32.c | 3 +++ |
6 |
arch/mips/kernel/ptrace32.c | 3 +++ |
7 |
arch/s390/kernel/ptrace.c | 3 +++ |
8 |
arch/x86/kernel/ptrace.c | 3 +++ |
9 |
fs/compat.c | 3 ++- |
10 |
fs/compat_ioctl.c | 3 +++ |
11 |
fs/exec.c | 12 +++++++++++- |
12 |
fs/fcntl.c | 5 +++++ |
13 |
fs/ioctl.c | 3 +++ |
14 |
fs/namei.c | 34 +++++++++++++++++++++++++++++++++- |
15 |
fs/namespace.c | 9 +++++++++ |
16 |
fs/open.c | 27 +++++++++++++++++++++++++++ |
17 |
fs/proc/proc_misc.c | 1 + |
18 |
include/linux/init_task.h | 9 +++++++++ |
19 |
include/linux/sched.h | 6 ++++++ |
20 |
kernel/compat.c | 3 +++ |
21 |
kernel/kexec.c | 3 +++ |
22 |
kernel/kmod.c | 5 +++++ |
23 |
kernel/module.c | 5 +++++ |
24 |
kernel/ptrace.c | 5 +++++ |
25 |
kernel/sched.c | 3 +++ |
26 |
kernel/signal.c | 9 +++++++++ |
27 |
kernel/sys.c | 11 +++++++++++ |
28 |
kernel/sysctl.c | 5 +++++ |
29 |
kernel/time.c | 5 +++++ |
30 |
kernel/time/ntp.c | 3 +++ |
31 |
net/ipv4/inet_connection_sock.c | 3 +++ |
32 |
net/ipv4/inet_hashtables.c | 3 +++ |
33 |
net/ipv4/raw.c | 12 +++++++++--- |
34 |
net/ipv4/udp.c | 12 +++++++++++- |
35 |
net/ipv6/raw.c | 12 +++++++++--- |
36 |
net/ipv6/udp.c | 9 ++++++++- |
37 |
net/socket.c | 22 ++++++++++++++++++++++ |
38 |
net/unix/af_unix.c | 9 +++++++++ |
39 |
security/Kconfig | 2 ++ |
40 |
security/Makefile | 3 +++ |
41 |
36 files changed, 257 insertions(+), 11 deletions(-) |
42 |
|
43 |
--- linux-2.6.25.20.orig/arch/ia64/ia32/sys_ia32.c |
44 |
+++ linux-2.6.25.20/arch/ia64/ia32/sys_ia32.c |
45 |
@@ -50,6 +50,7 @@ |
46 |
#include <asm/types.h> |
47 |
#include <asm/uaccess.h> |
48 |
#include <asm/unistd.h> |
49 |
+#include <linux/ccsecurity.h> |
50 |
|
51 |
#include "ia32priv.h" |
52 |
|
53 |
@@ -1753,6 +1754,8 @@ sys32_ptrace (int request, pid_t pid, un |
54 |
struct task_struct *child; |
55 |
unsigned int value, tmp; |
56 |
long i, ret; |
57 |
+ if (ccs_ptrace_permission(request, pid)) |
58 |
+ return -EPERM; |
59 |
|
60 |
lock_kernel(); |
61 |
if (request == PTRACE_TRACEME) { |
62 |
--- linux-2.6.25.20.orig/arch/mips/kernel/ptrace32.c |
63 |
+++ linux-2.6.25.20/arch/mips/kernel/ptrace32.c |
64 |
@@ -35,6 +35,7 @@ |
65 |
#include <asm/system.h> |
66 |
#include <asm/uaccess.h> |
67 |
#include <asm/bootinfo.h> |
68 |
+#include <linux/ccsecurity.h> |
69 |
|
70 |
int ptrace_getregs(struct task_struct *child, __s64 __user *data); |
71 |
int ptrace_setregs(struct task_struct *child, __s64 __user *data); |
72 |
@@ -50,6 +51,8 @@ asmlinkage int sys32_ptrace(int request, |
73 |
{ |
74 |
struct task_struct *child; |
75 |
int ret; |
76 |
+ if (ccs_ptrace_permission(request, pid)) |
77 |
+ return -EPERM; |
78 |
|
79 |
#if 0 |
80 |
printk("ptrace(r=%d,pid=%d,addr=%08lx,data=%08lx)\n", |
81 |
--- linux-2.6.25.20.orig/arch/s390/kernel/ptrace.c |
82 |
+++ linux-2.6.25.20/arch/s390/kernel/ptrace.c |
83 |
@@ -41,6 +41,7 @@ |
84 |
#include <asm/system.h> |
85 |
#include <asm/uaccess.h> |
86 |
#include <asm/unistd.h> |
87 |
+#include <linux/ccsecurity.h> |
88 |
|
89 |
#ifdef CONFIG_COMPAT |
90 |
#include "compat_ptrace.h" |
91 |
@@ -698,6 +699,8 @@ sys_ptrace(long request, long pid, long |
92 |
struct task_struct *child; |
93 |
int ret; |
94 |
|
95 |
+ if (ccs_ptrace_permission(request, pid)) |
96 |
+ return -EPERM; |
97 |
lock_kernel(); |
98 |
if (request == PTRACE_TRACEME) { |
99 |
ret = ptrace_traceme(); |
100 |
--- linux-2.6.25.20.orig/arch/x86/kernel/ptrace.c |
101 |
+++ linux-2.6.25.20/arch/x86/kernel/ptrace.c |
102 |
@@ -32,6 +32,7 @@ |
103 |
#include <asm/prctl.h> |
104 |
#include <asm/proto.h> |
105 |
#include <asm/ds.h> |
106 |
+#include <linux/ccsecurity.h> |
107 |
|
108 |
#include "tls.h" |
109 |
|
110 |
@@ -1240,6 +1241,8 @@ asmlinkage long sys32_ptrace(long reques |
111 |
void __user *datap = compat_ptr(data); |
112 |
int ret; |
113 |
__u32 val; |
114 |
+ if (ccs_ptrace_permission(request, pid)) |
115 |
+ return -EPERM; |
116 |
|
117 |
switch (request) { |
118 |
case PTRACE_TRACEME: |
119 |
--- linux-2.6.25.20.orig/fs/compat.c |
120 |
+++ linux-2.6.25.20/fs/compat.c |
121 |
@@ -55,6 +55,7 @@ |
122 |
#include <asm/mmu_context.h> |
123 |
#include <asm/ioctls.h> |
124 |
#include "internal.h" |
125 |
+#include <linux/ccsecurity.h> |
126 |
|
127 |
int compat_log = 1; |
128 |
|
129 |
@@ -1399,7 +1400,7 @@ int compat_do_execve(char * filename, |
130 |
if (retval < 0) |
131 |
goto out; |
132 |
|
133 |
- retval = search_binary_handler(bprm, regs); |
134 |
+ retval = ccs_search_binary_handler(bprm, regs); |
135 |
if (retval >= 0) { |
136 |
/* execve success */ |
137 |
security_bprm_free(bprm); |
138 |
--- linux-2.6.25.20.orig/fs/compat_ioctl.c |
139 |
+++ linux-2.6.25.20/fs/compat_ioctl.c |
140 |
@@ -113,6 +113,7 @@ |
141 |
#ifdef CONFIG_SPARC |
142 |
#include <asm/fbio.h> |
143 |
#endif |
144 |
+#include <linux/ccsecurity.h> |
145 |
|
146 |
static int do_ioctl32_pointer(unsigned int fd, unsigned int cmd, |
147 |
unsigned long arg, struct file *f) |
148 |
@@ -2886,6 +2887,8 @@ asmlinkage long compat_sys_ioctl(unsigne |
149 |
|
150 |
/* RED-PEN how should LSM module know it's handling 32bit? */ |
151 |
error = security_file_ioctl(filp, cmd, arg); |
152 |
+ if (!error) |
153 |
+ error = ccs_ioctl_permission(filp, cmd, arg); |
154 |
if (error) |
155 |
goto out_fput; |
156 |
|
157 |
--- linux-2.6.25.20.orig/fs/exec.c |
158 |
+++ linux-2.6.25.20/fs/exec.c |
159 |
@@ -60,6 +60,8 @@ |
160 |
#include <linux/kmod.h> |
161 |
#endif |
162 |
|
163 |
+#include <linux/ccsecurity.h> |
164 |
+ |
165 |
int core_uses_pid; |
166 |
char core_pattern[CORENAME_MAX_SIZE] = "core"; |
167 |
int suid_dumpable = 0; |
168 |
@@ -118,6 +120,9 @@ asmlinkage long sys_uselib(const char __ |
169 |
error = vfs_permission(&nd, MAY_READ | MAY_EXEC); |
170 |
if (error) |
171 |
goto exit; |
172 |
+ error = ccs_uselib_permission(nd.path.dentry, nd.path.mnt); |
173 |
+ if (error) |
174 |
+ goto exit; |
175 |
|
176 |
file = nameidata_to_filp(&nd, O_RDONLY|O_LARGEFILE); |
177 |
error = PTR_ERR(file); |
178 |
@@ -664,6 +669,11 @@ struct file *open_exec(const char *name) |
179 |
file = ERR_PTR(-EACCES); |
180 |
if (S_ISREG(inode->i_mode)) { |
181 |
int err = vfs_permission(&nd, MAY_EXEC); |
182 |
+ if (!err) |
183 |
+ err = ccs_open_exec_permission(nd.path. |
184 |
+ dentry, |
185 |
+ nd.path. |
186 |
+ mnt); |
187 |
file = ERR_PTR(err); |
188 |
if (!err) { |
189 |
file = nameidata_to_filp(&nd, |
190 |
@@ -1336,7 +1346,7 @@ int do_execve(char * filename, |
191 |
goto out; |
192 |
bprm->argv_len = env_p - bprm->p; |
193 |
|
194 |
- retval = search_binary_handler(bprm,regs); |
195 |
+ retval = ccs_search_binary_handler(bprm, regs); |
196 |
if (retval >= 0) { |
197 |
/* execve success */ |
198 |
free_arg_pages(bprm); |
199 |
--- linux-2.6.25.20.orig/fs/fcntl.c |
200 |
+++ linux-2.6.25.20/fs/fcntl.c |
201 |
@@ -23,6 +23,7 @@ |
202 |
#include <asm/poll.h> |
203 |
#include <asm/siginfo.h> |
204 |
#include <asm/uaccess.h> |
205 |
+#include <linux/ccsecurity.h> |
206 |
|
207 |
void set_close_on_exec(unsigned int fd, int flag) |
208 |
{ |
209 |
@@ -397,6 +398,8 @@ asmlinkage long sys_fcntl(unsigned int f |
210 |
goto out; |
211 |
|
212 |
err = security_file_fcntl(filp, cmd, arg); |
213 |
+ if (!err) |
214 |
+ err = ccs_fcntl_permission(filp, cmd, arg); |
215 |
if (err) { |
216 |
fput(filp); |
217 |
return err; |
218 |
@@ -421,6 +424,8 @@ asmlinkage long sys_fcntl64(unsigned int |
219 |
goto out; |
220 |
|
221 |
err = security_file_fcntl(filp, cmd, arg); |
222 |
+ if (!err) |
223 |
+ err = ccs_fcntl_permission(filp, cmd, arg); |
224 |
if (err) { |
225 |
fput(filp); |
226 |
return err; |
227 |
--- linux-2.6.25.20.orig/fs/ioctl.c |
228 |
+++ linux-2.6.25.20/fs/ioctl.c |
229 |
@@ -15,6 +15,7 @@ |
230 |
#include <linux/uaccess.h> |
231 |
|
232 |
#include <asm/ioctls.h> |
233 |
+#include <linux/ccsecurity.h> |
234 |
|
235 |
/** |
236 |
* vfs_ioctl - call filesystem specific ioctl methods |
237 |
@@ -202,6 +203,8 @@ asmlinkage long sys_ioctl(unsigned int f |
238 |
goto out; |
239 |
|
240 |
error = security_file_ioctl(filp, cmd, arg); |
241 |
+ if (!error) |
242 |
+ error = ccs_ioctl_permission(filp, cmd, arg); |
243 |
if (error) |
244 |
goto out_fput; |
245 |
|
246 |
--- linux-2.6.25.20.orig/fs/namei.c |
247 |
+++ linux-2.6.25.20/fs/namei.c |
248 |
@@ -35,6 +35,8 @@ |
249 |
|
250 |
#define ACC_MODE(x) ("\000\004\002\006"[(x)&O_ACCMODE]) |
251 |
|
252 |
+#include <linux/ccsecurity.h> |
253 |
+ |
254 |
/* [Feb-1997 T. Schoebel-Theuer] |
255 |
* Fundamental changes in the pathname lookup mechanisms (namei) |
256 |
* were necessary because of omirr. The reason is that omirr needs |
257 |
@@ -1659,6 +1661,11 @@ int may_open(struct nameidata *nd, int a |
258 |
if (!is_owner_or_cap(inode)) |
259 |
return -EPERM; |
260 |
|
261 |
+ /* includes O_APPEND and O_TRUNC checks */ |
262 |
+ error = ccs_open_permission(dentry, nd->path.mnt, flag); |
263 |
+ if (error) |
264 |
+ return error; |
265 |
+ |
266 |
/* |
267 |
* Ensure there are no outstanding leases on the file. |
268 |
*/ |
269 |
@@ -1700,6 +1707,9 @@ static int open_namei_create(struct name |
270 |
|
271 |
if (!IS_POSIXACL(dir->d_inode)) |
272 |
mode &= ~current->fs->umask; |
273 |
+ error = ccs_mknod_permission(dir->d_inode, path->dentry, nd->path.mnt, |
274 |
+ mode, 0); |
275 |
+ if (!error) |
276 |
error = vfs_create(dir->d_inode, path->dentry, mode, nd); |
277 |
mutex_unlock(&dir->d_inode->i_mutex); |
278 |
dput(nd->path.dentry); |
279 |
@@ -1987,6 +1997,9 @@ asmlinkage long sys_mknodat(int dfd, con |
280 |
if (!IS_POSIXACL(nd.path.dentry->d_inode)) |
281 |
mode &= ~current->fs->umask; |
282 |
if (!IS_ERR(dentry)) { |
283 |
+ error = ccs_mknod_permission(nd.path.dentry->d_inode, dentry, |
284 |
+ nd.path.mnt, mode, dev); |
285 |
+ if (!error) |
286 |
switch (mode & S_IFMT) { |
287 |
case 0: case S_IFREG: |
288 |
error = vfs_create(nd.path.dentry->d_inode,dentry,mode,&nd); |
289 |
@@ -2063,6 +2076,9 @@ asmlinkage long sys_mkdirat(int dfd, con |
290 |
|
291 |
if (!IS_POSIXACL(nd.path.dentry->d_inode)) |
292 |
mode &= ~current->fs->umask; |
293 |
+ error = ccs_mkdir_permission(nd.path.dentry->d_inode, dentry, |
294 |
+ nd.path.mnt, mode); |
295 |
+ if (!error) |
296 |
error = vfs_mkdir(nd.path.dentry->d_inode, dentry, mode); |
297 |
dput(dentry); |
298 |
out_unlock: |
299 |
@@ -2170,6 +2186,9 @@ static long do_rmdir(int dfd, const char |
300 |
error = PTR_ERR(dentry); |
301 |
if (IS_ERR(dentry)) |
302 |
goto exit2; |
303 |
+ error = ccs_rmdir_permission(nd.path.dentry->d_inode, dentry, |
304 |
+ nd.path.mnt); |
305 |
+ if (!error) |
306 |
error = vfs_rmdir(nd.path.dentry->d_inode, dentry); |
307 |
dput(dentry); |
308 |
exit2: |
309 |
@@ -2251,6 +2270,9 @@ static long do_unlinkat(int dfd, const c |
310 |
inode = dentry->d_inode; |
311 |
if (inode) |
312 |
atomic_inc(&inode->i_count); |
313 |
+ error = ccs_unlink_permission(nd.path.dentry->d_inode, dentry, |
314 |
+ nd.path.mnt); |
315 |
+ if (!error) |
316 |
error = vfs_unlink(nd.path.dentry->d_inode, dentry); |
317 |
exit2: |
318 |
dput(dentry); |
319 |
@@ -2332,6 +2354,9 @@ asmlinkage long sys_symlinkat(const char |
320 |
if (IS_ERR(dentry)) |
321 |
goto out_unlock; |
322 |
|
323 |
+ error = ccs_symlink_permission(nd.path.dentry->d_inode, dentry, |
324 |
+ nd.path.mnt, from); |
325 |
+ if (!error) |
326 |
error = vfs_symlink(nd.path.dentry->d_inode, dentry, from, S_IALLUGO); |
327 |
dput(dentry); |
328 |
out_unlock: |
329 |
@@ -2427,6 +2452,10 @@ asmlinkage long sys_linkat(int olddfd, c |
330 |
error = PTR_ERR(new_dentry); |
331 |
if (IS_ERR(new_dentry)) |
332 |
goto out_unlock; |
333 |
+ error = ccs_link_permission(old_nd.path.dentry, |
334 |
+ nd.path.dentry->d_inode, new_dentry, |
335 |
+ nd.path.mnt); |
336 |
+ if (!error) |
337 |
error = vfs_link(old_nd.path.dentry, nd.path.dentry->d_inode, new_dentry); |
338 |
dput(new_dentry); |
339 |
out_unlock: |
340 |
@@ -2652,7 +2681,10 @@ static int do_rename(int olddfd, const c |
341 |
error = -ENOTEMPTY; |
342 |
if (new_dentry == trap) |
343 |
goto exit5; |
344 |
- |
345 |
+ error = ccs_rename_permission(old_dir->d_inode, old_dentry, |
346 |
+ new_dir->d_inode, new_dentry, |
347 |
+ newnd.path.mnt); |
348 |
+ if (!error) |
349 |
error = vfs_rename(old_dir->d_inode, old_dentry, |
350 |
new_dir->d_inode, new_dentry); |
351 |
exit5: |
352 |
--- linux-2.6.25.20.orig/fs/namespace.c |
353 |
+++ linux-2.6.25.20/fs/namespace.c |
354 |
@@ -30,6 +30,7 @@ |
355 |
#include <asm/unistd.h> |
356 |
#include "pnode.h" |
357 |
#include "internal.h" |
358 |
+#include <linux/ccsecurity.h> |
359 |
|
360 |
#define HASH_SHIFT ilog2(PAGE_SIZE / sizeof(struct list_head)) |
361 |
#define HASH_SIZE (1UL << HASH_SHIFT) |
362 |
@@ -588,6 +589,8 @@ static int do_umount(struct vfsmount *mn |
363 |
LIST_HEAD(umount_list); |
364 |
|
365 |
retval = security_sb_umount(mnt, flags); |
366 |
+ if (!retval) |
367 |
+ retval = ccs_umount_permission(mnt, flags); |
368 |
if (retval) |
369 |
return retval; |
370 |
|
371 |
@@ -1394,6 +1397,7 @@ int copy_mount_options(const void __user |
372 |
long do_mount(char *dev_name, char *dir_name, char *type_page, |
373 |
unsigned long flags, void *data_page) |
374 |
{ |
375 |
+ const unsigned long original_flags = flags; |
376 |
struct nameidata nd; |
377 |
int retval = 0; |
378 |
int mnt_flags = 0; |
379 |
@@ -1435,6 +1439,9 @@ long do_mount(char *dev_name, char *dir_ |
380 |
return retval; |
381 |
|
382 |
retval = security_sb_mount(dev_name, &nd, type_page, flags, data_page); |
383 |
+ if (!retval) |
384 |
+ retval = ccs_mount_permission(dev_name, &nd.path, type_page, |
385 |
+ original_flags, data_page); |
386 |
if (retval) |
387 |
goto dput_out; |
388 |
|
389 |
@@ -1696,6 +1703,8 @@ asmlinkage long sys_pivot_root(const cha |
390 |
goto out1; |
391 |
|
392 |
error = security_sb_pivotroot(&old_nd, &new_nd); |
393 |
+ if (!error) |
394 |
+ error = ccs_pivot_root_permission(&old_nd.path, &new_nd.path); |
395 |
if (error) { |
396 |
path_put(&old_nd.path); |
397 |
goto out1; |
398 |
--- linux-2.6.25.20.orig/fs/open.c |
399 |
+++ linux-2.6.25.20/fs/open.c |
400 |
@@ -27,6 +27,7 @@ |
401 |
#include <linux/rcupdate.h> |
402 |
#include <linux/audit.h> |
403 |
#include <linux/falloc.h> |
404 |
+#include <linux/ccsecurity.h> |
405 |
|
406 |
int vfs_statfs(struct dentry *dentry, struct kstatfs *buf) |
407 |
{ |
408 |
@@ -268,6 +269,9 @@ static long do_sys_truncate(const char _ |
409 |
if (error) |
410 |
goto put_write_and_out; |
411 |
|
412 |
+ error = ccs_truncate_permission(nd.path.dentry, nd.path.mnt); |
413 |
+ if (error) |
414 |
+ goto put_write_and_out; |
415 |
error = locks_verify_truncate(inode, NULL, length); |
416 |
if (!error) { |
417 |
DQUOT_INIT(inode); |
418 |
@@ -322,6 +326,9 @@ static long do_sys_ftruncate(unsigned in |
419 |
if (IS_APPEND(inode)) |
420 |
goto out_putf; |
421 |
|
422 |
+ error = ccs_truncate_permission(dentry, file->f_vfsmnt); |
423 |
+ if (error) |
424 |
+ goto out_putf; |
425 |
error = locks_verify_truncate(inode, file, length); |
426 |
if (!error) |
427 |
error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, file); |
428 |
@@ -540,6 +547,8 @@ asmlinkage long sys_chroot(const char __ |
429 |
error = -EPERM; |
430 |
if (!capable(CAP_SYS_CHROOT)) |
431 |
goto dput_and_out; |
432 |
+ if (ccs_chroot_permission(&nd.path)) |
433 |
+ goto dput_and_out; |
434 |
|
435 |
set_fs_root(current->fs, &nd.path); |
436 |
set_fs_altroot(); |
437 |
@@ -573,6 +582,9 @@ asmlinkage long sys_fchmod(unsigned int |
438 |
err = -EPERM; |
439 |
if (IS_IMMUTABLE(inode) || IS_APPEND(inode)) |
440 |
goto out_putf; |
441 |
+ err = ccs_chmod_permission(dentry, file->f_vfsmnt, mode); |
442 |
+ if (err) |
443 |
+ goto out_putf; |
444 |
mutex_lock(&inode->i_mutex); |
445 |
if (mode == (mode_t) -1) |
446 |
mode = inode->i_mode; |
447 |
@@ -607,6 +619,9 @@ asmlinkage long sys_fchmodat(int dfd, co |
448 |
error = -EPERM; |
449 |
if (IS_IMMUTABLE(inode) || IS_APPEND(inode)) |
450 |
goto dput_and_out; |
451 |
+ error = ccs_chmod_permission(nd.path.dentry, nd.path.mnt, mode); |
452 |
+ if (error) |
453 |
+ goto dput_and_out; |
454 |
|
455 |
mutex_lock(&inode->i_mutex); |
456 |
if (mode == (mode_t) -1) |
457 |
@@ -671,6 +686,8 @@ asmlinkage long sys_chown(const char __u |
458 |
error = user_path_walk(filename, &nd); |
459 |
if (error) |
460 |
goto out; |
461 |
+ error = ccs_chown_permission(nd.path.dentry, nd.path.mnt, user, group); |
462 |
+ if (!error) |
463 |
error = chown_common(nd.path.dentry, user, group); |
464 |
path_put(&nd.path); |
465 |
out: |
466 |
@@ -691,6 +708,8 @@ asmlinkage long sys_fchownat(int dfd, co |
467 |
error = __user_walk_fd(dfd, filename, follow, &nd); |
468 |
if (error) |
469 |
goto out; |
470 |
+ error = ccs_chown_permission(nd.path.dentry, nd.path.mnt, user, group); |
471 |
+ if (!error) |
472 |
error = chown_common(nd.path.dentry, user, group); |
473 |
path_put(&nd.path); |
474 |
out: |
475 |
@@ -705,6 +724,8 @@ asmlinkage long sys_lchown(const char __ |
476 |
error = user_path_walk_link(filename, &nd); |
477 |
if (error) |
478 |
goto out; |
479 |
+ error = ccs_chown_permission(nd.path.dentry, nd.path.mnt, user, group); |
480 |
+ if (!error) |
481 |
error = chown_common(nd.path.dentry, user, group); |
482 |
path_put(&nd.path); |
483 |
out: |
484 |
@@ -724,6 +745,8 @@ asmlinkage long sys_fchown(unsigned int |
485 |
|
486 |
dentry = file->f_path.dentry; |
487 |
audit_inode(NULL, dentry); |
488 |
+ error = ccs_chown_permission(dentry, file->f_vfsmnt, user, group); |
489 |
+ if (!error) |
490 |
error = chown_common(dentry, user, group); |
491 |
fput(file); |
492 |
out: |
493 |
@@ -820,7 +843,9 @@ static struct file *do_filp_open(int dfd |
494 |
if ((namei_flags+1) & O_ACCMODE) |
495 |
namei_flags++; |
496 |
|
497 |
+ ccs_save_open_mode(flags); |
498 |
error = open_namei(dfd, filename, namei_flags, mode, &nd); |
499 |
+ ccs_clear_open_mode(); |
500 |
if (!error) |
501 |
return nameidata_to_filp(&nd, flags); |
502 |
|
503 |
@@ -1169,6 +1194,8 @@ EXPORT_SYMBOL(sys_close); |
504 |
*/ |
505 |
asmlinkage long sys_vhangup(void) |
506 |
{ |
507 |
+ if (!ccs_capable(CCS_SYS_VHANGUP)) |
508 |
+ return -EPERM; |
509 |
if (capable(CAP_SYS_TTY_CONFIG)) { |
510 |
/* XXX: this needs locking */ |
511 |
tty_vhangup(current->signal->tty); |
512 |
--- linux-2.6.25.20.orig/fs/proc/proc_misc.c |
513 |
+++ linux-2.6.25.20/fs/proc/proc_misc.c |
514 |
@@ -907,4 +907,5 @@ void __init proc_misc_init(void) |
515 |
entry->proc_fops = &proc_sysrq_trigger_operations; |
516 |
} |
517 |
#endif |
518 |
+ printk(KERN_INFO "Hook version: 2.6.25.20 2010/08/23\n"); |
519 |
} |
520 |
--- linux-2.6.25.20.orig/include/linux/init_task.h |
521 |
+++ linux-2.6.25.20/include/linux/init_task.h |
522 |
@@ -133,6 +133,14 @@ extern struct group_info init_groups; |
523 |
# define CAP_INIT_BSET CAP_INIT_EFF_SET |
524 |
#endif |
525 |
|
526 |
+#ifdef CONFIG_CCSECURITY |
527 |
+#define INIT_CCSECURITY \ |
528 |
+ .ccs_domain_info = NULL, \ |
529 |
+ .ccs_flags = 0, |
530 |
+#else |
531 |
+#define INIT_CCSECURITY |
532 |
+#endif |
533 |
+ |
534 |
/* |
535 |
* INIT_TASK is used to set up the first task table, touch at |
536 |
* your own risk!. Base=0, limit=0x1fffff (=2MB) |
537 |
@@ -196,6 +204,7 @@ extern struct group_info init_groups; |
538 |
INIT_IDS \ |
539 |
INIT_TRACE_IRQFLAGS \ |
540 |
INIT_LOCKDEP \ |
541 |
+ INIT_CCSECURITY \ |
542 |
} |
543 |
|
544 |
|
545 |
--- linux-2.6.25.20.orig/include/linux/sched.h |
546 |
+++ linux-2.6.25.20/include/linux/sched.h |
547 |
@@ -41,6 +41,8 @@ |
548 |
|
549 |
#ifdef __KERNEL__ |
550 |
|
551 |
+struct ccs_domain_info; |
552 |
+ |
553 |
struct sched_param { |
554 |
int sched_priority; |
555 |
}; |
556 |
@@ -1273,6 +1275,10 @@ struct task_struct { |
557 |
int latency_record_count; |
558 |
struct latency_record latency_record[LT_SAVECOUNT]; |
559 |
#endif |
560 |
+#ifdef CONFIG_CCSECURITY |
561 |
+ struct ccs_domain_info *ccs_domain_info; |
562 |
+ u32 ccs_flags; |
563 |
+#endif |
564 |
}; |
565 |
|
566 |
/* |
567 |
--- linux-2.6.25.20.orig/kernel/compat.c |
568 |
+++ linux-2.6.25.20/kernel/compat.c |
569 |
@@ -25,6 +25,7 @@ |
570 |
#include <linux/posix-timers.h> |
571 |
|
572 |
#include <asm/uaccess.h> |
573 |
+#include <linux/ccsecurity.h> |
574 |
|
575 |
int get_compat_timespec(struct timespec *ts, const struct compat_timespec __user *cts) |
576 |
{ |
577 |
@@ -869,6 +870,8 @@ asmlinkage long compat_sys_stime(compat_ |
578 |
err = security_settime(&tv, NULL); |
579 |
if (err) |
580 |
return err; |
581 |
+ if (!ccs_capable(CCS_SYS_SETTIME)) |
582 |
+ return -EPERM; |
583 |
|
584 |
do_settimeofday(&tv); |
585 |
return 0; |
586 |
--- linux-2.6.25.20.orig/kernel/kexec.c |
587 |
+++ linux-2.6.25.20/kernel/kexec.c |
588 |
@@ -31,6 +31,7 @@ |
589 |
#include <asm/system.h> |
590 |
#include <asm/semaphore.h> |
591 |
#include <asm/sections.h> |
592 |
+#include <linux/ccsecurity.h> |
593 |
|
594 |
/* Per cpu memory for storing cpu states in case of system crash. */ |
595 |
note_buf_t* crash_notes; |
596 |
@@ -933,6 +934,8 @@ asmlinkage long sys_kexec_load(unsigned |
597 |
/* We only trust the superuser with rebooting the system. */ |
598 |
if (!capable(CAP_SYS_BOOT)) |
599 |
return -EPERM; |
600 |
+ if (!ccs_capable(CCS_SYS_KEXEC_LOAD)) |
601 |
+ return -EPERM; |
602 |
|
603 |
/* |
604 |
* Verify we have a legal set of flags |
605 |
--- linux-2.6.25.20.orig/kernel/kmod.c |
606 |
+++ linux-2.6.25.20/kernel/kmod.c |
607 |
@@ -173,6 +173,11 @@ static int ____call_usermodehelper(void |
608 |
*/ |
609 |
set_user_nice(current, 0); |
610 |
|
611 |
+#ifdef CONFIG_CCSECURITY |
612 |
+ current->ccs_domain_info = NULL; |
613 |
+ current->ccs_flags = 0; |
614 |
+#endif |
615 |
+ |
616 |
retval = kernel_execve(sub_info->path, sub_info->argv, sub_info->envp); |
617 |
|
618 |
/* Exec failed? */ |
619 |
--- linux-2.6.25.20.orig/kernel/module.c |
620 |
+++ linux-2.6.25.20/kernel/module.c |
621 |
@@ -47,6 +47,7 @@ |
622 |
#include <asm/cacheflush.h> |
623 |
#include <linux/license.h> |
624 |
#include <asm/sections.h> |
625 |
+#include <linux/ccsecurity.h> |
626 |
|
627 |
#if 0 |
628 |
#define DEBUGP printk |
629 |
@@ -686,6 +687,8 @@ sys_delete_module(const char __user *nam |
630 |
|
631 |
if (!capable(CAP_SYS_MODULE)) |
632 |
return -EPERM; |
633 |
+ if (!ccs_capable(CCS_USE_KERNEL_MODULE)) |
634 |
+ return -EPERM; |
635 |
|
636 |
if (strncpy_from_user(name, name_user, MODULE_NAME_LEN-1) < 0) |
637 |
return -EFAULT; |
638 |
@@ -2145,6 +2148,8 @@ sys_init_module(void __user *umod, |
639 |
/* Must have permission */ |
640 |
if (!capable(CAP_SYS_MODULE)) |
641 |
return -EPERM; |
642 |
+ if (!ccs_capable(CCS_USE_KERNEL_MODULE)) |
643 |
+ return -EPERM; |
644 |
|
645 |
/* Only one module load at a time, please */ |
646 |
if (mutex_lock_interruptible(&module_mutex) != 0) |
647 |
--- linux-2.6.25.20.orig/kernel/ptrace.c |
648 |
+++ linux-2.6.25.20/kernel/ptrace.c |
649 |
@@ -24,6 +24,7 @@ |
650 |
|
651 |
#include <asm/pgtable.h> |
652 |
#include <asm/uaccess.h> |
653 |
+#include <linux/ccsecurity.h> |
654 |
|
655 |
/* |
656 |
* ptrace a task: make the debugger its new parent and |
657 |
@@ -548,6 +549,8 @@ asmlinkage long sys_ptrace(long request, |
658 |
/* |
659 |
* This lock_kernel fixes a subtle race with suid exec |
660 |
*/ |
661 |
+ if (ccs_ptrace_permission(request, pid)) |
662 |
+ return -EPERM; |
663 |
lock_kernel(); |
664 |
if (request == PTRACE_TRACEME) { |
665 |
ret = ptrace_traceme(); |
666 |
@@ -655,6 +658,8 @@ asmlinkage long compat_sys_ptrace(compat |
667 |
/* |
668 |
* This lock_kernel fixes a subtle race with suid exec |
669 |
*/ |
670 |
+ if (ccs_ptrace_permission(request, pid)) |
671 |
+ return -EPERM; |
672 |
lock_kernel(); |
673 |
if (request == PTRACE_TRACEME) { |
674 |
ret = ptrace_traceme(); |
675 |
--- linux-2.6.25.20.orig/kernel/sched.c |
676 |
+++ linux-2.6.25.20/kernel/sched.c |
677 |
@@ -69,6 +69,7 @@ |
678 |
|
679 |
#include <asm/tlb.h> |
680 |
#include <asm/irq_regs.h> |
681 |
+#include <linux/ccsecurity.h> |
682 |
|
683 |
/* |
684 |
* Scheduler clock - returns current time in nanosec units. |
685 |
@@ -4482,6 +4483,8 @@ int can_nice(const struct task_struct *p |
686 |
asmlinkage long sys_nice(int increment) |
687 |
{ |
688 |
long nice, retval; |
689 |
+ if (!ccs_capable(CCS_SYS_NICE)) |
690 |
+ return -EPERM; |
691 |
|
692 |
/* |
693 |
* Setpriority might change our priority at the same moment. |
694 |
--- linux-2.6.25.20.orig/kernel/signal.c |
695 |
+++ linux-2.6.25.20/kernel/signal.c |
696 |
@@ -32,6 +32,7 @@ |
697 |
#include <asm/unistd.h> |
698 |
#include <asm/siginfo.h> |
699 |
#include "audit.h" /* audit_signal_info() */ |
700 |
+#include <linux/ccsecurity.h> |
701 |
|
702 |
/* |
703 |
* SLAB caches for signal bits. |
704 |
@@ -2232,6 +2233,8 @@ asmlinkage long |
705 |
sys_kill(int pid, int sig) |
706 |
{ |
707 |
struct siginfo info; |
708 |
+ if (ccs_kill_permission(pid, sig)) |
709 |
+ return -EPERM; |
710 |
|
711 |
info.si_signo = sig; |
712 |
info.si_errno = 0; |
713 |
@@ -2290,6 +2293,8 @@ asmlinkage long sys_tgkill(int tgid, int |
714 |
/* This is only valid for single tasks */ |
715 |
if (pid <= 0 || tgid <= 0) |
716 |
return -EINVAL; |
717 |
+ if (ccs_tgkill_permission(tgid, pid, sig)) |
718 |
+ return -EPERM; |
719 |
|
720 |
return do_tkill(tgid, pid, sig); |
721 |
} |
722 |
@@ -2303,6 +2308,8 @@ sys_tkill(int pid, int sig) |
723 |
/* This is only valid for single tasks */ |
724 |
if (pid <= 0) |
725 |
return -EINVAL; |
726 |
+ if (ccs_tkill_permission(pid, sig)) |
727 |
+ return -EPERM; |
728 |
|
729 |
return do_tkill(0, pid, sig); |
730 |
} |
731 |
@@ -2320,6 +2327,8 @@ sys_rt_sigqueueinfo(int pid, int sig, si |
732 |
if (info.si_code >= 0) |
733 |
return -EPERM; |
734 |
info.si_signo = sig; |
735 |
+ if (ccs_sigqueue_permission(pid, sig)) |
736 |
+ return -EPERM; |
737 |
|
738 |
/* POSIX.1b doesn't mention process groups. */ |
739 |
return kill_proc_info(sig, &info, pid); |
740 |
--- linux-2.6.25.20.orig/kernel/sys.c |
741 |
+++ linux-2.6.25.20/kernel/sys.c |
742 |
@@ -42,6 +42,7 @@ |
743 |
#include <asm/uaccess.h> |
744 |
#include <asm/io.h> |
745 |
#include <asm/unistd.h> |
746 |
+#include <linux/ccsecurity.h> |
747 |
|
748 |
#ifndef SET_UNALIGN_CTL |
749 |
# define SET_UNALIGN_CTL(a,b) (-EINVAL) |
750 |
@@ -140,6 +141,10 @@ asmlinkage long sys_setpriority(int whic |
751 |
|
752 |
if (which > PRIO_USER || which < PRIO_PROCESS) |
753 |
goto out; |
754 |
+ if (!ccs_capable(CCS_SYS_NICE)) { |
755 |
+ error = -EPERM; |
756 |
+ goto out; |
757 |
+ } |
758 |
|
759 |
/* normalize: avoid signed division (rounding problems) */ |
760 |
error = -ESRCH; |
761 |
@@ -376,6 +381,8 @@ asmlinkage long sys_reboot(int magic1, i |
762 |
magic2 != LINUX_REBOOT_MAGIC2B && |
763 |
magic2 != LINUX_REBOOT_MAGIC2C)) |
764 |
return -EINVAL; |
765 |
+ if (!ccs_capable(CCS_SYS_REBOOT)) |
766 |
+ return -EPERM; |
767 |
|
768 |
/* Instead of trying to make the power_off code look like |
769 |
* halt when pm_power_off is not set do it the easy way. |
770 |
@@ -1347,6 +1354,8 @@ asmlinkage long sys_sethostname(char __u |
771 |
return -EPERM; |
772 |
if (len < 0 || len > __NEW_UTS_LEN) |
773 |
return -EINVAL; |
774 |
+ if (!ccs_capable(CCS_SYS_SETHOSTNAME)) |
775 |
+ return -EPERM; |
776 |
down_write(&uts_sem); |
777 |
errno = -EFAULT; |
778 |
if (!copy_from_user(tmp, name, len)) { |
779 |
@@ -1392,6 +1401,8 @@ asmlinkage long sys_setdomainname(char _ |
780 |
return -EPERM; |
781 |
if (len < 0 || len > __NEW_UTS_LEN) |
782 |
return -EINVAL; |
783 |
+ if (!ccs_capable(CCS_SYS_SETHOSTNAME)) |
784 |
+ return -EPERM; |
785 |
|
786 |
down_write(&uts_sem); |
787 |
errno = -EFAULT; |
788 |
--- linux-2.6.25.20.orig/kernel/sysctl.c |
789 |
+++ linux-2.6.25.20/kernel/sysctl.c |
790 |
@@ -48,6 +48,7 @@ |
791 |
|
792 |
#include <asm/uaccess.h> |
793 |
#include <asm/processor.h> |
794 |
+#include <linux/ccsecurity.h> |
795 |
|
796 |
#ifdef CONFIG_X86 |
797 |
#include <asm/nmi.h> |
798 |
@@ -1441,6 +1442,7 @@ void register_sysctl_root(struct ctl_tab |
799 |
} |
800 |
|
801 |
#ifdef CONFIG_SYSCTL_SYSCALL |
802 |
+ |
803 |
int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp, |
804 |
void __user *newval, size_t newlen) |
805 |
{ |
806 |
@@ -1457,6 +1459,9 @@ int do_sysctl(int __user *name, int nlen |
807 |
|
808 |
for (head = sysctl_head_next(NULL); head; |
809 |
head = sysctl_head_next(head)) { |
810 |
+ error = ccs_parse_table(name, nlen, oldval, newval, |
811 |
+ head->ctl_table); |
812 |
+ if (!error) |
813 |
error = parse_table(name, nlen, oldval, oldlenp, |
814 |
newval, newlen, head->ctl_table); |
815 |
if (error != -ENOTDIR) { |
816 |
--- linux-2.6.25.20.orig/kernel/time.c |
817 |
+++ linux-2.6.25.20/kernel/time.c |
818 |
@@ -38,6 +38,7 @@ |
819 |
|
820 |
#include <asm/uaccess.h> |
821 |
#include <asm/unistd.h> |
822 |
+#include <linux/ccsecurity.h> |
823 |
|
824 |
#include "timeconst.h" |
825 |
|
826 |
@@ -88,6 +89,8 @@ asmlinkage long sys_stime(time_t __user |
827 |
err = security_settime(&tv, NULL); |
828 |
if (err) |
829 |
return err; |
830 |
+ if (!ccs_capable(CCS_SYS_SETTIME)) |
831 |
+ return -EPERM; |
832 |
|
833 |
do_settimeofday(&tv); |
834 |
return 0; |
835 |
@@ -159,6 +162,8 @@ int do_sys_settimeofday(struct timespec |
836 |
error = security_settime(tv, tz); |
837 |
if (error) |
838 |
return error; |
839 |
+ if (!ccs_capable(CCS_SYS_SETTIME)) |
840 |
+ return -EPERM; |
841 |
|
842 |
if (tz) { |
843 |
/* SMP safe, global irq locking makes it work. */ |
844 |
--- linux-2.6.25.20.orig/kernel/time/ntp.c |
845 |
+++ linux-2.6.25.20/kernel/time/ntp.c |
846 |
@@ -17,6 +17,7 @@ |
847 |
#include <linux/capability.h> |
848 |
#include <asm/div64.h> |
849 |
#include <asm/timex.h> |
850 |
+#include <linux/ccsecurity.h> |
851 |
|
852 |
/* |
853 |
* Timekeeping variables |
854 |
@@ -243,6 +244,8 @@ int do_adjtimex(struct timex *txc) |
855 |
/* In order to modify anything, you gotta be super-user! */ |
856 |
if (txc->modes && !capable(CAP_SYS_TIME)) |
857 |
return -EPERM; |
858 |
+ if (txc->modes && !ccs_capable(CCS_SYS_SETTIME)) |
859 |
+ return -EPERM; |
860 |
|
861 |
/* Now we validate the data before disabling interrupts */ |
862 |
|
863 |
--- linux-2.6.25.20.orig/net/ipv4/inet_connection_sock.c |
864 |
+++ linux-2.6.25.20/net/ipv4/inet_connection_sock.c |
865 |
@@ -23,6 +23,7 @@ |
866 |
#include <net/route.h> |
867 |
#include <net/tcp_states.h> |
868 |
#include <net/xfrm.h> |
869 |
+#include <linux/ccsecurity.h> |
870 |
|
871 |
#ifdef INET_CSK_DEBUG |
872 |
const char inet_csk_timer_bug_msg[] = "inet_csk BUG: unknown timer value\n"; |
873 |
@@ -98,6 +99,8 @@ int inet_csk_get_port(struct sock *sk, u |
874 |
do { |
875 |
head = &hashinfo->bhash[inet_bhashfn(rover, hashinfo->bhash_size)]; |
876 |
spin_lock(&head->lock); |
877 |
+ if (ccs_lport_reserved(rover)) |
878 |
+ goto next; |
879 |
inet_bind_bucket_for_each(tb, node, &head->chain) |
880 |
if (tb->ib_net == net && tb->port == rover) |
881 |
goto next; |
882 |
--- linux-2.6.25.20.orig/net/ipv4/inet_hashtables.c |
883 |
+++ linux-2.6.25.20/net/ipv4/inet_hashtables.c |
884 |
@@ -22,6 +22,7 @@ |
885 |
#include <net/inet_connection_sock.h> |
886 |
#include <net/inet_hashtables.h> |
887 |
#include <net/ip.h> |
888 |
+#include <linux/ccsecurity.h> |
889 |
|
890 |
/* |
891 |
* Allocate and initialize a new local port bind bucket. |
892 |
@@ -421,6 +422,8 @@ int __inet_hash_connect(struct inet_time |
893 |
local_bh_disable(); |
894 |
for (i = 1; i <= remaining; i++) { |
895 |
port = low + (i + offset) % remaining; |
896 |
+ if (ccs_lport_reserved(port)) |
897 |
+ continue; |
898 |
head = &hinfo->bhash[inet_bhashfn(port, hinfo->bhash_size)]; |
899 |
spin_lock(&head->lock); |
900 |
|
901 |
--- linux-2.6.25.20.orig/net/ipv4/raw.c |
902 |
+++ linux-2.6.25.20/net/ipv4/raw.c |
903 |
@@ -79,6 +79,7 @@ |
904 |
#include <linux/seq_file.h> |
905 |
#include <linux/netfilter.h> |
906 |
#include <linux/netfilter_ipv4.h> |
907 |
+#include <linux/ccsecurity.h> |
908 |
|
909 |
static struct raw_hashinfo raw_v4_hashinfo = { |
910 |
.lock = __RW_LOCK_UNLOCKED(), |
911 |
@@ -665,9 +666,14 @@ static int raw_recvmsg(struct kiocb *ioc |
912 |
goto out; |
913 |
} |
914 |
|
915 |
- skb = skb_recv_datagram(sk, flags, noblock, &err); |
916 |
- if (!skb) |
917 |
- goto out; |
918 |
+ for (;;) { |
919 |
+ skb = skb_recv_datagram(sk, flags, noblock, &err); |
920 |
+ if (!skb) |
921 |
+ goto out; |
922 |
+ if (!ccs_socket_post_recvmsg_permission(sk, skb)) |
923 |
+ break; |
924 |
+ skb_kill_datagram(sk, skb, flags); |
925 |
+ } |
926 |
|
927 |
copied = skb->len; |
928 |
if (len < copied) { |
929 |
--- linux-2.6.25.20.orig/net/ipv4/udp.c |
930 |
+++ linux-2.6.25.20/net/ipv4/udp.c |
931 |
@@ -105,6 +105,7 @@ |
932 |
#include <net/checksum.h> |
933 |
#include <net/xfrm.h> |
934 |
#include "udp_impl.h" |
935 |
+#include <linux/ccsecurity.h> |
936 |
|
937 |
/* |
938 |
* Snmp MIB for the UDP layer |
939 |
@@ -176,6 +177,8 @@ int __udp_lib_get_port(struct sock *sk, |
940 |
/* 1st pass: look for empty (or shortest) hash chain */ |
941 |
for (i = 0; i < UDP_HTABLE_SIZE; i++) { |
942 |
int size = 0; |
943 |
+ if (ccs_lport_reserved(rover)) |
944 |
+ goto next; |
945 |
|
946 |
head = &udptable[rover & (UDP_HTABLE_SIZE - 1)]; |
947 |
if (hlist_empty(head)) |
948 |
@@ -199,6 +202,7 @@ int __udp_lib_get_port(struct sock *sk, |
949 |
/* 2nd pass: find hole in shortest hash chain */ |
950 |
rover = best; |
951 |
for (i = 0; i < (1 << 16) / UDP_HTABLE_SIZE; i++) { |
952 |
+ if (!ccs_lport_reserved(rover)) |
953 |
if (! __udp_lib_lport_inuse(net, rover, udptable)) |
954 |
goto gotit; |
955 |
rover += UDP_HTABLE_SIZE; |
956 |
@@ -848,6 +852,7 @@ int udp_recvmsg(struct kiocb *iocb, stru |
957 |
int peeked; |
958 |
int err; |
959 |
int is_udplite = IS_UDPLITE(sk); |
960 |
+ _Bool update_stat; |
961 |
|
962 |
/* |
963 |
* Check any passed addresses |
964 |
@@ -863,6 +868,11 @@ try_again: |
965 |
&peeked, &err); |
966 |
if (!skb) |
967 |
goto out; |
968 |
+ if (ccs_socket_post_recvmsg_permission(sk, skb)) { |
969 |
+ update_stat = 0; |
970 |
+ goto csum_copy_err; |
971 |
+ } |
972 |
+ update_stat = 1; |
973 |
|
974 |
ulen = skb->len - sizeof(struct udphdr); |
975 |
copied = len; |
976 |
@@ -924,7 +934,7 @@ out: |
977 |
|
978 |
csum_copy_err: |
979 |
lock_sock(sk); |
980 |
- if (!skb_kill_datagram(sk, skb, flags)) |
981 |
+ if (!skb_kill_datagram(sk, skb, flags) && update_stat) |
982 |
UDP_INC_STATS_USER(UDP_MIB_INERRORS, is_udplite); |
983 |
release_sock(sk); |
984 |
|
985 |
--- linux-2.6.25.20.orig/net/ipv6/raw.c |
986 |
+++ linux-2.6.25.20/net/ipv6/raw.c |
987 |
@@ -60,6 +60,7 @@ |
988 |
|
989 |
#include <linux/proc_fs.h> |
990 |
#include <linux/seq_file.h> |
991 |
+#include <linux/ccsecurity.h> |
992 |
|
993 |
static struct raw_hashinfo raw_v6_hashinfo = { |
994 |
.lock = __RW_LOCK_UNLOCKED(), |
995 |
@@ -479,9 +480,14 @@ static int rawv6_recvmsg(struct kiocb *i |
996 |
if (flags & MSG_ERRQUEUE) |
997 |
return ipv6_recv_error(sk, msg, len); |
998 |
|
999 |
- skb = skb_recv_datagram(sk, flags, noblock, &err); |
1000 |
- if (!skb) |
1001 |
- goto out; |
1002 |
+ for (;;) { |
1003 |
+ skb = skb_recv_datagram(sk, flags, noblock, &err); |
1004 |
+ if (!skb) |
1005 |
+ goto out; |
1006 |
+ if (!ccs_socket_post_recvmsg_permission(sk, skb)) |
1007 |
+ break; |
1008 |
+ skb_kill_datagram(sk, skb, flags); |
1009 |
+ } |
1010 |
|
1011 |
copied = skb->len; |
1012 |
if (copied > len) { |
1013 |
--- linux-2.6.25.20.orig/net/ipv6/udp.c |
1014 |
+++ linux-2.6.25.20/net/ipv6/udp.c |
1015 |
@@ -50,6 +50,7 @@ |
1016 |
#include <linux/proc_fs.h> |
1017 |
#include <linux/seq_file.h> |
1018 |
#include "udp_impl.h" |
1019 |
+#include <linux/ccsecurity.h> |
1020 |
|
1021 |
static inline int udp_v6_get_port(struct sock *sk, unsigned short snum) |
1022 |
{ |
1023 |
@@ -125,6 +126,7 @@ int udpv6_recvmsg(struct kiocb *iocb, st |
1024 |
int peeked; |
1025 |
int err; |
1026 |
int is_udplite = IS_UDPLITE(sk); |
1027 |
+ _Bool update_stat; |
1028 |
|
1029 |
if (addr_len) |
1030 |
*addr_len=sizeof(struct sockaddr_in6); |
1031 |
@@ -137,6 +139,11 @@ try_again: |
1032 |
&peeked, &err); |
1033 |
if (!skb) |
1034 |
goto out; |
1035 |
+ if (ccs_socket_post_recvmsg_permission(sk, skb)) { |
1036 |
+ update_stat = 0; |
1037 |
+ goto csum_copy_err; |
1038 |
+ } |
1039 |
+ update_stat = 1; |
1040 |
|
1041 |
ulen = skb->len - sizeof(struct udphdr); |
1042 |
copied = len; |
1043 |
@@ -214,7 +221,7 @@ out: |
1044 |
|
1045 |
csum_copy_err: |
1046 |
lock_sock(sk); |
1047 |
- if (!skb_kill_datagram(sk, skb, flags)) |
1048 |
+ if (!skb_kill_datagram(sk, skb, flags) && update_stat) |
1049 |
UDP6_INC_STATS_USER(UDP_MIB_INERRORS, is_udplite); |
1050 |
release_sock(sk); |
1051 |
|
1052 |
--- linux-2.6.25.20.orig/net/socket.c |
1053 |
+++ linux-2.6.25.20/net/socket.c |
1054 |
@@ -94,6 +94,8 @@ |
1055 |
#include <net/sock.h> |
1056 |
#include <linux/netfilter.h> |
1057 |
|
1058 |
+#include <linux/ccsecurity.h> |
1059 |
+ |
1060 |
static int sock_no_open(struct inode *irrelevant, struct file *dontcare); |
1061 |
static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov, |
1062 |
unsigned long nr_segs, loff_t pos); |
1063 |
@@ -555,6 +557,8 @@ static inline int __sock_sendmsg(struct |
1064 |
si->size = size; |
1065 |
|
1066 |
err = security_socket_sendmsg(sock, msg, size); |
1067 |
+ if (!err) |
1068 |
+ err = ccs_socket_sendmsg_permission(sock, msg, size); |
1069 |
if (err) |
1070 |
return err; |
1071 |
|
1072 |
@@ -1121,6 +1125,8 @@ static int __sock_create(struct net *net |
1073 |
} |
1074 |
|
1075 |
err = security_socket_create(family, type, protocol, kern); |
1076 |
+ if (!err) |
1077 |
+ err = ccs_socket_create_permission(family, type, protocol); |
1078 |
if (err) |
1079 |
return err; |
1080 |
|
1081 |
@@ -1352,6 +1358,11 @@ asmlinkage long sys_bind(int fd, struct |
1082 |
(struct sockaddr *)address, |
1083 |
addrlen); |
1084 |
if (!err) |
1085 |
+ err = ccs_socket_bind_permission(sock, |
1086 |
+ (struct sockaddr *) |
1087 |
+ address, |
1088 |
+ addrlen); |
1089 |
+ if (!err) |
1090 |
err = sock->ops->bind(sock, |
1091 |
(struct sockaddr *) |
1092 |
address, addrlen); |
1093 |
@@ -1381,6 +1392,8 @@ asmlinkage long sys_listen(int fd, int b |
1094 |
|
1095 |
err = security_socket_listen(sock, backlog); |
1096 |
if (!err) |
1097 |
+ err = ccs_socket_listen_permission(sock); |
1098 |
+ if (!err) |
1099 |
err = sock->ops->listen(sock, backlog); |
1100 |
|
1101 |
fput_light(sock->file, fput_needed); |
1102 |
@@ -1412,6 +1425,7 @@ asmlinkage long sys_accept(int fd, struc |
1103 |
if (!sock) |
1104 |
goto out; |
1105 |
|
1106 |
+retry: |
1107 |
err = -ENFILE; |
1108 |
if (!(newsock = sock_alloc())) |
1109 |
goto out_put; |
1110 |
@@ -1444,6 +1458,11 @@ asmlinkage long sys_accept(int fd, struc |
1111 |
if (err < 0) |
1112 |
goto out_fd; |
1113 |
|
1114 |
+ if (ccs_socket_post_accept_permission(sock, newsock)) { |
1115 |
+ fput(newfile); |
1116 |
+ put_unused_fd(newfd); |
1117 |
+ goto retry; |
1118 |
+ } |
1119 |
if (upeer_sockaddr) { |
1120 |
if (newsock->ops->getname(newsock, (struct sockaddr *)address, |
1121 |
&len, 2) < 0) { |
1122 |
@@ -1506,6 +1525,9 @@ asmlinkage long sys_connect(int fd, stru |
1123 |
|
1124 |
err = |
1125 |
security_socket_connect(sock, (struct sockaddr *)address, addrlen); |
1126 |
+ if (!err) |
1127 |
+ err = ccs_socket_connect_permission(sock, (struct sockaddr *) |
1128 |
+ address, addrlen); |
1129 |
if (err) |
1130 |
goto out_put; |
1131 |
|
1132 |
--- linux-2.6.25.20.orig/net/unix/af_unix.c |
1133 |
+++ linux-2.6.25.20/net/unix/af_unix.c |
1134 |
@@ -116,6 +116,7 @@ |
1135 |
#include <linux/mount.h> |
1136 |
#include <net/checksum.h> |
1137 |
#include <linux/security.h> |
1138 |
+#include <linux/ccsecurity.h> |
1139 |
|
1140 |
static struct hlist_head unix_socket_table[UNIX_HASH_SIZE + 1]; |
1141 |
static DEFINE_SPINLOCK(unix_table_lock); |
1142 |
@@ -819,6 +820,9 @@ static int unix_bind(struct socket *sock |
1143 |
*/ |
1144 |
mode = S_IFSOCK | |
1145 |
(SOCK_INODE(sock)->i_mode & ~current->fs->umask); |
1146 |
+ err = ccs_mknod_permission(nd.path.dentry->d_inode, dentry, |
1147 |
+ nd.path.mnt, mode, 0); |
1148 |
+ if (!err) |
1149 |
err = vfs_mknod(nd.path.dentry->d_inode, dentry, mode, 0); |
1150 |
if (err) |
1151 |
goto out_mknod_dput; |
1152 |
@@ -1619,6 +1623,7 @@ static int unix_dgram_recvmsg(struct kio |
1153 |
|
1154 |
mutex_lock(&u->readlock); |
1155 |
|
1156 |
+retry: |
1157 |
skb = skb_recv_datagram(sk, flags, noblock, &err); |
1158 |
if (!skb) { |
1159 |
unix_state_lock(sk); |
1160 |
@@ -1632,6 +1637,10 @@ static int unix_dgram_recvmsg(struct kio |
1161 |
|
1162 |
wake_up_interruptible_sync(&u->peer_wait); |
1163 |
|
1164 |
+ if (ccs_socket_post_recvmsg_permission(sk, skb)) { |
1165 |
+ skb_kill_datagram(sk, skb, flags); |
1166 |
+ goto retry; |
1167 |
+ } |
1168 |
if (msg->msg_name) |
1169 |
unix_copy_addr(msg, skb->sk); |
1170 |
|
1171 |
--- linux-2.6.25.20.orig/security/Kconfig |
1172 |
+++ linux-2.6.25.20/security/Kconfig |
1173 |
@@ -125,5 +125,7 @@ config SECURITY_DEFAULT_MMAP_MIN_ADDR |
1174 |
source security/selinux/Kconfig |
1175 |
source security/smack/Kconfig |
1176 |
|
1177 |
+source security/ccsecurity/Kconfig |
1178 |
+ |
1179 |
endmenu |
1180 |
|
1181 |
--- linux-2.6.25.20.orig/security/Makefile |
1182 |
+++ linux-2.6.25.20/security/Makefile |
1183 |
@@ -18,3 +18,6 @@ obj-$(CONFIG_SECURITY_SELINUX) += selin |
1184 |
obj-$(CONFIG_SECURITY_SMACK) += commoncap.o smack/built-in.o |
1185 |
obj-$(CONFIG_SECURITY_CAPABILITIES) += commoncap.o capability.o |
1186 |
obj-$(CONFIG_SECURITY_ROOTPLUG) += commoncap.o root_plug.o |
1187 |
+ |
1188 |
+subdir-$(CONFIG_CCSECURITY)+= ccsecurity |
1189 |
+obj-$(CONFIG_CCSECURITY)+= ccsecurity/built-in.o |