crypto: qat - add missing INIT_LIST_HEAD in probe()
Subsystems (2)
Giovanni Cabiddu
maintainerPATCH 1/1 crypto: qat - add missing INIT_LIST_HEAD in probe()
From: Shwethax Shetty <[email protected]>
If a list is not properly initialized before use, traversing it can lead to undefined behavior, including NULL pointer dereferences. In this case, the adf_ctl_stop_devices() function attempts to iterate over a list to retrieve accel_dev, but if the list hasn't been initialized, it may result in a kernel panic.
This issue was observed during testing, with the following stack trace:
BUG: kernel NULL pointer dereference, address: 0000000000000214
RIP: 0010:adf_ctl_stop_devices+0x65/0x240 [intel_qat]
4xxx 0000:86:00.0: pci_iomap_range() calls ioremap_driver_hardened()
? __die+0x24/0x70
? page_fault_oops+0x82/0x160
? do_user_addr_fault+0x65/0x690
? exc_page_fault+0x78/0x170
4xxx 0000:86:00.0: pci_iomap_range() calls ioremap_driver_hardened()
? asm_exc_page_fault+0x26/0x30
? adf_ctl_stop_devices+0x65/0x240 [intel_qat]
4xxx 0000:86:00.0: pci_iomap_range() calls ioremap_driver_hardened()
? adf_ctl_stop_devices+0x65/0x240 [intel_qat]
adf_ctl_ioctl+0x6a9/0x790 [intel_qat]To prevent this, add the missing INIT_LIST_HEAD() in adf_probe() to ensure the list is correctly initialized before use.
--- drivers/crypto/intel/qat/qat_420xx/adf_drv.c | 1 + drivers/crypto/intel/qat/qat_4xxx/adf_drv.c | 1 + drivers/crypto/intel/qat/qat_c3xxx/adf_drv.c | 1 + drivers/crypto/intel/qat/qat_c3xxxvf/adf_drv.c | 1 + drivers/crypto/intel/qat/qat_c62x/adf_drv.c | 1 + drivers/crypto/intel/qat/qat_c62xvf/adf_drv.c | 1 + drivers/crypto/intel/qat/qat_dh895xcc/adf_drv.c | 1 + drivers/crypto/intel/qat/qat_dh895xccvf/adf_drv.c | 1 + 8 files changed, 8 insertions(+)
drivers/crypto/intel/qat/qat_420xx/adf_drv.c +1 -0
@@ -55,6 +55,7 @@ static int adf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)return -ENOMEM ;INIT_LIST_HEAD (&accel_dev->crypto_list); +INIT_LIST_HEAD (&accel_dev->list); accel_pci_dev = &accel_dev->accel_pci_dev; accel_pci_dev->pci_dev = pdev;
drivers/crypto/intel/qat/qat_4xxx/adf_drv.c +1 -0
@@ -57,6 +57,7 @@ static int adf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)return -ENOMEM ;INIT_LIST_HEAD (&accel_dev->crypto_list); +INIT_LIST_HEAD (&accel_dev->list); accel_pci_dev = &accel_dev->accel_pci_dev; accel_pci_dev->pci_dev = pdev;
drivers/crypto/intel/qat/qat_c3xxx/adf_drv.c +1 -0
@@ -84,6 +84,7 @@ static int adf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)return -ENOMEM ;INIT_LIST_HEAD (&accel_dev->crypto_list); +INIT_LIST_HEAD (&accel_dev->list); accel_pci_dev = &accel_dev->accel_pci_dev; accel_pci_dev->pci_dev = pdev;
drivers/crypto/intel/qat/qat_c3xxxvf/adf_drv.c +1 -0
@@ -98,6 +98,7 @@ static int adf_probe(struct pci_dev *pdev, const struct pci_device_id *ent) pf =adf_devmgr_pci_to_accel_dev (pdev->physfn); accel_pci_dev = &accel_dev->accel_pci_dev; accel_pci_dev->pci_dev = pdev; +INIT_LIST_HEAD (&accel_dev->list);/* Add accel device to accel table */ if (adf_devmgr_add_dev (accel_dev, pf)) {
drivers/crypto/intel/qat/qat_c62x/adf_drv.c +1 -0
@@ -86,6 +86,7 @@ static int adf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)INIT_LIST_HEAD (&accel_dev->crypto_list); accel_pci_dev = &accel_dev->accel_pci_dev; accel_pci_dev->pci_dev = pdev; +INIT_LIST_HEAD (&accel_dev->list);/* Add accel device to accel table. * This should be called before adf_cleanup_accel is called */
drivers/crypto/intel/qat/qat_c62xvf/adf_drv.c +1 -0
@@ -98,6 +98,7 @@ static int adf_probe(struct pci_dev *pdev, const struct pci_device_id *ent) pf =adf_devmgr_pci_to_accel_dev (pdev->physfn); accel_pci_dev = &accel_dev->accel_pci_dev; accel_pci_dev->pci_dev = pdev; +INIT_LIST_HEAD (&accel_dev->list);/* Add accel device to accel table */ if (adf_devmgr_add_dev (accel_dev, pf)) {
drivers/crypto/intel/qat/qat_dh895xcc/adf_drv.c +1 -0
@@ -86,6 +86,7 @@ static int adf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)INIT_LIST_HEAD (&accel_dev->crypto_list); accel_pci_dev = &accel_dev->accel_pci_dev; accel_pci_dev->pci_dev = pdev; +INIT_LIST_HEAD (&accel_dev->list);/* Add accel device to accel table. * This should be called before adf_cleanup_accel is called */
drivers/crypto/intel/qat/qat_dh895xccvf/adf_drv.c +1 -0
@@ -98,6 +98,7 @@ static int adf_probe(struct pci_dev *pdev, const struct pci_device_id *ent) pf =adf_devmgr_pci_to_accel_dev (pdev->physfn); accel_pci_dev = &accel_dev->accel_pci_dev; accel_pci_dev->pci_dev = pdev; +INIT_LIST_HEAD (&accel_dev->list);/* Add accel device to accel table */ if (adf_devmgr_add_dev (accel_dev, pf)) {
base-commit: 60a2ff0c7e1bc0615558a4f4c65f031bcd00200d
Signature · 1 line
2.50.0
Giovanni Cabiddu
maintainerQuoted 39 lines · Giovanni Cabiddu
From: Shwethax Shetty <[email protected]>
If a list is not properly initialized before use, traversing it can lead to undefined behavior, including NULL pointer dereferences. In this case, the
adf_ctl_stop_devices()function attempts to iterate over a list to retrieveaccel_dev, but if the list hasn't been initialized, it may result in a kernel panic.This issue was observed during testing, with the following stack trace:
BUG: kernel NULL pointer dereference, address: 0000000000000214 RIP: 0010:adf_ctl_stop_devices+0x65/0x240 [intel_qat] 4xxx 0000:86:00.0: pci_iomap_range() calls ioremap_driver_hardened() ? __die+0x24/0x70 ? page_fault_oops+0x82/0x160 ? do_user_addr_fault+0x65/0x690 ? exc_page_fault+0x78/0x170 4xxx 0000:86:00.0: pci_iomap_range() calls ioremap_driver_hardened() ? asm_exc_page_fault+0x26/0x30 ? adf_ctl_stop_devices+0x65/0x240 [intel_qat] 4xxx 0000:86:00.0: pci_iomap_range() calls ioremap_driver_hardened() ? adf_ctl_stop_devices+0x65/0x240 [intel_qat] adf_ctl_ioctl+0x6a9/0x790 [intel_qat]To prevent this, add the missing
INIT_LIST_HEAD()inadf_probe()to ensure the list is correctly initialized before use.Fixes 7afa232e76ce ("crypto: qat - Intel(R) QAT DH895xcc accelerator")Fixes dd0f368398ea ("crypto: qat - Add qat dh895xcc VF driver")Fixes a6dabee6c8ba ("crypto: qat - add support for c62x accel type")Fixes 3771df3cff75 ("crypto: qat - add support for c62xvf accel type")Fixes 890c55f4dc0e ("crypto: qat - add support for c3xxx accel type")Fixes 8b206f2d666f ("crypto: qat - add support for c3xxxvf accel type")Fixes 8c8268166e83 ("crypto: qat - add qat_4xxx driver")Fixes fcf60f4bcf54 ("crypto: qat - add support for 420xx devices")Signed-off-by Shwethax Shetty <[email protected]>Reviewed-by Srikanth Thokala <[email protected]>Reviewed-by Ahsan Atta <[email protected]>Signed-off-by Giovanni Cabiddu <[email protected]>
Quoted 1 line
---
Herbert, please discard this patch.
accel_dev->list refers to an element within the list and the fields next and prev are set when the element is added. This patch is unnecessary.
Thanks,
Signature · 1 line
Giovanni