Skip to content

Commit cdc12eb

Browse files
cgzonespcmoore
authored andcommitted
selinux: make more use of current_sid()
Use the internal helper current_sid() where applicable. Signed-off-by: Christian Göttsche <[email protected]> Signed-off-by: Paul Moore <[email protected]>
1 parent 4b3124d commit cdc12eb

File tree

2 files changed

+8
-21
lines changed

2 files changed

+8
-21
lines changed

security/selinux/hooks.c

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2961,7 +2961,7 @@ static int selinux_inode_init_security_anon(struct inode *inode,
29612961
const struct qstr *name,
29622962
const struct inode *context_inode)
29632963
{
2964-
const struct task_security_struct *tsec = selinux_cred(current_cred());
2964+
u32 sid = current_sid();
29652965
struct common_audit_data ad;
29662966
struct inode_security_struct *isec;
29672967
int rc;
@@ -2990,7 +2990,7 @@ static int selinux_inode_init_security_anon(struct inode *inode,
29902990
} else {
29912991
isec->sclass = SECCLASS_ANON_INODE;
29922992
rc = security_transition_sid(
2993-
tsec->sid, tsec->sid,
2993+
sid, sid,
29942994
isec->sclass, name, &isec->sid);
29952995
if (rc)
29962996
return rc;
@@ -3005,7 +3005,7 @@ static int selinux_inode_init_security_anon(struct inode *inode,
30053005
ad.type = LSM_AUDIT_DATA_ANONINODE;
30063006
ad.u.anonclass = name ? (const char *)name->name : "?";
30073007

3008-
return avc_has_perm(tsec->sid,
3008+
return avc_has_perm(sid,
30093009
isec->sid,
30103010
isec->sclass,
30113011
FILE__CREATE,
@@ -3063,14 +3063,12 @@ static int selinux_inode_readlink(struct dentry *dentry)
30633063
static int selinux_inode_follow_link(struct dentry *dentry, struct inode *inode,
30643064
bool rcu)
30653065
{
3066-
const struct cred *cred = current_cred();
30673066
struct common_audit_data ad;
30683067
struct inode_security_struct *isec;
3069-
u32 sid;
3068+
u32 sid = current_sid();
30703069

30713070
ad.type = LSM_AUDIT_DATA_DENTRY;
30723071
ad.u.dentry = dentry;
3073-
sid = cred_sid(cred);
30743072
isec = inode_security_rcu(inode, rcu);
30753073
if (IS_ERR(isec))
30763074
return PTR_ERR(isec);
@@ -3094,12 +3092,11 @@ static noinline int audit_inode_permission(struct inode *inode,
30943092

30953093
static int selinux_inode_permission(struct inode *inode, int mask)
30963094
{
3097-
const struct cred *cred = current_cred();
30983095
u32 perms;
30993096
bool from_access;
31003097
bool no_block = mask & MAY_NOT_BLOCK;
31013098
struct inode_security_struct *isec;
3102-
u32 sid;
3099+
u32 sid = current_sid();
31033100
struct av_decision avd;
31043101
int rc, rc2;
31053102
u32 audited, denied;
@@ -3116,7 +3113,6 @@ static int selinux_inode_permission(struct inode *inode, int mask)
31163113

31173114
perms = file_mask_to_av(inode->i_mode, mask);
31183115

3119-
sid = cred_sid(cred);
31203116
isec = inode_security_rcu(inode, no_block);
31213117
if (IS_ERR(isec))
31223118
return PTR_ERR(isec);
@@ -5564,13 +5560,7 @@ static void selinux_inet_conn_established(struct sock *sk, struct sk_buff *skb)
55645560

55655561
static int selinux_secmark_relabel_packet(u32 sid)
55665562
{
5567-
const struct task_security_struct *tsec;
5568-
u32 tsid;
5569-
5570-
tsec = selinux_cred(current_cred());
5571-
tsid = tsec->sid;
5572-
5573-
return avc_has_perm(tsid, sid, SECCLASS_PACKET, PACKET__RELABELTO,
5563+
return avc_has_perm(current_sid(), sid, SECCLASS_PACKET, PACKET__RELABELTO,
55745564
NULL);
55755565
}
55765566

security/selinux/xfrm.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ static int selinux_xfrm_alloc_user(struct xfrm_sec_ctx **ctxp,
7676
gfp_t gfp)
7777
{
7878
int rc;
79-
const struct task_security_struct *tsec = selinux_cred(current_cred());
8079
struct xfrm_sec_ctx *ctx = NULL;
8180
u32 str_len;
8281

@@ -103,7 +102,7 @@ static int selinux_xfrm_alloc_user(struct xfrm_sec_ctx **ctxp,
103102
if (rc)
104103
goto err;
105104

106-
rc = avc_has_perm(tsec->sid, ctx->ctx_sid,
105+
rc = avc_has_perm(current_sid(), ctx->ctx_sid,
107106
SECCLASS_ASSOCIATION, ASSOCIATION__SETCONTEXT, NULL);
108107
if (rc)
109108
goto err;
@@ -134,12 +133,10 @@ static void selinux_xfrm_free(struct xfrm_sec_ctx *ctx)
134133
*/
135134
static int selinux_xfrm_delete(struct xfrm_sec_ctx *ctx)
136135
{
137-
const struct task_security_struct *tsec = selinux_cred(current_cred());
138-
139136
if (!ctx)
140137
return 0;
141138

142-
return avc_has_perm(tsec->sid, ctx->ctx_sid,
139+
return avc_has_perm(current_sid(), ctx->ctx_sid,
143140
SECCLASS_ASSOCIATION, ASSOCIATION__SETCONTEXT,
144141
NULL);
145142
}

0 commit comments

Comments
 (0)