Currently, Whonix only has AppArmor profiles for a few high-risk applications. This isn’t the best. It would be much better to have everything confined by default, including init which would greatly increase security.
This can also help a lot with the “untrusted root” idea as we can just develop a system-wide policy to restrict root.
AppArmor can do this by loading a profile for systemd in the initramfs.
Even when a user installs some sketchy malware, it will be restricted by default.
This isn’t something that can be done easily though. It will require a ton of work and testing.
Android also does this but with SELinux.
I’m not aware of any Linux distribution that does this (except Android).
Android apps are much simpler and more contained by design which makes something like systemwide SELinux possible.
Full system MAC is a PITA in my experience and I’ve tried Grsec’s RBAC back in the day which arguably has the most advanced auto profiling of any framework. I tried using it it a lot. There was a lot of unexplainable breakage despite running every program and exercising all of my needed functionality. Nonetheless if you can somehow make this work without running into serious showstopperes I don’t see why not.
Note that TOMOYO is an Apparmoresque designed MAC that supports sys wide profiling. Not sure you can stack it with Apparmor yet though.
[1] Suggest to enable by default at some point? Not sure yet. Current policy for AppArmor was:
A) enable by default for packages shipped by Whonix - since then developers can test (and know) the AppArmor profile and unlikely to break things (sdwdate, …)
B) opt-in (install by user) for software upgraded through Debian or third parties (Tor Browser) since that is more likely to break.
I guess this is the category B)?
Please add licensing header if you’re creating a pull request for this.
Experimental full system AppArmor policy for Whonix.
It’s really awesome idea I wouldn’t have thought of.
One nitpick: it’s not “full system”. It’s all systemd unit files, which is huge. But “full system” would mean “all of /” (/usr/bin etc etc).
Could still be in package apparmor-profile-anondist but maybe not /etc/apparmor.d folder [1]?
No, it is “full system”. All processes are spawned off the init process so every single process (except kernel processes) are automatically confined. That includes “all of /”.
It’s easily tested by running ps auxZ and you’ll see every process is confined or you can try using ls on a non-permitted directory such as /boot.
That’s why this is such a useful feature. Sandbox escapes will basically be nonexistent.
No binaries have the ux or Ux rule which would execute them unconfined. They all have the pix rule which executes them under their own AppArmor profile and if it doesn’t exist, it falls back to the original init-systemd profile.
Something generic like “Full System AppArmor Policy”.
It should be able to be used on any. I’m only testing on Whonix though.
It would be a good idea although I doubt any would be using those permissions. They’re usually regarded as dangerous even without a full system policy.
An issue I am currently facing though is the base abstraction using ix for a few files in the home directory https://github.com/Whonix/apparmor-profile-anondist/blob/master/etc/apparmor.d/abstractions/base.anondist#L159. This is problematic as I need to give access to the entire home directory with the pix rule so existing AppArmor profiles will still be in use. Using pix for the entire home directory and also pulling in the base abstraction (which has the ix rules) causes a conflict and the profile won’t enforce. This can be fixed by just adding a p before the ix in those rules.
I didn’t actually think of that. It can’t without disabling AppArmor. I’m hesitant to give access to /boot as that would allow a malicious program to mess with the kernel and initrd images. Although, I can probably restrict /boot access to apt only.
That’s alright. Full stop. Since you’re creating the package you should have most freedom to coin things.
I am not contributing much but seems like I am providing a Free platform with services:
review packages
build packages
installable from third party APT repository (similar to a PPA but more restricted, much less scalable)
sometimes install by default in Whonix, Kicksecure, which are distributions which potentially might become available as host operating systems, are already available for various virtualizers.
Other possible package names: apparmor-profile-full, apparmor-profile-everything.
Since there is security-misc already, perhaps a companion package security-extra (opt-in package) which comes with all the more experimental, (potential) breaking security enhancements? Or security-paranoid (depending on paranoid being viewed as compliment or insult) (after all the revelations on the state of computer security, nothing really is “paranoid”). Just brain storming.
Makes sense. Since this is becoming an opt-in package, there is nearly unlimited freedom of usability issues and inconveniences.
Would be OK. However, coming at a disadvantage. That would effectively make apt a tool which can be used (by root) to modify any file on the system. It would be possible to add local or remote APT repositories to /etc/apt/sources.list.d/ folder or to define the (local!) repository URI as APT command line parameter. By using a local APT repository it might even be possible to write a wrapper script that would abuse that mechanism to write to any file on the system.
Something like security-extra sounds like it’d be good for other hardening like kernel hardening but not AppArmor changes. “paranoid” being an insult would depend on the context. I doubt security-paranoid would be viewed as an insult.
Editing the policy at boot in the initramfs based on a boot parameter sounds really hacky and doesn’t seem like a good idea.
There is already a boot parameter to disable apparmor (apparmor=0) that can be used if needed.
True. Certain configuration options are also likely able to be abused. For example
The policy can block write access to the main apt configuration files and only allow /boot access to the apt-get-update-plus wrapper so the -o and -c options have no effect. Although this comes with a customizability decrease.
Didn’t have that idea. I was thinking rather complicated: create a deb package, add to local APT repository, apt update from local, apt install local package which runs the command (such as to modify /boot).
It supports extra options.
apt-get-update-plus does not have any limitations on passing any arguments anywhere.
I don’t have a great answer yet. Hopefully apt upgrades to /boot can be done without entirely disabling all apparmor ( apparmor=0 )?
Even during an “admin boot” (if we can implement that one day) where “anything goes” shouldn’t want to entirely disable apparmor?
It would probably be a good idea to make it disable any arguments if /etc/apparmor.d/init-systemd exists.
I think we should allow apt access to /boot by default but make sure it cannot be easily abused although even then, vulnerabilities in apt could give malware access to /boot.
Yes as well as not allowing write access to /etc/apt/apt.conf.d as you can specify config options in there too. It may be a good idea to just disallow write access to all of /etc/apt/.
Is there any other way to sneak in configuration options? Maybe /usr/lib/apt/ or /etc/dpkg/?
Also, nothing stops an attacker from overwriting /usr/bin/apt or other commands apt uses with a malicious version.
I can possibly allow apt to only execute a few needed binaries in it’s own apparmor profile then disallow write access to those binaries in the systemd-init profile.
These are definitely dangerous. We need to fully prevent all runtime bootloader and initramfs modifications, otherwise an attacker can easily disable apparmor after a reboot.
There is also /usr/share/initramfs-tools/ and /usr/share/grub/.
It might be a good idea to use Pix instead of pix rules so AppArmor scrubs the environment but this will probably break hardened_malloc if we use LD_PRELOAD for it.