Skip to main content
Vulnerability Database/CVE-2024-26704

CVE-2024-26704: Linux Kernel Use-After-Free Vulnerability

CVE-2024-26704 is a use-after-free flaw in Linux Kernel's ext4 filesystem that causes double-free of blocks during extent moves. This post explains the technical details, affected versions, and mitigation steps.

Published:

Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

Sources: National Vulnerability Database, CISA KEV, Exploit-DB

CVE-2024-26704 Overview

CVE-2024-26704 is a double-free vulnerability [CWE-415] in the Linux kernel's ext4 filesystem implementation. The flaw resides in the ext4_move_extents() function, which handles the EXT4_IOC_MOVE_EXT ioctl used to relocate file extents between inodes. When the extent-move loop fails after partially completing, the moved_len counter is not updated and preallocations are not discarded. Overlapping preallocated extents are then freed twice through ext4_mb_release_inode_pa() and ext4_process_freed_data(). Subsequent trim operations trigger a zero-division bug in mb_update_avg_fragment_size() because bb_free is non-zero while bb_fragments is zero.

Critical Impact

A local, authenticated user can trigger kernel memory corruption and a divide-by-zero panic, resulting in denial of service and potential compromise of kernel integrity.

Affected Products

  • Linux kernel (multiple stable branches, including 6.8-rc1 and 6.8-rc2)
  • Debian GNU/Linux 10 (LTS)
  • Downstream distributions shipping vulnerable ext4 builds

Discovery Timeline

  • 2024-04-03 - CVE-2024-26704 published to NVD
  • 2024-06 - Debian LTS security announcements published
  • 2026-08-04 - Last updated in NVD database

Technical Details for CVE-2024-26704

Vulnerability Analysis

The defect is a classic double-free in the ext4 extent-move path. The function ext4_move_extents() updates its moved_len return value only after the entire extent-move loop completes successfully. The function also uses moved_len as the gate for discarding preallocation reservations on orig_inode and donor_inode.

When the loop exits early due to a partial failure, extents have already been relocated, but moved_len remains at 0. As a result, the kernel skips the preallocation cleanup. If the newly moved extents overlap preallocated ranges on either inode, the same physical blocks become eligible for release through two independent paths.

The blocks are first freed via ext4_mb_release_inode_pa() when the preallocation is torn down, and again via ext4_process_freed_data() during normal transaction commit. This increments bb_free twice for the affected block group while bb_fragments is not updated accordingly.

Root Cause

The root cause is incorrect state tracking in ext4_move_extents(). The moved_len counter must reflect progress made so far, not only completion. Because cleanup decisions key off this value, a mid-loop failure leaves the filesystem in an inconsistent accounting state. The upstream fix updates moved_len after each successful extent move, ensuring preallocations are always released when needed.

Attack Vector

Exploitation requires local access and the ability to invoke the EXT4_IOC_MOVE_EXT ioctl against files on an ext4 filesystem. An attacker crafts source and donor files whose extents partially overlap preallocated regions and forces the move loop to abort partway through. A subsequent FITRIM ioctl or similar discard operation reaches mb_update_avg_fragment_size(), where division by bb_fragments == 0 triggers a kernel panic. Depending on allocator state, the double-free can also corrupt free-space metadata and enable further escalation.

No public proof-of-concept has been published for this issue, and it is not listed in the CISA Known Exploited Vulnerabilities catalog.

Detection Methods for CVE-2024-26704

Indicators of Compromise

  • Kernel oops or panic messages referencing mb_update_avg_fragment_size, ext4_mb_release_inode_pa, or ext4_process_freed_data.
  • Divide-by-zero traces originating from the ext4 multiblock allocator during FITRIM or background discard.
  • Unexpected filesystem corruption reports from e2fsck after use of EXT4_IOC_MOVE_EXT.

Detection Strategies

  • Audit syscall telemetry for unprivileged processes issuing ioctl with the EXT4_IOC_MOVE_EXT command number against sensitive filesystems.
  • Correlate kernel ring buffer entries (dmesg) with user sessions to attribute ext4 warnings to specific processes.
  • Compare running kernel version and build identifiers against the fixed commits listed in the vendor advisories.

Monitoring Recommendations

  • Forward /var/log/kern.log and journald kernel facility messages to a central analytics tier for anomaly detection.
  • Alert on repeated FITRIM failures or unexpected ext4-fs error entries on multi-tenant hosts.
  • Track package inventory to confirm all Linux hosts receive the patched kernel across fleets.

How to Mitigate CVE-2024-26704

Immediate Actions Required

  • Upgrade to a kernel build that includes the upstream fix referenced by commits 559ddacb90da, b4fbb89d722c, afba9d113200, and related backports on git.kernel.org.
  • On Debian systems, apply updates from the Debian LTS Announcement #17 and Debian LTS Announcement #20.
  • Reboot affected hosts after kernel package installation to activate the patched image.

Patch Information

The fix updates moved_len after each successful extent move inside ext4_move_extents(), ensuring preallocation discard logic executes even when the loop terminates early. Backported commits are available for multiple stable branches via the kernel.org stable tree, including commit 559ddacb and commit b4fbb89d.

Workarounds

  • Restrict local shell access on multi-tenant Linux hosts until patched kernels are deployed.
  • Where feasible, mount ext4 filesystems with options that limit untrusted use of EXT4_IOC_MOVE_EXT, such as denying write access on shared mounts to untrusted users.
  • Disable or defer fstrim timers on hosts suspected of having triggered the condition until the kernel is updated.
bash
# Verify kernel version and apply distribution updates
uname -r
sudo apt update && sudo apt upgrade linux-image-$(uname -r | sed 's/.*-//')
sudo systemctl reboot

Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

Sources: National Vulnerability Database, CISA KEV, Exploit-DB

Experience the Most Advanced Cybersecurity Platform

See how the world’s most intelligent, autonomous cybersecurity platform can protect your organization today and into the future.