Skip to content

Commit e0d0a95

Browse files
Phil Elwellpopcornmix
authored andcommitted
drm/vc4: Prevent load tracking from breaking FKMS
Firmware KMS uses a mixture of VC4 processing and dedicated code. The load tracking support in VC4 assumes it is dealing with vc4_plane_state objects when up-casting with container_of, but FKMS uses unadorned drm_plane_state structures causing the VC4 code to read off the end into random portions of memory. Work around the problem in a minimally- invasive way by over-allocating the FKMS plane state structures to be large enough to contain a vc4_plane_state, filling the remainder with zeroes. Signed-off-by: Phil Elwell <phil@raspberrypi.org>
1 parent 496556b commit e0d0a95

1 file changed

Lines changed: 32 additions & 2 deletions

File tree

‎drivers/gpu/drm/vc4/vc4_firmware_kms.c‎

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,20 @@ static int vc4_plane_atomic_check(struct drm_plane *plane,
559559
return 0;
560560
}
561561

562+
/* Called during init to allocate the plane's atomic state. */
563+
static void vc4_plane_reset(struct drm_plane *plane)
564+
{
565+
struct vc4_plane_state *vc4_state;
566+
567+
WARN_ON(plane->state);
568+
569+
vc4_state = kzalloc(sizeof(*vc4_state), GFP_KERNEL);
570+
if (!vc4_state)
571+
return;
572+
573+
__drm_atomic_helper_plane_reset(plane, &vc4_state->base);
574+
}
575+
562576
static void vc4_plane_destroy(struct drm_plane *plane)
563577
{
564578
drm_plane_cleanup(plane);
@@ -600,13 +614,29 @@ static bool vc4_fkms_format_mod_supported(struct drm_plane *plane,
600614
}
601615
}
602616

617+
static struct drm_plane_state *vc4_plane_duplicate_state(struct drm_plane *plane)
618+
{
619+
struct vc4_plane_state *vc4_state;
620+
621+
if (WARN_ON(!plane->state))
622+
return NULL;
623+
624+
vc4_state = kzalloc(sizeof(*vc4_state), GFP_KERNEL);
625+
if (!vc4_state)
626+
return NULL;
627+
628+
__drm_atomic_helper_plane_duplicate_state(plane, &vc4_state->base);
629+
630+
return &vc4_state->base;
631+
}
632+
603633
static const struct drm_plane_funcs vc4_plane_funcs = {
604634
.update_plane = drm_atomic_helper_update_plane,
605635
.disable_plane = drm_atomic_helper_disable_plane,
606636
.destroy = vc4_plane_destroy,
607637
.set_property = NULL,
608-
.reset = drm_atomic_helper_plane_reset,
609-
.atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state,
638+
.reset = vc4_plane_reset,
639+
.atomic_duplicate_state = vc4_plane_duplicate_state,
610640
.atomic_destroy_state = drm_atomic_helper_plane_destroy_state,
611641
.format_mod_supported = vc4_fkms_format_mod_supported,
612642
};

0 commit comments

Comments
 (0)