Re: [PATCH 2/3] drm/fb_helper: Fix references to dev->mode_config.num_connector

From: Lyude Paul
Date: Thu May 05 2016 - 11:27:39 EST


I would Cc it to stable just in case tbh. I picked up on this one since KASAN
was picking up on some of the memcpy() calls around here going out of bounds. I
can include some of the backtraces from that if needed.

On Wed, 2016-05-04 at 19:11 +0200, Daniel Vetter wrote:
> On Wed, May 04, 2016 at 11:28:52AM -0400, Lyude wrote:
> >
> > During boot, MST hotplugs are generally expected (even if no physical
> > hotplugging occurs) and result in DRM's connector topology changing.
> > This means that using num_connector from the current mode configuration
> > can lead to the number of connectors changing under us. This can lead to
> > some nasty scenarios in fbcon:
> >
> > - We allocate an array to the size of dev->mode_config.num_connectors.
> > - MST hotplug occurs, dev->mode_config.num_connectors gets incremented.
> > - We try to loop through each element in the array using the new value
> > Â of dev->mode_config.num_connectors, and end up going out of bounds
> > Â since dev->mode_config.num_connectors is now larger then the array we
> > Â allocated.
> >
> > fb_helper->connector_count however, will always remain consistent while
> > we do a modeset in fb_helper.
> >
> > Cc: stable@xxxxxxxxxxxxxxx
> > Signed-off-by: Lyude <cpaul@xxxxxxxxxx>
> Ok, this one looks like it's indeed in the same critical section (within
> drm_setup_outputs) as where we allocate the fb helper connector array. So
> I think this one here is not needed to fix a bug?
>
> Still makes sense as a patch, but not with cc: stable I think.
> -Daniel
>
> >
> > ---
> > Âdrivers/gpu/drm/drm_fb_helper.c | 4 ++--
> > Â1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/drm_fb_helper.c
> > b/drivers/gpu/drm/drm_fb_helper.c
> > index 855108e..15204c0 100644
> > --- a/drivers/gpu/drm/drm_fb_helper.c
> > +++ b/drivers/gpu/drm/drm_fb_helper.c
> > @@ -1914,7 +1914,7 @@ static int drm_pick_crtcs(struct drm_fb_helper
> > *fb_helper,
> > Â if (modes[n] == NULL)
> > Â return best_score;
> > Â
> > - crtcs = kzalloc(dev->mode_config.num_connector *
> > + crtcs = kzalloc(fb_helper->connector_count *
> > Â sizeof(struct drm_fb_helper_crtc *), GFP_KERNEL);
> > Â if (!crtcs)
> > Â return best_score;
> > @@ -1960,7 +1960,7 @@ static int drm_pick_crtcs(struct drm_fb_helper
> > *fb_helper,
> > Â if (score > best_score) {
> > Â best_score = score;
> > Â memcpy(best_crtcs, crtcs,
> > - ÂÂÂÂÂÂÂdev->mode_config.num_connector *
> > + ÂÂÂÂÂÂÂfb_helper->connector_count *
> > Â ÂÂÂÂÂÂÂsizeof(struct drm_fb_helper_crtc *));
> > Â }
> > Â }
> > --Â
> > 2.5.5
> >
> > _______________________________________________
> > dri-devel mailing list
> > dri-devel@xxxxxxxxxxxxxxxxxxxxx
> > https://lists.freedesktop.org/mailman/listinfo/dri-devel
--
Cheers,
Lyude