オープンソース・ソフトウェアの開発とダウンロード

Subversion リポジトリの参照

Contents of /trunk/1.8.x/ccs-patch/patches/ccs-patch-2.6.29-android-goldfish.diff

Parent Directory Parent Directory | Revision Log Revision Log


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

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26