From: Robin Murphy <robin.murphy@arm.com>
To: Anthony Iliopoulos <ailiop@suse.com>, Avi Weiss <thnkslprpt@gmail.com>
Cc: Marek Szyprowski <m.szyprowski@samsung.com>,
iommu@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] dma-debug: Avoid uninitialized hash traversal in mapping dumps
Date: Mon, 16 Nov 2026 13:45:25 +0000 [thread overview]
Message-ID: <609175e0-4e1c-4130-a9f1-0cfc7815c134@arm.com> (raw)
In-Reply-To: <E9412813-7A76-46D0-94E5-0537E9FF5DB8@suse.com>
On 16/11/2026 12:09 am, Anthony Iliopoulos wrote:
> On Sun, Nov 15, 2026 at 10:25:06AM +0200, Avi Weiss wrote:
>> Booting with dma_debug=off causes dma_debug_init() to return before
>> initializing the hash buckets. The debugfs dump file is registered
>> independently, so reading it traverses an uninitialized list and
>> triggers a NULL pointer dereference in dump_show(). The
>> debug_dma_dump_mappings() helper has the same unchecked traversal.
>
> So the debug_dma_dump_mappings() issue seems preexisting (the risk was
> there since its introduction in commit ac26c18bd35d, given that it
> doesn't check if dma_debug has been initialized), and it is not related
> to decoupling the debugfs init.
>
>> Skip both dump paths until dma_debug_initialized is set. Check the
>> initialization state rather than global_disable so that mappings
>> recorded before DMA debugging disables itself at runtime remain
>> available.
>
> I suppose this makes sense for debug_dma_dump_mappings, but I am not
> sure we need this for dump_show. See my next comment.
>
>> With CONFIG_DMA_API_DEBUG=y and CONFIG_DEBUG_FS=y, reading the dump
>> with dma_debug=off triggers an oops in the unpatched kernel. The
>> patched kernel returns an empty dump, while dumping with DMA debugging
>> enabled still returns mapping information.
>>
>> Fixes: 173735c346c4 ("dma-debug: fix debugfs initialization order")
>> Signed-off-by: Avi Weiss <thnkslprpt@gmail.com>
>> ---
>> kernel/dma/debug.c | 6 ++++++
>> 1 file changed, 6 insertions(+)
>>
>> diff --git a/kernel/dma/debug.c b/kernel/dma/debug.c
>> index 36c1f7cbb2ae..2f487246d8ce 100644
>> --- a/kernel/dma/debug.c
>> +++ b/kernel/dma/debug.c
>> @@ -543,6 +543,9 @@ void debug_dma_dump_mappings(struct device *dev)
>> int idx;
>> phys_addr_t cln;
>>
>> + if (!dma_debug_initialized)
>> + return;
>> +
>> for (idx = 0; idx < HASH_SIZE; idx++) {
>> struct hash_bucket *bucket = &dma_entry_hash[idx];
>> struct dma_debug_entry *entry;
>> @@ -576,6 +579,9 @@ static int dump_show(struct seq_file *seq, void *v)
>> int idx;
>> phys_addr_t cln;
>>
>> + if (!dma_debug_initialized)
>> + return 0;
>> +
>
> I think it makes better sense to skip creating debugfs files altogether
> when debugging is disabled, which was also the case before 15b28bbcd567.
TBH there's probably an argument for just getting rid of
debug_dma_dump_mappings() now too... Hands up anyone who's using a
20-year-old AMD GART as any kind of development machine at all, let
alone for DMA API debugging of new drivers?
Anyone?
Cheers,
Robin.
>
>> for (idx = 0; idx < HASH_SIZE; idx++) {
>> struct hash_bucket *bucket = &dma_entry_hash[idx];
>> struct dma_debug_entry *entry;
>>
>> base-commit: 97d73c8251226cf27cc6656b4c542869bb8c69fa
>> --
>> 2.43.0
>>
>
> Regards,
> Anthony
prev parent reply other threads:[~2026-11-16 13:45 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-15 8:25 Avi Weiss
2026-11-16 0:09 ` Anthony Iliopoulos
2026-11-16 13:45 ` Robin Murphy [this message]
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=609175e0-4e1c-4130-a9f1-0cfc7815c134@arm.com \
--to=robin.murphy@arm.com \
--cc=ailiop@suse.com \
--cc=iommu@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=m.szyprowski@samsung.com \
--cc=thnkslprpt@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®