8000
Skip to content

rm(1): guard against accidental removal of /* and /dev - #2381

Open
ZhangQiyue2011 wants to merge 1 commit into
freebsd:mainfrom
ZhangQiyue2011:rm-dev-protect
Open

rm(1): guard against accidental removal of /* and /dev#2381
ZhangQiyue2011 wants to merge 1 commit into
freebsd:mainfrom
ZhangQiyue2011:rm-dev-protect

Conversation

@ZhangQiyue2011
Copy link
Copy Markdown

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 /dev and /dev/ directory, rather than extending the blocklist to /bin, /usr or other system hierarchies, for two primary reasons:

  1. /dev is a required fundamental directory on a conforming POSIX system; a running system cannot function without it.
  2. There are essentially no legitimate, routine use cases to delete the entire top-level /dev directory tree on an active, booted FreeBSD instance.

By contrast, /bin and /usr do 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 /dev is a very strong signal of an accidental mass deletion originating from patterns like rm -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 aborts
  • rm -ri /*/ → blocked, prints error and aborts
  • rm -ri /dev → blocked, prints error and aborts
  • rm -ri /dev/ → blocked, prints error and aborts
  • Ordinary file/directory removal continues to work as before

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

0