diff mbox series

[1/7] drm/msm: fix use-after-free on probe deferral

Message ID 20220912154046.12900-2-johan+linaro@kernel.org (mailing list archive)
State Superseded
Headers show
Series drm/msm: probe deferral fixes | expand

Commit Message

Johan Hovold Sept. 12, 2022, 3:40 p.m. UTC
The bridge counter was never reset when tearing down the DRM device so
that stale pointers to deallocated structures would be accessed on the
next tear down (e.g. after a second late bind deferral).

Given enough bridges and a few probe deferrals this could currently also
lead to data beyond the bridge array being corrupted.

Fixes: d28ea556267c ("drm/msm: properly add and remove internal bridges")
Cc: stable@vger.kernel.org      # 5.19
Signed-off-by: Johan Hovold <johan+linaro@kernel.org>
---
 drivers/gpu/drm/msm/msm_drv.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Dmitry Baryshkov Sept. 12, 2022, 5:52 p.m. UTC | #1
On 12/09/2022 18:40, Johan Hovold wrote:
> The bridge counter was never reset when tearing down the DRM device so
> that stale pointers to deallocated structures would be accessed on the
> next tear down (e.g. after a second late bind deferral).
> 
> Given enough bridges and a few probe deferrals this could currently also
> lead to data beyond the bridge array being corrupted.
> 
> Fixes: d28ea556267c ("drm/msm: properly add and remove internal bridges")
> Cc: stable@vger.kernel.org      # 5.19

Fixes: a3376e3ec81c ("drm/msm: convert to drm_bridge")
Cc: stable@vger.kernel.org # 3.12

Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>

> Signed-off-by: Johan Hovold <johan+linaro@kernel.org>
> ---
>   drivers/gpu/drm/msm/msm_drv.c | 1 +
>   1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/gpu/drm/msm/msm_drv.c b/drivers/gpu/drm/msm/msm_drv.c
> index 391d86b54ded..d254fe2507ec 100644
> --- a/drivers/gpu/drm/msm/msm_drv.c
> +++ b/drivers/gpu/drm/msm/msm_drv.c
> @@ -241,6 +241,7 @@ static int msm_drm_uninit(struct device *dev)
>   
>   	for (i = 0; i < priv->num_bridges; i++)
>   		drm_bridge_remove(priv->bridges[i]);
> +	priv->num_bridges = 0;
>   
>   	pm_runtime_get_sync(dev);
>   	msm_irq_uninstall(ddev);
Johan Hovold Sept. 13, 2022, 7:31 a.m. UTC | #2
On Mon, Sep 12, 2022 at 08:52:44PM +0300, Dmitry Baryshkov wrote:
> On 12/09/2022 18:40, Johan Hovold wrote:
> > The bridge counter was never reset when tearing down the DRM device so
> > that stale pointers to deallocated structures would be accessed on the
> > next tear down (e.g. after a second late bind deferral).
> > 
> > Given enough bridges and a few probe deferrals this could currently also
> > lead to data beyond the bridge array being corrupted.
> > 
> > Fixes: d28ea556267c ("drm/msm: properly add and remove internal bridges")
> > Cc: stable@vger.kernel.org      # 5.19
> 
> Fixes: a3376e3ec81c ("drm/msm: convert to drm_bridge")
> Cc: stable@vger.kernel.org # 3.12

The use after free was introduced in 5.19, and the next patch takes care
of the possible overflow of the bridges array that has been around since
3.12.

But sure, this oversight has been there since 3.12. I'll reconsider
adding the other Fixes tag. The stable team struggles with context
changes apparently so not sure it's worth backporting, though.

> Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
> 
> > Signed-off-by: Johan Hovold <johan+linaro@kernel.org>
> > ---
> >   drivers/gpu/drm/msm/msm_drv.c | 1 +
> >   1 file changed, 1 insertion(+)
> > 
> > diff --git a/drivers/gpu/drm/msm/msm_drv.c b/drivers/gpu/drm/msm/msm_drv.c
> > index 391d86b54ded..d254fe2507ec 100644
> > --- a/drivers/gpu/drm/msm/msm_drv.c
> > +++ b/drivers/gpu/drm/msm/msm_drv.c
> > @@ -241,6 +241,7 @@ static int msm_drm_uninit(struct device *dev)
> >   
> >   	for (i = 0; i < priv->num_bridges; i++)
> >   		drm_bridge_remove(priv->bridges[i]);
> > +	priv->num_bridges = 0;
> >   
> >   	pm_runtime_get_sync(dev);
> >   	msm_irq_uninstall(ddev);

Johan
diff mbox series

Patch

diff --git a/drivers/gpu/drm/msm/msm_drv.c b/drivers/gpu/drm/msm/msm_drv.c
index 391d86b54ded..d254fe2507ec 100644
--- a/drivers/gpu/drm/msm/msm_drv.c
+++ b/drivers/gpu/drm/msm/msm_drv.c
@@ -241,6 +241,7 @@  static int msm_drm_uninit(struct device *dev)
 
 	for (i = 0; i < priv->num_bridges; i++)
 		drm_bridge_remove(priv->bridges[i]);
+	priv->num_bridges = 0;
 
 	pm_runtime_get_sync(dev);
 	msm_irq_uninstall(ddev);