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/mman.h>
21 #include <linux/pagemap.h>
22 #include <linux/swap.h>
23 #include <linux/security.h>
24 #include <linux/skbuff.h>
25 #include <linux/netlink.h>
27 #include <linux/xattr.h>
28 #include <linux/hugetlb.h>
29 #include <linux/ptrace.h>
30 #include <linux/file.h>
32 static int dummy_ptrace (struct task_struct *parent, struct task_struct *child)
37 static int dummy_capget (struct task_struct *target, kernel_cap_t * effective,
38 kernel_cap_t * inheritable, kernel_cap_t * permitted)
40 *effective = *inheritable = *permitted = 0;
41 if (!issecure(SECURE_NOROOT)) {
42 if (target->euid == 0) {
43 *permitted |= (~0 & ~CAP_FS_MASK);
44 *effective |= (~0 & ~CAP_TO_MASK(CAP_SETPCAP) & ~CAP_FS_MASK);
46 if (target->fsuid == 0) {
47 *permitted |= CAP_FS_MASK;
48 *effective |= CAP_FS_MASK;
54 static int dummy_capset_check (struct task_struct *target,
55 kernel_cap_t * effective,
56 kernel_cap_t * inheritable,
57 kernel_cap_t * permitted)
62 static void dummy_capset_set (struct task_struct *target,
63 kernel_cap_t * effective,
64 kernel_cap_t * inheritable,
65 kernel_cap_t * permitted)
70 static int dummy_acct (struct file *file)
75 static int dummy_capable (struct task_struct *tsk, int cap)
77 if (cap_raised (tsk->cap_effective, cap))
82 static int dummy_sysctl (ctl_table * table, int op)
87 static int dummy_quotactl (int cmds, int type, int id, struct super_block *sb)
92 static int dummy_quota_on (struct dentry *dentry)
97 static int dummy_syslog (int type)
99 if ((type != 3 && type != 10) && current->euid)
104 static int dummy_settime(struct timespec *ts, struct timezone *tz)
106 if (!capable(CAP_SYS_TIME))
111 static int dummy_vm_enough_memory(long pages)
113 int cap_sys_admin = 0;
115 if (dummy_capable(current, CAP_SYS_ADMIN) == 0)
117 return __vm_enough_memory(pages, cap_sys_admin);
120 static int dummy_bprm_alloc_security (struct linux_binprm *bprm)
125 static void dummy_bprm_free_security (struct linux_binprm *bprm)
130 static void dummy_bprm_apply_creds (struct linux_binprm *bprm, int unsafe)
132 if (bprm->e_uid != current->uid || bprm->e_gid != current->gid) {
133 current->mm->dumpable = suid_dumpable;
135 if ((unsafe & ~LSM_UNSAFE_PTRACE_CAP) && !capable(CAP_SETUID)) {
136 bprm->e_uid = current->uid;
137 bprm->e_gid = current->gid;
141 current->suid = current->euid = current->fsuid = bprm->e_uid;
142 current->sgid = current->egid = current->fsgid = bprm->e_gid;
144 dummy_capget(current, ¤t->cap_effective, ¤t->cap_inheritable, ¤t->cap_permitted);
147 static void dummy_bprm_post_apply_creds (struct linux_binprm *bprm)
152 static int dummy_bprm_set_security (struct linux_binprm *bprm)
157 static int dummy_bprm_check_security (struct linux_binprm *bprm)
162 static int dummy_bprm_secureexec (struct linux_binprm *bprm)
164 /* The new userland will simply use the value provided
165 in the AT_SECURE field to decide whether secure mode
166 is required. Hence, this logic is required to preserve
167 the legacy decision algorithm used by the old userland. */
168 return (current->euid != current->uid ||
169 current->egid != current->gid);
172 static int dummy_sb_alloc_security (struct super_block *sb)
177 static void dummy_sb_free_security (struct super_block *sb)
182 static int dummy_sb_copy_data (struct file_system_type *type,
183 void *orig, void *copy)
188 static int dummy_sb_kern_mount (struct super_block *sb, void *data)
193 static int dummy_sb_statfs (struct super_block *sb)
198 static int dummy_sb_mount (char *dev_name, struct nameidata *nd, char *type,
199 unsigned long flags, void *data)
204 static int dummy_sb_check_sb (struct vfsmount *mnt, struct nameidata *nd)
209 static int dummy_sb_umount (struct vfsmount *mnt, int flags)
214 static void dummy_sb_umount_close (struct vfsmount *mnt)
219 static void dummy_sb_umount_busy (struct vfsmount *mnt)
224 static void dummy_sb_post_remount (struct vfsmount *mnt, unsigned long flags,
231 static void dummy_sb_post_mountroot (void)
236 static void dummy_sb_post_addmount (struct vfsmount *mnt, struct nameidata *nd)
241 static int dummy_sb_pivotroot (struct nameidata *old_nd, struct nameidata *new_nd)
246 static void dummy_sb_post_pivotroot (struct nameidata *old_nd, struct nameidata *new_nd)
251 static int dummy_inode_alloc_security (struct inode *inode)
256 static void dummy_inode_free_security (struct inode *inode)
261 static int dummy_inode_init_security (struct inode *inode, struct inode *dir,
262 char **name, void **value, size_t *len)
267 static int dummy_inode_create (struct inode *inode, struct dentry *dentry,
273 static int dummy_inode_link (struct dentry *old_dentry, struct inode *inode,
274 struct dentry *new_dentry)
279 static int dummy_inode_unlink (struct inode *inode, struct dentry *dentry)
284 static int dummy_inode_symlink (struct inode *inode, struct dentry *dentry,
290 static int dummy_inode_mkdir (struct inode *inode, struct dentry *dentry,
296 static int dummy_inode_rmdir (struct inode *inode, struct dentry *dentry)
301 static int dummy_inode_mknod (struct inode *inode, struct dentry *dentry,
307 static int dummy_inode_rename (struct inode *old_inode,
308 struct dentry *old_dentry,
309 struct inode *new_inode,
310 struct dentry *new_dentry)
315 static int dummy_inode_readlink (struct dentry *dentry)
320 static int dummy_inode_follow_link (struct dentry *dentry,
321 struct nameidata *nameidata)
326 static int dummy_inode_permission (struct inode *inode, int mask, struct nameidata *nd)
331 static int dummy_inode_setattr (struct dentry *dentry, struct iattr *iattr)
336 static int dummy_inode_getattr (struct vfsmount *mnt, struct dentry *dentry)
341 static void dummy_inode_delete (struct inode *ino)
346 static int dummy_inode_setxattr (struct dentry *dentry, char *name, void *value,
347 size_t size, int flags)
349 if (!strncmp(name, XATTR_SECURITY_PREFIX,
350 sizeof(XATTR_SECURITY_PREFIX) - 1) &&
351 !capable(CAP_SYS_ADMIN))
356 static void dummy_inode_post_setxattr (struct dentry *dentry, char *name, void *value,
357 size_t size, int flags)
361 static int dummy_inode_getxattr (struct dentry *dentry, char *name)
366 static int dummy_inode_listxattr (struct dentry *dentry)
371 static int dummy_inode_removexattr (struct dentry *dentry, char *name)
373 if (!strncmp(name, XATTR_SECURITY_PREFIX,
374 sizeof(XATTR_SECURITY_PREFIX) - 1) &&
375 !capable(CAP_SYS_ADMIN))
380 static int dummy_inode_getsecurity(struct inode *inode, const char *name, void *buffer, size_t size, int err)
385 static int dummy_inode_setsecurity(struct inode *inode, const char *name, const void *value, size_t size, int flags)
390 static int dummy_inode_listsecurity(struct inode *inode, char *buffer, size_t buffer_size)
395 static int dummy_file_permission (struct file *file, int mask)
400 static int dummy_file_alloc_security (struct file *file)
405 static void dummy_file_free_security (struct file *file)
410 static int dummy_file_ioctl (struct file *file, unsigned int command,
416 static int dummy_file_mmap (struct file *file, unsigned long reqprot,
423 static int dummy_file_mprotect (struct vm_area_struct *vma,
424 unsigned long reqprot,
430 static int dummy_file_lock (struct file *file, unsigned int cmd)
435 static int dummy_file_fcntl (struct file *file, unsigned int cmd,
441 static int dummy_file_set_fowner (struct file *file)
446 static int dummy_file_send_sigiotask (struct task_struct *tsk,
447 struct fown_struct *fown, int sig)
452 static int dummy_file_receive (struct file *file)
457 static int dummy_task_create (unsigned long clone_flags)
462 static int dummy_task_alloc_security (struct task_struct *p)
467 static void dummy_task_free_security (struct task_struct *p)
472 static int dummy_task_setuid (uid_t id0, uid_t id1, uid_t id2, int flags)
477 static int dummy_task_post_setuid (uid_t id0, uid_t id1, uid_t id2, int flags)
479 dummy_capget(current, ¤t->cap_effective, ¤t->cap_inheritable, ¤t->cap_permitted);
483 static int dummy_task_setgid (gid_t id0, gid_t id1, gid_t id2, int flags)
488 static int dummy_task_setpgid (struct task_struct *p, pid_t pgid)
493 static int dummy_task_getpgid (struct task_struct *p)
498 static int dummy_task_getsid (struct task_struct *p)
503 static int dummy_task_setgroups (struct group_info *group_info)
508 static int dummy_task_setnice (struct task_struct *p, int nice)
513 static int dummy_task_setrlimit (unsigned int resource, struct rlimit *new_rlim)
518 static int dummy_task_setscheduler (struct task_struct *p, int policy,
519 struct sched_param *lp)
524 static int dummy_task_getscheduler (struct task_struct *p)
529 static int dummy_task_wait (struct task_struct *p)
534 static int dummy_task_kill (struct task_struct *p, struct siginfo *info,
540 static int dummy_task_prctl (int option, unsigned long arg2, unsigned long arg3,
541 unsigned long arg4, unsigned long arg5)
546 static void dummy_task_reparent_to_init (struct task_struct *p)
548 p->euid = p->fsuid = 0;
552 static void dummy_task_to_inode(struct task_struct *p, struct inode *inode)
555 static int dummy_ipc_permission (struct kern_ipc_perm *ipcp, short flag)
560 static int dummy_msg_msg_alloc_security (struct msg_msg *msg)
565 static void dummy_msg_msg_free_security (struct msg_msg *msg)
570 static int dummy_msg_queue_alloc_security (struct msg_queue *msq)
575 static void dummy_msg_queue_free_security (struct msg_queue *msq)
580 static int dummy_msg_queue_associate (struct msg_queue *msq,
586 static int dummy_msg_queue_msgctl (struct msg_queue *msq, int cmd)
591 static int dummy_msg_queue_msgsnd (struct msg_queue *msq, struct msg_msg *msg,
597 static int dummy_msg_queue_msgrcv (struct msg_queue *msq, struct msg_msg *msg,
598 struct task_struct *target, long type,
604 static int dummy_shm_alloc_security (struct shmid_kernel *shp)
609 static void dummy_shm_free_security (struct shmid_kernel *shp)
614 static int dummy_shm_associate (struct shmid_kernel *shp, int shmflg)
619 static int dummy_shm_shmctl (struct shmid_kernel *shp, int cmd)
624 static int dummy_shm_shmat (struct shmid_kernel *shp, char __user *shmaddr,
630 static int dummy_sem_alloc_security (struct sem_array *sma)
635 static void dummy_sem_free_security (struct sem_array *sma)
640 static int dummy_sem_associate (struct sem_array *sma, int semflg)
645 static int dummy_sem_semctl (struct sem_array *sma, int cmd)
650 static int dummy_sem_semop (struct sem_array *sma,
651 struct sembuf *sops, unsigned nsops, int alter)
656 static int dummy_netlink_send (struct sock *sk, struct sk_buff *skb)
658 NETLINK_CB(skb).eff_cap = current->cap_effective;
662 static int dummy_netlink_recv (struct sk_buff *skb)
664 if (!cap_raised (NETLINK_CB (skb).eff_cap, CAP_NET_ADMIN))
669 #ifdef CONFIG_SECURITY_NETWORK
670 static int dummy_unix_stream_connect (struct socket *sock,
671 struct socket *other,
677 static int dummy_unix_may_send (struct socket *sock,
678 struct socket *other)
683 static int dummy_socket_create (int family, int type,
684 int protocol, int kern)
689 static void dummy_socket_post_create (struct socket *sock, int family, int type,
690 int protocol, int kern)
695 static int dummy_socket_bind (struct socket *sock, struct sockaddr *address,
701 static int dummy_socket_connect (struct socket *sock, struct sockaddr *address,
707 static int dummy_socket_listen (struct socket *sock, int backlog)
712 static int dummy_socket_accept (struct socket *sock, struct socket *newsock)
717 static void dummy_socket_post_accept (struct socket *sock,
718 struct socket *newsock)
723 static int dummy_socket_sendmsg (struct socket *sock, struct msghdr *msg,
729 static int dummy_socket_recvmsg (struct socket *sock, struct msghdr *msg,
735 static int dummy_socket_getsockname (struct socket *sock)
740 static int dummy_socket_getpeername (struct socket *sock)
745 static int dummy_socket_setsockopt (struct socket *sock, int level, int optname)
750 static int dummy_socket_getsockopt (struct socket *sock, int level, int optname)
755 static int dummy_socket_shutdown (struct socket *sock, int how)
760 static int dummy_socket_sock_rcv_skb (struct sock *sk, struct sk_buff *skb)
765 static int dummy_socket_getpeersec(struct socket *sock, char __user *optval,
766 int __user *optlen, unsigned len)
771 static inline int dummy_sk_alloc_security (struct sock *sk, int family, gfp_t priority)
776 static inline void dummy_sk_free_security (struct sock *sk)
779 #endif /* CONFIG_SECURITY_NETWORK */
781 static int dummy_register_security (const char *name, struct security_operations *ops)
786 static int dummy_unregister_security (const char *name, struct security_operations *ops)
791 static void dummy_d_instantiate (struct dentry *dentry, struct inode *inode)
796 static int dummy_getprocattr(struct task_struct *p, char *name, void *value, size_t size)
801 static int dummy_setprocattr(struct task_struct *p, char *name, void *value, size_t size)
807 static inline int dummy_key_alloc(struct key *key)
812 static inline void dummy_key_free(struct key *key)
816 static inline int dummy_key_permission(key_ref_t key_ref,
817 struct task_struct *context,
822 #endif /* CONFIG_KEYS */
824 struct security_operations dummy_security_ops;
826 #define set_to_dummy_if_null(ops, function) \
828 if (!ops->function) { \
829 ops->function = dummy_##function; \
830 pr_debug("Had to override the " #function \
831 " security operation with the dummy one.\n");\
835 void security_fixup_ops (struct security_operations *ops)
837 set_to_dummy_if_null(ops, ptrace);
838 set_to_dummy_if_null(ops, capget);
839 set_to_dummy_if_null(ops, capset_check);
840 set_to_dummy_if_null(ops, capset_set);
841 set_to_dummy_if_null(ops, acct);
842 set_to_dummy_if_null(ops, capable);
843 set_to_dummy_if_null(ops, quotactl);
844 set_to_dummy_if_null(ops, quota_on);
845 set_to_dummy_if_null(ops, sysctl);
846 set_to_dummy_if_null(ops, syslog);
847 set_to_dummy_if_null(ops, settime);
848 set_to_dummy_if_null(ops, vm_enough_memory);
849 set_to_dummy_if_null(ops, bprm_alloc_security);
850 set_to_dummy_if_null(ops, bprm_free_security);
851 set_to_dummy_if_null(ops, bprm_apply_creds);
852 set_to_dummy_if_null(ops, bprm_post_apply_creds);
853 set_to_dummy_if_null(ops, bprm_set_security);
854 set_to_dummy_if_null(ops, bprm_check_security);
855 set_to_dummy_if_null(ops, bprm_secureexec);
856 set_to_dummy_if_null(ops, sb_alloc_security);
857 set_to_dummy_if_null(ops, sb_free_security);
858 set_to_dummy_if_null(ops, sb_copy_data);
859 set_to_dummy_if_null(ops, sb_kern_mount);
860 set_to_dummy_if_null(ops, sb_statfs);
861 set_to_dummy_if_null(ops, sb_mount);
862 set_to_dummy_if_null(ops, sb_check_sb);
863 set_to_dummy_if_null(ops, sb_umount);
864 set_to_dummy_if_null(ops, sb_umount_close);
865 set_to_dummy_if_null(ops, sb_umount_busy);
866 set_to_dummy_if_null(ops, sb_post_remount);
867 set_to_dummy_if_null(ops, sb_post_mountroot);
868 set_to_dummy_if_null(ops, sb_post_addmount);
869 set_to_dummy_if_null(ops, sb_pivotroot);
870 set_to_dummy_if_null(ops, sb_post_pivotroot);
871 set_to_dummy_if_null(ops, inode_alloc_security);
872 set_to_dummy_if_null(ops, inode_free_security);
873 set_to_dummy_if_null(ops, inode_init_security);
874 set_to_dummy_if_null(ops, inode_create);
875 set_to_dummy_if_null(ops, inode_link);
876 set_to_dummy_if_null(ops, inode_unlink);
877 set_to_dummy_if_null(ops, inode_symlink);
878 set_to_dummy_if_null(ops, inode_mkdir);
879 set_to_dummy_if_null(ops, inode_rmdir);
880 set_to_dummy_if_null(ops, inode_mknod);
881 set_to_dummy_if_null(ops, inode_rename);
882 set_to_dummy_if_null(ops, inode_readlink);
883 set_to_dummy_if_null(ops, inode_follow_link);
884 set_to_dummy_if_null(ops, inode_permission);
885 set_to_dummy_if_null(ops, inode_setattr);
886 set_to_dummy_if_null(ops, inode_getattr);
887 set_to_dummy_if_null(ops, inode_delete);
888 set_to_dummy_if_null(ops, inode_setxattr);
889 set_to_dummy_if_null(ops, inode_post_setxattr);
890 set_to_dummy_if_null(ops, inode_getxattr);
891 set_to_dummy_if_null(ops, inode_listxattr);
892 set_to_dummy_if_null(ops, inode_removexattr);
893 set_to_dummy_if_null(ops, inode_getsecurity);
894 set_to_dummy_if_null(ops, inode_setsecurity);
895 set_to_dummy_if_null(ops, inode_listsecurity);
896 set_to_dummy_if_null(ops, file_permission);
897 set_to_dummy_if_null(ops, file_alloc_security);
898 set_to_dummy_if_null(ops, file_free_security);
899 set_to_dummy_if_null(ops, file_ioctl);
900 set_to_dummy_if_null(ops, file_mmap);
901 set_to_dummy_if_null(ops, file_mprotect);
902 set_to_dummy_if_null(ops, file_lock);
903 set_to_dummy_if_null(ops, file_fcntl);
904 set_to_dummy_if_null(ops, file_set_fowner);
905 set_to_dummy_if_null(ops, file_send_sigiotask);
906 set_to_dummy_if_null(ops, file_receive);
907 set_to_dummy_if_null(ops, task_create);
908 set_to_dummy_if_null(ops, task_alloc_security);
909 set_to_dummy_if_null(ops, task_free_security);
910 set_to_dummy_if_null(ops, task_setuid);
911 set_to_dummy_if_null(ops, task_post_setuid);
912 set_to_dummy_if_null(ops, task_setgid);
913 set_to_dummy_if_null(ops, task_setpgid);
914 set_to_dummy_if_null(ops, task_getpgid);
915 set_to_dummy_if_null(ops, task_getsid);
916 set_to_dummy_if_null(ops, task_setgroups);
917 set_to_dummy_if_null(ops, task_setnice);
918 set_to_dummy_if_null(ops, task_setrlimit);
919 set_to_dummy_if_null(ops, task_setscheduler);
920 set_to_dummy_if_null(ops, task_getscheduler);
921 set_to_dummy_if_null(ops, task_wait);
922 set_to_dummy_if_null(ops, task_kill);
923 set_to_dummy_if_null(ops, task_prctl);
924 set_to_dummy_if_null(ops, task_reparent_to_init);
925 set_to_dummy_if_null(ops, task_to_inode);
926 set_to_dummy_if_null(ops, ipc_permission);
927 set_to_dummy_if_null(ops, msg_msg_alloc_security);
928 set_to_dummy_if_null(ops, msg_msg_free_security);
929 set_to_dummy_if_null(ops, msg_queue_alloc_security);
930 set_to_dummy_if_null(ops, msg_queue_free_security);
931 set_to_dummy_if_null(ops, msg_queue_associate);
932 set_to_dummy_if_null(ops, msg_queue_msgctl);
933 set_to_dummy_if_null(ops, msg_queue_msgsnd);
934 set_to_dummy_if_null(ops, msg_queue_msgrcv);
935 set_to_dummy_if_null(ops, shm_alloc_security);
936 set_to_dummy_if_null(ops, shm_free_security);
937 set_to_dummy_if_null(ops, shm_associate);
938 set_to_dummy_if_null(ops, shm_shmctl);
939 set_to_dummy_if_null(ops, shm_shmat);
940 set_to_dummy_if_null(ops, sem_alloc_security);
941 set_to_dummy_if_null(ops, sem_free_security);
942 set_to_dummy_if_null(ops, sem_associate);
943 set_to_dummy_if_null(ops, sem_semctl);
944 set_to_dummy_if_null(ops, sem_semop);
945 set_to_dummy_if_null(ops, netlink_send);
946 set_to_dummy_if_null(ops, netlink_recv);
947 set_to_dummy_if_null(ops, register_security);
948 set_to_dummy_if_null(ops, unregister_security);
949 set_to_dummy_if_null(ops, d_instantiate);
950 set_to_dummy_if_null(ops, getprocattr);
951 set_to_dummy_if_null(ops, setprocattr);
952 #ifdef CONFIG_SECURITY_NETWORK
953 set_to_dummy_if_null(ops, unix_stream_connect);
954 set_to_dummy_if_null(ops, unix_may_send);
955 set_to_dummy_if_null(ops, socket_create);
956 set_to_dummy_if_null(ops, socket_post_create);
957 set_to_dummy_if_null(ops, socket_bind);
958 set_to_dummy_if_null(ops, socket_connect);
959 set_to_dummy_if_null(ops, socket_listen);
960 set_to_dummy_if_null(ops, socket_accept);
961 set_to_dummy_if_null(ops, socket_post_accept);
962 set_to_dummy_if_null(ops, socket_sendmsg);
963 set_to_dummy_if_null(ops, socket_recvmsg);
964 set_to_dummy_if_null(ops, socket_getsockname);
965 set_to_dummy_if_null(ops, socket_getpeername);
966 set_to_dummy_if_null(ops, socket_setsockopt);
967 set_to_dummy_if_null(ops, socket_getsockopt);
968 set_to_dummy_if_null(ops, socket_shutdown);
969 set_to_dummy_if_null(ops, socket_sock_rcv_skb);
970 set_to_dummy_if_null(ops, socket_getpeersec);
971 set_to_dummy_if_null(ops, sk_alloc_security);
972 set_to_dummy_if_null(ops, sk_free_security);
973 #endif /* CONFIG_SECURITY_NETWORK */
975 set_to_dummy_if_null(ops, key_alloc);
976 set_to_dummy_if_null(ops, key_free);
977 set_to_dummy_if_null(ops, key_permission);
978 #endif /* CONFIG_KEYS */