fix(tools): judge the rm guard by base name so absolute paths cannot bypass it
checkRecursiveDelete compared the raw segment name, `seg.Name != "rm"`, while every sibling rule in the same table resolves the command through baseName -- checkMkfs, checkBlockDeviceWrite, checkKillAll, checkSystemPower, checkSelfTermination and checkDaemonLaunch all call baseName(seg.Name), and baseName's own doc says its purpose is that /sbin/reboot and reboot are judged the same. The test suite already pinned that convention for /sbin/poweroff. Because tokenise yields the raw first word, `/bin/rm -rf /` produced seg.Name == "/bin/rm", the rule declined, no other rule matched, and Hardline returned nil. Since provider/builtin calls command.Hardline on the shell tool's command field before every execution, an absolute path defeated the recursive-root-delete gate entirely. `/bin/rm -rf /etc` (any critical path, not just the root) was equally reachable; an overlay probe confirmed both, and confirmed the sibling /sbin/poweroff case was already correct. Resolve through baseName, matching the rest of the rule table, and add table cases for absolute-path rm plus an allow case for an ordinary absolute-path recursive delete so the normalisation cannot over-block. Found by an adversarial package sweep (temp tracker: tools-command-1, .local/issue-tracker/).
This commit is contained in:
1 parent
db18d2675a
commit
b0e7b03ca1
2 files changed
+17
-1
No files matched your search
@@ -205,8 +205,12 @@ var criticalPaths = map[string]bool{
|
||||
|
||||
// checkRecursiveDelete refuses a recursive rm whose target is a critical
|
||||
// path. A recursive delete elsewhere is ordinary work and is allowed.
|
||||
//
|
||||
// The command is resolved through baseName so that /bin/rm and rm are judged
|
||||
// alike, matching every sibling rule: comparing the raw segment name let
|
||||
// /bin/rm -rf / through while blocking rm -rf /.
|
||||
func checkRecursiveDelete(seg Segment) (string, bool) {
|
||||
if seg.Name != "rm" {
|
||||
if baseName(seg.Name) != "rm" {
|
||||
return "", false
|
||||
}
|
||||
if !hasRecursiveFlag(seg.Args) {
|
||||
|
||||
@@ -22,6 +22,15 @@ func TestHardlineBlocks(t *testing.T) {
|
||||
{"root delete dot", "rm -rf /.", "recursive-root-delete"},
|
||||
{"root delete long flag", "rm --recursive --force /", "recursive-root-delete"},
|
||||
{"root delete bundled reverse", "rm -fr /", "recursive-root-delete"},
|
||||
// An absolute path must be judged the same as a bare name: every sibling
|
||||
// rule already normalises through baseName, and baseName's own doc says
|
||||
// /sbin/reboot and reboot are meant to be judged alike. Comparing the raw
|
||||
// segment name here let /bin/rm -rf / through while blocking rm -rf /.
|
||||
{"absolute path root delete", "/bin/rm -rf /", "recursive-root-delete"},
|
||||
{"absolute path root delete reverse", "/usr/bin/rm -fr /", "recursive-root-delete"},
|
||||
{"absolute path root delete long flag", "/usr/bin/rm --recursive --force /", "recursive-root-delete"},
|
||||
{"absolute path etc delete", "/bin/rm -rf /etc", "recursive-root-delete"},
|
||||
{"absolute path sudo delete", "sudo /bin/rm -rf /", "recursive-root-delete"},
|
||||
{"home delete", "rm -rf ~", "recursive-root-delete"},
|
||||
{"home var delete", "rm -rf $HOME", "recursive-root-delete"},
|
||||
{"home brace delete", "rm -rf ${HOME}/", "recursive-root-delete"},
|
||||
@@ -129,6 +138,9 @@ func TestHardlineAllows(t *testing.T) {
|
||||
{"recursive delete in workspace", "rm -rf /workspace/tmp"},
|
||||
{"recursive delete of subdir", "rm -rf /var/lib/archie/work/tmp"},
|
||||
{"non-recursive root file", "rm /tmp/x"},
|
||||
// Normalising through baseName must not turn an ordinary recursive delete
|
||||
// that happens to use an absolute path into a refusal.
|
||||
{"absolute path recursive delete in workspace", "/bin/rm -rf /workspace/tmp"},
|
||||
|
||||
{"dd to a file", "dd if=/dev/zero of=disk.img bs=1M count=10"},
|
||||
{"redirect to null", "echo x > /dev/null"},
|
||||
|
||||
Reference in new issue
Block a user