Skip to contentSkip to conversation

CVE-2026-31412: usb: gadget: f_mass_storage: Fix potential integer overflow in check_command_size_in_blocks()

DISCUSSION Greg Kroah-Hartman 1 participant 1 message Apr 10

lore
Share & tools
lore
#0 lore raw

From: Greg Kroah-Hartman <[email protected]>

Description
===========

In the Linux kernel, the following vulnerability has been resolved:

usb: gadget: f_mass_storage: Fix potential integer overflow in check_command_size_in_blocks()

The check_command_size_in_blocks() function calculates the data size in bytes by left shifting common->data_size_from_cmnd by the block size (common->curlun->blkbits). However, it does not validate whether this shift operation will cause an integer overflow.

Initially, the block size is set up in fsg_lun_open() , and the common->data_size_from_cmnd is set up in do_scsi_command(). During initialization, there is no integer overflow check for the interaction between two variables.

So if a malicious USB host sends a SCSI READ or WRITE command requesting a large amount of data (common->data_size_from_cmnd), the left shift operation can wrap around. This results in a truncated data size, which can bypass boundary checks and potentially lead to memory corruption or out-of-bounds accesses.

Fix this by using the check_shl_overflow() macro to safely perform the shift and catch any overflows.

The Linux kernel CVE team has assigned CVE-2026-31412 to this issue.

Affected and fixed versions
===========================

	Issue introduced in 3.3 with commit 144974e7f9e32b53b02f6c8632be45d8f43d6ab5 and fixed in 6.1.167 with commit 91817ad5452defe69bc7bc0e355f0ed5d01125cc
	Issue introduced in 3.3 with commit 144974e7f9e32b53b02f6c8632be45d8f43d6ab5 and fixed in 6.6.130 with commit ce0caaed5940162780c5c223b8ae54968a5f059b
	Issue introduced in 3.3 with commit 144974e7f9e32b53b02f6c8632be45d8f43d6ab5 and fixed in 6.12.78 with commit 228b37936376143f4b60cc6828663f6eaceb81b5
	Issue introduced in 3.3 with commit 144974e7f9e32b53b02f6c8632be45d8f43d6ab5 and fixed in 6.18.19 with commit 3428dc5520c811e66622b2f5fa43341bf9a1f8b3
	Issue introduced in 3.3 with commit 144974e7f9e32b53b02f6c8632be45d8f43d6ab5 and fixed in 6.19.9 with commit 387ebb0453b99d71491419a5dc4ab4bee0cacbac
	Issue introduced in 3.3 with commit 144974e7f9e32b53b02f6c8632be45d8f43d6ab5 and fixed in 7.0-rc4 with commit 8479891d1f04a8ce55366fe4ca361ccdb96f02e1

Please see https://www.kernel.org for a full list of currently supported kernel versions by the kernel community.

Unaffected versions might change over time as fixes are backported to older supported kernel versions. The official CVE entry at

	https://cve.org/CVERecord/?id=CVE-2026-31412

will be updated if fixes are backported, please check that for the most up to date information about this issue.

Affected files
==============

The file(s) affected by this issue are:
drivers/usb/gadget/function/f_mass_storage.c

Mitigation
==========

The Linux kernel CVE team recommends that you update to the latest stable kernel version for this, and many other bugfixes. Individual changes are never tested alone, but rather are part of a larger kernel release. Cherry-picking individual commits is not recommended or supported by the Linux kernel community at all. If however, updating to the latest release is impossible, the individual changes to resolve this issue can be found at these commits:

	https://git.kernel.org/stable/c/91817ad5452defe69bc7bc0e355f0ed5d01125cc
	https://git.kernel.org/stable/c/ce0caaed5940162780c5c223b8ae54968a5f059b
	https://git.kernel.org/stable/c/228b37936376143f4b60cc6828663f6eaceb81b5
	https://git.kernel.org/stable/c/3428dc5520c811e66622b2f5fa43341bf9a1f8b3
	https://git.kernel.org/stable/c/387ebb0453b99d71491419a5dc4ab4bee0cacbac
	https://git.kernel.org/stable/c/8479891d1f04a8ce55366fe4ca361ccdb96f02e1