Skip to content

Commit 677e332

Browse files
Anuj Guptaaxboe
authored andcommitted
block: ensure correct integrity capability propagation in stacked devices
queue_limits_stack_integrity() incorrectly sets BLK_INTEGRITY_DEVICE_CAPABLE for a DM device even when none of its underlying devices support integrity. This happens because the flag is inherited unconditionally. Ensure that integrity capabilities are correctly propagated only when the underlying devices actually support integrity. Reported-by: M Nikhil <[email protected]> Link: https://lore.kernel.org/linux-block/[email protected]/ Fixes: c6e56cf ("block: move integrity information into queue_limits") Signed-off-by: Anuj Gupta <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 6cc477c commit 677e332

File tree

1 file changed

+21
-29
lines changed

1 file changed

+21
-29
lines changed

block/blk-settings.c

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -864,36 +864,28 @@ bool queue_limits_stack_integrity(struct queue_limits *t,
864864
if (!IS_ENABLED(CONFIG_BLK_DEV_INTEGRITY))
865865
return true;
866866

867-
if (!ti->tuple_size) {
868-
/* inherit the settings from the first underlying device */
869-
if (!(ti->flags & BLK_INTEGRITY_STACKED)) {
870-
ti->flags = BLK_INTEGRITY_DEVICE_CAPABLE |
871-
(bi->flags & BLK_INTEGRITY_REF_TAG);
872-
ti->csum_type = bi->csum_type;
873-
ti->tuple_size = bi->tuple_size;
874-
ti->pi_offset = bi->pi_offset;
875-
ti->interval_exp = bi->interval_exp;
876-
ti->tag_size = bi->tag_size;
877-
goto done;
878-
}
879-
if (!bi->tuple_size)
880-
goto done;
867+
if (ti->flags & BLK_INTEGRITY_STACKED) {
868+
if (ti->tuple_size != bi->tuple_size)
869+
goto incompatible;
870+
if (ti->interval_exp != bi->interval_exp)
871+
goto incompatible;
872+
if (ti->tag_size != bi->tag_size)
873+
goto incompatible;
874+
if (ti->csum_type != bi->csum_type)
875+
goto incompatible;
876+
if ((ti->flags & BLK_INTEGRITY_REF_TAG) !=
877+
(bi->flags & BLK_INTEGRITY_REF_TAG))
878+
goto incompatible;
879+
} else {
880+
ti->flags = BLK_INTEGRITY_STACKED;
881+
ti->flags |= (bi->flags & BLK_INTEGRITY_DEVICE_CAPABLE) |
882+
(bi->flags & BLK_INTEGRITY_REF_TAG);
883+
ti->csum_type = bi->csum_type;
884+
ti->tuple_size = bi->tuple_size;
885+
ti->pi_offset = bi->pi_offset;
886+
ti->interval_exp = bi->interval_exp;
887+
ti->tag_size = bi->tag_size;
881888
}
882-
883-
if (ti->tuple_size != bi->tuple_size)
884-
goto incompatible;
885-
if (ti->interval_exp != bi->interval_exp)
886-
goto incompatible;
887-
if (ti->tag_size != bi->tag_size)
888-
goto incompatible;
889-
if (ti->csum_type != bi->csum_type)
890-
goto incompatible;
891-
if ((ti->flags & BLK_INTEGRITY_REF_TAG) !=
892-
(bi->flags & BLK_INTEGRITY_REF_TAG))
893-
goto incompatible;
894-
895-
done:
896-
ti->flags |= BLK_INTEGRITY_STACKED;
897889
return true;
898890

899891
incompatible:

0 commit comments

Comments
 (0)