Conversation
SysctlCheck discarded the error from sysctl.Get and keyed only off an empty value, so on Linux it could not distinguish "this knob does not exist on this kernel" from "this knob exists but could not be read or its value was not recognized". Both collapsed to Unknown. kernel.exec-shield is the clearest case: it was a RHEL-only patch that no longer exists in any modern kernel, so it always rendered as Unknown, implying the check was inconclusive rather than inapplicable. Drive the result off the read error instead: fs.ErrNotExist now maps to N/A, while an unreadable, empty, or unrecognized value keeps Unknown. This applies to every sysctl in the registry, not just exec-shield. The runtime.GOOS special case is no longer needed -- platforms without /proc/sys hit the same ErrNotExist path and still report N/A. Fixes #355 Claude-Session: https://claude.ai/code/session_01QKUqcgQ5TDA2GYJh2MKX9s
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.
Fixes #355
Problem
SysctlCheckdiscarded the error fromsysctl.Getand keyed only off an empty value, so on Linux it could not distinguish two very different situations:Both collapsed to
Unknown.kernel.exec-shieldis the clearest case — it was a RHEL-only patch that no longer exists in any modern kernel, so it always rendered asUnknown, implying the check was inconclusive rather than inapplicable.Fix
Drive the result off the read error instead.
fs.ErrNotExistmaps toN/A; an unreadable, empty, or unrecognized value keepsUnknown.The issue suggested gating on kernel version. I went with presence detection instead: exec-shield's absence isn't tied to a version boundary (it never existed in vanilla kernels at all), and presence detection generalizes to every sysctl in the registry rather than special-casing one. On the reporter's system that also cleans up anything else their kernel doesn't build in — e.g.
dev.tty.legacy_tiocsti,vm.unprivileged_userfaultfd, orkernel.yama.ptrace_scopewithout YAMA.This also removes the
runtime.GOOSspecial case: platforms without/proc/syshit the sameErrNotExistpath and still reportN/A, so behavior there is unchanged.Kernel config checks already handled this correctly — absent options are skipped entirely in
KernelConfig— so no change was needed there.Testing
pkg/checksec/sysctl_test.gocovering each branch: absent knob, permission-denied knob, empty value, unmapped value, mapped valuegofmt/go vetclean,go build ./...OK, fullgo test ./...passesOne caveat worth stating plainly: I could not exercise this end-to-end against a real Linux kernel locally (macOS has no
/proc, no Docker available), so the Linux path is covered by unit tests on the extractedresolveSysctlResultrather than a live run. CI should cover the real thing.Docs
Updated the two
Unknownentries in the README's sample kernel output (kernel.yama.ptrace_scope,kernel.exec-shield) to match.checksec.bashalready printsUnsupportedfor a missing exec-shield and was left alone.https://claude.ai/code/session_01QKUqcgQ5TDA2GYJh2MKX9s