selinux: fix selinux_inode_setxattr oops
[linux-3.10.git] / security / capability.c
index c545bd1..61095df 100644 (file)
 
 #include <linux/security.h>
 
-static int cap_acct(struct file *file)
-{
-       return 0;
-}
-
-static int cap_sysctl(ctl_table *table, int op)
+static int cap_syslog(int type)
 {
        return 0;
 }
@@ -32,7 +27,7 @@ static int cap_quota_on(struct dentry *dentry)
        return 0;
 }
 
-static int cap_bprm_check_security (struct linux_binprm *bprm)
+static int cap_bprm_check_security(struct linux_binprm *bprm)
 {
        return 0;
 }
@@ -59,6 +54,11 @@ static int cap_sb_copy_data(char *orig, char *copy)
        return 0;
 }
 
+static int cap_sb_remount(struct super_block *sb, void *data)
+{
+       return 0;
+}
+
 static int cap_sb_kern_mount(struct super_block *sb, int flags, void *data)
 {
        return 0;
@@ -80,42 +80,16 @@ static int cap_sb_mount(char *dev_name, struct path *path, char *type,
        return 0;
 }
 
-static int cap_sb_check_sb(struct vfsmount *mnt, struct path *path)
-{
-       return 0;
-}
-
 static int cap_sb_umount(struct vfsmount *mnt, int flags)
 {
        return 0;
 }
 
-static void cap_sb_umount_close(struct vfsmount *mnt)
-{
-}
-
-static void cap_sb_umount_busy(struct vfsmount *mnt)
-{
-}
-
-static void cap_sb_post_remount(struct vfsmount *mnt, unsigned long flags,
-                               void *data)
-{
-}
-
-static void cap_sb_post_addmount(struct vfsmount *mnt, struct path *path)
-{
-}
-
 static int cap_sb_pivotroot(struct path *old_path, struct path *new_path)
 {
        return 0;
 }
 
-static void cap_sb_post_pivotroot(struct path *old_path, struct path *new_path)
-{
-}
-
 static int cap_sb_set_mnt_opts(struct super_block *sb,
                               struct security_mnt_opts *opts)
 {
@@ -144,13 +118,14 @@ static void cap_inode_free_security(struct inode *inode)
 }
 
 static int cap_inode_init_security(struct inode *inode, struct inode *dir,
-                                  char **name, void **value, size_t *len)
+                                  const struct qstr *qstr, char **name,
+                                  void **value, size_t *len)
 {
        return -EOPNOTSUPP;
 }
 
 static int cap_inode_create(struct inode *inode, struct dentry *dentry,
-                           int mask)
+                           umode_t mask)
 {
        return 0;
 }
@@ -173,7 +148,7 @@ static int cap_inode_symlink(struct inode *inode, struct dentry *dentry,
 }
 
 static int cap_inode_mkdir(struct inode *inode, struct dentry *dentry,
-                          int mask)
+                          umode_t mask)
 {
        return 0;
 }
@@ -184,7 +159,7 @@ static int cap_inode_rmdir(struct inode *inode, struct dentry *dentry)
 }
 
 static int cap_inode_mknod(struct inode *inode, struct dentry *dentry,
-                          int mode, dev_t dev)
+                          umode_t mode, dev_t dev)
 {
        return 0;
 }
@@ -221,10 +196,6 @@ static int cap_inode_getattr(struct vfsmount *mnt, struct dentry *dentry)
        return 0;
 }
 
-static void cap_inode_delete(struct inode *ino)
-{
-}
-
 static void cap_inode_post_setxattr(struct dentry *dentry, const char *name,
                                    const void *value, size_t size, int flags)
 {
@@ -264,13 +235,13 @@ static void cap_inode_getsecid(const struct inode *inode, u32 *secid)
 }
 
 #ifdef CONFIG_SECURITY_PATH
