From: sashiko-bot@kernel.org
To: "Thierry Reding" <thierry.reding@kernel.org>
Cc: "Vasily Gorbik" <gor@linux.ibm.com>,
"Christian Borntraeger" <borntraeger@linux.ibm.com>,
linux-trace-kernel@vger.kernel.org, robh@kernel.org,
dri-devel@lists.freedesktop.org, conor+dt@kernel.org,
"Alexander Gordeev" <agordeev@linux.ibm.com>,
media-ci@linuxtv.org, devicetree@vger.kernel.org,
linux-s390@vger.kernel.org, "Heiko Carstens" <hca@linux.ibm.com>
Subject: Re: [PATCH v6 08/12] dma-buf: heaps: Add debugfs support
Date: Fri, 04 Sep 2026 11:34:32 +0000 [thread overview]
Message-ID: <20260904113432.BD9FB1F00A3D@smtp.kernel.org> (raw)
In-Reply-To: <20260904-tegra-vpr-v6-8-79042cfa8de5@nvidia.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
New issues:
- [Medium] Incomplete resource cleanup in the newly added `dma_heap_exit()` leaves dynamically allocated heaps, character devices, and sysfs devices active but orphaned.
Pre-existing issues:
- [High] Race condition in `dma_heap_add` error path leads to a critical Use-After-Free of `struct dma_heap` due to premature device exposure.
--
commit e23fa30f3769a236faddd443565a8ccf6a9af125
Author: Thierry Reding <treding@nvidia.com>
dma-buf: heaps: Add debugfs support
This commit adds a callback to struct dma_heap_ops to show heap state in
debugfs. It creates a top-level dma_heap directory where individual heap
files are registered. A new dma_heap_exit() function is also introduced to
clean up the class and debugfs directory on module exit.
> diff --git a/drivers/dma-buf/dma-heap.c b/drivers/dma-buf/dma-heap.c
> index 8a6c2b6e0cc60..65c80dac65009 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
> +
> mutex_unlock(&heap_list_lock);
>
> return heap;
[Severity: High]
This isn't a bug introduced by this patch, but is it possible for a concurrent
userspace process to trigger a use-after-free during the error path of
dma_heap_add()?
Earlier in dma_heap_add(), the character device is exposed to userspace before
the name uniqueness check is performed:
ret = cdev_add(&heap->heap_cdev, heap->heap_devt, 1);
...
dev_ret = device_create(dma_heap_class, ...);
...
/* check the name is unique */
list_for_each_entry(h, &heap_list, list) {
if (!strcmp(h->name, exp_info->name)) {
...
goto err3;
}
}
If another driver attempts to register a heap with a duplicate name, could a
userspace process open the device before the uniqueness check fails? This would
store the heap pointer in the open file descriptor. When the uniqueness check
then fails, the error path executes kfree(heap), leaving the open file
descriptor pointing to freed memory.
[ ... ]
> @@ -335,6 +377,16 @@ static int dma_heap_init(void)
> }
> dma_heap_class->devnode = dma_heap_devnode;
>
> + dma_heap_init_debugfs();
> +
> return 0;
> }
> subsys_initcall(dma_heap_init);
> +
> +static void __exit dma_heap_exit(void)
> +{
> + dma_heap_exit_debugfs();
> + class_destroy(dma_heap_class);
[Severity: Medium]
Does this successfully tear down the resources if there are dynamically
allocated heaps still registered?
The dma_heap_exit() function destroys the sysfs class by calling
class_destroy(), but it doesn't appear to iterate over heap_list to cleanly
tear down the individual registered heaps.
Can this leave dangling references and lead to sysfs issues, since
device_destroy() and cdev_del() are never called for any active heaps before
the class is destroyed?
> + unregister_chrdev_region(dma_heap_devt, NUM_HEAP_MINORS);
> +}
> +__exitcall(dma_heap_exit);
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260904-tegra-vpr-v6-0-79042cfa8de5@nvidia.com?part=8
next prev parent reply other threads:[~2026-09-04 11:34 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-04 10:44 [PATCH v6 00/12] dma-buf: heaps: Add support for Tegra VPR Thierry Reding
2026-09-04 10:44 ` [PATCH v6 01/12] dt-bindings: reserved-memory: Document " Thierry Reding
2026-09-04 10:59 ` sashiko-bot
2026-09-04 10:44 ` [PATCH v6 02/12] dt-bindings: display: tegra: Document memory regions Thierry Reding
2026-09-04 10:56 ` sashiko-bot
2026-09-04 10:44 ` [PATCH v6 03/12] dt-bindings: gpu: host1x: Document memory-regions for NVDEC Thierry Reding
2026-09-04 11:03 ` sashiko-bot
2026-09-04 10:44 ` [PATCH v6 04/12] arm64/mm: Export set_direct_map_*_noflush() APIs Thierry Reding
2026-09-04 11:13 ` sashiko-bot
2026-09-04 10:44 ` [PATCH v6 05/12] bitmap: Add bitmap_allocate() function Thierry Reding
2026-09-04 11:13 ` sashiko-bot
2026-09-04 10:44 ` [PATCH v6 06/12] of: Export of_node_to_nid() Thierry Reding
2026-09-04 11:21 ` sashiko-bot
2026-09-04 10:44 ` [PATCH v6 07/12] mm/cma: Introduce cma_alloc_at() API Thierry Reding
2026-09-04 11:22 ` sashiko-bot
2026-09-04 10:44 ` [PATCH v6 08/12] dma-buf: heaps: Add debugfs support Thierry Reding
2026-09-04 11:34 ` sashiko-bot [this message]
2026-09-04 10:45 ` [PATCH v6 09/12] dma-buf: heaps: Add support for Tegra VPR Thierry Reding
2026-09-04 11:38 ` sashiko-bot
2026-09-04 10:45 ` [PATCH v6 10/12] arm64: tegra: Add VPR placeholder node on Tegra234 Thierry Reding
2026-09-04 11:54 ` sashiko-bot
2026-09-04 10:45 ` [PATCH v6 11/12] arm64: tegra: Hook up VPR to host1x Thierry Reding
2026-09-04 11:49 ` sashiko-bot
2026-09-04 10:45 ` [PATCH v6 12/12] arm64: tegra: Add VPR placeholder node on Tegra264 Thierry Reding
2026-09-04 11:53 ` sashiko-bot
2026-09-04 11:41 ` [PATCH v6 00/12] dma-buf: heaps: Add support for Tegra VPR Will Deacon
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=20260904113432.BD9FB1F00A3D@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