2022-07-16 08:18:44

by Zheyu Ma

[permalink] [raw]
Subject: [PATCH] drm/bridge: megachips: Fix a null pointer dereference bug

When removing the module we will get the following warning:

[ 31.911505] i2c-core: driver [stdp2690-ge-b850v3-fw] unregistered
[ 31.912484] general protection fault, probably for non-canonical address 0xdffffc0000000001: 0000 [#1] PREEMPT SMP KASAN PTI
[ 31.913338] KASAN: null-ptr-deref in range [0x0000000000000008-0x000000000000000f]
[ 31.915280] RIP: 0010:drm_bridge_remove+0x97/0x130
[ 31.921825] Call Trace:
[ 31.922533] stdp4028_ge_b850v3_fw_remove+0x34/0x60 [megachips_stdpxxxx_ge_b850v3_fw]
[ 31.923139] i2c_device_remove+0x181/0x1f0

The two bridges (stdp2690, stdp4028) do not probe at the same time, so
the driver does not call ge_b850v3_resgiter() when probing, causing the
driver to try to remove the object that has not been initialized.

Fix this by checking whether both the bridges are probed.

Signed-off-by: Zheyu Ma <[email protected]>
---
drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c b/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c
index cce98bf2a4e7..c68a4cdf4625 100644
--- a/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c
+++ b/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c
@@ -296,7 +296,9 @@ static void ge_b850v3_lvds_remove(void)
* This check is to avoid both the drivers
* removing the bridge in their remove() function
*/
- if (!ge_b850v3_lvds_ptr)
+ if (!ge_b850v3_lvds_ptr ||
+ !ge_b850v3_lvds_ptr->stdp2690_i2c ||
+ !ge_b850v3_lvds_ptr->stdp4028_i2c)
goto out;

drm_bridge_remove(&ge_b850v3_lvds_ptr->bridge);
--
2.25.1


2022-07-19 08:57:25

by Martyn Welch

[permalink] [raw]
Subject: Re: [PATCH] drm/bridge: megachips: Fix a null pointer dereference bug

On Sat, 2022-07-16 at 16:13 +0800, Zheyu Ma wrote:
> When removing the module we will get the following warning:
>
> [   31.911505] i2c-core: driver [stdp2690-ge-b850v3-fw] unregistered
> [   31.912484] general protection fault, probably for non-canonical
> address 0xdffffc0000000001: 0000 [#1] PREEMPT SMP KASAN PTI
> [   31.913338] KASAN: null-ptr-deref in range [0x0000000000000008-
> 0x000000000000000f]
> [   31.915280] RIP: 0010:drm_bridge_remove+0x97/0x130
> [   31.921825] Call Trace:
> [   31.922533]  stdp4028_ge_b850v3_fw_remove+0x34/0x60
> [megachips_stdpxxxx_ge_b850v3_fw]
> [   31.923139]  i2c_device_remove+0x181/0x1f0
>
> The two bridges (stdp2690, stdp4028) do not probe at the same time,
> so
> the driver does not call ge_b850v3_resgiter() when probing, causing
> the
> driver to try to remove the object that has not been initialized.
>
> Fix this by checking whether both the bridges are probed.
>
> Signed-off-by: Zheyu Ma <[email protected]>

Good catch!

Acked-by: Martyn Welch <[email protected]>

Would be worth adding:

Fixes: 11632d4aa2b3 ("drm/bridge: megachips: Ensure both bridges are
probed before registration")

> ---
>  drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c
> b/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c
> index cce98bf2a4e7..c68a4cdf4625 100644
> --- a/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c
> +++ b/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c
> @@ -296,7 +296,9 @@ static void ge_b850v3_lvds_remove(void)
>          * This check is to avoid both the drivers
>          * removing the bridge in their remove() function
>          */
> -       if (!ge_b850v3_lvds_ptr)
> +       if (!ge_b850v3_lvds_ptr ||
> +               !ge_b850v3_lvds_ptr->stdp2690_i2c ||
> +               !ge_b850v3_lvds_ptr->stdp4028_i2c)
>                 goto out;
>  
>         drm_bridge_remove(&ge_b850v3_lvds_ptr->bridge);

2022-08-02 15:30:14

by Ian Ray

[permalink] [raw]
Subject: Re: [PATCH] drm/bridge: megachips: Fix a null pointer dereference bug

On Tue, Jul 19, 2022 at 09:38:16AM +0100, Martyn Welch wrote:
> On Sat, 2022-07-16 at 16:13 +0800, Zheyu Ma wrote:
> > When removing the module we will get the following warning:
> >
> > [?? 31.911505] i2c-core: driver [stdp2690-ge-b850v3-fw] unregistered
> > [?? 31.912484] general protection fault, probably for non-canonical
> > address 0xdffffc0000000001: 0000 [#1] PREEMPT SMP KASAN PTI
> > [?? 31.913338] KASAN: null-ptr-deref in range [0x0000000000000008-
> > 0x000000000000000f]
> > [?? 31.915280] RIP: 0010:drm_bridge_remove+0x97/0x130
> > [?? 31.921825] Call Trace:
> > [?? 31.922533]? stdp4028_ge_b850v3_fw_remove+0x34/0x60
> > [megachips_stdpxxxx_ge_b850v3_fw]
> > [?? 31.923139]? i2c_device_remove+0x181/0x1f0
> >
> > The two bridges (stdp2690, stdp4028) do not probe at the same time,
> > so
> > the driver does not call ge_b850v3_resgiter() when probing, causing
> > the
> > driver to try to remove the object that has not been initialized.
> >
> > Fix this by checking whether both the bridges are probed.
> >
> > Signed-off-by: Zheyu Ma <[email protected]>
>
> Good catch!
>
> Acked-by: Martyn Welch <[email protected]>

Tested-by: Ian Ray <[email protected]>


>
> Would be worth adding:
>
> Fixes: 11632d4aa2b3 ("drm/bridge: megachips: Ensure both bridges are
> probed before registration")
>
> > ---
> > ?drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c | 4 +++-
> > ?1 file changed, 3 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c
> > b/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c
> > index cce98bf2a4e7..c68a4cdf4625 100644
> > --- a/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c
> > +++ b/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c
> > @@ -296,7 +296,9 @@ static void ge_b850v3_lvds_remove(void)
> > ???????? * This check is to avoid both the drivers
> > ???????? * removing the bridge in their remove() function
> > ???????? */
> > -???????if (!ge_b850v3_lvds_ptr)
> > +???????if (!ge_b850v3_lvds_ptr ||
> > +???????????????!ge_b850v3_lvds_ptr->stdp2690_i2c ||
> > +???????????????!ge_b850v3_lvds_ptr->stdp4028_i2c)
> > ????????????????goto out;
> > ?
> > ????????drm_bridge_remove(&ge_b850v3_lvds_ptr->bridge);
>

2022-08-29 15:14:53

by Robert Foss

[permalink] [raw]
Subject: Re: [PATCH] drm/bridge: megachips: Fix a null pointer dereference bug

On Sat, 16 Jul 2022 at 10:13, Zheyu Ma <[email protected]> wrote:
>
> When removing the module we will get the following warning:
>
> [ 31.911505] i2c-core: driver [stdp2690-ge-b850v3-fw] unregistered
> [ 31.912484] general protection fault, probably for non-canonical address 0xdffffc0000000001: 0000 [#1] PREEMPT SMP KASAN PTI
> [ 31.913338] KASAN: null-ptr-deref in range [0x0000000000000008-0x000000000000000f]
> [ 31.915280] RIP: 0010:drm_bridge_remove+0x97/0x130
> [ 31.921825] Call Trace:
> [ 31.922533] stdp4028_ge_b850v3_fw_remove+0x34/0x60 [megachips_stdpxxxx_ge_b850v3_fw]
> [ 31.923139] i2c_device_remove+0x181/0x1f0
>
> The two bridges (stdp2690, stdp4028) do not probe at the same time, so
> the driver does not call ge_b850v3_resgiter() when probing, causing the
> driver to try to remove the object that has not been initialized.
>
> Fix this by checking whether both the bridges are probed.
>
> Signed-off-by: Zheyu Ma <[email protected]>
> ---
> drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c b/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c
> index cce98bf2a4e7..c68a4cdf4625 100644
> --- a/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c
> +++ b/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c
> @@ -296,7 +296,9 @@ static void ge_b850v3_lvds_remove(void)
> * This check is to avoid both the drivers
> * removing the bridge in their remove() function
> */
> - if (!ge_b850v3_lvds_ptr)
> + if (!ge_b850v3_lvds_ptr ||
> + !ge_b850v3_lvds_ptr->stdp2690_i2c ||
> + !ge_b850v3_lvds_ptr->stdp4028_i2c)

This chunk fails checkpatch --strict.

Alignment should match open parenthesis
#39: FILE: drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c:300:


> goto out;
>
> drm_bridge_remove(&ge_b850v3_lvds_ptr->bridge);
> --
> 2.25.1
>

2022-08-30 07:59:35

by Zheyu Ma

[permalink] [raw]
Subject: Re: [PATCH] drm/bridge: megachips: Fix a null pointer dereference bug

Hi Robert,


On Mon, Aug 29, 2022 at 11:03 PM Robert Foss <[email protected]> wrote:
>
> On Sat, 16 Jul 2022 at 10:13, Zheyu Ma <[email protected]> wrote:
> >
> > When removing the module we will get the following warning:
> >
> > [ 31.911505] i2c-core: driver [stdp2690-ge-b850v3-fw] unregistered
> > [ 31.912484] general protection fault, probably for non-canonical address 0xdffffc0000000001: 0000 [#1] PREEMPT SMP KASAN PTI
> > [ 31.913338] KASAN: null-ptr-deref in range [0x0000000000000008-0x000000000000000f]
> > [ 31.915280] RIP: 0010:drm_bridge_remove+0x97/0x130
> > [ 31.921825] Call Trace:
> > [ 31.922533] stdp4028_ge_b850v3_fw_remove+0x34/0x60 [megachips_stdpxxxx_ge_b850v3_fw]
> > [ 31.923139] i2c_device_remove+0x181/0x1f0
> >
> > The two bridges (stdp2690, stdp4028) do not probe at the same time, so
> > the driver does not call ge_b850v3_resgiter() when probing, causing the
> > driver to try to remove the object that has not been initialized.
> >
> > Fix this by checking whether both the bridges are probed.
> >
> > Signed-off-by: Zheyu Ma <[email protected]>
> > ---
> > drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c | 4 +++-
> > 1 file changed, 3 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c b/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c
> > index cce98bf2a4e7..c68a4cdf4625 100644
> > --- a/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c
> > +++ b/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c
> > @@ -296,7 +296,9 @@ static void ge_b850v3_lvds_remove(void)
> > * This check is to avoid both the drivers
> > * removing the bridge in their remove() function
> > */
> > - if (!ge_b850v3_lvds_ptr)
> > + if (!ge_b850v3_lvds_ptr ||
> > + !ge_b850v3_lvds_ptr->stdp2690_i2c ||
> > + !ge_b850v3_lvds_ptr->stdp4028_i2c)
>
> This chunk fails checkpatch --strict.
>
> Alignment should match open parenthesis
> #39: FILE: drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c:300:

Thanks for your suggestion, I've sent the version 2 patch.

Regards,

Zheyu Ma