Develop and Download Open Source Software

Browse Subversion Repository

Contents of /trunk/caitsith-patch/caitsith/lsm-4.12.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 267 - (show annotations) (download) (as text)
Mon Aug 27 10:15:55 2018 UTC (5 years, 7 months ago) by kumaneko
File MIME type: text/x-csrc
File size: 38239 byte(s)


1 /*
2 * lsm.c
3 *
4 * Copyright (C) 2010-2013 Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
5 *
6 * Version: 0.2.3 2018/04/01
7 */
8
9 #include "caitsith.h"
10 #include "probe.h"
11
12 /* Prototype definition. */
13 static int __cs_alloc_task_security(const struct task_struct *task);
14 static void __cs_free_task_security(const struct task_struct *task);
15
16 /* Dummy security context for avoiding NULL pointer dereference. */
17 static struct cs_security cs_oom_security = {
18 .cs_domain_info = &cs_kernel_domain
19 };
20
21 /* Dummy security context for avoiding NULL pointer dereference. */
22 static struct cs_security cs_default_security = {
23 .cs_domain_info = &cs_kernel_domain
24 };
25
26 /* List of "struct cs_security". */
27 struct list_head cs_task_security_list[CS_MAX_TASK_SECURITY_HASH];
28 /* Lock for protecting cs_task_security_list[]. */
29 static DEFINE_SPINLOCK(cs_task_security_list_lock);
30
31 /* For exporting variables and functions. */
32 struct caitsith_exports caitsith_exports;
33
34 /* Original hooks. */
35 static union security_list_options original_cred_prepare;
36 static union security_list_options original_task_alloc;
37 static union security_list_options original_task_free;
38
39 #if !defined(CONFIG_CAITSITH_DEBUG)
40 #define cs_debug_trace(pos) do { } while (0)
41 #else
42 #define cs_debug_trace(pos) \
43 do { \
44 static bool done; \
45 if (!done) { \
46 printk(KERN_INFO \
47 "CAITSITH: Debug trace: " pos " of 2\n"); \
48 done = true; \
49 } \
50 } while (0)
51 #endif
52
53 /**
54 * cs_clear_execve - Release memory used by do_execve().
55 *
56 * @ret: 0 if do_execve() succeeded, negative value otherwise.
57 * @security: Pointer to "struct cs_security".
58 *
59 * Returns nothing.
60 */
61 static void cs_clear_execve(int ret, struct cs_security *security)
62 {
63 struct cs_request_info *r = security->r;
64
65 if (security == &cs_default_security || security == &cs_oom_security ||
66 !r)
67 return;
68 security->r = NULL;
69 cs_finish_execve(ret, r);
70 }
71
72 /**
73 * cs_task_alloc_security - Allocate memory for new tasks.
74 *
75 * @p: Pointer to "struct task_struct".
76 * @clone_flags: Flags passed to clone().
77 *
78 * Returns 0 on success, negative value otherwise.
79 */
80 static int cs_task_alloc_security(struct task_struct *p,
81 unsigned long clone_flags)
82 {
83 int rc = __cs_alloc_task_security(p);
84
85 if (rc)
86 return rc;
87 if (original_task_alloc.task_alloc) {
88 rc = original_task_alloc.task_alloc(p, clone_flags);
89 if (rc)
90 __cs_free_task_security(p);
91 }
92 return rc;
93 }
94
95 /**
96 * cs_task_free_security - Release memory for "struct task_struct".
97 *
98 * @p: Pointer to "struct task_struct".
99 *
100 * Returns nothing.
101 */
102 static void cs_task_free_security(struct task_struct *p)
103 {
104 struct cs_security *ptr = cs_find_task_security(p);
105 struct cs_request_info *r = ptr->r;
106
107 if (original_task_free.task_free)
108 original_task_free.task_free(p);
109 /*
110 * Since an LSM hook for reverting domain transition is missing,
111 * cs_finish_execve() is not called if exited immediately after
112 * execve() failed.
113 */
114 if (r) {
115 cs_debug_trace("2");
116 kfree(r->handler_path);
117 kfree(r);
118 ptr->r = NULL;
119 }
120 __cs_free_task_security(p);
121 }
122
123 /**
124 * __cs_free_task_security - Release memory associated with "struct task_struct".
125 *
126 * @task: Pointer to "struct task_struct".
127 *
128 * Returns nothing.
129 */
130 static void __cs_free_task_security(const struct task_struct *task)
131 {
132 unsigned long flags;
133 struct cs_security *ptr = cs_find_task_security(task);
134
135 if (ptr == &cs_default_security || ptr == &cs_oom_security)
136 return;
137 spin_lock_irqsave(&cs_task_security_list_lock, flags);
138 list_del_rcu(&ptr->list);
139 spin_unlock_irqrestore(&cs_task_security_list_lock, flags);
140 kfree_rcu(ptr, rcu);
141 }
142
143 /**
144 * cs_cred_prepare - Allocate memory for new credentials.
145 *
146 * @new: Pointer to "struct cred".
147 * @old: Pointer to "struct cred".
148 * @gfp: Memory allocation flags.
149 *
150 * Returns 0 on success, negative value otherwise.
151 */
152 static int cs_cred_prepare(struct cred *new, const struct cred *old,
153 gfp_t gfp)
154 {
155 /*
156 * For checking whether reverting domain transition is needed or not.
157 *
158 * See cs_find_task_security() for reason.
159 */
160 if (gfp == GFP_KERNEL)
161 cs_find_task_security(current);
162 if (original_cred_prepare.cred_prepare)
163 return original_cred_prepare.cred_prepare(new, old, gfp);
164 return 0;
165 }
166
167 /**
168 * cs_bprm_committing_creds - A hook which is called when do_execve() succeeded.
169 *
170 * @bprm: Pointer to "struct linux_binprm".
171 *
172 * Returns nothing.
173 */
174 static void cs_bprm_committing_creds(struct linux_binprm *bprm)
175 {
176 cs_clear_execve(0, cs_current_security());
177 }
178
179 #ifndef CONFIG_CAITSITH_OMIT_USERSPACE_LOADER
180
181 /**
182 * cs_policy_loader_exists - Check whether /sbin/caitsith-init exists.
183 *
184 * Returns true if /sbin/caitsith-init exists, false otherwise.
185 */
186 static _Bool cs_policy_loader_exists(void)
187 {
188 struct path path;
189
190 if (kern_path(CONFIG_CAITSITH_POLICY_LOADER, LOOKUP_FOLLOW, &path)
191 == 0) {
192 path_put(&path);
193 return 1;
194 }
195 printk(KERN_INFO "Not activating CaitSith as %s does not exist.\n",
196 CONFIG_CAITSITH_POLICY_LOADER);
197 return 0;
198 }
199
200 /**
201 * cs_load_policy - Run external policy loader to load policy.
202 *
203 * @filename: The program about to start.
204 *
205 * Returns nothing.
206 *
207 * This function checks whether @filename is /sbin/init, and if so
208 * invoke /sbin/caitsith-init and wait for the termination of
209 * /sbin/caitsith-init and then continues invocation of /sbin/init.
210 * /sbin/caitsith-init reads policy files in /etc/caitsith/ directory and
211 * writes to /sys/kernel/security/caitsith/ interfaces.
212 */
213 static void cs_load_policy(const char *filename)
214 {
215 static _Bool done;
216
217 if (done)
218 return;
219 if (strcmp(filename, CONFIG_CAITSITH_ACTIVATION_TRIGGER))
220 return;
221 if (!cs_policy_loader_exists())
222 return;
223 done = 1;
224 {
225 char *argv[2];
226 char *envp[3];
227
228 printk(KERN_INFO "Calling %s to load policy. Please wait.\n",
229 CONFIG_CAITSITH_POLICY_LOADER);
230 argv[0] = (char *) CONFIG_CAITSITH_POLICY_LOADER;
231 argv[1] = NULL;
232 envp[0] = "HOME=/";
233 envp[1] = "PATH=/sbin:/bin:/usr/sbin:/usr/bin";
234 envp[2] = NULL;
235 call_usermodehelper(argv[0], argv, envp, UMH_WAIT_PROC);
236 }
237 cs_check_profile();
238 }
239
240 #endif
241
242 /**
243 * cs_bprm_check_security - Check permission for execve().
244 *
245 * @bprm: Pointer to "struct linux_binprm".
246 *
247 * Returns 0 on success, negative value otherwise.
248 */
249 static int cs_bprm_check_security(struct linux_binprm *bprm)
250 {
251 struct cs_security *security = cs_current_security();
252
253 if (security == &cs_default_security || security == &cs_oom_security)
254 return -ENOMEM;
255 if (security->r)
256 return 0;
257 #ifndef CONFIG_CAITSITH_OMIT_USERSPACE_LOADER
258 if (!cs_policy_loaded)
259 cs_load_policy(bprm->filename);
260 #endif
261 return cs_start_execve(bprm, &security->r);
262 }
263
264 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0)
265 /**
266 * cs_file_open - Check permission for open().
267 *
268 * @f: Pointer to "struct file".
269 *
270 * Returns 0 on success, negative value otherwise.
271 */
272 static int cs_file_open(struct file *f)
273 {
274 return cs_open_permission(&f->f_path, f->f_flags);
275 }
276 #else
277 /**
278 * cs_file_open - Check permission for open().
279 *
280 * @f: Pointer to "struct file".
281 * @cred: Pointer to "struct cred".
282 *
283 * Returns 0 on success, negative value otherwise.
284 */
285 static int cs_file_open(struct file *f, const struct cred *cred)
286 {
287 return cs_open_permission(&f->f_path, f->f_flags);
288 }
289 #endif
290
291 #ifdef CONFIG_SECURITY_PATH
292
293 /**
294 * cs_path_chown - Check permission for chown()/chgrp().
295 *
296 * @path: Pointer to "struct path".
297 * @user: User ID.
298 * @group: Group ID.
299 *
300 * Returns 0 on success, negative value otherwise.
301 */
302 static int cs_path_chown(const struct path *path, kuid_t user, kgid_t group)
303 {
304 return cs_chown_permission(path, user, group);
305 }
306
307 /**
308 * cs_path_chmod - Check permission for chmod().
309 *
310 * @path: Pointer to "struct path".
311 * @mode: Mode.
312 *
313 * Returns 0 on success, negative value otherwise.
314 */
315 static int cs_path_chmod(const struct path *path, umode_t mode)
316 {
317 return cs_chmod_permission(path, mode);
318 }
319
320 /**
321 * cs_path_chroot - Check permission for chroot().
322 *
323 * @path: Pointer to "struct path".
324 *
325 * Returns 0 on success, negative value otherwise.
326 */
327 static int cs_path_chroot(const struct path *path)
328 {
329 return cs_chroot_permission(path);
330 }
331
332 /**
333 * cs_path_truncate - Check permission for truncate().
334 *
335 * @path: Pointer to "struct path".
336 *
337 * Returns 0 on success, negative value otherwise.
338 */
339 static int cs_path_truncate(const struct path *path)
340 {
341 return cs_truncate_permission(path);
342 }
343
344 #else
345
346 /**
347 * cs_inode_setattr - Check permission for chown()/chgrp()/chmod()/truncate().
348 *
349 * @dentry: Pointer to "struct dentry".
350 * @attr: Pointer to "struct iattr".
351 *
352 * Returns 0 on success, negative value otherwise.
353 */
354 static int cs_inode_setattr(struct dentry *dentry, struct iattr *attr)
355 {
356 int rc = 0;
357 struct path path = { .mnt = NULL, .dentry = dentry };
358
359 if (attr->ia_valid & ATTR_UID)
360 rc = cs_chown_permission(&path, attr->ia_uid, INVALID_GID);
361 if (!rc && (attr->ia_valid & ATTR_GID))
362 rc = cs_chown_permission(&path, INVALID_UID, attr->ia_gid);
363 if (!rc && (attr->ia_valid & ATTR_MODE))
364 rc = cs_chmod_permission(&path, attr->ia_mode);
365 if (!rc && (attr->ia_valid & ATTR_SIZE))
366 rc = cs_truncate_permission(&path);
367 return rc;
368 }
369
370 #endif
371
372 /**
373 * cs_inode_getattr - Check permission for stat().
374 *
375 * @path: Pointer to "struct path".
376 *
377 * Returns 0 on success, negative value otherwise.
378 */
379 static int cs_inode_getattr(const struct path *path)
380 {
381 return cs_getattr_permission(path);
382 }
383
384 #ifdef CONFIG_SECURITY_PATH
385
386 /**
387 * cs_path_mknod - Check permission for mknod().
388 *
389 * @dir: Pointer to "struct path".
390 * @dentry: Pointer to "struct dentry".
391 * @mode: Create mode.
392 * @dev: Device major/minor number.
393 *
394 * Returns 0 on success, negative value otherwise.
395 */
396 static int cs_path_mknod(const struct path *dir, struct dentry *dentry,
397 umode_t mode, unsigned int dev)
398 {
399 struct path path = { .mnt = dir->mnt, .dentry = dentry };
400
401 return cs_mknod_permission(&path, mode, dev);
402 }
403
404 /**
405 * cs_path_mkdir - Check permission for mkdir().
406 *
407 * @dir: Pointer to "struct path".
408 * @dentry: Pointer to "struct dentry".
409 * @mode: Create mode.
410 *
411 * Returns 0 on success, negative value otherwise.
412 */
413 static int cs_path_mkdir(const struct path *dir, struct dentry *dentry,
414 umode_t mode)
415 {
416 struct path path = { .mnt = dir->mnt, .dentry = dentry };
417
418 return cs_mkdir_permission(&path, mode);
419 }
420
421 /**
422 * cs_path_rmdir - Check permission for rmdir().
423 *
424 * @dir: Pointer to "struct path".
425 * @dentry: Pointer to "struct dentry".
426 *
427 * Returns 0 on success, negative value otherwise.
428 */
429 static int cs_path_rmdir(const struct path *dir, struct dentry *dentry)
430 {
431 struct path path = { .mnt = dir->mnt, .dentry = dentry };
432
433 return cs_rmdir_permission(&path);
434 }
435
436 /**
437 * cs_path_unlink - Check permission for unlink().
438 *
439 * @dir: Pointer to "struct path".
440 * @dentry: Pointer to "struct dentry".
441 *
442 * Returns 0 on success, negative value otherwise.
443 */
444 static int cs_path_unlink(const struct path *dir, struct dentry *dentry)
445 {
446 struct path path = { .mnt = dir->mnt, .dentry = dentry };
447
448 return cs_unlink_permission(&path);
449 }
450
451 /**
452 * cs_path_symlink - Check permission for symlink().
453 *
454 * @dir: Pointer to "struct path".
455 * @dentry: Pointer to "struct dentry".
456 * @old_name: Content of symbolic link.
457 *
458 * Returns 0 on success, negative value otherwise.
459 */
460 static int cs_path_symlink(const struct path *dir, struct dentry *dentry,
461 const char *old_name)
462 {
463 struct path path = { .mnt = dir->mnt, .dentry = dentry };
464
465 return cs_symlink_permission(&path, old_name);
466 }
467
468 /**
469 * cs_path_rename - Check permission for rename().
470 *
471 * @old_dir: Pointer to "struct path".
472 * @old_dentry: Pointer to "struct dentry".
473 * @new_dir: Pointer to "struct path".
474 * @new_dentry: Pointer to "struct dentry".
475 *
476 * Returns 0 on success, negative value otherwise.
477 */
478 static int cs_path_rename(const struct path *old_dir,
479 struct dentry *old_dentry,
480 const struct path *new_dir,
481 struct dentry *new_dentry)
482 {
483 struct path old = { .mnt = old_dir->mnt, .dentry = old_dentry };
484 struct path new = { .mnt = new_dir->mnt, .dentry = new_dentry };
485
486 return cs_rename_permission(&old, &new);
487 }
488
489 /**
490 * cs_path_link - Check permission for link().
491 *
492 * @old_dentry: Pointer to "struct dentry".
493 * @new_dir: Pointer to "struct path".
494 * @new_dentry: Pointer to "struct dentry".
495 *
496 * Returns 0 on success, negative value otherwise.
497 */
498 static int cs_path_link(struct dentry *old_dentry, const struct path *new_dir,
499 struct dentry *new_dentry)
500 {
501 struct path old = { .mnt = new_dir->mnt, .dentry = old_dentry };
502 struct path new = { .mnt = new_dir->mnt, .dentry = new_dentry };
503
504 return cs_link_permission(&old, &new);
505 }
506
507 #else
508
509 /**
510 * cs_inode_mknod - Check permission for mknod().
511 *
512 * @dir: Pointer to "struct inode".
513 * @dentry: Pointer to "struct dentry".
514 * @mode: Create mode.
515 * @dev: Device major/minor number.
516 *
517 * Returns 0 on success, negative value otherwise.
518 */
519 static int cs_inode_mknod(struct inode *dir, struct dentry *dentry,
520 umode_t mode, dev_t dev)
521 {
522 struct path path = { .mnt = NULL, .dentry = dentry };
523
524 return cs_mknod_permission(&path, mode, dev);
525 }
526
527 /**
528 * cs_inode_mkdir - Check permission for mkdir().
529 *
530 * @dir: Pointer to "struct inode".
531 * @dentry: Pointer to "struct dentry".
532 * @mode: Create mode.
533 *
534 * Returns 0 on success, negative value otherwise.
535 */
536 static int cs_inode_mkdir(struct inode *dir, struct dentry *dentry,
537 umode_t mode)
538 {
539 struct path path = { .mnt = NULL, .dentry = dentry };
540
541 return cs_mkdir_permission(&path, mode);
542 }
543
544 /**
545 * cs_inode_rmdir - Check permission for rmdir().
546 *
547 * @dir: Pointer to "struct inode".
548 * @dentry: Pointer to "struct dentry".
549 *
550 * Returns 0 on success, negative value otherwise.
551 */
552 static int cs_inode_rmdir(struct inode *dir, struct dentry *dentry)
553 {
554 struct path path = { .mnt = NULL, .dentry = dentry };
555
556 return cs_rmdir_permission(&path);
557 }
558
559 /**
560 * cs_inode_unlink - Check permission for unlink().
561 *
562 * @dir: Pointer to "struct inode".
563 * @dentry: Pointer to "struct dentry".
564 *
565 * Returns 0 on success, negative value otherwise.
566 */
567 static int cs_inode_unlink(struct inode *dir, struct dentry *dentry)
568 {
569 struct path path = { .mnt = NULL, .dentry = dentry };
570
571 return cs_unlink_permission(&path);
572 }
573
574 /**
575 * cs_inode_symlink - Check permission for symlink().
576 *
577 * @dir: Pointer to "struct inode".
578 * @dentry: Pointer to "struct dentry".
579 * @old_name: Content of symbolic link.
580 *
581 * Returns 0 on success, negative value otherwise.
582 */
583 static int cs_inode_symlink(struct inode *dir, struct dentry *dentry,
584 const char *old_name)
585 {
586 struct path path = { .mnt = NULL, .dentry = dentry };
587
588 return cs_symlink_permission(&path, old_name);
589 }
590
591 /**
592 * cs_inode_rename - Check permission for rename().
593 *
594 * @old_dir: Pointer to "struct inode".
595 * @old_dentry: Pointer to "struct dentry".
596 * @new_dir: Pointer to "struct inode".
597 * @new_dentry: Pointer to "struct dentry".
598 *
599 * Returns 0 on success, negative value otherwise.
600 */
601 static int cs_inode_rename(struct inode *old_dir, struct dentry *old_dentry,
602 struct inode *new_dir, struct dentry *new_dentry)
603 {
604 struct path old = { .mnt = NULL, .dentry = old_dentry };
605 struct path new = { .mnt = NULL, .dentry = new_dentry };
606
607 return cs_rename_permission(&old, &new);
608 }
609
610 /**
611 * cs_inode_link - Check permission for link().
612 *
613 * @old_dentry: Pointer to "struct dentry".
614 * @dir: Pointer to "struct inode".
615 * @new_dentry: Pointer to "struct dentry".
616 *
617 * Returns 0 on success, negative value otherwise.
618 */
619 static int cs_inode_link(struct dentry *old_dentry, struct inode *dir,
620 struct dentry *new_dentry)
621 {
622 struct path old = { .mnt = NULL, .dentry = old_dentry };
623 struct path new = { .mnt = NULL, .dentry = new_dentry };
624
625 return cs_link_permission(&old, &new);
626 }
627
628 /**
629 * cs_inode_create - Check permission for creat().
630 *
631 * @dir: Pointer to "struct inode".
632 * @dentry: Pointer to "struct dentry".
633 * @mode: Create mode.
634 *
635 * Returns 0 on success, negative value otherwise.
636 */
637 static int cs_inode_create(struct inode *dir, struct dentry *dentry,
638 umode_t mode)
639 {
640 struct path path = { .mnt = NULL, .dentry = dentry };
641
642 return cs_mknod_permission(&path, mode, 0);
643 }
644
645 #endif
646
647 #ifdef CONFIG_SECURITY_NETWORK
648
649 #include <net/sock.h>
650
651 /* Structure for remembering an accept()ed socket's status. */
652 struct cs_socket_tag {
653 struct list_head list;
654 struct inode *inode;
655 int status;
656 struct rcu_head rcu;
657 };
658
659 /*
660 * List for managing accept()ed sockets.
661 * Since we don't need to keep an accept()ed socket into this list after
662 * once the permission was granted, the number of entries in this list is
663 * likely small. Therefore, we don't use hash tables.
664 */
665 static LIST_HEAD(cs_accepted_socket_list);
666 /* Lock for protecting cs_accepted_socket_list . */
667 static DEFINE_SPINLOCK(cs_accepted_socket_list_lock);
668
669 /**
670 * cs_update_socket_tag - Update tag associated with accept()ed sockets.
671 *
672 * @inode: Pointer to "struct inode".
673 * @status: New status.
674 *
675 * Returns nothing.
676 *
677 * If @status == 0, memory for that socket will be released after RCU grace
678 * period.
679 */
680 static void cs_update_socket_tag(struct inode *inode, int status)
681 {
682 struct cs_socket_tag *ptr;
683 /*
684 * Protect whole section because multiple threads may call this
685 * function with same "sock" via cs_validate_socket().
686 */
687 spin_lock(&cs_accepted_socket_list_lock);
688 rcu_read_lock();
689 list_for_each_entry_rcu(ptr, &cs_accepted_socket_list, list) {
690 if (ptr->inode != inode)
691 continue;
692 ptr->status = status;
693 if (status)
694 break;
695 list_del_rcu(&ptr->list);
696 kfree_rcu(ptr, rcu);
697 break;
698 }
699 rcu_read_unlock();
700 spin_unlock(&cs_accepted_socket_list_lock);
701 }
702
703 /**
704 * cs_validate_socket - Check post accept() permission if needed.
705 *
706 * @sock: Pointer to "struct socket".
707 *
708 * Returns 0 on success, negative value otherwise.
709 */
710 static int cs_validate_socket(struct socket *sock)
711 {
712 struct inode *inode = SOCK_INODE(sock);
713 struct cs_socket_tag *ptr;
714 int ret = 0;
715
716 rcu_read_lock();
717 list_for_each_entry_rcu(ptr, &cs_accepted_socket_list, list) {
718 if (ptr->inode != inode)
719 continue;
720 ret = ptr->status;
721 break;
722 }
723 rcu_read_unlock();
724 if (ret <= 0)
725 /*
726 * This socket is not an accept()ed socket or this socket is
727 * an accept()ed socket and post accept() permission is done.
728 */
729 return ret;
730 /*
731 * Check post accept() permission now.
732 *
733 * Strictly speaking, we need to pass both listen()ing socket and
734 * accept()ed socket to __cs_socket_post_accept_permission().
735 * But since socket's family and type are same for both sockets,
736 * passing the accept()ed socket in place for the listen()ing socket
737 * will work.
738 */
739 ret = cs_socket_post_accept_permission(sock, sock);
740 /*
741 * If permission was granted, we forget that this is an accept()ed
742 * socket. Otherwise, we remember that this socket needs to return
743 * error for subsequent socketcalls.
744 */
745 cs_update_socket_tag(inode, ret);
746 return ret;
747 }
748
749 /**
750 * cs_socket_accept - Check permission for accept().
751 *
752 * @sock: Pointer to "struct socket".
753 * @newsock: Pointer to "struct socket".
754 *
755 * Returns 0 on success, negative value otherwise.
756 *
757 * This hook is used for setting up environment for doing post accept()
758 * permission check. If dereferencing sock->ops->something() were ordered by
759 * rcu_dereference(), we could replace sock->ops with "a copy of original
760 * sock->ops with modified sock->ops->accept()" using rcu_assign_pointer()
761 * in order to do post accept() permission check before returning to userspace.
762 * If we make the copy in security_socket_post_create(), it would be possible
763 * to safely replace sock->ops here, but we don't do so because we don't want
764 * to allocate memory for sockets which do not call sock->ops->accept().
765 * Therefore, we do post accept() permission check upon next socket syscalls
766 * rather than between sock->ops->accept() and returning to userspace.
767 * This means that if a socket was close()d before calling some socket
768 * syscalls, post accept() permission check will not be done.
769 */
770 static int cs_socket_accept(struct socket *sock, struct socket *newsock)
771 {
772 struct cs_socket_tag *ptr;
773 const int rc = cs_validate_socket(sock);
774
775 if (rc < 0)
776 return rc;
777 ptr = kzalloc(sizeof(*ptr), GFP_KERNEL);
778 if (!ptr)
779 return -ENOMEM;
780 /*
781 * Subsequent LSM hooks will receive "newsock". Therefore, I mark
782 * "newsock" as "an accept()ed socket but post accept() permission
783 * check is not done yet" by allocating memory using inode of the
784 * "newsock" as a search key.
785 */
786 ptr->inode = SOCK_INODE(newsock);
787 ptr->status = 1; /* Check post accept() permission later. */
788 spin_lock(&cs_accepted_socket_list_lock);
789 list_add_tail_rcu(&ptr->list, &cs_accepted_socket_list);
790 spin_unlock(&cs_accepted_socket_list_lock);
791 return 0;
792 }
793
794 /**
795 * cs_socket_listen - Check permission for listen().
796 *
797 * @sock: Pointer to "struct socket".
798 * @backlog: Backlog parameter.
799 *
800 * Returns 0 on success, negative value otherwise.
801 */
802 static int cs_socket_listen(struct socket *sock, int backlog)
803 {
804 const int rc = cs_validate_socket(sock);
805
806 if (rc < 0)
807 return rc;
808 return cs_socket_listen_permission(sock);
809 }
810
811 /**
812 * cs_socket_connect - Check permission for connect().
813 *
814 * @sock: Pointer to "struct socket".
815 * @addr: Pointer to "struct sockaddr".
816 * @addr_len: Size of @addr.
817 *
818 * Returns 0 on success, negative value otherwise.
819 */
820 static int cs_socket_connect(struct socket *sock, struct sockaddr *addr,
821 int addr_len)
822 {
823 const int rc = cs_validate_socket(sock);
824
825 if (rc < 0)
826 return rc;
827 return cs_socket_connect_permission(sock, addr, addr_len);
828 }
829
830 /**
831 * cs_socket_bind - Check permission for bind().
832 *
833 * @sock: Pointer to "struct socket".
834 * @addr: Pointer to "struct sockaddr".
835 * @addr_len: Size of @addr.
836 *
837 * Returns 0 on success, negative value otherwise.
838 */
839 static int cs_socket_bind(struct socket *sock, struct sockaddr *addr,
840 int addr_len)
841 {
842 const int rc = cs_validate_socket(sock);
843
844 if (rc < 0)
845 return rc;
846 return cs_socket_bind_permission(sock, addr, addr_len);
847 }
848
849 /**
850 * cs_socket_sendmsg - Check permission for sendmsg().
851 *
852 * @sock: Pointer to "struct socket".
853 * @msg: Pointer to "struct msghdr".
854 * @size: Size of message.
855 *
856 * Returns 0 on success, negative value otherwise.
857 */
858 static int cs_socket_sendmsg(struct socket *sock, struct msghdr *msg,
859 int size)
860 {
861 const int rc = cs_validate_socket(sock);
862
863 if (rc < 0)
864 return rc;
865 return cs_socket_sendmsg_permission(sock, msg, size);
866 }
867
868 /**
869 * cs_socket_recvmsg - Check permission for recvmsg().
870 *
871 * @sock: Pointer to "struct socket".
872 * @msg: Pointer to "struct msghdr".
873 * @size: Size of message.
874 * @flags: Flags.
875 *
876 * Returns 0 on success, negative value otherwise.
877 */
878 static int cs_socket_recvmsg(struct socket *sock, struct msghdr *msg,
879 int size, int flags)
880 {
881 return cs_validate_socket(sock);
882 }
883
884 /**
885 * cs_socket_getsockname - Check permission for getsockname().
886 *
887 * @sock: Pointer to "struct socket".
888 *
889 * Returns 0 on success, negative value otherwise.
890 */
891 static int cs_socket_getsockname(struct socket *sock)
892 {
893 return cs_validate_socket(sock);
894 }
895
896 /**
897 * cs_socket_getpeername - Check permission for getpeername().
898 *
899 * @sock: Pointer to "struct socket".
900 *
901 * Returns 0 on success, negative value otherwise.
902 */
903 static int cs_socket_getpeername(struct socket *sock)
904 {
905 return cs_validate_socket(sock);
906 }
907
908 /**
909 * cs_socket_getsockopt - Check permission for getsockopt().
910 *
911 * @sock: Pointer to "struct socket".
912 * @level: Level.
913 * @optname: Option's name,
914 *
915 * Returns 0 on success, negative value otherwise.
916 */
917 static int cs_socket_getsockopt(struct socket *sock, int level, int optname)
918 {
919 return cs_validate_socket(sock);
920 }
921
922 /**
923 * cs_socket_setsockopt - Check permission for setsockopt().
924 *
925 * @sock: Pointer to "struct socket".
926 * @level: Level.
927 * @optname: Option's name,
928 *
929 * Returns 0 on success, negative value otherwise.
930 */
931 static int cs_socket_setsockopt(struct socket *sock, int level, int optname)
932 {
933 return cs_validate_socket(sock);
934 }
935
936 /**
937 * cs_socket_shutdown - Check permission for shutdown().
938 *
939 * @sock: Pointer to "struct socket".
940 * @how: Shutdown mode.
941 *
942 * Returns 0 on success, negative value otherwise.
943 */
944 static int cs_socket_shutdown(struct socket *sock, int how)
945 {
946 return cs_validate_socket(sock);
947 }
948
949 #define SOCKFS_MAGIC 0x534F434B
950
951 /**
952 * cs_inode_free_security - Release memory associated with an inode.
953 *
954 * @inode: Pointer to "struct inode".
955 *
956 * Returns nothing.
957 *
958 * We use this hook for releasing memory associated with an accept()ed socket.
959 */
960 static void cs_inode_free_security(struct inode *inode)
961 {
962 if (inode->i_sb && inode->i_sb->s_magic == SOCKFS_MAGIC)
963 cs_update_socket_tag(inode, 0);
964 }
965
966 #endif
967
968 /**
969 * cs_sb_pivotroot - Check permission for pivot_root().
970 *
971 * @old_path: Pointer to "struct path".
972 * @new_path: Pointer to "struct path".
973 *
974 * Returns 0 on success, negative value otherwise.
975 */
976 static int cs_sb_pivotroot(const struct path *old_path,
977 const struct path *new_path)
978 {
979 return cs_pivot_root_permission(old_path, new_path);
980 }
981
982 /**
983 * cs_sb_mount - Check permission for mount().
984 *
985 * @dev_name: Name of device file.
986 * @path: Pointer to "struct path".
987 * @type: Name of filesystem type. Maybe NULL.
988 * @flags: Mount options.
989 * @data_page: Optional data. Maybe NULL.
990 *
991 * Returns 0 on success, negative value otherwise.
992 */
993 static int cs_sb_mount(const char *dev_name, const struct path *path,
994 const char *type, unsigned long flags, void *data_page)
995 {
996 return cs_mount_permission(dev_name, path, type, flags, data_page);
997 }
998
999 /**
1000 * cs_sb_umount - Check permission for umount().
1001 *
1002 * @mnt: Pointer to "struct vfsmount".
1003 * @flags: Unmount flags.
1004 *
1005 * Returns 0 on success, negative value otherwise.
1006 */
1007 static int cs_sb_umount(struct vfsmount *mnt, int flags)
1008 {
1009 struct path path = { .mnt = mnt, .dentry = mnt->mnt_root };
1010
1011 return cs_umount_permission(&path, flags);
1012 }
1013
1014 /**
1015 * cs_file_fcntl - Check permission for fcntl().
1016 *
1017 * @file: Pointer to "struct file".
1018 * @cmd: Command number.
1019 * @arg: Value for @cmd.
1020 *
1021 * Returns 0 on success, negative value otherwise.
1022 */
1023 static int cs_file_fcntl(struct file *file, unsigned int cmd,
1024 unsigned long arg)
1025 {
1026 return cs_fcntl_permission(file, cmd, arg);
1027 }
1028
1029 /**
1030 * cs_file_ioctl - Check permission for ioctl().
1031 *
1032 * @filp: Pointer to "struct file".
1033 * @cmd: Command number.
1034 * @arg: Value for @cmd.
1035 *
1036 * Returns 0 on success, negative value otherwise.
1037 */
1038 static int cs_file_ioctl(struct file *filp, unsigned int cmd,
1039 unsigned long arg)
1040 {
1041 return cs_ioctl_permission(filp, cmd, arg);
1042 }
1043
1044 #define MY_HOOK_INIT(HEAD, HOOK) \
1045 { .head = &probe_dummy_security_hook_heads.HEAD, \
1046 .hook = { .HEAD = HOOK } }
1047
1048 static struct security_hook_list caitsith_hooks[] = {
1049 /* Security context allocator. */
1050 MY_HOOK_INIT(task_free, cs_task_free_security),
1051 MY_HOOK_INIT(cred_prepare, cs_cred_prepare),
1052 MY_HOOK_INIT(task_alloc, cs_task_alloc_security),
1053 /* Security context updater for successful execve(). */
1054 MY_HOOK_INIT(bprm_check_security, cs_bprm_check_security),
1055 MY_HOOK_INIT(bprm_committing_creds, cs_bprm_committing_creds),
1056 /* Various permission checker. */
1057 MY_HOOK_INIT(file_open, cs_file_open),
1058 MY_HOOK_INIT(file_fcntl, cs_file_fcntl),
1059 MY_HOOK_INIT(file_ioctl, cs_file_ioctl),
1060 MY_HOOK_INIT(sb_pivotroot, cs_sb_pivotroot),
1061 MY_HOOK_INIT(sb_mount, cs_sb_mount),
1062 MY_HOOK_INIT(sb_umount, cs_sb_umount),
1063 #ifdef CONFIG_SECURITY_PATH
1064 MY_HOOK_INIT(path_mknod, cs_path_mknod),
1065 MY_HOOK_INIT(path_mkdir, cs_path_mkdir),
1066 MY_HOOK_INIT(path_rmdir, cs_path_rmdir),
1067 MY_HOOK_INIT(path_unlink, cs_path_unlink),
1068 MY_HOOK_INIT(path_symlink, cs_path_symlink),
1069 MY_HOOK_INIT(path_rename, cs_path_rename),
1070 MY_HOOK_INIT(path_link, cs_path_link),
1071 MY_HOOK_INIT(path_truncate, cs_path_truncate),
1072 MY_HOOK_INIT(path_chmod, cs_path_chmod),
1073 MY_HOOK_INIT(path_chown, cs_path_chown),
1074 MY_HOOK_INIT(path_chroot, cs_path_chroot),
1075 #else
1076 MY_HOOK_INIT(inode_mknod, cs_inode_mknod),
1077 MY_HOOK_INIT(inode_mkdir, cs_inode_mkdir),
1078 MY_HOOK_INIT(inode_rmdir, cs_inode_rmdir),
1079 MY_HOOK_INIT(inode_unlink, cs_inode_unlink),
1080 MY_HOOK_INIT(inode_symlink, cs_inode_symlink),
1081 MY_HOOK_INIT(inode_rename, cs_inode_rename),
1082 MY_HOOK_INIT(inode_link, cs_inode_link),
1083 MY_HOOK_INIT(inode_create, cs_inode_create),
1084 MY_HOOK_INIT(inode_setattr, cs_inode_setattr),
1085 #endif
1086 MY_HOOK_INIT(inode_getattr, cs_inode_getattr),
1087 #ifdef CONFIG_SECURITY_NETWORK
1088 MY_HOOK_INIT(socket_bind, cs_socket_bind),
1089 MY_HOOK_INIT(socket_connect, cs_socket_connect),
1090 MY_HOOK_INIT(socket_listen, cs_socket_listen),
1091 MY_HOOK_INIT(socket_sendmsg, cs_socket_sendmsg),
1092 MY_HOOK_INIT(socket_recvmsg, cs_socket_recvmsg),
1093 MY_HOOK_INIT(socket_getsockname, cs_socket_getsockname),
1094 MY_HOOK_INIT(socket_getpeername, cs_socket_getpeername),
1095 MY_HOOK_INIT(socket_getsockopt, cs_socket_getsockopt),
1096 MY_HOOK_INIT(socket_setsockopt, cs_socket_setsockopt),
1097 MY_HOOK_INIT(socket_shutdown, cs_socket_shutdown),
1098 MY_HOOK_INIT(socket_accept, cs_socket_accept),
1099 MY_HOOK_INIT(inode_free_security, cs_inode_free_security),
1100 #endif
1101 };
1102
1103 static inline void add_hook(struct security_hook_list *hook)
1104 {
1105 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 17, 0)
1106 hlist_add_tail_rcu(&hook->list, hook->head);
1107 #else
1108 list_add_tail_rcu(&hook->list, hook->head);
1109 #endif
1110 }
1111
1112 static void __init swap_hook(struct security_hook_list *hook,
1113 union security_list_options *original)
1114 {
1115 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 17, 0)
1116 struct hlist_head *list = hook->head;
1117
1118 if (hlist_empty(list)) {
1119 add_hook(hook);
1120 } else {
1121 struct security_hook_list *shp =
1122 hlist_entry(list->first, typeof(*shp), list);
1123
1124 while (shp->list.next)
1125 shp = hlist_entry(shp->list.next, typeof(*shp), list);
1126 *original = shp->hook;
1127 smp_wmb();
1128 shp->hook = hook->hook;
1129 }
1130 #else
1131 struct list_head *list = hook->head;
1132
1133 if (list_empty(list)) {
1134 add_hook(hook);
1135 } else {
1136 struct security_hook_list *shp =
1137 list_last_entry(list, struct security_hook_list, list);
1138
1139 *original = shp->hook;
1140 smp_wmb();
1141 shp->hook = hook->hook;
1142 }
1143 #endif
1144 }
1145
1146 #if defined(CONFIG_STRICT_KERNEL_RWX) && !defined(CONFIG_SECURITY_WRITABLE_HOOKS)
1147 #include <linux/uaccess.h> /* probe_kernel_write() */
1148 #define NEED_TO_CHECK_HOOKS_ARE_WRITABLE
1149
1150 #if defined(CONFIG_X86)
1151 #define MAX_RO_PAGES 1024
1152 static struct page *ro_pages[MAX_RO_PAGES] __initdata;
1153 static unsigned int ro_pages_len __initdata;
1154
1155 static bool __init lsm_test_page_ro(void *addr)
1156 {
1157 unsigned int i;
1158 int unused;
1159 struct page *page;
1160
1161 page = (struct page *) lookup_address((unsigned long) addr, &unused);
1162 if (!page)
1163 return false;
1164 if (test_bit(_PAGE_BIT_RW, &(page->flags)))
1165 return true;
1166 for (i = 0; i < ro_pages_len; i++)
1167 if (page == ro_pages[i])
1168 return true;
1169 if (ro_pages_len == MAX_RO_PAGES)
1170 return false;
1171 ro_pages[ro_pages_len++] = page;
1172 return true;
1173 }
1174
1175 static bool __init check_ro_pages(struct security_hook_heads *hooks)
1176 {
1177 int i;
1178 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 17, 0)
1179 struct hlist_head *list = &hooks->capable;
1180
1181 if (!probe_kernel_write(list, list, sizeof(void *)))
1182 return true;
1183 for (i = 0; i < ARRAY_SIZE(caitsith_hooks); i++) {
1184 struct hlist_head *head = caitsith_hooks[i].head;
1185 struct security_hook_list *shp;
1186
1187 if (!lsm_test_page_ro(&head->first))
1188 return false;
1189 hlist_for_each_entry(shp, head, list)
1190 if (!lsm_test_page_ro(&shp->list.next) ||
1191 !lsm_test_page_ro(&shp->list.pprev))
1192 return false;
1193 }
1194 #else
1195 struct list_head *list = &hooks->capable;
1196
1197 if (!probe_kernel_write(list, list, sizeof(void *)))
1198 return true;
1199 for (i = 0; i < ARRAY_SIZE(caitsith_hooks); i++) {
1200 struct list_head *head = caitsith_hooks[i].head;
1201 struct security_hook_list *shp;
1202
1203 if (!lsm_test_page_ro(&head->next) ||
1204 !lsm_test_page_ro(&head->prev))
1205 return false;
1206 list_for_each_entry(shp, head, list)
1207 if (!lsm_test_page_ro(&shp->list.next) ||
1208 !lsm_test_page_ro(&shp->list.prev))
1209 return false;
1210 }
1211 #endif
1212 return true;
1213 }
1214 #else
1215 static bool __init check_ro_pages(struct security_hook_heads *hooks)
1216 {
1217 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 17, 0)
1218 struct hlist_head *list = &hooks->capable;
1219 #else
1220 struct list_head *list = &hooks->capable;
1221 #endif
1222
1223 return !probe_kernel_write(list, list, sizeof(void *));
1224 }
1225 #endif
1226 #endif
1227
1228 /**
1229 * cs_init - Initialize this module.
1230 *
1231 * Returns 0 on success, negative value otherwise.
1232 */
1233 static int __init cs_init(void)
1234 {
1235 int idx;
1236 struct security_hook_heads *hooks = probe_security_hook_heads();
1237
1238 if (!hooks)
1239 goto out;
1240 for (idx = 0; idx < ARRAY_SIZE(caitsith_hooks); idx++)
1241 caitsith_hooks[idx].head = ((void *) hooks)
1242 + ((unsigned long) caitsith_hooks[idx].head)
1243 - ((unsigned long) &probe_dummy_security_hook_heads);
1244 #if defined(NEED_TO_CHECK_HOOKS_ARE_WRITABLE)
1245 if (!check_ro_pages(hooks)) {
1246 printk(KERN_INFO "Can't update security_hook_heads due to write protected. Retry with rodata=0 kernel command line option added.\n");
1247 return -EINVAL;
1248 }
1249 #endif
1250 caitsith_exports.find_task_by_vpid = probe_find_task_by_vpid();
1251 if (!caitsith_exports.find_task_by_vpid)
1252 goto out;
1253 caitsith_exports.find_task_by_pid_ns = probe_find_task_by_pid_ns();
1254 if (!caitsith_exports.find_task_by_pid_ns)
1255 goto out;
1256 caitsith_exports.d_absolute_path = probe_d_absolute_path();
1257 if (!caitsith_exports.d_absolute_path)
1258 goto out;
1259 for (idx = 0; idx < CS_MAX_TASK_SECURITY_HASH; idx++)
1260 INIT_LIST_HEAD(&cs_task_security_list[idx]);
1261 cs_init_module();
1262 #if defined(NEED_TO_CHECK_HOOKS_ARE_WRITABLE) && defined(CONFIG_X86)
1263 for (idx = 0; idx < ro_pages_len; idx++)
1264 set_bit(_PAGE_BIT_RW, &(ro_pages[idx]->flags));
1265 #endif
1266 swap_hook(&caitsith_hooks[0], &original_task_free);
1267 swap_hook(&caitsith_hooks[1], &original_cred_prepare);
1268 swap_hook(&caitsith_hooks[2], &original_task_alloc);
1269 for (idx = 3; idx < ARRAY_SIZE(caitsith_hooks); idx++)
1270 add_hook(&caitsith_hooks[idx]);
1271 #if defined(NEED_TO_CHECK_HOOKS_ARE_WRITABLE) && defined(CONFIG_X86)
1272 for (idx = 0; idx < ro_pages_len; idx++)
1273 clear_bit(_PAGE_BIT_RW, &(ro_pages[idx]->flags));
1274 #endif
1275 return 0;
1276 out:
1277 return -EINVAL;
1278 }
1279
1280 module_init(cs_init);
1281 MODULE_LICENSE("GPL");
1282
1283 /**
1284 * cs_used_by_cred - Check whether the given domain is in use or not.
1285 *
1286 * @domain: Pointer to "struct cs_domain_info".
1287 *
1288 * Returns true if @domain is in use, false otherwise.
1289 *
1290 * Caller holds rcu_read_lock().
1291 */
1292 bool cs_used_by_cred(const struct cs_domain_info *domain)
1293 {
1294 return false;
1295 }
1296
1297 /**
1298 * cs_add_task_security - Add "struct cs_security" to list.
1299 *
1300 * @ptr: Pointer to "struct cs_security".
1301 * @list: Pointer to "struct list_head".
1302 *
1303 * Returns nothing.
1304 */
1305 static void cs_add_task_security(struct cs_security *ptr,
1306 struct list_head *list)
1307 {
1308 unsigned long flags;
1309
1310 spin_lock_irqsave(&cs_task_security_list_lock, flags);
1311 list_add_rcu(&ptr->list, list);
1312 spin_unlock_irqrestore(&cs_task_security_list_lock, flags);
1313 }
1314
1315 /**
1316 * __cs_alloc_task_security - Allocate memory for new tasks.
1317 *
1318 * @task: Pointer to "struct task_struct".
1319 *
1320 * Returns 0 on success, negative value otherwise.
1321 */
1322 static int __cs_alloc_task_security(const struct task_struct *task)
1323 {
1324 struct cs_security *old_security = cs_current_security();
1325 struct cs_security *new_security = kzalloc(sizeof(*new_security),
1326 GFP_KERNEL);
1327 struct list_head *list = &cs_task_security_list
1328 [hash_ptr((void *) task, CS_TASK_SECURITY_HASH_BITS)];
1329
1330 if (!new_security)
1331 return -ENOMEM;
1332 new_security->task = task;
1333 new_security->cs_domain_info = old_security->cs_domain_info;
1334 new_security->cs_flags = old_security->cs_flags;
1335 cs_add_task_security(new_security, list);
1336 return 0;
1337 }
1338
1339 /**
1340 * cs_find_task_security - Find "struct cs_security" for given task.
1341 *
1342 * @task: Pointer to "struct task_struct".
1343 *
1344 * Returns pointer to "struct cs_security" on success, &cs_oom_security on
1345 * out of memory, &cs_default_security otherwise.
1346 *
1347 * If @task is current thread and "struct cs_security" for current thread was
1348 * not found, I try to allocate it. But if allocation failed, current thread
1349 * will be killed by SIGKILL. Note that if current->pid == 1, sending SIGKILL
1350 * won't work.
1351 */
1352 struct cs_security *cs_find_task_security(const struct task_struct *task)
1353 {
1354 struct cs_security *ptr;
1355 struct list_head *list = &cs_task_security_list
1356 [hash_ptr((void *) task, CS_TASK_SECURITY_HASH_BITS)];
1357 /* Make sure INIT_LIST_HEAD() in cs_mm_init() takes effect. */
1358 while (!list->next)
1359 smp_rmb();
1360 rcu_read_lock();
1361 list_for_each_entry_rcu(ptr, list, list) {
1362 if (ptr->task != task)
1363 continue;
1364 rcu_read_unlock();
1365 /*
1366 * Current thread needs to transit from old domain to new
1367 * domain before do_execve() succeeds in order to check
1368 * permission for interpreters and environment variables using
1369 * new domain's ACL rules. The domain transition has to be
1370 * visible from other CPU in order to allow interactive
1371 * enforcing mode. Also, the domain transition has to be
1372 * reverted if do_execve() failed. However, an LSM hook for
1373 * reverting domain transition is missing.
1374 *
1375 * security_prepare_creds() is called from prepare_creds() from
1376 * prepare_bprm_creds() from do_execve() before setting
1377 * current->in_execve flag, and current->in_execve flag is
1378 * cleared by the time next do_execve() request starts.
1379 * This means that we can emulate the missing LSM hook for
1380 * reverting domain transition, by calling this function from
1381 * security_prepare_creds().
1382 *
1383 * If current->in_execve is not set but ptr->cs_flags has
1384 * CS_TASK_IS_IN_EXECVE set, it indicates that do_execve()
1385 * has failed and reverting domain transition is needed.
1386 */
1387 if (task == current &&
1388 (ptr->cs_flags & CS_TASK_IS_IN_EXECVE) &&
1389 !current->in_execve) {
1390 cs_debug_trace("1");
1391 cs_clear_execve(-1, ptr);
1392 }
1393 return ptr;
1394 }
1395 rcu_read_unlock();
1396 if (task != current)
1397 return &cs_default_security;
1398 /* Use GFP_ATOMIC because caller may have called rcu_read_lock(). */
1399 ptr = kzalloc(sizeof(*ptr), GFP_ATOMIC);
1400 if (!ptr) {
1401 printk(KERN_WARNING "Unable to allocate memory for pid=%u\n",
1402 task->pid);
1403 send_sig(SIGKILL, current, 0);
1404 return &cs_oom_security;
1405 }
1406 *ptr = cs_default_security;
1407 ptr->task = task;
1408 cs_add_task_security(ptr, list);
1409 return ptr;
1410 }

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