[PATCH v2 0/8] scsi: target: keep command bytes inside the sg
From: Jia Jia
Date: Tue Nov 17 2026 - 23:14:06 EST
This series fixes eight target-core accesses past command-buffer or sg
boundaries. vhost-scsi can supply guest buffers whose sg boundaries do
not coincide with command fields, logical blocks or protection tuples.
Patch 1 builds the COMPARE AND WRITE write sg table from the entries
that contain the write half.
Patch 2 limits each REPORT REFERRALS LBA store to the bytes remaining
in the response buffer.
Patch 3 rejects SET TARGET PORT GROUPS parameter lists that end in a
partial four-byte descriptor.
Patch 4 lets sbc_dif_generate() write an eight-byte protection tuple
split across protection sg entries.
Patch 5 lets sbc_dif_verify() read a tuple split across protection sg
entries and rejects a partial tuple at the end of the list.
Patch 6 limits each CRC update to the bytes available in the current
data sg in both DIF generation and verification.
Patch 7 checks buffer lengths and uses sg copies for the pscsi MODE
SENSE write-protect byte and tape MODE SELECT block descriptor.
Patch 8 makes sbc_dif_verify() advance past an escaped block spanning
multiple data sg entries.
Patches 1, 2, 3 and 7 are independent. The DIF patches 4, 5, 6 and 8 fix
separate bugs and are posted in that order: patch 4 can stand alone,
patch 5 uses its tuple-copy helper, and patch 6 builds on both. Patch 8
covers escaped blocks, which bypass the CRC walk.
Changes in v2:
- Keep data sg advancement before the escape check in patch 5.
- Retain the existing atomic page mappings in the DIF paths.
- Fix escape advancement with the existing cursor loop in patch 8.
- Use the existing sg copy helpers for pscsi mode data in patch 7.
- Correct the Fixes tags in patches 1, 3 and 5.
- Explain why PI generation reads an existing tuple before updating it.
- Shorten the commit descriptions and retain the relevant trace frames.
Jia Jia (8):
scsi: target: take COMPARE AND WRITE data from the write half
scsi: target: keep REPORT REFERRALS stores inside the buffer
scsi: target: reject a short SET TARGET PORT GROUPS list
scsi: target: copy a DIF insert tuple across prot sgs
scsi: target: copy a DIF verify tuple across prot sgs
scsi: target: limit DIF block CRC to each data sg
scsi: target: keep pscsi mode bytes inside the data sgs
scsi: target: advance past escaped DIF blocks across data sgs
drivers/target/target_core_alua.c | 29 ++-
drivers/target/target_core_pscsi.c | 37 ++-
drivers/target/target_core_sbc.c | 422 ++++++++++++++++++++++-----------
drivers/target/target_core_transport.c | 11 +-
4 files changed, 338 insertions(+), 161 deletions(-)