All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] media: cobalt: fix null-ptr-deref when there is no PCI bridge
@ 2021-04-24  0:52 Tong Zhang
  2021-05-05  9:18 ` Hans Verkuil
  0 siblings, 1 reply; 4+ messages in thread
From: Tong Zhang @ 2021-04-24  0:52 UTC (permalink / raw)
  To: Hans Verkuil, Mauro Carvalho Chehab, linux-media, linux-kernel; +Cc: Tong Zhang

the PCI bridge might be NULL, so we'd better check before use it

[    1.870569] RIP: 0010:pcie_bus_link_get_lanes.isra.0+0x26/0x59 [cobalt]
[    1.875880] Call Trace:
[    1.876013]  cobalt_probe.cold+0x1be/0xc11 [cobalt]
[    1.876683]  pci_device_probe+0x10f/0x1c0

Signed-off-by: Tong Zhang <ztong0001@gmail.com>
---
 drivers/media/pci/cobalt/cobalt-driver.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/media/pci/cobalt/cobalt-driver.c b/drivers/media/pci/cobalt/cobalt-driver.c
index 0695078ef812..5687ed4869ac 100644
--- a/drivers/media/pci/cobalt/cobalt-driver.c
+++ b/drivers/media/pci/cobalt/cobalt-driver.c
@@ -189,6 +189,8 @@ void cobalt_pcie_status_show(struct cobalt *cobalt)
 	u32 capa;
 	u16 stat, ctrl;
 
+	if (!pci_bus_dev)
+		return;
 	if (!pci_is_pcie(pci_dev) || !pci_is_pcie(pci_bus_dev))
 		return;
 
@@ -247,6 +249,8 @@ static unsigned pcie_bus_link_get_lanes(struct cobalt *cobalt)
 	struct pci_dev *pci_dev = cobalt->pci_dev->bus->self;
 	u32 link;
 
+	if (!pci_dev)
+		return 0;
 	if (!pci_is_pcie(pci_dev))
 		return 0;
 	pcie_capability_read_dword(pci_dev, PCI_EXP_LNKCAP, &link);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] media: cobalt: fix null-ptr-deref when there is no PCI bridge
  2021-04-24  0:52 [PATCH] media: cobalt: fix null-ptr-deref when there is no PCI bridge Tong Zhang
@ 2021-05-05  9:18 ` Hans Verkuil
  2021-05-10 22:32   ` Tong Zhang
  0 siblings, 1 reply; 4+ messages in thread
From: Hans Verkuil @ 2021-05-05  9:18 UTC (permalink / raw)
  To: Tong Zhang, Mauro Carvalho Chehab, linux-media, linux-kernel

On 24/04/2021 02:52, Tong Zhang wrote:
> the PCI bridge might be NULL, so we'd better check before use it
> 
> [    1.870569] RIP: 0010:pcie_bus_link_get_lanes.isra.0+0x26/0x59 [cobalt]
> [    1.875880] Call Trace:
> [    1.876013]  cobalt_probe.cold+0x1be/0xc11 [cobalt]
> [    1.876683]  pci_device_probe+0x10f/0x1c0

How did you test this? With some virtualized PCI bus or something? I'm not sure
how this can happen.

Regards,

	Hans

> 
> Signed-off-by: Tong Zhang <ztong0001@gmail.com>
> ---
>  drivers/media/pci/cobalt/cobalt-driver.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/media/pci/cobalt/cobalt-driver.c b/drivers/media/pci/cobalt/cobalt-driver.c
> index 0695078ef812..5687ed4869ac 100644
> --- a/drivers/media/pci/cobalt/cobalt-driver.c
> +++ b/drivers/media/pci/cobalt/cobalt-driver.c
> @@ -189,6 +189,8 @@ void cobalt_pcie_status_show(struct cobalt *cobalt)
>  	u32 capa;
>  	u16 stat, ctrl;
>  
> +	if (!pci_bus_dev)
> +		return;
>  	if (!pci_is_pcie(pci_dev) || !pci_is_pcie(pci_bus_dev))
>  		return;
>  
> @@ -247,6 +249,8 @@ static unsigned pcie_bus_link_get_lanes(struct cobalt *cobalt)
>  	struct pci_dev *pci_dev = cobalt->pci_dev->bus->self;
>  	u32 link;
>  
> +	if (!pci_dev)
> +		return 0;
>  	if (!pci_is_pcie(pci_dev))
>  		return 0;
>  	pcie_capability_read_dword(pci_dev, PCI_EXP_LNKCAP, &link);
> 


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] media: cobalt: fix null-ptr-deref when there is no PCI bridge
  2021-05-05  9:18 ` Hans Verkuil
@ 2021-05-10 22:32   ` Tong Zhang
  2021-05-26 13:07     ` Hans Verkuil
  0 siblings, 1 reply; 4+ messages in thread
From: Tong Zhang @ 2021-05-10 22:32 UTC (permalink / raw)
  To: Hans Verkuil; +Cc: Mauro Carvalho Chehab, linux-media, open list

