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.
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>
25 static int dummy_ptrace (struct task_struct
*parent
, struct task_struct
*child
)
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
;
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
)
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
)
63 static int dummy_acct (struct file
*file
)
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 */
74 /* capability denied */
78 static int dummy_sysctl (ctl_table
* table
, int op
)
83 static int dummy_quotactl (int cmds
, int type
, int id
, struct super_block
*sb
)
88 static int dummy_quota_on (struct file
*f
)
93 static int dummy_syslog (int type
)
95 if ((type
!= 3) && current
->euid
)
100 static int dummy_bprm_alloc_security (struct linux_binprm
*bprm
)
105 static void dummy_bprm_free_security (struct linux_binprm
*bprm
)
110 static void dummy_bprm_compute_creds (struct linux_binprm
*bprm
)
115 static int dummy_bprm_set_security (struct linux_binprm
*bprm
)
120 static int dummy_bprm_check_security (struct linux_binprm
*bprm
)
125 static int dummy_sb_alloc_security (struct super_block
*sb
)
130 static void dummy_sb_free_security (struct super_block
*sb
)
135 static int dummy_sb_kern_mount (struct super_block
*sb
)
140 static int dummy_sb_statfs (struct super_block
*sb
)
145 static int dummy_sb_mount (char *dev_name
, struct nameidata
*nd
, char *type
,
146 unsigned long flags
, void *data
)
151 static int dummy_sb_check_sb (struct vfsmount
*mnt
, struct nameidata
*nd
)
156 static int dummy_sb_umount (struct vfsmount
*mnt
, int flags
)
161 static void dummy_sb_umount_close (struct vfsmount
*mnt
)
166 static void dummy_sb_umount_busy (struct vfsmount
*mnt
)
171 static void dummy_sb_post_remount (struct vfsmount
*mnt
, unsigned long flags
,
178 static void dummy_sb_post_mountroot (void)
183 static void dummy_sb_post_addmount (struct vfsmount
*mnt
, struct nameidata
*nd
)
188 static int dummy_sb_pivotroot (struct nameidata
*old_nd
, struct nameidata
*new_nd
)
193 static void dummy_sb_post_pivotroot (struct nameidata
*old_nd
, struct nameidata
*new_nd
)
198 static int dummy_inode_alloc_security (struct inode
*inode
)
203 static void dummy_inode_free_security (struct inode
*inode
)
208 static int dummy_inode_create (struct inode
*inode
, struct dentry
*dentry
,
214 static void dummy_inode_post_create (struct inode
*inode
, struct dentry
*dentry
,
220 static int dummy_inode_link (struct dentry
*old_dentry
, struct inode
*inode
,
221 struct dentry
*new_dentry
)
226 static void dummy_inode_post_link (struct dentry
*old_dentry
,
228 struct dentry
*new_dentry
)
233 static int dummy_inode_unlink (struct inode
*inode
, struct dentry
*dentry
)
238 static int dummy_inode_symlink (struct inode
*inode
, struct dentry
*dentry
,
244 static void dummy_inode_post_symlink (struct inode
*inode
,
245 struct dentry
*dentry
, const char *name
)
250 static int dummy_inode_mkdir (struct inode
*inode
, struct dentry
*dentry
,
256 static void dummy_inode_post_mkdir (struct inode
*inode
, struct dentry
*dentry
,
262 static int dummy_inode_rmdir (struct inode
*inode
, struct dentry
*dentry
)
267 static int dummy_inode_mknod (struct inode
*inode
, struct dentry
*dentry
,
273 static void dummy_inode_post_mknod (struct inode
*inode
, struct dentry
*dentry
,
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
)
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
)
295 static int dummy_inode_readlink (struct dentry
*dentry
)
300 static int dummy_inode_follow_link (struct dentry
*dentry
,
301 struct nameidata
*nameidata
)
306 static int dummy_inode_permission (struct inode
*inode
, int mask
)
311 static int dummy_inode_setattr (struct dentry
*dentry
, struct iattr
*iattr
)
316 static int dummy_inode_getattr (struct vfsmount
*mnt
, struct dentry
*dentry
)
321 static void dummy_inode_delete (struct inode
*ino
)
326 static int dummy_inode_setxattr (struct dentry
*dentry
, char *name
, void *value
,
327 size_t size
, int flags
)
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
)
342 static int dummy_inode_listxattr (struct dentry
*dentry
)
347 static int dummy_inode_removexattr (struct dentry
*dentry
, char *name
)
352 static int dummy_inode_getsecurity(struct dentry
*dentry
, const char *name
, void *buffer
, size_t size
)
357 static int dummy_inode_setsecurity(struct dentry
*dentry
, const char *name
, const void *value
, size_t size
, int flags
)
362 static int dummy_inode_listsecurity(struct dentry
*dentry
, char *buffer
)
367 static int dummy_file_permission (struct file
*file
, int mask
)
372 static int dummy_file_alloc_security (struct file
*file
)
377 static void dummy_file_free_security (struct file
*file
)
382 static int dummy_file_ioctl (struct file
*file
, unsigned int command
,
388 static int dummy_file_mmap (struct file
*file
, unsigned long prot
,
394 static int dummy_file_mprotect (struct vm_area_struct
*vma
, unsigned long prot
)
399 static int dummy_file_lock (struct file
*file
, unsigned int cmd
)
404 static int dummy_file_fcntl (struct file
*file
, unsigned int cmd
,
410 static int dummy_file_set_fowner (struct file
*file
)
415 static int dummy_file_send_sigiotask (struct task_struct
*tsk
,
416 struct fown_struct
*fown
, int fd
,
422 static int dummy_file_receive (struct file
*file
)
427 static int dummy_task_create (unsigned long clone_flags
)
432 static int dummy_task_alloc_security (struct task_struct
*p
)
437 static void dummy_task_free_security (struct task_struct
*p
)
442 static int dummy_task_setuid (uid_t id0
, uid_t id1
, uid_t id2
, int flags
)
447 static int dummy_task_post_setuid (uid_t id0
, uid_t id1
, uid_t id2
, int flags
)
452 static int dummy_task_setgid (gid_t id0
, gid_t id1
, gid_t id2
, int flags
)
457 static int dummy_task_setpgid (struct task_struct
*p
, pid_t pgid
)
462 static int dummy_task_getpgid (struct task_struct
*p
)
467 static int dummy_task_getsid (struct task_struct
*p
)
472 static int dummy_task_setgroups (int gidsetsize
, gid_t
* grouplist
)
477 static int dummy_task_setnice (struct task_struct
*p
, int nice
)
482 static int dummy_task_setrlimit (unsigned int resource
, struct rlimit
*new_rlim
)
487 static int dummy_task_setscheduler (struct task_struct
*p
, int policy
,
488 struct sched_param
*lp
)
493 static int dummy_task_getscheduler (struct task_struct
*p
)
498 static int dummy_task_wait (struct task_struct
*p
)
503 static int dummy_task_kill (struct task_struct
*p
, struct siginfo
*info
,
509 static int dummy_task_prctl (int option
, unsigned long arg2
, unsigned long arg3
,
510 unsigned long arg4
, unsigned long arg5
)
515 static void dummy_task_reparent_to_init (struct task_struct
*p
)
517 p
->euid
= p
->fsuid
= 0;
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
)
529 static int dummy_msg_msg_alloc_security (struct msg_msg
*msg
)
534 static void dummy_msg_msg_free_security (struct msg_msg
*msg
)
539 static int dummy_msg_queue_alloc_security (struct msg_queue
*msq
)
544 static void dummy_msg_queue_free_security (struct msg_queue
*msq
)
549 static int dummy_msg_queue_associate (struct msg_queue
*msq
,
555 static int dummy_msg_queue_msgctl (struct msg_queue
*msq
, int cmd
)
560 static int dummy_msg_queue_msgsnd (struct msg_queue
*msq
, struct msg_msg
*msg
,
566 static int dummy_msg_queue_msgrcv (struct msg_queue
*msq
, struct msg_msg
*msg
,
567 struct task_struct
*target
, long type
,
573 static int dummy_shm_alloc_security (struct shmid_kernel
*shp
)
578 static void dummy_shm_free_security (struct shmid_kernel
*shp
)
583 static int dummy_shm_associate (struct shmid_kernel
*shp
, int shmflg
)
588 static int dummy_shm_shmctl (struct shmid_kernel
*shp
, int cmd
)
593 static int dummy_shm_shmat (struct shmid_kernel
*shp
, char *shmaddr
,
599 static int dummy_sem_alloc_security (struct sem_array
*sma
)
604 static void dummy_sem_free_security (struct sem_array
*sma
)
609 static int dummy_sem_associate (struct sem_array
*sma
, int semflg
)
614 static int dummy_sem_semctl (struct sem_array
*sma
, int cmd
)
619 static int dummy_sem_semop (struct sem_array
*sma
,
620 struct sembuf
*sops
, unsigned nsops
, int alter
)
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
);
630 NETLINK_CB (skb
).eff_cap
= 0;
634 static int dummy_netlink_recv (struct sk_buff
*skb
)
636 if (!cap_raised (NETLINK_CB (skb
).eff_cap
, CAP_NET_ADMIN
))
641 #ifdef CONFIG_SECURITY_NETWORK
642 static int dummy_unix_stream_connect (struct socket
*sock
,
643 struct socket
*other
,
649 static int dummy_unix_may_send (struct socket
*sock
,
650 struct socket
*other
)
655 static int dummy_socket_create (int family
, int type
, int protocol
)
660 static void dummy_socket_post_create (struct socket
*sock
, int family
, int type
,
666 static int dummy_socket_bind (struct socket
*sock
, struct sockaddr
*address
,
672 static int dummy_socket_connect (struct socket
*sock
, struct sockaddr
*address
,
678 static int dummy_socket_listen (struct socket
*sock
, int backlog
)
683 static int dummy_socket_accept (struct socket
*sock
, struct socket
*newsock
)
688 static void dummy_socket_post_accept (struct socket
*sock
,
689 struct socket
*newsock
)
694 static int dummy_socket_sendmsg (struct socket
*sock
, struct msghdr
*msg
,
700 static int dummy_socket_recvmsg (struct socket
*sock
, struct msghdr
*msg
,
706 static int dummy_socket_getsockname (struct socket
*sock
)
711 static int dummy_socket_getpeername (struct socket
*sock
)
716 static int dummy_socket_setsockopt (struct socket
*sock
, int level
, int optname
)
721 static int dummy_socket_getsockopt (struct socket
*sock
, int level
, int optname
)
726 static int dummy_socket_shutdown (struct socket
*sock
, int how
)
731 static int dummy_socket_sock_rcv_skb (struct sock
*sk
, struct sk_buff
*skb
)
735 #endif /* CONFIG_SECURITY_NETWORK */
737 static int dummy_register_security (const char *name
, struct security_operations
*ops
)
742 static int dummy_unregister_security (const char *name
, struct security_operations
*ops
)
747 static void dummy_d_instantiate (struct dentry
*dentry
, struct inode
*inode
)
752 static int dummy_getprocattr(struct task_struct
*p
, char *name
, void *value
, size_t size
)
757 static int dummy_setprocattr(struct task_struct
*p
, char *name
, void *value
, size_t size
)
763 struct security_operations dummy_security_ops
;
765 #define set_to_dummy_if_null(ops, function) \
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");\
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 */