[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: RISC-V bugs from scanning


  • To: xen-devel@xxxxxxxxxxxxxxxxxxxx
  • From: Baptiste Le Duc <baptiste.le-duc@xxxxxxxxxx>
  • Date: Fri, 4 Dec 2026 11:13:57 +0100
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=vates.tech header.i="@vates.tech" header.h="From:Subject:Date:Message-ID:To:MIME-Version:Content-Type:Content-Transfer-Encoding:In-Reply-To:References:Feedback-ID"
  • Autocrypt: addr=baptiste.le-duc@xxxxxxxxxx; keydata= xsBNBGoPSX8BCADSuTikqW3FD4mscQugY1thRaKlIhcJ2G9YCWYXAlp+xosvTlzfIftOZZim 750MLvyKtLPkQzB6TZtFZBiexSraaF/MdDKRTT5DcVa3r7ZnHgqMclWlPa4ioysS4yFcJanL cyNOT7HUFvIdirMMqiViedfYtS0GORPBBPVISD6ClMz3ecHIxqllfq9CHYQn4amKEfHmh6tm Rufo4Gjl6x8cUFZZlRQf+aCmUzdSPA0P5u3sueYH1uEz4w/jbD53MlKqzCvxUeOsfS2swTQA 6mS9jIgOjNadpUTOzKfDHMgFirtG+HFpm45Nwp6KQizxgDVOfTnOfVHm5Gwqm3ETl9y5ABEB AAHNPEJhcHRpc3RlIExlIER1YyAoVmF0ZXMgWXViaWtleSkgPGJhcHRpc3RlLmxlLWR1Y0B2 YXRlcy50ZWNoPsLAjgQTAQoAOBYhBGiSJ6HgW88MgT/gfu2Cu2XL9M6QBQJqD0l/AhsDBQsJ CAcCBhUKCQgLAgQWAgMBAh4BAheAAAoJEO2Cu2XL9M6QuMcH/ihiy/Nrxp919AmY0ENnc0NK r/2LDvW/hrX4FfbpxAmrGmQ7MU1aQTk0JDbfcsG8OYH6wO5sqnXb1gz50YrEdpfVSbHz5YTZ EhDIxE4g7NrvJZh3Qc0m0CAyjYTNHen7J6olVaCMjrOH7uRHUYZ7Pl3am9mZosfLmez/aWJO a6ihQxBXHI75brlk1teIURkep2kP7P0Flmfl4cA//saREoTF7GXCtjOSQk/xg8PP0Sswqp5G TdJptn3FQn6lAzfz0eFSYqkaoX2c2k1MDa7o+UX9cfGPL8ybMKnYkasLxck6eOWGJWf+YTrm ga/r0kBaftmqNDgt5nI2jNTDwZcT9g3OwE0Eag9JfwEIAM6IWbuBSvz+erv27oGDDpo8M6Fp dGUvft7v+WceHUfxiXpYFx9qgIU6XGy6y+3lJMAvNcltS8DuhioqMlfKRSYGKZlpliY65dNP 557IuM4ctVJ+I9CVclvv9eahARQKgF5auLJAAlvGSmU+ufNvlwTUmLIRcrPviTmB6X5jJYc+ fiNeyI0HcsgcN21C0r62tUCypuZ+vgEJXw2bx1V8mVGZKxdGJPh58QF6kRK+xmd4kEComLGV BeM6BcVOtEjDcGNC0tLhXb0p9g1Ys55iA8sd6s4WacyolW2J6rwmcOkjiWexWw1caYgIWAV1 004M3gwUaOz0dGq2i7HQ0AiVfVkAEQEAAcLAdgQYAQoAIBYhBGiSJ6HgW88MgT/gfu2Cu2XL 9M6QBQJqD0l/AhsMAAoJEO2Cu2XL9M6QovYH/RjstyL5o/V5K74ylBtz0j5t3pLX5JKbwApi 656rGgDdqElImyvvZppNMl/mgHNzvxmfFAhJXnSX9f1fqVEQKOGEhLUastnl/ssBiE5x7btM V0GAffxXbXJZbVv4b/DI+gVrOPc2YXlVwruapvTZNtD3hqPrkjrmq5WTtGR2loIVSe62hmh0 BGD2Fy79b/hYWyBqhayPBEjwGW75u4/yn+Yqy1PgG3hIcvg7GSuT3akhHZSB2Mbguzcoyf9Q DJl6t33JxPRkkNrEdkPPmRlQCTSiUkVjKqMDF3jlINWsJ5t4jKFsNF91ksdw7aQgiX+tQIpE ugMC1NuNi5dDGip66bw=
  • Delivery-date: Fri, 04 Dec 2026 10:14:08 +0000
  • Feedback-id: default:8631fc262581453bbf619ec5b2062170:Sweego
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Hi,

Thanks for the reports. I created according public issues on our gitlab
olkur/xen:

1. cpu_khz becomes 0 for a timebase-frequency below 500Hz (medium)
   https://gitlab.com/xen-project/people/olkur/xen/-/work_items/67
2. IMSIC device tree properties allow undefined shifts
   https://gitlab.com/xen-project/people/olkur/xen/-/work_items/68
3. IMSIC MMIO regset validation is looser than the former exact-size check
   https://gitlab.com/xen-project/people/olkur/xen/-/work_items/69
4. p2m_set_type() swallows a failed metadata page allocation
   https://gitlab.com/xen-project/people/olkur/xen/-/work_items/70
5. paging_ret_to_domheap() returns success when the pool is too small
   https://gitlab.com/xen-project/people/olkur/xen/-/work_items/71
6. total_pages counts only the free pages of the P2M pool
   https://gitlab.com/xen-project/people/olkur/xen/-/work_items/72
7. hartid_to_cpuid() matches pcpu_info[] entries never set
   https://gitlab.com/xen-project/people/olkur/xen/-/work_items/73
8. APLIC source number check off by one, source 0 not rejected
   https://gitlab.com/xen-project/people/olkur/xen/-/work_items/74

They all carry the SECURITY label, so the batch can be found here:
https://gitlab.com/xen-project/people/olkur/xen/-/issues/?label_name%5B%5D=%F0%9F%97%82%EF%B8%8FSECURITY

Anyone can pick one up: assign yourself, then open the fix MR with a
Fixes: trailer and link the issue from the MR sidebar.

Thanks,
Baptiste


On 12/3/26 10:55 PM, Andrew Cooper wrote:
Hello,

As per the call earlier, here are the bugs reports:

1. [#64] 4c6718375829 - riscv: a timebase-frequency below 500Hz makes cpu_khz
    zero (pre-existing, from 025a9858fe69)

    Severity: medium

    preinit_dt_xen_time() in xen/arch/riscv/time.c sets cpu_khz =
    DIV_ROUND(rate, 1000) without checking the result, which is 0 for a device
    tree timebase-frequency below 500Hz (and for one within 500Hz of
    UINT32_MAX). ticks_to_ns() and ns_to_ticks() then divide by zero, which
    does not trap on RISC-V but makes NOW() constant and every timer deadline
    appear to lie in the past, so Xen does not get through boot in a usable
    state; Arm panics on a timer frequency below 1kHz instead. Host device tree
    input only, not guest-triggerable; RISC-V is not security supported (it is
    not mentioned in SUPPORT.md).

2. [#13] c7e36fc130b8 - riscv: IMSIC device tree properties allow undefined
    shifts (pre-existing, from c9bd8b322ecb)

    Severity: low

    imsic_parse_node() in xen/arch/riscv/imsic.c accepts guest-index-bits up to
    52 although IMSIC_HART_SIZE() shifts a 32-bit value by it (now also used as
    a divisor), accepts guest + hart index bits of 52, giving BIT(64, UL) for
    the group size, checks group-index-bits + group-index-shift - 1 in 32-bit
    arithmetic so that a huge shift wraps and passes, and does not require
    group-index-shift to be at least guest + hart index bits + 12. Only device
    trees with values outside the riscv,imsics binding are affected, and the
    result is a mis-parsed or rejected node at boot. Firmware-provided data
    only; not guest-triggerable. The xen-devel discussion of the introducing
    commit could only be checked in part.

3. [#15] c7e36fc130b8 - riscv/imsic: MMIO regset validation is looser than the
    former exact-size check

    Severity: low

    Validation is looser than the former exact-size check: regsets of size 0,
    sizes not a multiple of the per-hart size, and overlapping/duplicate
    regsets within a group are now accepted. Harmless today (regsets are not
    mapped anywhere yet), but will matter once guest interrupt files get mapped
    from these ranges. It depends on host device tree / firmware provided data
    processed at boot; not guest-exploitable.

4. [#123] 13d4a6776b93 - riscv/p2m: p2m_set_type() swallows a failed metadata
    page allocation, and its callers install inconsistent PTEs (pre-existing,
    from df31e3163d6e)

    Severity: low

    p2m_set_type() in xen/arch/riscv/p2m.c returns void and, when
    p2m_alloc_page() cannot supply the metadata page needed for a type stored
    outside the PTE (p2m_map_foreign_rw/_ro), only calls domain_crash() and
    returns, so its callers continue as if the type had been recorded.
    p2m_split_superpage() then writes all 512 entries of the new table with the
    p2m_ext_storage type bits copied from the superpage although the table has
    no metadata page, reports success, and p2m_set_entry() in the same call
    passes the replaced entry to p2m_free_subtree(), where p2m_get_type() maps
    the NULL metadata page pointer (an ASSERT failure in debug builds, a wild
    read otherwise). For a new leaf p2m_pte_from_mfn() produces a valid PTE
    with the requested permissions but type p2m_invalid, and p2m_set_entry()
    returns 0. This is latent: at this revision nothing built for RISC-V
    creates foreign mappings, start_xen() creates no guest domain, and
    domain_crash() itself ends in the unimplemented arch_domain_shutdown(), so
    it cannot be triggered, by a guest or otherwise. RISC-V is not mentioned in
    SUPPORT.md and so is not security supported.

5. [#124] 13d4a6776b93 - riscv/paging: paging_ret_to_domheap() returns false,
    i.e. success, when the pool holds fewer pages than requested (pre-existing,
    from 824ec513843b)

    Severity: low

    paging_ret_to_domheap() in xen/arch/riscv/paging.c returns int (0 on
    success, -errno on failure) but uses "return false" when the pool holds
    fewer pages than requested, which its only caller, p2m_alloc_root_table(),
    takes as success. With a P2M pool smaller than the four root table pages
    (for example "xen,domain-p2m-mem-mb = <0>") the root table is therefore
    allocated from the domheap without being accounted against the pool,
    instead of the pool setup failing with -ENOMEM. The effect is limited to
    this accounting, the pool size is chosen by the host administrator or the
    toolstack, and at this revision no code path creates a domain on RISC-V:
    not guest-triggerable, no security impact.

6. [#125] 13d4a6776b93 - riscv/paging: total_pages tracks only the free pages
    of the P2M pool, but is used as the pool size when resizing and reporting
    (known) (pre-existing, from af87a609c79d and 6f7881e331ea and a8606445b129)

    Severity: low

    d->arch.paging.total_pages is decremented by paging_alloc_page() and
    incremented by paging_free_page() in xen/arch/riscv/paging.c, so it counts
    only the pages currently on the free list, yet paging_freelist_adjust()
    compares it with the requested total pool size and
    arch_get_paging_mempool_size() in xen/arch/riscv/p2m.c returns it as "the
    size of the pool". Once P2M pages are in use, every
    arch_set_paging_mempool_size(d, N) therefore tops the free list up to N,
    leaving the pool larger than requested by the number of pages in use, and
    the reported size excludes the pages in use; no counter of in-use pages
    exists to compensate. Only the toolstack's
    XEN_DOMCTL_{get,set}_paging_mempool_size can expose this, which is not
    reachable on RISC-V at this revision (no hypercall entry, no domain is
    created): a latent accounting bug, not guest-triggerable and without
    security impact.

    Already raised on xen-devel (review of the root table allocation:
    total_pages should include pages in use; the effect on resizing and
    reporting is not discussed):
    
https://lore.kernel.org/xen-devel/7491c934-f847-4fe2-9d9b-a500f0888198@xxxxxxxx/

    Already raised on xen-devel (same point, follow-up):
    
https://lore.kernel.org/xen-devel/2aa2135f-e422-417f-a509-74f61c3b19de@xxxxxxxx/

    Already raised on xen-devel (author's answer: total_pages is present only
    for the freelist):
    
https://lore.kernel.org/xen-devel/6f9714f7-3b65-4903-acbf-a0aa537bb3f5@xxxxxxxxx/

7. [#152] f0de6e9b8b66 - riscv: hartid_to_cpuid() matches pcpu_info[] entries
    whose hart ID was never set (pre-existing, from c9bd8b322ecb and
    f8b21e5a5ee6)

    Severity: low

    hartid_to_cpuid() in xen/arch/riscv/include/asm/smp.h compares only the
    hart_id field of all NR_CPUS entries of pcpu_info[], without checking that
    the entry's processor_id is valid, although the comment next to the array
    in xen/arch/riscv/smp.c says that hart_id is meaningful only then. The
    array is statically initialised with hart_id 0 everywhere, and only entry 0
    is ever given a real hart ID, that of the boot hart. In a build with
    CONFIG_NR_CPUS of 2 or more (the RISC-V default is 1) which is started on a
    hart whose ID is not 0, a lookup of hart 0 therefore returns CPU 1 instead
    of CPU_NONE. The only caller, imsic_init() in xen/arch/riscv/imsic.c,
    checks the result against nr_cpu_ids only, records hart 0's interrupt file
    in msi[1] for a CPU which Xen does not have, and counts it as a handler: a
    device tree in which the boot hart itself has no usable IMSIC entry then no
    longer fails with "No CPU handlers found", and hart 0 is not reported as
    unsupported like the other harts Xen does not use. Otherwise the effect is
    latent while Xen runs on a single CPU. It happens once at boot and depends
    only on the build configuration and the firmware's hart numbering; it is
    not guest-triggerable.

8. [#157] 193f78719f5a - riscv/aplic: the source number check in
    intc_route_irq_to_xen() is off by one, and source 0 is not rejected before
    it indexes sourcecfg[] (pre-existing, from 8b5887d8cdda and a8b85fabf609)

    Severity: low

    intc_route_irq_to_xen() in xen/arch/riscv/intc.c asserts desc->irq <
    num_irqs, while APLIC sources are numbered from 1 to num_irqs, the value of
    riscv,num-sources, as the assertion which the reviewed commit adds to
    aplic_set_irq_affinity() has it. With a valid host device tree whose
    console UART uses the highest source number, a debug build fails the
    assertion at boot when ns16550 sets up its interrupt; release builds work.
    Apart from that assertion nothing validates the source number taken from
    the device tree: aplic_irq_xlate() and platform_get_irq() pass source 0 on,
    intc_route_irq_to_guest() has no check, and aplic_set_irq_type() in
    xen/arch/riscv/aplic.c computes desc->irq - 1 as an unsigned index, so that
    source 0 would write sourcecfg[0xffffffff], 16GiB beyond the mapped
    registers, in debug and release builds alike. This second part is latent:
    ns16550, the only user of setup_irq() on RISC-V, does not request IRQ 0,
    and the guest routing path has no caller as long as RISC-V does not build
    domains. The number comes from the host device tree only, so neither part
    is guest-triggerable. RISC-V is not mentioned in SUPPORT.md, so it is not
    security supported.



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.