rm(1): guard against accidental removal of /* and /dev - #2381
Open
ZhangQiyue2011 wants to merge 1 commit into
Open
rm(1): guard against accidental removal of /* and /dev#2381ZhangQiyue2011 wants to merge 1 commit into
ZhangQiyue2011 wants to merge 1 commit into
Conversation
Reject attempts to remove /*, /dev, /*/, or /dev/ via an early argument check. This mitigates accidental mistakes only, and will not prevent deliberate destructive operations. Signed-off-by: Zhang Qiyue <peter-open-source.probing805@aleeas.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.
This change adds an early argument check in rm to reject attempts to remove
/*,/dev,/*/, or/dev/.This mitigation only targets accidental mass deletion from patterns such as
rm -rf /*; deliberate destructive operations are not blocked.This guard only blocks removal of the top-level
/devand/dev/directory, rather than extending the blocklist to/bin,/usror other system hierarchies, for two primary reasons:/devis a required fundamental directory on a conforming POSIX system; a running system cannot function without it./devdirectory tree on an active, booted FreeBSD instance.By contrast,
/binand/usrdo have valid scenarios for full removal, such as chroot construction, embedded system customization, and root filesystem refactoring. Blocking them would interfere with legitimate system-administration workflows.Additionally, an argument list containing
/devis a very strong signal of an accidental mass deletion originating from patterns likerm -rf /*. In such a failure mode, we abort the entire operation immediately instead of filtering out only the dangerous path and continuing to delete remaining items. Broken scripts or catastrophic typos should not be partially tolerated.Tested:
rm -ri /*→ blocked, prints error and abortsrm -ri /*/→ blocked, prints error and abortsrm -ri /dev→ blocked, prints error and abortsrm -ri /dev/→ blocked, prints error and aborts