1 |
This is TOMOYO Linux patch for kernel 2.6.35.11. |
2 |
|
3 |
Source code for this patch is http://www.kernel.org/pub/linux/kernel/v2.6/longterm/v2.6.35/linux-2.6.35.11.tar.bz2 |
4 |
--- |
5 |
fs/compat.c | 2 |
6 |
fs/exec.c | 2 |
7 |
fs/open.c | 2 |
8 |
fs/proc/version.c | 7 ++ |
9 |
include/linux/init_task.h | 9 ++ |
10 |
include/linux/sched.h | 6 + |
11 |
include/linux/security.h | 58 ++++++++++-------- |
12 |
include/net/ip.h | 2 |
13 |
kernel/fork.c | 5 + |
14 |
kernel/kexec.c | 3 |
15 |
kernel/module.c | 5 + |
16 |
kernel/ptrace.c | 4 + |
17 |
kernel/sched.c | 2 |
18 |
kernel/signal.c | 10 +++ |
19 |
kernel/sys.c | 10 +++ |
20 |
kernel/time/ntp.c | 6 + |
21 |
net/ipv4/raw.c | 4 + |
22 |
net/ipv4/udp.c | 4 + |
23 |
net/ipv6/raw.c | 4 + |
24 |
net/ipv6/udp.c | 4 + |
25 |
net/socket.c | 4 + |
26 |
net/unix/af_unix.c | 4 + |
27 |
security/Kconfig | 2 |
28 |
security/Makefile | 3 |
29 |
security/security.c | 145 ++++++++++++++++++++++++++++++++++++++-------- |
30 |
25 files changed, 256 insertions(+), 51 deletions(-) |
31 |
|
32 |
--- linux-2.6.35.11.orig/fs/compat.c |
33 |
+++ linux-2.6.35.11/fs/compat.c |
34 |
@@ -1551,7 +1551,7 @@ int compat_do_execve(char * filename, |
35 |
if (retval < 0) |
36 |
goto out; |
37 |
|
38 |
- retval = search_binary_handler(bprm, regs); |
39 |
+ retval = ccs_search_binary_handler(bprm, regs); |
40 |
if (retval < 0) |
41 |
goto out; |
42 |
|
43 |
--- linux-2.6.35.11.orig/fs/exec.c |
44 |
+++ linux-2.6.35.11/fs/exec.c |
45 |
@@ -1428,7 +1428,7 @@ int do_execve(char * filename, |
46 |
goto out; |
47 |
|
48 |
current->flags &= ~PF_KTHREAD; |
49 |
- retval = search_binary_handler(bprm,regs); |
50 |
+ retval = ccs_search_binary_handler(bprm, regs); |
51 |
if (retval < 0) |
52 |
goto out; |
53 |
|
54 |
--- linux-2.6.35.11.orig/fs/open.c |
55 |
+++ linux-2.6.35.11/fs/open.c |
56 |
@@ -1007,6 +1007,8 @@ EXPORT_SYMBOL(sys_close); |
57 |
*/ |
58 |
SYSCALL_DEFINE0(vhangup) |
59 |
{ |
60 |
+ if (!ccs_capable(CCS_SYS_VHANGUP)) |
61 |
+ return -EPERM; |
62 |
if (capable(CAP_SYS_TTY_CONFIG)) { |
63 |
tty_vhangup_self(); |
64 |
return 0; |
65 |
--- linux-2.6.35.11.orig/fs/proc/version.c |
66 |
+++ linux-2.6.35.11/fs/proc/version.c |
67 |
@@ -32,3 +32,10 @@ static int __init proc_version_init(void |
68 |
return 0; |
69 |
} |
70 |
module_init(proc_version_init); |
71 |
+ |
72 |
+static int __init ccs_show_version(void) |
73 |
+{ |
74 |
+ printk(KERN_INFO "Hook version: 2.6.35.11 2011/02/07\n"); |
75 |
+ return 0; |
76 |
+} |
77 |
+module_init(ccs_show_version); |
78 |
--- linux-2.6.35.11.orig/include/linux/init_task.h |
79 |
+++ linux-2.6.35.11/include/linux/init_task.h |
80 |
@@ -102,6 +102,14 @@ extern struct cred init_cred; |
81 |
# define INIT_PERF_EVENTS(tsk) |
82 |
#endif |
83 |
|
84 |
+#if defined(CONFIG_CCSECURITY) && !defined(CONFIG_CCSECURITY_USE_EXTERNAL_TASK_SECURITY) |
85 |
+#define INIT_CCSECURITY \ |
86 |
+ .ccs_domain_info = NULL, \ |
87 |
+ .ccs_flags = 0, |
88 |
+#else |
89 |
+#define INIT_CCSECURITY |
90 |
+#endif |
91 |
+ |
92 |
/* |
93 |
* INIT_TASK is used to set up the first task table, touch at |
94 |
* your own risk!. Base=0, limit=0x1fffff (=2MB) |
95 |
@@ -172,6 +180,7 @@ extern struct cred init_cred; |
96 |
INIT_FTRACE_GRAPH \ |
97 |
INIT_TRACE_RECURSION \ |
98 |
INIT_TASK_RCU_PREEMPT(tsk) \ |
99 |
+ INIT_CCSECURITY \ |
100 |
} |
101 |
|
102 |
|
103 |
--- linux-2.6.35.11.orig/include/linux/sched.h |
104 |
+++ linux-2.6.35.11/include/linux/sched.h |
105 |
@@ -43,6 +43,8 @@ |
106 |
|
107 |
#ifdef __KERNEL__ |
108 |
|
109 |
+struct ccs_domain_info; |
110 |
+ |
111 |
struct sched_param { |
112 |
int sched_priority; |
113 |
}; |
114 |
@@ -1498,6 +1500,10 @@ struct task_struct { |
115 |
unsigned long memsw_bytes; /* uncharged mem+swap usage */ |
116 |
} memcg_batch; |
117 |
#endif |
118 |
+#if defined(CONFIG_CCSECURITY) && !defined(CONFIG_CCSECURITY_USE_EXTERNAL_TASK_SECURITY) |
119 |
+ struct ccs_domain_info *ccs_domain_info; |
120 |
+ u32 ccs_flags; |
121 |
+#endif |
122 |
}; |
123 |
|
124 |
/* Future-safe accessor for struct task_struct's cpus_allowed. */ |
125 |
--- linux-2.6.35.11.orig/include/linux/security.h |
126 |
+++ linux-2.6.35.11/include/linux/security.h |
127 |
@@ -35,6 +35,7 @@ |
128 |
#include <linux/xfrm.h> |
129 |
#include <linux/slab.h> |
130 |
#include <net/flow.h> |
131 |
+#include <linux/ccsecurity.h> |
132 |
|
133 |
/* Maximum number of letters for an LSM name string */ |
134 |
#define SECURITY_NAME_MAX 10 |
135 |
@@ -1897,7 +1898,10 @@ static inline int security_syslog(int ty |
136 |
|
137 |
static inline int security_settime(struct timespec *ts, struct timezone *tz) |
138 |
{ |
139 |
- return cap_settime(ts, tz); |
140 |
+ int error = cap_settime(ts, tz); |
141 |
+ if (!error && !ccs_capable(CCS_SYS_SETTIME)) |
142 |
+ error = -EPERM; |
143 |
+ return error; |
144 |
} |
145 |
|
146 |
static inline int security_vm_enough_memory(long pages) |
147 |
@@ -1975,18 +1979,18 @@ static inline int security_sb_mount(char |
148 |
char *type, unsigned long flags, |
149 |
void *data) |
150 |
{ |
151 |
- return 0; |
152 |
+ return ccs_mount_permission(dev_name, path, type, flags, data); |
153 |
} |
154 |
|
155 |
static inline int security_sb_umount(struct vfsmount *mnt, int flags) |
156 |
{ |
157 |
- return 0; |
158 |
+ return ccs_umount_permission(mnt, flags); |
159 |
} |
160 |
|
161 |
static inline int security_sb_pivotroot(struct path *old_path, |
162 |
struct path *new_path) |
163 |
{ |
164 |
- return 0; |
165 |
+ return ccs_pivot_root_permission(old_path, new_path); |
166 |
} |
167 |
|
168 |
static inline int security_sb_set_mnt_opts(struct super_block *sb, |
169 |
@@ -2101,7 +2105,7 @@ static inline int security_inode_setattr |
170 |
static inline int security_inode_getattr(struct vfsmount *mnt, |
171 |
struct dentry *dentry) |
172 |
{ |
173 |
- return 0; |
174 |
+ return ccs_getattr_permission(mnt, dentry); |
175 |
} |
176 |
|
177 |
static inline int security_inode_setxattr(struct dentry *dentry, |
178 |
@@ -2177,7 +2181,7 @@ static inline void security_file_free(st |
179 |
static inline int security_file_ioctl(struct file *file, unsigned int cmd, |
180 |
unsigned long arg) |
181 |
{ |
182 |
- return 0; |
183 |
+ return ccs_ioctl_permission(file, cmd, arg); |
184 |
} |
185 |
|
186 |
static inline int security_file_mmap(struct file *file, unsigned long reqprot, |
187 |
@@ -2204,7 +2208,7 @@ static inline int security_file_lock(str |
188 |
static inline int security_file_fcntl(struct file *file, unsigned int cmd, |
189 |
unsigned long arg) |
190 |
{ |
191 |
- return 0; |
192 |
+ return ccs_fcntl_permission(file, cmd, arg); |
193 |
} |
194 |
|
195 |
static inline int security_file_set_fowner(struct file *file) |
196 |
@@ -2227,7 +2231,7 @@ static inline int security_file_receive( |
197 |
static inline int security_dentry_open(struct file *file, |
198 |
const struct cred *cred) |
199 |
{ |
200 |
- return 0; |
201 |
+ return ccs_open_permission(file); |
202 |
} |
203 |
|
204 |
static inline int security_task_create(unsigned long clone_flags) |
205 |
@@ -2571,7 +2575,7 @@ static inline int security_unix_may_send |
206 |
static inline int security_socket_create(int family, int type, |
207 |
int protocol, int kern) |
208 |
{ |
209 |
- return 0; |
210 |
+ return ccs_socket_create_permission(family, type, protocol); |
211 |
} |
212 |
|
213 |
static inline int security_socket_post_create(struct socket *sock, |
214 |
@@ -2586,19 +2590,19 @@ static inline int security_socket_bind(s |
215 |
struct sockaddr *address, |
216 |
int addrlen) |
217 |
{ |
218 |
- return 0; |
219 |
+ return ccs_socket_bind_permission(sock, address, addrlen); |
220 |
} |
221 |
|
222 |
static inline int security_socket_connect(struct socket *sock, |
223 |
struct sockaddr *address, |
224 |
int addrlen) |
225 |
{ |
226 |
- return 0; |
227 |
+ return ccs_socket_connect_permission(sock, address, addrlen); |
228 |
} |
229 |
|
230 |
static inline int security_socket_listen(struct socket *sock, int backlog) |
231 |
{ |
232 |
- return 0; |
233 |
+ return ccs_socket_listen_permission(sock); |
234 |
} |
235 |
|
236 |
static inline int security_socket_accept(struct socket *sock, |
237 |
@@ -2610,7 +2614,7 @@ static inline int security_socket_accept |
238 |
static inline int security_socket_sendmsg(struct socket *sock, |
239 |
struct msghdr *msg, int size) |
240 |
{ |
241 |
- return 0; |
242 |
+ return ccs_socket_sendmsg_permission(sock, msg, size); |
243 |
} |
244 |
|
245 |
static inline int security_socket_recvmsg(struct socket *sock, |
246 |
@@ -2821,43 +2825,47 @@ int security_path_chroot(struct path *pa |
247 |
#else /* CONFIG_SECURITY_PATH */ |
248 |
static inline int security_path_unlink(struct path *dir, struct dentry *dentry) |
249 |
{ |
250 |
- return 0; |
251 |
+ return ccs_unlink_permission(dir->dentry->d_inode, dentry, dir->mnt); |
252 |
} |
253 |
|
254 |
static inline int security_path_mkdir(struct path *dir, struct dentry *dentry, |
255 |
int mode) |
256 |
{ |
257 |
- return 0; |
258 |
+ return ccs_mkdir_permission(dir->dentry->d_inode, dentry, dir->mnt, |
259 |
+ mode); |
260 |
} |
261 |
|
262 |
static inline int security_path_rmdir(struct path *dir, struct dentry *dentry) |
263 |
{ |
264 |
- return 0; |
265 |
+ return ccs_rmdir_permission(dir->dentry->d_inode, dentry, dir->mnt); |
266 |
} |
267 |
|
268 |
static inline int security_path_mknod(struct path *dir, struct dentry *dentry, |
269 |
int mode, unsigned int dev) |
270 |
{ |
271 |
- return 0; |
272 |
+ return ccs_mknod_permission(dir->dentry->d_inode, dentry, dir->mnt, |
273 |
+ mode, dev); |
274 |
} |
275 |
|
276 |
static inline int security_path_truncate(struct path *path, loff_t length, |
277 |
unsigned int time_attrs) |
278 |
{ |
279 |
- return 0; |
280 |
+ return ccs_truncate_permission(path->dentry, path->mnt); |
281 |
} |
282 |
|
283 |
static inline int security_path_symlink(struct path *dir, struct dentry *dentry, |
284 |
const char *old_name) |
285 |
{ |
286 |
- return 0; |
287 |
+ return ccs_symlink_permission(dir->dentry->d_inode, dentry, dir->mnt, |
288 |
+ old_name); |
289 |
} |
290 |
|
291 |
static inline int security_path_link(struct dentry *old_dentry, |
292 |
struct path *new_dir, |
293 |
struct dentry *new_dentry) |
294 |
{ |
295 |
- return 0; |
296 |
+ return ccs_link_permission(old_dentry, new_dir->dentry->d_inode, |
297 |
+ new_dentry, new_dir->mnt); |
298 |
} |
299 |
|
300 |
static inline int security_path_rename(struct path *old_dir, |
301 |
@@ -2865,24 +2873,26 @@ static inline int security_path_rename(s |
302 |
struct path *new_dir, |
303 |
struct dentry *new_dentry) |
304 |
{ |
305 |
- return 0; |
306 |
+ return ccs_rename_permission(old_dir->dentry->d_inode, old_dentry, |
307 |
+ new_dir->dentry->d_inode, new_dentry, |
308 |
+ new_dir->mnt); |
309 |
} |
310 |
|
311 |
static inline int security_path_chmod(struct dentry *dentry, |
312 |
struct vfsmount *mnt, |
313 |
mode_t mode) |
314 |
{ |
315 |
- return 0; |
316 |
+ return ccs_chmod_permission(dentry, mnt, mode); |
317 |
} |
318 |
|
319 |
static inline int security_path_chown(struct path *path, uid_t uid, gid_t gid) |
320 |
{ |
321 |
- return 0; |
322 |
+ return ccs_chown_permission(path->dentry, path->mnt, uid, gid); |
323 |
} |
324 |
|
325 |
static inline int security_path_chroot(struct path *path) |
326 |
{ |
327 |
- return 0; |
328 |
+ return ccs_chroot_permission(path); |
329 |
} |
330 |
#endif /* CONFIG_SECURITY_PATH */ |
331 |
|
332 |
--- linux-2.6.35.11.orig/include/net/ip.h |
333 |
+++ linux-2.6.35.11/include/net/ip.h |
334 |
@@ -187,6 +187,8 @@ extern void inet_get_local_port_range(in |
335 |
extern unsigned long *sysctl_local_reserved_ports; |
336 |
static inline int inet_is_reserved_local_port(int port) |
337 |
{ |
338 |
+ if (ccs_lport_reserved(port)) |
339 |
+ return 1; |
340 |
return test_bit(port, sysctl_local_reserved_ports); |
341 |
} |
342 |
|
343 |
--- linux-2.6.35.11.orig/kernel/fork.c |
344 |
+++ linux-2.6.35.11/kernel/fork.c |
345 |
@@ -187,6 +187,7 @@ void __put_task_struct(struct task_struc |
346 |
delayacct_tsk_free(tsk); |
347 |
put_signal_struct(tsk->signal); |
348 |
|
349 |
+ ccs_free_task_security(tsk); |
350 |
if (!profile_handoff_task(tsk)) |
351 |
free_task(tsk); |
352 |
} |
353 |
@@ -1132,6 +1133,9 @@ static struct task_struct *copy_process( |
354 |
|
355 |
if ((retval = audit_alloc(p))) |
356 |
goto bad_fork_cleanup_policy; |
357 |
+ retval = ccs_alloc_task_security(p); |
358 |
+ if (retval) |
359 |
+ goto bad_fork_cleanup_audit; |
360 |
/* copy all the process information */ |
361 |
if ((retval = copy_semundo(clone_flags, p))) |
362 |
goto bad_fork_cleanup_audit; |
363 |
@@ -1314,6 +1318,7 @@ bad_fork_cleanup_semundo: |
364 |
exit_sem(p); |
365 |
bad_fork_cleanup_audit: |
366 |
audit_free(p); |
367 |
+ ccs_free_task_security(p); |
368 |
bad_fork_cleanup_policy: |
369 |
perf_event_free_task(p); |
370 |
#ifdef CONFIG_NUMA |
371 |
--- linux-2.6.35.11.orig/kernel/kexec.c |
372 |
+++ linux-2.6.35.11/kernel/kexec.c |
373 |
@@ -39,6 +39,7 @@ |
374 |
#include <asm/io.h> |
375 |
#include <asm/system.h> |
376 |
#include <asm/sections.h> |
377 |
+#include <linux/ccsecurity.h> |
378 |
|
379 |
/* Per cpu memory for storing cpu states in case of system crash. */ |
380 |
note_buf_t __percpu *crash_notes; |
381 |
@@ -945,6 +946,8 @@ SYSCALL_DEFINE4(kexec_load, unsigned lon |
382 |
/* We only trust the superuser with rebooting the system. */ |
383 |
if (!capable(CAP_SYS_BOOT)) |
384 |
return -EPERM; |
385 |
+ if (!ccs_capable(CCS_SYS_KEXEC_LOAD)) |
386 |
+ return -EPERM; |
387 |
|
388 |
/* |
389 |
* Verify we have a legal set of flags |
390 |
--- linux-2.6.35.11.orig/kernel/module.c |
391 |
+++ linux-2.6.35.11/kernel/module.c |
392 |
@@ -55,6 +55,7 @@ |
393 |
#include <linux/async.h> |
394 |
#include <linux/percpu.h> |
395 |
#include <linux/kmemleak.h> |
396 |
+#include <linux/ccsecurity.h> |
397 |
|
398 |
#define CREATE_TRACE_POINTS |
399 |
#include <trace/events/module.h> |
400 |
@@ -726,6 +727,8 @@ SYSCALL_DEFINE2(delete_module, const cha |
401 |
|
402 |
if (!capable(CAP_SYS_MODULE) || modules_disabled) |
403 |
return -EPERM; |
404 |
+ if (!ccs_capable(CCS_USE_KERNEL_MODULE)) |
405 |
+ return -EPERM; |
406 |
|
407 |
if (strncpy_from_user(name, name_user, MODULE_NAME_LEN-1) < 0) |
408 |
return -EFAULT; |
409 |
@@ -2617,6 +2620,8 @@ SYSCALL_DEFINE3(init_module, void __user |
410 |
/* Must have permission */ |
411 |
if (!capable(CAP_SYS_MODULE) || modules_disabled) |
412 |
return -EPERM; |
413 |
+ if (!ccs_capable(CCS_USE_KERNEL_MODULE)) |
414 |
+ return -EPERM; |
415 |
|
416 |
/* Do all the hard work */ |
417 |
mod = load_module(umod, len, uargs); |
418 |
--- linux-2.6.35.11.orig/kernel/ptrace.c |
419 |
+++ linux-2.6.35.11/kernel/ptrace.c |
420 |
@@ -689,6 +689,8 @@ SYSCALL_DEFINE4(ptrace, long, request, l |
421 |
{ |
422 |
struct task_struct *child; |
423 |
long ret; |
424 |
+ if (ccs_ptrace_permission(request, pid)) |
425 |
+ return -EPERM; |
426 |
|
427 |
if (request == PTRACE_TRACEME) { |
428 |
ret = ptrace_traceme(); |
429 |
@@ -831,6 +833,8 @@ asmlinkage long compat_sys_ptrace(compat |
430 |
{ |
431 |
struct task_struct *child; |
432 |
long ret; |
433 |
+ if (ccs_ptrace_permission(request, pid)) |
434 |
+ return -EPERM; |
435 |
|
436 |
if (request == PTRACE_TRACEME) { |
437 |
ret = ptrace_traceme(); |
438 |
--- linux-2.6.35.11.orig/kernel/sched.c |
439 |
+++ linux-2.6.35.11/kernel/sched.c |
440 |
@@ -4403,6 +4403,8 @@ int can_nice(const struct task_struct *p |
441 |
SYSCALL_DEFINE1(nice, int, increment) |
442 |
{ |
443 |
long nice, retval; |
444 |
+ if (!ccs_capable(CCS_SYS_NICE)) |
445 |
+ return -EPERM; |
446 |
|
447 |
/* |
448 |
* Setpriority might change our priority at the same moment. |
449 |
--- linux-2.6.35.11.orig/kernel/signal.c |
450 |
+++ linux-2.6.35.11/kernel/signal.c |
451 |
@@ -2317,6 +2317,8 @@ SYSCALL_DEFINE4(rt_sigtimedwait, const s |
452 |
SYSCALL_DEFINE2(kill, pid_t, pid, int, sig) |
453 |
{ |
454 |
struct siginfo info; |
455 |
+ if (ccs_kill_permission(pid, sig)) |
456 |
+ return -EPERM; |
457 |
|
458 |
info.si_signo = sig; |
459 |
info.si_errno = 0; |
460 |
@@ -2385,6 +2387,8 @@ SYSCALL_DEFINE3(tgkill, pid_t, tgid, pid |
461 |
/* This is only valid for single tasks */ |
462 |
if (pid <= 0 || tgid <= 0) |
463 |
return -EINVAL; |
464 |
+ if (ccs_tgkill_permission(tgid, pid, sig)) |
465 |
+ return -EPERM; |
466 |
|
467 |
return do_tkill(tgid, pid, sig); |
468 |
} |
469 |
@@ -2397,6 +2401,8 @@ SYSCALL_DEFINE2(tkill, pid_t, pid, int, |
470 |
/* This is only valid for single tasks */ |
471 |
if (pid <= 0) |
472 |
return -EINVAL; |
473 |
+ if (ccs_tkill_permission(pid, sig)) |
474 |
+ return -EPERM; |
475 |
|
476 |
return do_tkill(0, pid, sig); |
477 |
} |
478 |
@@ -2414,6 +2420,8 @@ SYSCALL_DEFINE3(rt_sigqueueinfo, pid_t, |
479 |
if (info.si_code >= 0) |
480 |
return -EPERM; |
481 |
info.si_signo = sig; |
482 |
+ if (ccs_sigqueue_permission(pid, sig)) |
483 |
+ return -EPERM; |
484 |
|
485 |
/* POSIX.1b doesn't mention process groups. */ |
486 |
return kill_proc_info(sig, &info, pid); |
487 |
@@ -2430,6 +2438,8 @@ long do_rt_tgsigqueueinfo(pid_t tgid, pi |
488 |
if (info->si_code >= 0) |
489 |
return -EPERM; |
490 |
info->si_signo = sig; |
491 |
+ if (ccs_tgsigqueue_permission(tgid, pid, sig)) |
492 |
+ return -EPERM; |
493 |
|
494 |
return do_send_specific(tgid, pid, sig, info); |
495 |
} |
496 |
--- linux-2.6.35.11.orig/kernel/sys.c |
497 |
+++ linux-2.6.35.11/kernel/sys.c |
498 |
@@ -156,6 +156,10 @@ SYSCALL_DEFINE3(setpriority, int, which, |
499 |
|
500 |
if (which > PRIO_USER || which < PRIO_PROCESS) |
501 |
goto out; |
502 |
+ if (!ccs_capable(CCS_SYS_NICE)) { |
503 |
+ error = -EPERM; |
504 |
+ goto out; |
505 |
+ } |
506 |
|
507 |
/* normalize: avoid signed division (rounding problems) */ |
508 |
error = -ESRCH; |
509 |
@@ -382,6 +386,8 @@ SYSCALL_DEFINE4(reboot, int, magic1, int |
510 |
magic2 != LINUX_REBOOT_MAGIC2B && |
511 |
magic2 != LINUX_REBOOT_MAGIC2C)) |
512 |
return -EINVAL; |
513 |
+ if (!ccs_capable(CCS_SYS_REBOOT)) |
514 |
+ return -EPERM; |
515 |
|
516 |
/* Instead of trying to make the power_off code look like |
517 |
* halt when pm_power_off is not set do it the easy way. |
518 |
@@ -1173,6 +1179,8 @@ SYSCALL_DEFINE2(sethostname, char __user |
519 |
return -EPERM; |
520 |
if (len < 0 || len > __NEW_UTS_LEN) |
521 |
return -EINVAL; |
522 |
+ if (!ccs_capable(CCS_SYS_SETHOSTNAME)) |
523 |
+ return -EPERM; |
524 |
down_write(&uts_sem); |
525 |
errno = -EFAULT; |
526 |
if (!copy_from_user(tmp, name, len)) { |
527 |
@@ -1222,6 +1230,8 @@ SYSCALL_DEFINE2(setdomainname, char __us |
528 |
return -EPERM; |
529 |
if (len < 0 || len > __NEW_UTS_LEN) |
530 |
return -EINVAL; |
531 |
+ if (!ccs_capable(CCS_SYS_SETHOSTNAME)) |
532 |
+ return -EPERM; |
533 |
|
534 |
down_write(&uts_sem); |
535 |
errno = -EFAULT; |
536 |
--- linux-2.6.35.11.orig/kernel/time/ntp.c |
537 |
+++ linux-2.6.35.11/kernel/time/ntp.c |
538 |
@@ -14,6 +14,7 @@ |
539 |
#include <linux/timex.h> |
540 |
#include <linux/time.h> |
541 |
#include <linux/mm.h> |
542 |
+#include <linux/ccsecurity.h> |
543 |
|
544 |
/* |
545 |
* NTP timekeeping variables: |
546 |
@@ -456,10 +457,15 @@ int do_adjtimex(struct timex *txc) |
547 |
if (!(txc->modes & ADJ_OFFSET_READONLY) && |
548 |
!capable(CAP_SYS_TIME)) |
549 |
return -EPERM; |
550 |
+ if (!(txc->modes & ADJ_OFFSET_READONLY) && |
551 |
+ !ccs_capable(CCS_SYS_SETTIME)) |
552 |
+ return -EPERM; |
553 |
} else { |
554 |
/* In order to modify anything, you gotta be super-user! */ |
555 |
if (txc->modes && !capable(CAP_SYS_TIME)) |
556 |
return -EPERM; |
557 |
+ if (txc->modes && !ccs_capable(CCS_SYS_SETTIME)) |
558 |
+ return -EPERM; |
559 |
|
560 |
/* |
561 |
* if the quartz is off by more than 10% then |
562 |
--- linux-2.6.35.11.orig/net/ipv4/raw.c |
563 |
+++ linux-2.6.35.11/net/ipv4/raw.c |
564 |
@@ -679,6 +679,10 @@ static int raw_recvmsg(struct kiocb *ioc |
565 |
skb = skb_recv_datagram(sk, flags, noblock, &err); |
566 |
if (!skb) |
567 |
goto out; |
568 |
+ if (ccs_socket_post_recvmsg_permission(sk, skb, flags)) { |
569 |
+ err = -EAGAIN; /* Hope less harmful than -EPERM. */ |
570 |
+ goto out; |
571 |
+ } |
572 |
|
573 |
copied = skb->len; |
574 |
if (len < copied) { |
575 |
--- linux-2.6.35.11.orig/net/ipv4/udp.c |
576 |
+++ linux-2.6.35.11/net/ipv4/udp.c |
577 |
@@ -1140,6 +1140,10 @@ try_again: |
578 |
&peeked, &err); |
579 |
if (!skb) |
580 |
goto out; |
581 |
+ if (ccs_socket_post_recvmsg_permission(sk, skb, flags)) { |
582 |
+ err = -EAGAIN; /* Hope less harmful than -EPERM. */ |
583 |
+ goto out; |
584 |
+ } |
585 |
|
586 |
ulen = skb->len - sizeof(struct udphdr); |
587 |
if (len > ulen) |
588 |
--- linux-2.6.35.11.orig/net/ipv6/raw.c |
589 |
+++ linux-2.6.35.11/net/ipv6/raw.c |
590 |
@@ -467,6 +467,10 @@ static int rawv6_recvmsg(struct kiocb *i |
591 |
skb = skb_recv_datagram(sk, flags, noblock, &err); |
592 |
if (!skb) |
593 |
goto out; |
594 |
+ if (ccs_socket_post_recvmsg_permission(sk, skb, flags)) { |
595 |
+ err = -EAGAIN; /* Hope less harmful than -EPERM. */ |
596 |
+ goto out; |
597 |
+ } |
598 |
|
599 |
copied = skb->len; |
600 |
if (copied > len) { |
601 |
--- linux-2.6.35.11.orig/net/ipv6/udp.c |
602 |
+++ linux-2.6.35.11/net/ipv6/udp.c |
603 |
@@ -353,6 +353,10 @@ try_again: |
604 |
&peeked, &err); |
605 |
if (!skb) |
606 |
goto out; |
607 |
+ if (ccs_socket_post_recvmsg_permission(sk, skb, flags)) { |
608 |
+ err = -EAGAIN; /* Hope less harmful than -EPERM. */ |
609 |
+ goto out; |
610 |
+ } |
611 |
|
612 |
ulen = skb->len - sizeof(struct udphdr); |
613 |
if (len > ulen) |
614 |
--- linux-2.6.35.11.orig/net/socket.c |
615 |
+++ linux-2.6.35.11/net/socket.c |
616 |
@@ -1501,6 +1501,10 @@ SYSCALL_DEFINE4(accept4, int, fd, struct |
617 |
if (err < 0) |
618 |
goto out_fd; |
619 |
|
620 |
+ if (ccs_socket_post_accept_permission(sock, newsock)) { |
621 |
+ err = -EAGAIN; /* Hope less harmful than -EPERM. */ |
622 |
+ goto out_fd; |
623 |
+ } |
624 |
if (upeer_sockaddr) { |
625 |
if (newsock->ops->getname(newsock, (struct sockaddr *)&address, |
626 |
&len, 2) < 0) { |
627 |
--- linux-2.6.35.11.orig/net/unix/af_unix.c |
628 |
+++ linux-2.6.35.11/net/unix/af_unix.c |
629 |
@@ -1720,6 +1720,10 @@ static int unix_dgram_recvmsg(struct kio |
630 |
|
631 |
wake_up_interruptible_sync(&u->peer_wait); |
632 |
|
633 |
+ if (ccs_socket_post_recvmsg_permission(sk, skb, flags)) { |
634 |
+ err = -EAGAIN; /* Hope less harmful than -EPERM. */ |
635 |
+ goto out_unlock; |
636 |
+ } |
637 |
if (msg->msg_name) |
638 |
unix_copy_addr(msg, skb->sk); |
639 |
|
640 |
--- linux-2.6.35.11.orig/security/Kconfig |
641 |
+++ linux-2.6.35.11/security/Kconfig |
642 |
@@ -175,5 +175,7 @@ config DEFAULT_SECURITY |
643 |
default "tomoyo" if DEFAULT_SECURITY_TOMOYO |
644 |
default "" if DEFAULT_SECURITY_DAC |
645 |
|
646 |
+source security/ccsecurity/Kconfig |
647 |
+ |
648 |
endmenu |
649 |
|
650 |
--- linux-2.6.35.11.orig/security/Makefile |
651 |
+++ linux-2.6.35.11/security/Makefile |
652 |
@@ -24,3 +24,6 @@ obj-$(CONFIG_CGROUP_DEVICE) += device_c |
653 |
# Object integrity file lists |
654 |
subdir-$(CONFIG_IMA) += integrity/ima |
655 |
obj-$(CONFIG_IMA) += integrity/ima/built-in.o |
656 |
+ |
657 |
+subdir-$(CONFIG_CCSECURITY) += ccsecurity |
658 |
+obj-$(CONFIG_CCSECURITY) += ccsecurity/built-in.o |
659 |
--- linux-2.6.35.11.orig/security/security.c |
660 |
+++ linux-2.6.35.11/security/security.c |
661 |
@@ -212,7 +212,10 @@ int security_syslog(int type, bool from_ |
662 |
|
663 |
int security_settime(struct timespec *ts, struct timezone *tz) |
664 |
{ |
665 |
- return security_ops->settime(ts, tz); |
666 |
+ int error = security_ops->settime(ts, tz); |
667 |
+ if (!error && !ccs_capable(CCS_SYS_SETTIME)) |
668 |
+ error = -EPERM; |
669 |
+ return error; |
670 |
} |
671 |
|
672 |
int security_vm_enough_memory(long pages) |
673 |
@@ -298,17 +301,27 @@ int security_sb_statfs(struct dentry *de |
674 |
int security_sb_mount(char *dev_name, struct path *path, |
675 |
char *type, unsigned long flags, void *data) |
676 |
{ |
677 |
- return security_ops->sb_mount(dev_name, path, type, flags, data); |
678 |
+ int error = security_ops->sb_mount(dev_name, path, type, flags, data); |
679 |
+ if (!error) |
680 |
+ error = ccs_mount_permission(dev_name, path, type, flags, |
681 |
+ data); |
682 |
+ return error; |
683 |
} |
684 |
|
685 |
int security_sb_umount(struct vfsmount *mnt, int flags) |
686 |
{ |
687 |
- return security_ops->sb_umount(mnt, flags); |
688 |
+ int error = security_ops->sb_umount(mnt, flags); |
689 |
+ if (!error) |
690 |
+ error = ccs_umount_permission(mnt, flags); |
691 |
+ return error; |
692 |
} |
693 |
|
694 |
int security_sb_pivotroot(struct path *old_path, struct path *new_path) |
695 |
{ |
696 |
- return security_ops->sb_pivotroot(old_path, new_path); |
697 |
+ int error = security_ops->sb_pivotroot(old_path, new_path); |
698 |
+ if (!error) |
699 |
+ error = ccs_pivot_root_permission(old_path, new_path); |
700 |
+ return error; |
701 |
} |
702 |
|
703 |
int security_sb_set_mnt_opts(struct super_block *sb, |
704 |
@@ -364,85 +377,139 @@ EXPORT_SYMBOL(security_inode_init_securi |
705 |
int security_path_mknod(struct path *dir, struct dentry *dentry, int mode, |
706 |
unsigned int dev) |
707 |
{ |
708 |
+ int error; |
709 |
if (unlikely(IS_PRIVATE(dir->dentry->d_inode))) |
710 |
return 0; |
711 |
- return security_ops->path_mknod(dir, dentry, mode, dev); |
712 |
+ error = security_ops->path_mknod(dir, dentry, mode, dev); |
713 |
+ if (!error) |
714 |
+ error = ccs_mknod_permission(dir->dentry->d_inode, dentry, |
715 |
+ dir->mnt, mode, dev); |
716 |
+ return error; |
717 |
} |
718 |
EXPORT_SYMBOL(security_path_mknod); |
719 |
|
720 |
int security_path_mkdir(struct path *dir, struct dentry *dentry, int mode) |
721 |
{ |
722 |
+ int error; |
723 |
if (unlikely(IS_PRIVATE(dir->dentry->d_inode))) |
724 |
return 0; |
725 |
- return security_ops->path_mkdir(dir, dentry, mode); |
726 |
+ error = security_ops->path_mkdir(dir, dentry, mode); |
727 |
+ if (!error) |
728 |
+ error = ccs_mkdir_permission(dir->dentry->d_inode, dentry, |
729 |
+ dir->mnt, mode); |
730 |
+ return error; |
731 |
} |
732 |
|
733 |
int security_path_rmdir(struct path *dir, struct dentry *dentry) |
734 |
{ |
735 |
+ int error; |
736 |
if (unlikely(IS_PRIVATE(dir->dentry->d_inode))) |
737 |
return 0; |
738 |
- return security_ops->path_rmdir(dir, dentry); |
739 |
+ error = security_ops->path_rmdir(dir, dentry); |
740 |
+ if (!error) |
741 |
+ error = ccs_rmdir_permission(dir->dentry->d_inode, dentry, |
742 |
+ dir->mnt); |
743 |
+ return error; |
744 |
} |
745 |
|
746 |
int security_path_unlink(struct path *dir, struct dentry *dentry) |
747 |
{ |
748 |
+ int error; |
749 |
if (unlikely(IS_PRIVATE(dir->dentry->d_inode))) |
750 |
return 0; |
751 |
- return security_ops->path_unlink(dir, dentry); |
752 |
+ error = security_ops->path_unlink(dir, dentry); |
753 |
+ if (!error) |
754 |
+ error = ccs_unlink_permission(dir->dentry->d_inode, dentry, |
755 |
+ dir->mnt); |
756 |
+ return error; |
757 |
} |
758 |
|
759 |
int security_path_symlink(struct path *dir, struct dentry *dentry, |
760 |
const char *old_name) |
761 |
{ |
762 |
+ int error; |
763 |
if (unlikely(IS_PRIVATE(dir->dentry->d_inode))) |
764 |
return 0; |
765 |
- return security_ops->path_symlink(dir, dentry, old_name); |
766 |
+ error = security_ops->path_symlink(dir, dentry, old_name); |
767 |
+ if (!error) |
768 |
+ error = ccs_symlink_permission(dir->dentry->d_inode, dentry, |
769 |
+ dir->mnt, old_name); |
770 |
+ return error; |
771 |
} |
772 |
|
773 |
int security_path_link(struct dentry *old_dentry, struct path *new_dir, |
774 |
struct dentry *new_dentry) |
775 |
{ |
776 |
+ int error; |
777 |
if (unlikely(IS_PRIVATE(old_dentry->d_inode))) |
778 |
return 0; |
779 |
- return security_ops->path_link(old_dentry, new_dir, new_dentry); |
780 |
+ error = security_ops->path_link(old_dentry, new_dir, new_dentry); |
781 |
+ if (!error) |
782 |
+ error = ccs_link_permission(old_dentry, |
783 |
+ new_dir->dentry->d_inode, |
784 |
+ new_dentry, new_dir->mnt); |
785 |
+ return error; |
786 |
} |
787 |
|
788 |
int security_path_rename(struct path *old_dir, struct dentry *old_dentry, |
789 |
struct path *new_dir, struct dentry *new_dentry) |
790 |
{ |
791 |
+ int error; |
792 |
if (unlikely(IS_PRIVATE(old_dentry->d_inode) || |
793 |
(new_dentry->d_inode && IS_PRIVATE(new_dentry->d_inode)))) |
794 |
return 0; |
795 |
- return security_ops->path_rename(old_dir, old_dentry, new_dir, |
796 |
- new_dentry); |
797 |
+ error = security_ops->path_rename(old_dir, old_dentry, new_dir, |
798 |
+ new_dentry); |
799 |
+ if (!error) |
800 |
+ error = ccs_rename_permission(old_dir->dentry->d_inode, |
801 |
+ old_dentry, |
802 |
+ new_dir->dentry->d_inode, |
803 |
+ new_dentry, new_dir->mnt); |
804 |
+ return error; |
805 |
} |
806 |
|
807 |
int security_path_truncate(struct path *path, loff_t length, |
808 |
unsigned int time_attrs) |
809 |
{ |
810 |
+ int error; |
811 |
if (unlikely(IS_PRIVATE(path->dentry->d_inode))) |
812 |
return 0; |
813 |
- return security_ops->path_truncate(path, length, time_attrs); |
814 |
+ error = security_ops->path_truncate(path, length, time_attrs); |
815 |
+ if (!error) |
816 |
+ error = ccs_truncate_permission(path->dentry, path->mnt); |
817 |
+ return error; |
818 |
} |
819 |
|
820 |
int security_path_chmod(struct dentry *dentry, struct vfsmount *mnt, |
821 |
mode_t mode) |
822 |
{ |
823 |
+ int error; |
824 |
if (unlikely(IS_PRIVATE(dentry->d_inode))) |
825 |
return 0; |
826 |
- return security_ops->path_chmod(dentry, mnt, mode); |
827 |
+ error = security_ops->path_chmod(dentry, mnt, mode); |
828 |
+ if (!error) |
829 |
+ error = ccs_chmod_permission(dentry, mnt, mode); |
830 |
+ return error; |
831 |
} |
832 |
|
833 |
int security_path_chown(struct path *path, uid_t uid, gid_t gid) |
834 |
{ |
835 |
+ int error; |
836 |
if (unlikely(IS_PRIVATE(path->dentry->d_inode))) |
837 |
return 0; |
838 |
- return security_ops->path_chown(path, uid, gid); |
839 |
+ error = security_ops->path_chown(path, uid, gid); |
840 |
+ if (!error) |
841 |
+ error = ccs_chown_permission(path->dentry, path->mnt, uid, |
842 |
+ gid); |
843 |
+ return error; |
844 |
} |
845 |
|
846 |
int security_path_chroot(struct path *path) |
847 |
{ |
848 |
- return security_ops->path_chroot(path); |
849 |
+ int error = security_ops->path_chroot(path); |
850 |
+ if (!error) |
851 |
+ error = ccs_chroot_permission(path); |
852 |
+ return error; |
853 |
} |
854 |
#endif |
855 |
|
856 |
@@ -540,9 +607,13 @@ EXPORT_SYMBOL_GPL(security_inode_setattr |
857 |
|
858 |
int security_inode_getattr(struct vfsmount *mnt, struct dentry *dentry) |
859 |
{ |
860 |
+ int error; |
861 |
if (unlikely(IS_PRIVATE(dentry->d_inode))) |
862 |
return 0; |
863 |
- return security_ops->inode_getattr(mnt, dentry); |
864 |
+ error = security_ops->inode_getattr(mnt, dentry); |
865 |
+ if (!error) |
866 |
+ error = ccs_getattr_permission(mnt, dentry); |
867 |
+ return error; |
868 |
} |
869 |
|
870 |
int security_inode_setxattr(struct dentry *dentry, const char *name, |
871 |
@@ -635,7 +706,10 @@ void security_file_free(struct file *fil |
872 |
|
873 |
int security_file_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
874 |
{ |
875 |
- return security_ops->file_ioctl(file, cmd, arg); |
876 |
+ int error = security_ops->file_ioctl(file, cmd, arg); |
877 |
+ if (!error) |
878 |
+ error = ccs_ioctl_permission(file, cmd, arg); |
879 |
+ return error; |
880 |
} |
881 |
|
882 |
int security_file_mmap(struct file *file, unsigned long reqprot, |
883 |
@@ -663,7 +737,10 @@ int security_file_lock(struct file *file |
884 |
|
885 |
int security_file_fcntl(struct file *file, unsigned int cmd, unsigned long arg) |
886 |
{ |
887 |
- return security_ops->file_fcntl(file, cmd, arg); |
888 |
+ int error = security_ops->file_fcntl(file, cmd, arg); |
889 |
+ if (!error) |
890 |
+ error = ccs_fcntl_permission(file, cmd, arg); |
891 |
+ return error; |
892 |
} |
893 |
|
894 |
int security_file_set_fowner(struct file *file) |
895 |
@@ -684,7 +761,10 @@ int security_file_receive(struct file *f |
896 |
|
897 |
int security_dentry_open(struct file *file, const struct cred *cred) |
898 |
{ |
899 |
- return security_ops->dentry_open(file, cred); |
900 |
+ int error = security_ops->dentry_open(file, cred); |
901 |
+ if (!error) |
902 |
+ error = ccs_open_permission(file); |
903 |
+ return error; |
904 |
} |
905 |
|
906 |
int security_task_create(unsigned long clone_flags) |
907 |
@@ -997,7 +1077,10 @@ EXPORT_SYMBOL(security_unix_may_send); |
908 |
|
909 |
int security_socket_create(int family, int type, int protocol, int kern) |
910 |
{ |
911 |
- return security_ops->socket_create(family, type, protocol, kern); |
912 |
+ int error = security_ops->socket_create(family, type, protocol, kern); |
913 |
+ if (!error) |
914 |
+ error = ccs_socket_create_permission(family, type, protocol); |
915 |
+ return error; |
916 |
} |
917 |
|
918 |
int security_socket_post_create(struct socket *sock, int family, |
919 |
@@ -1009,17 +1092,26 @@ int security_socket_post_create(struct s |
920 |
|
921 |
int security_socket_bind(struct socket *sock, struct sockaddr *address, int addrlen) |
922 |
{ |
923 |
- return security_ops->socket_bind(sock, address, addrlen); |
924 |
+ int error = security_ops->socket_bind(sock, address, addrlen); |
925 |
+ if (!error) |
926 |
+ error = ccs_socket_bind_permission(sock, address, addrlen); |
927 |
+ return error; |
928 |
} |
929 |
|
930 |
int security_socket_connect(struct socket *sock, struct sockaddr *address, int addrlen) |
931 |
{ |
932 |
- return security_ops->socket_connect(sock, address, addrlen); |
933 |
+ int error = security_ops->socket_connect(sock, address, addrlen); |
934 |
+ if (!error) |
935 |
+ error = ccs_socket_connect_permission(sock, address, addrlen); |
936 |
+ return error; |
937 |
} |
938 |
|
939 |
int security_socket_listen(struct socket *sock, int backlog) |
940 |
{ |
941 |
- return security_ops->socket_listen(sock, backlog); |
942 |
+ int error = security_ops->socket_listen(sock, backlog); |
943 |
+ if (!error) |
944 |
+ error = ccs_socket_listen_permission(sock); |
945 |
+ return error; |
946 |
} |
947 |
|
948 |
int security_socket_accept(struct socket *sock, struct socket *newsock) |
949 |
@@ -1029,7 +1121,10 @@ int security_socket_accept(struct socket |
950 |
|
951 |
int security_socket_sendmsg(struct socket *sock, struct msghdr *msg, int size) |
952 |
{ |
953 |
- return security_ops->socket_sendmsg(sock, msg, size); |
954 |
+ int error = security_ops->socket_sendmsg(sock, msg, size); |
955 |
+ if (!error) |
956 |
+ error = ccs_socket_sendmsg_permission(sock, msg, size); |
957 |
+ return error; |
958 |
} |
959 |
|
960 |
int security_socket_recvmsg(struct socket *sock, struct msghdr *msg, |