Security: split proc ptrace checking into read vs. attach
[kernel.git] / security / dummy.c
1 /*
2  * Stub functions for the default security function pointers in case no
3  * security model is loaded.
4  *
5  * Copyright (C) 2001 WireX Communications, Inc <chris@wirex.com>
6  * Copyright (C) 2001-2002  Greg Kroah-Hartman <greg@kroah.com>
7  * Copyright (C) 2001 Networks Associates Technology, Inc <ssmalley@nai.com>
8  *
9  *      This program is free software; you can redistribute it and/or modify
10  *      it under the terms of the GNU General Public License as published by
11  *      the Free Software Foundation; either version 2 of the License, or
12  *      (at your option) any later version.
13  */
14
15 #undef DEBUG
16
17 #include <linux/capability.h>
18 #include <linux/kernel.h>
19 #include <linux/mman.h>
20 #include <linux/pagemap.h>
21 #include <linux/swap.h>
22 #include <linux/security.h>
23 #include <linux/skbuff.h>
24 #include <linux/netlink.h>
25 #include <net/sock.h>
26 #include <linux/xattr.h>
27 #include <linux/hugetlb.h>
28 #include <linux/ptrace.h>
29 #include <linux/file.h>
30 #include <linux/prctl.h>
31 #include <linux/securebits.h>
32
33 static int dummy_ptrace (struct task_struct *parent, struct task_struct *child,
34                          unsigned int mode)
35 {
36         return 0;
37 }
38
39 static int dummy_capget (struct task_struct *target, kernel_cap_t * effective,
40                          kernel_cap_t * inheritable, kernel_cap_t * permitted)
41 {
42         if (target->euid == 0) {
43                 cap_set_full(*permitted);
44                 cap_set_init_eff(*effective);
45         } else {
46                 cap_clear(*permitted);
47                 cap_clear(*effective);
48         }
49
50         cap_clear(*inheritable);
51
52         if (target->fsuid != 0) {
53                 *permitted = cap_drop_fs_set(*permitted);
54                 *effective = cap_drop_fs_set(*effective);
55         }
56         return 0;
57 }
58
59 static int dummy_capset_check (struct task_struct *target,
60                                kernel_cap_t * effective,
61                                kernel_cap_t * inheritable,
62                                kernel_cap_t * permitted)
63 {
64         return -EPERM;
65 }
66
67 static void dummy_capset_set (struct task_struct *target,
68                               kernel_cap_t * effective,
69                               kernel_cap_t * inheritable,
70                               kernel_cap_t * permitted)
71 {
72         return;
73 }
74
75 static int dummy_acct (struct file *file)
76 {
77         return 0;
78 }
79
80 static int dummy_capable (struct task_struct *tsk, int cap)
81 {
82         if (cap_raised (tsk->cap_effective, cap))
83                 return 0;
84         return -EPERM;
85 }
86
87 static int dummy_sysctl (ctl_table * table, int op)
88 {
89         return 0;
90 }
91
92 static int dummy_quotactl (int cmds, int type, int id, struct super_block *sb)
93 {
94         return 0;
95 }
96
97 static int dummy_quota_on (struct dentry *dentry)
98 {
99         return 0;
100 }
101
102 static int dummy_syslog (int type)
103 {
104         if ((type != 3 && type != 10) && current->euid)
105                 return -EPERM;
106         return 0;
107 }
108
109 static int dummy_settime(struct timespec *ts, struct timezone *tz)
110 {
111         if (!capable(CAP_SYS_TIME))
112                 return -EPERM;
113         return 0;
114 }
115
116 static int dummy_vm_enough_memory(struct mm_struct *mm, long pages)
117 {
118         int cap_sys_admin = 0;
119
120         if (dummy_capable(current, CAP_SYS_ADMIN) == 0)
121                 cap_sys_admin = 1;
122         return __vm_enough_memory(mm, pages, cap_sys_admin);
123 }
124
125 static int dummy_bprm_alloc_security (struct linux_binprm *bprm)
126 {
127         return 0;
128 }
129
130 static void dummy_bprm_free_security (struct linux_binprm *bprm)
131 {
132         return;
133 }
134
135 static void dummy_bprm_apply_creds (struct linux_binprm *bprm, int unsafe)
136 {
137         if (bprm->e_uid != current->uid || bprm->e_gid != current->gid) {
138                 set_dumpable(current->mm, suid_dumpable);
139
140                 if ((unsafe & ~LSM_UNSAFE_PTRACE_CAP) && !capable(CAP_SETUID)) {
141                         bprm->e_uid = current->uid;
142                         bprm->e_gid = current->gid;
143                 }
144         }
145
146         current->suid = current->euid = current->fsuid = bprm->e_uid;
147         current->sgid = current->egid = current->fsgid = bprm->e_gid;
148
149         dummy_capget(current, &current->cap_effective, &current->cap_inheritable, &current->cap_permitted);
150 }
151
152 static void dummy_bprm_post_apply_creds (struct linux_binprm *bprm)
153 {
154         return;
155 }
156
157 static int dummy_bprm_set_security (struct linux_binprm *bprm)
158 {
159         return 0;
160 }
161
162 static int dummy_bprm_check_security (struct linux_binprm *bprm)
163 {
164         return 0;
165 }
166
167 static int dummy_bprm_secureexec (struct linux_binprm *bprm)
168 {
169         /* The new userland will simply use the value provided
170            in the AT_SECURE field to decide whether secure mode
171            is required.  Hence, this logic is required to preserve
172            the legacy decision algorithm used by the old userland. */
173         return (current->euid != current->uid ||
174                 current->egid != current->gid);
175 }
176
177 static int dummy_sb_alloc_security (struct super_block *sb)
178 {
179         return 0;
180 }
181
182 static void dummy_sb_free_security (struct super_block *sb)
183 {
184         return;
185 }
186
187 static int dummy_sb_copy_data (char *orig, char *copy)
188 {
189         return 0;
190 }
191
192 static int dummy_sb_kern_mount (struct super_block *sb, void *data)
193 {
194         return 0;
195 }
196
197 static int dummy_sb_statfs (struct dentry *dentry)
198 {
199         return 0;
200 }
201
202 static int dummy_sb_mount (char *dev_name, struct path *path, char *type,
203                            unsigned long flags, void *data)
204 {
205         return 0;
206 }
207
208 static int dummy_sb_check_sb (struct vfsmount *mnt, struct path *path)
209 {
210         return 0;
211 }
212
213 static int dummy_sb_umount (struct vfsmount *mnt, int flags)
214 {
215         return 0;
216 }
217
218 static void dummy_sb_umount_close (struct vfsmount *mnt)
219 {
220         return;
221 }
222
223 static void dummy_sb_umount_busy (struct vfsmount *mnt)
224 {
225         return;
226 }
227
228 static void dummy_sb_post_remount (struct vfsmount *mnt, unsigned long flags,
229                                    void *data)
230 {
231         return;
232 }
233
234
235 static void dummy_sb_post_addmount (struct vfsmount *mnt, struct path *path)
236 {
237         return;
238 }
239
240 static int dummy_sb_pivotroot (struct path *old_path, struct path *new_path)
241 {
242         return 0;
243 }
244
245 static void dummy_sb_post_pivotroot (struct path *old_path, struct path *new_path)
246 {
247         return;
248 }
249
250 static int dummy_sb_get_mnt_opts(const struct super_block *sb,
251                                  struct security_mnt_opts *opts)
252 {
253         security_init_mnt_opts(opts);
254         return 0;
255 }
256
257 static int dummy_sb_set_mnt_opts(struct super_block *sb,
258                                  struct security_mnt_opts *opts)
259 {
260         if (unlikely(opts->num_mnt_opts))
261                 return -EOPNOTSUPP;
262         return 0;
263 }
264
265 static void dummy_sb_clone_mnt_opts(const struct super_block *oldsb,
266                                     struct super_block *newsb)
267 {
268         return;
269 }
270
271 static int dummy_sb_parse_opts_str(char *options, struct security_mnt_opts *opts)
272 {
273         return 0;
274 }
275
276 static int dummy_inode_alloc_security (struct inode *inode)
277 {
278         return 0;
279 }
280
281 static void dummy_inode_free_security (struct inode *inode)
282 {
283         return;
284 }
285
286 static int dummy_inode_init_security (struct inode *inode, struct inode *dir,
287                                       char **name, void **value, size_t *len)
288 {
289         return -EOPNOTSUPP;
290 }
291
292 static int dummy_inode_create (struct inode *inode, struct dentry *dentry,
293                                int mask)
294 {
295         return 0;
296 }
297
298 static int dummy_inode_link (struct dentry *old_dentry, struct inode *inode,
299                              struct dentry *new_dentry)
300 {
301         return 0;
302 }
303
304 static int dummy_inode_unlink (struct inode *inode, struct dentry *dentry)
305 {
306         return 0;
307 }
308
309 static int dummy_inode_symlink (struct inode *inode, struct dentry *dentry,
310                                 const char *name)
311 {
312         return 0;
313 }
314
315 static int dummy_inode_mkdir (struct inode *inode, struct dentry *dentry,
316                               int mask)
317 {
318         return 0;
319 }
320
321 static int dummy_inode_rmdir (struct inode *inode, struct dentry *dentry)
322 {
323         return 0;
324 }
325
326 static int dummy_inode_mknod (struct inode *inode, struct dentry *dentry,
327                               int mode, dev_t dev)
328 {
329         return 0;
330 }
331
332 static int dummy_inode_rename (struct inode *old_inode,
333                                struct dentry *old_dentry,
334                                struct inode *new_inode,
335                                struct dentry *new_dentry)
336 {
337         return 0;
338 }
339
340 static int dummy_inode_readlink (struct dentry *dentry)
341 {
342         return 0;
343 }
344
345 static int dummy_inode_follow_link (struct dentry *dentry,
346                                     struct nameidata *nameidata)
347 {
348         return 0;
349 }
350
351 static int dummy_inode_permission (struct inode *inode, int mask, struct nameidata *nd)
352 {
353         return 0;
354 }
355
356 static int dummy_inode_setattr (struct dentry *dentry, struct iattr *iattr)
357 {
358         return 0;
359 }
360
361 static int dummy_inode_getattr (struct vfsmount *mnt, struct dentry *dentry)
362 {
363         return 0;
364 }
365
366 static void dummy_inode_delete (struct inode *ino)
367 {
368         return;
369 }
370
371 static int dummy_inode_setxattr (struct dentry *dentry, const char *name,
372                                  const void *value, size_t size, int flags)
373 {
374         if (!strncmp(name, XATTR_SECURITY_PREFIX,
375                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
376             !capable(CAP_SYS_ADMIN))
377                 return -EPERM;
378         return 0;
379 }
380
381 static void dummy_inode_post_setxattr (struct dentry *dentry, const char *name,
382                                        const void *value, size_t size,
383                                        int flags)
384 {
385 }
386
387 static int dummy_inode_getxattr (struct dentry *dentry, const char *name)
388 {
389         return 0;
390 }
391
392 static int dummy_inode_listxattr (struct dentry *dentry)
393 {
394         return 0;
395 }
396
397 static int dummy_inode_removexattr (struct dentry *dentry, const char *name)
398 {
399         if (!strncmp(name, XATTR_SECURITY_PREFIX,
400                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
401             !capable(CAP_SYS_ADMIN))
402                 return -EPERM;
403         return 0;
404 }
405
406 static int dummy_inode_need_killpriv(struct dentry *dentry)
407 {
408         return 0;
409 }
410
411 static int dummy_inode_killpriv(struct dentry *dentry)
412 {
413         return 0;
414 }
415
416 static int dummy_inode_getsecurity(const struct inode *inode, const char *name, void **buffer, bool alloc)
417 {
418         return -EOPNOTSUPP;
419 }
420
421 static int dummy_inode_setsecurity(struct inode *inode, const char *name, const void *value, size_t size, int flags)
422 {
423         return -EOPNOTSUPP;
424 }
425
426 static int dummy_inode_listsecurity(struct inode *inode, char *buffer, size_t buffer_size)
427 {
428         return 0;
429 }
430
431 static void dummy_inode_getsecid(const struct inode *inode, u32 *secid)
432 {
433         *secid = 0;
434 }
435
436 static int dummy_file_permission (struct file *file, int mask)
437 {
438         return 0;
439 }
440
441 static int dummy_file_alloc_security (struct file *file)
442 {
443         return 0;
444 }
445
446 static void dummy_file_free_security (struct file *file)
447 {
448         return;
449 }
450
451 static int dummy_file_ioctl (struct file *file, unsigned int command,
452                              unsigned long arg)
453 {
454         return 0;
455 }
456
457 static int dummy_file_mmap (struct file *file, unsigned long reqprot,
458                             unsigned long prot,
459                             unsigned long flags,
460                             unsigned long addr,
461                             unsigned long addr_only)
462 {
463         if ((addr < mmap_min_addr) && !capable(CAP_SYS_RAWIO))
464                 return -EACCES;
465         return 0;
466 }
467
468 static int dummy_file_mprotect (struct vm_area_struct *vma,
469                                 unsigned long reqprot,
470                                 unsigned long prot)
471 {
472         return 0;
473 }
474
475 static int dummy_file_lock (struct file *file, unsigned int cmd)
476 {
477         return 0;
478 }
479
480 static int dummy_file_fcntl (struct file *file, unsigned int cmd,
481                              unsigned long arg)
482 {
483         return 0;
484 }
485
486 static int dummy_file_set_fowner (struct file *file)
487 {
488         return 0;
489 }
490
491 static int dummy_file_send_sigiotask (struct task_struct *tsk,
492                                       struct fown_struct *fown, int sig)
493 {
494         return 0;
495 }
496
497 static int dummy_file_receive (struct file *file)
498 {
499         return 0;
500 }
501
502 static int dummy_dentry_open (struct file *file)
503 {
504         return 0;
505 }
506
507 static int dummy_task_create (unsigned long clone_flags)
508 {
509         return 0;
510 }
511
512 static int dummy_task_alloc_security (struct task_struct *p)
513 {
514         return 0;
515 }
516
517 static void dummy_task_free_security (struct task_struct *p)
518 {
519         return;
520 }
521
522 static int dummy_task_setuid (uid_t id0, uid_t id1, uid_t id2, int flags)
523 {
524         return 0;
525 }
526
527 static int dummy_task_post_setuid (uid_t id0, uid_t id1, uid_t id2, int flags)
528 {
529         dummy_capget(current, &current->cap_effective, &current->cap_inheritable, &current->cap_permitted);
530         return 0;
531 }
532
533 static int dummy_task_setgid (gid_t id0, gid_t id1, gid_t id2, int flags)
534 {
535         return 0;
536 }
537
538 static int dummy_task_setpgid (struct task_struct *p, pid_t pgid)
539 {
540         return 0;
541 }
542
543 static int dummy_task_getpgid (struct task_struct *p)
544 {
545         return 0;
546 }
547
548 static int dummy_task_getsid (struct task_struct *p)
549 {
550         return 0;
551 }
552
553 static void dummy_task_getsecid (struct task_struct *p, u32 *secid)
554 {
555         *secid = 0;
556 }
557
558 static int dummy_task_setgroups (struct group_info *group_info)
559 {
560         return 0;
561 }
562
563 static int dummy_task_setnice (struct task_struct *p, int nice)
564 {
565         return 0;
566 }
567
568 static int dummy_task_setioprio (struct task_struct *p, int ioprio)
569 {
570         return 0;
571 }
572
573 static int dummy_task_getioprio (struct task_struct *p)
574 {
575         return 0;
576 }
577
578 static int dummy_task_setrlimit (unsigned int resource, struct rlimit *new_rlim)
579 {
580         return 0;
581 }
582
583 static int dummy_task_setscheduler (struct task_struct *p, int policy,
584                                     struct sched_param *lp)
585 {
586         return 0;
587 }
588
589 static int dummy_task_getscheduler (struct task_struct *p)
590 {
591         return 0;
592 }
593
594 static int dummy_task_movememory (struct task_struct *p)
595 {
596         return 0;
597 }
598
599 static int dummy_task_wait (struct task_struct *p)
600 {
601         return 0;
602 }
603
604 static int dummy_task_kill (struct task_struct *p, struct siginfo *info,
605                             int sig, u32 secid)
606 {
607         return 0;
608 }
609
610 static int dummy_task_prctl (int option, unsigned long arg2, unsigned long arg3,
611                              unsigned long arg4, unsigned long arg5, long *rc_p)
612 {
613         switch (option) {
614         case PR_CAPBSET_READ:
615                 *rc_p = (cap_valid(arg2) ? 1 : -EINVAL);
616                 break;
617         case PR_GET_KEEPCAPS:
618                 *rc_p = issecure(SECURE_KEEP_CAPS);
619                 break;
620         case PR_SET_KEEPCAPS:
621                 if (arg2 > 1)
622                         *rc_p = -EINVAL;
623                 else if (arg2)
624                         current->securebits |= issecure_mask(SECURE_KEEP_CAPS);
625                 else
626                         current->securebits &=
627                                 ~issecure_mask(SECURE_KEEP_CAPS);
628                 break;
629         default:
630                 return 0;
631         }
632
633         return 1;
634 }
635
636 static void dummy_task_reparent_to_init (struct task_struct *p)
637 {
638         p->euid = p->fsuid = 0;
639         return;
640 }
641
642 static void dummy_task_to_inode(struct task_struct *p, struct inode *inode)
643 { }
644
645 static int dummy_ipc_permission (struct kern_ipc_perm *ipcp, short flag)
646 {
647         return 0;
648 }
649
650 static void dummy_ipc_getsecid(struct kern_ipc_perm *ipcp, u32 *secid)
651 {
652         *secid = 0;
653 }
654
655 static int dummy_msg_msg_alloc_security (struct msg_msg *msg)
656 {
657         return 0;
658 }
659
660 static void dummy_msg_msg_free_security (struct msg_msg *msg)
661 {
662         return;
663 }
664
665 static int dummy_msg_queue_alloc_security (struct msg_queue *msq)
666 {
667         return 0;
668 }
669
670 static void dummy_msg_queue_free_security (struct msg_queue *msq)
671 {
672         return;
673 }
674
675 static int dummy_msg_queue_associate (struct msg_queue *msq, 
676                                       int msqflg)
677 {
678         return 0;
679 }
680
681 static int dummy_msg_queue_msgctl (struct msg_queue *msq, int cmd)
682 {
683         return 0;
684 }
685
686 static int dummy_msg_queue_msgsnd (struct msg_queue *msq, struct msg_msg *msg,
687                                    int msgflg)
688 {
689         return 0;
690 }
691
692 static int dummy_msg_queue_msgrcv (struct msg_queue *msq, struct msg_msg *msg,
693                                    struct task_struct *target, long type,
694                                    int mode)
695 {
696         return 0;
697 }
698
699 static int dummy_shm_alloc_security (struct shmid_kernel *shp)
700 {
701         return 0;
702 }
703
704 static void dummy_shm_free_security (struct shmid_kernel *shp)
705 {
706         return;
707 }
708
709 static int dummy_shm_associate (struct shmid_kernel *shp, int shmflg)
710 {
711         return 0;
712 }
713
714 static int dummy_shm_shmctl (struct shmid_kernel *shp, int cmd)
715 {
716         return 0;
717 }
718
719 static int dummy_shm_shmat (struct shmid_kernel *shp, char __user *shmaddr,
720                             int shmflg)
721 {
722         return 0;
723 }
724
725 static int dummy_sem_alloc_security (struct sem_array *sma)
726 {
727         return 0;
728 }
729
730 static void dummy_sem_free_security (struct sem_array *sma)
731 {
732         return;
733 }
734
735 static int dummy_sem_associate (struct sem_array *sma, int semflg)
736 {
737         return 0;
738 }
739
740 static int dummy_sem_semctl (struct sem_array *sma, int cmd)
741 {
742         return 0;
743 }
744
745 static int dummy_sem_semop (struct sem_array *sma, 
746                             struct sembuf *sops, unsigned nsops, int alter)
747 {
748         return 0;
749 }
750
751 static int dummy_netlink_send (struct sock *sk, struct sk_buff *skb)
752 {
753         NETLINK_CB(skb).eff_cap = current->cap_effective;
754         return 0;
755 }
756
757 static int dummy_netlink_recv (struct sk_buff *skb, int cap)
758 {
759         if (!cap_raised (NETLINK_CB (skb).eff_cap, cap))
760                 return -EPERM;
761         return 0;
762 }
763
764 #ifdef CONFIG_SECURITY_NETWORK
765 static int dummy_unix_stream_connect (struct socket *sock,
766                                       struct socket *other,
767                                       struct sock *newsk)
768 {
769         return 0;
770 }
771
772 static int dummy_unix_may_send (struct socket *sock,
773                                 struct socket *other)
774 {
775         return 0;
776 }
777
778 static int dummy_socket_create (int family, int type,
779                                 int protocol, int kern)
780 {
781         return 0;
782 }
783
784 static int dummy_socket_post_create (struct socket *sock, int family, int type,
785                                      int protocol, int kern)
786 {
787         return 0;
788 }
789
790 static int dummy_socket_bind (struct socket *sock, struct sockaddr *address,
791                               int addrlen)
792 {
793         return 0;
794 }
795
796 static int dummy_socket_connect (struct socket *sock, struct sockaddr *address,
797                                  int addrlen)
798 {
799         return 0;
800 }
801
802 static int dummy_socket_listen (struct socket *sock, int backlog)
803 {
804         return 0;
805 }
806
807 static int dummy_socket_accept (struct socket *sock, struct socket *newsock)
808 {
809         return 0;
810 }
811
812 static void dummy_socket_post_accept (struct socket *sock, 
813                                       struct socket *newsock)
814 {
815         return;
816 }
817
818 static int dummy_socket_sendmsg (struct socket *sock, struct msghdr *msg,
819                                  int size)
820 {
821         return 0;
822 }
823
824 static int dummy_socket_recvmsg (struct socket *sock, struct msghdr *msg,
825                                  int size, int flags)
826 {
827         return 0;
828 }
829
830 static int dummy_socket_getsockname (struct socket *sock)
831 {
832         return 0;
833 }
834
835 static int dummy_socket_getpeername (struct socket *sock)
836 {
837         return 0;
838 }
839
840 static int dummy_socket_setsockopt (struct socket *sock, int level, int optname)
841 {
842         return 0;
843 }
844
845 static int dummy_socket_getsockopt (struct socket *sock, int level, int optname)
846 {
847         return 0;
848 }
849
850 static int dummy_socket_shutdown (struct socket *sock, int how)
851 {
852         return 0;
853 }
854
855 static int dummy_socket_sock_rcv_skb (struct sock *sk, struct sk_buff *skb)
856 {
857         return 0;
858 }
859
860 static int dummy_socket_getpeersec_stream(struct socket *sock, char __user *optval,
861                                           int __user *optlen, unsigned len)
862 {
863         return -ENOPROTOOPT;
864 }
865
866 static int dummy_socket_getpeersec_dgram(struct socket *sock, struct sk_buff *skb, u32 *secid)
867 {
868         return -ENOPROTOOPT;
869 }
870
871 static inline int dummy_sk_alloc_security (struct sock *sk, int family, gfp_t priority)
872 {
873         return 0;
874 }
875
876 static inline void dummy_sk_free_security (struct sock *sk)
877 {
878 }
879
880 static inline void dummy_sk_clone_security (const struct sock *sk, struct sock *newsk)
881 {
882 }
883
884 static inline void dummy_sk_getsecid(struct sock *sk, u32 *secid)
885 {
886 }
887
888 static inline void dummy_sock_graft(struct sock* sk, struct socket *parent)
889 {
890 }
891
892 static inline int dummy_inet_conn_request(struct sock *sk,
893                         struct sk_buff *skb, struct request_sock *req)
894 {
895         return 0;
896 }
897
898 static inline void dummy_inet_csk_clone(struct sock *newsk,
899                         const struct request_sock *req)
900 {
901 }
902
903 static inline void dummy_inet_conn_established(struct sock *sk,
904                         struct sk_buff *skb)
905 {
906 }
907
908 static inline void dummy_req_classify_flow(const struct request_sock *req,
909                         struct flowi *fl)
910 {
911 }
912 #endif  /* CONFIG_SECURITY_NETWORK */
913
914 #ifdef CONFIG_SECURITY_NETWORK_XFRM
915 static int dummy_xfrm_policy_alloc_security(struct xfrm_sec_ctx **ctxp,
916                                             struct xfrm_user_sec_ctx *sec_ctx)
917 {
918         return 0;
919 }
920
921 static inline int dummy_xfrm_policy_clone_security(struct xfrm_sec_ctx *old_ctx,
922                                            struct xfrm_sec_ctx **new_ctxp)
923 {
924         return 0;
925 }
926
927 static void dummy_xfrm_policy_free_security(struct xfrm_sec_ctx *ctx)
928 {
929 }
930
931 static int dummy_xfrm_policy_delete_security(struct xfrm_sec_ctx *ctx)
932 {
933         return 0;
934 }
935
936 static int dummy_xfrm_state_alloc_security(struct xfrm_state *x,
937         struct xfrm_user_sec_ctx *sec_ctx, u32 secid)
938 {
939         return 0;
940 }
941
942 static void dummy_xfrm_state_free_security(struct xfrm_state *x)
943 {
944 }
945
946 static int dummy_xfrm_state_delete_security(struct xfrm_state *x)
947 {
948         return 0;
949 }
950
951 static int dummy_xfrm_policy_lookup(struct xfrm_sec_ctx *ctx,
952                                     u32 sk_sid, u8 dir)
953 {
954         return 0;
955 }
956
957 static int dummy_xfrm_state_pol_flow_match(struct xfrm_state *x,
958                                 struct xfrm_policy *xp, struct flowi *fl)
959 {
960         return 1;
961 }
962
963 static int dummy_xfrm_decode_session(struct sk_buff *skb, u32 *fl, int ckall)
964 {
965         return 0;
966 }
967
968 #endif /* CONFIG_SECURITY_NETWORK_XFRM */
969 static int dummy_register_security (const char *name, struct security_operations *ops)
970 {
971         return -EINVAL;
972 }
973
974 static void dummy_d_instantiate (struct dentry *dentry, struct inode *inode)
975 {
976         return;
977 }
978
979 static int dummy_getprocattr(struct task_struct *p, char *name, char **value)
980 {
981         return -EINVAL;
982 }
983
984 static int dummy_setprocattr(struct task_struct *p, char *name, void *value, size_t size)
985 {
986         return -EINVAL;
987 }
988
989 static int dummy_secid_to_secctx(u32 secid, char **secdata, u32 *seclen)
990 {
991         return -EOPNOTSUPP;
992 }
993
994 static int dummy_secctx_to_secid(const char *secdata, u32 seclen, u32 *secid)
995 {
996         return -EOPNOTSUPP;
997 }
998
999 static void dummy_release_secctx(char *secdata, u32 seclen)
1000 {
1001 }
1002
1003 #ifdef CONFIG_KEYS
1004 static inline int dummy_key_alloc(struct key *key, struct task_struct *ctx,
1005                                   unsigned long flags)
1006 {
1007         return 0;
1008 }
1009
1010 static inline void dummy_key_free(struct key *key)
1011 {
1012 }
1013
1014 static inline int dummy_key_permission(key_ref_t key_ref,
1015                                        struct task_struct *context,
1016                                        key_perm_t perm)
1017 {
1018         return 0;
1019 }
1020
1021 static int dummy_key_getsecurity(struct key *key, char **_buffer)
1022 {
1023         *_buffer = NULL;
1024         return 0;
1025 }
1026
1027 #endif /* CONFIG_KEYS */
1028
1029 #ifdef CONFIG_AUDIT
1030 static inline int dummy_audit_rule_init(u32 field, u32 op, char *rulestr,
1031                                         void **lsmrule)
1032 {
1033         return 0;
1034 }
1035
1036 static inline int dummy_audit_rule_known(struct audit_krule *krule)
1037 {
1038         return 0;
1039 }
1040
1041 static inline int dummy_audit_rule_match(u32 secid, u32 field, u32 op,
1042                                          void *lsmrule,
1043                                          struct audit_context *actx)
1044 {
1045         return 0;
1046 }
1047
1048 static inline void dummy_audit_rule_free(void *lsmrule)
1049 { }
1050
1051 #endif /* CONFIG_AUDIT */
1052
1053 struct security_operations dummy_security_ops = {
1054         .name = "dummy",
1055 };
1056
1057 #define set_to_dummy_if_null(ops, function)                             \
1058         do {                                                            \
1059                 if (!ops->function) {                                   \
1060                         ops->function = dummy_##function;               \
1061                         pr_debug("Had to override the " #function       \
1062                                  " security operation with the dummy one.\n");\
1063                         }                                               \
1064         } while (0)
1065
1066 void security_fixup_ops (struct security_operations *ops)
1067 {
1068         set_to_dummy_if_null(ops, ptrace);
1069         set_to_dummy_if_null(ops, capget);
1070         set_to_dummy_if_null(ops, capset_check);
1071         set_to_dummy_if_null(ops, capset_set);
1072         set_to_dummy_if_null(ops, acct);
1073         set_to_dummy_if_null(ops, capable);
1074         set_to_dummy_if_null(ops, quotactl);
1075         set_to_dummy_if_null(ops, quota_on);
1076         set_to_dummy_if_null(ops, sysctl);
1077         set_to_dummy_if_null(ops, syslog);
1078         set_to_dummy_if_null(ops, settime);
1079         set_to_dummy_if_null(ops, vm_enough_memory);
1080         set_to_dummy_if_null(ops, bprm_alloc_security);
1081         set_to_dummy_if_null(ops, bprm_free_security);
1082         set_to_dummy_if_null(ops, bprm_apply_creds);
1083         set_to_dummy_if_null(ops, bprm_post_apply_creds);
1084         set_to_dummy_if_null(ops, bprm_set_security);
1085         set_to_dummy_if_null(ops, bprm_check_security);
1086         set_to_dummy_if_null(ops, bprm_secureexec);
1087         set_to_dummy_if_null(ops, sb_alloc_security);
1088         set_to_dummy_if_null(ops, sb_free_security);
1089         set_to_dummy_if_null(ops, sb_copy_data);
1090         set_to_dummy_if_null(ops, sb_kern_mount);
1091         set_to_dummy_if_null(ops, sb_statfs);
1092         set_to_dummy_if_null(ops, sb_mount);
1093         set_to_dummy_if_null(ops, sb_check_sb);
1094         set_to_dummy_if_null(ops, sb_umount);
1095         set_to_dummy_if_null(ops, sb_umount_close);
1096         set_to_dummy_if_null(ops, sb_umount_busy);
1097         set_to_dummy_if_null(ops, sb_post_remount);
1098         set_to_dummy_if_null(ops, sb_post_addmount);
1099         set_to_dummy_if_null(ops, sb_pivotroot);
1100         set_to_dummy_if_null(ops, sb_post_pivotroot);
1101         set_to_dummy_if_null(ops, sb_get_mnt_opts);
1102         set_to_dummy_if_null(ops, sb_set_mnt_opts);
1103         set_to_dummy_if_null(ops, sb_clone_mnt_opts);
1104         set_to_dummy_if_null(ops, sb_parse_opts_str);
1105         set_to_dummy_if_null(ops, inode_alloc_security);
1106         set_to_dummy_if_null(ops, inode_free_security);
1107         set_to_dummy_if_null(ops, inode_init_security);
1108         set_to_dummy_if_null(ops, inode_create);
1109         set_to_dummy_if_null(ops, inode_link);
1110         set_to_dummy_if_null(ops, inode_unlink);
1111         set_to_dummy_if_null(ops, inode_symlink);
1112         set_to_dummy_if_null(ops, inode_mkdir);
1113         set_to_dummy_if_null(ops, inode_rmdir);
1114         set_to_dummy_if_null(ops, inode_mknod);
1115         set_to_dummy_if_null(ops, inode_rename);
1116         set_to_dummy_if_null(ops, inode_readlink);
1117         set_to_dummy_if_null(ops, inode_follow_link);
1118         set_to_dummy_if_null(ops, inode_permission);
1119         set_to_dummy_if_null(ops, inode_setattr);
1120         set_to_dummy_if_null(ops, inode_getattr);
1121         set_to_dummy_if_null(ops, inode_delete);
1122         set_to_dummy_if_null(ops, inode_setxattr);
1123         set_to_dummy_if_null(ops, inode_post_setxattr);
1124         set_to_dummy_if_null(ops, inode_getxattr);
1125         set_to_dummy_if_null(ops, inode_listxattr);
1126         set_to_dummy_if_null(ops, inode_removexattr);
1127         set_to_dummy_if_null(ops, inode_need_killpriv);
1128         set_to_dummy_if_null(ops, inode_killpriv);
1129         set_to_dummy_if_null(ops, inode_getsecurity);
1130         set_to_dummy_if_null(ops, inode_setsecurity);
1131         set_to_dummy_if_null(ops, inode_listsecurity);
1132         set_to_dummy_if_null(ops, inode_getsecid);
1133         set_to_dummy_if_null(ops, file_permission);
1134         set_to_dummy_if_null(ops, file_alloc_security);
1135         set_to_dummy_if_null(ops, file_free_security);
1136         set_to_dummy_if_null(ops, file_ioctl);
1137         set_to_dummy_if_null(ops, file_mmap);
1138         set_to_dummy_if_null(ops, file_mprotect);
1139         set_to_dummy_if_null(ops, file_lock);
1140         set_to_dummy_if_null(ops, file_fcntl);
1141         set_to_dummy_if_null(ops, file_set_fowner);
1142         set_to_dummy_if_null(ops, file_send_sigiotask);
1143         set_to_dummy_if_null(ops, file_receive);
1144         set_to_dummy_if_null(ops, dentry_open);
1145         set_to_dummy_if_null(ops, task_create);
1146         set_to_dummy_if_null(ops, task_alloc_security);
1147         set_to_dummy_if_null(ops, task_free_security);
1148         set_to_dummy_if_null(ops, task_setuid);
1149         set_to_dummy_if_null(ops, task_post_setuid);
1150         set_to_dummy_if_null(ops, task_setgid);
1151         set_to_dummy_if_null(ops, task_setpgid);
1152         set_to_dummy_if_null(ops, task_getpgid);
1153         set_to_dummy_if_null(ops, task_getsid);
1154         set_to_dummy_if_null(ops, task_getsecid);
1155         set_to_dummy_if_null(ops, task_setgroups);
1156         set_to_dummy_if_null(ops, task_setnice);
1157         set_to_dummy_if_null(ops, task_setioprio);
1158         set_to_dummy_if_null(ops, task_getioprio);
1159         set_to_dummy_if_null(ops, task_setrlimit);
1160         set_to_dummy_if_null(ops, task_setscheduler);
1161         set_to_dummy_if_null(ops, task_getscheduler);
1162         set_to_dummy_if_null(ops, task_movememory);
1163         set_to_dummy_if_null(ops, task_wait);
1164         set_to_dummy_if_null(ops, task_kill);
1165         set_to_dummy_if_null(ops, task_prctl);
1166         set_to_dummy_if_null(ops, task_reparent_to_init);
1167         set_to_dummy_if_null(ops, task_to_inode);
1168         set_to_dummy_if_null(ops, ipc_permission);
1169         set_to_dummy_if_null(ops, ipc_getsecid);
1170         set_to_dummy_if_null(ops, msg_msg_alloc_security);
1171         set_to_dummy_if_null(ops, msg_msg_free_security);
1172         set_to_dummy_if_null(ops, msg_queue_alloc_security);
1173         set_to_dummy_if_null(ops, msg_queue_free_security);
1174         set_to_dummy_if_null(ops, msg_queue_associate);
1175         set_to_dummy_if_null(ops, msg_queue_msgctl);
1176         set_to_dummy_if_null(ops, msg_queue_msgsnd);
1177         set_to_dummy_if_null(ops, msg_queue_msgrcv);
1178         set_to_dummy_if_null(ops, shm_alloc_security);
1179         set_to_dummy_if_null(ops, shm_free_security);
1180         set_to_dummy_if_null(ops, shm_associate);
1181         set_to_dummy_if_null(ops, shm_shmctl);
1182         set_to_dummy_if_null(ops, shm_shmat);
1183         set_to_dummy_if_null(ops, sem_alloc_security);
1184         set_to_dummy_if_null(ops, sem_free_security);
1185         set_to_dummy_if_null(ops, sem_associate);
1186         set_to_dummy_if_null(ops, sem_semctl);
1187         set_to_dummy_if_null(ops, sem_semop);
1188         set_to_dummy_if_null(ops, netlink_send);
1189         set_to_dummy_if_null(ops, netlink_recv);
1190         set_to_dummy_if_null(ops, register_security);
1191         set_to_dummy_if_null(ops, d_instantiate);
1192         set_to_dummy_if_null(ops, getprocattr);
1193         set_to_dummy_if_null(ops, setprocattr);
1194         set_to_dummy_if_null(ops, secid_to_secctx);
1195         set_to_dummy_if_null(ops, secctx_to_secid);
1196         set_to_dummy_if_null(ops, release_secctx);
1197 #ifdef CONFIG_SECURITY_NETWORK
1198         set_to_dummy_if_null(ops, unix_stream_connect);
1199         set_to_dummy_if_null(ops, unix_may_send);
1200         set_to_dummy_if_null(ops, socket_create);
1201         set_to_dummy_if_null(ops, socket_post_create);
1202         set_to_dummy_if_null(ops, socket_bind);
1203         set_to_dummy_if_null(ops, socket_connect);
1204         set_to_dummy_if_null(ops, socket_listen);
1205         set_to_dummy_if_null(ops, socket_accept);
1206         set_to_dummy_if_null(ops, socket_post_accept);
1207         set_to_dummy_if_null(ops, socket_sendmsg);
1208         set_to_dummy_if_null(ops, socket_recvmsg);
1209         set_to_dummy_if_null(ops, socket_getsockname);
1210         set_to_dummy_if_null(ops, socket_getpeername);
1211         set_to_dummy_if_null(ops, socket_setsockopt);
1212         set_to_dummy_if_null(ops, socket_getsockopt);
1213         set_to_dummy_if_null(ops, socket_shutdown);
1214         set_to_dummy_if_null(ops, socket_sock_rcv_skb);
1215         set_to_dummy_if_null(ops, socket_getpeersec_stream);
1216         set_to_dummy_if_null(ops, socket_getpeersec_dgram);
1217         set_to_dummy_if_null(ops, sk_alloc_security);
1218         set_to_dummy_if_null(ops, sk_free_security);
1219         set_to_dummy_if_null(ops, sk_clone_security);
1220         set_to_dummy_if_null(ops, sk_getsecid);
1221         set_to_dummy_if_null(ops, sock_graft);
1222         set_to_dummy_if_null(ops, inet_conn_request);
1223         set_to_dummy_if_null(ops, inet_csk_clone);
1224         set_to_dummy_if_null(ops, inet_conn_established);
1225         set_to_dummy_if_null(ops, req_classify_flow);
1226  #endif /* CONFIG_SECURITY_NETWORK */
1227 #ifdef  CONFIG_SECURITY_NETWORK_XFRM
1228         set_to_dummy_if_null(ops, xfrm_policy_alloc_security);
1229         set_to_dummy_if_null(ops, xfrm_policy_clone_security);
1230         set_to_dummy_if_null(ops, xfrm_policy_free_security);
1231         set_to_dummy_if_null(ops, xfrm_policy_delete_security);
1232         set_to_dummy_if_null(ops, xfrm_state_alloc_security);
1233         set_to_dummy_if_null(ops, xfrm_state_free_security);
1234         set_to_dummy_if_null(ops, xfrm_state_delete_security);
1235         set_to_dummy_if_null(ops, xfrm_policy_lookup);
1236         set_to_dummy_if_null(ops, xfrm_state_pol_flow_match);
1237         set_to_dummy_if_null(ops, xfrm_decode_session);
1238 #endif  /* CONFIG_SECURITY_NETWORK_XFRM */
1239 #ifdef CONFIG_KEYS
1240         set_to_dummy_if_null(ops, key_alloc);
1241         set_to_dummy_if_null(ops, key_free);
1242         set_to_dummy_if_null(ops, key_permission);
1243         set_to_dummy_if_null(ops, key_getsecurity);
1244 #endif  /* CONFIG_KEYS */
1245 #ifdef CONFIG_AUDIT
1246         set_to_dummy_if_null(ops, audit_rule_init);
1247         set_to_dummy_if_null(ops, audit_rule_known);
1248         set_to_dummy_if_null(ops, audit_rule_match);
1249         set_to_dummy_if_null(ops, audit_rule_free);
1250 #endif
1251 }
1252