[PATCH 0/2] nvmet: fix file backend short I/O and LBA range checks

From: shao.mingyin

Date: Wed Nov 11 2026 - 09:42:44 EST


The file backend computes byte offsets from the LBA and block size with
unchecked 64-bit arithmetic and does not handle short reads or writes.
A host can therefore make the backend report success for a transfer that
only covered part of the range, and a large LBA or length can wrap the
range check and reach vfs_fallocate() with an out-of-range offset.

Patch 1 makes nvmet_file_execute_io() stop at an incomplete submit
instead of advancing the position and eventually reporting success, and
converts a zero-byte completion on the common path to -EIO. Patch 2
adds a shared overflow-safe range check and uses it for read, write,
discard and write zeroes.

The two patches are independent and can be applied in any order. Both
carry Fixes: and Cc: stable.

Testing: both were tested on 7.3.0-next-20261030 with the loop transport
and a file-backed namespace under QEMU/TCG. Patch 1 used failslab to
reach the chunked path and a shortened backing file to force an
incomplete chunk; the unpatched target returned 0 with the tail of the
host buffer unchanged and only part of the write reaching the file, and
all four cases return 0x6006 after the patch. Patch 2 wrote SLBA 2^52+1
with a 4096-byte block size, which wraps to offset 0x1000; the unpatched
target accepted the command, and it now fails with 0x6081 (Capacity
Exceeded). Both patches also apply to next-20261105 and pass
checkpatch.pl --strict with no errors.

Shao Mingyin (2):
nvmet: handle short reads and writes in the file backend
nvmet: use overflow-safe range checks in the file backend

drivers/nvme/target/io-cmd-file.c | 48 ++++++++++++++++++++++++++++-----------
1 file changed, 35 insertions(+), 13 deletions(-)

---
base-commit: ddfe51b0a0f5dc9e415cc2c8ad8db17532dd426b