[igt-dev] [PATCH i-g-t 1/1] lib/intel_allocator: Check validity of the file descriptor

Zbigniew Kempczyński zbigniew.kempczynski at intel.com
Thu Jun 17 07:05:25 UTC 2021


On Wed, Jun 16, 2021 at 01:37:14PM +0200, Andrzej Turko wrote:
> All procedures for opening particular types of allocators
> query the gtt size. Even if the user has provided the
> boundaries of the address space managed by the allocator,
> the query is performed for the sake of validation.
> 
> gem_aperture_size() called with an invalid id returns a
> default value instead of failing. Thus, we need to
> additionally check whether the file descriptor is valid.
> 
> Signed-off-by: Andrzej Turko <andrzej.turko at linux.intel.com>
> Cc: Zbigniew Kempczyński <zbigniew.kempczynski at intel.com>

Agree, we should catch such situation and prevent user to 
use not valid vm range (invalid fd will get 256M of gtt size
what is bad here).

Assert here is ok, we want to expose invalid use and fix it
in following patches.

Reviewed-by: Zbigniew Kempczyński <zbigniew.kempczynski at intel.com>

--
Zbigniew


> ---
>  lib/intel_allocator.c | 11 +++++++++++
>  1 file changed, 11 insertions(+)
> 
> diff --git a/lib/intel_allocator.c b/lib/intel_allocator.c
> index 96f839d4b..c060e10c3 100644
> --- a/lib/intel_allocator.c
> +++ b/lib/intel_allocator.c
> @@ -166,6 +166,15 @@ static inline void map_entry_free_func(struct igt_map_entry *entry)
>  	free(entry->data);
>  }
>  
> +static bool can_report_gtt_size(int fd)
> +{
> +	struct drm_i915_gem_context_param p = {
> +		.param = I915_CONTEXT_PARAM_GTT_SIZE
> +	};
> +
> +	return (__gem_context_get_param(fd, &p) == 0);
> +}
> +
>  static uint64_t __handle_create(struct allocator *al)
>  {
>  	struct handle_entry *h = malloc(sizeof(*h));
> @@ -271,6 +280,8 @@ static struct intel_allocator *intel_allocator_create(int fd,
>  {
>  	struct intel_allocator *ial = NULL;
>  
> +	igt_assert(can_report_gtt_size(fd));
> +
>  	switch (allocator_type) {
>  	/*
>  	 * Few words of explanation is required here.
> -- 
> 2.25.1
> 


More information about the igt-dev mailing list