On Wed, May 5, 2021 at 2:18 AM Hans Verkuil <hverkuil-cisco@xs4all.nl> wrote:
>
> On 24/04/2021 02:52, Tong Zhang wrote:
> > the PCI bridge might be NULL, so we'd better check before use it
> >
> > [    1.870569] RIP: 0010:pcie_bus_link_get_lanes.isra.0+0x26/0x59 [cobalt]
> > [    1.875880] Call Trace:
> > [    1.876013]  cobalt_probe.cold+0x1be/0xc11 [cobalt]
> > [    1.876683]  pci_device_probe+0x10f/0x1c0
>
> How did you test this? With some virtualized PCI bus or something? I'm not sure
> how this can happen.
>
Hello Hans,
IMHO bus->self is pci bridge device and we can have a system
configuration that does not have such a bridge,
in this case, bus->self is NULL.
- Tong
> Regards,
>
>         Hans
>
> >
> > Signed-off-by: Tong Zhang <ztong0001@gmail.com>
> > ---
> >  drivers/media/pci/cobalt/cobalt-driver.c | 4 ++++
> >  1 file changed, 4 insertions(+)
> >
> > diff --git a/drivers/media/pci/cobalt/cobalt-driver.c b/drivers/media/pci/cobalt/cobalt-driver.c
> > index 0695078ef812..5687ed4869ac 100644
> > --- a/drivers/media/pci/cobalt/cobalt-driver.c
> > +++ b/drivers/media/pci/cobalt/cobalt-driver.c
> > @@ -189,6 +189,8 @@ void cobalt_pcie_status_show(struct cobalt *cobalt)
> >       u32 capa;
> >       u16 stat, ctrl;
> >
> > +     if (!pci_bus_dev)
> > +             return;
> >       if (!pci_is_pcie(pci_dev) || !pci_is_pcie(pci_bus_dev))
> >               return;
> >
> > @@ -247,6 +249,8 @@ static unsigned pcie_bus_link_get_lanes(struct cobalt *cobalt)
> >       struct pci_dev *pci_dev = cobalt->pci_dev->bus->self;
> >       u32 link;
> >
> > +     if (!pci_dev)
> > +             return 0;
> >       if (!pci_is_pcie(pci_dev))
> >               return 0;
> >       pcie_capability_read_dword(pci_dev, PCI_EXP_LNKCAP, &link);
> >
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] media: cobalt: fix null-ptr-deref when there is no PCI bridge
  2021-05-10 22:32   ` Tong Zhang
@ 2021-05-26 13:07     ` Hans Verkuil
  0 siblings, 0 replies; 4+ messages in thread
From: Hans Verkuil @ 2021-05-26 13:07 UTC (permalink / raw)
  To: Tong Zhang; +Cc: Mauro Carvalho Chehab, linux-media, open list

On 11/05/2021 00:32, Tong Zhang wrote:
> On Wed, May 5, 2021 at 2:18 AM Hans Verkuil <hverkuil-cisco@xs4all.nl> wrote:
>>
>> On 24/04/2021 02:52, Tong Zhang wrote:
>>> the PCI bridge might be NULL, so we'd better check before use it
>>>
>>> [    1.870569] RIP: 0010:pcie_bus_link_get_lanes.isra.0+0x26/0x59 [cobalt]
>>> [    1.875880] Call Trace:
>>> [    1.876013]  cobalt_probe.cold+0x1be/0xc11 [cobalt]
>>> [    1.876683]  pci_device_probe+0x10f/0x1c0
>>
>> How did you test this? With some virtualized PCI bus or something? I'm not sure
>> how this can happen.
>>
> Hello Hans,
> IMHO bus->self is pci bridge device and we can have a system
> configuration that does not have such a bridge,
> in this case, bus->self is NULL.

That does not answer my question :-)

You show a backtrace in the commit message, how did you get that?

Regards,

	Hans

> - Tong
>> Regards,
>>
>>         Hans
>>
>>>
>>> Signed-off-by: Tong Zhang <ztong0001@gmail.com>
>>> ---
>>>  drivers/media/pci/cobalt/cobalt-driver.c | 4 ++++
>>>  1 file changed, 4 insertions(+)
>>>
>>> diff --git a/drivers/media/pci/cobalt/cobalt-driver.c b/drivers/media/pci/cobalt/cobalt-driver.c
>>> index 0695078ef812..5687ed4869ac 100644
>>> --- a/drivers/media/pci/cobalt/cobalt-driver.c
>>> +++ b/drivers/media/pci/cobalt/cobalt-driver.c
>>> @@ -189,6 +189,8 @@ void cobalt_pcie_status_show(struct cobalt *cobalt)
>>>       u32 capa;
>>>       u16 stat, ctrl;
>>>
>>> +     if (!pci_bus_dev)
>>> +             return;
>>>       if (!pci_is_pcie(pci_dev) || !pci_is_pcie(pci_bus_dev))
>>>               return;
>>>
>>> @@ -247,6 +249,8 @@ static unsigned pcie_bus_link_get_lanes(struct cobalt *cobalt)
>>>       struct pci_dev *pci_dev = cobalt->pci_dev->bus->self;
>>>       u32 link;
>>>
>>> +     if (!pci_dev)
>>> +             return 0;
>>>       if (!pci_is_pcie(pci_dev))
>>>               return 0;
>>>       pcie_capability_read_dword(pci_dev, PCI_EXP_LNKCAP, &link);
>>>
>>


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-05-26 13:07 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-24  0:52 [PATCH] media: cobalt: fix null-ptr-deref when there is no PCI bridge Tong Zhang
2021-05-05  9:18 ` Hans Verkuil
2021-05-10 22:32   ` Tong Zhang
2021-05-26 13:07     ` Hans Verkuil

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.