59 points · by Bender · 2y ago · 78 comments
I understand the historical reasoning for the / vs /usr vs /usr/local split —
• / was a mount of the machine vendor's installation-engineering-provided bring-up tape — a tape that could usually be safely unmounted once boot was complete and the kernel + persistent daemons had loaded into RAM. (We still have something akin to this in Linux land in the form of the initramfs!)
• /usr was a read-only-mounted OS distribution, either spooled onto the same tape drive that had been reading the rootfs tape a moment before, or (later) over NFS from a high-read-IOPS shared disk server, where in either case the mountpoint was expected to never go away while the OS was running, and therefore the loader could spawn binaries from here using flushable memory-mapped disk IO (allowing far more running processes to fit within the machine's limited memory — important for time-sharing!);
• /usr/local was a separate site-specific mount of stuff added by the local sysadmin — often created as a separate "tacked on the end" partition on the OS distribution tape (you could just attach more tape on the end of the reel, and then format it!) Later, once machine-local hard disks were a thing but Unix systems were still generally mounting /usr over NFS, /usr/local evolved to be the read-only partition of the machine-local HD (and such systems gained a matching read-write local-disk partition, /var.)
But $PREFIX/bin and $PREFIX/sbin were, as far as I know, always just regular directories under the same $PREFIX-level mountpoint, never separate mountpoints of their own.
The only difference I can even think of between a $PREFIX/bin and a $PREFIX/sbin dir, is that the $PREFIX/sbin dir wasn't in $PATH for most users. But surely that was never a real line of defense for security?
Even in 1994 this was still common, https://archive.org/details/learningunix0000gard/page/48/mod...
But why does Kernighan, on that same page, mention /usr/bin already being a thing? If /usr is what we would today call /home, why does it have a bin subdir?
Look at row #3.
None of the mainstream distributions create nor manage that directory for you.
The idea is that if a user needs some kind of software and is able to build it autonomously then they can set $PATH and other environment variables to make it available to the session. Please note that in ~/.local there are bin, man, lib and other directories, so you can pretty much build, install and run what you need without bothering your sysadmin :)
These days… some package managers might put stuff in there so that they can work without needing root permission and without messing up with the general system.
That was retconned, actually. My understanding is that the original "/usr" was a second RK05 disk pack added to an early system at Bell Labs for storing stuff owned/created/managed by "users" instead of the system folks. Space was precious in those days and RAID was still a decade in the future. You got your 2MB and had to decide where to mount it and what to put there.
Early Unix filesystems were an ad-hoc wreck, basically. Sun cleaned this up a lot as they moved (or tried to move) to NFS as the primary filesystem for workgroup installations, which is where we get the modern ideas from that you are tagging "historical". I believe (but am not sure) that "sbin" hails from this era.
Then Red Hat came by another decade later and further symmetrized the rules, but in the process essentially obsoleted the distinction between "/" and "/usr", etc...
> Utilities used for system administration (and other root-only commands) are stored in /sbin, /usr/sbin, and /usr/local/sbin. /sbin contains binaries essential for booting, restoring, recovering, and/or repairing the system in addition to the binaries in /bin. ...
> Originally, /sbin binaries were kept in /etc. ...
> Deciding what things go into "sbin" directories is simple: if a normal (not a system administrator) user will ever run it directly, then it must be placed in one of the "bin" directories. Ordinary users should not have to place any of the sbin directories in their path.
I don't think it was a security thing, more a usability thing? Why see "reboot" on your path when you can't use it?
Why did you go to so much effort to avoid typing 'usr'?
(And bevcause GNU autotools uses the variable $PREFIX to abstract away the differences between these — you can `./configure --prefix=/usr` or `./configure --prefix=$HOME/.local` if you like.)
Hard disks used to fail pretty often, filesystems had (and still have) bugs. It makes sense to stick your administrative utilities needed to run/recover a given system in its own little less frequently modified filesystem vs. user applications that tend to see more churn/use in general.
It's not strictly a disk space issue.
While I was looking up that link, I found the original discussion for Fedora 10 (2008) about adding /usr/sbin to $PATH which was a little more controversial (at the time): https://lists.fedoraproject.org/archives/list/devel@lists.fe...
An application can be thought of as a combination of the binary, libraries, resources, and state. By default the applications needs to be able to read any of these and be able to read and write the state. Unix's FSH's biggest problem is that it tries to group files together by type instead of grouping files together by application. Nix can technically group things by application, but it is not really standardized so things can get messy and it is still normal for applications to read and write files from anywhere.
That's not really scattered. /nix/store has the generated files. They get linked to /etc if the app requires that kind of thing - often it's just added to the arguments instead. ~/.config is for user preferences (possible to flip at app runtime or static) which are not a system setting. /var is for system services states. Those are very separate use cases and get managed in different ways. The apps should also never be aware that /nix/store is a thing.
To me they all look the same. For example you could have a /nix/state that had a directory for each program. Each program could have its own global and user specific state it could manage from within its directory.
Those are features, not bugs... There are reasons for all of those existing and for why you wouldn't want everything in a centralized place.
https://wiki.gobolinux.org/Overview/GoboLinux-Filesystem-Hie...
Source: https://nixos.wiki/wiki/Overview_of_the_NixOS_Linux_distribu...
That sounds horrible. NixOS sounded kind of interesting, but if that's true it kills any interest I had in it.
Packages are installed into /usr/bin and /usr/sbin.
Locally-built software (e.g. `./configure --prefix=/; make; make install`) is installed into /usr/local/bin and /usr/local/sbin, which should still always require elevated privileges to write to.
~/.local/bin is convenient but dangerous, because a process should not be able to overwrite itself on disk (unless the user has allowed it to auto-update itself, instead of using a package manager with out-of-band public key retrieval)
This is all probably in the discussions,
A. "Audit all binaries run as root" (TODO lookup the probably CIS control URL for this; look for disk-resident programs that run with elevated privileges)
A.1. Find setuid and setgid files:
sudo \
find / -type f \( -perm -4000 -o -perm -2000 \) -exec ls -ld '{}' \; \
2> find-setuid.errors \
> find-setuid.files
A.2. Find setcap binariesA.3. Find extended filesystem attribute permissions with e.g. getfacl
A.4. List everything in */sbin that only root users should need to run (*)
A.5. Find everything that's `chown root; chmod o-x`;
(When you remove the e(x)ecute bit from a directory, that user/group/other can't list the files in the directory; which is logged to stderr when e.g. `find`
Nowadays we can just do the SBOM tool on everything in every */?bin direcotry and just check those
If "merge sbin into bin" isn't already changed in the FHS spec, I'm -0 to -1 on the idea and don't see really any benefits.
Filesystem Hierarchy Standard: https://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard
Disadvantage: Users would inadvertantly exec() programs they don't need to run log exec()s of, if /sbin and /bin are merged; there will be more binary enumeration log messages to parse.
Disadvantage: Other distros won't merge /sbin and /bin, so the paths in log messages in support issues and mailing lists would be less universally searchable
In any event, it doesn’t really make sense to me to deny read access for any executables, so long as you don’t also deny read access to Python or a C compiler.
Really, if permission mode bits are the only thing preventing damage from such tools your vulnerability is not within your path or mode bits.
The main advantage I see of having them separate is that you can remove sbin from user's $PATH to avoid confusion.