fix(hide-hardware-info): look up group with getent#375
Open
maybebyte wants to merge 1 commit into
Open
Conversation
The sysfs/cpuinfo whitelist gated its chgrp/chmod on
`grep -q "${1}" /etc/group`, an unanchored substring match over the
whole file. A group whose name merely contains the string, or a user
listed as a member of any group, produced a false positive: the branch
ran chgrp against a group that does not exist (silently swallowed by
`|| true`) and suppressed the "group does not exist" warning, so an
admin who never created the group was told nothing.
Use `getent group "${1}"` instead. It matches by exact group name or
GID and consults NSS, so groups from non-file sources are recognized
as well.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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
hide-hardware-infodecides whether to hand/sys(or/proc/cpuinfo) to adedicated whitelist group based on whether that group exists, but tested
existence with an unanchored
grepover/etc/groupthat false-matches. Thisswitches the check to an exact, NSS-aware
getentlookup.Changes
grep -q "${1}" /etc/groupmatched the group name (sysfs/cpuinfo) as a substring anywhere in the file — including inside a longergroup name or a group's comma-separated member list. On a false positive the
branch ran
chgrpagainst a group that does not exist (silently swallowed by|| true) and suppressed the "group does not exist" warning, so the whitelistquietly did nothing while the code path reported success.
getent group "${1}", which matches by exact groupname/GID and consults NSS, so groups from non-file sources (LDAP,
systemd-userdb, SSS) are recognized too.
Testing
bash -n usr/libexec/security-misc/hide-hardware-info#security-misc-shared—parses cleanly.
printf 'plugdev:x:46:sysfs\n' | grep -q sysfsmatches (exit 0) although no group namedsysfsexists, whereasgetent group sysfsreturns no such group (exit 2) on the same host.chgrp/chmodon a live/syswith a realwhitelist group) requires root and mutates system state; the change is
isolated to the existence check.
Notes for reviewers
sysfs/cpuinfoexists —getentand the oldgrepboth match; only the false-positive paths differ.