PCI: endpoint: Fix NULL pointer dereference for ->get_features()
Subsystems (2)
A message that is not in the archive (sent off-list or not yet received): CGME20201218154704epcas5p1446559adbd4a5b267a4c940b5f744970@epcas5p1.samsung.com
PATCH v2 1/1 PCI: endpoint: Fix NULL pointer dereference for ->get_features()
get_features ops of pci_epc_ops may return NULL, causing NULL pointer dereference in pci_epf_test_bind function. Let us add a check for pci_epc_feature pointer in pci_epf_test_bind before we access it to avoid any such NULL pointer dereference and return -ENOTSUPP in case pci_epc_feature is not found.
---
v2:
rebase on v1
v1: https://lore.kernel.org/patchwork/patch/1208269/
drivers/pci/endpoint/functions/pci-epf-test.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/pci/endpoint/functions/pci-epf-test.c +8 -5
@@ -835,13 +835,16 @@ static int pci_epf_test_bind(struct pci_epf *epf)return -EINVAL ; epc_features =pci_epc_get_features (epc, epf->func_no); -if (epc_features) { - linkup_notifier = epc_features->linkup_notifier; - core_init_notifier = epc_features->core_init_notifier; - test_reg_bar =pci_epc_get_first_free_bar (epc_features); -pci_epf_configure_bar (epf, epc_features); +if (!epc_features) { +dev_err (&epf->dev,"epc_features not implemented\n" ); +return -EOPNOTSUPP ; } + linkup_notifier = epc_features->linkup_notifier; + core_init_notifier = epc_features->core_init_notifier; + test_reg_bar =pci_epc_get_first_free_bar (epc_features); +pci_epf_configure_bar (epf, epc_features); + epf_test->test_reg_bar = test_reg_bar; epf_test->epc_features = epc_features;
Signature · 1 line
2.7.4
Quoted 5 lines · Shradha Todi
get_featuresops ofpci_epc_opsmay return NULL, causing NULL pointer dereference inpci_epf_test_bindfunction. Let us add a check forpci_epc_featurepointer inpci_epf_test_bindbefore we access it to avoid any such NULL pointer dereference and return-ENOTSUPPin casepci_epc_featureis not found.
Can you add a Fixes: tag to identify where this broke to help people decide where to backport the fix?
Quoted 40 lines
Reviewed-by Pankaj Dubey <[email protected]>Signed-off-by Sriram Dash <[email protected]>Signed-off-by Shradha Todi <[email protected]>---
v2:
rebase on v1
v1: https://lore.kernel.org/patchwork/patch/1208269/drivers/pci/endpoint/functions/pci-epf-test.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)drivers/pci/endpoint/functions/pci-epf-test.c +8
-5@@ -835,13 +835,16 @@ static int pci_epf_test_bind(struct pci_epf *epf)return -EINVAL ; epc_features =pci_epc_get_features (epc, epf->func_no); -if (epc_features) { - linkup_notifier = epc_features->linkup_notifier; - core_init_notifier = epc_features->core_init_notifier; - test_reg_bar =pci_epc_get_first_free_bar (epc_features); -pci_epf_configure_bar (epf, epc_features); +if (!epc_features) { +dev_err (&epf->dev,"epc_features not implemented\n" ); +return -EOPNOTSUPP ; } + linkup_notifier = epc_features->linkup_notifier; + core_init_notifier = epc_features->core_init_notifier; + test_reg_bar =pci_epc_get_first_free_bar (epc_features); +pci_epf_configure_bar (epf, epc_features); + epf_test->test_reg_bar = test_reg_bar; epf_test->epc_features = epc_features;Signature · 1 line
2.7.4
Quoted 4 lines
From: Bjorn Helgaas <[email protected]>
Subject: Re: [PATCH v2] PCI: endpoint: Fix NULL pointer dereference for -Quoted 1 line
get_features()
Quoted 8 lines
Quoted 5 lines · Shradha Todi
get_featuresops ofpci_epc_opsmay return NULL, causing NULL pointer dereference inpci_epf_test_bindfunction. Let us add a check forpci_epc_featurepointer inpci_epf_test_bindbefore we access it to avoid any such NULL pointer dereference and return-ENOTSUPPin casepci_epc_featureis not found.Can you add a Fixes: tag to identify where this broke to help people
decide
Quoted 2 lines
where to backport the fix?
Thanks for the review. Sure we will add the Fixes tag and respin this patch.
Quoted 45 lines
Quoted 9 lines
Reviewed-by Pankaj Dubey <[email protected]>Signed-off-by Sriram Dash <[email protected]>Signed-off-by Shradha Todi <[email protected]>---
v2:
rebase on v1
v1:
https://protect2.fireeye.com/v1/url?k=6193fa90-3e08c3dd-619271df-0cc47
aa8f5ba-a79111ee2c1d1660&q=1&e=a9ee1ef7-2713-4099-8d06-738532d78b26&u=
Quoted 35 lines
https%3A%2F%2Flore.kernel.org%2Fpatchwork%2Fpatch%2F1208269%2F
drivers/pci/endpoint/functions/pci-epf-test.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)drivers/pci/endpoint/functions/pci-epf-test.c +8
-6@@ -835,13 +835,16 @@ static int pci_epf_test_bind(struct pci_epf *epf)return -EINVAL ; epc_features =pci_epc_get_features (epc, epf->func_no); -if (epc_features) { - linkup_notifier = epc_features->linkup_notifier; - core_init_notifier = epc_features->core_init_notifier; - test_reg_bar =pci_epc_get_first_free_bar (epc_features); -pci_epf_configure_bar (epf, epc_features); +if (!epc_features) { +dev_err (&epf->dev,"epc_features not implemented\n" ); +return -EOPNOTSUPP ; } + linkup_notifier = epc_features->linkup_notifier; + core_init_notifier = epc_features->core_init_notifier; + test_reg_bar =pci_epc_get_first_free_bar (epc_features); +pci_epf_configure_bar (epf, epc_features); + epf_test->test_reg_bar = test_reg_bar; epf_test->epc_features = epc_features; --2.7.4