Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp860217imm; Fri, 1 Jun 2018 10:46:06 -0700 (PDT) X-Google-Smtp-Source: ADUXVKK/Z1/QNzYDcIm5PkHRm96joemttBROt+NBr8wyfeiRS+tcUyMzkbjowAXhAUqyCeS7YpLm X-Received: by 2002:a62:883:: with SMTP id 3-v6mr11938278pfi.154.1527875166789; Fri, 01 Jun 2018 10:46:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527875166; cv=none; d=google.com; s=arc-20160816; b=E+IiYOOc/UoEJQVF5E+ssrBmCylHeazQvG5VPPJ2BU3kJVfjhhJ73VFGwQZpbRzHYs KyNMfubQn+8a0HgSYQ7z60W84q+txabASHBhKIQ8pwQJehLH8Hfv/hXcIa4wNCDC89yB CtZCwK4Wkt5H32eW8rkXBYHpt/9iGLZslT1gnt9BL+6iUIOClGqEdLPf9di5PAz8rqLC rKVpfyqUMHQKOGzkiU9pMWMRg2+4h2tn8Ux94yD7HEtry8GBigeCZCcTLRtE/gQAcoY6 lCIV/SYo7asdzsoo48VUukufNOBmfVSKlnd9GZomIqGCrMluhyeHRH+5v2f8bS7N34LR Y4uw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature :arc-authentication-results; bh=f7BPforU+tt4WBgyURu+WkYnomi8ZraqK+xs45e8e9s=; b=io9rxVqWoLmh+TifHSKhYEkEn9zhsCk195nsRHz+k8xaL4/OpfBhXRvX67fcfIXMKR qoZWv3jvjyozhygMzb8f7rNFarV/gXzN8g1wgZBzmroVMApg5jmByf5F9Igc09b4IfnJ YM1TjHXmg71cywfRkdtf7TCdRngjPdc1jgDC01FgJI/73BigUogQncv8n5udQEF5J3uT qsxwi/g0lwyIK77j+Hv71S2nzzyyNQDkqR0cvEr0DGxwf5tpqcCM8MrT+dqdNh5pwnQi MfpKLWNk8g/9GldhKD4YsU7SYVlZ//Ihbm3IA3hhzOYh2+2EfCyuUQyJdKlCEoBuKxUL iscA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@yahoo.com header.s=s2048 header.b=qeyZ6O6h; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g15-v6si19629208plq.242.2018.06.01.10.45.52; Fri, 01 Jun 2018 10:46:06 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@yahoo.com header.s=s2048 header.b=qeyZ6O6h; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752970AbeFARpV (ORCPT + 99 others); Fri, 1 Jun 2018 13:45:21 -0400 Received: from sonic301-28.consmr.mail.gq1.yahoo.com ([98.137.64.154]:46588 "EHLO sonic301-28.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752857AbeFARpR (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:Date:In-Reply-To:From:Subject; b=qeyZ6O6hiu0HGUhqOj1olQxCPAIMCntTDI7czIu1m2UOWeipADJ7D4YlTf5ZuNBFT+fCkXEb5jKW6hm+j/JqcYdh2q5iFqyFUo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 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-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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(-) 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; }