News for hackers. Stuff that matters.
Re:Pkgbase Removes FreeBSD Base System Feature by messe on Wednesday July 30, 2025 @02:43AM (#44731451)
> Consider this command:

    # pkg delete -af
> [...]

> What the same "pkg delete -af" command does on a PKGBASE FreeBSD system?

> It kills/destroys almost all of the FreeBSD Base System [...]

> POLA is the principle that made FreeBSD such predictable system. Where is the POLA now?

IMO if you convert the base system to be installed via packages and then force delete all packages, then the principle of least astonishment says that you'll delete most of the base system too.

Re:Pkgbase Removes FreeBSD Base System Feature by yjftsjthsd-h on Wednesday July 30, 2025 @02:47AM (#44731473)
There's an interesting analog to GNU rm having --preserve-root/--no-preserve-root ... Is it more or less surprising for `rm -rf /` to be special? (This isn't meant as advocating one side or the other; I think it's a genuine point of philosophical tension.)
Re:Pkgbase Removes FreeBSD Base System Feature by inopinatus on Wednesday July 30, 2025 @03:49AM (#44731793)
reminds me of that time a colleague (and FreeBSD committer) proposed su --with-wheel-group for gnu coreutils
Re:Pkgbase Removes FreeBSD Base System Feature by charcircuit on Wednesday July 30, 2025 @02:53AM (#44731502)
rm should not have permission to break the operating system. If a program can break the operating system that is a failure in the operating system's sandboxing or permissions. no-preserve-root tries to solve the issue at the wrong layer of the stack and only adresses one way to break the os. Being special to just / doesn't make sense to me.
Re:Pkgbase Removes FreeBSD Base System Feature by ender341341 on Wednesday July 30, 2025 @03:36AM (#44731736)
It's treated special cause most shells handle undefined variables as empty strings so `rm -rf "${base_path}/${sub_dir}"` can turn into `rm -rf '/'` and users commonly don't expect that.

While that case may be simple to catch the writers of gnu rm also recognize that scripts tend to not be well tested and decided "better than it currently is" is better than "we didn't do any mitigations to a common problem cause the solution wasn't perfect".

Re:Pkgbase Removes FreeBSD Base System Feature by serbuvlad on Wednesday July 30, 2025 @03:46AM (#44731783)
Ah, the beauties of the POSIX shell.
Re:Pkgbase Removes FreeBSD Base System Feature by riffraff on Wednesday July 30, 2025 @04:54AM (#44732122)
I think a valid interpretation of GPs point could be that top-level folders should have special properties so that they're not at risk of a bad rm, e.g. xattr "unchangeable" flags.

The fact that you can accidentally nuke the system seems a remnant from the olden days which we should have corrected a long time ago.

(I think GNU did a valid mitigation with preserve-root, just musing philosophically.)

Re:Pkgbase Removes FreeBSD Base System Feature by delamon on Wednesday July 30, 2025 @05:18AM (#44732274)
"immutable" top-level folders won't cut it. In order to recursively delete a folder, rm has to delete leaves first. So, you will endup with empty top-level folders, which is no better.
Re:Pkgbase Removes FreeBSD Base System Feature by charcircuit on Wednesday July 30, 2025 @06:30AM (#44732592)
>rm has to delete leaves first

There is nothing fundamental with rm for it to work like that.

Re:Pkgbase Removes FreeBSD Base System Feature by lmz on Wednesday July 30, 2025 @10:11AM (#44734474)
It does if you ever want rmdir to succeed.
Re:Pkgbase Removes FreeBSD Base System Feature by ender341341 on Wednesday July 30, 2025 @03:51PM (#44738779)
I think they mean that rm could check the folder you're trying to delete and see if it has whatever attribute and if so don't delete it's contents. so "rm -rf /" would see that '/' has it and be a no-op, but '~/home/foo' doesn't so it would recurse and start deleting. It could go further do that check for each sub directory recursively, so say '~/home/foo/bar/baz' that 'bar' does have the flag so `rm -rf ~/home/foo/` would delete everything else from the foo folder but leave bar and it's descendants alone.
Re:Pkgbase Removes FreeBSD Base System Feature by ender341341 on Wednesday July 30, 2025 @04:02PM (#44738882)
That's reasonable, I was mainly responding to this part

> Being special to just / doesn't make sense to me.

and explaining why being special to / can make sense. I too often feel like people see comments like that and decide to let perfect get in the way of better in their own work.

Re:Pkgbase Removes FreeBSD Base System Feature by grahamjperrin on Thursday July 31, 2025 @08:41PM (#44751829)
> … GPs point …

I'm slightly disoriented, who's the other GP?

(I'm a GP.)

Re:Pkgbase Removes FreeBSD Base System Feature by josefx on Wednesday July 30, 2025 @03:25AM (#44731672)
At some point you have to give something the ability to update and modify system components and even then it is extreemely unlikely that deleting everything starting with / is the intended behavior.
Re:Pkgbase Removes FreeBSD Base System Feature by mcherm on Wednesday July 30, 2025 @04:23AM (#44731982)
An EXTRA flag to rm could be required in order for it to be able to modify fundamental os files. This would eliminate nearly all accidents.
Re:Pkgbase Removes FreeBSD Base System Feature by dspillett on Wednesday July 30, 2025 @05:43AM (#44732407)
Though that requires rm to know what objects are fundamental. While there are some obvious static choices there are many others that are going to vary between installations. You could add extended attributes to indicate what is what, but that is an extra complication for distro maintainers. You could use the immutable flag though again that will be a faf for upgrades (remove flags, update files, replace flags). Once rm is protecting users in this way, there might be an expectation that other tools will too, but the time you get to this point rather than reinventing the while, perhaps just use something like selinux (I assume BSD has an equivalent capabilities based option?) and other existing control features.

rm having --preserve-root on by default is I think a simple mitigation that protects against the most common potential accidents than any of the above would protect from, and if something more than that is wanted then things like the immutable flag already exist and would cover far more than just rm.

Re:Pkgbase Removes FreeBSD Base System Feature by josefx on Thursday July 31, 2025 @04:23AM (#44743552)
You already have to login as root to modify fundamental os files and any modification can break things just as baldy as rm can.
Re:Pkgbase Removes FreeBSD Base System Feature by charcircuit on Wednesday July 30, 2025 @06:31AM (#44732594)
I agree, but rm doesn't have to be the thing to modify system files.
Re:Pkgbase Removes FreeBSD Base System Feature by serbuvlad on Wednesday July 30, 2025 @03:45AM (#44731776)
Why?

Obviously rm -rf / will only "destroy the operating system" if the user is root and we're in the root namespace. There is nothing stopping you from building a sandboxed OS that never gives your users real root (Android).

But what'd be the point of that? Users care about their data, not about their OS internals. If the OS blows, that's just an OS reinstall. But if a non-backed-up /home blows, that could be months of work. And any program that can delete a file in /home (as they need to be able to do to allow the user to do everyday work) can also delete all of them.

Re:Pkgbase Removes FreeBSD Base System Feature by charcircuit on Wednesday July 30, 2025 @06:33AM (#44732608)
>not about their OS internals

Yes, they do. Users definitely care about their system being able to properly boot and work correctly. It's unnaceptable how Linux distros make you use a live usb to go in and fix them instead of having a built in way to the OS for it to recover from bad things happening.

Re:Pkgbase Removes FreeBSD Base System Feature by hulitu on Wednesday July 30, 2025 @11:10AM (#44735254)
> rm should not have permission to break the operating system.

It doesn't. You must su to root to "achieve" that.

Re:Pkgbase Removes FreeBSD Base System Feature by yjftsjthsd-h on Wednesday July 30, 2025 @11:38AM (#44735632)
> no-preserve-root tries to solve the issue at the wrong layer of the stack and only adresses one way to break the os. Being special to just / doesn't make sense to me.

I could see that making sense. Maybe a "really important core OS" attribute? (I wouldn't want `rm /bin/sh` to run without forcing either.)

However,

> If a program can break the operating system that is a failure in the operating system's sandboxing or permissions.

Not necessarily. I have on multiple occasions logged into a machine, gotten a root shell, and then told it to wipe its own disks (either by block discard, or just dding over with /dev/null). That is a legitimate use that should work.

Re:Pkgbase Removes FreeBSD Base System Feature by charcircuit on Wednesday July 30, 2025 @12:37PM (#44736401)
>and then told it to wipe its own disks

This can be done via a dedicated factory reset or wipe feature. It doesn't need to be the responsibility of rm.

Re:Pkgbase Removes FreeBSD Base System Feature by yjftsjthsd-h on Wednesday July 30, 2025 @03:02PM (#44738223)
It sounded like you were arguing that no program should be able to do it, which makes it somewhat difficult to implement a wipe feature. (And whatever wipe/reset feature we have needs to be done by some operating system, because a solution that requires adding new features to everything's firmware is a non-starter in practice)
Re:Pkgbase Removes FreeBSD Base System Feature by throw0101d on Wednesday July 30, 2025 @07:02AM (#44732763)
> Is it more or less surprising for `rm -rf /` to be special?

A few years the POSIX folks declared that the behaviour of `rm -rf /` nuking the entire file system is a bug.

IIRC, one of the Sun Solaris folks (Cantrill? Gregg? Other?) thought the behaviour was dumb and argued successfully that it should not be work that way. Any implementation that does it is not POSIX-compliant.

Re:Pkgbase Removes FreeBSD Base System Feature by hulitu on Wednesday July 30, 2025 @11:06AM (#44735202)
> A few years the POSIX folks declared that the behaviour of `rm -rf /` nuking the entire file system is a bug.

Yes. PEBKAC bug. /s

Re:Pkgbase Removes FreeBSD Base System Feature by pjmlp on Wednesday July 30, 2025 @08:34AM (#44733392)
Once upon a time I nuked a GNU/Linux installation exactly with that command, due to a finger race between backspace and return keys.
Re:Pkgbase Removes FreeBSD Base System Feature by hulitu on Wednesday July 30, 2025 @11:08AM (#44735219)
Re:Pkgbase Removes FreeBSD Base System Feature by znpy on Wednesday July 30, 2025 @03:23AM (#44731653)
What is POLA in this context?
Re:Pkgbase Removes FreeBSD Base System Feature by phkamp on Wednesday July 30, 2025 @03:25AM (#44731663)
POLA = Principle Of Least Astonishment
Re:Pkgbase Removes FreeBSD Base System Feature by grahamjperrin on Saturday August 02, 2025 @01:09AM (#44765024)
I think, messe means that removal is _not_ astonishing, if removal is not simply requested.

Removal is forcibly requested.

The force means, remove more than what's normal. An abnormal removal.