From: Jordan Justen <jordan.l.justen@intel.com>
To: intel-gfx <intel-gfx@lists.freedesktop.org>
Cc: dri-devel <dri-devel@lists.freedesktop.org>
Subject: [Intel-gfx] [PATCH 4/4] drm/i915/guc: Verify hwconfig blob matches supported format
Date: Mon, 7 Feb 2022 11:28:54 -0800 [thread overview]
Message-ID: <20220207192854.862959-5-jordan.l.justen@intel.com> (raw)
In-Reply-To: <20220207192854.862959-1-jordan.l.justen@intel.com>
Signed-off-by: Jordan Justen <jordan.l.justen@intel.com>
---
.../gpu/drm/i915/gt/uc/intel_guc_hwconfig.c | 26 +++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/drivers/gpu/drm/i915/gt/uc/intel_guc_hwconfig.c b/drivers/gpu/drm/i915/gt/uc/intel_guc_hwconfig.c
index ce6088f112d4..695ef7a8f519 100644
--- a/drivers/gpu/drm/i915/gt/uc/intel_guc_hwconfig.c
+++ b/drivers/gpu/drm/i915/gt/uc/intel_guc_hwconfig.c
@@ -71,6 +71,26 @@ static int guc_hwconfig_discover_size(struct intel_guc_hwconfig *hwconfig)
return 0;
}
+static int verify_hwconfig_blob(const struct intel_guc_hwconfig *hwconfig)
+{
+ if (hwconfig->size % 4 != 0 || hwconfig->ptr == NULL)
+ return -EINVAL;
+
+ struct drm_i915_query_hwconfig_blob_item *pos = hwconfig->ptr;
+ u32 remaining = (hwconfig->size / 4);
+ while (remaining > 0) {
+ if (remaining < 2)
+ return -EINVAL;
+ if (pos->length > remaining - 2)
+ return -EINVAL;
+ remaining -= 2 + pos->length;
+ pos = (void *)&pos->data[pos->length];
+ }
+
+ DRM_INFO("hwconfig blob format appears valid\n");
+ return 0;
+}
+
static int guc_hwconfig_fill_buffer(struct intel_guc_hwconfig *hwconfig)
{
struct intel_guc *guc = hwconfig_to_guc(hwconfig);
@@ -91,6 +111,12 @@ static int guc_hwconfig_fill_buffer(struct intel_guc_hwconfig *hwconfig)
if (ret >= 0)
memcpy(hwconfig->ptr, vaddr, hwconfig->size);
+ if (verify_hwconfig_blob(hwconfig)) {
+ DRM_ERROR("Ignoring invalid hwconfig blob received from "
+ "GuC!\n");
+ return -EINVAL;
+ }
+
i915_vma_unpin_and_release(&vma, I915_VMA_RELEASE_MAP);
return ret;
--
2.34.1
next prev parent reply other threads:[~2022-02-07 19:29 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-07 19:28 [Intel-gfx] [PATCH 0/4] GuC HWCONFIG with documentation Jordan Justen
2022-02-07 19:28 ` [Intel-gfx] [PATCH 1/4] drm/i915/guc: Add fetch of hwconfig table Jordan Justen
2022-02-07 19:28 ` [Intel-gfx] [PATCH 2/4] drm/i915/uapi: Add query for hwconfig blob Jordan Justen
2022-02-07 19:28 ` [Intel-gfx] [PATCH 3/4] drm/i915/uapi: Add struct drm_i915_query_hwconfig_blob_item Jordan Justen
2022-02-08 0:07 ` kernel test robot
2022-02-08 9:19 ` Tvrtko Ursulin
2022-02-07 19:28 ` Jordan Justen [this message]
2022-02-07 22:45 ` [Intel-gfx] [PATCH 4/4] drm/i915/guc: Verify hwconfig blob matches supported format kernel test robot
2022-02-07 22:45 ` kernel test robot
2022-02-07 23:36 ` kernel test robot
2022-02-08 9:36 ` Tvrtko Ursulin
2022-02-08 22:45 ` Jordan Justen
2022-02-07 19:59 ` [Intel-gfx] ✗ Fi.CI.BUILD: failure for GuC HWCONFIG with documentation 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=20220207192854.862959-5-jordan.l.justen@intel.com \
--to=jordan.l.justen@intel.com \
--cc=dri-devel@lists.freedesktop.org \
--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