public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 00/10] drm/msm: probe deferral fixes
@ 2022-09-13  8:53 Johan Hovold
  2022-09-13  8:53 ` [PATCH v2 01/10] drm/msm: fix use-after-free on probe deferral Johan Hovold
                   ` (11 more replies)
  0 siblings, 12 replies; 43+ messages in thread
From: Johan Hovold @ 2022-09-13  8:53 UTC (permalink / raw)
  To: Douglas Anderson, Dmitry Baryshkov, Rob Clark, Abhinav Kumar
  Cc: Andrzej Hajda, Neil Armstrong, Robert Foss, Laurent Pinchart,
	Jonas Karlman, Jernej Skrabec, Daniel Vetter, Sean Paul,
	Stephen Boyd, Bjorn Andersson, Manivannan Sadhasivam,
	Kuogee Hsieh, Steev Klimaszewski, dri-devel, linux-arm-msm,
	freedreno, linux-kernel, Johan Hovold

The MSM DRM driver is currently broken in multiple ways with respect to
probe deferral. Not only does the driver currently fail to probe again
after a late deferral, but due to a related use-after-free bug this also
triggers NULL-pointer dereferences.

These bugs are not new but have become critical with the release of
5.19 where probe is deferred in case the aux-bus EP panel driver has not
yet been loaded.

The underlying problem is lifetime issues due to careless use of
device-managed resources.

Specifically, device-managed resources allocated post component bind
must be tied to the lifetime of the aggregate DRM device or they will
not necessarily be released when binding of the aggregate device is
deferred.

The following call chain and pseudo code serves as an illustration of
the problem:

 - platform_probe(pdev1)
   - dp_display_probe()
     - component_add()

 - platform_probe(pdev2) 				// last component
   - dp_display_probe()					// d0
       - component_add()
         - try_to_bring_up_aggregate_device()
	   - devres_open_group(adev->parent)		// d1

	   - msm_drm_bind()
	     - msm_drm_init()
	       - component_bind_all()
	         - for_each_component()
		   - component_bind()
		     - devres_open_group(&pdev->dev)	// d2
	             - dp_display_bind()
		       - devm_kzalloc(&pdev->dev)	// a1, OK
		     - devres_close_group(&pdev->dev)	// d3

	       - dpu_kms_hw_init()
	         - for_each_panel()
	           - msm_dp_modeset_init()
		     - dp_display_request_irq()
		       - devm_request_irq(&pdev->dev)	// a2, BUG
		     - if (pdev == pdev2 && condition)
		       - return -EPROBE_DEFER;

	      - if (error)
 	        - component_unbind_all()
	          - for_each_component()
		    - component_unbind()
		      - dp_display_unbind()
		      - devres_release_group(&pdev->dev) // d4, only a1 is freed

           - if (error)
	     - devres_release_group(adev->parent)	// d5

The device-managed allocation a2 is buggy as its lifetime is tied to the
component platform device and will not be released when the aggregate
device bind fails (e.g. due to a probe deferral).

When pdev2 is later probed again, the attempt to allocate the IRQ a
second time will fail for pdev1 (which is still bound to its platform
driver).

This series fixes the lifetime issues by tying the lifetime of a2 (and
similar allocations) to the lifetime of the aggregate device so that a2
is released at d5.

In some cases, such has for the DP IRQ, the above situation can also be
avoided by moving the allocation in question to the platform driver
probe (d0) or component bind (between d2 and d3). But as doing so is not
a general fix, this can be done later as a cleanup/optimisation.

Johan

Changes in v2
 - use a custom devres action instead of amending the AUX bus interface
   (Doug)
 - split sanity check fixes and cleanups per bridge type (Dmitry)
 - add another Fixes tag for the missing bridge counter reset (Dmitry)


