From: Nicola Vetrini <nicola.vetrini@bugseng.com>
To: Jan Beulich <jbeulich@suse.com>
Cc: xen-devel@lists.xenproject.org,
Gyujeong Jin <wlsrbwjd7232@gmail.com>,
Stefano Stabellini <sstabellini@kernel.org>,
Julien Grall <julien@xen.org>,
Bertrand Marquis <bertrand.marquis@arm.com>,
Michal Orzel <michal.orzel@amd.com>
Subject: Re: [BUG] Potential double-free in Xen dt-overlay attach/remove error path
Date: Fri, 10 Apr 2026 12:06:46 +0200 [thread overview]
Message-ID: <aaeff4b4915c28a6ac5a7abfa4ab7679@bugseng.com> (raw)
In-Reply-To: <c4961231-7882-49d8-8c68-c014ca0a5e4f@suse.com>
On 2026-04-10 08:31, Jan Beulich wrote:
> On 09.04.2026 23:28, Gyujeong Jin wrote:
>> Hello Team, I was advised to report this issue in this way because
>> dt-overlay is currently experimental and not security supported.
>>
>> I would like to report a potential memory safety issue in Xen related
>> to
>> the Device Tree overlay handling logic.
>> ------------------------------
>> Problem Description
>>
>> A double-free / use-after-free condition may occur in the dt-overlay
>> handling path when an overlay attachment fails and the same overlay is
>> later removed.
>>
>> The issue arises because rangeset objects are freed on the failure
>> path of
>> handle_attach_overlay_nodes(), but the corresponding pointers are not
>> cleared. Subsequently, handle_remove_overlay_nodes() may operate on
>> these
>> stale pointers, leading to a second free.
>> Affected Component
>>
>> - Xen ARM
>> - Device Tree overlay subsystem
>> - File: xen/common/device-tree/dt-overlay.c
>>
>> Relevant functions:
>>
>> - handle_attach_overlay_nodes()
>> - handle_remove_overlay_nodes()
>>
>> Impact
>>
>> This issue may lead to:
>>
>> - Double-free of rangeset structures
>> - Use-after-free when accessing stale pointers
>> - Potential hypervisor crash (DoS)
>> - Possible memory corruption depending on allocator behavior
>>
>> Given that this occurs in the hypervisor context, the impact could
>> extend
>> beyond a simple crash under certain conditions.
>> Root Cause
>>
>> The issue originates from inconsistent memory management between the
>> attach
>> failure path and the remove path.
>>
>> In handle_attach_overlay_nodes(), the failure path frees rangeset
>> objects:
>>
>> static long handle_attach_overlay_nodes(...)
>> {
>> ...
>>
>> if ( entry )
>> {
>> rangeset_destroy(entry->irq_ranges);
>> rangeset_destroy(entry->iomem_ranges);
>> }
>>
>> return rc;
>> }
>>
>> However, the corresponding pointers (entry->irq_ranges and
>> entry->iomem_ranges) are not set to NULL afterward, leaving dangling
>> pointers in the entry structure.
>
> Further to this, am I overlooking any check preventing an already
> created
> pair of rangesets to be replaced by new ones, leaking the original
> pair?
>
> And then there's a Misra issue as well: dt_overlay_domctl() has
> unreachable
> code. Anything other than XEN_DOMCTL_DT_OVERLAY_ATTACH is excluded at
> the
> top, so the "else" body near the bottom is unreachable. (This in turn
> makes
> me wonder: How come there's no "detach"?) Yet then, that's probably
> pretty
> meaningless, as there look to be other issues (Misra and general
> robustness
> ones) as well.
>
> Jan
Is it by any chance enabled in *-allcode analyses? I don't see such
reports for unreachable code on ARM64.
--
Nicola Vetrini, B.Sc.
Software Engineer
BUGSENG (https://bugseng.com)
LinkedIn: https://www.linkedin.com/in/nicola-vetrini-a42471253
next prev parent reply other threads:[~2026-04-10 10:07 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-09 21:28 [BUG] Potential double-free in Xen dt-overlay attach/remove error path Gyujeong Jin
2026-04-10 6:31 ` Jan Beulich
2026-04-10 10:06 ` Nicola Vetrini [this message]
2026-04-10 10:11 ` Andrew Cooper
2026-04-10 12:58 ` Orzel, Michal
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=aaeff4b4915c28a6ac5a7abfa4ab7679@bugseng.com \
--to=nicola.vetrini@bugseng.com \
--cc=bertrand.marquis@arm.com \
--cc=jbeulich@suse.com \
--cc=julien@xen.org \
--cc=michal.orzel@amd.com \
--cc=sstabellini@kernel.org \
--cc=wlsrbwjd7232@gmail.com \
--cc=xen-devel@lists.xenproject.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.