Re: [PATCH] drm/xe: Fix overflow in guc_ct_snapshot_capture

Matthew Brost
2026-03-04T19:08:04Z

On Wed, Mar 04, 2026 at 08:39:52PM +0200, Mika Kuoppala wrote:
> Matthew Brost <matthew.brost@intel.com> writes:
>
> > On Wed, Mar 04, 2026 at 01:25:01PM +0200, Mika Kuoppala wrote:
> >> snapshot->ctb is u32*, so pointer arithmetic on it scales
> >> the byte offset from xe_bo_size() by 4, overshooting the
> >> intended start of the g2h portion and writing past the
> >> allocated buffer.
> >>
> >> Fix this by using *u8 to get the arithmetic right and also
> >> prevent future mishaps.
> >>
> >> Fixes: af3de6cf06f9 ("drm/xe: Split H2G and G2H into separate buffer objects")
> >> Cc: Matthew Brost <matthew.brost@intel.com>
> >> Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
> >> Cc: "Thomas Hellström" <thomas.hellstrom@linux.intel.com>
> >> Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
> >> Cc: intel-xe@lists.freedesktop.org
> >> Signed-off-by: Mika Kuoppala <mika.kuoppala@linux.intel.com>
> >> ---
> >> drivers/gpu/drm/xe/xe_guc_ct_types.h | 2 +-
> >> 1 file changed, 1 insertion(+), 1 deletion(-)
> >>
> >> diff --git a/drivers/gpu/drm/xe/xe_guc_ct_types.h b/drivers/gpu/drm/xe/xe_guc_ct_types.h
> >> index 46ad1402347d..1b4b9b713d42 100644
> >> --- a/drivers/gpu/drm/xe/xe_guc_ct_types.h
> >> +++ b/drivers/gpu/drm/xe/xe_guc_ct_types.h
> >> @@ -74,7 +74,7 @@ struct xe_guc_ct_snapshot {
> >> /** @ctb_size: size of the snapshot of the CTB */
> >> size_t ctb_size;
> >> /** @ctb: snapshot of the entire CTB */
> >> - u32 *ctb;
> >> + u8 *ctb;
> >
> > Ah, I see the issue. Maybe 'void *ctb'?
> >
>
> What is the benefit? We clearly do arithmetic on it.
> You want u8 * cast on where memcpy is done?
>

memcpy + xe_map / iosys_map layers operate on void * pointers.

Functionally I agree no difference as the point math for u8 * or void *
is the same but for consistency void * I believe makes more sense.

Matt

> > Matt
> >
> >> };
> >>
> >> /**
> >> --
> >> 2.43.0
> >>