From: Casey Schaufler Date: Fri, 1 Jun 2018 17:45:12 +0000 (-0700) Subject: Smack: Fix memory leak in smack_inode_getsecctx X-Git-Tag: submit/tizen/20201211.030542~25 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c4ec74834a5ae15b5cbb25be6ddb64210150c295;p=platform%2Fkernel%2Flinux-amlogic.git 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 Reported-by: CHANDAN VN Tested-by: CHANDAN VN [sw0312.kim: cherry-pick mainline commit 0f8983cf97d3] Signed-off-by: Seung-Woo Kim --- diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c index a5debdb120a7..17989324b7b0 100644 --- a/security/smack/smack_lsm.c +++ b/security/smack/smack_lsm.c @@ -1559,9 +1559,9 @@ static int smack_inode_listsecurity(struct inode *inode, char *buffer, */ static void smack_inode_getsecid(struct inode *inode, u32 *secid) { - struct inode_smack *isp = inode->i_security; + struct smack_known *skp = smk_of_inode(inode); - *secid = isp->smk_inode->smk_secid; + *secid = skp->smk_secid; } /* @@ -4619,12 +4619,10 @@ static int smack_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen) static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen) { - int len = 0; - len = smack_inode_getsecurity(inode, XATTR_SMACK_SUFFIX, ctx, true); + struct smack_known *skp = smk_of_inode(inode); - if (len < 0) - return len; - *ctxlen = len; + *ctx = skp->smk_known; + *ctxlen = strlen(skp->smk_known); return 0; }