The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Triet Hoang <triet.hoang.dev@gmail.com>
To: royalnet026@gmail.com
Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
	ogabbay@kernel.org, tomeu@tomeuvizoso.net,
	triet.hoang.dev@gmail.com, markus.elfring@web.de
Subject: [PATCH v5 1/2] drm/rocket: Check allocations before use
Date: Tue, 18 Aug 2026 11:15:04 +0700	[thread overview]
Message-ID: <20260818041505.1579320-1-triet.hoang.dev@gmail.com> (raw)
In-Reply-To: <20260817093009.22359-1-royalnet026@gmail.com>

Check the result of kvmalloc_array() in rocket_job_push() and
kmalloc_objs() in rocket_job_open() before using the allocated
buffers.

Fixes: 0810d5ad88a1 ("accel/rocket: Add job submission IOCTL")

Signed-off-by: Triet Hoang <triet.hoang.dev@gmail.com>
---
Changes in v2:
- Free scheds when drm_sched_entity_init() fails.
- Initialize ret to 0.

Changes in v3:
- Move patch version descriptions below the '---' marker.

Changes in v4:
- Remove unnecessary initialization of ret to 0.
- Adjust commit message word wrapping.
- Add Fixes tag.

Changes in v5:
- Add check overflow before kvmalloc_array() in rocket_job_push().
---
 drivers/accel/rocket/rocket_job.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/drivers/accel/rocket/rocket_job.c b/drivers/accel/rocket/rocket_job.c
index ac51bff39833..15e93c355c38 100644
--- a/drivers/accel/rocket/rocket_job.c
+++ b/drivers/accel/rocket/rocket_job.c
@@ -189,9 +189,15 @@ static int rocket_job_push(struct rocket_job *job)
 	struct drm_gem_object **bos;
 	struct ww_acquire_ctx acquire_ctx;
 	int ret = 0;
+	size_t bos_count;
+
+	if (check_add_overflow(job->in_bo_count, job->out_bo_count, &bos_count))
+		return -EOVERFLOW;
+
+	bos = kvmalloc_array(bos_count, sizeof(void *), GFP_KERNEL);
+	if (!bos)
+		return -ENOMEM;
 
-	bos = kvmalloc_array(job->in_bo_count + job->out_bo_count, sizeof(void *),
-			     GFP_KERNEL);
 	memcpy(bos, job->in_bos, job->in_bo_count * sizeof(void *));
 	memcpy(&bos[job->in_bo_count], job->out_bos, job->out_bo_count * sizeof(void *));
 
@@ -501,6 +507,9 @@ int rocket_job_open(struct rocket_file_priv *rocket_priv)
 	unsigned int core;
 	int ret;
 
+	if (!scheds)
+		return -ENOMEM;
+
 	for (core = 0; core < rdev->num_cores; core++)
 		scheds[core] = &rdev->cores[core].sched;
 
@@ -509,9 +518,9 @@ int rocket_job_open(struct rocket_file_priv *rocket_priv)
 				    scheds,
 				    rdev->num_cores, NULL);
 	if (WARN_ON(ret))
-		return ret;
+		kfree(scheds);
 
-	return 0;
+	return ret;
 }
 
 void rocket_job_close(struct rocket_file_priv *rocket_priv)
-- 
2.53.0


  parent reply	other threads:[~2026-08-18  4:15 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20260817055315.C9AA41F000E9@smtp.kernel.org>
2026-08-17  7:20 ` [PATCH v2] drm/rocket: Check allocations before use Triet Hoang
2026-08-17  9:20   ` Markus Elfring
2026-08-17  9:31     ` [PATCH v3] " Triet Hoang
2026-08-17  9:55       ` Markus Elfring
2026-08-17 11:22         ` Triet Hoang
2026-08-17  9:30   ` [PATCH v2] " Igor Paunovic
2026-08-17 13:14     ` Triet Hoang
2026-08-17 14:01     ` [PATCH v4 1/2] " Triet Hoang
2026-08-17 14:01       ` [PATCH v4 2/2] drm/rocket: Keep scheduler allocation in rocket_file_priv Triet Hoang
2026-08-17 17:06         ` Markus Elfring
2026-08-17 16:40       ` [PATCH v4 1/2] drm/rocket: Check allocations before use Markus Elfring
2026-08-18  1:31         ` Triet Hoang
2026-08-18  5:48           ` [v4 " Markus Elfring
2026-08-18  6:21             ` [PATCH] " Triet Hoang
2026-08-17 14:28     ` [PATCH v2] " Triet Hoang
2026-08-18  1:55       ` Triet Hoang
2026-08-18  1:56       ` Triet Hoang
2026-08-18  4:15     ` Triet Hoang [this message]
2026-08-18  4:15       ` [PATCH v5 2/2] drm/rocket: Keep scheduler allocation in rocket_file_priv Triet Hoang
2026-08-18  4:23         ` [PATCH v5] drm/rocket: Check allocations before use Triet Hoang

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=20260818041505.1579320-1-triet.hoang.dev@gmail.com \
    --to=triet.hoang.dev@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=markus.elfring@web.de \
    --cc=ogabbay@kernel.org \
    --cc=royalnet026@gmail.com \
    --cc=tomeu@tomeuvizoso.net \
    /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