mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: TAKANO Mitsuhiro via B4 Relay <devnull+takano32.gmail.com@kernel.org>
To: Konstantin Sinyuk <ksinyuk@kernel.org>,
	 Koby Elbaz <elbaz.koby@gmail.com>,
	Oded Gabbay <ogabbay@kernel.org>
Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
	 TAKANO Mitsuhiro <takano32@gmail.com>
Subject: [PATCH] accel/habanalabs: check for NULL block_device before dereferencing
Date: Sat, 28 Nov 2026 22:21:04 +0000	[thread overview]
Message-ID: <20261128-b4-hldio-null-bdev-v1-1-ee65516c9f1f@gmail.com> (raw)

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>



                 reply	other threads:[~2026-11-28 22:21 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261128-b4-hldio-null-bdev-v1-1-ee65516c9f1f@gmail.com \
    --to=devnull+takano32.gmail.com@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=elbaz.koby@gmail.com \
    --cc=ksinyuk@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ogabbay@kernel.org \
    --cc=takano32@gmail.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

all inboxes | Powered by JetHome®