From: Shao Mingyin ata_scsi_var_len_cdb_xlat() returns 1 for an unsupported service action without setting sense data. ata_scsi_translate() then completes the command with the SCSI result still zero, reporting SAM_STAT_GOOD even though no ATA command was issued and no data was transferred. Set ILLEGAL REQUEST/INVALID FIELD IN CDB before returning, with the field pointer referring to the SERVICE ACTION field at byte 8. Fixes: b1ffbf854e08 ("libata: Support for an ATA PASS-THROUGH(32) command.") Reviewed-by: Damien Le Moal Signed-off-by: Shao Mingyin --- Changes in v3: - Code unchanged; retain the Damien Le Moal Reviewed-by tag. Previous version: https://lore.kernel.org/all/20261111223130666omUZ0JoWtfZjRFRrWPse8@zte.com.cn/ Changes in v2: - No code changes; regenerate against the series base and keep the Reviewed-by tag. v1: https://lore.kernel.org/all/20261104221102824qAKUWNkiSgZ1yRnQM8hI9@zte.com.cn/ Validation on x86-64 with GCC 13 and UBSAN: a userspace harness compiled the translation functions verbatim with SCSI/device stubs. For service action 0x1234, completion changed from result 0 to ILLEGAL REQUEST, INVALID FIELD IN CDB; the invalid-field helper received field pointer 8. A valid ATA_32 service action remained accepted. drivers/ata/libata-scsi.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index 0bc147cf4c0fa50c7d5b84029b7fb1a548c6f1a3..2491e90fb1a5ec6e83234a07eef5342055875937 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -5032,7 +5032,13 @@ static unsigned int ata_scsi_var_len_cdb_xlat(struct ata_queued_cmd *qc) if (sa == ATA_32) return ata_scsi_pass_thru(qc); - /* unsupported service action */ + /* + * Unsupported service action. Set the sense data explicitly, as + * returning 1 without it makes ata_scsi_translate() complete the + * command with the SCSI result still zero, that is, with + * SAM_STAT_GOOD. + */ + ata_scsi_set_invalid_field(qc->dev, scmd, 8, 0xff); return 1; }