All of lore.kernel.org
 help / color / mirror / Atom feed
* RISC-V bugs from scanning
@ 2026-12-03 21:53 Andrew Cooper
  2026-12-04 10:13 ` Baptiste Le Duc
  0 siblings, 1 reply; 5+ messages in thread
From: Andrew Cooper @ 2026-12-03 21:53 UTC (permalink / raw)
  To: xen-devel; +Cc: Andrew Cooper, Oleksii Kurochko, Baptiste Le Duc

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@suse.com/

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

   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@gmail.com/

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.



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-12-04 10:59 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 21:53 RISC-V bugs from scanning Andrew Cooper
2026-12-04 10:13 ` Baptiste Le Duc
2026-12-04 10:21   ` Andrew Cooper
2026-12-04 10:50     ` Roger Pau Monné
2026-12-04 10:58       ` Baptiste Le Duc

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.