aboutsummaryrefslogtreecommitdiffstats
path: root/security/selinux/hooks.c
diff options
context:
space:
mode:
Diffstat (limited to 'security/selinux/hooks.c')
-rw-r--r--security/selinux/hooks.c101
1 files changed, 27 insertions, 74 deletions
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index b9f8d9731c3d..4ae834d89bce 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);
@@ -270,7 +244,6 @@ static int sk_alloc_security(struct sock *sk, int family, gfp_t priority)
270 if (!ssec) 244 if (!ssec)
271 return -ENOMEM; 245 return -ENOMEM;
272 246
273 ssec->magic = SELINUX_MAGIC;
274 ssec->sk = sk; 247 ssec->sk = sk;
275 ssec->peer_sid = SECINITSID_UNLABELED; 248 ssec->peer_sid = SECINITSID_UNLABELED;
276 sk->sk_security = ssec; 249 sk->sk_security = ssec;
@@ -282,7 +255,7 @@ static void sk_free_security(struct sock *sk)
282{ 255{
283 struct sk_security_struct *ssec = sk->sk_security; 256 struct sk_security_struct *ssec = sk->sk_security;
284 257
285 if (sk->sk_family != PF_UNIX || ssec->magic != SELINUX_MAGIC) 258 if (sk->sk_family != PF_UNIX)
286 return; 259 return;
287 260
288 sk->sk_security = NULL; 261 sk->sk_security = NULL;
@@ -1483,7 +1456,6 @@ static int selinux_bprm_alloc_security(struct linux_binprm *bprm)
1483 if (!bsec) 1456 if (!bsec)
1484 return -ENOMEM; 1457 return -ENOMEM;
1485 1458
1486 bsec->magic = SELINUX_MAGIC;
1487 bsec->bprm = bprm; 1459 bsec->bprm = bprm;
1488 bsec->sid = SECINITSID_UNLABELED; 1460 bsec->sid = SECINITSID_UNLABELED;
1489 bsec->set = 0; 1461 bsec->set = 0;
@@ -2454,35 +2426,27 @@ static int selinux_file_mprotect(struct vm_area_struct *vma,
2454 prot = reqprot; 2426 prot = reqprot;
2455 2427
2456#ifndef CONFIG_PPC32 2428#ifndef CONFIG_PPC32
2457 if ((prot & PROT_EXEC) && !(vma->vm_flags & VM_EXECUTABLE) && 2429 if ((prot & PROT_EXEC) && !(vma->vm_flags & VM_EXEC)) {
2458 (vma->vm_start >= vma->vm_mm->start_brk && 2430 rc = 0;
2459 vma->vm_end <= vma->vm_mm->brk)) { 2431 if (vma->vm_start >= vma->vm_mm->start_brk &&
2460 /* 2432 vma->vm_end <= vma->vm_mm->brk) {
2461 * We are making an executable mapping in the brk region. 2433 rc = task_has_perm(current, current,
2462 * This has an additional execheap check. 2434 PROCESS__EXECHEAP);
2463 */ 2435 } else if (!vma->vm_file &&
2464 rc = task_has_perm(current, current, PROCESS__EXECHEAP); 2436 vma->vm_start <= vma->vm_mm->start_stack &&
2465 if (rc) 2437 vma->vm_end >= vma->vm_mm->start_stack) {
2466 return rc; 2438 rc = task_has_perm(current, current, PROCESS__EXECSTACK);
2467 } 2439 } else if (vma->vm_file && vma->anon_vma) {
2468 if (vma->vm_file != NULL && vma->anon_vma != NULL && (prot & PROT_EXEC)) { 2440 /*
2469 /* 2441 * We are making executable a file mapping that has
2470 * We are making executable a file mapping that has 2442 * had some COW done. Since pages might have been
2471 * had some COW done. Since pages might have been written, 2443 * written, check ability to execute the possibly
2472 * check ability to execute the possibly modified content. 2444 * modified content. This typically should only
2473 * This typically should only occur for text relocations. 2445 * occur for text relocations.
2474 */ 2446 */
2475 int rc = file_has_perm(current, vma->vm_file, FILE__EXECMOD); 2447 rc = file_has_perm(current, vma->vm_file,
2476 if (rc) 2448 FILE__EXECMOD);
2477 return rc; 2449 }
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) 2450 if (rc)
2487 return rc; 2451 return rc;
2488 } 2452 }
@@ -3642,14 +3606,9 @@ static int ipc_alloc_security(struct task_struct *task,
3642 if (!isec) 3606 if (!isec)
3643 return -ENOMEM; 3607 return -ENOMEM;
3644 3608
3645 isec->magic = SELINUX_MAGIC;
3646 isec->sclass = sclass; 3609 isec->sclass = sclass;
3647 isec->ipc_perm = perm; 3610 isec->ipc_perm = perm;
3648 if (tsec) { 3611 isec->sid = tsec->sid;
3649 isec->sid = tsec->sid;
3650 } else {
3651 isec->sid = SECINITSID_UNLABELED;
3652 }
3653 perm->security = isec; 3612 perm->security = isec;
3654 3613
3655 return 0; 3614 return 0;
@@ -3658,9 +3617,6 @@ static int ipc_alloc_security(struct task_struct *task,
3658static void ipc_free_security(struct kern_ipc_perm *perm) 3617static void ipc_free_security(struct kern_ipc_perm *perm)
3659{ 3618{
3660 struct ipc_security_struct *isec = perm->security; 3619 struct ipc_security_struct *isec = perm->security;
3661 if (!isec || isec->magic != SELINUX_MAGIC)
3662 return;
3663
3664 perm->security = NULL; 3620 perm->security = NULL;
3665 kfree(isec); 3621 kfree(isec);
3666} 3622}
@@ -3673,7 +3629,6 @@ static int msg_msg_alloc_security(struct msg_msg *msg)
3673 if (!msec) 3629 if (!msec)
3674 return -ENOMEM; 3630 return -ENOMEM;
3675 3631
3676 msec->magic = SELINUX_MAGIC;
3677 msec->msg = msg; 3632 msec->msg = msg;
3678 msec->sid = SECINITSID_UNLABELED; 3633 msec->sid = SECINITSID_UNLABELED;
3679 msg->security = msec; 3634 msg->security = msec;
@@ -3684,8 +3639,6 @@ static int msg_msg_alloc_security(struct msg_msg *msg)
3684static void msg_msg_free_security(struct msg_msg *msg) 3639static void msg_msg_free_security(struct msg_msg *msg)
3685{ 3640{
3686 struct msg_security_struct *msec = msg->security; 3641 struct msg_security_struct *msec = msg->security;
3687 if (!msec || msec->magic != SELINUX_MAGIC)
3688 return;
3689 3642
3690 msg->security = NULL; 3643 msg->security = NULL;
3691 kfree(msec); 3644 kfree(msec);