[Intel-gfx] [PATCH v13 5/9] drm/i915: Check for integer truncation on scatterlist creation
Jani Nikula
jani.nikula at intel.com
Wed Sep 28 08:51:00 UTC 2022
On Wed, 28 Sep 2022, Gwan-gyeong Mun <gwan-gyeong.mun at intel.com> wrote:
> diff --git a/drivers/gpu/drm/i915/i915_scatterlist.h b/drivers/gpu/drm/i915/i915_scatterlist.h
> index 9ddb3e743a3e..1d1802beb42b 100644
> --- a/drivers/gpu/drm/i915/i915_scatterlist.h
> +++ b/drivers/gpu/drm/i915/i915_scatterlist.h
> @@ -220,4 +220,15 @@ struct i915_refct_sgt *i915_rsgt_from_buddy_resource(struct ttm_resource *res,
> u64 region_start,
> u32 page_alignment);
>
> +/* Wrap scatterlist.h to sanity check for integer truncation */
> +typedef unsigned int __sg_size_t; /* see linux/scatterlist.h */
> +#define sg_alloc_table(sgt, nents, gfp) \
> + overflows_type(nents, __sg_size_t) ? -E2BIG \
> + : ((sg_alloc_table)(sgt, (__sg_size_t)(nents), gfp))
> +
> +#define sg_alloc_table_from_pages_segment(sgt, pages, npages, offset, size, max_segment, gfp) \
> + overflows_type(npages, __sg_size_t) ? -E2BIG \
> + : ((sg_alloc_table_from_pages_segment)(sgt, pages, (__sg_size_t)(npages), offset, \
> + size, max_segment, gfp))
> +
> #endif
No. I don't think we should shadow sg_alloc_table() and
sg_alloc_table_from_pages_segment().
Either get this in scatterlist.h (preferred) or prefix with i915_ or
whatever to indicate it's our local thing.
i915_scatterlist.h already has too much scatterlist "namespace" abuse
that I'd rather see gone than violated more.
BR,
Jani.
--
Jani Nikula, Intel Open Source Graphics Center
More information about the Intel-gfx
mailing list