]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-4.4/btrfs-sysfs-don-t-leak-memory-when-failing-add-fsid.patch
drop rdma-cma-consider-scope_id-while-binding-to-ipv6-ll-.patch from 4.4, 4.9, and...
[thirdparty/kernel/stable-queue.git] / queue-4.4 / btrfs-sysfs-don-t-leak-memory-when-failing-add-fsid.patch
1 From e32773357d5cc271b1d23550b3ed026eb5c2a468 Mon Sep 17 00:00:00 2001
2 From: "Tobin C. Harding" <tobin@kernel.org>
3 Date: Mon, 13 May 2019 13:39:12 +1000
4 Subject: btrfs: sysfs: don't leak memory when failing add fsid
5
6 From: Tobin C. Harding <tobin@kernel.org>
7
8 commit e32773357d5cc271b1d23550b3ed026eb5c2a468 upstream.
9
10 A failed call to kobject_init_and_add() must be followed by a call to
11 kobject_put(). Currently in the error path when adding fs_devices we
12 are missing this call. This could be fixed by calling
13 btrfs_sysfs_remove_fsid() if btrfs_sysfs_add_fsid() returns an error or
14 by adding a call to kobject_put() directly in btrfs_sysfs_add_fsid().
15 Here we choose the second option because it prevents the slightly
16 unusual error path handling requirements of kobject from leaking out
17 into btrfs functions.
18
19 Add a call to kobject_put() in the error path of kobject_add_and_init().
20 This causes the release method to be called if kobject_init_and_add()
21 fails. open_tree() is the function that calls btrfs_sysfs_add_fsid()
22 and the error code in this function is already written with the
23 assumption that the release method is called during the error path of
24 open_tree() (as seen by the call to btrfs_sysfs_remove_fsid() under the
25 fail_fsdev_sysfs label).
26
27 Cc: stable@vger.kernel.org # v4.4+
28 Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
29 Signed-off-by: Tobin C. Harding <tobin@kernel.org>
30 Reviewed-by: David Sterba <dsterba@suse.com>
31 Signed-off-by: David Sterba <dsterba@suse.com>
32 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
33
34 ---
35 fs/btrfs/sysfs.c | 7 ++++++-
36 1 file changed, 6 insertions(+), 1 deletion(-)
37
38 --- a/fs/btrfs/sysfs.c
39 +++ b/fs/btrfs/sysfs.c
40 @@ -733,7 +733,12 @@ int btrfs_sysfs_add_fsid(struct btrfs_fs
41 fs_devs->fsid_kobj.kset = btrfs_kset;
42 error = kobject_init_and_add(&fs_devs->fsid_kobj,
43 &btrfs_ktype, parent, "%pU", fs_devs->fsid);
44 - return error;
45 + if (error) {
46 + kobject_put(&fs_devs->fsid_kobj);
47 + return error;
48 + }
49 +
50 + return 0;
51 }
52
53 int btrfs_sysfs_add_mounted(struct btrfs_fs_info *fs_info)