From: Shao Mingyin ATA PASS-THROUGH(32) has no MULTIPLE_COUNT field. Byte 1 is CONTROL, and bits 7:5 are reserved or obsolete. Interpreting these bits as a multiple count can issue spurious count mismatch warnings for multiple commands instead of rejecting the invalid CDB. Reject nonzero byte 1 bits 7:5 with field pointer 1. Skip the CDB count comparison for the 32-byte form while retaining the device multiple-mode check. Also point to byte 10 for invalid PROTOCOL. The 12- and 16-byte MULTIPLE_COUNT checks remain unchanged. Fixes: b1ffbf854e08 ("libata: Support for an ATA PASS-THROUGH(32) command.") Suggested-by: Niklas Cassel Signed-off-by: Shao Mingyin --- Changes in v3 (Damien Le Moal): - Reject nonzero reserved/obsolete bits 7:5 of byte 1 with fp=1. - Retain the short-CDB count and device multiple-mode checks. - Update the subject, description and CONTROL-byte test expectations. v2: https://lore.kernel.org/all/20261111223129430zClEJF8TDgu_h8ZYM843Q@zte.com.cn/ Validation on x86-64 with GCC 13 and UBSAN: a userspace harness compiles ata_scsi_pass_thru() verbatim with SCSI/device stubs. All 256 CONTROL values are checked for both non-multiple and multiple commands. Nonzero bits 7:5 are rejected with field pointer 1; values with those bits clear are accepted without count warnings. The device multiple-mode check and 12-/16-byte count checks still pass. Field pointers are observed helper arguments; sense construction and device access use stubs. drivers/ata/libata-scsi.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index a61fb03312793ca94d81d8061a16c66e786c4cf3..0bc147cf4c0fa50c7d5b84029b7fb1a548c6f1a3 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -3388,7 +3388,7 @@ static unsigned int ata_scsi_pass_thru(struct ata_queued_cmd *qc) tf->protocol = ata_scsi_map_proto(cdb[1 + cdb_offset]); if (tf->protocol == ATA_PROT_UNKNOWN) { - fp = 1; + fp = 1 + cdb_offset; goto invalid_fld; } @@ -3573,27 +3573,32 @@ static unsigned int ata_scsi_pass_thru(struct ata_queued_cmd *qc) goto invalid_fld; } - /* sanity check for pio multi commands */ + /* Sanity check for pio multi commands (not supported with ATA 32). */ + if (cdb[0] == VARIABLE_LENGTH_CMD && (cdb[1] & 0xe0)) { + fp = 1; + goto invalid_fld; + } + if ((cdb[1] & 0xe0) && !is_multi_taskfile(tf)) { fp = 1; goto invalid_fld; } if (is_multi_taskfile(tf)) { - unsigned int multi_count = 1 << (cdb[1] >> 5); - if (!dev->multi_count) { ata_scsi_set_sense(dev, scmd, ABORTED_COMMAND, NO_ADDITIONAL_SENSE_INFORMATION); return 1; } - /* compare the passed through multi_count - * with the cached multi_count of libata - */ - if (multi_count != dev->multi_count) - ata_dev_warn(dev, "invalid multi_count %u ignored\n", - multi_count); + if (cdb[0] != VARIABLE_LENGTH_CMD) { + unsigned int multi_count = 1 << (cdb[1] >> 5); + + /* Compare with the cached multiple count of libata. */ + if (multi_count != dev->multi_count) + ata_dev_warn(dev, "invalid multi_count %u ignored\n", + multi_count); + } } /*