]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.11.2/ib-core-fix-sysfs-registration-error-flow.patch
4.9-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 4.11.2 / ib-core-fix-sysfs-registration-error-flow.patch
1 From b312be3d87e4c80872cbea869e569175c5eb0f9a Mon Sep 17 00:00:00 2001
2 From: Jack Morgenstein <jackm@dev.mellanox.co.il>
3 Date: Sun, 19 Mar 2017 10:55:57 +0200
4 Subject: IB/core: Fix sysfs registration error flow
5
6 From: Jack Morgenstein <jackm@dev.mellanox.co.il>
7
8 commit b312be3d87e4c80872cbea869e569175c5eb0f9a upstream.
9
10 The kernel commit cited below restructured ib device management
11 so that the device kobject is initialized in ib_alloc_device.
12
13 As part of the restructuring, the kobject is now initialized in
14 procedure ib_alloc_device, and is later added to the device hierarchy
15 in the ib_register_device call stack, in procedure
16 ib_device_register_sysfs (which calls device_add).
17
18 However, in the ib_device_register_sysfs error flow, if an error
19 occurs following the call to device_add, the cleanup procedure
20 device_unregister is called. This call results in the device object
21 being deleted -- which results in various use-after-free crashes.
22
23 The correct cleanup call is device_del -- which undoes device_add
24 without deleting the device object.
25
26 The device object will then (correctly) be deleted in the
27 ib_register_device caller's error cleanup flow, when the caller invokes
28 ib_dealloc_device.
29
30 Fixes: 55aeed06544f6 ("IB/core: Make ib_alloc_device init the kobject")
31 Signed-off-by: Jack Morgenstein <jackm@dev.mellanox.co.il>
32 Signed-off-by: Leon Romanovsky <leon@kernel.org>
33 Signed-off-by: Doug Ledford <dledford@redhat.com>
34 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
35
36 ---
37 drivers/infiniband/core/sysfs.c | 2 +-
38 1 file changed, 1 insertion(+), 1 deletion(-)
39
40 --- a/drivers/infiniband/core/sysfs.c
41 +++ b/drivers/infiniband/core/sysfs.c
42 @@ -1301,7 +1301,7 @@ err_put:
43 free_port_list_attributes(device);
44
45 err_unregister:
46 - device_unregister(class_dev);
47 + device_del(class_dev);
48
49 err:
50 return ret;