From: Ziyi Guo <n7l8m4@u.northwestern.edu>
To: Koby Elbaz <koby.elbaz@intel.com>,
Konstantin Sinyuk <konstantin.sinyuk@intel.com>,
Oded Gabbay <ogabbay@kernel.org>
Cc: Tomer Tayar <tomer.tayar@intel.com>,
farah kassabri <fkassabri@habana.ai>,
dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
Ziyi Guo <n7l8m4@u.northwestern.edu>
Subject: [PATCH] accel/habanalabs: reject zero-element timestamp buffer allocation
Date: Fri, 13 Feb 2026 17:35:30 +0000 [thread overview]
Message-ID: <20260213173530.2963318-1-n7l8m4@u.northwestern.edu> (raw)
A user can issue a DRM_IOCTL_HL_MEMORY ioctl with
op=HL_MEM_OP_TS_ALLOC and num_of_elements=0. The
allocate_timestamps_buffers() function only validates the upper bound
(> TS_MAX_ELEMENTS_NUM) but not zero, allowing num_of_elements=0 to
reach vmalloc_user(0 * sizeof(u64)), which triggers WARN_ON_ONCE(!size)
in __vmalloc_node_range().
On systems with panic_on_warn=1, this allows a local user with device
access to crash the kernel.
Add a zero check to the existing validation, matching the pattern
already present in HL_MEM_OP_ALLOC (memory.c:2214).
Fixes: 9158bf69e74f ("habanalabs: Timestamps buffers registration")
Signed-off-by: Ziyi Guo <n7l8m4@u.northwestern.edu>
---
drivers/accel/habanalabs/common/memory.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/accel/habanalabs/common/memory.c b/drivers/accel/habanalabs/common/memory.c
index 633db4bff46f..37dbb9a013bf 100644
--- a/drivers/accel/habanalabs/common/memory.c
+++ b/drivers/accel/habanalabs/common/memory.c
@@ -2176,8 +2176,9 @@ static int allocate_timestamps_buffers(struct hl_fpriv *hpriv, struct hl_mem_in
struct hl_mem_mgr *mmg = &hpriv->mem_mgr;
struct hl_mmap_mem_buf *buf;
- if (args->num_of_elements > TS_MAX_ELEMENTS_NUM) {
- dev_err(mmg->dev, "Num of elements exceeds Max allowed number (0x%x > 0x%x)\n",
+ if (args->num_of_elements > TS_MAX_ELEMENTS_NUM ||
+ args->num_of_elements == 0) {
+ dev_err(mmg->dev, "Invalid num of elements %u, valid range [1, 0x%x]\n",
args->num_of_elements, TS_MAX_ELEMENTS_NUM);
return -EINVAL;
}
--
2.34.1
next reply other threads:[~2026-02-13 17:35 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-13 17:35 Ziyi Guo [this message]
2026-02-13 21:24 ` Claude review: accel/habanalabs: reject zero-element timestamp buffer allocation Claude Code Review Bot
2026-02-13 21:24 ` Claude Code Review Bot
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=20260213173530.2963318-1-n7l8m4@u.northwestern.edu \
--to=n7l8m4@u.northwestern.edu \
--cc=dri-devel@lists.freedesktop.org \
--cc=fkassabri@habana.ai \
--cc=koby.elbaz@intel.com \
--cc=konstantin.sinyuk@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=ogabbay@kernel.org \
--cc=tomer.tayar@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