aboutsummaryrefslogtreecommitdiffstats
path: root/security/selinux/hooks.c
diff options
context:
space:
mode:
authorJeff Garzik <jgarzik@pobox.com>2006-02-07 01:47:12 -0500
committerJeff Garzik <jgarzik@pobox.com>2006-02-07 01:47:12 -0500
commit3c9b3a8575b4f2551e3b5b74ffa1c3559c6338eb (patch)
tree7f8d84353852401ec74e005f6f0b1eb958b9a70d /security/selinux/hooks.c
parentc0d3c0c0ce94d3db893577ae98e64414d92e49d8 (diff)
parentc03296a868ae7c91aa2d8b372184763b18f16d7a (diff)
Merge branch 'master'
Diffstat (limited to 'security/selinux/hooks.c')
-rw-r--r--security/selinux/hooks.c122
1 files changed, 30 insertions, 92 deletions
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index b9f8d9731c3d..b7773bf68efa 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -127,7 +127,6 @@ static int task_alloc_security(struct task_struct *task)
127 if (!tsec) 127 if (!tsec)
128 return -ENOMEM; 128 return -ENOMEM;
129 129
130 tsec->magic = SELINUX_MAGIC;
131 tsec->task = task; 130 tsec->task = task;
132 tsec->osid = tsec->sid = tsec->ptrace_sid = SECINITSID_UNLABELED; 131 tsec->osid = tsec->sid = tsec->ptrace_sid = SECINITSID_UNLABELED;
133 task->security = tsec; 132 task->security = tsec;
@@ -138,10 +137,6 @@ static int task_alloc_security(struct task_struct *task)
138static void task_free_security(struct task_struct *task) 137static void task_free_security(struct task_struct *task)
139{ 138{
140 struct task_security_struct *tsec = task->security; 139 struct task_security_struct *tsec = task->security;
141
142 if (!tsec || tsec->magic != SELINUX_MAGIC)
143 return;
144
145 task->security = NULL; 140 task->security = NULL;
146 kfree(tsec); 141 kfree(tsec);
147} 142}
@@ -157,14 +152,10 @@ static int inode_alloc_security(struct inode *inode)
157 152
158 init_MUTEX(&isec->sem); 153 init_MUTEX(&isec->sem);
159 INIT_LIST_HEAD(&isec->list); 154 INIT_LIST_HEAD(&isec->list);
160 isec->magic = SELINUX_MAGIC;
161 isec->inode = inode; 155 isec->inode = inode;
162 isec->sid = SECINITSID_UNLABELED; 156 isec->sid = SECINITSID_UNLABELED;
163 isec->sclass = SECCLASS_FILE; 157 isec->sclass = SECCLASS_FILE;
164 if (tsec && tsec->magic == SELINUX_MAGIC) 158 isec->task_sid = tsec->sid;
165 isec->task_sid = tsec->sid;
166 else
167 isec->task_sid = SECINITSID_UNLABELED;
168 inode->i_security = isec; 159 inode->i_security = isec;
169 160
170 return 0; 161 return 0;
@@ -175,9 +166,6 @@ static void inode_free_security(struct inode *inode)
175 struct inode_security_struct *isec = inode->i_security; 166 struct inode_security_struct *isec = inode->i_security;
176 struct superblock_security_struct *sbsec = inode->i_sb->s_security; 167 struct superblock_security_struct *sbsec = inode->i_sb->s_security;
177 168
178 if (!isec || isec->magic != SELINUX_MAGIC)
179 return;
180
181 spin_lock(&sbsec->isec_lock); 169 spin_lock(&sbsec->isec_lock);
182 if (!list_empty(&isec->list)) 170 if (!list_empty(&isec->list))
183 list_del_init(&isec->list); 171 list_del_init(&isec->list);
@@ -192,19 +180,13 @@ static int file_alloc_security(struct file *file)
192 struct task_security_struct *tsec = current->security; 180 struct task_security_struct *tsec = current->security;
193 struct file_security_struct *fsec; 181 struct file_security_struct *fsec;
194 182
195 fsec = kzalloc(sizeof(struct file_security_struct), GFP_ATOMIC); 183 fsec = kzalloc(sizeof(struct file_security_struct), GFP_KERNEL);
196 if (!fsec) 184 if (!fsec)
197 return -ENOMEM; 185 return -ENOMEM;
198 186
199 fsec->magic = SELINUX_MAGIC;
200 fsec->file = file; 187 fsec->file = file;
201 if (tsec && tsec->magic == SELINUX_MAGIC) { 188 fsec->sid = tsec->sid;
202 fsec->sid = tsec->sid; 189 fsec->fown_sid = tsec->sid;
203 fsec->fown_sid = tsec->sid;
204 } else {
205 fsec->sid = SECINITSID_UNLABELED;
206 fsec->fown_sid = SECINITSID_UNLABELED;
207 }
208 file->f_security = fsec; 190 file->f_security = fsec;
209 191
210 return 0; 192 return 0;
@@ -213,10 +195,6 @@ static int file_alloc_security(struct file *file)
213static void file_free_security(struct file *file) 195static void file_free_security(struct file *file)
214{ 196{
215 struct file_security_struct *fsec = file->f_security; 197 struct file_security_struct *fsec = file->f_security;
216
217 if (!fsec || fsec->magic != SELINUX_MAGIC)
218 return;
219
220 file->f_security = NULL; 198 file->f_security = NULL;
221 kfree(fsec); 199 kfree(fsec);
222} 200}
@@ -233,7 +211,6 @@ static int superblock_alloc_security(struct super_block *sb)
233 INIT_LIST_HEAD(&sbsec->list); 211 INIT_LIST_HEAD(&sbsec->list);
234 INIT_LIST_HEAD(&sbsec->isec_head); 212 INIT_LIST_HEAD(&sbsec->isec_head);
235 spin_lock_init(&sbsec->isec_lock); 213 spin_lock_init(&sbsec->isec_lock);
236 sbsec->magic = SELINUX_MAGIC;
237 sbsec->sb = sb; 214 sbsec->sb = sb;
238 sbsec->sid = SECINITSID_UNLABELED; 215 sbsec->sid = SECINITSID_UNLABELED;
239 sbsec->def_sid = SECINITSID_FILE; 216 sbsec->def_sid = SECINITSID_FILE;
@@ -246,9 +223,6 @@ static void superblock_free_security(struct super_block *sb)
246{ 223{
247 struct superblock_security_struct *sbsec = sb->s_security; 224 struct superblock_security_struct *sbsec = sb->s_security;
248 225
249 if (!sbsec || sbsec->magic != SELINUX_MAGIC)
250 return;
251
252 spin_lock(&sb_security_lock); 226 spin_lock(&sb_security_lock);
253 if (!list_empty(&sbsec->list)) 227 if (!list_empty(&sbsec->list))
254 list_del_init(&sbsec->list); 228 list_del_init(&sbsec->list);
@@ -258,7 +232,6 @@ static void superblock_free_security(struct super_block *sb)
258 kfree(sbsec); 232 kfree(sbsec);
259} 233}
260 234
261#ifdef CONFIG_SECURITY_NETWORK
262static int sk_alloc_security(struct sock *sk, int family, gfp_t priority) 235static int sk_alloc_security(struct sock *sk, int family, gfp_t priority)
263{ 236{
264 struct sk_security_struct *ssec; 237 struct sk_security_struct *ssec;
@@ -270,7 +243,6 @@ static int sk_alloc_security(struct sock *sk, int family, gfp_t priority)
270 if (!ssec) 243 if (!ssec)
271 return -ENOMEM; 244 return -ENOMEM;
272 245
273 ssec->magic = SELINUX_MAGIC;
274 ssec->sk = sk; 246 ssec->sk = sk;
275 ssec->peer_sid = SECINITSID_UNLABELED; 247 ssec->peer_sid = SECINITSID_UNLABELED;
276 sk->sk_security = ssec; 248 sk->sk_security = ssec;
@@ -282,13 +254,12 @@ static void sk_free_security(struct sock *sk)
282{ 254{
283 struct sk_security_struct *ssec = sk->sk_security; 255 struct sk_security_struct *ssec = sk->sk_security;
284 256
285 if (sk->sk_family != PF_UNIX || ssec->magic != SELINUX_MAGIC) 257 if (sk->sk_family != PF_UNIX)
286 return; 258 return;
287 259
288 sk->sk_security = NULL; 260 sk->sk_security = NULL;
289 kfree(ssec); 261 kfree(ssec);
290} 262}
291#endif /* CONFIG_SECURITY_NETWORK */
292 263
293/* The security server must be initialized before 264/* The security server must be initialized before
294 any labeling or access decisions can be provided. */ 265 any labeling or access decisions can be provided. */
@@ -1483,7 +1454,6 @@ static int selinux_bprm_alloc_security(struct linux_binprm *bprm)
1483 if (!bsec) 1454 if (!bsec)
1484 return -ENOMEM; 1455 return -ENOMEM;
1485 1456
1486 bsec->magic = SELINUX_MAGIC;
1487 bsec->bprm = bprm; 1457 bsec->bprm = bprm;
1488 bsec->sid = SECINITSID_UNLABELED; 1458 bsec->sid = SECINITSID_UNLABELED;
1489 bsec->set = 0; 1459 bsec->set = 0;
@@ -2454,35 +2424,27 @@ static int selinux_file_mprotect(struct vm_area_struct *vma,
2454 prot = reqprot; 2424 prot = reqprot;
2455 2425
2456#ifndef CONFIG_PPC32 2426#ifndef CONFIG_PPC32
2457 if ((prot & PROT_EXEC) && !(vma->vm_flags & VM_EXECUTABLE) && 2427 if ((prot & PROT_EXEC) && !(vma->vm_flags & VM_EXEC)) {
2458 (vma->vm_start >= vma->vm_mm->start_brk && 2428 rc = 0;
2459 vma->vm_end <= vma->vm_mm->brk)) { 2429 if (vma->vm_start >= vma->vm_mm->start_brk &&
2460 /* 2430 vma->vm_end <= vma->vm_mm->brk) {
2461 * We are making an executable mapping in the brk region. 2431 rc = task_has_perm(current, current,
2462 * This has an additional execheap check. 2432 PROCESS__EXECHEAP);
2463 */ 2433 } else if (!vma->vm_file &&
2464 rc = task_has_perm(current, current, PROCESS__EXECHEAP); 2434 vma->vm_start <= vma->vm_mm->start_stack &&
2465 if (rc) 2435 vma->vm_end >= vma->vm_mm->start_stack) {
2466 return rc; 2436 rc = task_has_perm(current, current, PROCESS__EXECSTACK);
2467 } 2437 } else if (vma->vm_file && vma->anon_vma) {
2468 if (vma->vm_file != NULL && vma->anon_vma != NULL && (prot & PROT_EXEC)) { 2438 /*
2469 /* 2439 * We are making executable a file mapping that has
2470 * We are making executable a file mapping that has 2440 * had some COW done. Since pages might have been
2471 * had some COW done. Since pages might have been written, 2441 * written, check ability to execute the possibly
2472 * check ability to execute the possibly modified content. 2442 * modified content. This typically should only
2473 * This typically should only occur for text relocations. 2443 * occur for text relocations.
2474 */ 2444 */
2475 int rc = file_has_perm(current, vma->vm_file, FILE__EXECMOD); 2445 rc = file_has_perm(current, vma->vm_file,
2476 if (rc) 2446 FILE__EXECMOD);
2477 return rc; 2447 }
2478 }
2479 if (!vma->vm_file && (prot & PROT_EXEC) &&
2480 vma->vm_start <= vma->vm_mm->start_stack &&
2481 vma->vm_end >= vma->vm_mm->start_stack) {
2482 /* Attempt to make the process stack executable.
2483 * This has an additional execstack check.
2484 */
2485 rc = task_has_perm(current, current, PROCESS__EXECSTACK);
2486 if (rc) 2448 if (rc)
2487 return rc; 2449 return rc;
2488 } 2450 }
@@ -2772,8 +2734,6 @@ static void selinux_task_to_inode(struct task_struct *p,
2772 return; 2734 return;
2773} 2735}
2774 2736
2775#ifdef CONFIG_SECURITY_NETWORK
2776
2777/* Returns error only if unable to parse addresses */ 2737/* Returns error only if unable to parse addresses */
2778static int selinux_parse_skb_ipv4(struct sk_buff *skb, struct avc_audit_data *ad) 2738static int selinux_parse_skb_ipv4(struct sk_buff *skb, struct avc_audit_data *ad)
2779{ 2739{
@@ -3592,15 +3552,6 @@ static unsigned int selinux_ipv6_postroute_last(unsigned int hooknum,
3592 3552
3593#endif /* CONFIG_NETFILTER */ 3553#endif /* CONFIG_NETFILTER */
3594 3554
3595#else
3596
3597static inline int selinux_nlmsg_perm(struct sock *sk, struct sk_buff *skb)
3598{
3599 return 0;
3600}
3601
3602#endif /* CONFIG_SECURITY_NETWORK */
3603
3604static int selinux_netlink_send(struct sock *sk, struct sk_buff *skb) 3555static int selinux_netlink_send(struct sock *sk, struct sk_buff *skb)
3605{ 3556{
3606 struct task_security_struct *tsec; 3557 struct task_security_struct *tsec;
@@ -3642,14 +3593,9 @@ static int ipc_alloc_security(struct task_struct *task,
3642 if (!isec) 3593 if (!isec)
3643 return -ENOMEM; 3594 return -ENOMEM;
3644 3595
3645 isec->magic = SELINUX_MAGIC;
3646 isec->sclass = sclass; 3596 isec->sclass = sclass;
3647 isec->ipc_perm = perm; 3597 isec->ipc_perm = perm;
3648 if (tsec) { 3598 isec->sid = tsec->sid;
3649 isec->sid = tsec->sid;
3650 } else {
3651 isec->sid = SECINITSID_UNLABELED;
3652 }
3653 perm->security = isec; 3599 perm->security = isec;
3654 3600
3655 return 0; 3601 return 0;
@@ -3658,9 +3604,6 @@ static int ipc_alloc_security(struct task_struct *task,
3658static void ipc_free_security(struct kern_ipc_perm *perm) 3604static void ipc_free_security(struct kern_ipc_perm *perm)
3659{ 3605{
3660 struct ipc_security_struct *isec = perm->security; 3606 struct ipc_security_struct *isec = perm->security;
3661 if (!isec || isec->magic != SELINUX_MAGIC)
3662 return;
3663
3664 perm->security = NULL; 3607 perm->security = NULL;
3665 kfree(isec); 3608 kfree(isec);
3666} 3609}
@@ -3673,7 +3616,6 @@ static int msg_msg_alloc_security(struct msg_msg *msg)
3673 if (!msec) 3616 if (!msec)
3674 return -ENOMEM; 3617 return -ENOMEM;
3675 3618
3676 msec->magic = SELINUX_MAGIC;
3677 msec->msg = msg; 3619 msec->msg = msg;
3678 msec->sid = SECINITSID_UNLABELED; 3620 msec->sid = SECINITSID_UNLABELED;
3679 msg->security = msec; 3621 msg->security = msec;
@@ -3684,8 +3626,6 @@ static int msg_msg_alloc_security(struct msg_msg *msg)
3684static void msg_msg_free_security(struct msg_msg *msg) 3626static void msg_msg_free_security(struct msg_msg *msg)
3685{ 3627{
3686 struct msg_security_struct *msec = msg->security; 3628 struct msg_security_struct *msec = msg->security;
3687 if (!msec || msec->magic != SELINUX_MAGIC)
3688 return;
3689 3629
3690 msg->security = NULL; 3630 msg->security = NULL;
3691 kfree(msec); 3631 kfree(msec);
@@ -4387,7 +4327,6 @@ static struct security_operations selinux_ops = {
4387 .getprocattr = selinux_getprocattr, 4327 .getprocattr = selinux_getprocattr,
4388 .setprocattr = selinux_setprocattr, 4328 .setprocattr = selinux_setprocattr,
4389 4329
4390#ifdef CONFIG_SECURITY_NETWORK
4391 .unix_stream_connect = selinux_socket_unix_stream_connect, 4330 .unix_stream_connect = selinux_socket_unix_stream_connect,
4392 .unix_may_send = selinux_socket_unix_may_send, 4331 .unix_may_send = selinux_socket_unix_may_send,
4393 4332
@@ -4409,7 +4348,6 @@ static struct security_operations selinux_ops = {
4409 .sk_alloc_security = selinux_sk_alloc_security, 4348 .sk_alloc_security = selinux_sk_alloc_security,
4410 .sk_free_security = selinux_sk_free_security, 4349 .sk_free_security = selinux_sk_free_security,
4411 .sk_getsid = selinux_sk_getsid_security, 4350 .sk_getsid = selinux_sk_getsid_security,
4412#endif
4413 4351
4414#ifdef CONFIG_SECURITY_NETWORK_XFRM 4352#ifdef CONFIG_SECURITY_NETWORK_XFRM
4415 .xfrm_policy_alloc_security = selinux_xfrm_policy_alloc, 4353 .xfrm_policy_alloc_security = selinux_xfrm_policy_alloc,
@@ -4487,7 +4425,7 @@ next_sb:
4487 all processes and objects when they are created. */ 4425 all processes and objects when they are created. */
4488security_initcall(selinux_init); 4426security_initcall(selinux_init);
4489 4427
4490#if defined(CONFIG_SECURITY_NETWORK) && defined(CONFIG_NETFILTER) 4428#if defined(CONFIG_NETFILTER)
4491 4429
4492static struct nf_hook_ops selinux_ipv4_op = { 4430static struct nf_hook_ops selinux_ipv4_op = {
4493 .hook = selinux_ipv4_postroute_last, 4431 .hook = selinux_ipv4_postroute_last,
@@ -4548,13 +4486,13 @@ static void selinux_nf_ip_exit(void)
4548} 4486}
4549#endif 4487#endif
4550 4488
4551#else /* CONFIG_SECURITY_NETWORK && CONFIG_NETFILTER */ 4489#else /* CONFIG_NETFILTER */
4552 4490
4553#ifdef CONFIG_SECURITY_SELINUX_DISABLE 4491#ifdef CONFIG_SECURITY_SELINUX_DISABLE
4554#define selinux_nf_ip_exit() 4492#define selinux_nf_ip_exit()
4555#endif 4493#endif
4556 4494
4557#endif /* CONFIG_SECURITY_NETWORK && CONFIG_NETFILTER */ 4495#endif /* CONFIG_NETFILTER */
4558 4496
4559#ifdef CONFIG_SECURITY_SELINUX_DISABLE 4497#ifdef CONFIG_SECURITY_SELINUX_DISABLE
4560int selinux_disable(void) 4498int selinux_disable(void)