* [PATCH v2] PCI: endpoint: Fix NULL pointer dereference for ->get_features() [not found] <CGME20201218154704epcas5p1446559adbd4a5b267a4c940b5f744970@epcas5p1.samsung.com> @ 2020-12-18 15:45 ` Shradha Todi 2020-12-23 20:34 ` Bjorn Helgaas 0 siblings, 1 reply; 3+ messages in thread From: Shradha Todi @ 2020-12-18 15:45 UTC (permalink / raw) To: linux-kernel, linux-pci Cc: kishon, lorenzo.pieralisi, bhelgaas, pankaj.dubey, Shradha Todi, Sriram Dash 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. Reviewed-by: Pankaj Dubey <pankaj.dubey@samsung.com> Signed-off-by: Sriram Dash <sriram.dash@samsung.com> Signed-off-by: Shradha Todi <shradha.t@samsung.com> --- 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(-) diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c index 66723d5..f1842e6 100644 --- a/drivers/pci/endpoint/functions/pci-epf-test.c +++ b/drivers/pci/endpoint/functions/pci-epf-test.c @@ -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 ^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] PCI: endpoint: Fix NULL pointer dereference for ->get_features() 2020-12-18 15:45 ` [PATCH v2] PCI: endpoint: Fix NULL pointer dereference for ->get_features() Shradha Todi @ 2020-12-23 20:34 ` Bjorn Helgaas 2020-12-24 5:50 ` Shradha Todi 0 siblings, 1 reply; 3+ messages in thread From: Bjorn Helgaas @ 2020-12-23 20:34 UTC (permalink / raw) To: Shradha Todi Cc: linux-kernel, linux-pci, kishon, lorenzo.pieralisi, bhelgaas, pankaj.dubey, Sriram Dash On Fri, Dec 18, 2020 at 09:15:16PM +0530, Shradha Todi wrote: > 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. Can you add a Fixes: tag to identify where this broke to help people decide where to backport the fix? > Reviewed-by: Pankaj Dubey <pankaj.dubey@samsung.com> > Signed-off-by: Sriram Dash <sriram.dash@samsung.com> > Signed-off-by: Shradha Todi <shradha.t@samsung.com> > --- > 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(-) > > diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c > index 66723d5..f1842e6 100644 > --- a/drivers/pci/endpoint/functions/pci-epf-test.c > +++ b/drivers/pci/endpoint/functions/pci-epf-test.c > @@ -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 > ^ permalink raw reply [flat|nested] 3+ messages in thread
* RE: [PATCH v2] PCI: endpoint: Fix NULL pointer dereference for ->get_features() 2020-12-23 20:34 ` Bjorn Helgaas @ 2020-12-24 5:50 ` Shradha Todi 0 siblings, 0 replies; 3+ messages in thread From: Shradha Todi @ 2020-12-24 5:50 UTC (permalink / raw) To: 'Bjorn Helgaas' Cc: linux-kernel, linux-pci, kishon, lorenzo.pieralisi, bhelgaas, pankaj.dubey, 'Sriram Dash' > From: Bjorn Helgaas <helgaas@kernel.org> > Subject: Re: [PATCH v2] PCI: endpoint: Fix NULL pointer dereference for - > >get_features() > > On Fri, Dec 18, 2020 at 09:15:16PM +0530, Shradha Todi wrote: > > 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. > > Can you add a Fixes: tag to identify where this broke to help people decide > where to backport the fix? > Thanks for the review. Sure we will add the Fixes tag and respin this patch. > > Reviewed-by: Pankaj Dubey <pankaj.dubey@samsung.com> > > Signed-off-by: Sriram Dash <sriram.dash@samsung.com> > > Signed-off-by: Shradha Todi <shradha.t@samsung.com> > > --- > > 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= > > 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(-) > > > > diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c > > b/drivers/pci/endpoint/functions/pci-epf-test.c > > index 66723d5..f1842e6 100644 > > --- a/drivers/pci/endpoint/functions/pci-epf-test.c > > +++ b/drivers/pci/endpoint/functions/pci-epf-test.c > > @@ -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 > > ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-12-24 6:04 UTC | newest] Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- [not found] <CGME20201218154704epcas5p1446559adbd4a5b267a4c940b5f744970@epcas5p1.samsung.com> 2020-12-18 15:45 ` [PATCH v2] PCI: endpoint: Fix NULL pointer dereference for ->get_features() Shradha Todi 2020-12-23 20:34 ` Bjorn Helgaas 2020-12-24 5:50 ` Shradha Todi
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).