1 |
kumaneko |
1498 |
This is TOMOYO Linux patch for Debian Etch. |
2 |
|
|
|
3 |
|
|
Source code for this patch is "apt-get install linux-source-2.6.18" |
4 |
|
|
--- |
5 |
kumaneko |
2796 |
arch/alpha/kernel/ptrace.c | 3 +++ |
6 |
|
|
arch/ia64/ia32/sys_ia32.c | 3 +++ |
7 |
|
|
arch/ia64/kernel/ptrace.c | 3 +++ |
8 |
|
|
arch/m32r/kernel/ptrace.c | 3 +++ |
9 |
|
|
arch/mips/kernel/ptrace32.c | 3 +++ |
10 |
|
|
arch/powerpc/kernel/ptrace32.c | 3 +++ |
11 |
|
|
arch/s390/kernel/ptrace.c | 3 +++ |
12 |
|
|
arch/sparc/kernel/ptrace.c | 5 +++++ |
13 |
|
|
arch/sparc64/kernel/ptrace.c | 5 +++++ |
14 |
|
|
arch/x86_64/ia32/ptrace32.c | 3 +++ |
15 |
|
|
fs/Kconfig | 2 ++ |
16 |
|
|
fs/Makefile | 2 ++ |
17 |
|
|
fs/attr.c | 5 +++++ |
18 |
|
|
fs/compat.c | 9 ++++++++- |
19 |
|
|
fs/exec.c | 12 +++++++++++- |
20 |
|
|
fs/fcntl.c | 5 +++++ |
21 |
|
|
fs/ioctl.c | 5 +++++ |
22 |
|
|
fs/namei.c | 38 ++++++++++++++++++++++++++++++++++++++ |
23 |
|
|
fs/namespace.c | 28 +++++++++++++++++++++++++++- |
24 |
|
|
fs/open.c | 14 ++++++++++++++ |
25 |
|
|
fs/proc/Makefile | 3 +++ |
26 |
|
|
fs/proc/proc_misc.c | 1 + |
27 |
|
|
include/linux/init_task.h | 2 ++ |
28 |
|
|
include/linux/sched.h | 4 ++++ |
29 |
|
|
kernel/compat.c | 3 +++ |
30 |
|
|
kernel/kexec.c | 3 +++ |
31 |
|
|
kernel/kmod.c | 3 +++ |
32 |
|
|
kernel/module.c | 7 +++++-- |
33 |
|
|
kernel/ptrace.c | 3 +++ |
34 |
|
|
kernel/sched.c | 3 +++ |
35 |
|
|
kernel/signal.c | 13 +++++++++++++ |
36 |
|
|
kernel/sys.c | 11 +++++++++++ |
37 |
|
|
kernel/sysctl.c | 11 +++++++++++ |
38 |
|
|
kernel/time.c | 7 +++++++ |
39 |
|
|
net/ipv4/inet_connection_sock.c | 3 +++ |
40 |
|
|
net/ipv4/inet_hashtables.c | 3 +++ |
41 |
|
|
net/ipv4/raw.c | 4 ++++ |
42 |
|
|
net/ipv4/udp.c | 11 ++++++++++- |
43 |
|
|
net/ipv6/inet6_hashtables.c | 5 ++++- |
44 |
|
|
net/ipv6/raw.c | 4 ++++ |
45 |
|
|
net/ipv6/udp.c | 9 +++++++++ |
46 |
kumaneko |
2805 |
net/socket.c | 26 ++++++++++++++++++++++++-- |
47 |
kumaneko |
2796 |
net/unix/af_unix.c | 4 ++++ |
48 |
kumaneko |
2805 |
43 files changed, 288 insertions(+), 9 deletions(-) |
49 |
kumaneko |
1498 |
|
50 |
kumaneko |
2513 |
--- linux-2.6.18-24etch2.orig/arch/alpha/kernel/ptrace.c |
51 |
|
|
+++ linux-2.6.18-24etch2/arch/alpha/kernel/ptrace.c |
52 |
kumaneko |
2796 |
@@ -20,6 +20,7 @@ |
53 |
kumaneko |
1498 |
#include <asm/pgtable.h> |
54 |
|
|
#include <asm/system.h> |
55 |
|
|
#include <asm/fpu.h> |
56 |
|
|
+#include <linux/tomoyo.h> |
57 |
|
|
|
58 |
|
|
#include "proto.h" |
59 |
|
|
|
60 |
kumaneko |
2796 |
@@ -268,6 +269,8 @@ do_sys_ptrace(long request, long pid, lo |
61 |
kumaneko |
1498 |
unsigned long tmp; |
62 |
|
|
size_t copied; |
63 |
|
|
long ret; |
64 |
kumaneko |
2282 |
+ if (!ccs_capable(CCS_SYS_PTRACE)) |
65 |
kumaneko |
1498 |
+ return -EPERM; |
66 |
|
|
|
67 |
|
|
lock_kernel(); |
68 |
|
|
DBG(DBG_MEM, ("request=%ld pid=%ld addr=0x%lx data=0x%lx\n", |
69 |
kumaneko |
2513 |
--- linux-2.6.18-24etch2.orig/arch/ia64/ia32/sys_ia32.c |
70 |
|
|
+++ linux-2.6.18-24etch2/arch/ia64/ia32/sys_ia32.c |
71 |
kumaneko |
2796 |
@@ -56,6 +56,7 @@ |
72 |
kumaneko |
1498 |
#include <asm/types.h> |
73 |
|
|
#include <asm/uaccess.h> |
74 |
|
|
#include <asm/unistd.h> |
75 |
|
|
+#include <linux/tomoyo.h> |
76 |
|
|
|
77 |
|
|
#include "ia32priv.h" |
78 |
|
|
|
79 |
kumaneko |
2796 |
@@ -1741,6 +1742,8 @@ sys32_ptrace (int request, pid_t pid, un |
80 |
kumaneko |
1498 |
struct task_struct *child; |
81 |
|
|
unsigned int value, tmp; |
82 |
|
|
long i, ret; |
83 |
kumaneko |
2282 |
+ if (!ccs_capable(CCS_SYS_PTRACE)) |
84 |
kumaneko |
1498 |
+ return -EPERM; |
85 |
|
|
|
86 |
|
|
lock_kernel(); |
87 |
|
|
if (request == PTRACE_TRACEME) { |
88 |
kumaneko |
2513 |
--- linux-2.6.18-24etch2.orig/arch/ia64/kernel/ptrace.c |
89 |
|
|
+++ linux-2.6.18-24etch2/arch/ia64/kernel/ptrace.c |
90 |
kumaneko |
2796 |
@@ -28,6 +28,7 @@ |
91 |
kumaneko |
1498 |
#ifdef CONFIG_PERFMON |
92 |
|
|
#include <asm/perfmon.h> |
93 |
|
|
#endif |
94 |
|
|
+#include <linux/tomoyo.h> |
95 |
|
|
|
96 |
|
|
#include "entry.h" |
97 |
|
|
|
98 |
kumaneko |
2796 |
@@ -1417,6 +1418,8 @@ sys_ptrace (long request, pid_t pid, uns |
99 |
kumaneko |
1498 |
struct task_struct *child; |
100 |
|
|
struct switch_stack *sw; |
101 |
|
|
long ret; |
102 |
kumaneko |
2282 |
+ if (!ccs_capable(CCS_SYS_PTRACE)) |
103 |
kumaneko |
1498 |
+ return -EPERM; |
104 |
|
|
|
105 |
|
|
lock_kernel(); |
106 |
|
|
ret = -EPERM; |
107 |
kumaneko |
2513 |
--- linux-2.6.18-24etch2.orig/arch/m32r/kernel/ptrace.c |
108 |
|
|
+++ linux-2.6.18-24etch2/arch/m32r/kernel/ptrace.c |
109 |
kumaneko |
2796 |
@@ -32,6 +32,7 @@ |
110 |
kumaneko |
1498 |
#include <asm/system.h> |
111 |
|
|
#include <asm/processor.h> |
112 |
|
|
#include <asm/mmu_context.h> |
113 |
|
|
+#include <linux/tomoyo.h> |
114 |
|
|
|
115 |
|
|
/* |
116 |
|
|
* This routine will get a word off of the process kernel stack. |
117 |
kumaneko |
2796 |
@@ -742,6 +743,8 @@ asmlinkage long sys_ptrace(long request, |
118 |
kumaneko |
1498 |
{ |
119 |
|
|
struct task_struct *child; |
120 |
|
|
int ret; |
121 |
kumaneko |
2282 |
+ if (!ccs_capable(CCS_SYS_PTRACE)) |
122 |
kumaneko |
1498 |
+ return -EPERM; |
123 |
|
|
|
124 |
|
|
lock_kernel(); |
125 |
|
|
if (request == PTRACE_TRACEME) { |
126 |
kumaneko |
2513 |
--- linux-2.6.18-24etch2.orig/arch/mips/kernel/ptrace32.c |
127 |
|
|
+++ linux-2.6.18-24etch2/arch/mips/kernel/ptrace32.c |
128 |
kumaneko |
2796 |
@@ -35,6 +35,7 @@ |
129 |
kumaneko |
1498 |
#include <asm/system.h> |
130 |
|
|
#include <asm/uaccess.h> |
131 |
|
|
#include <asm/bootinfo.h> |
132 |
|
|
+#include <linux/tomoyo.h> |
133 |
|
|
|
134 |
|
|
int ptrace_getregs (struct task_struct *child, __s64 __user *data); |
135 |
|
|
int ptrace_setregs (struct task_struct *child, __s64 __user *data); |
136 |
kumaneko |
2796 |
@@ -50,6 +51,8 @@ asmlinkage int sys32_ptrace(int request, |
137 |
kumaneko |
1498 |
{ |
138 |
|
|
struct task_struct *child; |
139 |
|
|
int ret; |
140 |
kumaneko |
2282 |
+ if (!ccs_capable(CCS_SYS_PTRACE)) |
141 |
kumaneko |
1498 |
+ return -EPERM; |
142 |
|
|
|
143 |
|
|
#if 0 |
144 |
|
|
printk("ptrace(r=%d,pid=%d,addr=%08lx,data=%08lx)\n", |
145 |
kumaneko |
2513 |
--- linux-2.6.18-24etch2.orig/arch/powerpc/kernel/ptrace32.c |
146 |
|
|
+++ linux-2.6.18-24etch2/arch/powerpc/kernel/ptrace32.c |
147 |
kumaneko |
2796 |
@@ -32,6 +32,7 @@ |
148 |
kumaneko |
1498 |
#include <asm/page.h> |
149 |
|
|
#include <asm/pgtable.h> |
150 |
|
|
#include <asm/system.h> |
151 |
|
|
+#include <linux/tomoyo.h> |
152 |
|
|
|
153 |
|
|
#include "ptrace-common.h" |
154 |
|
|
|
155 |
kumaneko |
2796 |
@@ -45,6 +46,8 @@ long compat_sys_ptrace(int request, int |
156 |
kumaneko |
1498 |
{ |
157 |
|
|
struct task_struct *child; |
158 |
|
|
int ret; |
159 |
kumaneko |
2282 |
+ if (!ccs_capable(CCS_SYS_PTRACE)) |
160 |
kumaneko |
1498 |
+ return -EPERM; |
161 |
|
|
|
162 |
|
|
lock_kernel(); |
163 |
|
|
if (request == PTRACE_TRACEME) { |
164 |
kumaneko |
2513 |
--- linux-2.6.18-24etch2.orig/arch/s390/kernel/ptrace.c |
165 |
|
|
+++ linux-2.6.18-24etch2/arch/s390/kernel/ptrace.c |
166 |
kumaneko |
2796 |
@@ -41,6 +41,7 @@ |
167 |
kumaneko |
1498 |
#include <asm/system.h> |
168 |
|
|
#include <asm/uaccess.h> |
169 |
|
|
#include <asm/unistd.h> |
170 |
|
|
+#include <linux/tomoyo.h> |
171 |
|
|
|
172 |
|
|
#ifdef CONFIG_COMPAT |
173 |
|
|
#include "compat_ptrace.h" |
174 |
kumaneko |
2796 |
@@ -711,6 +712,8 @@ sys_ptrace(long request, long pid, long |
175 |
kumaneko |
1498 |
struct task_struct *child; |
176 |
|
|
int ret; |
177 |
|
|
|
178 |
kumaneko |
2282 |
+ if (!ccs_capable(CCS_SYS_PTRACE)) |
179 |
kumaneko |
1498 |
+ return -EPERM; |
180 |
|
|
lock_kernel(); |
181 |
|
|
if (request == PTRACE_TRACEME) { |
182 |
|
|
ret = ptrace_traceme(); |
183 |
kumaneko |
2513 |
--- linux-2.6.18-24etch2.orig/arch/sparc/kernel/ptrace.c |
184 |
|
|
+++ linux-2.6.18-24etch2/arch/sparc/kernel/ptrace.c |
185 |
kumaneko |
2796 |
@@ -23,6 +23,7 @@ |
186 |
kumaneko |
1498 |
#include <asm/pgtable.h> |
187 |
|
|
#include <asm/system.h> |
188 |
|
|
#include <asm/uaccess.h> |
189 |
|
|
+#include <linux/tomoyo.h> |
190 |
|
|
|
191 |
|
|
#define MAGIC_CONSTANT 0x80000000 |
192 |
|
|
|
193 |
kumaneko |
2796 |
@@ -267,6 +268,10 @@ asmlinkage void do_ptrace(struct pt_regs |
194 |
kumaneko |
1498 |
unsigned long addr2 = regs->u_regs[UREG_I4]; |
195 |
|
|
struct task_struct *child; |
196 |
|
|
int ret; |
197 |
kumaneko |
2282 |
+ if (!ccs_capable(CCS_SYS_PTRACE)) { |
198 |
kumaneko |
1498 |
+ pt_error_return(regs, EPERM); |
199 |
|
|
+ return; |
200 |
|
|
+ } |
201 |
|
|
|
202 |
|
|
lock_kernel(); |
203 |
|
|
#ifdef DEBUG_PTRACE |
204 |
kumaneko |
2513 |
--- linux-2.6.18-24etch2.orig/arch/sparc64/kernel/ptrace.c |
205 |
|
|
+++ linux-2.6.18-24etch2/arch/sparc64/kernel/ptrace.c |
206 |
kumaneko |
2796 |
@@ -32,6 +32,7 @@ |
207 |
kumaneko |
1498 |
#include <asm/spitfire.h> |
208 |
|
|
#include <asm/page.h> |
209 |
|
|
#include <asm/cpudata.h> |
210 |
|
|
+#include <linux/tomoyo.h> |
211 |
|
|
|
212 |
|
|
/* Returning from ptrace is a bit tricky because the syscall return |
213 |
|
|
* low level code assumes any value returned which is negative and |
214 |
kumaneko |
2796 |
@@ -176,6 +177,10 @@ asmlinkage void do_ptrace(struct pt_regs |
215 |
kumaneko |
1498 |
unsigned long addr2 = regs->u_regs[UREG_I4]; |
216 |
|
|
struct task_struct *child; |
217 |
|
|
int ret; |
218 |
kumaneko |
2282 |
+ if (!ccs_capable(CCS_SYS_PTRACE)) { |
219 |
kumaneko |
1498 |
+ pt_error_return(regs, EPERM); |
220 |
|
|
+ return; |
221 |
|
|
+ } |
222 |
|
|
|
223 |
|
|
if (test_thread_flag(TIF_32BIT)) { |
224 |
|
|
addr &= 0xffffffffUL; |
225 |
kumaneko |
2513 |
--- linux-2.6.18-24etch2.orig/arch/x86_64/ia32/ptrace32.c |
226 |
|
|
+++ linux-2.6.18-24etch2/arch/x86_64/ia32/ptrace32.c |
227 |
kumaneko |
2796 |
@@ -26,6 +26,7 @@ |
228 |
kumaneko |
1498 |
#include <asm/i387.h> |
229 |
|
|
#include <asm/fpu32.h> |
230 |
|
|
#include <asm/ia32.h> |
231 |
|
|
+#include <linux/tomoyo.h> |
232 |
|
|
|
233 |
|
|
/* |
234 |
|
|
* Determines which flags the user has access to [1 = access, 0 = no access]. |
235 |
kumaneko |
2796 |
@@ -230,6 +231,8 @@ asmlinkage long sys32_ptrace(long reques |
236 |
kumaneko |
1498 |
void __user *datap = compat_ptr(data); |
237 |
|
|
int ret; |
238 |
|
|
__u32 val; |
239 |
kumaneko |
2282 |
+ if (!ccs_capable(CCS_SYS_PTRACE)) |
240 |
kumaneko |
1498 |
+ return -EPERM; |
241 |
|
|
|
242 |
|
|
switch (request) { |
243 |
|
|
case PTRACE_TRACEME: |
244 |
kumaneko |
2513 |
--- linux-2.6.18-24etch2.orig/fs/Kconfig |
245 |
|
|
+++ linux-2.6.18-24etch2/fs/Kconfig |
246 |
kumaneko |
1498 |
@@ -1931,5 +1931,7 @@ endmenu |
247 |
|
|
|
248 |
|
|
source "fs/nls/Kconfig" |
249 |
|
|
|
250 |
|
|
+source "fs/Kconfig.ccs" |
251 |
|
|
+ |
252 |
|
|
endmenu |
253 |
|
|
|
254 |
kumaneko |
2513 |
--- linux-2.6.18-24etch2.orig/fs/Makefile |
255 |
|
|
+++ linux-2.6.18-24etch2/fs/Makefile |
256 |
kumaneko |
1498 |
@@ -102,3 +102,5 @@ obj-$(CONFIG_HOSTFS) += hostfs/ |
257 |
|
|
obj-$(CONFIG_HPPFS) += hppfs/ |
258 |
|
|
obj-$(CONFIG_DEBUG_FS) += debugfs/ |
259 |
|
|
obj-$(CONFIG_OCFS2_FS) += ocfs2/ |
260 |
|
|
+ |
261 |
|
|
+include $(srctree)/fs/Makefile-2.6.ccs |
262 |
kumaneko |
2513 |
--- linux-2.6.18-24etch2.orig/fs/attr.c |
263 |
|
|
+++ linux-2.6.18-24etch2/fs/attr.c |
264 |
kumaneko |
2796 |
@@ -15,6 +15,7 @@ |
265 |
kumaneko |
1498 |
#include <linux/fcntl.h> |
266 |
|
|
#include <linux/quotaops.h> |
267 |
|
|
#include <linux/security.h> |
268 |
|
|
+#include <linux/tomoyo.h> |
269 |
|
|
|
270 |
|
|
/* Taken over from the old code... */ |
271 |
|
|
|
272 |
kumaneko |
2796 |
@@ -146,11 +147,15 @@ int notify_change(struct dentry * dentry |
273 |
kumaneko |
1498 |
if (inode->i_op && inode->i_op->setattr) { |
274 |
|
|
error = security_inode_setattr(dentry, attr); |
275 |
kumaneko |
2796 |
if (!error) |
276 |
|
|
+ error = ccs_check_setattr_permission(dentry, attr); |
277 |
kumaneko |
2794 |
+ if (!error) |
278 |
kumaneko |
1498 |
error = inode->i_op->setattr(dentry, attr); |
279 |
|
|
} else { |
280 |
|
|
error = inode_change_ok(inode, attr); |
281 |
|
|
if (!error) |
282 |
|
|
error = security_inode_setattr(dentry, attr); |
283 |
kumaneko |
2794 |
+ if (!error) |
284 |
|
|
+ error = ccs_check_setattr_permission(dentry, attr); |
285 |
kumaneko |
1498 |
if (!error) { |
286 |
|
|
if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) || |
287 |
|
|
(ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) |
288 |
kumaneko |
2513 |
--- linux-2.6.18-24etch2.orig/fs/compat.c |
289 |
|
|
+++ linux-2.6.18-24etch2/fs/compat.c |
290 |
kumaneko |
2796 |
@@ -52,6 +52,7 @@ |
291 |
kumaneko |
1498 |
#include <asm/uaccess.h> |
292 |
|
|
#include <asm/mmu_context.h> |
293 |
|
|
#include <asm/ioctls.h> |
294 |
|
|
+#include <linux/tomoyo.h> |
295 |
|
|
|
296 |
|
|
extern void sigset_from_compat(sigset_t *set, compat_sigset_t *compat); |
297 |
|
|
|
298 |
kumaneko |
2796 |
@@ -397,6 +398,8 @@ asmlinkage long compat_sys_ioctl(unsigne |
299 |
kumaneko |
2279 |
|
300 |
|
|
/* RED-PEN how should LSM module know it's handling 32bit? */ |
301 |
|
|
error = security_file_ioctl(filp, cmd, arg); |
302 |
|
|
+ if (!error) |
303 |
|
|
+ error = ccs_check_ioctl_permission(filp, cmd, arg); |
304 |
|
|
if (error) |
305 |
|
|
goto out_fput; |
306 |
|
|
|
307 |
kumaneko |
2796 |
@@ -421,6 +424,10 @@ asmlinkage long compat_sys_ioctl(unsigne |
308 |
kumaneko |
1498 |
/*FALL THROUGH*/ |
309 |
|
|
|
310 |
|
|
default: |
311 |
kumaneko |
2282 |
+ if (!ccs_capable(CCS_SYS_IOCTL)) { |
312 |
kumaneko |
1498 |
+ error = -EPERM; |
313 |
|
|
+ goto out_fput; |
314 |
|
|
+ } |
315 |
|
|
if (filp->f_op && filp->f_op->compat_ioctl) { |
316 |
|
|
error = filp->f_op->compat_ioctl(filp, cmd, arg); |
317 |
|
|
if (error != -ENOIOCTLCMD) |
318 |
kumaneko |
2796 |
@@ -1567,7 +1574,7 @@ int compat_do_execve(char * filename, |
319 |
kumaneko |
1498 |
if (retval < 0) |
320 |
|
|
goto out; |
321 |
|
|
|
322 |
|
|
- retval = search_binary_handler(bprm, regs); |
323 |
kumaneko |
2300 |
+ retval = ccs_search_binary_handler(bprm, regs); |
324 |
kumaneko |
1498 |
if (retval >= 0) { |
325 |
|
|
free_arg_pages(bprm); |
326 |
|
|
|
327 |
kumaneko |
2513 |
--- linux-2.6.18-24etch2.orig/fs/exec.c |
328 |
|
|
+++ linux-2.6.18-24etch2/fs/exec.c |
329 |
kumaneko |
2796 |
@@ -57,6 +57,8 @@ |
330 |
kumaneko |
1498 |
#include <linux/kmod.h> |
331 |
|
|
#endif |
332 |
|
|
|
333 |
|
|
+#include <linux/tomoyo.h> |
334 |
|
|
+ |
335 |
|
|
int core_uses_pid; |
336 |
|
|
char core_pattern[65] = "core"; |
337 |
|
|
int suid_dumpable = 0; |
338 |
kumaneko |
2796 |
@@ -139,6 +141,10 @@ asmlinkage long sys_uselib(const char __ |
339 |
kumaneko |
1498 |
if (error) |
340 |
|
|
goto exit; |
341 |
|
|
|
342 |
kumaneko |
2306 |
+ error = ccs_check_uselib_permission(nd.dentry, nd.mnt); |
343 |
kumaneko |
1498 |
+ if (error) |
344 |
|
|
+ goto exit; |
345 |
|
|
+ |
346 |
|
|
file = nameidata_to_filp(&nd, O_RDONLY); |
347 |
|
|
error = PTR_ERR(file); |
348 |
|
|
if (IS_ERR(file)) |
349 |
kumaneko |
2796 |
@@ -486,6 +492,9 @@ struct file *open_exec(const char *name) |
350 |
kumaneko |
1498 |
if (!(nd.mnt->mnt_flags & MNT_NOEXEC) && |
351 |
|
|
S_ISREG(inode->i_mode)) { |
352 |
|
|
int err = vfs_permission(&nd, MAY_EXEC); |
353 |
kumaneko |
2306 |
+ if (!err) |
354 |
|
|
+ err = ccs_check_open_exec_permission(nd.dentry, |
355 |
|
|
+ nd.mnt); |
356 |
kumaneko |
1498 |
file = ERR_PTR(err); |
357 |
|
|
if (!err) { |
358 |
|
|
file = nameidata_to_filp(&nd, O_RDONLY); |
359 |
kumaneko |
2796 |
@@ -1188,7 +1197,8 @@ int do_execve(char * filename, |
360 |
kumaneko |
1498 |
if (retval < 0) |
361 |
|
|
goto out; |
362 |
|
|
|
363 |
|
|
- retval = search_binary_handler(bprm,regs); |
364 |
kumaneko |
2300 |
+ retval = ccs_search_binary_handler(bprm, regs); |
365 |
kumaneko |
1498 |
+ |
366 |
|
|
if (retval >= 0) { |
367 |
|
|
free_arg_pages(bprm); |
368 |
|
|
|
369 |
kumaneko |
2513 |
--- linux-2.6.18-24etch2.orig/fs/fcntl.c |
370 |
|
|
+++ linux-2.6.18-24etch2/fs/fcntl.c |
371 |
kumaneko |
2796 |
@@ -22,6 +22,7 @@ |
372 |
kumaneko |
1498 |
#include <asm/poll.h> |
373 |
|
|
#include <asm/siginfo.h> |
374 |
|
|
#include <asm/uaccess.h> |
375 |
|
|
+#include <linux/tomoyo.h> |
376 |
|
|
|
377 |
|
|
void fastcall set_close_on_exec(unsigned int fd, int flag) |
378 |
|
|
{ |
379 |
kumaneko |
2796 |
@@ -214,6 +215,10 @@ static int setfl(int fd, struct file * f |
380 |
kumaneko |
1498 |
if (((arg ^ filp->f_flags) & O_APPEND) && IS_APPEND(inode)) |
381 |
|
|
return -EPERM; |
382 |
|
|
|
383 |
|
|
+ if (((arg ^ filp->f_flags) & O_APPEND) && |
384 |
|
|
+ ccs_check_rewrite_permission(filp)) |
385 |
|
|
+ return -EPERM; |
386 |
|
|
+ |
387 |
|
|
/* O_NOATIME can only be set by the owner or superuser */ |
388 |
|
|
if ((arg & O_NOATIME) && !(filp->f_flags & O_NOATIME)) |
389 |
|
|
if (current->fsuid != inode->i_uid && !capable(CAP_FOWNER)) |
390 |
kumaneko |
2513 |
--- linux-2.6.18-24etch2.orig/fs/ioctl.c |
391 |
|
|
+++ linux-2.6.18-24etch2/fs/ioctl.c |
392 |
kumaneko |
2796 |
@@ -15,6 +15,7 @@ |
393 |
kumaneko |
1498 |
|
394 |
|
|
#include <asm/uaccess.h> |
395 |
|
|
#include <asm/ioctls.h> |
396 |
|
|
+#include <linux/tomoyo.h> |
397 |
|
|
|
398 |
|
|
static long do_ioctl(struct file *filp, unsigned int cmd, |
399 |
|
|
unsigned long arg) |
400 |
kumaneko |
2796 |
@@ -23,6 +24,8 @@ static long do_ioctl(struct file *filp, |
401 |
kumaneko |
1498 |
|
402 |
|
|
if (!filp->f_op) |
403 |
|
|
goto out; |
404 |
kumaneko |
2282 |
+ if (!ccs_capable(CCS_SYS_IOCTL)) |
405 |
kumaneko |
1498 |
+ return -EPERM; |
406 |
|
|
|
407 |
|
|
if (filp->f_op->unlocked_ioctl) { |
408 |
|
|
error = filp->f_op->unlocked_ioctl(filp, cmd, arg); |
409 |
kumaneko |
2796 |
@@ -167,6 +170,8 @@ asmlinkage long sys_ioctl(unsigned int f |
410 |
kumaneko |
2279 |
goto out; |
411 |
|
|
|
412 |
|
|
error = security_file_ioctl(filp, cmd, arg); |
413 |
|
|
+ if (!error) |
414 |
|
|
+ error = ccs_check_ioctl_permission(filp, cmd, arg); |
415 |
|
|
if (error) |
416 |
|
|
goto out_fput; |
417 |
|
|
|
418 |
kumaneko |
2513 |
--- linux-2.6.18-24etch2.orig/fs/namei.c |
419 |
|
|
+++ linux-2.6.18-24etch2/fs/namei.c |
420 |
kumaneko |
2796 |
@@ -37,6 +37,8 @@ |
421 |
kumaneko |
1498 |
|
422 |
|
|
#define ACC_MODE(x) ("\000\004\002\006"[(x)&O_ACCMODE]) |
423 |
|
|
|
424 |
|
|
+#include <linux/tomoyo.h> |
425 |
|
|
+ |
426 |
|
|
/* [Feb-1997 T. Schoebel-Theuer] |
427 |
|
|
* Fundamental changes in the pathname lookup mechanisms (namei) |
428 |
|
|
* were necessary because of omirr. The reason is that omirr needs |
429 |
kumaneko |
2796 |
@@ -1536,6 +1538,11 @@ int may_open(struct nameidata *nd, int a |
430 |
kumaneko |
1498 |
if (current->fsuid != inode->i_uid && !capable(CAP_FOWNER)) |
431 |
|
|
return -EPERM; |
432 |
|
|
|
433 |
|
|
+ /* includes O_APPEND and O_TRUNC checks */ |
434 |
|
|
+ error = ccs_check_open_permission(dentry, nd->mnt, flag); |
435 |
|
|
+ if (error) |
436 |
|
|
+ return error; |
437 |
|
|
+ |
438 |
|
|
/* |
439 |
|
|
* Ensure there are no outstanding leases on the file. |
440 |
|
|
*/ |
441 |
kumaneko |
2796 |
@@ -1567,6 +1574,7 @@ int may_open(struct nameidata *nd, int a |
442 |
kumaneko |
1498 |
return 0; |
443 |
|
|
} |
444 |
|
|
|
445 |
|
|
+#include <linux/tomoyo_vfs.h> |
446 |
|
|
/* |
447 |
|
|
* open_namei() |
448 |
|
|
* |
449 |
kumaneko |
2796 |
@@ -1650,6 +1658,9 @@ do_last: |
450 |
kumaneko |
2297 |
if (!path.dentry->d_inode) { |
451 |
|
|
if (!IS_POSIXACL(dir->d_inode)) |
452 |
|
|
mode &= ~current->fs->umask; |
453 |
|
|
+ error = ccs_check_mknod_permission(dir->d_inode, path.dentry, |
454 |
kumaneko |
2299 |
+ nd->mnt, mode, 0); |
455 |
kumaneko |
2297 |
+ if (!error) |
456 |
|
|
error = vfs_create(dir->d_inode, path.dentry, mode, nd); |
457 |
|
|
mutex_unlock(&dir->d_inode->i_mutex); |
458 |
|
|
dput(nd->dentry); |
459 |
kumaneko |
2796 |
@@ -1848,6 +1859,10 @@ asmlinkage long sys_mknodat(int dfd, con |
460 |
kumaneko |
2297 |
if (!IS_POSIXACL(nd.dentry->d_inode)) |
461 |
|
|
mode &= ~current->fs->umask; |
462 |
|
|
if (!IS_ERR(dentry)) { |
463 |
kumaneko |
2299 |
+ error = ccs_check_mknod_permission(nd.dentry->d_inode, dentry, |
464 |
|
|
+ nd.mnt, mode, |
465 |
kumaneko |
2297 |
+ new_decode_dev(dev)); |
466 |
|
|
+ if (!error) |
467 |
|
|
switch (mode & S_IFMT) { |
468 |
|
|
case 0: case S_IFREG: |
469 |
kumaneko |
1498 |
error = vfs_create(nd.dentry->d_inode,dentry,mode,&nd); |
470 |
kumaneko |
2796 |
@@ -1921,6 +1936,10 @@ asmlinkage long sys_mkdirat(int dfd, con |
471 |
kumaneko |
1498 |
if (!IS_ERR(dentry)) { |
472 |
|
|
if (!IS_POSIXACL(nd.dentry->d_inode)) |
473 |
|
|
mode &= ~current->fs->umask; |
474 |
kumaneko |
2297 |
+ error = ccs_check_mkdir_permission(nd.dentry->d_inode, |
475 |
|
|
+ dentry, nd.mnt, |
476 |
|
|
+ mode); |
477 |
kumaneko |
1498 |
+ if (!error) |
478 |
|
|
error = vfs_mkdir(nd.dentry->d_inode, dentry, mode); |
479 |
|
|
dput(dentry); |
480 |
|
|
} |
481 |
kumaneko |
2796 |
@@ -2029,6 +2048,9 @@ static long do_rmdir(int dfd, const char |
482 |
kumaneko |
1498 |
dentry = lookup_hash(&nd); |
483 |
|
|
error = PTR_ERR(dentry); |
484 |
|
|
if (!IS_ERR(dentry)) { |
485 |
kumaneko |
2297 |
+ error = ccs_check_rmdir_permission(nd.dentry->d_inode, dentry, |
486 |
|
|
+ nd.mnt); |
487 |
kumaneko |
1498 |
+ if (!error) |
488 |
|
|
error = vfs_rmdir(nd.dentry->d_inode, dentry); |
489 |
|
|
dput(dentry); |
490 |
|
|
} |
491 |
kumaneko |
2796 |
@@ -2109,6 +2131,9 @@ static long do_unlinkat(int dfd, const c |
492 |
kumaneko |
1498 |
inode = dentry->d_inode; |
493 |
|
|
if (inode) |
494 |
|
|
atomic_inc(&inode->i_count); |
495 |
kumaneko |
2297 |
+ error = ccs_check_unlink_permission(nd.dentry->d_inode, dentry, |
496 |
|
|
+ nd.mnt); |
497 |
|
|
+ if (!error) |
498 |
kumaneko |
1498 |
error = vfs_unlink(nd.dentry->d_inode, dentry); |
499 |
|
|
exit2: |
500 |
|
|
dput(dentry); |
501 |
kumaneko |
2796 |
@@ -2187,6 +2212,10 @@ asmlinkage long sys_symlinkat(const char |
502 |
kumaneko |
1498 |
dentry = lookup_create(&nd, 0); |
503 |
|
|
error = PTR_ERR(dentry); |
504 |
|
|
if (!IS_ERR(dentry)) { |
505 |
kumaneko |
2297 |
+ error = ccs_check_symlink_permission(nd.dentry->d_inode, |
506 |
|
|
+ dentry, nd.mnt, |
507 |
|
|
+ from); |
508 |
kumaneko |
1498 |
+ if (!error) |
509 |
|
|
error = vfs_symlink(nd.dentry->d_inode, dentry, from, S_IALLUGO); |
510 |
|
|
dput(dentry); |
511 |
|
|
} |
512 |
kumaneko |
2796 |
@@ -2281,6 +2310,10 @@ asmlinkage long sys_linkat(int olddfd, c |
513 |
kumaneko |
1498 |
new_dentry = lookup_create(&nd, 0); |
514 |
|
|
error = PTR_ERR(new_dentry); |
515 |
|
|
if (!IS_ERR(new_dentry)) { |
516 |
kumaneko |
2297 |
+ error = ccs_check_link_permission(old_nd.dentry, |
517 |
|
|
+ nd.dentry->d_inode, |
518 |
|
|
+ new_dentry, nd.mnt); |
519 |
kumaneko |
1498 |
+ if (!error) |
520 |
|
|
error = vfs_link(old_nd.dentry, nd.dentry->d_inode, new_dentry); |
521 |
|
|
dput(new_dentry); |
522 |
|
|
} |
523 |
kumaneko |
2796 |
@@ -2507,6 +2540,11 @@ static int do_rename(int olddfd, const c |
524 |
kumaneko |
1498 |
if (new_dentry == trap) |
525 |
|
|
goto exit5; |
526 |
|
|
|
527 |
kumaneko |
2297 |
+ error = ccs_check_rename_permission(old_dir->d_inode, old_dentry, |
528 |
|
|
+ new_dir->d_inode, new_dentry, |
529 |
|
|
+ newnd.mnt); |
530 |
|
|
+ if (!error) |
531 |
kumaneko |
1498 |
+ |
532 |
|
|
error = vfs_rename(old_dir->d_inode, old_dentry, |
533 |
|
|
new_dir->d_inode, new_dentry); |
534 |
|
|
exit5: |
535 |
kumaneko |
2513 |
--- linux-2.6.18-24etch2.orig/fs/namespace.c |
536 |
|
|
+++ linux-2.6.18-24etch2/fs/namespace.c |
537 |
kumaneko |
2796 |
@@ -25,6 +25,8 @@ |
538 |
kumaneko |
1498 |
#include <asm/uaccess.h> |
539 |
|
|
#include <asm/unistd.h> |
540 |
|
|
#include "pnode.h" |
541 |
|
|
+#include <linux/sakura.h> |
542 |
|
|
+#include <linux/tomoyo.h> |
543 |
|
|
|
544 |
|
|
extern int __init init_rootfs(void); |
545 |
|
|
|
546 |
kumaneko |
2796 |
@@ -553,6 +555,9 @@ static int do_umount(struct vfsmount *mn |
547 |
kumaneko |
1498 |
if (retval) |
548 |
|
|
return retval; |
549 |
|
|
|
550 |
|
|
+ if (ccs_may_umount(mnt)) |
551 |
|
|
+ return -EPERM; |
552 |
|
|
+ |
553 |
|
|
/* |
554 |
|
|
* Allow userspace to request a mountpoint be expired rather than |
555 |
|
|
* unmounting unconditionally. Unmount only happens if: |
556 |
kumaneko |
2796 |
@@ -641,6 +646,8 @@ asmlinkage long sys_umount(char __user * |
557 |
kumaneko |
1498 |
{ |
558 |
|
|
struct nameidata nd; |
559 |
|
|
int retval; |
560 |
kumaneko |
2282 |
+ if (!ccs_capable(CCS_SYS_UMOUNT)) |
561 |
kumaneko |
1498 |
+ return -EPERM; |
562 |
|
|
|
563 |
|
|
retval = __user_walk(name, LOOKUP_FOLLOW, &nd); |
564 |
|
|
if (retval) |
565 |
kumaneko |
2796 |
@@ -925,6 +932,9 @@ static int do_loopback(struct nameidata |
566 |
kumaneko |
1498 |
|
567 |
|
|
if (!check_mnt(nd->mnt) || !check_mnt(old_nd.mnt)) |
568 |
|
|
goto out; |
569 |
|
|
+ err = -EPERM; |
570 |
|
|
+ if (ccs_may_mount(nd)) |
571 |
|
|
+ goto out; |
572 |
|
|
|
573 |
|
|
err = -ENOMEM; |
574 |
|
|
if (recurse) |
575 |
kumaneko |
2796 |
@@ -1009,7 +1019,9 @@ static int do_move_mount(struct nameidat |
576 |
kumaneko |
1498 |
err = -EINVAL; |
577 |
|
|
if (!check_mnt(nd->mnt) || !check_mnt(old_nd.mnt)) |
578 |
|
|
goto out; |
579 |
|
|
- |
580 |
|
|
+ err = -EPERM; |
581 |
|
|
+ if (ccs_may_umount(old_nd.mnt) || ccs_may_mount(nd)) |
582 |
|
|
+ goto out; |
583 |
|
|
err = -ENOENT; |
584 |
|
|
mutex_lock(&nd->dentry->d_inode->i_mutex); |
585 |
|
|
if (IS_DEADDIR(nd->dentry->d_inode)) |
586 |
kumaneko |
2796 |
@@ -1111,6 +1123,9 @@ int do_add_mount(struct vfsmount *newmnt |
587 |
kumaneko |
1498 |
err = -EINVAL; |
588 |
|
|
if (S_ISLNK(newmnt->mnt_root->d_inode->i_mode)) |
589 |
|
|
goto unlock; |
590 |
|
|
+ err = -EPERM; |
591 |
|
|
+ if (ccs_may_mount(nd)) |
592 |
|
|
+ goto unlock; |
593 |
|
|
|
594 |
|
|
newmnt->mnt_flags = mnt_flags; |
595 |
|
|
if ((err = graft_tree(newmnt, nd))) |
596 |
kumaneko |
2796 |
@@ -1402,6 +1417,13 @@ long do_mount(char *dev_name, char *dir_ |
597 |
kumaneko |
1498 |
if (data_page) |
598 |
|
|
((char *)data_page)[PAGE_SIZE - 1] = 0; |
599 |
|
|
|
600 |
kumaneko |
2282 |
+ if (!ccs_capable(CCS_SYS_MOUNT)) |
601 |
kumaneko |
1498 |
+ return -EPERM; |
602 |
|
|
+ retval = ccs_check_mount_permission(dev_name, dir_name, type_page, |
603 |
|
|
+ &flags); |
604 |
|
|
+ if (retval) |
605 |
|
|
+ return retval; |
606 |
|
|
+ |
607 |
|
|
/* Separate the per-mountpoint flags */ |
608 |
|
|
if (flags & MS_NOSUID) |
609 |
|
|
mnt_flags |= MNT_NOSUID; |
610 |
kumaneko |
2796 |
@@ -1691,6 +1713,8 @@ asmlinkage long sys_pivot_root(const cha |
611 |
kumaneko |
1498 |
|
612 |
|
|
if (!capable(CAP_SYS_ADMIN)) |
613 |
|
|
return -EPERM; |
614 |
kumaneko |
2282 |
+ if (!ccs_capable(CCS_SYS_PIVOT_ROOT)) |
615 |
kumaneko |
1498 |
+ return -EPERM; |
616 |
|
|
|
617 |
|
|
lock_kernel(); |
618 |
|
|
|
619 |
kumaneko |
2796 |
@@ -1707,6 +1731,8 @@ asmlinkage long sys_pivot_root(const cha |
620 |
kumaneko |
1498 |
goto out1; |
621 |
|
|
|
622 |
|
|
error = security_sb_pivotroot(&old_nd, &new_nd); |
623 |
|
|
+ if (!error) |
624 |
|
|
+ error = ccs_check_pivot_root_permission(&old_nd, &new_nd); |
625 |
|
|
if (error) { |
626 |
|
|
path_release(&old_nd); |
627 |
|
|
goto out1; |
628 |
kumaneko |
2513 |
--- linux-2.6.18-24etch2.orig/fs/open.c |
629 |
|
|
+++ linux-2.6.18-24etch2/fs/open.c |
630 |
kumaneko |
2796 |
@@ -30,6 +30,8 @@ |
631 |
kumaneko |
1498 |
#include <linux/audit.h> |
632 |
|
|
|
633 |
|
|
#include <asm/unistd.h> |
634 |
|
|
+#include <linux/sakura.h> |
635 |
|
|
+#include <linux/tomoyo.h> |
636 |
|
|
|
637 |
|
|
int vfs_statfs(struct dentry *dentry, struct kstatfs *buf) |
638 |
|
|
{ |
639 |
kumaneko |
2796 |
@@ -267,6 +269,8 @@ static long do_sys_truncate(const char _ |
640 |
kumaneko |
1498 |
if (error) |
641 |
|
|
goto dput_and_out; |
642 |
|
|
|
643 |
kumaneko |
2297 |
+ error = ccs_check_truncate_permission(nd.dentry, nd.mnt, length, 0); |
644 |
kumaneko |
1498 |
+ if (!error) |
645 |
|
|
error = locks_verify_truncate(inode, NULL, length); |
646 |
|
|
if (!error) { |
647 |
|
|
DQUOT_INIT(inode); |
648 |
kumaneko |
2796 |
@@ -320,6 +324,10 @@ static long do_sys_ftruncate(unsigned in |
649 |
kumaneko |
1498 |
if (IS_APPEND(inode)) |
650 |
|
|
goto out_putf; |
651 |
|
|
|
652 |
kumaneko |
2297 |
+ error = ccs_check_truncate_permission(dentry, file->f_vfsmnt, length, |
653 |
|
|
+ 0); |
654 |
kumaneko |
1498 |
+ if (error) |
655 |
|
|
+ goto out_putf; |
656 |
|
|
error = locks_verify_truncate(inode, file, length); |
657 |
|
|
if (!error) |
658 |
|
|
error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, file); |
659 |
kumaneko |
2796 |
@@ -608,6 +616,10 @@ asmlinkage long sys_chroot(const char __ |
660 |
kumaneko |
1498 |
error = -EPERM; |
661 |
|
|
if (!capable(CAP_SYS_CHROOT)) |
662 |
|
|
goto dput_and_out; |
663 |
kumaneko |
2282 |
+ if (!ccs_capable(CCS_SYS_CHROOT)) |
664 |
kumaneko |
1498 |
+ goto dput_and_out; |
665 |
|
|
+ if (ccs_check_chroot_permission(&nd)) |
666 |
|
|
+ goto dput_and_out; |
667 |
|
|
|
668 |
|
|
set_fs_root(current->fs, nd.mnt, nd.dentry); |
669 |
|
|
set_fs_altroot(); |
670 |
kumaneko |
2796 |
@@ -1199,6 +1211,8 @@ EXPORT_SYMBOL(sys_close); |
671 |
kumaneko |
1498 |
*/ |
672 |
|
|
asmlinkage long sys_vhangup(void) |
673 |
|
|
{ |
674 |
kumaneko |
2282 |
+ if (!ccs_capable(CCS_SYS_VHANGUP)) |
675 |
kumaneko |
1498 |
+ return -EPERM; |
676 |
|
|
if (capable(CAP_SYS_TTY_CONFIG)) { |
677 |
|
|
tty_vhangup(current->signal->tty); |
678 |
|
|
return 0; |
679 |
kumaneko |
2513 |
--- linux-2.6.18-24etch2.orig/fs/proc/Makefile |
680 |
|
|
+++ linux-2.6.18-24etch2/fs/proc/Makefile |
681 |
kumaneko |
1498 |
@@ -13,3 +13,6 @@ proc-y += inode.o root.o base.o ge |
682 |
|
|
proc-$(CONFIG_PROC_KCORE) += kcore.o |
683 |
|
|
proc-$(CONFIG_PROC_VMCORE) += vmcore.o |
684 |
|
|
proc-$(CONFIG_PROC_DEVICETREE) += proc_devtree.o |
685 |
|
|
+ |
686 |
|
|
+proc-$(CONFIG_SAKURA) += ccs_proc.o |
687 |
|
|
+proc-$(CONFIG_TOMOYO) += ccs_proc.o |
688 |
kumaneko |
2513 |
--- linux-2.6.18-24etch2.orig/fs/proc/proc_misc.c |
689 |
|
|
+++ linux-2.6.18-24etch2/fs/proc/proc_misc.c |
690 |
kumaneko |
2796 |
@@ -723,4 +723,5 @@ void __init proc_misc_init(void) |
691 |
kumaneko |
1498 |
if (entry) |
692 |
|
|
entry->proc_fops = &proc_sysrq_trigger_operations; |
693 |
|
|
#endif |
694 |
kumaneko |
2796 |
+ printk(KERN_INFO "Hook version: 2.6.18-24etch2 2009/07/23\n"); |
695 |
kumaneko |
1498 |
} |
696 |
kumaneko |
2513 |
--- linux-2.6.18-24etch2.orig/include/linux/init_task.h |
697 |
|
|
+++ linux-2.6.18-24etch2/include/linux/init_task.h |
698 |
kumaneko |
2796 |
@@ -128,6 +128,8 @@ extern struct group_info init_groups; |
699 |
kumaneko |
1498 |
.pi_lock = SPIN_LOCK_UNLOCKED, \ |
700 |
|
|
INIT_TRACE_IRQFLAGS \ |
701 |
|
|
INIT_LOCKDEP \ |
702 |
kumaneko |
2282 |
+ .ccs_domain_info = NULL, \ |
703 |
|
|
+ .ccs_flags = 0, \ |
704 |
kumaneko |
1498 |
} |
705 |
|
|
|
706 |
|
|
|
707 |
kumaneko |
2513 |
--- linux-2.6.18-24etch2.orig/include/linux/sched.h |
708 |
|
|
+++ linux-2.6.18-24etch2/include/linux/sched.h |
709 |
kumaneko |
2796 |
@@ -25,6 +25,8 @@ |
710 |
kumaneko |
1498 |
#define CLONE_CHILD_SETTID 0x01000000 /* set the TID in the child */ |
711 |
|
|
#define CLONE_STOPPED 0x02000000 /* Start in stopped state */ |
712 |
|
|
|
713 |
kumaneko |
2282 |
+struct ccs_domain_info; |
714 |
kumaneko |
1498 |
+ |
715 |
|
|
/* |
716 |
|
|
* Scheduling policies |
717 |
|
|
*/ |
718 |
kumaneko |
2796 |
@@ -996,6 +998,8 @@ struct task_struct { |
719 |
kumaneko |
1498 |
#ifdef CONFIG_TASK_DELAY_ACCT |
720 |
|
|
struct task_delay_info *delays; |
721 |
|
|
#endif |
722 |
kumaneko |
2282 |
+ struct ccs_domain_info *ccs_domain_info; |
723 |
|
|
+ u32 ccs_flags; |
724 |
kumaneko |
1498 |
}; |
725 |
|
|
|
726 |
|
|
static inline pid_t process_group(struct task_struct *tsk) |
727 |
kumaneko |
2513 |
--- linux-2.6.18-24etch2.orig/kernel/compat.c |
728 |
|
|
+++ linux-2.6.18-24etch2/kernel/compat.c |
729 |
kumaneko |
2796 |
@@ -24,6 +24,7 @@ |
730 |
kumaneko |
1498 |
#include <linux/migrate.h> |
731 |
|
|
|
732 |
|
|
#include <asm/uaccess.h> |
733 |
|
|
+#include <linux/tomoyo.h> |
734 |
|
|
|
735 |
|
|
int get_compat_timespec(struct timespec *ts, const struct compat_timespec __user *cts) |
736 |
|
|
{ |
737 |
kumaneko |
2796 |
@@ -836,6 +837,8 @@ asmlinkage long compat_sys_stime(compat_ |
738 |
kumaneko |
1498 |
err = security_settime(&tv, NULL); |
739 |
|
|
if (err) |
740 |
|
|
return err; |
741 |
kumaneko |
2282 |
+ if (!ccs_capable(CCS_SYS_SETTIME)) |
742 |
kumaneko |
1498 |
+ return -EPERM; |
743 |
|
|
|
744 |
|
|
do_settimeofday(&tv); |
745 |
|
|
return 0; |
746 |
kumaneko |
2513 |
--- linux-2.6.18-24etch2.orig/kernel/kexec.c |
747 |
|
|
+++ linux-2.6.18-24etch2/kernel/kexec.c |
748 |
kumaneko |
2796 |
@@ -26,6 +26,7 @@ |
749 |
kumaneko |
1498 |
#include <asm/io.h> |
750 |
|
|
#include <asm/system.h> |
751 |
|
|
#include <asm/semaphore.h> |
752 |
|
|
+#include <linux/tomoyo.h> |
753 |
|
|
|
754 |
|
|
/* Per cpu memory for storing cpu states in case of system crash. */ |
755 |
|
|
note_buf_t* crash_notes; |
756 |
kumaneko |
2796 |
@@ -922,6 +923,8 @@ asmlinkage long sys_kexec_load(unsigned |
757 |
kumaneko |
1498 |
/* We only trust the superuser with rebooting the system. */ |
758 |
|
|
if (!capable(CAP_SYS_BOOT)) |
759 |
|
|
return -EPERM; |
760 |
kumaneko |
2282 |
+ if (!ccs_capable(CCS_SYS_KEXEC_LOAD)) |
761 |
kumaneko |
1498 |
+ return -EPERM; |
762 |
|
|
|
763 |
|
|
/* |
764 |
|
|
* Verify we have a legal set of flags |
765 |
kumaneko |
2513 |
--- linux-2.6.18-24etch2.orig/kernel/kmod.c |
766 |
|
|
+++ linux-2.6.18-24etch2/kernel/kmod.c |
767 |
kumaneko |
2796 |
@@ -148,6 +148,9 @@ static int ____call_usermodehelper(void |
768 |
kumaneko |
1498 |
/* We can run anywhere, unlike our parent keventd(). */ |
769 |
|
|
set_cpus_allowed(current, CPU_MASK_ALL); |
770 |
|
|
|
771 |
kumaneko |
2282 |
+ current->ccs_domain_info = NULL; |
772 |
|
|
+ current->ccs_flags = 0; |
773 |
kumaneko |
1498 |
+ |
774 |
|
|
retval = -EPERM; |
775 |
|
|
if (current->fs->root) |
776 |
|
|
retval = execve(sub_info->path, sub_info->argv,sub_info->envp); |
777 |
kumaneko |
2513 |
--- linux-2.6.18-24etch2.orig/kernel/module.c |
778 |
|
|
+++ linux-2.6.18-24etch2/kernel/module.c |
779 |
kumaneko |
2796 |
@@ -44,6 +44,7 @@ |
780 |
kumaneko |
1498 |
#include <asm/semaphore.h> |
781 |
|
|
#include <asm/cacheflush.h> |
782 |
|
|
#include <linux/license.h> |
783 |
|
|
+#include <linux/tomoyo.h> |
784 |
|
|
|
785 |
|
|
#if 0 |
786 |
|
|
#define DEBUGP printk |
787 |
kumaneko |
2796 |
@@ -652,7 +653,8 @@ sys_delete_module(const char __user *nam |
788 |
kumaneko |
1498 |
|
789 |
|
|
if (!capable(CAP_SYS_MODULE)) |
790 |
|
|
return -EPERM; |
791 |
|
|
- |
792 |
kumaneko |
2282 |
+ if (!ccs_capable(CCS_USE_KERNEL_MODULE)) |
793 |
kumaneko |
1498 |
+ return -EPERM; |
794 |
|
|
if (strncpy_from_user(name, name_user, MODULE_NAME_LEN-1) < 0) |
795 |
|
|
return -EFAULT; |
796 |
|
|
name[MODULE_NAME_LEN-1] = '\0'; |
797 |
kumaneko |
2796 |
@@ -1884,7 +1886,8 @@ sys_init_module(void __user *umod, |
798 |
kumaneko |
1498 |
/* Must have permission */ |
799 |
|
|
if (!capable(CAP_SYS_MODULE)) |
800 |
|
|
return -EPERM; |
801 |
|
|
- |
802 |
kumaneko |
2282 |
+ if (!ccs_capable(CCS_USE_KERNEL_MODULE)) |
803 |
kumaneko |
1498 |
+ return -EPERM; |
804 |
|
|
/* Only one module load at a time, please */ |
805 |
|
|
if (mutex_lock_interruptible(&module_mutex) != 0) |
806 |
|
|
return -EINTR; |
807 |
kumaneko |
2513 |
--- linux-2.6.18-24etch2.orig/kernel/ptrace.c |
808 |
|
|
+++ linux-2.6.18-24etch2/kernel/ptrace.c |
809 |
kumaneko |
2796 |
@@ -21,6 +21,7 @@ |
810 |
kumaneko |
1498 |
|
811 |
|
|
#include <asm/pgtable.h> |
812 |
|
|
#include <asm/uaccess.h> |
813 |
|
|
+#include <linux/tomoyo.h> |
814 |
|
|
|
815 |
|
|
/* |
816 |
|
|
* ptrace a task: make the debugger its new parent and |
817 |
kumaneko |
2796 |
@@ -509,6 +510,8 @@ asmlinkage long sys_ptrace(long request, |
818 |
kumaneko |
1498 |
/* |
819 |
|
|
* This lock_kernel fixes a subtle race with suid exec |
820 |
|
|
*/ |
821 |
kumaneko |
2282 |
+ if (!ccs_capable(CCS_SYS_PTRACE)) |
822 |
kumaneko |
1498 |
+ return -EPERM; |
823 |
|
|
lock_kernel(); |
824 |
|
|
if (request == PTRACE_TRACEME) { |
825 |
|
|
ret = ptrace_traceme(); |
826 |
kumaneko |
2513 |
--- linux-2.6.18-24etch2.orig/kernel/sched.c |
827 |
|
|
+++ linux-2.6.18-24etch2/kernel/sched.c |
828 |
kumaneko |
2796 |
@@ -55,6 +55,7 @@ |
829 |
kumaneko |
1498 |
#include <asm/tlb.h> |
830 |
|
|
|
831 |
|
|
#include <asm/unistd.h> |
832 |
|
|
+#include <linux/tomoyo.h> |
833 |
|
|
|
834 |
|
|
/* |
835 |
|
|
* Convert user-nice values [ -20 ... 0 ... 19 ] |
836 |
kumaneko |
2796 |
@@ -3939,6 +3940,8 @@ int can_nice(const struct task_struct *p |
837 |
kumaneko |
1498 |
asmlinkage long sys_nice(int increment) |
838 |
|
|
{ |
839 |
|
|
long nice, retval; |
840 |
kumaneko |
2282 |
+ if (!ccs_capable(CCS_SYS_NICE)) |
841 |
kumaneko |
1498 |
+ return -EPERM; |
842 |
|
|
|
843 |
|
|
/* |
844 |
|
|
* Setpriority might change our priority at the same moment. |
845 |
kumaneko |
2513 |
--- linux-2.6.18-24etch2.orig/kernel/signal.c |
846 |
|
|
+++ linux-2.6.18-24etch2/kernel/signal.c |
847 |
kumaneko |
2796 |
@@ -28,6 +28,7 @@ |
848 |
kumaneko |
1498 |
#include <asm/unistd.h> |
849 |
|
|
#include <asm/siginfo.h> |
850 |
|
|
#include "audit.h" /* audit_signal_info() */ |
851 |
|
|
+#include <linux/tomoyo.h> |
852 |
|
|
|
853 |
|
|
/* |
854 |
|
|
* SLAB caches for signal bits. |
855 |
kumaneko |
2796 |
@@ -2183,6 +2184,10 @@ asmlinkage long |
856 |
kumaneko |
1498 |
sys_kill(int pid, int sig) |
857 |
|
|
{ |
858 |
|
|
struct siginfo info; |
859 |
kumaneko |
2282 |
+ if (sig && !ccs_capable(CCS_SYS_KILL)) |
860 |
kumaneko |
1498 |
+ return -EPERM; |
861 |
|
|
+ if (sig && ccs_check_signal_acl(sig, pid)) |
862 |
|
|
+ return -EPERM; |
863 |
|
|
|
864 |
|
|
info.si_signo = sig; |
865 |
|
|
info.si_errno = 0; |
866 |
kumaneko |
2796 |
@@ -2241,6 +2246,10 @@ asmlinkage long sys_tgkill(int tgid, int |
867 |
kumaneko |
1498 |
/* This is only valid for single tasks */ |
868 |
|
|
if (pid <= 0 || tgid <= 0) |
869 |
|
|
return -EINVAL; |
870 |
kumaneko |
2282 |
+ if (sig && !ccs_capable(CCS_SYS_KILL)) |
871 |
kumaneko |
1498 |
+ return -EPERM; |
872 |
|
|
+ if (sig && ccs_check_signal_acl(sig, pid)) |
873 |
|
|
+ return -EPERM; |
874 |
|
|
|
875 |
|
|
return do_tkill(tgid, pid, sig); |
876 |
|
|
} |
877 |
kumaneko |
2796 |
@@ -2254,6 +2263,10 @@ sys_tkill(int pid, int sig) |
878 |
kumaneko |
1498 |
/* This is only valid for single tasks */ |
879 |
|
|
if (pid <= 0) |
880 |
|
|
return -EINVAL; |
881 |
kumaneko |
2282 |
+ if (sig && !ccs_capable(CCS_SYS_KILL)) |
882 |
kumaneko |
1498 |
+ return -EPERM; |
883 |
|
|
+ if (sig && ccs_check_signal_acl(sig, pid)) |
884 |
|
|
+ return -EPERM; |
885 |
|
|
|
886 |
|
|
return do_tkill(0, pid, sig); |
887 |
|
|
} |
888 |
kumaneko |
2513 |
--- linux-2.6.18-24etch2.orig/kernel/sys.c |
889 |
|
|
+++ linux-2.6.18-24etch2/kernel/sys.c |
890 |
kumaneko |
2796 |
@@ -36,6 +36,7 @@ |
891 |
kumaneko |
1498 |
#include <asm/uaccess.h> |
892 |
|
|
#include <asm/io.h> |
893 |
|
|
#include <asm/unistd.h> |
894 |
|
|
+#include <linux/tomoyo.h> |
895 |
|
|
|
896 |
|
|
#ifndef SET_UNALIGN_CTL |
897 |
|
|
# define SET_UNALIGN_CTL(a,b) (-EINVAL) |
898 |
kumaneko |
2796 |
@@ -467,6 +468,10 @@ asmlinkage long sys_setpriority(int whic |
899 |
kumaneko |
1498 |
|
900 |
|
|
if (which > 2 || which < 0) |
901 |
|
|
goto out; |
902 |
kumaneko |
2282 |
+ if (!ccs_capable(CCS_SYS_NICE)) { |
903 |
kumaneko |
1498 |
+ error = -EPERM; |
904 |
|
|
+ goto out; |
905 |
|
|
+ } |
906 |
|
|
|
907 |
|
|
/* normalize: avoid signed division (rounding problems) */ |
908 |
|
|
error = -ESRCH; |
909 |
kumaneko |
2796 |
@@ -693,6 +698,8 @@ asmlinkage long sys_reboot(int magic1, i |
910 |
kumaneko |
1498 |
magic2 != LINUX_REBOOT_MAGIC2B && |
911 |
|
|
magic2 != LINUX_REBOOT_MAGIC2C)) |
912 |
|
|
return -EINVAL; |
913 |
kumaneko |
2282 |
+ if (!ccs_capable(CCS_SYS_REBOOT)) |
914 |
kumaneko |
1498 |
+ return -EPERM; |
915 |
|
|
|
916 |
|
|
/* Instead of trying to make the power_off code look like |
917 |
|
|
* halt when pm_power_off is not set do it the easy way. |
918 |
kumaneko |
2796 |
@@ -1690,6 +1697,8 @@ asmlinkage long sys_sethostname(char __u |
919 |
kumaneko |
1498 |
return -EPERM; |
920 |
|
|
if (len < 0 || len > __NEW_UTS_LEN) |
921 |
|
|
return -EINVAL; |
922 |
kumaneko |
2282 |
+ if (!ccs_capable(CCS_SYS_SETHOSTNAME)) |
923 |
kumaneko |
1498 |
+ return -EPERM; |
924 |
|
|
down_write(&uts_sem); |
925 |
|
|
errno = -EFAULT; |
926 |
|
|
if (!copy_from_user(tmp, name, len)) { |
927 |
kumaneko |
2796 |
@@ -1735,6 +1744,8 @@ asmlinkage long sys_setdomainname(char _ |
928 |
kumaneko |
1498 |
return -EPERM; |
929 |
|
|
if (len < 0 || len > __NEW_UTS_LEN) |
930 |
|
|
return -EINVAL; |
931 |
kumaneko |
2282 |
+ if (!ccs_capable(CCS_SYS_SETHOSTNAME)) |
932 |
kumaneko |
1498 |
+ return -EPERM; |
933 |
|
|
|
934 |
|
|
down_write(&uts_sem); |
935 |
|
|
errno = -EFAULT; |
936 |
kumaneko |
2513 |
--- linux-2.6.18-24etch2.orig/kernel/sysctl.c |
937 |
|
|
+++ linux-2.6.18-24etch2/kernel/sysctl.c |
938 |
kumaneko |
2796 |
@@ -48,6 +48,7 @@ |
939 |
kumaneko |
1498 |
|
940 |
|
|
#include <asm/uaccess.h> |
941 |
|
|
#include <asm/processor.h> |
942 |
|
|
+#include <linux/tomoyo.h> |
943 |
|
|
|
944 |
|
|
extern int proc_nr_files(ctl_table *table, int write, struct file *filp, |
945 |
|
|
void __user *buffer, size_t *lenp, loff_t *ppos); |
946 |
kumaneko |
2796 |
@@ -1169,6 +1170,9 @@ int do_sysctl(int __user *name, int nlen |
947 |
kumaneko |
1498 |
|
948 |
|
|
spin_unlock(&sysctl_lock); |
949 |
|
|
|
950 |
kumaneko |
2298 |
+ error = ccs_parse_table(name, nlen, oldval, newval, |
951 |
kumaneko |
1498 |
+ head->ctl_table); |
952 |
|
|
+ if (!error) |
953 |
|
|
error = parse_table(name, nlen, oldval, oldlenp, |
954 |
|
|
newval, newlen, head->ctl_table, |
955 |
|
|
&context); |
956 |
kumaneko |
2796 |
@@ -1241,6 +1245,13 @@ repeat: |
957 |
kumaneko |
1498 |
if (ctl_perm(table, 001)) |
958 |
|
|
return -EPERM; |
959 |
|
|
if (table->strategy) { |
960 |
|
|
+ int op = 0; |
961 |
|
|
+ if (oldval) |
962 |
|
|
+ op |= 004; |
963 |
|
|
+ if (newval) |
964 |
|
|
+ op |= 002; |
965 |
|
|
+ if (ctl_perm(table, op)) |
966 |
|
|
+ return -EPERM; |
967 |
|
|
error = table->strategy( |
968 |
|
|
table, name, nlen, |
969 |
|
|
oldval, oldlenp, |
970 |
kumaneko |
2513 |
--- linux-2.6.18-24etch2.orig/kernel/time.c |
971 |
|
|
+++ linux-2.6.18-24etch2/kernel/time.c |
972 |
kumaneko |
2796 |
@@ -39,6 +39,7 @@ |
973 |
kumaneko |
1498 |
|
974 |
|
|
#include <asm/uaccess.h> |
975 |
|
|
#include <asm/unistd.h> |
976 |
|
|
+#include <linux/tomoyo.h> |
977 |
|
|
|
978 |
|
|
/* |
979 |
|
|
* The timezone where the local system is located. Used as a default by some |
980 |
kumaneko |
2796 |
@@ -91,6 +92,8 @@ asmlinkage long sys_stime(time_t __user |
981 |
kumaneko |
1498 |
err = security_settime(&tv, NULL); |
982 |
|
|
if (err) |
983 |
|
|
return err; |
984 |
kumaneko |
2282 |
+ if (!ccs_capable(CCS_SYS_SETTIME)) |
985 |
kumaneko |
1498 |
+ return -EPERM; |
986 |
|
|
|
987 |
|
|
do_settimeofday(&tv); |
988 |
|
|
return 0; |
989 |
kumaneko |
2796 |
@@ -161,6 +164,8 @@ int do_sys_settimeofday(struct timespec |
990 |
kumaneko |
1498 |
error = security_settime(tv, tz); |
991 |
|
|
if (error) |
992 |
|
|
return error; |
993 |
kumaneko |
2282 |
+ if (!ccs_capable(CCS_SYS_SETTIME)) |
994 |
kumaneko |
1498 |
+ return -EPERM; |
995 |
|
|
|
996 |
|
|
if (tz) { |
997 |
|
|
/* SMP safe, global irq locking makes it work. */ |
998 |
kumaneko |
2796 |
@@ -221,6 +226,8 @@ int do_adjtimex(struct timex *txc) |
999 |
kumaneko |
1498 |
/* In order to modify anything, you gotta be super-user! */ |
1000 |
|
|
if (txc->modes && !capable(CAP_SYS_TIME)) |
1001 |
|
|
return -EPERM; |
1002 |
kumaneko |
2282 |
+ if (txc->modes && !ccs_capable(CCS_SYS_SETTIME)) |
1003 |
kumaneko |
1498 |
+ return -EPERM; |
1004 |
|
|
|
1005 |
|
|
/* Now we validate the data before disabling interrupts */ |
1006 |
|
|
|
1007 |
kumaneko |
2513 |
--- linux-2.6.18-24etch2.orig/net/ipv4/inet_connection_sock.c |
1008 |
|
|
+++ linux-2.6.18-24etch2/net/ipv4/inet_connection_sock.c |
1009 |
kumaneko |
2796 |
@@ -23,6 +23,7 @@ |
1010 |
kumaneko |
1498 |
#include <net/route.h> |
1011 |
|
|
#include <net/tcp_states.h> |
1012 |
|
|
#include <net/xfrm.h> |
1013 |
|
|
+#include <linux/sakura.h> |
1014 |
|
|
|
1015 |
|
|
#ifdef INET_CSK_DEBUG |
1016 |
|
|
const char inet_csk_timer_bug_msg[] = "inet_csk BUG: unknown timer value\n"; |
1017 |
kumaneko |
2796 |
@@ -87,6 +88,8 @@ int inet_csk_get_port(struct inet_hashin |
1018 |
kumaneko |
1498 |
do { |
1019 |
|
|
head = &hashinfo->bhash[inet_bhashfn(rover, hashinfo->bhash_size)]; |
1020 |
|
|
spin_lock(&head->lock); |
1021 |
kumaneko |
2299 |
+ if (ccs_lport_reserved(rover)) |
1022 |
kumaneko |
1498 |
+ goto next; |
1023 |
|
|
inet_bind_bucket_for_each(tb, node, &head->chain) |
1024 |
|
|
if (tb->port == rover) |
1025 |
|
|
goto next; |
1026 |
kumaneko |
2513 |
--- linux-2.6.18-24etch2.orig/net/ipv4/inet_hashtables.c |
1027 |
|
|
+++ linux-2.6.18-24etch2/net/ipv4/inet_hashtables.c |
1028 |
kumaneko |
2796 |
@@ -22,6 +22,7 @@ |
1029 |
kumaneko |
1498 |
#include <net/inet_connection_sock.h> |
1030 |
|
|
#include <net/inet_hashtables.h> |
1031 |
|
|
#include <net/ip.h> |
1032 |
|
|
+#include <linux/sakura.h> |
1033 |
|
|
|
1034 |
|
|
/* |
1035 |
|
|
* Allocate and initialize a new local port bind bucket. |
1036 |
kumaneko |
2796 |
@@ -263,6 +264,8 @@ int inet_hash_connect(struct inet_timewa |
1037 |
kumaneko |
1498 |
local_bh_disable(); |
1038 |
|
|
for (i = 1; i <= range; i++) { |
1039 |
|
|
port = low + (i + offset) % range; |
1040 |
kumaneko |
2299 |
+ if (ccs_lport_reserved(port)) |
1041 |
kumaneko |
1498 |
+ continue; |
1042 |
|
|
head = &hinfo->bhash[inet_bhashfn(port, hinfo->bhash_size)]; |
1043 |
|
|
spin_lock(&head->lock); |
1044 |
|
|
|
1045 |
kumaneko |
2513 |
--- linux-2.6.18-24etch2.orig/net/ipv4/raw.c |
1046 |
|
|
+++ linux-2.6.18-24etch2/net/ipv4/raw.c |
1047 |
kumaneko |
2796 |
@@ -79,6 +79,7 @@ |
1048 |
kumaneko |
2459 |
#include <linux/seq_file.h> |
1049 |
|
|
#include <linux/netfilter.h> |
1050 |
|
|
#include <linux/netfilter_ipv4.h> |
1051 |
|
|
+#include <linux/tomoyo_socket.h> |
1052 |
|
|
|
1053 |
|
|
struct hlist_head raw_v4_htable[RAWV4_HTABLE_SIZE]; |
1054 |
|
|
DEFINE_RWLOCK(raw_v4_lock); |
1055 |
kumaneko |
2796 |
@@ -592,6 +593,9 @@ static int raw_recvmsg(struct kiocb *ioc |
1056 |
kumaneko |
2459 |
skb = skb_recv_datagram(sk, flags, noblock, &err); |
1057 |
|
|
if (!skb) |
1058 |
|
|
goto out; |
1059 |
|
|
+ err = ccs_socket_recvmsg_permission(sk, skb, flags); |
1060 |
|
|
+ if (err) |
1061 |
|
|
+ goto out; |
1062 |
|
|
|
1063 |
|
|
copied = skb->len; |
1064 |
|
|
if (len < copied) { |
1065 |
kumaneko |
2513 |
--- linux-2.6.18-24etch2.orig/net/ipv4/udp.c |
1066 |
|
|
+++ linux-2.6.18-24etch2/net/ipv4/udp.c |
1067 |
kumaneko |
2796 |
@@ -108,6 +108,8 @@ |
1068 |
kumaneko |
1498 |
#include <net/inet_common.h> |
1069 |
|
|
#include <net/checksum.h> |
1070 |
|
|
#include <net/xfrm.h> |
1071 |
|
|
+#include <linux/sakura.h> |
1072 |
kumaneko |
2459 |
+#include <linux/tomoyo_socket.h> |
1073 |
kumaneko |
1498 |
|
1074 |
|
|
/* |
1075 |
|
|
* Snmp MIB for the UDP layer |
1076 |
kumaneko |
2796 |
@@ -146,6 +148,8 @@ static int udp_v4_get_port(struct sock * |
1077 |
kumaneko |
1498 |
result = sysctl_local_port_range[0] + |
1078 |
|
|
((result - sysctl_local_port_range[0]) & |
1079 |
|
|
(UDP_HTABLE_SIZE - 1)); |
1080 |
kumaneko |
2299 |
+ if (ccs_lport_reserved(result)) |
1081 |
kumaneko |
1498 |
+ continue; |
1082 |
|
|
goto gotit; |
1083 |
|
|
} |
1084 |
|
|
size = 0; |
1085 |
kumaneko |
2796 |
@@ -162,6 +166,8 @@ static int udp_v4_get_port(struct sock * |
1086 |
kumaneko |
1498 |
result = sysctl_local_port_range[0] |
1087 |
|
|
+ ((result - sysctl_local_port_range[0]) & |
1088 |
|
|
(UDP_HTABLE_SIZE - 1)); |
1089 |
kumaneko |
2299 |
+ if (ccs_lport_reserved(result)) |
1090 |
kumaneko |
1498 |
+ continue; |
1091 |
|
|
if (!udp_lport_inuse(result)) |
1092 |
|
|
break; |
1093 |
|
|
} |
1094 |
kumaneko |
2796 |
@@ -796,7 +802,10 @@ try_again: |
1095 |
kumaneko |
2459 |
skb = skb_recv_datagram(sk, flags, noblock, &err); |
1096 |
|
|
if (!skb) |
1097 |
|
|
goto out; |
1098 |
|
|
- |
1099 |
|
|
+ err = ccs_socket_recvmsg_permission(sk, skb, flags); |
1100 |
|
|
+ if (err) |
1101 |
|
|
+ goto out; |
1102 |
|
|
+ |
1103 |
|
|
copied = skb->len - sizeof(struct udphdr); |
1104 |
|
|
if (copied > len) { |
1105 |
|
|
copied = len; |
1106 |
kumaneko |
2513 |
--- linux-2.6.18-24etch2.orig/net/ipv6/inet6_hashtables.c |
1107 |
|
|
+++ linux-2.6.18-24etch2/net/ipv6/inet6_hashtables.c |
1108 |
kumaneko |
2796 |
@@ -21,6 +21,7 @@ |
1109 |
kumaneko |
1498 |
#include <net/inet_hashtables.h> |
1110 |
|
|
#include <net/inet6_hashtables.h> |
1111 |
|
|
#include <net/ip.h> |
1112 |
|
|
+#include <linux/sakura.h> |
1113 |
|
|
|
1114 |
|
|
void __inet6_hash(struct inet_hashinfo *hashinfo, |
1115 |
|
|
struct sock *sk) |
1116 |
kumaneko |
2796 |
@@ -172,7 +173,7 @@ static int __inet6_check_established(str |
1117 |
kumaneko |
1498 |
const struct in6_addr *saddr = &np->daddr; |
1118 |
|
|
const int dif = sk->sk_bound_dev_if; |
1119 |
|
|
const u32 ports = INET_COMBINED_PORTS(inet->dport, lport); |
1120 |
|
|
- const unsigned int hash = inet6_ehashfn(daddr, inet->num, saddr, |
1121 |
|
|
+ const unsigned int hash = inet6_ehashfn(daddr, lport, saddr, |
1122 |
|
|
inet->dport); |
1123 |
|
|
struct inet_ehash_bucket *head = inet_ehash_bucket(hinfo, hash); |
1124 |
|
|
struct sock *sk2; |
1125 |
kumaneko |
2796 |
@@ -266,6 +267,8 @@ int inet6_hash_connect(struct inet_timew |
1126 |
kumaneko |
1498 |
local_bh_disable(); |
1127 |
|
|
for (i = 1; i <= range; i++) { |
1128 |
|
|
port = low + (i + offset) % range; |
1129 |
kumaneko |
2299 |
+ if (ccs_lport_reserved(port)) |
1130 |
kumaneko |
1498 |
+ continue; |
1131 |
|
|
head = &hinfo->bhash[inet_bhashfn(port, hinfo->bhash_size)]; |
1132 |
|
|
spin_lock(&head->lock); |
1133 |
|
|
|
1134 |
kumaneko |
2513 |
--- linux-2.6.18-24etch2.orig/net/ipv6/raw.c |
1135 |
|
|
+++ linux-2.6.18-24etch2/net/ipv6/raw.c |
1136 |
kumaneko |
2796 |
@@ -56,6 +56,7 @@ |
1137 |
kumaneko |
2459 |
|
1138 |
|
|
#include <linux/proc_fs.h> |
1139 |
|
|
#include <linux/seq_file.h> |
1140 |
|
|
+#include <linux/tomoyo_socket.h> |
1141 |
|
|
|
1142 |
|
|
struct hlist_head raw_v6_htable[RAWV6_HTABLE_SIZE]; |
1143 |
|
|
DEFINE_RWLOCK(raw_v6_lock); |
1144 |
kumaneko |
2796 |
@@ -387,6 +388,9 @@ static int rawv6_recvmsg(struct kiocb *i |
1145 |
kumaneko |
2459 |
skb = skb_recv_datagram(sk, flags, noblock, &err); |
1146 |
|
|
if (!skb) |
1147 |
|
|
goto out; |
1148 |
|
|
+ err = ccs_socket_recvmsg_permission(sk, skb, flags); |
1149 |
|
|
+ if (err) |
1150 |
|
|
+ goto out; |
1151 |
|
|
|
1152 |
|
|
copied = skb->len; |
1153 |
|
|
if (copied > len) { |
1154 |
kumaneko |
2513 |
--- linux-2.6.18-24etch2.orig/net/ipv6/udp.c |
1155 |
|
|
+++ linux-2.6.18-24etch2/net/ipv6/udp.c |
1156 |
kumaneko |
2796 |
@@ -58,6 +58,8 @@ |
1157 |
kumaneko |
1498 |
|
1158 |
|
|
#include <linux/proc_fs.h> |
1159 |
|
|
#include <linux/seq_file.h> |
1160 |
|
|
+#include <linux/sakura.h> |
1161 |
kumaneko |
2459 |
+#include <linux/tomoyo_socket.h> |
1162 |
kumaneko |
1498 |
|
1163 |
|
|
DEFINE_SNMP_STAT(struct udp_mib, udp_stats_in6) __read_mostly; |
1164 |
|
|
|
1165 |
kumaneko |
2796 |
@@ -88,6 +90,8 @@ static int udp_v6_get_port(struct sock * |
1166 |
kumaneko |
1498 |
result = sysctl_local_port_range[0] + |
1167 |
|
|
((result - sysctl_local_port_range[0]) & |
1168 |
|
|
(UDP_HTABLE_SIZE - 1)); |
1169 |
kumaneko |
2299 |
+ if (ccs_lport_reserved(result)) |
1170 |
kumaneko |
1498 |
+ continue; |
1171 |
|
|
goto gotit; |
1172 |
|
|
} |
1173 |
|
|
size = 0; |
1174 |
kumaneko |
2796 |
@@ -104,6 +108,8 @@ static int udp_v6_get_port(struct sock * |
1175 |
kumaneko |
1498 |
result = sysctl_local_port_range[0] |
1176 |
|
|
+ ((result - sysctl_local_port_range[0]) & |
1177 |
|
|
(UDP_HTABLE_SIZE - 1)); |
1178 |
kumaneko |
2299 |
+ if (ccs_lport_reserved(result)) |
1179 |
kumaneko |
1498 |
+ continue; |
1180 |
|
|
if (!udp_lport_inuse(result)) |
1181 |
|
|
break; |
1182 |
|
|
} |
1183 |
kumaneko |
2796 |
@@ -237,6 +243,9 @@ try_again: |
1184 |
kumaneko |
2459 |
skb = skb_recv_datagram(sk, flags, noblock, &err); |
1185 |
|
|
if (!skb) |
1186 |
|
|
goto out; |
1187 |
|
|
+ err = ccs_socket_recvmsg_permission(sk, skb, flags); |
1188 |
|
|
+ if (err) |
1189 |
|
|
+ goto out; |
1190 |
|
|
|
1191 |
|
|
copied = skb->len - sizeof(struct udphdr); |
1192 |
|
|
if (copied > len) { |
1193 |
kumaneko |
2513 |
--- linux-2.6.18-24etch2.orig/net/socket.c |
1194 |
|
|
+++ linux-2.6.18-24etch2/net/socket.c |
1195 |
kumaneko |
2796 |
@@ -94,6 +94,9 @@ |
1196 |
kumaneko |
1498 |
#include <net/sock.h> |
1197 |
|
|
#include <linux/netfilter.h> |
1198 |
|
|
|
1199 |
|
|
+#include <linux/tomoyo.h> |
1200 |
|
|
+#include <linux/tomoyo_socket.h> |
1201 |
|
|
+ |
1202 |
|
|
static int sock_no_open(struct inode *irrelevant, struct file *dontcare); |
1203 |
|
|
static ssize_t sock_aio_read(struct kiocb *iocb, char __user *buf, |
1204 |
|
|
size_t size, loff_t pos); |
1205 |
kumaneko |
2805 |
@@ -590,9 +593,12 @@ static inline int __sock_sendmsg(struct |
1206 |
|
|
si->size = size; |
1207 |
|
|
|
1208 |
kumaneko |
1498 |
err = security_socket_sendmsg(sock, msg, size); |
1209 |
kumaneko |
2805 |
+ if (!err) |
1210 |
|
|
+ err = ccs_socket_sendmsg_permission(sock, (struct sockaddr *) |
1211 |
|
|
+ msg->msg_name, |
1212 |
|
|
+ msg->msg_namelen); |
1213 |
kumaneko |
1498 |
if (err) |
1214 |
|
|
return err; |
1215 |
|
|
- |
1216 |
|
|
return sock->ops->sendmsg(iocb, sock, msg, size); |
1217 |
|
|
} |
1218 |
|
|
|
1219 |
kumaneko |
2805 |
@@ -1149,6 +1155,8 @@ static int __sock_create(int family, int |
1220 |
kumaneko |
1498 |
} |
1221 |
|
|
|
1222 |
|
|
err = security_socket_create(family, type, protocol, kern); |
1223 |
kumaneko |
2805 |
+ if (!err) |
1224 |
|
|
+ err = ccs_socket_create_permission(family, type, protocol); |
1225 |
kumaneko |
1498 |
if (err) |
1226 |
|
|
return err; |
1227 |
kumaneko |
2805 |
|
1228 |
|
|
@@ -1343,6 +1351,11 @@ asmlinkage long sys_bind(int fd, struct |
1229 |
kumaneko |
1498 |
if((err=move_addr_to_kernel(umyaddr,addrlen,address))>=0) { |
1230 |
|
|
err = security_socket_bind(sock, (struct sockaddr *)address, addrlen); |
1231 |
kumaneko |
2796 |
if (!err) |
1232 |
kumaneko |
1498 |
+ err = ccs_socket_bind_permission(sock, |
1233 |
|
|
+ (struct sockaddr *) |
1234 |
|
|
+ address, |
1235 |
|
|
+ addrlen); |
1236 |
kumaneko |
2796 |
+ if (!err) |
1237 |
kumaneko |
1498 |
err = sock->ops->bind(sock, |
1238 |
|
|
(struct sockaddr *)address, addrlen); |
1239 |
kumaneko |
2796 |
} |
1240 |
kumaneko |
2805 |
@@ -1371,6 +1384,8 @@ asmlinkage long sys_listen(int fd, int b |
1241 |
kumaneko |
1498 |
|
1242 |
|
|
err = security_socket_listen(sock, backlog); |
1243 |
kumaneko |
2796 |
if (!err) |
1244 |
|
|
+ err = ccs_socket_listen_permission(sock); |
1245 |
kumaneko |
1498 |
+ if (!err) |
1246 |
|
|
err = sock->ops->listen(sock, backlog); |
1247 |
|
|
|
1248 |
kumaneko |
2796 |
fput_light(sock->file, fput_needed); |
1249 |
kumaneko |
2805 |
@@ -1434,6 +1449,11 @@ asmlinkage long sys_accept(int fd, struc |
1250 |
kumaneko |
1498 |
if (err < 0) |
1251 |
|
|
goto out_fd; |
1252 |
|
|
|
1253 |
|
|
+ if (ccs_socket_accept_permission(newsock, |
1254 |
|
|
+ (struct sockaddr *) address)) { |
1255 |
|
|
+ err = -ECONNABORTED; /* Hope less harmful than -EPERM. */ |
1256 |
|
|
+ goto out_fd; |
1257 |
|
|
+ } |
1258 |
|
|
if (upeer_sockaddr) { |
1259 |
|
|
if(newsock->ops->getname(newsock, (struct sockaddr *)address, &len, 2)<0) { |
1260 |
|
|
err = -ECONNABORTED; |
1261 |
kumaneko |
2805 |
@@ -1488,9 +1508,11 @@ asmlinkage long sys_connect(int fd, stru |
1262 |
|
|
goto out_put; |
1263 |
|
|
|
1264 |
kumaneko |
1498 |
err = security_socket_connect(sock, (struct sockaddr *)address, addrlen); |
1265 |
kumaneko |
2805 |
+ if (!err) |
1266 |
|
|
+ err = ccs_socket_connect_permission(sock, (struct sockaddr *) |
1267 |
|
|
+ address, addrlen); |
1268 |
kumaneko |
1498 |
if (err) |
1269 |
|
|
goto out_put; |
1270 |
|
|
- |
1271 |
|
|
err = sock->ops->connect(sock, (struct sockaddr *) address, addrlen, |
1272 |
|
|
sock->file->f_flags); |
1273 |
|
|
out_put: |
1274 |
kumaneko |
2513 |
--- linux-2.6.18-24etch2.orig/net/unix/af_unix.c |
1275 |
|
|
+++ linux-2.6.18-24etch2/net/unix/af_unix.c |
1276 |
kumaneko |
2796 |
@@ -116,6 +116,7 @@ |
1277 |
kumaneko |
1498 |
#include <linux/mount.h> |
1278 |
|
|
#include <net/checksum.h> |
1279 |
|
|
#include <linux/security.h> |
1280 |
|
|
+#include <linux/tomoyo.h> |
1281 |
|
|
|
1282 |
|
|
int sysctl_unix_max_dgram_qlen = 10; |
1283 |
|
|
|
1284 |
kumaneko |
2796 |
@@ -807,6 +808,9 @@ static int unix_bind(struct socket *sock |
1285 |
kumaneko |
1498 |
*/ |
1286 |
|
|
mode = S_IFSOCK | |
1287 |
|
|
(SOCK_INODE(sock)->i_mode & ~current->fs->umask); |
1288 |
kumaneko |
2297 |
+ err = ccs_check_mknod_permission(nd.dentry->d_inode, dentry, |
1289 |
|
|
+ nd.mnt, mode, 0); |
1290 |
kumaneko |
1498 |
+ if (!err) |
1291 |
|
|
err = vfs_mknod(nd.dentry->d_inode, dentry, mode, 0); |
1292 |
|
|
if (err) |
1293 |
|
|
goto out_mknod_dput; |