]> git.baikalelectronics.ru Git - kernel.git/commit
ata: ahci_platform: fix null-ptr-deref in ahci_platform_enable_regulators()
authorWang Hai <wanghai38@huawei.com>
Wed, 13 Oct 2021 06:16:31 +0000 (14:16 +0800)
committerDamien Le Moal <damien.lemoal@wdc.com>
Thu, 14 Oct 2021 03:22:47 +0000 (12:22 +0900)
commit9379d03b82ec28f5fa3a50147239896c22bfa65e
treee51c86b3ab4ae1e796b7f89d5569d4f3cff4e3fe
parenteb42463599bbfeaa4a49efb1e609d80aad8c877b
ata: ahci_platform: fix null-ptr-deref in ahci_platform_enable_regulators()

I got a null-ptr-deref report:

KASAN: null-ptr-deref in range [0x0000000000000090-0x0000000000000097]
...
RIP: 0010:regulator_enable+0x84/0x260
...
Call Trace:
 ahci_platform_enable_regulators+0xae/0x320
 ahci_platform_enable_resources+0x1a/0x120
 ahci_probe+0x4f/0x1b9
 platform_probe+0x10b/0x280
...
 entry_SYSCALL_64_after_hwframe+0x44/0xae

If devm_regulator_get() in ahci_platform_get_resources() fails,
hpriv->phy_regulator will point to NULL, when enabling or disabling it,
null-ptr-deref will occur.

ahci_probe()
ahci_platform_get_resources()
devm_regulator_get(, "phy") // failed, let phy_regulator = NULL
ahci_platform_enable_resources()
ahci_platform_enable_regulators()
regulator_enable(hpriv->phy_regulator) // null-ptr-deref

commit 0de2194210f3 ("ata: libahci_platform: Fix regulator_get_optional()
misuse") replaces devm_regulator_get_optional() with devm_regulator_get(),
but PHY regulator omits to delete "hpriv->phy_regulator = NULL;" like AHCI.
Delete it like AHCI regulator to fix this bug.

Fixes: commit 0de2194210f3 ("ata: libahci_platform: Fix regulator_get_optional() misuse")
Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Wang Hai <wanghai38@huawei.com>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
drivers/ata/libahci_platform.c