[PATCH 0/6] block: fix integrity offset/length conversions

Caleb Sander Mateos posted 6 patches 2 months, 2 weeks ago
There is a newer version of this series
block/bio-integrity-fs.c            |  5 +++--
block/bio-integrity.c               |  2 +-
block/t10-pi.c                      |  4 ++--
drivers/nvme/target/io-cmd-bdev.c   |  3 +--
drivers/target/target_core_iblock.c |  3 +--
include/linux/blk-integrity.h       | 12 ++++++------
6 files changed, 14 insertions(+), 15 deletions(-)
[PATCH 0/6] block: fix integrity offset/length conversions
Posted by Caleb Sander Mateos 2 months, 2 weeks ago
The block layer's integrity code currently sets the seed (initial
reference tag) in units of 512-byte sectors but increments it in units
of integrity intervals. Not only do the T10 DIF formats require ref tags
to be the lower bits of the logical block address, but mixing the two
units means the ref tags used for a particular logical block vary based
on its offset within a read/write request. This looks to be a
longstanding bug affecting block devices that support integrity with
block sizes > 512 bytes; I'm surprised it wasn't noticed before.

Also fix the newly added fs_bio_integrity_verify() to pass
bio_integrity_verify() a struct bdev_iter representing the data instead
of the integrity. Most of the integrity data is currently being skipped.

Caleb Sander Mateos (6):
  blk-integrity: take sector_t in bio_integrity_intervals()
  block: use integrity interval instead of sector as seed
  bio-integrity-fs: pass data iter to bio_integrity_verify()
  bio-integrity-fs: use integrity interval instead of sector as seed
  t10-pi: use bio_integrity_intervals() helper
  target: use bio_integrity_intervals() helper

 block/bio-integrity-fs.c            |  5 +++--
 block/bio-integrity.c               |  2 +-
 block/t10-pi.c                      |  4 ++--
 drivers/nvme/target/io-cmd-bdev.c   |  3 +--
 drivers/target/target_core_iblock.c |  3 +--
 include/linux/blk-integrity.h       | 12 ++++++------
 6 files changed, 14 insertions(+), 15 deletions(-)

-- 
2.45.2
Re: [PATCH 0/6] block: fix integrity offset/length conversions
Posted by Anuj gupta 2 months, 2 weeks ago
> The block layer's integrity code currently sets the seed (initial
> reference tag) in units of 512-byte sectors but increments it in units
> of integrity intervals. Not only do the T10 DIF formats require ref tags
> to be the lower bits of the logical block address, but mixing the two
> units means the ref tags used for a particular logical block vary based
> on its offset within a read/write request. This looks to be a
> longstanding bug affecting block devices that support integrity with
> block sizes > 512 bytes; I'm surprised it wasn't noticed before.
>
This likely went unnoticed because the remap path compensates for it:
blk_integrity_prepare() rewrites the host-side sector-based ref tag to
the correct device-visible interval/LBA value, and
blk_integrity_complete() rewrites it back on reads. So for block-auto
PI, and for the FS-PI path that goes through the same remap, the
device-facing ref tag still comes out correct even though the host-side
seed is semantically wrong.