selinux: cleanup selinux_lsm_getattr()
[sfrench/cifs-2.6.git] / security / selinux / hooks.c
index 3448454c82d033f7be8a6b942c462c6816360302..190d3f94c5955841448b290cd8a9c51567d84c03 100644 (file)
@@ -6348,55 +6348,55 @@ static void selinux_d_instantiate(struct dentry *dentry, struct inode *inode)
 static int selinux_lsm_getattr(unsigned int attr, struct task_struct *p,
                               char **value)
 {
-       const struct task_security_struct *__tsec;
-       u32 sid;
+       const struct task_security_struct *tsec;
        int error;
-       unsigned len;
+       u32 sid;
+       u32 len;
 
        rcu_read_lock();
-       __tsec = selinux_cred(__task_cred(p));
-
-       if (current != p) {
-               error = avc_has_perm(current_sid(), __tsec->sid,
+       tsec = selinux_cred(__task_cred(p));
+       if (p != current) {
+               error = avc_has_perm(current_sid(), tsec->sid,
                                     SECCLASS_PROCESS, PROCESS__GETATTR, NULL);
                if (error)
-                       goto bad;
+                       goto err_unlock;
        }
-
        switch (attr) {
        case LSM_ATTR_CURRENT:
-               sid = __tsec->sid;
+               sid = tsec->sid;
                break;
        case LSM_ATTR_PREV:
-               sid = __tsec->osid;
+               sid = tsec->osid;
                break;
        case LSM_ATTR_EXEC:
-               sid = __tsec->exec_sid;
+               sid = tsec->exec_sid;
                break;
        case LSM_ATTR_FSCREATE:
-               sid = __tsec->create_sid;
+               sid = tsec->create_sid;
                break;
        case LSM_ATTR_KEYCREATE:
-               sid = __tsec->keycreate_sid;
+               sid = tsec->keycreate_sid;
                break;
        case LSM_ATTR_SOCKCREATE:
-               sid = __tsec->sockcreate_sid;
+               sid = tsec->sockcreate_sid;
                break;
        default:
                error = -EOPNOTSUPP;
-               goto bad;
+               goto err_unlock;
        }
        rcu_read_unlock();
 
-       if (!sid)
+       if (sid == SECSID_NULL) {
+               *value = NULL;
                return 0;
+       }
 
        error = security_sid_to_context(sid, value, &len);
        if (error)
                return error;
        return len;
 
-bad:
+err_unlock:
        rcu_read_unlock();
        return error;
 }