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

Subversion リポジトリの参照

Annotation of /trunk/1.8.x/ccs-patch/patches/ccs-patch-2.6.28-hardened-gentoo.diff

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3061 - (hide annotations) (download) (as text)
Thu Sep 24 03:50:59 2009 UTC (14 years, 7 months ago) by kumaneko
Original Path: trunk/1.7.x/ccs-patch/patches/ccs-patch-2.6.28-hardened-gentoo.diff
File MIME type: text/x-diff
File size: 33606 byte(s)


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

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