Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp398849imm; Thu, 31 May 2018 02:29:39 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJTOX1XUszkiugtfPg1j9MWS0R058a0AUg5WIfpicL5egZRVg54P7+FRfN0VQecsX4B0rS+ X-Received: by 2002:a63:a00a:: with SMTP id r10-v6mr4977468pge.222.1527758979136; Thu, 31 May 2018 02:29:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527758979; cv=none; d=google.com; s=arc-20160816; b=my0SWubZ8WoS4Ya8J3VlA7otJgBSV7taA3sJmOMaRLa4FuIGg+XER+7kCbtmMBgLpJ PfrWKoBGeTRKf6NRPHiHC+MJnK3MByI1UrFKg5M0BlmxTEMxROG7+qoxiy7KULjAMdzq KtZNx347nfe5W1f7HOpqKIhsMooyqavuC355OJCdKR7W/gHzPn5hbs0Cu2D4KY2Nfmgz FaCgwOMULyVBE4ybCl1Y7ccn56EIiOpgqxeJkop/lEbefPySz5bBPPY39zqU6T03KuUW ytRJCfCMTFTZCbMC8HMKKUrU8kGFCSLbb/iDx2xT3VQoSWDGY2H3t69JUP8Ug0i8924l NZKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:dlp-filter:cms-type:message-id :date:subject:cc:to:from:dkim-signature:dkim-filter :arc-authentication-results; bh=wbLX5rDNeWVFA4X+OnFlvZtoywAC/DP/2Nlup4ktKAo=; b=QW/fk+BOB40IkQfQlZeLNArvLlEWR6m4/TFyk8SUucrwrZURg5+tjCwXFn/gYJzbGD UayJIjGOtncclCbOoDnaGgavC5ub3xUZQplF+ONlhdS5Hov86OVEhgjghw64REggmJnx 35zomKborej2aBibdHGPEK6UtOKOc0u8vUEVBZS9iT5ER20ToWpJp+EILoddeV/VssfD XL3jW9B3V2klNW+1nbg+oemPVwNeuBJ90kTgqWUfHwDUXG1j1BOlmCvY2prZHAI1AypB c3uZKwQK6ewora7eWDUzRigJm9nDGatgyPXN2rOgY0FleX/wsNm52+nawNaqRXuDvdI+ k61A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=PQKfvpkE; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z3-v6si36356454plb.228.2018.05.31.02.29.24; Thu, 31 May 2018 02:29:39 -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=pass header.i=@samsung.com header.s=mail20170921 header.b=PQKfvpkE; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754267AbeEaJ2y (ORCPT + 99 others); Thu, 31 May 2018 05:28:54 -0400 Received: from mailout1.samsung.com ([203.254.224.24]:23629 "EHLO mailout1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754164AbeEaJ2v (ORCPT ); Thu, 31 May 2018 05:28:51 -0400 Received: from epcas5p2.samsung.com (unknown [182.195.41.40]) by mailout1.samsung.com (KnoxPortal) with ESMTP id 20180531092849epoutp010e13475450b548b0a9d822622d52a684~zsKcCDzGW0715207152epoutp01c; Thu, 31 May 2018 09:28:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.samsung.com 20180531092849epoutp010e13475450b548b0a9d822622d52a684~zsKcCDzGW0715207152epoutp01c DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1527758930; bh=wbLX5rDNeWVFA4X+OnFlvZtoywAC/DP/2Nlup4ktKAo=; h=From:To:Cc:Subject:Date:References:From; b=PQKfvpkERdDpAlKKxPsNgKgDoPBR3G5B/rrwhD/i0u/DHM8PcBmGjdCPMoU5FNJ4l 4jXuZLLPT6QhI+b2xqrvlJHvQly+hGNAObxvrVtEmwkBu1YNYaQXSaWFq5/7v3tLdM PcZS9GES7yl+RSKsfWKREnmc1nZLwReblBgNA3Q0= Received: from epsmges1p1.samsung.com (unknown [182.195.40.197]) by epcas5p4.samsung.com (KnoxPortal) with ESMTP id 20180531092849epcas5p45345a801574155129ffb7fd6f89b0e27~zsKbnBC6U2316723167epcas5p4q; Thu, 31 May 2018 09:28:49 +0000 (GMT) Received: from epcas1p4.samsung.com ( [182.195.41.48]) by epsmges1p1.samsung.com (Symantec Messaging Gateway) with SMTP id 55.54.04066.150CF0B5; Thu, 31 May 2018 18:28:49 +0900 (KST) Received: from epsmgms2p1new.samsung.com (unknown [182.195.42.142]) by epcas1p2.samsung.com (KnoxPortal) with ESMTP id 20180531092848epcas1p24b638ccd6da00f1e039bdb64de7e1a5b~zsKayuuee2181621816epcas1p2B; Thu, 31 May 2018 09:28:48 +0000 (GMT) X-AuditID: b6c32a35-ba1ff70000000fe2-0f-5b0fc051b775 Received: from epmmp1.local.host ( [203.254.227.16]) by epsmgms2p1new.samsung.com (Symantec Messaging Gateway) with SMTP id 5E.0D.03915.050CF0B5; Thu, 31 May 2018 18:28:48 +0900 (KST) Received: from chandan.sa.corp.samsungelectronics.net ([107.109.106.209]) by mmp1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0P9L00MTJ6BNIR50@mmp1.samsung.com>; Thu, 31 May 2018 18:28:48 +0900 (KST) From: CHANDAN VN To: gregkh@linuxfoundation.org, tj@kernel.org, bfields@fieldses.org, jlayton@kernel.org, linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, casey@schaufler-ca.com Cc: cpgs@samsung.com, chandan.vn@samsung.com, sireesha.t@samsung.com Subject: [PATCH 1/1] Fix memory leak in kernfs_security_xattr_set and kernfs_security_xattr_set Date: Thu, 31 May 2018 14:58:31 +0530 Message-id: <1527758911-18610-1-git-send-email-chandan.vn@samsung.com> X-Mailer: git-send-email 1.9.1 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprHKsWRmVeSWpSXmKPExsWy7bCmgW7gAf5og31nZCxeTImyuLftF5vF hC8RFi8PaVo0L17PZvFz2Sp2i8u75rBZXDhwmtVi14UCi1/LjzI6cHlsmNrE5rFpVSebx/65 a9g9+rasYvQ4un8Rm8fnTXIBbFGpNhmpiSmpRQqpecn5KZl56bZK3sHxzvGmZgaGuoaWFuZK CnmJuam2Si4+AbpumTlAZykplCXmlAKFAhKLi5X07WyK8ktLUhUy8otLbJWiDQ2N9AwNzPWM jIC0aayVkSlQSUJqxpYTGxkLJohVPHi3kLWB8Z5QFyMnh4SAicTyl3PZuhi5OIQEdjBKNMye wwjhfGeU+HloDxNM1erZj1ghErsZJSZtvc4E4XQzSZzpeMUCUsUmoClxYt40dpCEiMAaRolz a3YwgySYBVwkTv7vYQSxhQUSJe7teA1mswioSsx99h1sBa+Am8TZD5fZINbJSZw8NhlsnYRA D5vEnW8guzmAHBeJ1uXREDXCEq+Ob2GHCEtLXDpqC2HmS7zarQBRUSHxv2ErC4RtLzFj8Vao a/gk3n3tgRrIK9HRBg0JD4lXrYvASoQEYiVmrH3BNoFRYgEjwypGsdSC4tz01GLDAkO94sTc 4tK8dL3k/NxNjOC0oWW6g3HKOZ9DjAIcjEo8vBxr+KKFWBPLiitzDzFKcDArifBOKeOPFuJN SaysSi3Kjy8qzUktPsRoCvT/RGYp0eR8YErLK4k3NDUyMzOwNLc0szCwUBLnbTP/FyUkkJ5Y kpqdmlqQWgTTx8TBKdXAeDG/IpFF2DNAZnOyhafctTMGX7KcllvdMbGqeyOpx7Pz1b/1G2aV /2csOrr7zYXAYPaAWeXLnly5K7FA8e6VHYv/BhesNzezdW0odPjkaTSdu+qzVSuH0/InnrUL emxju71C4pcvWV3gl3x61oUpify/WaYfdg/aP6f8bbRlcfyzZSKbvik8VGIpzkg01GIuKk4E ADzl8tAxAwAA X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmplluLIzCtJLcpLzFFi42I5/e+xgG7AAf5og/PvlS1eTImyuLftF5vF hC8RFi8PaVo0L17PZvFz2Sp2i8u75rBZXDhwmtVi14UCi1/LjzI6cHlsmNrE5rFpVSebx/65 a9g9+rasYvQ4un8Rm8fnTXIBbFFcNimpOZllqUX6dglcGVtObGQsmCBW8eDdQtYGxntCXYyc HBICJhKrZz9i7WLk4hAS2Mko0bxhCQuE08sksWnBGXaQKjYBTYkT86axgyREBNYwSkx/uI4R JMEs4CJx8n8PmC0skChxb8drMJtFQFVi7rPvTCA2r4CbxNkPl9kg1slJnDw2mXUCI9cCRoZV jJKpBcW56bnFRgWGeanlesWJucWleel6yfm5mxiBgbPtsFbfDsb7S+IPMQpwMCrx8HKs4YsW Yk0sK67MPcQowcGsJMI7pYw/Wog3JbGyKrUoP76oNCe1+BCjNAeLkjjv7bxjkUIC6Yklqdmp qQWpRTBZJg5OqQbGkvwJHIZ/o6e8mhw6XdzGgDM+XXpZOofkB0PRBzqPu16c5RK+K6ksd+H1 AVmOZVznXlzy2xiRcrCOaUqS9PIejjWuXVeCUgOfeS8UMC2cpBup/ZD3BMfcf9pnMzzD1Zdw uy77tFkxlTWBaaetws7W1yEdz1KXHyo2dljbNXV+4Pkvjcu2LxJVYinOSDTUYi4qTgQA5E47 lRgCAAA= X-CMS-MailID: 20180531092848epcas1p24b638ccd6da00f1e039bdb64de7e1a5b X-Msg-Generator: CA CMS-TYPE: 101P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20180531092848epcas1p24b638ccd6da00f1e039bdb64de7e1a5b References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "sireesha.t" Leak is caused because smack_inode_getsecurity() is allocating memory using kstrdup(). Though the security_release_secctx() is called, it would not free the allocated memory. Calling security_release_secctx is not relevant for this scenario as inode_getsecurity() does not provide a "secctx". Similar fix has been mainlined: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git/commit/?id=57e7ba04d422c3d41c8426380303ec9b7533ded9 The fix is to replace the security_release_secctx() with a kfree() Below is the KMEMLEAK dump: unreferenced object 0xffffffc025e11c80 (size 64): comm "systemd-tmpfile", pid 2452, jiffies 4294894464 (age 235587.492s) hex dump (first 32 bytes): 53 79 73 74 65 6d 3a 3a 53 68 61 72 65 64 00 00 System::Shared.. 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ backtrace: [] __save_stack_trace+0x28/0x34 [] create_object+0x130/0x25c [] kmemleak_alloc+0x30/0x5c [] __kmalloc_track_caller+0x1cc/0x2a8 [] kstrdup+0x3c/0x6c [] smack_inode_getsecurity+0xcc/0xec [] smack_inode_getsecctx+0x24/0x44 [] security_inode_getsecctx+0x50/0x70 [] kernfs_security_xattr_set+0x74/0xe0 [] __vfs_setxattr+0x74/0x90 [] __vfs_setxattr_noperm+0x80/0x1ac [] vfs_setxattr+0x84/0xac [] setxattr+0x114/0x178 [] path_setxattr+0x74/0xb8 [] SyS_lsetxattr+0x10/0x1c [] __sys_trace_return+0x0/0x4 Signed-off-by: sireesha.t Signed-off-by: CHANDAN VN --- fs/kernfs/inode.c | 3 ++- fs/nfsd/nfs4xdr.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/fs/kernfs/inode.c b/fs/kernfs/inode.c index a343039..53befb8 100644 --- a/fs/kernfs/inode.c +++ b/fs/kernfs/inode.c @@ -369,7 +369,8 @@ static int kernfs_security_xattr_set(const struct xattr_handler *handler, mutex_unlock(&kernfs_mutex); if (secdata) - security_release_secctx(secdata, secdata_len); + kfree(secdata); + return error; } diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c index aaa88c1..1e0dbe9 100644 --- a/fs/nfsd/nfs4xdr.c +++ b/fs/nfsd/nfs4xdr.c @@ -2911,7 +2911,7 @@ static int get_parent_attributes(struct svc_export *exp, struct kstat *stat) out: #ifdef CONFIG_NFSD_V4_SECURITY_LABEL if (context) - security_release_secctx(context, contextlen); + kfree(context); #endif /* CONFIG_NFSD_V4_SECURITY_LABEL */ kfree(acl); if (tempfh) { -- 1.9.1