CVE-2025-40040

Description

A flaw was found in the Linux kernel’s KSM (Kernel Same-page Merging) subsystem during ksm_madvise() operations: when a madvise(MADV_UNMERGEABLE) call is made on a VMA registered for userfaultfd (UFFD) in MINOR mode, the code clears the VM_MERGEABLE flag incorrectly. The constant VM_MERGEABLE is defined as a 32-bit unsigned int, and when negated and promoted to unsigned long, the upper 32 bits are cleared unexpectedly. This leads to an inconsistent VMA state (e.g., a valid vm_userfaultfd_ctx pointer but missing UFFD flags), which under certain conditions causes kernel panics or warnings during userfaultfd_release_all().

Statement

The VM_MERGEABLE constant had a 32 bit unsigned type. As a result ksm_madvise with MADV_UNMERGEABLE could apply the mask 0x000000007fffffff to a 64 bit vm_flags value and unintentionally clear every flag in its upper 32 bits. A local user can reach the demonstrated failure by registering a supported VMA with userfaultfd MINOR mode and then applying MADV_UNMERGEABLE. This leaves a valid vm_userfaultfd_ctx pointer without the corresponding UFFD flags and userfaultfd_release_all can detect the inconsistency and trigger a kernel BUG or a later kernel WARNING. For the CVSS the PR:L value is selected because exploitation requires a local user context able to create the relevant mapping and invoke userfaultfd and madvise operations. The established impact is local denial of service through a kernel panic on affected versions. No UAF OOB access or arbitrary write primitive is demonstrated. Limited confidentiality or integrity impact remains a grounded worst case concern because multiple upper VMA metadata flags are cleared rather than only the intended KSM flag.

Mitigation

Mitigation for this issue is either not available or the currently available options don't meet the Red Hat Product Security criteria comprising ease of use and deployment, applicability to widespread installation base or stability.

Common Vulnerability Scoring System (CVSS) Score Details

Info alert:Important note

CVSS scores for open source components depend on vendor-specific factors (e.g. version or build chain). Therefore, Red Hat's score and impact rating can be different from NVD and other vendors. Red Hat remains the authoritative CVE Naming Authority (CNA) source for its products and services (see Red Hat classifications).

The following CVSS metrics and score provided are preliminary and subject to review.

CVSS v3 Score Breakdown

Red HatNVDcve.org
Base Score5.55.57.8
Attack VectorLocalLocalLocal
Attack ComplexityLowLowLow
Privileges RequiredLowLowLow
User InteractionNoneNoneNone
ScopeUnchangedUnchangedUnchanged
ConfidentialityNoneNoneHigh
Integrity ImpactNoneNoneHigh
Availability ImpactHighHighHigh

Vector

Red Hat: CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:N/I:N/A:H

NVD: CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:N/I:N/A:H

cve.org: CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H

Understanding the Weakness (CWE)

Availability

Technical Impact: DoS: Resource Consumption (CPU); DoS: Resource Consumption (Memory)

Resources including CPU, memory, and stack memory could be rapidly consumed or exhausted, eventually leading to an exit or crash.

Confidentiality

Technical Impact: Read Application Data

In some cases, an application's interpreter might kill a process or thread that appears to be consuming too many resources, such as with PHP's memory_limit setting. When the interpreter kills the process/thread, it might report an error containing detailed information such as the application's installation path.

Frequently Asked Questions

Want to get errata notifications? Sign up here.