From: Jani Nikula <jani.nikula@linux.intel.com>
To: Intel Graphics Development <intel-gfx@lists.freedesktop.org>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Subject: Re: [PATCH 5/5] drm/i915: Use unsigned for overflow checks in execbuf
Date: Thu, 19 Sep 2013 13:46:31 +0300 [thread overview]
Message-ID: <874n9h84xk.fsf@intel.com> (raw)
In-Reply-To: <1379585916-6521-5-git-send-email-daniel.vetter@ffwll.ch>
On Thu, 19 Sep 2013, Daniel Vetter <daniel.vetter@ffwll.ch> wrote:
> There's actually no real risk since we already check for stricter
> constraints earlier (using UINT_MAX / sizeof (struct
> drm_i915_gem_exec_object2) as the limit). But in eb_create we use
> signed integers, which steals a factor of 2. Luckily struct
> drm_i915_gem_exec_object2 for this to not matter.
Parse error.
> Still, be consistent and use unsigned integers.
>
> Similar use unsinged integers when checking for overflows in the
> relocation entry processing.
>
> I've also added a new subtests to igt/gem_reloc_overflow to also
> test for overflowing args->buffer_count values.
>
> Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
> ---
> drivers/gpu/drm/i915/i915_gem_execbuffer.c | 13 +++++++------
> 1 file changed, 7 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
> index a733118..cd98aeb 100644
> --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
> +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
> @@ -45,18 +45,19 @@ struct eb_vmas {
> static struct eb_vmas *
> eb_create(struct drm_i915_gem_execbuffer2 *args, struct i915_address_space *vm)
> {
> + unsigned size, count;
My OCD says always use "unsigned int", not just "unsigned". To me this
is like having:
const foo;
static bar;
YMMV.
Otherwise,
Reviewed-by: Jani Nikula <jani.nikula@intel.com>
> struct eb_vmas *eb = NULL;
>
> if (args->flags & I915_EXEC_HANDLE_LUT) {
> - int size = args->buffer_count;
> + size = args->buffer_count;
> size *= sizeof(struct i915_vma *);
> size += sizeof(struct eb_vmas);
> eb = kmalloc(size, GFP_TEMPORARY | __GFP_NOWARN | __GFP_NORETRY);
> }
>
> if (eb == NULL) {
> - int size = args->buffer_count;
> - int count = PAGE_SIZE / sizeof(struct hlist_head) / 2;
> + size = args->buffer_count;
> + count = PAGE_SIZE / sizeof(struct hlist_head) / 2;
> BUILD_BUG_ON_NOT_POWER_OF_2(PAGE_SIZE / sizeof(struct hlist_head));
> while (count > 2*size)
> count >>= 1;
> @@ -667,7 +668,7 @@ i915_gem_execbuffer_relocate_slow(struct drm_device *dev,
> bool need_relocs;
> int *reloc_offset;
> int i, total, ret;
> - int count = args->buffer_count;
> + unsigned count = args->buffer_count;
>
> if (WARN_ON(list_empty(&eb->vmas)))
> return 0;
> @@ -818,8 +819,8 @@ validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
> int count)
> {
> int i;
> - int relocs_total = 0;
> - int relocs_max = INT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
> + unsigned relocs_total = 0;
> + unsigned relocs_max = UINT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
>
> for (i = 0; i < count; i++) {
> char __user *ptr = to_user_ptr(exec[i].relocs_ptr);
> --
> 1.8.4.rc3
>
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/intel-gfx
--
Jani Nikula, Intel Open Source Technology Center
next prev parent reply other threads:[~2013-09-19 10:44 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-19 10:18 [PATCH 1/5] drm/i915: use pointer = k[cmz...]alloc(sizeof(*pointer), ...) pattern Daniel Vetter
2013-09-19 10:18 ` [PATCH 2/5] drm/i915: Use kcalloc more Daniel Vetter
2013-09-19 10:38 ` Jani Nikula
2013-09-19 10:50 ` Chris Wilson
2013-09-19 11:00 ` Jani Nikula
2013-09-19 11:12 ` Chris Wilson
2013-09-19 10:46 ` Chris Wilson
2013-09-19 11:53 ` Daniel Vetter
2013-09-19 12:06 ` [PATCH] " Daniel Vetter
2013-09-19 12:30 ` Chris Wilson
2013-09-19 12:35 ` Daniel Vetter
2013-09-19 12:41 ` Chris Wilson
2013-09-19 12:51 ` Daniel Vetter
2013-09-19 12:58 ` Chris Wilson
2013-09-20 22:37 ` Daniel Vetter
2013-09-19 13:40 ` Jani Nikula
2013-09-19 10:18 ` [PATCH 3/5] drm/i915: Ditch INTELFB_CONN_LIMIT Daniel Vetter
2013-09-19 10:53 ` Jani Nikula
2013-09-19 12:05 ` [PATCH] " Daniel Vetter
2013-09-19 13:32 ` Jani Nikula
2013-09-19 10:18 ` [PATCH 4/5] drm/i915: check for allocation overflow in error state capture Daniel Vetter
2013-09-20 23:39 ` Ben Widawsky
2013-09-19 10:18 ` [PATCH 5/5] drm/i915: Use unsigned for overflow checks in execbuf Daniel Vetter
2013-09-19 10:44 ` Chris Wilson
2013-09-19 12:00 ` [PATCH] " Daniel Vetter
2013-09-19 12:53 ` Daniel Vetter
2013-09-19 13:05 ` Chris Wilson
2013-09-19 10:46 ` Jani Nikula [this message]
2013-09-19 10:34 ` [PATCH 1/5] drm/i915: use pointer = k[cmz...]alloc(sizeof(*pointer), ...) pattern Jani Nikula
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=874n9h84xk.fsf@intel.com \
--to=jani.nikula@linux.intel.com \
--cc=daniel.vetter@ffwll.ch \
--cc=intel-gfx@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox