Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Shuicheng Lin <shuicheng.lin@intel.com>
To: intel-xe@lists.freedesktop.org
Cc: Shuicheng Lin <shuicheng.lin@intel.com>,
	Matthew Brost <matthew.brost@intel.com>,
	Ashutosh Dixit <ashutosh.dixit@intel.com>
Subject: [PATCH 3/3] drm/xe/oa: Limit num_syncs to prevent oversized allocations
Date: Fri,  5 Dec 2025 19:05:10 +0000	[thread overview]
Message-ID: <20251205190506.2426471-8-shuicheng.lin@intel.com> (raw)
In-Reply-To: <20251205190506.2426471-5-shuicheng.lin@intel.com>

The OA open parameters did not validate num_syncs, allowing
userspace to pass arbitrarily large values, potentially
leading to excessive allocations.

Add checks to ensure that num_syncs does not exceed XE_MAX_SYNCS,
returning -EINVAL when the limit is violated.

Fixes: c8507a25cebd ("drm/xe/oa/uapi: Define and parse OA sync properties")
Cc: Matthew Brost <matthew.brost@intel.com>
Cc: Ashutosh Dixit <ashutosh.dixit@intel.com>
Signed-off-by: Shuicheng Lin <shuicheng.lin@intel.com>
---
 drivers/gpu/drm/xe/xe_oa.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/drivers/gpu/drm/xe/xe_oa.c b/drivers/gpu/drm/xe/xe_oa.c
index cc48663c2b48..7477c27a4ba2 100644
--- a/drivers/gpu/drm/xe/xe_oa.c
+++ b/drivers/gpu/drm/xe/xe_oa.c
@@ -1254,6 +1254,11 @@ static int xe_oa_set_no_preempt(struct xe_oa *oa, u64 value,
 static int xe_oa_set_prop_num_syncs(struct xe_oa *oa, u64 value,
 				    struct xe_oa_open_param *param)
 {
+	if (value > XE_MAX_SYNCS) {
+		drm_dbg(&oa->xe->drm, "num_syncs %llu must be <= %u\n",
+			value, XE_MAX_SYNCS);
+		return -EINVAL;
+	}
 	param->num_syncs = value;
 	return 0;
 }
@@ -1404,6 +1409,12 @@ static int xe_oa_parse_syncs(struct xe_oa *oa,
 	}
 
 	if (param->num_syncs) {
+		if (param->num_syncs > XE_MAX_SYNCS) {
+			drm_dbg(&oa->xe->drm, "num_syncs %d must be <= %u\n",
+				param->num_syncs, XE_MAX_SYNCS);
+			ret = -EINVAL;
+			goto exit;
+		}
 		param->syncs = kcalloc(param->num_syncs, sizeof(*param->syncs), GFP_KERNEL);
 		if (!param->syncs) {
 			ret = -ENOMEM;
-- 
2.50.1


  parent reply	other threads:[~2025-12-05 19:08 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-05 19:05 [PATCH 0/3] Limit num_syncs to prevent oversized allocations Shuicheng Lin
2025-12-05 19:05 ` [PATCH 1/3] drm/xe/exec: " Shuicheng Lin
2025-12-05 21:23   ` Matthew Brost
2025-12-05 19:05 ` [PATCH 2/3] drm/xe/vm: " Shuicheng Lin
2025-12-05 19:05 ` Shuicheng Lin [this message]
2025-12-05 20:36   ` [PATCH 3/3] drm/xe/oa: " Dixit, Ashutosh
2025-12-05 20:55     ` Matthew Brost
2025-12-05 21:06       ` Dixit, Ashutosh
2025-12-05 22:03 ` ✗ CI.checkpatch: warning for " Patchwork
2025-12-05 22:05 ` ✓ CI.KUnit: success " Patchwork
2025-12-05 23:08 ` ✓ Xe.CI.BAT: " 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=20251205190506.2426471-8-shuicheng.lin@intel.com \
    --to=shuicheng.lin@intel.com \
    --cc=ashutosh.dixit@intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=matthew.brost@intel.com \
    /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