In the Linux kernel, the following vulnerability has been resolved:
ufs: validate cylinder group metadata before caching it
ufs_read_cylinder() copies the cylinder group index and the rotor
positions straight from the on-disk group and caches them without any
check:
<pre>
ucpi->c_cgx = fs32_to_cpu(sb, ucg->cg_cgx);
ucpi->c_rotor = fs32_to_cpu(sb, ucg->cg_rotor);
ucpi->c_frotor = fs32_to_cpu(sb, ucg->cg_frotor);
ucpi->c_irotor = fs32_to_cpu(sb, ucg->cg_irotor);
</pre>
They are then used as indices during allocation and free:
-
c_cgx indexes the cylinder summary array as
UFS_SB(sb)->fs_cs(ucpi->c_cgx), so a value past s_ncg writes a 32
bit count outside the s_csp allocation.
-
c_frotor becomes a bitmap scan start, start = c_frotor >> 3, and
then length = ((s_fpg + 7) >> 3) - start. A start beyond the block
bitmap wraps the unsigned length to a huge value, so ubh_scanc()
walks far past the cylinder group buffers. c_irotor drives the
inode bitmap the same way.
A crafted image can set any of these freely, turning an ordinary
allocation into an out of bounds access.
Reject a cylinder group whose recorded index does not match the group
being read, or whose rotors fall outside the group, before the metadata
is cached. Valid filesystems keep cg_cgx equal to the group number and
the rotors within the group, so only malformed images are rejected.
CVSS Vector: CVSS:3.1/AV:L/AC:H/PR:N/UI:R/S:U/C:H/I:H/A:H
CVSS Score: 7
AV:L - The bad cg_cgx/cg_rotor/cg_frotor/cg_irotor values come from a crafted UFS image's cylinder group block, read by ufs_read_cylinder(). They are then used by the local VFS allocate/free paths (ufs_new_fragments, ufs_free_fragments, ufs_new_inode, ufs_free_inode). No network protocol carries these bytes.
AC:H - ufs_load_cylinder() is called only from the allocate/free paths in balloc.c and ialloc.c. These need a read-write mount, and ufs_fill_super() returns -EROFS for one unless the non-default CONFIG_UFS_FS_WRITE ("DANGEROUS") is set. Major distros leave it off and only a few MIPS defconfigs set it, so reaching the bug depends on a rare kernel config.
PR:N - The attacker only has to craft the image. The ufs file_system_type sets FS_REQUIRES_DEV without FS_USERNS_MOUNT, so the mount is done by a privileged victim, not the attacker. After that, creating or extending a file triggers the allocation.
UI:R - A victim has to mount the attacker-supplied UFS image read-write before ufs_read_cylinder() caches the malformed cylinder group fields.
S:U - The out-of-bounds accesses stay in kernel heap memory in the same kernel security authority. No guest/host or hardware boundary is crossed.
C:H - If c_frotor/c_irotor lie outside the group, the unsigned length in ufs_bitmap_search() wraps. ubh_scanc() then reads far past the cylinder group buffers, an unbounded out-of-bounds read of kernel memory.
I:H - ufs_add_fragments()/ufs_free_* call fs32_add() on UFS_SB(sb)->fs_cs(ucpi->c_cgx). An attacker-chosen c_cgx beyond s_ncg adds to a 32-bit value outside the s_csp heap allocation, an out-of-bounds heap write at a chosen index.
A:H - The wild ubh_scanc() walk and the out-of-bounds fs_cs() writes can oops the kernel or corrupt the heap, crashing the system.
| Attack Vector |
Local |
Scope |
Unchanged |
| Attack Complexity |
High |
Confidentiality Impact |
High |
| Privileges Required |
None |
Integrity Impact |
High |
| User Interaction |
Required |
Availability Impact |
High |
AV:L - The bad cg_cgx/cg_rotor/cg_frotor/cg_irotor values come from a crafted UFS image's cylinder group block, read by ufs_read_cylinder(). They are then used by the local VFS allocate/free paths (ufs_new_fragments, ufs_free_fragments, ufs_new_inode, ufs_free_inode). No network protocol carries these bytes.
AC:H - ufs_load_cylinder() is called only from the allocate/free paths in balloc.c and ialloc.c. These need a read-write mount, and ufs_fill_super() returns -EROFS for one unless the non-default CONFIG_UFS_FS_WRITE ("DANGEROUS") is set. Major distros leave it off and only a few MIPS defconfigs set it, so reaching the bug depends on a rare kernel config.
PR:N - The attacker only has to craft the image. The ufs file_system_type sets FS_REQUIRES_DEV without FS_USERNS_MOUNT, so the mount is done by a privileged victim, not the attacker. After that, creating or extending a file triggers the allocation.
UI:R - A victim has to mount the attacker-supplied UFS image read-write before ufs_read_cylinder() caches the malformed cylinder group fields.
S:U - The out-of-bounds accesses stay in kernel heap memory in the same kernel security authority. No guest/host or hardware boundary is crossed.
C:H - If c_frotor/c_irotor lie outside the group, the unsigned length in ufs_bitmap_search() wraps. ubh_scanc() then reads far past the cylinder group buffers, an unbounded out-of-bounds read of kernel memory.
I:H - ufs_add_fragments()/ufs_free_* call fs32_add() on UFS_SB(sb)->fs_cs(ucpi->c_cgx). An attacker-chosen c_cgx beyond s_ncg adds to a 32-bit value outside the s_csp heap allocation, an out-of-bounds heap write at a chosen index.
A:H - The wild ubh_scanc() walk and the out-of-bounds fs_cs() writes can oops the kernel or corrupt the heap, crashing the system.
CVSS 3.1