From patchwork Fri Jun 1 17:45:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 10444191 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1E6B96028F for ; Fri, 1 Jun 2018 17:45:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0CE4428A19 for ; Fri, 1 Jun 2018 17:45:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F3AB928BFF; Fri, 1 Jun 2018 17:45:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 88F6D28A19 for ; Fri, 1 Jun 2018 17:45:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752857AbeFARpW (ORCPT ); Fri, 1 Jun 2018 13:45:22 -0400 Received: from sonic301-28.consmr.mail.gq1.yahoo.com ([98.137.64.154]:42494 "EHLO sonic301-28.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752839AbeFARpR (ORCPT ); Fri, 1 Jun 2018 13:45:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1527875116; bh=qM7FXSpC4xfv5fIaCcb0Does5UJm5PQaq4mQd7f5EM8=; h=Subject:To:Cc:References:From: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6tVLGsfS7OAPivB37zwQy39hsCV88TTW8qaA1MeOdFULyV6g0tV.M3eP Received: from sonic.gate.mail.ne1.yahoo.com by sonic301.consmr.mail.gq1.yahoo.com with HTTP; Fri, 1 Jun 2018 17:45:16 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO [192.168.0.105]) ([67.169.65.224]) by smtp415.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 7ec93ea80107c3e37a1963c63d77a994; Fri, 01 Jun 2018 17:45:13 +0000 (UTC) Subject: [PATCH] Smack: Fix memory leak in smack_inode_getsecctx To: chandan.vn@samsung.com, "linux-security-module@vger.kernel.org" Cc: Tejun Heo , "gregkh@linuxfoundation.org" , "bfields@fieldses.org" , "jlayton@kernel.org" , "linux-kernel@vger.kernel.org" , "linux-nfs@vger.kernel.org" , CPGS , Sireesha Talluri , Chris Wright , Casey Schaufler References: <02d9878e-65bf-5de8-9658-cf0f692f358c@schaufler-ca.com> <1ced6bce-92cc-7e0c-fab4-0aaa3d03b82f@schaufler-ca.com> <1527758911-18610-1-git-send-email-chandan.vn@samsung.com> <20180531153943.GR1351649@devbig577.frc2.facebook.com> <4f00f9ae-3302-83b9-c083-d21ade380eb2@schaufler-ca.com> <20180531161107.GV1351649@devbig577.frc2.facebook.com> <20180601085609epcms5p5fefac0156a4816e9e48751211ab595ee@epcms5p5> <20180601162913epcms5p7737f5b4376d8865af1eae119aa866550@epcms5p7> <5b0b157a-0e8c-d8f5-901e-836d545a8e4c@schaufler-ca.com> From: Casey Schaufler Message-ID: Date: Fri, 1 Jun 2018 10:45:12 -0700 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: <5b0b157a-0e8c-d8f5-901e-836d545a8e4c@schaufler-ca.com> Content-Language: en-US Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- security/smack/smack_lsm.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html 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, */ 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; } /* @@ -4538,12 +4538,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; }