ata: libata-scsi: Fix system suspend for a security locked drive
Subsystems (2)
Niklas Cassel
maintainerPATCH 1/2 ata: libata-scsi: Fix system suspend for a security locked drive
Commit cf3fc037623c ("ata: libata-scsi: Fix ata_to_sense_error() status handling") fixed ata_to_sense_error() to properly generate sense key ABORTED COMMAND (without any additional sense code), instead of the previous bogus sense key ILLEGAL REQUEST with the additional sense code UNALIGNED WRITE COMMAND, for a failed command.
However, this broke suspend for Security locked drives (drives that have Security enabled, and have not been Security unlocked by boot firmware).
The reason for this is that the SCSI disk driver, for the Synchronize Cache command only, treats any sense data with sense key ILLEGAL REQUEST as a successful command (regardless of ASC / ASCQ).
After commit cf3fc037623c ("ata: libata-scsi: Fix ata_to_sense_error() status handling") the code that treats any sense data with sense key ILLEGAL REQUEST as a successful command is no longer applicable, so the command fails, which causes the system suspend to be aborted:
sd 1:0:0:0: PM: dpm_run_callback(): scsi_bus_suspend returns -5 sd 1:0:0:0: PM: failed to suspend async: error -5
PM: Some devices failed to suspend, or early wake event detected
To make suspend work once again, for a Security locked device only, return sense data LOGICAL UNIT ACCESS NOT AUTHORIZED, the actual sense data which a real SCSI device would have returned if locked. The SCSI disk driver treats this sense data as a successful command.
--- drivers/ata/libata-scsi.c | 7 +++++++ include/linux/ata.h | 1 + 2 files changed, 8 insertions(+)
drivers/ata/libata-scsi.c +7 -0
@@ -992,6 +992,13 @@ static void ata_gen_ata_sense(struct ata_queued_cmd *qc)return ; } +if (ata_id_is_locked (dev->id)) { +/* Security locked */ +/* LOGICAL UNIT ACCESS NOT AUTHORIZED */ +ata_scsi_set_sense (dev, cmd,DATA_PROTECT ,0x74 ,0x71 ); +return ; + } +if (!(qc->flags &ATA_QCFLAG_RTF_FILLED )) {ata_dev_dbg (dev,"Missing result TF: reporting aborted command\n" );
include/linux/ata.h +1 -0
@@ -566,6 +566,7 @@ struct ata_bmdma_prd {#define ata_id_has_ncq (id) ((id)[ATA_ID_SATA_CAPABILITY] & (1 << 8))#define ata_id_queue_depth (id) (((id)[ATA_ID_QUEUE_DEPTH] & 0x1f) + 1)#define ata_id_removable (id) ((id)[ATA_ID_CONFIG] & (1 << 7)) +#define ata_id_is_locked (id) (((id)[ATA_ID_DLF] & 0x7) == 0x7)#define ata_id_has_atapi_AN (id) \ ((((id)[ATA_ID_SATA_CAPABILITY] != 0x0000) && \ ((id)[ATA_ID_SATA_CAPABILITY] != 0xffff)) && \
Signature · 1 line
2.51.1
Niklas Cassel
maintainerPATCH 2/2 ata: libata-core: Set capacity to zero for a security locked drive
For Security locked drives (drives that have Security enabled, and have not been Security unlocked by boot firmware), the automatic partition scanning will result in the user being spammed with errors such as:
ata5.00: failed command: READ DMA
ata5.00: cmd c8/00:08:00:00:00/00:00:00:00:00/e0 tag 7 dma 4096 in
res 51/04:08:00:00:00/00:00:00:00:00/e0 Emask 0x1 (device error)
ata5.00: status: { DRDY ERR }
ata5.00: error: { ABRT }
sd 4:0:0:0: [sda] tag#7 FAILED Result: hostbyte=DID_OK driverbyte=DRIVER_OK cmd_age=0s sd 4:0:0:0: [sda] tag#7 Sense Key : Aborted Command [current]
sd 4:0:0:0: [sda] tag#7 Add. Sense: No additional sense information
during boot, because most commands except for IDENTIFY will be aborted by a Security locked drive.
For a Security locked drive, set capacity to zero, so that no automatic partition scanning will happen.
If the user later unlocks the drive using e.g. hdparm, the close() by the user space application should trigger a revalidation of the drive.
--- drivers/ata/libata-core.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/ata/libata-core.c +10 -0
@@ -3006,6 +3006,16 @@ int ata_dev_configure(struct ata_device *dev) } dev->n_sectors =ata_id_n_sectors (id); +if (ata_id_is_locked (id)) { +/* +* If Security locked, set capacity to zero to prevent +* any I/O, e.g. partition scanning, as any I/O to a +* locked drive will result in user visible errors. +*/ +ata_dev_info (dev, +"Security locked, setting capacity to zero\n" ); + dev->n_sectors =0 ; + }/* get current R/W Multiple count setting */ if ((dev->id[47 ] >>8 ) ==0x80 && (dev->id[59 ] &0x100 )) {
Signature · 1 line
2.51.1
Quoted 27 lines · Niklas Cassel
Commit
cf3fc037623c("ata: libata-scsi: Fixata_to_sense_error()status handling") fixedata_to_sense_error()to properly generate sense key ABORTED COMMAND (without any additional sense code), instead of the previous bogus sense key ILLEGAL REQUEST with the additional sense code UNALIGNED WRITE COMMAND, for a failed command.However, this broke suspend for Security locked drives (drives that have Security enabled, and have not been Security unlocked by boot firmware).
The reason for this is that the SCSI disk driver, for the Synchronize Cache command only, treats any sense data with sense key ILLEGAL REQUEST as a successful command (regardless of ASC / ASCQ).
After commit
cf3fc037623c("ata: libata-scsi: Fixata_to_sense_error()status handling") the code that treats any sense data with sense key ILLEGAL REQUEST as a successful command is no longer applicable, so the command fails, which causes the system suspend to be aborted:sd 1:0:0:0: PM:
dpm_run_callback():scsi_bus_suspendreturns -5 sd 1:0:0:0: PM: failed to suspend async: error -5
PM: Some devices failed to suspend, or early wake event detectedTo make suspend work once again, for a Security locked device only, return sense data LOGICAL UNIT ACCESS NOT AUTHORIZED, the actual sense data which a real SCSI device would have returned if locked. The SCSI disk driver treats this sense data as a successful command.
Quoted 5 lines
Reported-by Ilia Baryshnikov <[email protected]>Fixes cf3fc037623c ("ata: libata-scsi: Fix ata_to_sense_error() status handling")Signed-off-by Niklas Cassel <[email protected]>
I think that adding this to ata_scsi_flush_xlat() would be better, but this way may be able to catch more cases like sync failure. So for now, let's go with this.
Signature · 2 lines
Damien Le Moal Western Digital Research
Re: [PATCH 2/2] ata: libata-core: Set capacity to zero for a security locked drive
In reply to Niklas CasselQuoted 16 lines · Niklas Cassel
For Security locked drives (drives that have Security enabled, and have not been Security unlocked by boot firmware), the automatic partition scanning will result in the user being spammed with errors such as:
ata5.00: failed command: READ DMA
ata5.00: cmd c8/00:08:00:00:00/00:00:00:00:00/e0 tag 7 dma 4096 inres 51/04:08:00:00:00/00:00:00:00:00/e0 Emask 0x1 (device error)ata5.00: status: { DRDY ERR }
ata5.00: error: { ABRT }
sd 4:0:0:0: [sda] tag#7 FAILED Result: hostbyte=DID_OK driverbyte=DRIVER_OK cmd_age=0s sd 4:0:0:0: [sda] tag#7 Sense Key : Aborted Command [current]
sd 4:0:0:0: [sda] tag#7 Add. Sense: No additional sense informationduring boot, because most commands except for IDENTIFY will be aborted by a Security locked drive.
Quoted 7 lines
For a Security locked drive, set capacity to zero, so that no automatic partition scanning will happen.
If the user later unlocks the drive using e.g. hdparm, the
close()by the user space application should trigger a revalidation of the drive.Signed-off-by Niklas Cassel <[email protected]>
Looks good.
Signature · 2 lines
Damien Le Moal Western Digital Research
Niklas,
Quoted 5 lines
Commit
cf3fc037623c("ata: libata-scsi: Fixata_to_sense_error()status handling") fixedata_to_sense_error()to properly generate sense key ABORTED COMMAND (without any additional sense code), instead of the previous bogus sense key ILLEGAL REQUEST with the additional sense code UNALIGNED WRITE COMMAND, for a failed command.
Signature · 1 line
Martin K. Petersen
Re: [PATCH 2/2] ata: libata-core: Set capacity to zero for a security locked drive
In reply to Niklas CasselNiklas,
Quoted 3 lines
For Security locked drives (drives that have Security enabled, and have not been Security unlocked by boot firmware), the automatic partition scanning will result in the user being spammed with errors such as:
Signature · 1 line
Martin K. Petersen
Quoted 32 lines · Niklas Cassel
Commit
cf3fc037623c("ata: libata-scsi: Fixata_to_sense_error()status handling") fixedata_to_sense_error()to properly generate sense key ABORTED COMMAND (without any additional sense code), instead of the previous bogus sense key ILLEGAL REQUEST with the additional sense code UNALIGNED WRITE COMMAND, for a failed command.However, this broke suspend for Security locked drives (drives that have Security enabled, and have not been Security unlocked by boot firmware).
The reason for this is that the SCSI disk driver, for the Synchronize Cache command only, treats any sense data with sense key ILLEGAL REQUEST as a successful command (regardless of ASC / ASCQ).
After commit
cf3fc037623c("ata: libata-scsi: Fixata_to_sense_error()status handling") the code that treats any sense data with sense key ILLEGAL REQUEST as a successful command is no longer applicable, so the command fails, which causes the system suspend to be aborted:sd 1:0:0:0: PM:
dpm_run_callback():scsi_bus_suspendreturns -5 sd 1:0:0:0: PM: failed to suspend async: error -5
PM: Some devices failed to suspend, or early wake event detectedTo make suspend work once again, for a Security locked device only, return sense data LOGICAL UNIT ACCESS NOT AUTHORIZED, the actual sense data which a real SCSI device would have returned if locked. The SCSI disk driver treats this sense data as a successful command.
Reported-by Ilia Baryshnikov <[email protected]>Fixes cf3fc037623c ("ata: libata-scsi: Fix ata_to_sense_error() status handling")Signed-off-by Niklas Cassel <[email protected]>
Quoted 5 lines
--- drivers/ata/libata-scsi.c | 7 +++++++ include/linux/ata.h | 1 + 2 files changed, 8 insertions(+)
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke Kernel Storage Architect [email protected] +49 911 74053 688 SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich
Re: [PATCH 2/2] ata: libata-core: Set capacity to zero for a security locked drive
In reply to Niklas CasselQuoted 38 lines · Niklas Cassel
For Security locked drives (drives that have Security enabled, and have not been Security unlocked by boot firmware), the automatic partition scanning will result in the user being spammed with errors such as:
ata5.00: failed command: READ DMA
ata5.00: cmd c8/00:08:00:00:00/00:00:00:00:00/e0 tag 7 dma 4096 inres 51/04:08:00:00:00/00:00:00:00:00/e0 Emask 0x1 (device error)ata5.00: status: { DRDY ERR }
ata5.00: error: { ABRT }
sd 4:0:0:0: [sda] tag#7 FAILED Result: hostbyte=DID_OK driverbyte=DRIVER_OK cmd_age=0s sd 4:0:0:0: [sda] tag#7 Sense Key : Aborted Command [current]
sd 4:0:0:0: [sda] tag#7 Add. Sense: No additional sense informationduring boot, because most commands except for IDENTIFY will be aborted by a Security locked drive.
For a Security locked drive, set capacity to zero, so that no automatic partition scanning will happen.
If the user later unlocks the drive using e.g. hdparm, the
close()by the user space application should trigger a revalidation of the drive.Signed-off-by Niklas Cassel <[email protected]>--- drivers/ata/libata-core.c | 10 ++++++++++ 1 file changed, 10 insertions(+)drivers/ata/libata-core.c +3
-0@@ -3006,6 +3006,16 @@ int ata_dev_configure(struct ata_device *dev) } dev->n_sectors =ata_id_n_sectors (id); +if (ata_id_is_locked (id)) { +/* +* If Security locked, set capacity to zero to prevent
drivers/ata/libata-core.c int ata_dev_configure(struct ata_device *dev) · line 3021
Quoted 10 lines
drivers/ata/libata-core.c +7
-0+* any I/O, e.g. partition scanning, as any I/O to a +* locked drive will result in user visible errors. +*/ +ata_dev_info (dev, +"Security locked, setting capacity to zero\n" ); + dev->n_sectors =0 ; + }/* get current R/W Multiple count setting */ if ((dev->id[47 ] >>8 ) ==0x80 && (dev->id[59 ] &0x100 )) {
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke Kernel Storage Architect [email protected] +49 911 74053 688 SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich
Quoted 10 lines · Niklas Cassel
Commit
cf3fc037623c("ata: libata-scsi: Fixata_to_sense_error()status handling") fixedata_to_sense_error()to properly generate sense key ABORTED COMMAND (without any additional sense code), instead of the previous bogus sense key ILLEGAL REQUEST with the additional sense code UNALIGNED WRITE COMMAND, for a failed command.However, this broke suspend for Security locked drives (drives that have Security enabled, and have not been Security unlocked by boot firmware).
[...]
Applied to libata/linux.git (for-6.18-fixes), thanks!
[1/2] ata: libata-scsi: Fix system suspend for a security locked drive
https://git.kernel.org/libata/linux/c/b1189068 [2/2] ata: libata-core: Set capacity to zero for a security locked drive https://git.kernel.org/libata/linux/c/91842ed8
Kind regards,
Niklas