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