All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Zbigniew Kempczyński" <zbigniew.kempczynski@intel.com>
To: Andrzej Turko <andrzej.turko@linux.intel.com>
Cc: igt-dev@lists.freedesktop.org
Subject: Re: [igt-dev] [PATCH i-g-t 1/1] lib/intel_allocator: Check validity of the file descriptor
Date: Thu, 17 Jun 2021 09:05:25 +0200	[thread overview]
Message-ID: <20210617070525.GC4129@zkempczy-mobl2> (raw)
In-Reply-To: <20210616113714.5766-2-andrzej.turko@linux.intel.com>

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@linux.intel.com>
> Cc: Zbigniew Kempczyński <zbigniew.kempczynski@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@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
> 
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

  parent reply	other threads:[~2021-06-17  7:05 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-16 11:37 [igt-dev] [PATCH i-g-t 0/1] Check the file descriptor while opening intel allocator Andrzej Turko
2021-06-16 11:37 ` [igt-dev] [PATCH i-g-t 1/1] lib/intel_allocator: Check validity of the file descriptor Andrzej Turko
2021-06-16 12:05   ` Petri Latvala
2021-06-17  6:06     ` Zbigniew Kempczyński
2021-06-17  6:42       ` Petri Latvala
2021-06-17  7:05   ` Zbigniew Kempczyński [this message]
2021-06-16 15:25 ` [igt-dev] ✓ Fi.CI.BAT: success for Check the file descriptor while opening intel allocator Patchwork
2021-06-16 17:13 ` [igt-dev] ✓ Fi.CI.IGT: " Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210617070525.GC4129@zkempczy-mobl2 \
    --to=zbigniew.kempczynski@intel.com \
    --cc=andrzej.turko@linux.intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.