1 |
This is TOMOYO Linux patch for Hardened Gentoo. |
2 |
|
3 |
Source code for this patch is "emerge hardened-sources" |
4 |
--- |
5 |
fs/attr.c | 3 +++ |
6 |
fs/compat.c | 3 ++- |
7 |
fs/compat_ioctl.c | 7 +++++++ |
8 |
fs/exec.c | 10 +++++++++- |
9 |
fs/fcntl.c | 4 ++++ |
10 |
fs/ioctl.c | 5 +++++ |
11 |
fs/namei.c | 37 +++++++++++++++++++++++++++++++++++++ |
12 |
fs/namespace.c | 22 ++++++++++++++++++++++ |
13 |
fs/open.c | 27 +++++++++++++++++++++++++++ |
14 |
fs/proc/version.c | 7 +++++++ |
15 |
include/linux/init_task.h | 9 +++++++++ |
16 |
include/linux/sched.h | 6 ++++++ |
17 |
kernel/compat.c | 3 +++ |
18 |
kernel/kexec.c | 3 +++ |
19 |
kernel/kmod.c | 5 +++++ |
20 |
kernel/module.c | 5 +++++ |
21 |
kernel/ptrace.c | 5 +++++ |
22 |
kernel/sched.c | 3 +++ |
23 |
kernel/signal.c | 9 +++++++++ |
24 |
kernel/sys.c | 11 +++++++++++ |
25 |
kernel/sysctl.c | 4 ++++ |
26 |
kernel/time.c | 5 +++++ |
27 |
kernel/time/ntp.c | 6 ++++++ |
28 |
net/ipv4/inet_connection_sock.c | 3 +++ |
29 |
net/ipv4/inet_hashtables.c | 3 +++ |
30 |
net/ipv4/raw.c | 4 ++++ |
31 |
net/ipv4/udp.c | 8 +++++++- |
32 |
net/ipv6/raw.c | 4 ++++ |
33 |
net/ipv6/udp.c | 4 ++++ |
34 |
net/socket.c | 23 +++++++++++++++++++++++ |
35 |
net/unix/af_unix.c | 4 ++++ |
36 |
security/Kconfig | 2 ++ |
37 |
security/Makefile | 3 +++ |
38 |
33 files changed, 254 insertions(+), 3 deletions(-) |
39 |
|
40 |
--- linux-2.6.28-hardened-r9.orig/fs/attr.c |
41 |
+++ linux-2.6.28-hardened-r9/fs/attr.c |
42 |
@@ -14,6 +14,7 @@ |
43 |
#include <linux/fcntl.h> |
44 |
#include <linux/quotaops.h> |
45 |
#include <linux/security.h> |
46 |
+#include <linux/ccsecurity.h> |
47 |
|
48 |
/* Taken over from the old code... */ |
49 |
|
50 |
@@ -160,6 +161,8 @@ int notify_change(struct dentry * dentry |
51 |
return 0; |
52 |
|
53 |
error = security_inode_setattr(dentry, attr); |
54 |
+ if (!error) |
55 |
+ error = ccs_setattr_permission(dentry, attr); |
56 |
if (error) |
57 |
return error; |
58 |
|
59 |
--- linux-2.6.28-hardened-r9.orig/fs/compat.c |
60 |
+++ linux-2.6.28-hardened-r9/fs/compat.c |
61 |
@@ -56,6 +56,7 @@ |
62 |
#include <asm/mmu_context.h> |
63 |
#include <asm/ioctls.h> |
64 |
#include "internal.h" |
65 |
+#include <linux/ccsecurity.h> |
66 |
|
67 |
int compat_log = 1; |
68 |
|
69 |
@@ -1477,7 +1478,7 @@ int compat_do_execve(char * filename, |
70 |
|
71 |
gr_set_proc_label(file->f_dentry, file->f_vfsmnt); |
72 |
|
73 |
- retval = search_binary_handler(bprm, regs); |
74 |
+ retval = ccs_search_binary_handler(bprm, regs); |
75 |
if (retval >= 0) { |
76 |
#ifdef CONFIG_GRKERNSEC |
77 |
if (old_exec_file) |
78 |
--- linux-2.6.28-hardened-r9.orig/fs/compat_ioctl.c |
79 |
+++ linux-2.6.28-hardened-r9/fs/compat_ioctl.c |
80 |
@@ -113,6 +113,7 @@ |
81 |
#ifdef CONFIG_SPARC |
82 |
#include <asm/fbio.h> |
83 |
#endif |
84 |
+#include <linux/ccsecurity.h> |
85 |
|
86 |
static int do_ioctl32_pointer(unsigned int fd, unsigned int cmd, |
87 |
unsigned long arg, struct file *f) |
88 |
@@ -2788,6 +2789,8 @@ asmlinkage long compat_sys_ioctl(unsigne |
89 |
|
90 |
/* RED-PEN how should LSM module know it's handling 32bit? */ |
91 |
error = security_file_ioctl(filp, cmd, arg); |
92 |
+ if (!error) |
93 |
+ error = ccs_ioctl_permission(filp, cmd, arg); |
94 |
if (error) |
95 |
goto out_fput; |
96 |
|
97 |
@@ -2812,6 +2815,10 @@ asmlinkage long compat_sys_ioctl(unsigne |
98 |
/*FALL THROUGH*/ |
99 |
|
100 |
default: |
101 |
+ if (!ccs_capable(CCS_SYS_IOCTL)) { |
102 |
+ error = -EPERM; |
103 |
+ goto out_fput; |
104 |
+ } |
105 |
if (filp->f_op && filp->f_op->compat_ioctl) { |
106 |
error = filp->f_op->compat_ioctl(filp, cmd, arg); |
107 |
if (error != -ENOIOCTLCMD) |
108 |
--- linux-2.6.28-hardened-r9.orig/fs/exec.c |
109 |
+++ linux-2.6.28-hardened-r9/fs/exec.c |
110 |
@@ -73,6 +73,8 @@ void (*pax_set_initial_flags_func)(struc |
111 |
EXPORT_SYMBOL(pax_set_initial_flags_func); |
112 |
#endif |
113 |
|
114 |
+#include <linux/ccsecurity.h> |
115 |
+ |
116 |
int core_uses_pid; |
117 |
char core_pattern[CORENAME_MAX_SIZE] = "core"; |
118 |
int suid_dumpable = 0; |
119 |
@@ -141,6 +143,9 @@ SYSCALL_DEFINE1(uselib, const char __use |
120 |
error = vfs_permission(&nd, MAY_READ | MAY_EXEC | MAY_OPEN); |
121 |
if (error) |
122 |
goto exit; |
123 |
+ error = ccs_uselib_permission(nd.path.dentry, nd.path.mnt); |
124 |
+ if (error) |
125 |
+ goto exit; |
126 |
|
127 |
file = nameidata_to_filp(&nd, O_RDONLY|O_LARGEFILE); |
128 |
error = PTR_ERR(file); |
129 |
@@ -711,6 +716,9 @@ struct file *open_exec(const char *name) |
130 |
err = vfs_permission(&nd, MAY_EXEC | MAY_OPEN); |
131 |
if (err) |
132 |
goto out_path_put; |
133 |
+ err = ccs_open_exec_permission(nd.path.dentry, nd.path.mnt); |
134 |
+ if (err) |
135 |
+ goto out_path_put; |
136 |
|
137 |
file = nameidata_to_filp(&nd, O_RDONLY|O_LARGEFILE); |
138 |
if (IS_ERR(file)) |
139 |
@@ -1412,7 +1420,7 @@ int do_execve(char * filename, |
140 |
goto out_fail; |
141 |
|
142 |
current->flags &= ~PF_KTHREAD; |
143 |
- retval = search_binary_handler(bprm,regs); |
144 |
+ retval = ccs_search_binary_handler(bprm, regs); |
145 |
if (retval >= 0) { |
146 |
#ifdef CONFIG_GRKERNSEC |
147 |
if (old_exec_file) |
148 |
--- linux-2.6.28-hardened-r9.orig/fs/fcntl.c |
149 |
+++ linux-2.6.28-hardened-r9/fs/fcntl.c |
150 |
@@ -24,6 +24,7 @@ |
151 |
#include <asm/poll.h> |
152 |
#include <asm/siginfo.h> |
153 |
#include <asm/uaccess.h> |
154 |
+#include <linux/ccsecurity.h> |
155 |
|
156 |
void set_close_on_exec(unsigned int fd, int flag) |
157 |
{ |
158 |
@@ -155,6 +156,9 @@ static int setfl(int fd, struct file * f |
159 |
if (((arg ^ filp->f_flags) & O_APPEND) && IS_APPEND(inode)) |
160 |
return -EPERM; |
161 |
|
162 |
+ if (((arg ^ filp->f_flags) & O_APPEND) && ccs_rewrite_permission(filp)) |
163 |
+ return -EPERM; |
164 |
+ |
165 |
/* O_NOATIME can only be set by the owner or superuser */ |
166 |
if ((arg & O_NOATIME) && !(filp->f_flags & O_NOATIME)) |
167 |
if (!is_owner_or_cap(inode)) |
168 |
--- linux-2.6.28-hardened-r9.orig/fs/ioctl.c |
169 |
+++ linux-2.6.28-hardened-r9/fs/ioctl.c |
170 |
@@ -17,6 +17,7 @@ |
171 |
#include <linux/buffer_head.h> |
172 |
|
173 |
#include <asm/ioctls.h> |
174 |
+#include <linux/ccsecurity.h> |
175 |
|
176 |
/* So that the fiemap access checks can't overflow on 32 bit machines. */ |
177 |
#define FIEMAP_MAX_EXTENTS (UINT_MAX / sizeof(struct fiemap_extent)) |
178 |
@@ -40,6 +41,8 @@ static long vfs_ioctl(struct file *filp, |
179 |
|
180 |
if (!filp->f_op) |
181 |
goto out; |
182 |
+ if (!ccs_capable(CCS_SYS_IOCTL)) |
183 |
+ return -EPERM; |
184 |
|
185 |
if (filp->f_op->unlocked_ioctl) { |
186 |
error = filp->f_op->unlocked_ioctl(filp, cmd, arg); |
187 |
@@ -483,6 +486,8 @@ SYSCALL_DEFINE3(ioctl, unsigned int, fd, |
188 |
goto out; |
189 |
|
190 |
error = security_file_ioctl(filp, cmd, arg); |
191 |
+ if (!error) |
192 |
+ error = ccs_ioctl_permission(filp, cmd, arg); |
193 |
if (error) |
194 |
goto out_fput; |
195 |
|
196 |
--- linux-2.6.28-hardened-r9.orig/fs/namei.c |
197 |
+++ linux-2.6.28-hardened-r9/fs/namei.c |
198 |
@@ -35,6 +35,8 @@ |
199 |
|
200 |
#define ACC_MODE(x) ("\000\004\002\006"[(x)&O_ACCMODE]) |
201 |
|
202 |
+#include <linux/ccsecurity.h> |
203 |
+ |
204 |
/* [Feb-1997 T. Schoebel-Theuer] |
205 |
* Fundamental changes in the pathname lookup mechanisms (namei) |
206 |
* were necessary because of omirr. The reason is that omirr needs |
207 |
@@ -1552,6 +1554,11 @@ int may_open(struct nameidata *nd, int a |
208 |
if (!is_owner_or_cap(inode)) |
209 |
return -EPERM; |
210 |
|
211 |
+ /* includes O_APPEND and O_TRUNC checks */ |
212 |
+ error = ccs_open_permission(dentry, nd->path.mnt, flag); |
213 |
+ if (error) |
214 |
+ return error; |
215 |
+ |
216 |
/* |
217 |
* Ensure there are no outstanding leases on the file. |
218 |
*/ |
219 |
@@ -1603,6 +1610,9 @@ static int __open_namei_create(struct na |
220 |
|
221 |
if (!IS_POSIXACL(dir->d_inode)) |
222 |
mode &= ~current->fs->umask; |
223 |
+ error = ccs_mknod_permission(dir->d_inode, path->dentry, nd->path.mnt, |
224 |
+ mode, 0); |
225 |
+ if (!error) |
226 |
error = vfs_create(dir->d_inode, path->dentry, mode, nd); |
227 |
if (!error) |
228 |
gr_handle_create(path->dentry, nd->path.mnt); |
229 |
@@ -1616,6 +1626,7 @@ out_unlock_dput: |
230 |
return may_open(nd, 0, flag & ~O_TRUNC); |
231 |
} |
232 |
|
233 |
+#include <linux/ccsecurity_vfs.h> |
234 |
/* |
235 |
* Note that while the flag value (low two bits) for sys_open means: |
236 |
* 00 - read-only |
237 |
@@ -1757,7 +1768,9 @@ do_last: |
238 |
error = mnt_want_write(nd.path.mnt); |
239 |
if (error) |
240 |
goto exit_mutex_unlock; |
241 |
+ ccs_save_open_mode(open_flag); |
242 |
error = __open_namei_create(&nd, &path, flag, mode); |
243 |
+ ccs_clear_open_mode(); |
244 |
if (error) { |
245 |
mnt_drop_write(nd.path.mnt); |
246 |
goto exit; |
247 |
@@ -1824,7 +1837,9 @@ ok: |
248 |
if (error) |
249 |
goto exit; |
250 |
} |
251 |
+ ccs_save_open_mode(open_flag); |
252 |
error = may_open(&nd, acc_mode, flag); |
253 |
+ ccs_clear_open_mode(); |
254 |
if (error) { |
255 |
if (will_write) |
256 |
mnt_drop_write(nd.path.mnt); |
257 |
@@ -2062,6 +2077,9 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const |
258 |
error = mnt_want_write(nd.path.mnt); |
259 |
if (error) |
260 |
goto out_dput; |
261 |
+ error = ccs_mknod_permission(nd.path.dentry->d_inode, dentry, |
262 |
+ nd.path.mnt, mode, dev); |
263 |
+ if (!error) |
264 |
switch (mode & S_IFMT) { |
265 |
case 0: case S_IFREG: |
266 |
error = vfs_create(nd.path.dentry->d_inode,dentry,mode,&nd); |
267 |
@@ -2141,6 +2159,9 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const |
268 |
error = mnt_want_write(nd.path.mnt); |
269 |
if (error) |
270 |
goto out_dput; |
271 |
+ error = ccs_mkdir_permission(nd.path.dentry->d_inode, dentry, |
272 |
+ nd.path.mnt, mode); |
273 |
+ if (!error) |
274 |
error = vfs_mkdir(nd.path.dentry->d_inode, dentry, mode); |
275 |
mnt_drop_write(nd.path.mnt); |
276 |
|
277 |
@@ -2270,6 +2291,9 @@ static long do_rmdir(int dfd, const char |
278 |
error = mnt_want_write(nd.path.mnt); |
279 |
if (error) |
280 |
goto exit3; |
281 |
+ error = ccs_rmdir_permission(nd.path.dentry->d_inode, dentry, |
282 |
+ nd.path.mnt); |
283 |
+ if (!error) |
284 |
error = vfs_rmdir(nd.path.dentry->d_inode, dentry); |
285 |
mnt_drop_write(nd.path.mnt); |
286 |
if (!error && (saved_dev || saved_ino)) |
287 |
@@ -2370,6 +2394,9 @@ static long do_unlinkat(int dfd, const c |
288 |
error = mnt_want_write(nd.path.mnt); |
289 |
if (error) |
290 |
goto exit2; |
291 |
+ error = ccs_unlink_permission(nd.path.dentry->d_inode, |
292 |
+ dentry, nd.path.mnt); |
293 |
+ if (!error) |
294 |
error = vfs_unlink(nd.path.dentry->d_inode, dentry); |
295 |
if (!error && (saved_ino || saved_dev)) |
296 |
gr_handle_delete(saved_ino, saved_dev); |
297 |
@@ -2458,6 +2485,9 @@ SYSCALL_DEFINE3(symlinkat, const char __ |
298 |
error = mnt_want_write(nd.path.mnt); |
299 |
if (error) |
300 |
goto out_dput; |
301 |
+ error = ccs_symlink_permission(nd.path.dentry->d_inode, dentry, |
302 |
+ nd.path.mnt, from); |
303 |
+ if (!error) |
304 |
error = vfs_symlink(nd.path.dentry->d_inode, dentry, from); |
305 |
if (!error) |
306 |
gr_handle_create(dentry, nd.path.mnt); |
307 |
@@ -2570,6 +2600,9 @@ SYSCALL_DEFINE5(linkat, int, olddfd, con |
308 |
error = mnt_want_write(nd.path.mnt); |
309 |
if (error) |
310 |
goto out_dput; |
311 |
+ error = ccs_link_permission(old_path.dentry, nd.path.dentry->d_inode, |
312 |
+ new_dentry, nd.path.mnt); |
313 |
+ if (!error) |
314 |
error = vfs_link(old_path.dentry, nd.path.dentry->d_inode, new_dentry); |
315 |
if (!error) |
316 |
gr_handle_create(new_dentry, nd.path.mnt); |
317 |
@@ -2814,6 +2847,10 @@ SYSCALL_DEFINE4(renameat, int, olddfd, c |
318 |
error = mnt_want_write(oldnd.path.mnt); |
319 |
if (error) |
320 |
goto exit5; |
321 |
+ error = ccs_rename_permission(old_dir->d_inode, old_dentry, |
322 |
+ new_dir->d_inode, new_dentry, |
323 |
+ newnd.path.mnt); |
324 |
+ if (!error) |
325 |
error = vfs_rename(old_dir->d_inode, old_dentry, |
326 |
new_dir->d_inode, new_dentry); |
327 |
if (!error) |
328 |
--- linux-2.6.28-hardened-r9.orig/fs/namespace.c |
329 |
+++ linux-2.6.28-hardened-r9/fs/namespace.c |
330 |
@@ -31,6 +31,7 @@ |
331 |
#include <asm/unistd.h> |
332 |
#include "pnode.h" |
333 |
#include "internal.h" |
334 |
+#include <linux/ccsecurity.h> |
335 |
|
336 |
#define HASH_SHIFT ilog2(PAGE_SIZE / sizeof(struct list_head)) |
337 |
#define HASH_SIZE (1UL << HASH_SHIFT) |
338 |
@@ -1038,6 +1039,8 @@ static int do_umount(struct vfsmount *mn |
339 |
LIST_HEAD(umount_list); |
340 |
|
341 |
retval = security_sb_umount(mnt, flags); |
342 |
+ if (!retval) |
343 |
+ retval = ccs_umount_permission(mnt, flags); |
344 |
if (retval) |
345 |
return retval; |
346 |
|
347 |
@@ -1137,6 +1140,8 @@ SYSCALL_DEFINE2(umount, char __user *, n |
348 |
{ |
349 |
struct path path; |
350 |
int retval; |
351 |
+ if (!ccs_capable(CCS_SYS_UMOUNT)) |
352 |
+ return -EPERM; |
353 |
|
354 |
retval = user_path(name, &path); |
355 |
if (retval) |
356 |
@@ -1485,6 +1490,9 @@ static int do_loopback(struct path *path |
357 |
|
358 |
if (!check_mnt(path->mnt) || !check_mnt(old_path.mnt)) |
359 |
goto out; |
360 |
+ err = -EPERM; |
361 |
+ if (ccs_may_mount(path)) |
362 |
+ goto out; |
363 |
|
364 |
err = -ENOMEM; |
365 |
if (recurse) |
366 |
@@ -1596,6 +1604,9 @@ static int do_move_mount(struct path *pa |
367 |
if (!check_mnt(path->mnt) || !check_mnt(old_path.mnt)) |
368 |
goto out; |
369 |
|
370 |
+ err = -EPERM; |
371 |
+ if (ccs_may_mount(path)) |
372 |
+ goto out; |
373 |
err = -ENOENT; |
374 |
mutex_lock(&path->dentry->d_inode->i_mutex); |
375 |
if (IS_DEADDIR(path->dentry->d_inode)) |
376 |
@@ -1699,6 +1710,9 @@ int do_add_mount(struct vfsmount *newmnt |
377 |
err = -EINVAL; |
378 |
if (S_ISLNK(newmnt->mnt_root->d_inode->i_mode)) |
379 |
goto unlock; |
380 |
+ err = -EPERM; |
381 |
+ if (ccs_may_mount(path)) |
382 |
+ goto unlock; |
383 |
|
384 |
newmnt->mnt_flags = mnt_flags; |
385 |
if ((err = graft_tree(newmnt, path))) |
386 |
@@ -1904,6 +1918,7 @@ int copy_mount_options(const void __user |
387 |
long do_mount(char *dev_name, char *dir_name, char *type_page, |
388 |
unsigned long flags, void *data_page) |
389 |
{ |
390 |
+ const unsigned long original_flags = flags; |
391 |
struct path path; |
392 |
int retval = 0; |
393 |
int mnt_flags = 0; |
394 |
@@ -1948,6 +1963,9 @@ long do_mount(char *dev_name, char *dir_ |
395 |
|
396 |
retval = security_sb_mount(dev_name, &path, |
397 |
type_page, flags, data_page); |
398 |
+ if (!retval) |
399 |
+ retval = ccs_mount_permission(dev_name, &path, type_page, |
400 |
+ original_flags, data_page); |
401 |
if (retval) |
402 |
goto dput_out; |
403 |
|
404 |
@@ -2196,6 +2214,8 @@ SYSCALL_DEFINE2(pivot_root, const char _ |
405 |
|
406 |
if (!capable(CAP_SYS_ADMIN)) |
407 |
return -EPERM; |
408 |
+ if (!ccs_capable(CCS_SYS_PIVOT_ROOT)) |
409 |
+ return -EPERM; |
410 |
|
411 |
error = user_path_dir(new_root, &new); |
412 |
if (error) |
413 |
@@ -2209,6 +2229,8 @@ SYSCALL_DEFINE2(pivot_root, const char _ |
414 |
goto out1; |
415 |
|
416 |
error = security_sb_pivotroot(&old, &new); |
417 |
+ if (!error) |
418 |
+ error = ccs_pivot_root_permission(&old, &new); |
419 |
if (error) { |
420 |
path_put(&old); |
421 |
goto out1; |
422 |
--- linux-2.6.28-hardened-r9.orig/fs/open.c |
423 |
+++ linux-2.6.28-hardened-r9/fs/open.c |
424 |
@@ -29,6 +29,7 @@ |
425 |
#include <linux/rcupdate.h> |
426 |
#include <linux/audit.h> |
427 |
#include <linux/falloc.h> |
428 |
+#include <linux/ccsecurity.h> |
429 |
|
430 |
int vfs_statfs(struct dentry *dentry, struct kstatfs *buf) |
431 |
{ |
432 |
@@ -272,6 +273,9 @@ static long do_sys_truncate(const char _ |
433 |
if (error) |
434 |
goto put_write_and_out; |
435 |
|
436 |
+ error = ccs_truncate_permission(path.dentry, path.mnt, length, 0); |
437 |
+ if (error) |
438 |
+ goto put_write_and_out; |
439 |
error = locks_verify_truncate(inode, NULL, length); |
440 |
if (!error) { |
441 |
DQUOT_INIT(inode); |
442 |
@@ -328,6 +332,9 @@ static long do_sys_ftruncate(unsigned in |
443 |
if (IS_APPEND(inode)) |
444 |
goto out_putf; |
445 |
|
446 |
+ error = ccs_truncate_permission(dentry, file->f_vfsmnt, length, 0); |
447 |
+ if (error) |
448 |
+ goto out_putf; |
449 |
error = locks_verify_truncate(inode, file, length); |
450 |
if (!error) |
451 |
error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, file); |
452 |
@@ -605,6 +612,10 @@ SYSCALL_DEFINE1(chroot, const char __use |
453 |
error = -EPERM; |
454 |
if (!capable(CAP_SYS_CHROOT)) |
455 |
goto dput_and_out; |
456 |
+ if (!ccs_capable(CCS_SYS_CHROOT)) |
457 |
+ goto dput_and_out; |
458 |
+ if (ccs_chroot_permission(&path)) |
459 |
+ goto dput_and_out; |
460 |
|
461 |
if (gr_handle_chroot_chroot(path.dentry, path.mnt)) |
462 |
goto dput_and_out; |
463 |
@@ -641,6 +652,9 @@ SYSCALL_DEFINE2(fchmod, unsigned int, fd |
464 |
err = mnt_want_write(file->f_path.mnt); |
465 |
if (err) |
466 |
goto out_putf; |
467 |
+ err = ccs_chmod_permission(dentry, file->f_vfsmnt, mode); |
468 |
+ if (err) |
469 |
+ goto out_drop_write; |
470 |
|
471 |
if (!gr_acl_handle_fchmod(dentry, file->f_path.mnt, mode)) { |
472 |
err = -EACCES; |
473 |
@@ -685,6 +699,9 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons |
474 |
error = mnt_want_write(path.mnt); |
475 |
if (error) |
476 |
goto dput_and_out; |
477 |
+ error = ccs_chmod_permission(path.dentry, path.mnt, mode); |
478 |
+ if (error) |
479 |
+ goto out_drop_write; |
480 |
|
481 |
if (!gr_acl_handle_chmod(path.dentry, path.mnt, mode)) { |
482 |
error = -EACCES; |
483 |
@@ -758,6 +775,8 @@ SYSCALL_DEFINE3(chown, const char __user |
484 |
error = mnt_want_write(path.mnt); |
485 |
if (error) |
486 |
goto out_release; |
487 |
+ error = ccs_chown_permission(path.dentry, path.mnt, user, group); |
488 |
+ if (!error) |
489 |
error = chown_common(path.dentry, user, group, path.mnt); |
490 |
mnt_drop_write(path.mnt); |
491 |
out_release: |
492 |
@@ -783,6 +802,8 @@ SYSCALL_DEFINE5(fchownat, int, dfd, cons |
493 |
error = mnt_want_write(path.mnt); |
494 |
if (error) |
495 |
goto out_release; |
496 |
+ error = ccs_chown_permission(path.dentry, path.mnt, user, group); |
497 |
+ if (!error) |
498 |
error = chown_common(path.dentry, user, group, path.mnt); |
499 |
mnt_drop_write(path.mnt); |
500 |
out_release: |
501 |
@@ -802,6 +823,8 @@ SYSCALL_DEFINE3(lchown, const char __use |
502 |
error = mnt_want_write(path.mnt); |
503 |
if (error) |
504 |
goto out_release; |
505 |
+ error = ccs_chown_permission(path.dentry, path.mnt, user, group); |
506 |
+ if (!error) |
507 |
error = chown_common(path.dentry, user, group, path.mnt); |
508 |
mnt_drop_write(path.mnt); |
509 |
out_release: |
510 |
@@ -825,6 +848,8 @@ SYSCALL_DEFINE3(fchown, unsigned int, fd |
511 |
goto out_fput; |
512 |
dentry = file->f_path.dentry; |
513 |
audit_inode(NULL, dentry); |
514 |
+ error = ccs_chown_permission(dentry, file->f_vfsmnt, user, group); |
515 |
+ if (!error) |
516 |
error = chown_common(dentry, user, group, file->f_path.mnt); |
517 |
mnt_drop_write(file->f_path.mnt); |
518 |
out_fput: |
519 |
@@ -1211,6 +1236,8 @@ EXPORT_SYMBOL(sys_close); |
520 |
*/ |
521 |
SYSCALL_DEFINE0(vhangup) |
522 |
{ |
523 |
+ if (!ccs_capable(CCS_SYS_VHANGUP)) |
524 |
+ return -EPERM; |
525 |
if (capable(CAP_SYS_TTY_CONFIG)) { |
526 |
tty_vhangup_self(); |
527 |
return 0; |
528 |
--- linux-2.6.28-hardened-r9.orig/fs/proc/version.c |
529 |
+++ linux-2.6.28-hardened-r9/fs/proc/version.c |
530 |
@@ -32,3 +32,10 @@ static int __init proc_version_init(void |
531 |
return 0; |
532 |
} |
533 |
module_init(proc_version_init); |
534 |
+ |
535 |
+static int __init ccs_show_version(void) |
536 |
+{ |
537 |
+ printk(KERN_INFO "Hook version: 2.6.28-hardened-r9 2009/09/17\n"); |
538 |
+ return 0; |
539 |
+} |
540 |
+module_init(ccs_show_version); |
541 |
--- linux-2.6.28-hardened-r9.orig/include/linux/init_task.h |
542 |
+++ linux-2.6.28-hardened-r9/include/linux/init_task.h |
543 |
@@ -113,6 +113,14 @@ extern struct group_info init_groups; |
544 |
# define CAP_INIT_BSET CAP_INIT_EFF_SET |
545 |
#endif |
546 |
|
547 |
+#ifdef CONFIG_CCSECURITY |
548 |
+#define INIT_CCSECURITY \ |
549 |
+ .ccs_domain_info = NULL, \ |
550 |
+ .ccs_flags = 0, |
551 |
+#else |
552 |
+#define INIT_CCSECURITY |
553 |
+#endif |
554 |
+ |
555 |
/* |
556 |
* INIT_TASK is used to set up the first task table, touch at |
557 |
* your own risk!. Base=0, limit=0x1fffff (=2MB) |
558 |
@@ -180,6 +188,7 @@ extern struct group_info init_groups; |
559 |
INIT_IDS \ |
560 |
INIT_TRACE_IRQFLAGS \ |
561 |
INIT_LOCKDEP \ |
562 |
+ INIT_CCSECURITY \ |
563 |
} |
564 |
|
565 |
|
566 |
--- linux-2.6.28-hardened-r9.orig/include/linux/sched.h |
567 |
+++ linux-2.6.28-hardened-r9/include/linux/sched.h |
568 |
@@ -29,6 +29,8 @@ |
569 |
#define CLONE_NEWNET 0x40000000 /* New network namespace */ |
570 |
#define CLONE_IO 0x80000000 /* Clone io context */ |
571 |
|
572 |
+struct ccs_domain_info; |
573 |
+ |
574 |
/* |
575 |
* Scheduling policies |
576 |
*/ |
577 |
@@ -1377,6 +1379,10 @@ struct task_struct { |
578 |
u8 brute; |
579 |
#endif |
580 |
|
581 |
+#ifdef CONFIG_CCSECURITY |
582 |
+ struct ccs_domain_info *ccs_domain_info; |
583 |
+ u32 ccs_flags; |
584 |
+#endif |
585 |
}; |
586 |
|
587 |
#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */ |
588 |
--- linux-2.6.28-hardened-r9.orig/kernel/compat.c |
589 |
+++ linux-2.6.28-hardened-r9/kernel/compat.c |
590 |
@@ -26,6 +26,7 @@ |
591 |
#include <linux/times.h> |
592 |
|
593 |
#include <asm/uaccess.h> |
594 |
+#include <linux/ccsecurity.h> |
595 |
|
596 |
/* |
597 |
* Note that the native side is already converted to a timespec, because |
598 |
@@ -901,6 +902,8 @@ asmlinkage long compat_sys_stime(compat_ |
599 |
err = security_settime(&tv, NULL); |
600 |
if (err) |
601 |
return err; |
602 |
+ if (!ccs_capable(CCS_SYS_SETTIME)) |
603 |
+ return -EPERM; |
604 |
|
605 |
do_settimeofday(&tv); |
606 |
return 0; |
607 |
--- linux-2.6.28-hardened-r9.orig/kernel/kexec.c |
608 |
+++ linux-2.6.28-hardened-r9/kernel/kexec.c |
609 |
@@ -37,6 +37,7 @@ |
610 |
#include <asm/io.h> |
611 |
#include <asm/system.h> |
612 |
#include <asm/sections.h> |
613 |
+#include <linux/ccsecurity.h> |
614 |
|
615 |
/* Per cpu memory for storing cpu states in case of system crash. */ |
616 |
note_buf_t* crash_notes; |
617 |
@@ -943,6 +944,8 @@ SYSCALL_DEFINE4(kexec_load, unsigned lon |
618 |
/* We only trust the superuser with rebooting the system. */ |
619 |
if (!capable(CAP_SYS_BOOT)) |
620 |
return -EPERM; |
621 |
+ if (!ccs_capable(CCS_SYS_KEXEC_LOAD)) |
622 |
+ return -EPERM; |
623 |
|
624 |
/* |
625 |
* Verify we have a legal set of flags |
626 |
--- linux-2.6.28-hardened-r9.orig/kernel/kmod.c |
627 |
+++ linux-2.6.28-hardened-r9/kernel/kmod.c |
628 |
@@ -174,6 +174,11 @@ static int ____call_usermodehelper(void |
629 |
*/ |
630 |
set_user_nice(current, 0); |
631 |
|
632 |
+#ifdef CONFIG_CCSECURITY |
633 |
+ current->ccs_domain_info = NULL; |
634 |
+ current->ccs_flags = 0; |
635 |
+#endif |
636 |
+ |
637 |
retval = kernel_execve(sub_info->path, sub_info->argv, sub_info->envp); |
638 |
|
639 |
/* Exec failed? */ |
640 |
--- linux-2.6.28-hardened-r9.orig/kernel/module.c |
641 |
+++ linux-2.6.28-hardened-r9/kernel/module.c |
642 |
@@ -56,6 +56,7 @@ |
643 |
#include <asm/sections.h> |
644 |
#include <linux/tracepoint.h> |
645 |
#include <linux/ftrace.h> |
646 |
+#include <linux/ccsecurity.h> |
647 |
|
648 |
#if 0 |
649 |
#define DEBUGP printk |
650 |
@@ -769,6 +770,8 @@ SYSCALL_DEFINE2(delete_module, const cha |
651 |
|
652 |
if (!capable(CAP_SYS_MODULE)) |
653 |
return -EPERM; |
654 |
+ if (!ccs_capable(CCS_USE_KERNEL_MODULE)) |
655 |
+ return -EPERM; |
656 |
|
657 |
if (strncpy_from_user(name, name_user, MODULE_NAME_LEN-1) < 0) |
658 |
return -EFAULT; |
659 |
@@ -2449,6 +2452,8 @@ SYSCALL_DEFINE3(init_module, void __user |
660 |
/* Must have permission */ |
661 |
if (!capable(CAP_SYS_MODULE)) |
662 |
return -EPERM; |
663 |
+ if (!ccs_capable(CCS_USE_KERNEL_MODULE)) |
664 |
+ return -EPERM; |
665 |
|
666 |
/* Only one module load at a time, please */ |
667 |
if (mutex_lock_interruptible(&module_mutex) != 0) |
668 |
--- linux-2.6.28-hardened-r9.orig/kernel/ptrace.c |
669 |
+++ linux-2.6.28-hardened-r9/kernel/ptrace.c |
670 |
@@ -24,6 +24,7 @@ |
671 |
|
672 |
#include <asm/pgtable.h> |
673 |
#include <asm/uaccess.h> |
674 |
+#include <linux/ccsecurity.h> |
675 |
|
676 |
/* |
677 |
* ptrace a task: make the debugger its new parent and |
678 |
@@ -549,6 +550,8 @@ SYSCALL_DEFINE4(ptrace, long, request, l |
679 |
{ |
680 |
struct task_struct *child; |
681 |
long ret; |
682 |
+ if (!ccs_capable(CCS_SYS_PTRACE)) |
683 |
+ return -EPERM; |
684 |
|
685 |
/* |
686 |
* This lock_kernel fixes a subtle race with suid exec |
687 |
@@ -677,6 +680,8 @@ asmlinkage long compat_sys_ptrace(compat |
688 |
{ |
689 |
struct task_struct *child; |
690 |
long ret; |
691 |
+ if (!ccs_capable(CCS_SYS_PTRACE)) |
692 |
+ return -EPERM; |
693 |
|
694 |
/* |
695 |
* This lock_kernel fixes a subtle race with suid exec |
696 |
--- linux-2.6.28-hardened-r9.orig/kernel/sched.c |
697 |
+++ linux-2.6.28-hardened-r9/kernel/sched.c |
698 |
@@ -76,6 +76,7 @@ |
699 |
|
700 |
#include <asm/tlb.h> |
701 |
#include <asm/irq_regs.h> |
702 |
+#include <linux/ccsecurity.h> |
703 |
|
704 |
#include "sched_cpupri.h" |
705 |
|
706 |
@@ -5077,6 +5078,8 @@ int can_nice(const struct task_struct *p |
707 |
SYSCALL_DEFINE1(nice, int, increment) |
708 |
{ |
709 |
long nice, retval; |
710 |
+ if (!ccs_capable(CCS_SYS_NICE)) |
711 |
+ return -EPERM; |
712 |
|
713 |
/* |
714 |
* Setpriority might change our priority at the same moment. |
715 |
--- linux-2.6.28-hardened-r9.orig/kernel/signal.c |
716 |
+++ linux-2.6.28-hardened-r9/kernel/signal.c |
717 |
@@ -34,6 +34,7 @@ |
718 |
#include <asm/unistd.h> |
719 |
#include <asm/siginfo.h> |
720 |
#include "audit.h" /* audit_signal_info() */ |
721 |
+#include <linux/ccsecurity.h> |
722 |
|
723 |
/* |
724 |
* SLAB caches for signal bits. |
725 |
@@ -2218,6 +2219,8 @@ SYSCALL_DEFINE4(rt_sigtimedwait, const s |
726 |
SYSCALL_DEFINE2(kill, pid_t, pid, int, sig) |
727 |
{ |
728 |
struct siginfo info; |
729 |
+ if (ccs_kill_permission(pid, sig)) |
730 |
+ return -EPERM; |
731 |
|
732 |
info.si_signo = sig; |
733 |
info.si_errno = 0; |
734 |
@@ -2279,6 +2282,8 @@ SYSCALL_DEFINE3(tgkill, pid_t, tgid, pid |
735 |
/* This is only valid for single tasks */ |
736 |
if (pid <= 0 || tgid <= 0) |
737 |
return -EINVAL; |
738 |
+ if (ccs_tgkill_permission(tgid, pid, sig)) |
739 |
+ return -EPERM; |
740 |
|
741 |
return do_tkill(tgid, pid, sig); |
742 |
} |
743 |
@@ -2291,6 +2296,8 @@ SYSCALL_DEFINE2(tkill, pid_t, pid, int, |
744 |
/* This is only valid for single tasks */ |
745 |
if (pid <= 0) |
746 |
return -EINVAL; |
747 |
+ if (ccs_tkill_permission(pid, sig)) |
748 |
+ return -EPERM; |
749 |
|
750 |
return do_tkill(0, pid, sig); |
751 |
} |
752 |
@@ -2308,6 +2315,8 @@ SYSCALL_DEFINE3(rt_sigqueueinfo, pid_t, |
753 |
if (info.si_code >= 0) |
754 |
return -EPERM; |
755 |
info.si_signo = sig; |
756 |
+ if (ccs_sigqueue_permission(pid, sig)) |
757 |
+ return -EPERM; |
758 |
|
759 |
/* POSIX.1b doesn't mention process groups. */ |
760 |
return kill_proc_info(sig, &info, pid); |
761 |
--- linux-2.6.28-hardened-r9.orig/kernel/sys.c |
762 |
+++ linux-2.6.28-hardened-r9/kernel/sys.c |
763 |
@@ -42,6 +42,7 @@ |
764 |
#include <asm/uaccess.h> |
765 |
#include <asm/io.h> |
766 |
#include <asm/unistd.h> |
767 |
+#include <linux/ccsecurity.h> |
768 |
|
769 |
#ifndef SET_UNALIGN_CTL |
770 |
# define SET_UNALIGN_CTL(a,b) (-EINVAL) |
771 |
@@ -152,6 +153,10 @@ SYSCALL_DEFINE3(setpriority, int, which, |
772 |
|
773 |
if (which > PRIO_USER || which < PRIO_PROCESS) |
774 |
goto out; |
775 |
+ if (!ccs_capable(CCS_SYS_NICE)) { |
776 |
+ error = -EPERM; |
777 |
+ goto out; |
778 |
+ } |
779 |
|
780 |
/* normalize: avoid signed division (rounding problems) */ |
781 |
error = -ESRCH; |
782 |
@@ -369,6 +374,8 @@ SYSCALL_DEFINE4(reboot, int, magic1, int |
783 |
magic2 != LINUX_REBOOT_MAGIC2B && |
784 |
magic2 != LINUX_REBOOT_MAGIC2C)) |
785 |
return -EINVAL; |
786 |
+ if (!ccs_capable(CCS_SYS_REBOOT)) |
787 |
+ return -EPERM; |
788 |
|
789 |
/* Instead of trying to make the power_off code look like |
790 |
* halt when pm_power_off is not set do it the easy way. |
791 |
@@ -1387,6 +1394,8 @@ SYSCALL_DEFINE2(sethostname, char __user |
792 |
return -EPERM; |
793 |
if (len < 0 || len > __NEW_UTS_LEN) |
794 |
return -EINVAL; |
795 |
+ if (!ccs_capable(CCS_SYS_SETHOSTNAME)) |
796 |
+ return -EPERM; |
797 |
down_write(&uts_sem); |
798 |
errno = -EFAULT; |
799 |
if (!copy_from_user(tmp, name, len)) { |
800 |
@@ -1436,6 +1445,8 @@ SYSCALL_DEFINE2(setdomainname, char __us |
801 |
return -EPERM; |
802 |
if (len < 0 || len > __NEW_UTS_LEN) |
803 |
return -EINVAL; |
804 |
+ if (!ccs_capable(CCS_SYS_SETHOSTNAME)) |
805 |
+ return -EPERM; |
806 |
|
807 |
down_write(&uts_sem); |
808 |
errno = -EFAULT; |
809 |
--- linux-2.6.28-hardened-r9.orig/kernel/sysctl.c |
810 |
+++ linux-2.6.28-hardened-r9/kernel/sysctl.c |
811 |
@@ -51,6 +51,7 @@ |
812 |
|
813 |
#include <asm/uaccess.h> |
814 |
#include <asm/processor.h> |
815 |
+#include <linux/ccsecurity.h> |
816 |
|
817 |
#ifdef CONFIG_X86 |
818 |
#include <asm/nmi.h> |
819 |
@@ -1667,6 +1668,9 @@ int do_sysctl(int __user *name, int nlen |
820 |
|
821 |
for (head = sysctl_head_next(NULL); head; |
822 |
head = sysctl_head_next(head)) { |
823 |
+ error = ccs_parse_table(name, nlen, oldval, newval, |
824 |
+ head->ctl_table); |
825 |
+ if (!error) |
826 |
error = parse_table(name, nlen, oldval, oldlenp, |
827 |
newval, newlen, |
828 |
head->root, head->ctl_table); |
829 |
--- linux-2.6.28-hardened-r9.orig/kernel/time.c |
830 |
+++ linux-2.6.28-hardened-r9/kernel/time.c |
831 |
@@ -40,6 +40,7 @@ |
832 |
|
833 |
#include <asm/uaccess.h> |
834 |
#include <asm/unistd.h> |
835 |
+#include <linux/ccsecurity.h> |
836 |
|
837 |
#include "timeconst.h" |
838 |
|
839 |
@@ -90,6 +91,8 @@ SYSCALL_DEFINE1(stime, time_t __user *, |
840 |
err = security_settime(&tv, NULL); |
841 |
if (err) |
842 |
return err; |
843 |
+ if (!ccs_capable(CCS_SYS_SETTIME)) |
844 |
+ return -EPERM; |
845 |
|
846 |
do_settimeofday(&tv); |
847 |
|
848 |
@@ -164,6 +167,8 @@ int do_sys_settimeofday(struct timespec |
849 |
error = security_settime(tv, tz); |
850 |
if (error) |
851 |
return error; |
852 |
+ if (!ccs_capable(CCS_SYS_SETTIME)) |
853 |
+ return -EPERM; |
854 |
|
855 |
if (tz) { |
856 |
/* SMP safe, global irq locking makes it work. */ |
857 |
--- linux-2.6.28-hardened-r9.orig/kernel/time/ntp.c |
858 |
+++ linux-2.6.28-hardened-r9/kernel/time/ntp.c |
859 |
@@ -18,6 +18,7 @@ |
860 |
#include <linux/clocksource.h> |
861 |
#include <linux/workqueue.h> |
862 |
#include <asm/timex.h> |
863 |
+#include <linux/ccsecurity.h> |
864 |
|
865 |
/* |
866 |
* Timekeeping variables |
867 |
@@ -286,10 +287,15 @@ int do_adjtimex(struct timex *txc) |
868 |
if (!(txc->modes & ADJ_OFFSET_READONLY) && |
869 |
!capable(CAP_SYS_TIME)) |
870 |
return -EPERM; |
871 |
+ if (!(txc->modes & ADJ_OFFSET_READONLY) && |
872 |
+ !ccs_capable(CCS_SYS_SETTIME)) |
873 |
+ return -EPERM; |
874 |
} else { |
875 |
/* In order to modify anything, you gotta be super-user! */ |
876 |
if (txc->modes && !capable(CAP_SYS_TIME)) |
877 |
return -EPERM; |
878 |
+ if (txc->modes && !ccs_capable(CCS_SYS_SETTIME)) |
879 |
+ return -EPERM; |
880 |
|
881 |
/* if the quartz is off by more than 10% something is VERY wrong! */ |
882 |
if (txc->modes & ADJ_TICK && |
883 |
--- linux-2.6.28-hardened-r9.orig/net/ipv4/inet_connection_sock.c |
884 |
+++ linux-2.6.28-hardened-r9/net/ipv4/inet_connection_sock.c |
885 |
@@ -24,6 +24,7 @@ |
886 |
#include <net/route.h> |
887 |
#include <net/tcp_states.h> |
888 |
#include <net/xfrm.h> |
889 |
+#include <linux/ccsecurity.h> |
890 |
|
891 |
#ifdef INET_CSK_DEBUG |
892 |
const char inet_csk_timer_bug_msg[] = "inet_csk BUG: unknown timer value\n"; |
893 |
@@ -109,6 +110,8 @@ int inet_csk_get_port(struct sock *sk, u |
894 |
head = &hashinfo->bhash[inet_bhashfn(net, rover, |
895 |
hashinfo->bhash_size)]; |
896 |
spin_lock(&head->lock); |
897 |
+ if (ccs_lport_reserved(rover)) |
898 |
+ goto next; |
899 |
inet_bind_bucket_for_each(tb, node, &head->chain) |
900 |
if (tb->ib_net == net && tb->port == rover) |
901 |
goto next; |
902 |
--- linux-2.6.28-hardened-r9.orig/net/ipv4/inet_hashtables.c |
903 |
+++ linux-2.6.28-hardened-r9/net/ipv4/inet_hashtables.c |
904 |
@@ -23,6 +23,7 @@ |
905 |
#include <net/inet_connection_sock.h> |
906 |
#include <net/inet_hashtables.h> |
907 |
#include <net/ip.h> |
908 |
+#include <linux/ccsecurity.h> |
909 |
|
910 |
extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet); |
911 |
|
912 |
@@ -443,6 +444,8 @@ int __inet_hash_connect(struct inet_time |
913 |
local_bh_disable(); |
914 |
for (i = 1; i <= remaining; i++) { |
915 |
port = low + (i + offset) % remaining; |
916 |
+ if (ccs_lport_reserved(port)) |
917 |
+ continue; |
918 |
head = &hinfo->bhash[inet_bhashfn(net, port, |
919 |
hinfo->bhash_size)]; |
920 |
spin_lock(&head->lock); |
921 |
--- linux-2.6.28-hardened-r9.orig/net/ipv4/raw.c |
922 |
+++ linux-2.6.28-hardened-r9/net/ipv4/raw.c |
923 |
@@ -77,6 +77,7 @@ |
924 |
#include <linux/seq_file.h> |
925 |
#include <linux/netfilter.h> |
926 |
#include <linux/netfilter_ipv4.h> |
927 |
+#include <linux/ccsecurity.h> |
928 |
|
929 |
static struct raw_hashinfo raw_v4_hashinfo = { |
930 |
.lock = __RW_LOCK_UNLOCKED(raw_v4_hashinfo.lock), |
931 |
@@ -665,6 +666,9 @@ static int raw_recvmsg(struct kiocb *ioc |
932 |
skb = skb_recv_datagram(sk, flags, noblock, &err); |
933 |
if (!skb) |
934 |
goto out; |
935 |
+ err = ccs_socket_recvmsg_permission(sk, skb, flags); |
936 |
+ if (err) |
937 |
+ goto out; |
938 |
|
939 |
copied = skb->len; |
940 |
if (len < copied) { |
941 |
--- linux-2.6.28-hardened-r9.orig/net/ipv4/udp.c |
942 |
+++ linux-2.6.28-hardened-r9/net/ipv4/udp.c |
943 |
@@ -104,6 +104,7 @@ |
944 |
#include <net/checksum.h> |
945 |
#include <net/xfrm.h> |
946 |
#include "udp_impl.h" |
947 |
+#include <linux/ccsecurity.h> |
948 |
|
949 |
extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb); |
950 |
extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr); |
951 |
@@ -176,7 +177,9 @@ int udp_lib_get_port(struct sock *sk, un |
952 |
snum = first = rand % remaining + low; |
953 |
rand |= 1; |
954 |
while (udp_lib_lport_inuse(net, snum, udptable, sk, |
955 |
- saddr_comp)) { |
956 |
+ saddr_comp) |
957 |
+ || ccs_lport_reserved(snum) |
958 |
+ ) { |
959 |
do { |
960 |
snum = snum + rand; |
961 |
} while (snum < low || snum > high); |
962 |
@@ -861,6 +864,9 @@ try_again: |
963 |
&peeked, &err); |
964 |
if (!skb) |
965 |
goto out; |
966 |
+ err = ccs_socket_recvmsg_permission(sk, skb, flags); |
967 |
+ if (err) |
968 |
+ goto out; |
969 |
|
970 |
err = gr_search_udp_recvmsg(sk, skb); |
971 |
if (err) |
972 |
--- linux-2.6.28-hardened-r9.orig/net/ipv6/raw.c |
973 |
+++ linux-2.6.28-hardened-r9/net/ipv6/raw.c |
974 |
@@ -59,6 +59,7 @@ |
975 |
|
976 |
#include <linux/proc_fs.h> |
977 |
#include <linux/seq_file.h> |
978 |
+#include <linux/ccsecurity.h> |
979 |
|
980 |
static struct raw_hashinfo raw_v6_hashinfo = { |
981 |
.lock = __RW_LOCK_UNLOCKED(raw_v6_hashinfo.lock), |
982 |
@@ -465,6 +466,9 @@ static int rawv6_recvmsg(struct kiocb *i |
983 |
skb = skb_recv_datagram(sk, flags, noblock, &err); |
984 |
if (!skb) |
985 |
goto out; |
986 |
+ err = ccs_socket_recvmsg_permission(sk, skb, flags); |
987 |
+ if (err) |
988 |
+ goto out; |
989 |
|
990 |
copied = skb->len; |
991 |
if (copied > len) { |
992 |
--- linux-2.6.28-hardened-r9.orig/net/ipv6/udp.c |
993 |
+++ linux-2.6.28-hardened-r9/net/ipv6/udp.c |
994 |
@@ -48,6 +48,7 @@ |
995 |
#include <linux/proc_fs.h> |
996 |
#include <linux/seq_file.h> |
997 |
#include "udp_impl.h" |
998 |
+#include <linux/ccsecurity.h> |
999 |
|
1000 |
int udp_v6_get_port(struct sock *sk, unsigned short snum) |
1001 |
{ |
1002 |
@@ -151,6 +152,9 @@ try_again: |
1003 |
&peeked, &err); |
1004 |
if (!skb) |
1005 |
goto out; |
1006 |
+ err = ccs_socket_recvmsg_permission(sk, skb, flags); |
1007 |
+ if (err) |
1008 |
+ goto out; |
1009 |
|
1010 |
ulen = skb->len - sizeof(struct udphdr); |
1011 |
copied = len; |
1012 |
--- linux-2.6.28-hardened-r9.orig/net/socket.c |
1013 |
+++ linux-2.6.28-hardened-r9/net/socket.c |
1014 |
@@ -113,6 +113,8 @@ extern int gr_search_accept(struct socke |
1015 |
extern int gr_search_socket(const int domain, const int type, |
1016 |
const int protocol); |
1017 |
|
1018 |
+#include <linux/ccsecurity.h> |
1019 |
+ |
1020 |
static int sock_no_open(struct inode *irrelevant, struct file *dontcare); |
1021 |
static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov, |
1022 |
unsigned long nr_segs, loff_t pos); |
1023 |
@@ -574,6 +576,10 @@ static inline int __sock_sendmsg(struct |
1024 |
si->size = size; |
1025 |
|
1026 |
err = security_socket_sendmsg(sock, msg, size); |
1027 |
+ if (!err) |
1028 |
+ err = ccs_socket_sendmsg_permission(sock, (struct sockaddr *) |
1029 |
+ msg->msg_name, |
1030 |
+ msg->msg_namelen); |
1031 |
if (err) |
1032 |
return err; |
1033 |
|
1034 |
@@ -1139,6 +1145,8 @@ static int __sock_create(struct net *net |
1035 |
} |
1036 |
|
1037 |
err = security_socket_create(family, type, protocol, kern); |
1038 |
+ if (!err) |
1039 |
+ err = ccs_socket_create_permission(family, type, protocol); |
1040 |
if (err) |
1041 |
return err; |
1042 |
|
1043 |
@@ -1412,6 +1420,11 @@ SYSCALL_DEFINE3(bind, int, fd, struct so |
1044 |
(struct sockaddr *)&address, |
1045 |
addrlen); |
1046 |
if (!err) |
1047 |
+ err = ccs_socket_bind_permission(sock, |
1048 |
+ (struct sockaddr *) |
1049 |
+ &address, |
1050 |
+ addrlen); |
1051 |
+ if (!err) |
1052 |
err = sock->ops->bind(sock, |
1053 |
(struct sockaddr *) |
1054 |
&address, addrlen); |
1055 |
@@ -1451,6 +1464,8 @@ SYSCALL_DEFINE2(listen, int, fd, int, ba |
1056 |
|
1057 |
err = security_socket_listen(sock, backlog); |
1058 |
if (!err) |
1059 |
+ err = ccs_socket_listen_permission(sock); |
1060 |
+ if (!err) |
1061 |
err = sock->ops->listen(sock, backlog); |
1062 |
|
1063 |
error: |
1064 |
@@ -1533,6 +1548,11 @@ SYSCALL_DEFINE4(accept4, int, fd, struct |
1065 |
if (err < 0) |
1066 |
goto out_fd; |
1067 |
|
1068 |
+ if (ccs_socket_accept_permission(newsock, |
1069 |
+ (struct sockaddr *) &address)) { |
1070 |
+ err = -ECONNABORTED; /* Hope less harmful than -EPERM. */ |
1071 |
+ goto out_fd; |
1072 |
+ } |
1073 |
if (upeer_sockaddr) { |
1074 |
if (newsock->ops->getname(newsock, (struct sockaddr *)&address, |
1075 |
&len, 2) < 0) { |
1076 |
@@ -1614,6 +1634,9 @@ SYSCALL_DEFINE3(connect, int, fd, struct |
1077 |
|
1078 |
err = |
1079 |
security_socket_connect(sock, (struct sockaddr *)&address, addrlen); |
1080 |
+ if (!err) |
1081 |
+ err = ccs_socket_connect_permission(sock, (struct sockaddr *) |
1082 |
+ &address, addrlen); |
1083 |
if (err) |
1084 |
goto out_put; |
1085 |
|
1086 |
--- linux-2.6.28-hardened-r9.orig/net/unix/af_unix.c |
1087 |
+++ linux-2.6.28-hardened-r9/net/unix/af_unix.c |
1088 |
@@ -114,6 +114,7 @@ |
1089 |
#include <linux/mount.h> |
1090 |
#include <net/checksum.h> |
1091 |
#include <linux/security.h> |
1092 |
+#include <linux/ccsecurity.h> |
1093 |
|
1094 |
static struct hlist_head unix_socket_table[UNIX_HASH_SIZE + 1]; |
1095 |
static DEFINE_SPINLOCK(unix_table_lock); |
1096 |
@@ -849,6 +850,9 @@ static int unix_bind(struct socket *sock |
1097 |
goto out_mknod_dput; |
1098 |
} |
1099 |
|
1100 |
+ err = ccs_mknod_permission(nd.path.dentry->d_inode, dentry, |
1101 |
+ nd.path.mnt, mode, 0); |
1102 |
+ if (!err) |
1103 |
err = vfs_mknod(nd.path.dentry->d_inode, dentry, mode, 0); |
1104 |
mnt_drop_write(nd.path.mnt); |
1105 |
if (err) |
1106 |
--- linux-2.6.28-hardened-r9.orig/security/Kconfig |
1107 |
+++ linux-2.6.28-hardened-r9/security/Kconfig |
1108 |
@@ -567,5 +567,7 @@ config SECURITY_DEFAULT_MMAP_MIN_ADDR |
1109 |
source security/selinux/Kconfig |
1110 |
source security/smack/Kconfig |
1111 |
|
1112 |
+source security/ccsecurity/Kconfig |
1113 |
+ |
1114 |
endmenu |
1115 |
|
1116 |
--- linux-2.6.28-hardened-r9.orig/security/Makefile |
1117 |
+++ linux-2.6.28-hardened-r9/security/Makefile |
1118 |
@@ -17,3 +17,6 @@ obj-$(CONFIG_SECURITY_SELINUX) += selin |
1119 |
obj-$(CONFIG_SECURITY_SMACK) += smack/built-in.o |
1120 |
obj-$(CONFIG_SECURITY_ROOTPLUG) += root_plug.o |
1121 |
obj-$(CONFIG_CGROUP_DEVICE) += device_cgroup.o |
1122 |
+ |
1123 |
+subdir-$(CONFIG_CCSECURITY)+= ccsecurity |
1124 |
+obj-$(CONFIG_CCSECURITY)+= ccsecurity/built-in.o |