-static int cap_path_mknod(struct path *dir, struct dentry *dentry, int mode,
+static int cap_path_mknod(struct path *dir, struct dentry *dentry, umode_t mode,
                          unsigned int dev)
 {
        return 0;
 }
 
-static int cap_path_mkdir(struct path *dir, struct dentry *dentry, int mode)
+static int cap_path_mkdir(struct path *dir, struct dentry *dentry, umode_t mode)
 {
        return 0;
 }
@@ -303,8 +274,22 @@ static int cap_path_rename(struct path *old_path, struct dentry *old_dentry,
        return 0;
 }
 
-static int cap_path_truncate(struct path *path, loff_t length,
-                            unsigned int time_attrs)
+static int cap_path_truncate(struct path *path)
+{
+       return 0;
+}
+
+static int cap_path_chmod(struct path *path, umode_t mode)
+{
+       return 0;
+}
+
+static int cap_path_chown(struct path *path, uid_t uid, gid_t gid)
+{
+       return 0;
+}
+
+static int cap_path_chroot(struct path *root)
 {
        return 0;
 }
@@ -330,15 +315,6 @@ static int cap_file_ioctl(struct file *file, unsigned int command,
        return 0;
 }
 
-static int cap_file_mmap(struct file *file, unsigned long reqprot,
-                        unsigned long prot, unsigned long flags,
-                        unsigned long addr, unsigned long addr_only)
-{
-       if ((addr < mmap_min_addr) && !capable(CAP_SYS_RAWIO))
-               return -EACCES;
-       return 0;
-}
-
 static int cap_file_mprotect(struct vm_area_struct *vma, unsigned long reqprot,
                             unsigned long prot)
 {
@@ -372,7 +348,7 @@ static int cap_file_receive(struct file *file)
        return 0;
 }
 
-static int cap_dentry_open(struct file *file, const struct cred *cred)
+static int cap_file_open(struct file *file, const struct cred *cred)
 {
        return 0;
 }
@@ -382,35 +358,39 @@ static int cap_task_create(unsigned long clone_flags)
        return 0;
 }
 
-static void cap_cred_free(struct cred *cred)
+static void cap_task_free(struct task_struct *task)
 {
 }
 
-static int cap_cred_prepare(struct cred *new, const struct cred *old, gfp_t gfp)
+static int cap_cred_alloc_blank(struct cred *cred, gfp_t gfp)
 {
        return 0;
 }
 
-static void cap_cred_commit(struct cred *new, const struct cred *old)
+static void cap_cred_free(struct cred *cred)
 {
 }
 
-static int cap_kernel_act_as(struct cred *new, u32 secid)
+static int cap_cred_prepare(struct cred *new, const struct cred *old, gfp_t gfp)
 {
        return 0;
 }
 
-static int cap_kernel_create_files_as(struct cred *new, struct inode *inode)
+static void cap_cred_transfer(struct cred *new, const struct cred *old)
+{
+}
+
+static int cap_kernel_act_as(struct cred *new, u32 secid)
 {
        return 0;
 }
 
-static int cap_task_setuid(uid_t id0, uid_t id1, uid_t id2, int flags)
+static int cap_kernel_create_files_as(struct cred *new, struct inode *inode)
 {
        return 0;
 }
 
-static int cap_task_setgid(gid_t id0, gid_t id1, gid_t id2, int flags)
+static int cap_kernel_module_request(char *kmod_name)
 {
        return 0;
 }
@@ -435,17 +415,13 @@ static void cap_task_getsecid(struct task_struct *p, u32 *secid)
        *secid = 0;
 }
 
-static int cap_task_setgroups(struct group_info *group_info)
-{
-       return 0;
-}
-
 static int cap_task_getioprio(struct task_struct *p)
 {
        return 0;
 }
 
-static int cap_task_setrlimit(unsigned int resource, struct rlimit *new_rlim)
+static int cap_task_setrlimit(struct task_struct *p, unsigned int resource,
+               struct rlimit *new_rlim)
 {
        return 0;
 }
@@ -576,7 +552,7 @@ static int cap_sem_semop(struct sem_array *sma, struct sembuf *sops,
 }
 
 #ifdef CONFIG_SECURITY_NETWORK
-static int cap_unix_stream_connect(struct socket *sock, struct socket *other,
+static int cap_unix_stream_connect(struct sock *sock, struct sock *other,
                                   struct sock *newsk)
 {
        return 0;
@@ -620,10 +596,6 @@ static int cap_socket_accept(struct socket *sock, struct socket *newsock)
        return 0;
 }
 
-static void cap_socket_post_accept(struct socket *sock, struct socket *newsock)
-{
-}
-
 static int cap_socket_sendmsg(struct socket *sock, struct msghdr *msg, int size)
 {
        return 0;
@@ -714,10 +686,37 @@ static void cap_inet_conn_established(struct sock *sk, struct sk_buff *skb)
 {
 }
 
+static int cap_secmark_relabel_packet(u32 secid)
+{
+       return 0;
+}
+
+static void cap_secmark_refcount_inc(void)
+{
+}
+
+static void cap_secmark_refcount_dec(void)
+{
+}
+
 static void cap_req_classify_flow(const struct request_sock *req,
                                  struct flowi *fl)
 {
 }
+
+static int cap_tun_dev_create(void)
+{
+       return 0;
+}
+
+static void cap_tun_dev_post_create(struct sock *sk)
+{
+}
+
+static int cap_tun_dev_attach(struct sock *sk)
+{
+       return 0;
+}
 #endif /* CONFIG_SECURITY_NETWORK */
 
 #ifdef CONFIG_SECURITY_NETWORK_XFRM
@@ -765,7 +764,7 @@ static int cap_xfrm_policy_lookup(struct xfrm_sec_ctx *ctx, u32 sk_sid, u8 dir)
 
 static int cap_xfrm_state_pol_flow_match(struct xfrm_state *x,
                                         struct xfrm_policy *xp,
-                                        struct flowi *fl)
+                                        const struct flowi *fl)
 {
        return 1;
 }
@@ -798,13 +797,28 @@ static int cap_secid_to_secctx(u32 secid, char **secdata, u32 *seclen)
 
 static int cap_secctx_to_secid(const char *secdata, u32 seclen, u32 *secid)
 {
-       return -EOPNOTSUPP;
+       *secid = 0;
+       return 0;
 }
 
 static void cap_release_secctx(char *secdata, u32 seclen)
 {
 }
 
+static int cap_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen)
+{
+       return 0;
+}
+
+static int cap_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen)
+{
+       return 0;
+}
+
+static int cap_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
+{
+       return 0;
+}
 #ifdef CONFIG_KEYS
 static int cap_key_alloc(struct key *key, const struct cred *cred,
                         unsigned long flags)
