diff options
author | Luis Henriques <lhenriques@suse.com> | 2017-04-28 06:14:04 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2017-05-20 08:28:39 -0400 |
commit | 091784ae973837a11d9d894f2aee63a44af641af (patch) | |
tree | bad809ccde3f9966f567d2c91c514505193215e3 /fs | |
parent | 9a6bb7b5637eb3dc9b16085d05e176edf27665e6 (diff) |
ceph: fix memory leak in __ceph_setxattr()
commit eeca958dce0a9231d1969f86196653eb50fcc9b3 upstream.
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:
[<ffffffff81560199>] kmemleak_alloc+0x49/0xa0
[<ffffffff810f3e5b>] kmem_cache_alloc+0x9b/0xf0
[<ffffffff812b157e>] __ceph_setxattr+0x17e/0x820
[<ffffffff812b1c57>] ceph_set_xattr_handler+0x37/0x40
[<ffffffff8111fb4b>] __vfs_removexattr+0x4b/0x60
[<ffffffff8111fd37>] vfs_removexattr+0x77/0xd0
[<ffffffff8111fdd1>] removexattr+0x41/0x60
[<ffffffff8111fe65>] path_removexattr+0x75/0xa0
[<ffffffff81120aeb>] SyS_lremovexattr+0xb/0x10
[<ffffffff81564b20>] entry_SYSCALL_64_fastpath+0x13/0x94
[<ffffffffffffffff>] 0xffffffffffffffff
Signed-off-by: Luis Henriques <lhenriques@suse.com>
Reviewed-by: "Yan, Zheng" <zyan@redhat.com>
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/ceph/xattr.c | 3 |
1 files changed, 3 insertions, 0 deletions
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, | |||
392 | 392 | ||
393 | if (update_xattr) { | 393 | if (update_xattr) { |
394 | int err = 0; | 394 | int err = 0; |
395 | |||
395 | if (xattr && (flags & XATTR_CREATE)) | 396 | if (xattr && (flags & XATTR_CREATE)) |
396 | err = -EEXIST; | 397 | err = -EEXIST; |
397 | else if (!xattr && (flags & XATTR_REPLACE)) | 398 | else if (!xattr && (flags & XATTR_REPLACE)) |
@@ -399,12 +400,14 @@ static int __set_xattr(struct ceph_inode_info *ci, | |||
399 | if (err) { | 400 | if (err) { |
400 | kfree(name); | 401 | kfree(name); |
401 | kfree(val); | 402 | kfree(val); |
403 | kfree(*newxattr); | ||
402 | return err; | 404 | return err; |
403 | } | 405 | } |
404 | if (update_xattr < 0) { | 406 | if (update_xattr < 0) { |
405 | if (xattr) | 407 | if (xattr) |
406 | __remove_xattr(ci, xattr); | 408 | __remove_xattr(ci, xattr); |
407 | kfree(name); | 409 | kfree(name); |
410 | kfree(*newxattr); | ||
408 | return 0; | 411 | return 0; |
409 | } | 412 | } |
410 | } | 413 | } |