smack: Fix missing calls to netlbl_skbuff_err()
[safe/jmp/linux-2.6] / security / smack / smack_lsm.c
index b5c8f92..6e2dc0b 100644 (file)
@@ -87,26 +87,46 @@ struct inode_smack *new_inode_smack(char *smack)
  */
 
 /**
- * smack_ptrace - Smack approval on ptrace
- * @ptp: parent task pointer
+ * smack_ptrace_may_access - Smack approval on PTRACE_ATTACH
  * @ctp: child task pointer
  *
  * Returns 0 if access is OK, an error code otherwise
  *
  * Do the capability checks, and require read and write.
  */
-static int smack_ptrace(struct task_struct *ptp, struct task_struct *ctp)
+static int smack_ptrace_may_access(struct task_struct *ctp, unsigned int mode)
 {
        int rc;
 
-       rc = cap_ptrace(ptp, ctp);
+       rc = cap_ptrace_may_access(ctp, mode);
        if (rc != 0)
                return rc;
 
-       rc = smk_access(ptp->security, ctp->security, MAY_READWRITE);
-       if (rc != 0 && __capable(ptp, CAP_MAC_OVERRIDE))
+       rc = smk_access(current->security, ctp->security, MAY_READWRITE);
+       if (rc != 0 && capable(CAP_MAC_OVERRIDE))
                return 0;
+       return rc;
+}
 
+/**
+ * smack_ptrace_traceme - Smack approval on PTRACE_TRACEME
+ * @ptp: parent task pointer
+ *
+ * Returns 0 if access is OK, an error code otherwise
+ *
+ * Do the capability checks, and require read and write.
+ */
+static int smack_ptrace_traceme(struct task_struct *ptp)
+{
+       int rc;
+
+       rc = cap_ptrace_traceme(ptp);
+       if (rc != 0)
+               return rc;
+
+       rc = smk_access(ptp->security, current->security, MAY_READWRITE);
+       if (rc != 0 && has_capability(ptp, CAP_MAC_OVERRIDE))
+               return 0;
        return rc;
 }
 
@@ -521,8 +541,7 @@ static int smack_inode_rename(struct inode *old_inode,
  *
  * Returns 0 if access is permitted, -EACCES otherwise
  */
-static int smack_inode_permission(struct inode *inode, int mask,
-                                 struct nameidata *nd)
+static int smack_inode_permission(struct inode *inode, int mask)
 {
        /*
         * No permission to check. Existence test. Yup, it's there.
@@ -923,7 +942,7 @@ static int smack_file_send_sigiotask(struct task_struct *tsk,
         */
        file = container_of(fown, struct file, f_owner);
        rc = smk_access(file->f_security, tsk->security, MAY_WRITE);
-       if (rc != 0 && __capable(tsk, CAP_MAC_OVERRIDE))
+       if (rc != 0 && has_capability(tsk, CAP_MAC_OVERRIDE))
                return 0;
        return rc;
 }
@@ -1164,12 +1183,12 @@ static int smack_task_wait(struct task_struct *p)
         * account for the smack labels having gotten to
         * be different in the first place.
         *
-        * This breaks the strict subjet/object access
+        * This breaks the strict subject/object access
         * control ideal, taking the object's privilege
         * state into account in the decision as well as
         * the smack value.
         */
-       if (capable(CAP_MAC_OVERRIDE) || __capable(p, CAP_MAC_OVERRIDE))
+       if (capable(CAP_MAC_OVERRIDE) || has_capability(p, CAP_MAC_OVERRIDE))
                return 0;
 
        return rc;
@@ -1821,27 +1840,6 @@ static void smack_ipc_getsecid(struct kern_ipc_perm *ipp, u32 *secid)
        *secid = smack_to_secid(smack);
 }
 
-/* module stacking operations */
-
-/**
- * smack_register_security - stack capability module
- * @name: module name
- * @ops: module operations - ignored
- *
- * Allow the capability module to register.
- */
-static int smack_register_security(const char *name,
-                                  struct security_operations *ops)
-{
-       if (strcmp(name, "capability") != 0)
-               return -EINVAL;
-
-       printk(KERN_INFO "%s:  Registering secondary module %s\n",
-              __func__, name);
-
-       return 0;
-}
-
 /**
  * smack_d_instantiate - Make sure the blob is correct on an inode
  * @opt_dentry: unused
@@ -1881,6 +1879,18 @@ static void smack_d_instantiate(struct dentry *opt_dentry, struct inode *inode)
        final = sbsp->smk_default;
 
        /*
+        * If this is the root inode the superblock
+        * may be in the process of initialization.
+        * If that is the case use the root value out
+        * of the superblock.
+        */
+       if (opt_dentry->d_parent == opt_dentry) {
+               isp->smk_inode = sbsp->smk_root;
+               isp->smk_flags |= SMK_INODE_INSTANT;
+               goto unlockandout;
+       }
+
+       /*
         * This is pretty hackish.
         * Casey says that we shouldn't have to do
         * file system specific code, but it does help
@@ -2025,9 +2035,6 @@ static int smack_setprocattr(struct task_struct *p, char *name,
 {
        char *newsmack;
 
-       if (!__capable(p, CAP_MAC_ADMIN))
-               return -EPERM;
-
        /*
         * Changing another process' Smack value is too dangerous
         * and supports no sane use case.
@@ -2035,6 +2042,9 @@ static int smack_setprocattr(struct task_struct *p, char *name,
        if (p != current)
                return -EPERM;
 
+       if (!capable(CAP_MAC_ADMIN))
+               return -EPERM;
+
        if (value == NULL || size == 0 || size >= SMK_LABELLEN)
                return -EINVAL;
 
@@ -2169,7 +2179,10 @@ static int smack_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb)
         * This is the simplist possible security model
         * for networking.
         */
-       return smk_access(smack, ssp->smk_in, MAY_WRITE);
+       rc = smk_access(smack, ssp->smk_in, MAY_WRITE);
+       if (rc != 0)
+               netlbl_skbuff_err(skb, rc, 0);
+       return rc;
 }
 
 /**
@@ -2561,7 +2574,8 @@ static void smack_release_secctx(char *secdata, u32 seclen)
 struct security_operations smack_ops = {
        .name =                         "smack",
 
-       .ptrace =                       smack_ptrace,
+       .ptrace_may_access =            smack_ptrace_may_access,
+       .ptrace_traceme =               smack_ptrace_traceme,
        .capget =                       cap_capget,
        .capset_check =                 cap_capset_check,
        .capset_set =                   cap_capset_set,
@@ -2660,8 +2674,6 @@ struct security_operations smack_ops = {
        .netlink_send =                 cap_netlink_send,
        .netlink_recv =                 cap_netlink_recv,
 
-       .register_security =            smack_register_security,
-
        .d_instantiate =                smack_d_instantiate,
 
        .getprocattr =                  smack_getprocattr,
@@ -2740,4 +2752,3 @@ static __init int smack_init(void)
  * all processes and objects when they are created.
  */
 security_initcall(smack_init);
-