martijnvanbrummelen / nwipe

nwipe secure disk eraser
GNU General Public License v2.0
631 stars 71 forks source link

Fix hidden sector detection for logical 4096 sector size #543

Closed PartialVolume closed 5 months ago

PartialVolume commented 5 months ago

This fixes an issue where nwipe detects a discrepancy between the number of sectors reported by hdparm and nwipe's own HPA/DCO functions that were reporting the same values, using number of sectors based on 512 byte sectors but disagreed with the number of sectors generated from libata which was reporting the number of sectors based on 4096 byte sectors.

This has been fixed by always calculating the number of sectors returned by libata using 512 bytes per sector so a direct comparison can be made to data from hdparm & nwipe's HPA/DCO functions.

PartialVolume commented 5 months ago

HELP NEEDED to test hidden sector detection on 4096/4096 sector drives @Firminator @ggruber @mdcato or anybody else that may have such a drive.

This patch needs testing on 4096 logical sector drives. All my drives are 512/512 or 512/4096 logical/physical so no good for this test. I've tried setting the sector size but none of my drives seem to support that feature of hdparm. The logical/physical sectors as reported by fdisk -l

Disk /dev/nvme0n1: 931.51 GiB, 1000204886016 bytes, 1953525168 sectors Disk model: WD Blue SN570 1TB
Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes

To test:

Locate a disk that reports a logical sector size as 4096/4096, possibly enterprise ? Unfortunately my 12TB EXOS drives are 512/4096 so no good.

Create a hidden sector in the disk with hdparm, i.e

Example

# Determine sectors and whether there is already hidden sectors
hdparm -N /dev/sdc

# where xxxxxxxxxxx is the number of sectors reported above -1
hdparm -N xxxxxxxxxxxx /dev/sdc

# IMPORTANT, send system to sleep or power cycle drive

Confirm nwipe v0.35.6 reports a hidden sector and in the nwipe logs it's the expected size

Reset the HPA so there is no hidden sector

# xxxxxxxxxx is the original (real) number of sectors
hdparm -N xxxxxxxxxxxx /dev/sdc

# IMPORTANT, send system to sleep or power cycle drive

Check nwipe v0.35.6 reports no hidden sector

Thanks !

PartialVolume commented 5 months ago

Also see #542 that describes the false positive on a 4096/4096 encrypted drive.

PartialVolume commented 5 months ago

Once I get confirmation this patch #543 works correctly for detecting hidden sectors on 4096/4096 logical/physical disk drives I'll release nwipe v0.36

ggruber commented 5 months ago

unfortunately I'm struggling with a new nwipe test box with 3,5" drive bays. Hope the get around this in the next two days. But afaik I have no 4kn drive on my shelfs, only 512n and 512e. Even a ST16000NM001G I've my hands on as borrowed offers 512e mode.

PartialVolume commented 5 months ago

@ggruber thanks for checking, 4096/4096 drives seem to be a very rare drive, I read somewhere that the PS3 drive was formatted this way. Unfortunately I don't have any of those either.

ggruber commented 5 months ago

my 3,5" Testbox is running now, but no 4kn disk, sry

PartialVolume commented 5 months ago

No problem, these Western Digital Red Pro - 6TB 7200RPM 4Kn SATA III 6Gb/s 128MB Cache 3.5" NAS Network Hard Drive - WD6002FFWX are 4Kn, is that something you might come across?

Firminator commented 5 months ago

Western Digital UltraStar has a bunch of 4Kn drives.

DC HC530 (14TB) DC HC520 (12TB) DC HC510 (10TB) DC HC320 (8TB) DC HC310 (4 and 6 TB)

Model number is important. Only the ones ending with 42XX (SAS) or N6XX (SATA) are 4Kn. Example: HUH721212ALN600 (looks like a HGST model number in my mind, did WD buy Hitachi/HGST?)

source: research on a new power saving feature (PWDIS - Power Disable) that effectively prevents newer gen enterprise drives to not power when using different SAS or SATA power connectors than what came with the server. We came across this the other day trying to wipe a retired SAN. See https://documents.westerndigital.com/content/dam/doc-library/en_us/assets/public/western-digital/collateral/tech-brief/tech-brief-western-digital-power-disable-pin.pdf

Other vendors are aslo affected: https://global.icydock.com/product/faq/Power_Disable_Feature_25_35_SATA_SAS_HDD_SSD_list.pdf

Video Fix: https://invidious.fdn.fr/watch?v=fnISM_LMuss

PartialVolume commented 5 months ago

@Firminator So like this one

They are not cheap! I did think about buying one but that's too expensive for me for just a occasional test drive.

Thanks for the info re PWDIS, interesting.

mdcato commented 5 months ago

Sorry for the delay responding, and also sorry all drives I have available are 512/4096.


From: PartialVolume @.> Sent: Saturday, February 3, 2024 16:34 To: martijnvanbrummelen/nwipe @.> Cc: Mike Cato / Hays Technical Services @.>; Mention @.> Subject: Re: [martijnvanbrummelen/nwipe] Fix hidden sector detection for logical 4096 size (PR #543)

HELP NEEDED to test hidden sector detection on 4096/4096 sector drives @Firminatorhttps://github.com/Firminator @ggruberhttps://github.com/ggruber @mdcatohttps://github.com/mdcato or anybody else that may have such a drive.

This patch needs testing on 4096 logical sector drives. All my drives are 512/512 or 512/4096 logical/physical as reported by fdisk -l

To test:

Locate a disk, possibly enterprise ? although my 12TB EXOS drives are 512/4096 that has 4096/4096 logical/physical sector sizes.

Create a hidden sector in the disk with hdparm, i.e

Example

Determine sectors and whether there is already hidden sectors

hdparm -N /dev/sdc

where xxxxxxxxxxx is the number of sectors reported above -1

hdparm -N xxxxxxxxxxxx /dev/sdc

IMPORTANT, send system to sleep or power cycle drive

Confirm nwipe v0.35.6 reports a hidden sector and in the nwipe logs it's the expected size

Reset the HPA so there is no hidden sector

xxxxxxxxxx is the original (real) number of sectors

hdparm -N xxxxxxxxxxxx /dev/sdc

IMPORTANT, send system to sleep or power cycle drive

Check nwipe v0.35.6 reports no hidden sector

Thanks !

— Reply to this email directly, view it on GitHubhttps://github.com/martijnvanbrummelen/nwipe/pull/543#issuecomment-1925473017, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ANGK2PSMKIF6SGK67WQOG7LYR23QJAVCNFSM6AAAAABCYKRLJOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMRVGQ3TGMBRG4. You are receiving this because you were mentioned.Message ID: @.***>

PartialVolume commented 5 months ago

No problem, I'm sure somebody will turn up with one eventually.