Skip to content

Commit e6b5ebc

Browse files
committed
selinux: cleanup selinux_lsm_getattr()
A number of small changes to selinux_lsm_getattr() to improve the quality and readability of the code: * Explicitly set the `value` parameter to NULL in the case where an attribute has not been set. * Rename the `__tsec` variable to `tsec` to better fit the SELinux code. * Rename `bad` to `err_unlock` to better indicate the jump target drops the RCU lock. Signed-off-by: Paul Moore <[email protected]>
1 parent 0142c56 commit e6b5ebc

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

security/selinux/hooks.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6348,55 +6348,55 @@ static void selinux_d_instantiate(struct dentry *dentry, struct inode *inode)
63486348
static int selinux_lsm_getattr(unsigned int attr, struct task_struct *p,
63496349
char **value)
63506350
{
6351-
const struct task_security_struct *__tsec;
6352-
u32 sid;
6351+
const struct task_security_struct *tsec;
63536352
int error;
6354-
unsigned len;
6353+
u32 sid;
6354+
u32 len;
63556355

63566356
rcu_read_lock();
6357-
__tsec = selinux_cred(__task_cred(p));
6358-
6359-
if (current != p) {
6360-
error = avc_has_perm(current_sid(), __tsec->sid,
6357+
tsec = selinux_cred(__task_cred(p));
6358+
if (p != current) {
6359+
error = avc_has_perm(current_sid(), tsec->sid,
63616360
SECCLASS_PROCESS, PROCESS__GETATTR, NULL);
63626361
if (error)
6363-
goto bad;
6362+
goto err_unlock;
63646363
}
6365-
63666364
switch (attr) {
63676365
case LSM_ATTR_CURRENT:
6368-
sid = __tsec->sid;
6366+
sid = tsec->sid;
63696367
break;
63706368
case LSM_ATTR_PREV:
6371-
sid = __tsec->osid;
6369+
sid = tsec->osid;
63726370
break;
63736371
case LSM_ATTR_EXEC:
6374-
sid = __tsec->exec_sid;
6372+
sid = tsec->exec_sid;
63756373
break;
63766374
case LSM_ATTR_FSCREATE:
6377-
sid = __tsec->create_sid;
6375+
sid = tsec->create_sid;
63786376
break;
63796377
case LSM_ATTR_KEYCREATE:
6380-
sid = __tsec->keycreate_sid;
6378+
sid = tsec->keycreate_sid;
63816379
break;
63826380
case LSM_ATTR_SOCKCREATE:
6383-
sid = __tsec->sockcreate_sid;
6381+
sid = tsec->sockcreate_sid;
63846382
break;
63856383
default:
63866384
error = -EOPNOTSUPP;
6387-
goto bad;
6385+
goto err_unlock;
63886386
}
63896387
rcu_read_unlock();
63906388

6391-
if (!sid)
6389+
if (sid == SECSID_NULL) {
6390+
*value = NULL;
63926391
return 0;
6392+
}
63936393

63946394
error = security_sid_to_context(sid, value, &len);
63956395
if (error)
63966396
return error;
63976397
return len;
63986398

6399-
bad:
6399+
err_unlock:
64006400
rcu_read_unlock();
64016401
return error;
64026402
}

0 commit comments

Comments
 (0)