@@ -852,10 +866,6 @@ static void cap_audit_rule_free(void *lsmrule)
 }
 #endif /* CONFIG_AUDIT */
 
-struct security_operations default_security_ops = {
-       .name   = "default",
-};
-
 #define set_to_cap_if_null(ops, function)                              \
        do {                                                            \
                if (!ops->function) {                                   \
@@ -865,17 +875,15 @@ struct security_operations default_security_ops = {
                        }                                               \
        } while (0)
 
-void security_fixup_ops(struct security_operations *ops)
+void __init security_fixup_ops(struct security_operations *ops)
 {
-       set_to_cap_if_null(ops, ptrace_may_access);
+       set_to_cap_if_null(ops, ptrace_access_check);
        set_to_cap_if_null(ops, ptrace_traceme);
        set_to_cap_if_null(ops, capget);
        set_to_cap_if_null(ops, capset);
-       set_to_cap_if_null(ops, acct);
        set_to_cap_if_null(ops, capable);
        set_to_cap_if_null(ops, quotactl);
        set_to_cap_if_null(ops, quota_on);
-       set_to_cap_if_null(ops, sysctl);
        set_to_cap_if_null(ops, syslog);
        set_to_cap_if_null(ops, settime);
        set_to_cap_if_null(ops, vm_enough_memory);
@@ -887,18 +895,13 @@ void security_fixup_ops(struct security_operations *ops)
        set_to_cap_if_null(ops, sb_alloc_security);
        set_to_cap_if_null(ops, sb_free_security);
        set_to_cap_if_null(ops, sb_copy_data);
+       set_to_cap_if_null(ops, sb_remount);
        set_to_cap_if_null(ops, sb_kern_mount);
        set_to_cap_if_null(ops, sb_show_options);
        set_to_cap_if_null(ops, sb_statfs);
        set_to_cap_if_null(ops, sb_mount);
-       set_to_cap_if_null(ops, sb_check_sb);
        set_to_cap_if_null(ops, sb_umount);
-       set_to_cap_if_null(ops, sb_umount_close);
-       set_to_cap_if_null(ops, sb_umount_busy);
-       set_to_cap_if_null(ops, sb_post_remount);
-       set_to_cap_if_null(ops, sb_post_addmount);
        set_to_cap_if_null(ops, sb_pivotroot);
-       set_to_cap_if_null(ops, sb_post_pivotroot);
        set_to_cap_if_null(ops, sb_set_mnt_opts);
        set_to_cap_if_null(ops, sb_clone_mnt_opts);
        set_to_cap_if_null(ops, sb_parse_opts_str);
@@ -918,7 +921,6 @@ void security_fixup_ops(struct security_operations *ops)
        set_to_cap_if_null(ops, inode_permission);
        set_to_cap_if_null(ops, inode_setattr);
        set_to_cap_if_null(ops, inode_getattr);
-       set_to_cap_if_null(ops, inode_delete);
        set_to_cap_if_null(ops, inode_setxattr);
        set_to_cap_if_null(ops, inode_post_setxattr);
        set_to_cap_if_null(ops, inode_getxattr);
@@ -939,33 +941,37 @@ void security_fixup_ops(struct security_operations *ops)
        set_to_cap_if_null(ops, path_link);
        set_to_cap_if_null(ops, path_rename);
        set_to_cap_if_null(ops, path_truncate);
+       set_to_cap_if_null(ops, path_chmod);
+       set_to_cap_if_null(ops, path_chown);
+       set_to_cap_if_null(ops, path_chroot);
 #endif
        set_to_cap_if_null(ops, file_permission);
        set_to_cap_if_null(ops, file_alloc_security);
        set_to_cap_if_null(ops, file_free_security);
        set_to_cap_if_null(ops, file_ioctl);
-       set_to_cap_if_null(ops, file_mmap);
+       set_to_cap_if_null(ops, mmap_addr);
+       set_to_cap_if_null(ops, mmap_file);
        set_to_cap_if_null(ops, file_mprotect);
        set_to_cap_if_null(ops, file_lock);
        set_to_cap_if_null(ops, file_fcntl);
        set_to_cap_if_null(ops, file_set_fowner);
        set_to_cap_if_null(ops, file_send_sigiotask);
        set_to_cap_if_null(ops, file_receive);
-       set_to_cap_if_null(ops, dentry_open);
+       set_to_cap_if_null(ops, file_open);
        set_to_cap_if_null(ops, task_create);
+       set_to_cap_if_null(ops, task_free);
+       set_to_cap_if_null(ops, cred_alloc_blank);
        set_to_cap_if_null(ops, cred_free);
        set_to_cap_if_null(ops, cred_prepare);
-       set_to_cap_if_null(ops, cred_commit);
+       set_to_cap_if_null(ops, cred_transfer);
        set_to_cap_if_null(ops, kernel_act_as);
        set_to_cap_if_null(ops, kernel_create_files_as);
-       set_to_cap_if_null(ops, task_setuid);
+       set_to_cap_if_null(ops, kernel_module_request);
        set_to_cap_if_null(ops, task_fix_setuid);
-       set_to_cap_if_null(ops, task_setgid);
        set_to_cap_if_null(ops, task_setpgid);
        set_to_cap_if_null(ops, task_getpgid);
        set_to_cap_if_null(ops, task_getsid);
        set_to_cap_if_null(ops, task_getsecid);
-       set_to_cap_if_null(ops, task_setgroups);
        set_to_cap_if_null(ops, task_setnice);
        set_to_cap_if_null(ops, task_setioprio);
        set_to_cap_if_null(ops, task_getioprio);
@@ -998,13 +1004,15 @@ void security_fixup_ops(struct security_operations *ops)
        set_to_cap_if_null(ops, sem_semctl);
        set_to_cap_if_null(ops, sem_semop);
        set_to_cap_if_null(ops, netlink_send);
-       set_to_cap_if_null(ops, netlink_recv);
        set_to_cap_if_null(ops, d_instantiate);
        set_to_cap_if_null(ops, getprocattr);
        set_to_cap_if_null(ops, setprocattr);
        set_to_cap_if_null(ops, secid_to_secctx);
        set_to_cap_if_null(ops, secctx_to_secid);
        set_to_cap_if_null(ops, release_secctx);
+       set_to_cap_if_null(ops, inode_notifysecctx);
+       set_to_cap_if_null(ops, inode_setsecctx);
+       set_to_cap_if_null(ops, inode_getsecctx);
 #ifdef CONFIG_SECURITY_NETWORK
        set_to_cap_if_null(ops, unix_stream_connect);
        set_to_cap_if_null(ops, unix_may_send);
@@ -1014,7 +1022,6 @@ void security_fixup_ops(struct security_operations *ops)
        set_to_cap_if_null(ops, socket_connect);
        set_to_cap_if_null(ops, socket_listen);
        set_to_cap_if_null(ops, socket_accept);
-       set_to_cap_if_null(ops, socket_post_accept);
        set_to_cap_if_null(ops, socket_sendmsg);
        set_to_cap_if_null(ops, socket_recvmsg);
        set_to_cap_if_null(ops, socket_getsockname);
@@ -1033,7 +1040,13 @@ void security_fixup_ops(struct security_operations *ops)
        set_to_cap_if_null(ops, inet_conn_request);
        set_to_cap_if_null(ops, inet_csk_clone);
        set_to_cap_if_null(ops, inet_conn_established);
+       set_to_cap_if_null(ops, secmark_relabel_packet);
+       set_to_cap_if_null(ops, secmark_refcount_inc);
+       set_to_cap_if_null(ops, secmark_refcount_dec);
        set_to_cap_if_null(ops, req_classify_flow);
+       set_to_cap_if_null(ops, tun_dev_create);
+       set_to_cap_if_null(ops, tun_dev_post_create);
+       set_to_cap_if_null(ops, tun_dev_attach);
 #endif /* CONFIG_SECURITY_NETWORK */
 #ifdef CONFIG_SECURITY_NETWORK_XFRM
        set_to_cap_if_null(ops, xfrm_policy_alloc_security);