Skip to content

Commit 3613dbe

Browse files
Yang YingliangDamien Le Moal
authored andcommitted
ata: libata-transport: fix error handling in ata_tport_add()
In ata_tport_add(), the return value of transport_add_device() is not checked. As a result, it causes null-ptr-deref while removing the module, because transport_remove_device() is called to remove the device that was not added. Unable to handle kernel NULL pointer dereference at virtual address 00000000000000d0 CPU: 12 PID: 13605 Comm: rmmod Kdump: loaded Tainted: G W 6.1.0-rc3+ #8 pstate: 60400009 (nZCv daif +PAN -UAO -TCO -DIT -SSBS BTYPE=--) pc : device_del+0x48/0x39c lr : device_del+0x44/0x39c Call trace: device_del+0x48/0x39c attribute_container_class_device_del+0x28/0x40 transport_remove_classdev+0x60/0x7c attribute_container_device_trigger+0x118/0x120 transport_remove_device+0x20/0x30 ata_tport_delete+0x34/0x60 [libata] ata_port_detach+0x148/0x1b0 [libata] ata_pci_remove_one+0x50/0x80 [libata] ahci_remove_one+0x4c/0x8c [ahci] Fix this by checking and handling return value of transport_add_device() in ata_tport_add(). Fixes: d902747 ("[libata] Add ATA transport class") Signed-off-by: Yang Yingliang <[email protected]> Signed-off-by: Damien Le Moal <[email protected]>
1 parent 8c76310 commit 3613dbe

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

drivers/ata/libata-transport.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,9 @@ int ata_tport_add(struct device *parent,
301301
pm_runtime_enable(dev);
302302
pm_runtime_forbid(dev);
303303

304-
transport_add_device(dev);
304+
error = transport_add_device(dev);
305+
if (error)
306+
goto tport_transport_add_err;
305307
transport_configure_device(dev);
306308

307309
error = ata_tlink_add(&ap->link);
@@ -312,6 +314,7 @@ int ata_tport_add(struct device *parent,
312314

313315
tport_link_err:
314316
transport_remove_device(dev);
317+
tport_transport_add_err:
315318
device_del(dev);
316319

317320
tport_err:

0 commit comments

Comments
 (0)