Johan Hovold (10):
  drm/msm: fix use-after-free on probe deferral
  drm/msm/dp: fix memory corruption with too many bridges
  drm/msm/dsi: fix memory corruption with too many bridges
  drm/msm/hdmi: fix memory corruption with too many bridges
  drm/msm/dp: fix IRQ lifetime
  drm/msm/dp: fix aux-bus EP lifetime
  drm/msm/dp: fix bridge lifetime
  drm/msm/hdmi: fix IRQ lifetime
  drm/msm/dp: drop modeset sanity checks
  drm/msm/dsi: drop modeset sanity checks

 drivers/gpu/drm/msm/dp/dp_display.c | 26 +++++++++++++++++++-------
 drivers/gpu/drm/msm/dp/dp_parser.c  |  6 +++---
 drivers/gpu/drm/msm/dp/dp_parser.h  |  5 +++--
 drivers/gpu/drm/msm/dsi/dsi.c       |  9 +++++----
 drivers/gpu/drm/msm/hdmi/hdmi.c     |  7 ++++++-
 drivers/gpu/drm/msm/msm_drv.c       |  1 +
 6 files changed, 37 insertions(+), 17 deletions(-)

-- 
2.35.1


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

end of thread, other threads:[~2022-10-24 16:56 UTC | newest]

Thread overview: 43+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-13  8:53 [PATCH v2 00/10] drm/msm: probe deferral fixes Johan Hovold
2022-09-13  8:53 ` [PATCH v2 01/10] drm/msm: fix use-after-free on probe deferral Johan Hovold
2022-09-22 19:48   ` [Freedreno] " Kuogee Hsieh
2022-09-22 20:01   ` Kuogee Hsieh
2022-09-13  8:53 ` [PATCH v2 02/10] drm/msm/dp: fix memory corruption with too many bridges Johan Hovold
2022-09-22 19:51   ` [Freedreno] " Kuogee Hsieh
2022-09-22 19:54   ` Dmitry Baryshkov
2022-09-13  8:53 ` [PATCH v2 03/10] drm/msm/dsi: " Johan Hovold
2022-09-22 19:51   ` Kuogee Hsieh
2022-09-22 19:54   ` Dmitry Baryshkov
2022-09-13  8:53 ` [PATCH v2 04/10] drm/msm/hdmi: " Johan Hovold
2022-09-22 19:52   ` [Freedreno] " Kuogee Hsieh
2022-09-22 19:54   ` Dmitry Baryshkov
2022-09-13  8:53 ` [PATCH v2 05/10] drm/msm/dp: fix IRQ lifetime Johan Hovold
2022-09-22 19:54   ` [Freedreno] " Kuogee Hsieh
2022-09-13  8:53 ` [PATCH v2 06/10] drm/msm/dp: fix aux-bus EP lifetime Johan Hovold
2022-09-13 12:36   ` Doug Anderson
2022-09-13  8:53 ` [PATCH v2 07/10] drm/msm/dp: fix bridge lifetime Johan Hovold
2022-09-22 19:56   ` [Freedreno] " Kuogee Hsieh
2022-09-13  8:53 ` [PATCH v2 08/10] drm/msm/hdmi: fix IRQ lifetime Johan Hovold
2022-09-22 19:55   ` Kuogee Hsieh
2022-09-23  6:17     ` Johan Hovold
2022-09-13  8:53 ` [PATCH v2 09/10] drm/msm/dp: drop modeset sanity checks Johan Hovold
2022-09-22 19:57   ` Kuogee Hsieh
2022-09-26 18:17   ` Abhinav Kumar
2022-09-27  7:14     ` Johan Hovold
2022-09-27 18:42       ` Abhinav Kumar
2022-09-28 12:24         ` Johan Hovold
2022-09-28 15:33           ` Abhinav Kumar
2022-09-28 15:57             ` Johan Hovold
2022-09-13  8:53 ` [PATCH v2 10/10] drm/msm/dsi: " Johan Hovold
2022-09-22 19:58   ` [Freedreno] " Kuogee Hsieh
2022-09-26 18:21   ` Abhinav Kumar
2022-09-27  7:16     ` Johan Hovold
2022-09-27 18:44       ` Abhinav Kumar
2022-09-13 20:23 ` [PATCH v2 00/10] drm/msm: probe deferral fixes Steev Klimaszewski
2022-09-14  6:01   ` Johan Hovold
2022-09-16 16:43     ` Steev Klimaszewski
2022-09-20  9:06 ` Johan Hovold
2022-10-21  6:27   ` Johan Hovold
2022-10-21 16:05     ` Abhinav Kumar
2022-10-24 11:33       ` Johan Hovold
2022-10-24 15:01         ` Rob Clark

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox