* [PATCH] accel/habanalabs: check for NULL block_device before dereferencing
@ 2026-11-28 22:21 TAKANO Mitsuhiro via B4 Relay
0 siblings, 0 replies; only message in thread
From: TAKANO Mitsuhiro via B4 Relay @ 2026-11-28 22:21 UTC (permalink / raw)
To: Konstantin Sinyuk, Koby Elbaz, Oded Gabbay
Cc: dri-devel, linux-kernel, TAKANO Mitsuhiro
From: TAKANO Mitsuhiro <takano32@gmail.com>
In hl_dio_fd_register(), bd->bd_disk is dereferenced right after reading
sb->s_bdev, before bd is checked for NULL. If the file descriptor refers
to a file on a non-block-backed filesystem (such as tmpfs or NFS),
sb->s_bdev is NULL and dereferencing bd->bd_disk triggers a NULL pointer
dereference.
Check bd before dereferencing bd->bd_disk.
Fixes: 8cbacc9a2703 ("accel/habanalabs: add NVMe Direct I/O (HLDIO) infrastructure")
Signed-off-by: TAKANO Mitsuhiro <takano32@gmail.com>
---
Verification: compile-tested on x86_64 with CONFIG_DRM_ACCEL_HABANALABS=m
and CONFIG_HL_HLDIO=y (make W=1 drivers/accel/habanalabs/common/hldio.o;
0 warnings) and checked with scripts/checkpatch.pl --strict. Checked
against linux-next (next-20261127) and lore.kernel.org for duplicates.
Not runtime-tested on Habanalabs hardware.
The change and the changelog text were produced with an AI coding
assistant (Gemini) working from the tree; I reviewed the diff and the
reasoning, and I am responsible for the submission.
---
drivers/accel/habanalabs/common/hldio.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/accel/habanalabs/common/hldio.c b/drivers/accel/habanalabs/common/hldio.c
index c33c817a9..aa3b38be9 100644
--- a/drivers/accel/habanalabs/common/hldio.c
+++ b/drivers/accel/habanalabs/common/hldio.c
@@ -94,8 +94,6 @@ static int hl_dio_fd_register(struct hl_ctx *ctx, int fd, struct hl_dio_fd *f)
inode = file_inode(f->filp);
sb = inode->i_sb;
- bd = sb->s_bdev;
- gd = bd->bd_disk;
if (inode->i_blocks << sb->s_blocksize_bits < i_size_read(inode)) {
dev_err(hdev->dev, "sparse files are not currently supported\n");
@@ -103,11 +101,13 @@ static int hl_dio_fd_register(struct hl_ctx *ctx, int fd, struct hl_dio_fd *f)
goto fput;
}
- if (!bd || !gd) {
+ bd = sb->s_bdev;
+ if (!bd || !bd->bd_disk) {
dev_err(hdev->dev, "invalid block device\n");
rc = -ENODEV;
goto fput;
}
+ gd = bd->bd_disk;
/* Get the underlying device from the block device */
disk_dev = disk_to_dev(gd);
if (!dma_pci_p2pdma_supported(disk_dev)) {
---
base-commit: f93eb7cfc4bfa5d46340f360873726e3e77f2365
change-id: 20261128-b4-hldio-null-bdev-79a0ab174f01
Best regards,
--
TAKANO Mitsuhiro <takano32@gmail.com>
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-28 22:21 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-28 22:21 [PATCH] accel/habanalabs: check for NULL block_device before dereferencing TAKANO Mitsuhiro via B4 Relay
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®