Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Thierry Reding" <thierry.reding@kernel.org>
Cc: devicetree@vger.kernel.org, dri-devel@lists.freedesktop.org,
	"Vasily Gorbik" <gor@linux.ibm.com>,
	robh@kernel.org, linux-s390@vger.kernel.org,
	"Alexander Gordeev" <agordeev@linux.ibm.com>,
	linux-trace-kernel@vger.kernel.org, media-ci@linuxtv.org,
	"Christian Borntraeger" <borntraeger@linux.ibm.com>,
	conor+dt@kernel.org, "Heiko Carstens" <hca@linux.ibm.com>
Subject: Re: [PATCH v5 06/10] dma-buf: heaps: Add debugfs support
Date: Fri, 14 Aug 2026 15:43:17 +0000	[thread overview]
Message-ID: <20260814154318.03BF41F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260814-tegra-vpr-v5-6-71832b5d0246@nvidia.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] A race condition in `dma_heap_add()` allows userspace to trigger an exploitable use-after-free by opening the character device before the initialization completes.
--

--- Patch [6]: [PATCH v5 06/10] dma-buf: heaps: Add debugfs support ---
commit f236972ccf6e5f7088156d7adcf0aed10121c6c6
Author: Thierry Reding <treding@nvidia.com>

dma-buf: heaps: Add debugfs support
    
Add a callback to struct dma_heap_ops that heap providers can implement
to show information about the state of the heap in debugfs. A top-level
directory named "dma_heap" is created in debugfs and individual files
will be named after the heaps.

> diff --git a/drivers/dma-buf/dma-heap.c b/drivers/dma-buf/dma-heap.c
> index 3937dd41bb0f6..f279b8fdd3ce0 100644
> --- a/drivers/dma-buf/dma-heap.c
> +++ b/drivers/dma-buf/dma-heap.c

[ ... ]

> @@ -299,6 +334,13 @@ struct dma_heap *dma_heap_add(const struct dma_heap_export_info *exp_info)
>  
>  	/* Add heap to the list */
>  	list_add(&heap->list, &heap_list);
> +
> +#ifdef CONFIG_DEBUG_FS
> +	if (heap->ops && heap->ops->show)
> +		debugfs_create_file(heap->name, 0444, dma_heap_debugfs_dir,
> +				    heap, &dma_heap_debug_fops);
> +#endif
> +

[Severity: High]
This is a pre-existing issue, but is there a race condition in this function
that could lead to a use-after-free?

In dma_heap_add(), cdev_add() is called earlier, making the device accessible.
If the duplicate name check fails, it goes to the error path, destroying the
device and freeing the heap structure:

drivers/dma-buf/dma-heap.c:dma_heap_add() {
    ...
    ret = cdev_add(&heap->heap_cdev, heap->heap_devt, 1);
    ...
    list_for_each_entry(h, &heap_list, list) {
        if (!strcmp(h->name, exp_info->name)) {
            ...
            goto err3;
        }
    }
    ...
err3:
    device_destroy(dma_heap_class, heap->heap_devt);
    ...
err0:
    kfree(heap);
    return err_ret;
}

If a user concurrently opens the device between cdev_add() and the kfree()
on the error path, would the resulting file descriptor retain a dangling
pointer to the freed heap structure in file->private_data?

Could a subsequent ioctl() on this file descriptor then dereference the freed
heap, triggering a use-after-free?

>  	mutex_unlock(&heap_list_lock);
>  
>  	return heap;

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260814-tegra-vpr-v5-0-71832b5d0246@nvidia.com?part=6

  reply	other threads:[~2026-08-14 15:43 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-14 15:29 [PATCH v5 00/10] dma-buf: heaps: Add support for Tegra VPR Thierry Reding
2026-08-14 15:29 ` [PATCH v5 01/10] dt-bindings: reserved-memory: Document " Thierry Reding
2026-08-14 15:39   ` sashiko-bot
2026-08-14 15:29 ` [PATCH v5 02/10] dt-bindings: display: tegra: Document memory regions Thierry Reding
2026-08-14 15:36   ` sashiko-bot
2026-08-14 15:29 ` [PATCH v5 03/10] dt-bindings: gpu: host1x: Document memory-regions for NVDEC Thierry Reding
2026-08-14 15:39   ` sashiko-bot
2026-08-14 15:29 ` [PATCH v5 04/10] bitmap: Add bitmap_allocate() function Thierry Reding
2026-08-14 15:36   ` sashiko-bot
2026-08-14 15:29 ` [PATCH v5 05/10] mm/cma: Introduce cma_alloc_at() API Thierry Reding
2026-08-14 15:38   ` sashiko-bot
2026-08-14 15:29 ` [PATCH v5 06/10] dma-buf: heaps: Add debugfs support Thierry Reding
2026-08-14 15:43   ` sashiko-bot [this message]
2026-08-14 15:29 ` [PATCH v5 07/10] dma-buf: heaps: Add support for Tegra VPR Thierry Reding
2026-08-14 15:43   ` sashiko-bot
2026-08-14 15:29 ` [PATCH v5 08/10] arm64: tegra: Add VPR placeholder node on Tegra234 Thierry Reding
2026-08-14 15:38   ` sashiko-bot
2026-08-14 15:29 ` [PATCH v5 09/10] arm64: tegra: Hook up VPR to host1x Thierry Reding
2026-08-14 15:44   ` sashiko-bot
2026-08-14 15:29 ` [PATCH v5 10/10] arm64: tegra: Add VPR placeholder node on Tegra264 Thierry Reding
2026-08-14 15:41   ` sashiko-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=20260814154318.03BF41F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=agordeev@linux.ibm.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=linux-s390@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=media-ci@linuxtv.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=thierry.reding@kernel.org \
    /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