do_gettimeoffset() is unused.
[linux-2.6/linux-mips.git] / security / dummy.c
blob18de8edb32c84a853fa1db400f08785158fbc692
1 /*
2 * Stub functions for the default security function pointers in case no
3 * security model is loaded.
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>
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.
15 #undef DEBUG
17 #include <linux/config.h>
18 #include <linux/module.h>
19 #include <linux/kernel.h>
20 #include <linux/security.h>
21 #include <linux/skbuff.h>
22 #include <linux/netlink.h>
23 #include <net/sock.h>
25 static int dummy_ptrace (struct task_struct *parent, struct task_struct *child)
27 return 0;
30 static int dummy_capget (struct task_struct *target, kernel_cap_t * effective,
31 kernel_cap_t * inheritable, kernel_cap_t * permitted)
33 *effective = *inheritable = *permitted = 0;
34 if (!issecure(SECURE_NOROOT)) {
35 if (target->euid == 0) {
36 *permitted |= (~0 & ~CAP_FS_MASK);
37 *effective |= (~0 & ~CAP_TO_MASK(CAP_SETPCAP) & ~CAP_FS_MASK);
39 if (target->fsuid == 0) {
40 *permitted |= CAP_FS_MASK;
41 *effective |= CAP_FS_MASK;
44 return 0;
47 static int dummy_capset_check (struct task_struct *target,
48 kernel_cap_t * effective,
49 kernel_cap_t * inheritable,
50 kernel_cap_t * permitted)
52 return -EPERM;
55 static void dummy_capset_set (struct task_struct *target,
56 kernel_cap_t * effective,
57 kernel_cap_t * inheritable,
58 kernel_cap_t * permitted)
60 return;
63 static int dummy_acct (struct file *file)
65 return 0;
68 static int dummy_capable (struct task_struct *tsk, int cap)
70 if (cap_is_fs_cap (cap) ? tsk->fsuid == 0 : tsk->euid == 0)
71 /* capability granted */
72 return 0;
74 /* capability denied */
75 return -EPERM;
78 static int dummy_sysctl (ctl_table * table, int op)
80 return 0;
83 static int dummy_quotactl (int cmds, int type, int id, struct super_block *sb)
85 return 0;
88 static int dummy_quota_on (struct file *f)
90 return 0;
93 static int dummy_syslog (int type)
95 if ((type != 3) && current->euid)
96 return -EPERM;
97 return 0;
100 static int dummy_bprm_alloc_security (struct linux_binprm *bprm)
102 return 0;
105 static void dummy_bprm_free_security (struct linux_binprm *bprm)
107 return;
110 static void dummy_bprm_compute_creds (struct linux_binprm *bprm)
112 return;
115 static int dummy_bprm_set_security (struct linux_binprm *bprm)
117 return 0;
120 static int dummy_bprm_check_security (struct linux_binprm *bprm)
122 return 0;
125 static int dummy_sb_alloc_security (struct super_block *sb)
127 return 0;
130 static void dummy_sb_free_security (struct super_block *sb)
132 return;
135 static int dummy_sb_kern_mount (struct super_block *sb)
137 return 0;
140 static int dummy_sb_statfs (struct super_block *sb)
142 return 0;
145 static int dummy_sb_mount (char *dev_name, struct nameidata *nd, char *type,
146 unsigned long flags, void *data)
148 return 0;
151 static int dummy_sb_check_sb (struct vfsmount *mnt, struct nameidata *nd)
153 return 0;
156 static int dummy_sb_umount (struct vfsmount *mnt, int flags)
158 return 0;
161 static void dummy_sb_umount_close (struct vfsmount *mnt)
163 return;
166 static void dummy_sb_umount_busy (struct vfsmount *mnt)
168 return;
171 static void dummy_sb_post_remount (struct vfsmount *mnt, unsigned long flags,
172 void *data)
174 return;
178 static void dummy_sb_post_mountroot (void)
180 return;
183 static void dummy_sb_post_addmount (struct vfsmount *mnt, struct nameidata *nd)
185 return;
188 static int dummy_sb_pivotroot (struct nameidata *old_nd, struct nameidata *new_nd)
190 return 0;
193 static void dummy_sb_post_pivotroot (struct nameidata *old_nd, struct nameidata *new_nd)
195 return;
198 static int dummy_inode_alloc_security (struct inode *inode)
200 return 0;
203 static void dummy_inode_free_security (struct inode *inode)
205 return;
208 static int dummy_inode_create (struct inode *inode, struct dentry *dentry,
209 int mask)
211 return 0;
214 static void dummy_inode_post_create (struct inode *inode, struct dentry *dentry,
215 int mask)
217 return;
220 static int dummy_inode_link (struct dentry *old_dentry, struct inode *inode,
221 struct dentry *new_dentry)
223 return 0;
226 static void dummy_inode_post_link (struct dentry *old_dentry,
227 struct inode *inode,
228 struct dentry *new_dentry)
230 return;
233 static int dummy_inode_unlink (struct inode *inode, struct dentry *dentry)
235 return 0;
238 static int dummy_inode_symlink (struct inode *inode, struct dentry *dentry,
239 const char *name)
241 return 0;
244 static void dummy_inode_post_symlink (struct inode *inode,
245 struct dentry *dentry, const char *name)
247 return;
250 static int dummy_inode_mkdir (struct inode *inode, struct dentry *dentry,
251 int mask)
253 return 0;
256 static void dummy_inode_post_mkdir (struct inode *inode, struct dentry *dentry,
257 int mask)
259 return;
262 static int dummy_inode_rmdir (struct inode *inode, struct dentry *dentry)
264 return 0;
267 static int dummy_inode_mknod (struct inode *inode, struct dentry *dentry,
268 int mode, dev_t dev)
270 return 0;
273 static void dummy_inode_post_mknod (struct inode *inode, struct dentry *dentry,
274 int mode, dev_t dev)
276 return;
279 static int dummy_inode_rename (struct inode *old_inode,
280 struct dentry *old_dentry,
281 struct inode *new_inode,
282 struct dentry *new_dentry)
284 return 0;
287 static void dummy_inode_post_rename (struct inode *old_inode,
288 struct dentry *old_dentry,
289 struct inode *new_inode,
290 struct dentry *new_dentry)
292 return;
295 static int dummy_inode_readlink (struct dentry *dentry)
297 return 0;
300 static int dummy_inode_follow_link (struct dentry *dentry,
301 struct nameidata *nameidata)
303 return 0;
306 static int dummy_inode_permission (struct inode *inode, int mask)
308 return 0;
311 static int dummy_inode_setattr (struct dentry *dentry, struct iattr *iattr)
313 return 0;
316 static int dummy_inode_getattr (struct vfsmount *mnt, struct dentry *dentry)
318 return 0;
321 static void dummy_inode_delete (struct inode *ino)
323 return;
326 static int dummy_inode_setxattr (struct dentry *dentry, char *name, void *value,
327 size_t size, int flags)
329 return 0;
332 static void dummy_inode_post_setxattr (struct dentry *dentry, char *name, void *value,
333 size_t size, int flags)
337 static int dummy_inode_getxattr (struct dentry *dentry, char *name)
339 return 0;
342 static int dummy_inode_listxattr (struct dentry *dentry)
344 return 0;
347 static int dummy_inode_removexattr (struct dentry *dentry, char *name)
349 return 0;
352 static int dummy_inode_getsecurity(struct dentry *dentry, const char *name, void *buffer, size_t size)
354 return -EOPNOTSUPP;
357 static int dummy_inode_setsecurity(struct dentry *dentry, const char *name, const void *value, size_t size, int flags)
359 return -EOPNOTSUPP;
362 static int dummy_inode_listsecurity(struct dentry *dentry, char *buffer)
364 return 0;
367 static int dummy_file_permission (struct file *file, int mask)
369 return 0;
372 static int dummy_file_alloc_security (struct file *file)
374 return 0;
377 static void dummy_file_free_security (struct file *file)
379 return;
382 static int dummy_file_ioctl (struct file *file, unsigned int command,
383 unsigned long arg)
385 return 0;
388 static int dummy_file_mmap (struct file *file, unsigned long prot,
389 unsigned long flags)
391 return 0;
394 static int dummy_file_mprotect (struct vm_area_struct *vma, unsigned long prot)
396 return 0;
399 static int dummy_file_lock (struct file *file, unsigned int cmd)
401 return 0;
404 static int dummy_file_fcntl (struct file *file, unsigned int cmd,
405 unsigned long arg)
407 return 0;
410 static int dummy_file_set_fowner (struct file *file)
412 return 0;
415 static int dummy_file_send_sigiotask (struct task_struct *tsk,
416 struct fown_struct *fown, int fd,
417 int reason)
419 return 0;
422 static int dummy_file_receive (struct file *file)
424 return 0;
427 static int dummy_task_create (unsigned long clone_flags)
429 return 0;
432 static int dummy_task_alloc_security (struct task_struct *p)
434 return 0;
437 static void dummy_task_free_security (struct task_struct *p)
439 return;
442 static int dummy_task_setuid (uid_t id0, uid_t id1, uid_t id2, int flags)
444 return 0;
447 static int dummy_task_post_setuid (uid_t id0, uid_t id1, uid_t id2, int flags)
449 return 0;
452 static int dummy_task_setgid (gid_t id0, gid_t id1, gid_t id2, int flags)
454 return 0;
457 static int dummy_task_setpgid (struct task_struct *p, pid_t pgid)
459 return 0;
462 static int dummy_task_getpgid (struct task_struct *p)
464 return 0;
467 static int dummy_task_getsid (struct task_struct *p)
469 return 0;
472 static int dummy_task_setgroups (int gidsetsize, gid_t * grouplist)
474 return 0;
477 static int dummy_task_setnice (struct task_struct *p, int nice)
479 return 0;
482 static int dummy_task_setrlimit (unsigned int resource, struct rlimit *new_rlim)
484 return 0;
487 static int dummy_task_setscheduler (struct task_struct *p, int policy,
488 struct sched_param *lp)
490 return 0;
493 static int dummy_task_getscheduler (struct task_struct *p)
495 return 0;
498 static int dummy_task_wait (struct task_struct *p)
500 return 0;
503 static int dummy_task_kill (struct task_struct *p, struct siginfo *info,
504 int sig)
506 return 0;
509 static int dummy_task_prctl (int option, unsigned long arg2, unsigned long arg3,
510 unsigned long arg4, unsigned long arg5)
512 return 0;
515 static void dummy_task_reparent_to_init (struct task_struct *p)
517 p->euid = p->fsuid = 0;
518 return;
521 static void dummy_task_to_inode(struct task_struct *p, struct inode *inode)
524 static int dummy_ipc_permission (struct kern_ipc_perm *ipcp, short flag)
526 return 0;
529 static int dummy_msg_msg_alloc_security (struct msg_msg *msg)
531 return 0;
534 static void dummy_msg_msg_free_security (struct msg_msg *msg)
536 return;
539 static int dummy_msg_queue_alloc_security (struct msg_queue *msq)
541 return 0;
544 static void dummy_msg_queue_free_security (struct msg_queue *msq)
546 return;
549 static int dummy_msg_queue_associate (struct msg_queue *msq,
550 int msqflg)
552 return 0;
555 static int dummy_msg_queue_msgctl (struct msg_queue *msq, int cmd)
557 return 0;
560 static int dummy_msg_queue_msgsnd (struct msg_queue *msq, struct msg_msg *msg,
561 int msgflg)
563 return 0;
566 static int dummy_msg_queue_msgrcv (struct msg_queue *msq, struct msg_msg *msg,
567 struct task_struct *target, long type,
568 int mode)
570 return 0;
573 static int dummy_shm_alloc_security (struct shmid_kernel *shp)
575 return 0;
578 static void dummy_shm_free_security (struct shmid_kernel *shp)
580 return;
583 static int dummy_shm_associate (struct shmid_kernel *shp, int shmflg)
585 return 0;
588 static int dummy_shm_shmctl (struct shmid_kernel *shp, int cmd)
590 return 0;
593 static int dummy_shm_shmat (struct shmid_kernel *shp, char *shmaddr,
594 int shmflg)
596 return 0;
599 static int dummy_sem_alloc_security (struct sem_array *sma)
601 return 0;
604 static void dummy_sem_free_security (struct sem_array *sma)
606 return;
609 static int dummy_sem_associate (struct sem_array *sma, int semflg)
611 return 0;
614 static int dummy_sem_semctl (struct sem_array *sma, int cmd)
616 return 0;
619 static int dummy_sem_semop (struct sem_array *sma,
620 struct sembuf *sops, unsigned nsops, int alter)
622 return 0;
625 static int dummy_netlink_send (struct sk_buff *skb)
627 if (current->euid == 0)
628 cap_raise (NETLINK_CB (skb).eff_cap, CAP_NET_ADMIN);
629 else
630 NETLINK_CB (skb).eff_cap = 0;
631 return 0;
634 static int dummy_netlink_recv (struct sk_buff *skb)
636 if (!cap_raised (NETLINK_CB (skb).eff_cap, CAP_NET_ADMIN))
637 return -EPERM;
638 return 0;
641 #ifdef CONFIG_SECURITY_NETWORK
642 static int dummy_unix_stream_connect (struct socket *sock,
643 struct socket *other,
644 struct sock *newsk)
646 return 0;
649 static int dummy_unix_may_send (struct socket *sock,
650 struct socket *other)
652 return 0;
655 static int dummy_socket_create (int family, int type, int protocol)
657 return 0;
660 static void dummy_socket_post_create (struct socket *sock, int family, int type,
661 int protocol)
663 return;
666 static int dummy_socket_bind (struct socket *sock, struct sockaddr *address,
667 int addrlen)
669 return 0;
672 static int dummy_socket_connect (struct socket *sock, struct sockaddr *address,
673 int addrlen)
675 return 0;
678 static int dummy_socket_listen (struct socket *sock, int backlog)
680 return 0;
683 static int dummy_socket_accept (struct socket *sock, struct socket *newsock)
685 return 0;
688 static void dummy_socket_post_accept (struct socket *sock,
689 struct socket *newsock)
691 return;
694 static int dummy_socket_sendmsg (struct socket *sock, struct msghdr *msg,
695 int size)
697 return 0;
700 static int dummy_socket_recvmsg (struct socket *sock, struct msghdr *msg,
701 int size, int flags)
703 return 0;
706 static int dummy_socket_getsockname (struct socket *sock)
708 return 0;
711 static int dummy_socket_getpeername (struct socket *sock)
713 return 0;
716 static int dummy_socket_setsockopt (struct socket *sock, int level, int optname)
718 return 0;
721 static int dummy_socket_getsockopt (struct socket *sock, int level, int optname)
723 return 0;
726 static int dummy_socket_shutdown (struct socket *sock, int how)
728 return 0;
731 static int dummy_socket_sock_rcv_skb (struct sock *sk, struct sk_buff *skb)
733 return 0;
735 #endif /* CONFIG_SECURITY_NETWORK */
737 static int dummy_register_security (const char *name, struct security_operations *ops)
739 return -EINVAL;
742 static int dummy_unregister_security (const char *name, struct security_operations *ops)
744 return -EINVAL;
747 static void dummy_d_instantiate (struct dentry *dentry, struct inode *inode)
749 return;
752 static int dummy_getprocattr(struct task_struct *p, char *name, void *value, size_t size)
754 return -EINVAL;
757 static int dummy_setprocattr(struct task_struct *p, char *name, void *value, size_t size)
759 return -EINVAL;
763 struct security_operations dummy_security_ops;
765 #define set_to_dummy_if_null(ops, function) \
766 do { \
767 if (!ops->function) { \
768 ops->function = dummy_##function; \
769 pr_debug("Had to override the " #function \
770 " security operation with the dummy one.\n");\
772 } while (0)
774 void security_fixup_ops (struct security_operations *ops)
776 set_to_dummy_if_null(ops, ptrace);
777 set_to_dummy_if_null(ops, capget);
778 set_to_dummy_if_null(ops, capset_check);
779 set_to_dummy_if_null(ops, capset_set);
780 set_to_dummy_if_null(ops, acct);
781 set_to_dummy_if_null(ops, capable);
782 set_to_dummy_if_null(ops, quotactl);
783 set_to_dummy_if_null(ops, quota_on);
784 set_to_dummy_if_null(ops, sysctl);
785 set_to_dummy_if_null(ops, syslog);
786 set_to_dummy_if_null(ops, bprm_alloc_security);
787 set_to_dummy_if_null(ops, bprm_free_security);
788 set_to_dummy_if_null(ops, bprm_compute_creds);
789 set_to_dummy_if_null(ops, bprm_set_security);
790 set_to_dummy_if_null(ops, bprm_check_security);
791 set_to_dummy_if_null(ops, sb_alloc_security);
792 set_to_dummy_if_null(ops, sb_free_security);
793 set_to_dummy_if_null(ops, sb_kern_mount);
794 set_to_dummy_if_null(ops, sb_statfs);
795 set_to_dummy_if_null(ops, sb_mount);
796 set_to_dummy_if_null(ops, sb_check_sb);
797 set_to_dummy_if_null(ops, sb_umount);
798 set_to_dummy_if_null(ops, sb_umount_close);
799 set_to_dummy_if_null(ops, sb_umount_busy);
800 set_to_dummy_if_null(ops, sb_post_remount);
801 set_to_dummy_if_null(ops, sb_post_mountroot);
802 set_to_dummy_if_null(ops, sb_post_addmount);
803 set_to_dummy_if_null(ops, sb_pivotroot);
804 set_to_dummy_if_null(ops, sb_post_pivotroot);
805 set_to_dummy_if_null(ops, inode_alloc_security);
806 set_to_dummy_if_null(ops, inode_free_security);
807 set_to_dummy_if_null(ops, inode_create);
808 set_to_dummy_if_null(ops, inode_post_create);
809 set_to_dummy_if_null(ops, inode_link);
810 set_to_dummy_if_null(ops, inode_post_link);
811 set_to_dummy_if_null(ops, inode_unlink);
812 set_to_dummy_if_null(ops, inode_symlink);
813 set_to_dummy_if_null(ops, inode_post_symlink);
814 set_to_dummy_if_null(ops, inode_mkdir);
815 set_to_dummy_if_null(ops, inode_post_mkdir);
816 set_to_dummy_if_null(ops, inode_rmdir);
817 set_to_dummy_if_null(ops, inode_mknod);
818 set_to_dummy_if_null(ops, inode_post_mknod);
819 set_to_dummy_if_null(ops, inode_rename);
820 set_to_dummy_if_null(ops, inode_post_rename);
821 set_to_dummy_if_null(ops, inode_readlink);
822 set_to_dummy_if_null(ops, inode_follow_link);
823 set_to_dummy_if_null(ops, inode_permission);
824 set_to_dummy_if_null(ops, inode_setattr);
825 set_to_dummy_if_null(ops, inode_getattr);
826 set_to_dummy_if_null(ops, inode_delete);
827 set_to_dummy_if_null(ops, inode_setxattr);
828 set_to_dummy_if_null(ops, inode_post_setxattr);
829 set_to_dummy_if_null(ops, inode_getxattr);
830 set_to_dummy_if_null(ops, inode_listxattr);
831 set_to_dummy_if_null(ops, inode_removexattr);
832 set_to_dummy_if_null(ops, inode_getsecurity);
833 set_to_dummy_if_null(ops, inode_setsecurity);
834 set_to_dummy_if_null(ops, inode_listsecurity);
835 set_to_dummy_if_null(ops, file_permission);
836 set_to_dummy_if_null(ops, file_alloc_security);
837 set_to_dummy_if_null(ops, file_free_security);
838 set_to_dummy_if_null(ops, file_ioctl);
839 set_to_dummy_if_null(ops, file_mmap);
840 set_to_dummy_if_null(ops, file_mprotect);
841 set_to_dummy_if_null(ops, file_lock);
842 set_to_dummy_if_null(ops, file_fcntl);
843 set_to_dummy_if_null(ops, file_set_fowner);
844 set_to_dummy_if_null(ops, file_send_sigiotask);
845 set_to_dummy_if_null(ops, file_receive);
846 set_to_dummy_if_null(ops, task_create);
847 set_to_dummy_if_null(ops, task_alloc_security);
848 set_to_dummy_if_null(ops, task_free_security);
849 set_to_dummy_if_null(ops, task_setuid);
850 set_to_dummy_if_null(ops, task_post_setuid);
851 set_to_dummy_if_null(ops, task_setgid);
852 set_to_dummy_if_null(ops, task_setpgid);
853 set_to_dummy_if_null(ops, task_getpgid);
854 set_to_dummy_if_null(ops, task_getsid);
855 set_to_dummy_if_null(ops, task_setgroups);
856 set_to_dummy_if_null(ops, task_setnice);
857 set_to_dummy_if_null(ops, task_setrlimit);
858 set_to_dummy_if_null(ops, task_setscheduler);
859 set_to_dummy_if_null(ops, task_getscheduler);
860 set_to_dummy_if_null(ops, task_wait);
861 set_to_dummy_if_null(ops, task_kill);
862 set_to_dummy_if_null(ops, task_prctl);
863 set_to_dummy_if_null(ops, task_reparent_to_init);
864 set_to_dummy_if_null(ops, task_to_inode);
865 set_to_dummy_if_null(ops, ipc_permission);
866 set_to_dummy_if_null(ops, msg_msg_alloc_security);
867 set_to_dummy_if_null(ops, msg_msg_free_security);
868 set_to_dummy_if_null(ops, msg_queue_alloc_security);
869 set_to_dummy_if_null(ops, msg_queue_free_security);
870 set_to_dummy_if_null(ops, msg_queue_associate);
871 set_to_dummy_if_null(ops, msg_queue_msgctl);
872 set_to_dummy_if_null(ops, msg_queue_msgsnd);
873 set_to_dummy_if_null(ops, msg_queue_msgrcv);
874 set_to_dummy_if_null(ops, shm_alloc_security);
875 set_to_dummy_if_null(ops, shm_free_security);
876 set_to_dummy_if_null(ops, shm_associate);
877 set_to_dummy_if_null(ops, shm_shmctl);
878 set_to_dummy_if_null(ops, shm_shmat);
879 set_to_dummy_if_null(ops, sem_alloc_security);
880 set_to_dummy_if_null(ops, sem_free_security);
881 set_to_dummy_if_null(ops, sem_associate);
882 set_to_dummy_if_null(ops, sem_semctl);
883 set_to_dummy_if_null(ops, sem_semop);
884 set_to_dummy_if_null(ops, netlink_send);
885 set_to_dummy_if_null(ops, netlink_recv);
886 set_to_dummy_if_null(ops, register_security);
887 set_to_dummy_if_null(ops, unregister_security);
888 set_to_dummy_if_null(ops, d_instantiate);
889 set_to_dummy_if_null(ops, getprocattr);
890 set_to_dummy_if_null(ops, setprocattr);
891 #ifdef CONFIG_SECURITY_NETWORK
892 set_to_dummy_if_null(ops, unix_stream_connect);
893 set_to_dummy_if_null(ops, unix_may_send);
894 set_to_dummy_if_null(ops, socket_create);
895 set_to_dummy_if_null(ops, socket_post_create);
896 set_to_dummy_if_null(ops, socket_bind);
897 set_to_dummy_if_null(ops, socket_connect);
898 set_to_dummy_if_null(ops, socket_listen);
899 set_to_dummy_if_null(ops, socket_accept);
900 set_to_dummy_if_null(ops, socket_post_accept);
901 set_to_dummy_if_null(ops, socket_sendmsg);
902 set_to_dummy_if_null(ops, socket_recvmsg);
903 set_to_dummy_if_null(ops, socket_getsockname);
904 set_to_dummy_if_null(ops, socket_getpeername);
905 set_to_dummy_if_null(ops, socket_setsockopt);
906 set_to_dummy_if_null(ops, socket_getsockopt);
907 set_to_dummy_if_null(ops, socket_shutdown);
908 set_to_dummy_if_null(ops, socket_sock_rcv_skb);
909 #endif /* CONFIG_SECURITY_NETWORK */