Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2998216AbdD1Nwp (ORCPT ); Fri, 28 Apr 2017 09:52:45 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50100 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S968301AbdD1Nwf (ORCPT ); Fri, 28 Apr 2017 09:52:35 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com D8A195277F Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=zyan@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com D8A195277F Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 10.3 \(3273\)) Subject: Re: [PATCH] ceph: fix memory leak in __ceph_setxattr() From: "Yan, Zheng" In-Reply-To: <20170428101404.17765-1-lhenriques@suse.com> Date: Fri, 28 Apr 2017 21:52:26 +0800 Cc: Sage Weil , Ilya Dryomov , ceph-devel , Linux Kernel Mailing List , stable@vger.kernel.org Content-Transfer-Encoding: 7bit Message-Id: <4A628342-B33B-4730-889F-3D8F62037CB1@redhat.com> References: <20170428101404.17765-1-lhenriques@suse.com> To: Luis Henriques X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 28 Apr 2017 13:52:35 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2123 Lines: 69 > On 28 Apr 2017, at 18:14, Luis Henriques wrote: > > The ceph_inode_xattr needs to be released when removing an xattr. Easily > reproducible running the 'generic/020' test from xfstests or simply by > doing: > > attr -s attr0 -V 0 /mnt/test && attr -r attr0 /mnt/test > > While there, also fix the error path. > > Here's the kmemleak splat: > > unreferenced object 0xffff88001f86fbc0 (size 64): > comm "attr", pid 244, jiffies 4294904246 (age 98.464s) > hex dump (first 32 bytes): > 40 fa 86 1f 00 88 ff ff 80 32 38 1f 00 88 ff ff @........28..... > 00 01 00 00 00 00 ad de 00 02 00 00 00 00 ad de ................ > backtrace: > [] kmemleak_alloc+0x49/0xa0 > [] kmem_cache_alloc+0x9b/0xf0 > [] __ceph_setxattr+0x17e/0x820 > [] ceph_set_xattr_handler+0x37/0x40 > [] __vfs_removexattr+0x4b/0x60 > [] vfs_removexattr+0x77/0xd0 > [] removexattr+0x41/0x60 > [] path_removexattr+0x75/0xa0 > [] SyS_lremovexattr+0xb/0x10 > [] entry_SYSCALL_64_fastpath+0x13/0x94 > [] 0xffffffffffffffff > > Cc: stable@vger.kernel.org > Signed-off-by: Luis Henriques > --- > fs/ceph/xattr.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/fs/ceph/xattr.c b/fs/ceph/xattr.c > index febc28f9e2c2..75267cdd5dfd 100644 > --- a/fs/ceph/xattr.c > +++ b/fs/ceph/xattr.c > @@ -392,6 +392,7 @@ static int __set_xattr(struct ceph_inode_info *ci, > > if (update_xattr) { > int err = 0; > + > if (xattr && (flags & XATTR_CREATE)) > err = -EEXIST; > else if (!xattr && (flags & XATTR_REPLACE)) > @@ -399,12 +400,14 @@ static int __set_xattr(struct ceph_inode_info *ci, > if (err) { > kfree(name); > kfree(val); > + kfree(*newxattr); > return err; > } > if (update_xattr < 0) { > if (xattr) > __remove_xattr(ci, xattr); > kfree(name); > + kfree(*newxattr); > return 0; > } > } Applied, thanks Yan, Zheng