CVE-2026-31786 Overview
CVE-2026-31786 is a buffer overflow vulnerability in the Linux kernel's Xen hypervisor sysfs interface, specifically within drivers/xen/sys-hypervisor.c. The build ID returned by HYPERVISOR_xen_version(XENVER_build_id) is neither NUL-terminated nor formatted as a string. When buildid_show calls sprintf to format this data, the function reads past the intended buffer until it encounters a NUL byte, leaking adjacent memory into the sysfs output. This issue is tracked upstream as XSA-485 and affects multiple Linux kernel branches including 7.1-rc1 and 7.1-rc2. The vulnerability is categorized as an out-of-bounds write [CWE-787].
Critical Impact
A local authenticated user reading the Xen build ID sysfs attribute can trigger a buffer overflow leading to potential memory corruption and disclosure of adjacent kernel memory contents.
Affected Products
- Linux Kernel (multiple stable branches)
- Linux Kernel 7.1-rc1
- Linux Kernel 7.1-rc2
Discovery Timeline
- 2026-04-30 - CVE-2026-31786 published to NVD
- 2026-05-06 - Last updated in NVD database
Technical Details for CVE-2026-31786
Vulnerability Analysis
The flaw resides in the buildid_show sysfs handler within drivers/xen/sys-hypervisor.c. The Xen hypercall HYPERVISOR_xen_version(XENVER_build_id) returns raw binary data representing the hypervisor build identifier. This data is not NUL-terminated and does not follow C string conventions. The kernel code incorrectly treats the returned buffer as a string and passes it to sprintf, which copies bytes until it encounters a NUL terminator.
When no NUL byte exists within the expected length, sprintf continues reading and writing beyond the source buffer's boundary. The advisory demonstrates this with a 0x17-byte build ID where the resulting sysfs output extends past the intended data into adjacent memory. This produces both a write overflow into the destination buffer and a read overflow on the source side.
Root Cause
The root cause is improper handling of a fixed-length binary buffer as a NUL-terminated C string. The use of sprintf with the %s format specifier on non-string data violates the function's input contract. The corrected implementation uses memcpy with an explicit length, ensuring that the operation respects the actual size returned by the hypercall and does not depend on terminator scanning.
Attack Vector
Exploitation requires local access with low privileges sufficient to read the Xen hypervisor sysfs attributes (typically /sys/hypervisor/properties/build_id). The attacker triggers the vulnerable code path by reading the build ID attribute. The resulting memory disclosure may expose kernel pointers or other sensitive data useful for further exploitation. The buffer overflow on the kernel stack or heap could potentially be leveraged for privilege escalation depending on adjacent memory layout.
No verified public exploit code is available. Refer to the Xen Advisory #485 and the OpenWall Security Discussion for additional technical context.
Detection Methods for CVE-2026-31786
Indicators of Compromise
- Unexpected reads from /sys/hypervisor/properties/build_id by non-administrative processes
- Kernel oops or panic entries in dmesg referencing buildid_show or sys-hypervisor
- Anomalous binary content returned from the Xen hypervisor sysfs interface
Detection Strategies
- Audit installed kernel package versions against the fixed commits published on git.kernel.org and compare against the affected version range
- Monitor process access patterns to Xen hypervisor sysfs paths using Linux audit subsystem rules
- Inspect kernel build configurations for CONFIG_XEN to identify systems that compile in the vulnerable code path
Monitoring Recommendations
- Enable auditd rules covering /sys/hypervisor/ to capture read operations and the responsible process context
- Collect and centralize kernel logs to detect memory corruption signatures in production Xen guest and dom0 workloads
- Track patch status across the Linux fleet using configuration management telemetry to confirm remediation
How to Mitigate CVE-2026-31786
Immediate Actions Required
- Apply the upstream kernel patches referenced in the vendor advisories to all systems running Xen-enabled kernels
- Restrict access to Xen hypervisor sysfs attributes by enforcing appropriate file mode and capability controls
- Prioritize remediation on Xen dom0 hosts and guests where untrusted local users may exist
Patch Information
The Linux kernel maintainers have published fixes across multiple stable branches. Relevant commits include 27fdbab4221b, 4b4defd2fce3, 52cecff98bda, 5c5ff7c7bd15, 8288d031a01d, d5f59216650c, e3af585e1728, and f458ba102da9. The fix replaces the sprintf call with a length-bounded memcpy against the actual size returned by the hypercall.
Workarounds
- Limit read permissions on /sys/hypervisor/properties/build_id to root-only access using udev rules or filesystem permissions
- Disable the Xen sysfs hypervisor interface in kernel configuration where the build ID attribute is not required operationally
- Apply mandatory access control policies (SELinux or AppArmor) to constrain which processes can read Xen sysfs paths
# Restrict read access on the affected sysfs attribute
chmod 0400 /sys/hypervisor/properties/build_id
# Verify kernel package against fixed versions
uname -r
dmesg | grep -i 'xen\|buildid'
Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

