fix(wipe): harden verify_wipe and host_info audit safety#38
Merged
Conversation
Fixes several correctness bugs in the NIST 800-88 wipe library that could cause the post-wipe verification and audit log to silently misreport. verify_wipe (FR-076/077/092/093/098): - Method-aware pattern check. Overwrite methods (nwipe random, used for hdd/usb-flash/fallback) leave RANDOM data; the old all-zeros/0xFF check ALWAYS failed on them (false negative). Now overwrite types verify that a sample is not an unwritten all-0x00 block, while erase types (nvme-ssd/sata-ssd and SED crypto variants) still require zeros/0xFF. - Full-width sample offset. RANDOM is only 15 bits, so RANDOM*RANDOM (max ~1.07e9 blocks ≈ 550GB) never sampled the tail of larger drives; a 2TB drive sampled only ~27% of its capacity. Combine three draws for 45 bits of range, covering any real drive. - Detect read failures. A failed dd read is no longer silently treated as a passing sample; with pipefail the I/O error fails verification. - Add od -v. Without it, od collapses repeated 16-byte lines to a "*" marker, so even a correctly all-zeroed drive never matched the pattern. - verify_wipe now takes the drive type; wipe-now.sh and wipe-wizard.sh pass it through. host_info (FR-078/094): - Build the host JSON with python3 json.dumps instead of raw printf. A DMI value containing a double-quote produced invalid JSON that crashed init_audit's json.loads() and aborted audit initialization. Values are passed as argv so they cannot inject code. Adds tests/test_verify_wipe.sh covering host_info escaping, the method-aware pattern logic, read-failure handling, and full-range offset coverage on a simulated 2TB drive.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes six confirmed correctness bugs in the NIST 800-88 wipe library (
autorun/wipe-lib.sh). All were verified by real execution before fixing, and are covered by a new test.Resolves: FR-076, FR-077, FR-078, FR-092, FR-093, FR-094, FR-098 (Redmine #48104, #48105, #48106, #48084, #48085, #48086, #48090).
verify_wipenwipe random→ hdd/usb-flash/fallback) leave random data; the old all-zeros/0xFF check always failed on them (false negative). Overwrite types now verify the sample is not an unwritten all-0x00 block; erase types (nvme-ssd/sata-ssd+ SED crypto variants) still require zeros/0xFF.RANDOMis 15 bits, soRANDOM*RANDOM(max ~1.07e9 blocks ≈ 550 GB) never sampled the tail of larger drives — a 2 TB drive sampled only ~27 %. Now combines three draws for 45 bits of range.ddread is no longer silently treated as a passing sample. (wipe-lib.shalready setspipefail; the actual defect was the swallowed read inverify_wipe, not awipe_driveddcall —wipe_driveusesnwipe.)od -vfix (found during testing): without it,odcollapses repeated 16-byte lines to a*marker, so even a correctly all-zeroed drive never matched the pattern — the original verify would have false-negatived on zeroed drives too.dtypearg;wipe-now.shandwipe-wizard.shpass it through.host_info(FR-078/094)python3 json.dumpsinstead of rawprintf. A DMI value containing a"produced invalid JSON that crashedinit_audit'sjson.loads()and aborted audit initialization. Values are passed as argv (no code injection).Testing
tests/test_verify_wipe.sh(new) covers host_info escaping, method-aware pattern logic, read-failure handling, and full-range offset coverage on a simulated 2 TB drive. Full suite green;shellcheck --severity=warningclean on all changed files.Notes / out of scope
wipe-lib.shhas 4 pre-existing SC2034 warnings (YELLOW/CYANused by sourcing scripts;remainder/method_cmddead vars) — not introduced here; left untouched to keep this change surgical.local rc=$?) and FR-099 (shred pass count) were investigated and are not bugs — see the respective Redmine tickets for the evidence.