aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCasey Schaufler <casey@schaufler-ca.com>2018-06-01 13:45:12 -0400
committerCasey Schaufler <casey@schaufler-ca.com>2018-06-05 15:16:01 -0400
commit0f8983cf97d3327531b7843c831517cac3a1b9ed (patch)
tree04978f906764ad6794bf824545ff6b35542f443c
parentb3859ee18ed287170b66b19a78191f7312ec3470 (diff)
Smack: Fix memory leak in smack_inode_getsecctx
Fix memory leak in smack_inode_getsecctx The implementation of smack_inode_getsecctx() made incorrect assumptions about how Smack presents a security context. Smack does not need to allocate memory to support security contexts, so "releasing" a Smack context is a no-op. The code made an unnecessary copy and returned that as a context, which was never freed. The revised implementation returns the context correctly. Signed-off-by: Casey Schaufler <casey@schaufler-ca.com> Reported-by: CHANDAN VN <chandan.vn@samsung.com> Tested-by: CHANDAN VN <chandan.vn@samsung.com>
-rw-r--r--security/smack/smack_lsm.c12
1 files changed, 5 insertions, 7 deletions
diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
index 0b414836bebd..5e3beae334a8 100644
--- a/security/smack/smack_lsm.c
+++ b/security/smack/smack_lsm.c
@@ -1545,9 +1545,9 @@ static int smack_inode_listsecurity(struct inode *inode, char *buffer,
1545 */ 1545 */
1546static void smack_inode_getsecid(struct inode *inode, u32 *secid) 1546static void smack_inode_getsecid(struct inode *inode, u32 *secid)
1547{ 1547{
1548 struct inode_smack *isp = inode->i_security; 1548 struct smack_known *skp = smk_of_inode(inode);
1549 1549
1550 *secid = isp->smk_inode->smk_secid; 1550 *secid = skp->smk_secid;
1551} 1551}
1552 1552
1553/* 1553/*
@@ -4538,12 +4538,10 @@ static int smack_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen)
4538 4538
4539static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen) 4539static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
4540{ 4540{
4541 int len = 0; 4541 struct smack_known *skp = smk_of_inode(inode);
4542 len = smack_inode_getsecurity(inode, XATTR_SMACK_SUFFIX, ctx, true);
4543 4542
4544 if (len < 0) 4543 *ctx = skp->smk_known;
4545 return len; 4544 *ctxlen = strlen(skp->smk_known);
4546 *ctxlen = len;
4547 return 0; 4545 return 0;
4548} 4546}
4549 4547