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