Repository navigation
Correctness and CI hardening: BAR parse, cap sizing, check exit code, --from-json validation, barmodel panics, lint in CI - #96
Closed
NetVar1337 wants to merge 6 commits into
Conversation
The retry Sscanf discarded its result and Size = end - start + 1 ran with no end >= start guard, so a partially parsed or inverted resource line produced a uint64 underflow (~1.8e19-byte BAR) that flowed into aperture/clamp math. Reject lines that don't parse to three fields or have end < start.
capSizeAt recomputed cap size from a static map defaulting to 8 bytes, so zeroVendorRegisters zeroed bytes belonging to unrecognized caps >8B and findFreeCapSpace could overlap-inject. capSize now uses the exact inter-cap extent recorded in cap.Data for linked caps, keeping the conservative floor for the terminal cap (whose Data runs to end-of-space).
run() always returned nil, so scripted 'check && build' pipelines could never gate on a bad donor. Return an error (and silence the cobra usage dump) when issues are found.
device_context.json is an untrusted boundary. UnmarshalJSON copied config_space_size straight into ConfigSpace.Size; an out-of-range value made Bytes() and Size-bounded consumers read past the fixed 4096-byte array. Require the declared size to match the hex-word count and fit the backing array, and clamp Size in NewConfigSpaceFromBytes.
validateModel panicked on the normal build path, aborting the whole CLI on a misaligned/duplicate offset or overlapping mask. It now returns an error: BuildBARModels propagates it, and BuildBARModel/SynthesizeBARModel log and return nil (callers already handle nil) so a bad spec table or hostile donor-derived probe degrades gracefully.
The configured linters never ran in CI, so PRs merged unlinted. Add a lint job and migrate .golangci.yml to the v2 schema required by the go 1.26 toolchain (gosimple is now folded into staticcheck); set max-issues limits to 0 so findings are no longer silently capped.
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.
Six focused correctness/hardening fixes, each with a test where it adds behavior. Full
go test ./...,go vet, andgofmtare clean.Fixes
ParseBARsFromSysfsResourcediscarded the retrySscanfresult and computedSize = end - start + 1with noend >= startguard, so a partially parsed or invertedresourceline produced auint64underflow (~1.8e19-byte BAR) that flowed into aperture/clamp math. Now rejected as a disabled BAR.capSizeAtrecomputed cap size from a static map defaulting to 8 bytes, sozeroVendorRegisterszeroed bytes belonging to unrecognized caps larger than 8B (SATA idx/data, HyperTransport, AF…) andfindFreeCapSpacecould overlap-inject. NewcapSizeuses the exact inter-cap extent fromcap.Datafor linked caps, keeping the conservative floor for the terminal cap (whoseDataruns to end-of-space, so it must not claim the trailing gap).checkalways returnednil, so scriptedcheck && buildpipelines could never gate on a bad donor. It now returns an error (with the cobra usage dump silenced) when issues are found.device_context.jsonis an untrusted boundary;UnmarshalJSONcopiedconfig_space_sizestraight intoConfigSpace.Size, and an out-of-range value madeBytes()/ size-bounded consumers read past the fixed 4096-byte array. The declared size must now match the hex-word count and fit the backing array;NewConfigSpaceFromBytesalso clampsSize.validateModelpanicked on the normal build path, aborting the whole CLI on a misaligned/duplicate offset or overlapping mask. It now returns an error:BuildBARModelspropagates it, andBuildBARModel/SynthesizeBARModellog and returnnil(callers already handlenil) so a bad spec table or hostile donor-derived probe degrades gracefully. Signatures unchanged.lintjob and migrates.golangci.ymlto the v2 schema required by the go 1.26 toolchain (gosimpleis now folded intostaticcheck);max-issueslimits set to 0 so findings are no longer silently capped.Tests
TestParseBARsFromSysfsResourceMalformed— inverted / truncated / unparsable resource lines are disabled.TestCapSizePrefersChainExtentButFloorsTerminalCap— inner cap reports its full 16-byte extent; terminal cap falls back to the static floor.TestDeviceContext_RejectsBadConfigSpaceSize— mismatched / negative / oversizedconfig_space_sizeare rejected; a consistent in-range size round-trips.Notes
lintjob pins the action by tag with aTODOto convert to a commit SHA (matching the other actions inci.yml) once a golangci-lint v2 release is chosen. First run may surface pre-existing findings the old 50/5 caps hid; no new linters (gosec etc.) were added here to avoid a red gate on day one.