All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
To: igt-dev@lists.freedesktop.org
Cc: Intel-gfx@lists.freedesktop.org
Subject: [PATCH i-g-t] tests/i915/query: Check no buffer overwrite
Date: Fri, 22 Nov 2019 10:43:07 +0000	[thread overview]
Message-ID: <20191122104307.30412-1-tvrtko.ursulin@linux.intel.com> (raw)

From: Tvrtko Ursulin <tvrtko.ursulin@intel.com>

Check that the engine query is not polluting the buffer past the size it
indicated it would write.

Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
---
 tests/i915/i915_query.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/tests/i915/i915_query.c b/tests/i915/i915_query.c
index ecbec3ae141d..92dd8f48a5d0 100644
--- a/tests/i915/i915_query.c
+++ b/tests/i915/i915_query.c
@@ -496,7 +496,8 @@ static void engines_invalid(int fd)
 {
 	struct drm_i915_query_engine_info *engines;
 	struct drm_i915_query_item item;
-	unsigned int len;
+	unsigned int i, len;
+	char *buf;
 
 	/* Flags is MBZ. */
 	memset(&item, 0, sizeof(item));
@@ -574,6 +575,20 @@ static void engines_invalid(int fd)
 		       -1, 0);
 	igt_assert(engines != MAP_FAILED);
 
+	/* Check no write past len. */
+	memset(engines, 0, 4096);
+	memset(&item, 0, sizeof(item));
+	item.query_id = DRM_I915_QUERY_ENGINE_INFO;
+	item.length = len;
+	item.data_ptr = to_user_pointer(engines);
+	i915_query_items(fd, &item, 1);
+	igt_assert_eq(item.length, len);
+	buf = (char *)engines;
+	buf += len;
+	for (i = 0; i < 4096 - len; i++, buf++)
+		igt_assert_f(*buf == 0, "Garbage %u bytes after buffer! (%x)\n",
+			     i, *buf);
+
 	/* PROT_NONE is similar to unmapped area. */
 	memset(engines, 0, len);
 	igt_assert_eq(mprotect(engines, len, PROT_NONE), 0);
-- 
2.20.1

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

WARNING: multiple messages have this Message-ID (diff)
From: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
To: igt-dev@lists.freedesktop.org
Cc: Intel-gfx@lists.freedesktop.org
Subject: [Intel-gfx] [PATCH i-g-t] tests/i915/query: Check no buffer overwrite
Date: Fri, 22 Nov 2019 10:43:07 +0000	[thread overview]
Message-ID: <20191122104307.30412-1-tvrtko.ursulin@linux.intel.com> (raw)
Message-ID: <20191122104307.DBEwSZo6NEo-dGRqU87Oh4UEfYGaJveieiRlfrnL9lw@z> (raw)

From: Tvrtko Ursulin <tvrtko.ursulin@intel.com>

Check that the engine query is not polluting the buffer past the size it
indicated it would write.

Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
---
 tests/i915/i915_query.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/tests/i915/i915_query.c b/tests/i915/i915_query.c
index ecbec3ae141d..92dd8f48a5d0 100644
--- a/tests/i915/i915_query.c
+++ b/tests/i915/i915_query.c
@@ -496,7 +496,8 @@ static void engines_invalid(int fd)
 {
 	struct drm_i915_query_engine_info *engines;
 	struct drm_i915_query_item item;
-	unsigned int len;
+	unsigned int i, len;
+	char *buf;
 
 	/* Flags is MBZ. */
 	memset(&item, 0, sizeof(item));
@@ -574,6 +575,20 @@ static void engines_invalid(int fd)
 		       -1, 0);
 	igt_assert(engines != MAP_FAILED);
 
+	/* Check no write past len. */
+	memset(engines, 0, 4096);
+	memset(&item, 0, sizeof(item));
+	item.query_id = DRM_I915_QUERY_ENGINE_INFO;
+	item.length = len;
+	item.data_ptr = to_user_pointer(engines);
+	i915_query_items(fd, &item, 1);
+	igt_assert_eq(item.length, len);
+	buf = (char *)engines;
+	buf += len;
+	for (i = 0; i < 4096 - len; i++, buf++)
+		igt_assert_f(*buf == 0, "Garbage %u bytes after buffer! (%x)\n",
+			     i, *buf);
+
 	/* PROT_NONE is similar to unmapped area. */
 	memset(engines, 0, len);
 	igt_assert_eq(mprotect(engines, len, PROT_NONE), 0);
-- 
2.20.1

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

             reply	other threads:[~2019-11-22 10:43 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-22 10:43 Tvrtko Ursulin [this message]
2019-11-22 10:43 ` [Intel-gfx] [PATCH i-g-t] tests/i915/query: Check no buffer overwrite Tvrtko Ursulin
2019-11-22 10:50 ` Chris Wilson
2019-11-22 10:50   ` [igt-dev] [Intel-gfx] " Chris Wilson
2019-11-22 10:50   ` Chris Wilson
2019-11-22 12:23 ` [igt-dev] ✓ Fi.CI.BAT: success for " Patchwork
2019-11-23 18:24 ` [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=20191122104307.30412-1-tvrtko.ursulin@linux.intel.com \
    --to=tvrtko.ursulin@linux.intel.com \
    --cc=Intel-gfx@lists.freedesktop.org \
    --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.