-
Notifications
You must be signed in to change notification settings - Fork 273
Description
Hello,
Similar issues were raised earlier, in #378, #679 and #681, but for a different use-cases, where I think common suggestion was "use something else, your use-case isn't a good fit for bwrap".
As this is a different use-case where I bumped into same limitation, wanted to open a separate issue to suggest adding option for it instead.
In my case, what happens is, in my understanding:
- Chromium-based browser runs bwrap to run glycin image-parser in it.
- bwrap sets up unprivileged container with no-new-privs, and then exec's e.g. glycin-svg image parser binary.
- glycin-svg does pretty much nothing but parsing an image from file descriptor or shm and returning some kind of bitmap.
For many good reasons, it's nice to run app such as browser with as much sandboxing as possible, for example with AppArmor LSM profile.
In which case, AppArmor assigns profile to a chromium binary, with many rules for it.
Then when it runs bwrap ... /usr/lib/glycin-loaders/2+/glycin-svg, bwrap has its own distinct profile, transitioned to via e.g. /usr/bin/bwrap px -> chromium-wrapper//chromium//bwrap rule. That profile has a ton of complicated permissive rules allowing bwrap to setup its sandbox.
And then when bwrap runs glycin-svg image parser (still quite a vulnerable thing - see long history of SVG parsing bugs), it needs a similar transition rule, with its own profile, which is almost empty - all image-parsing is done in userspace code, no extra access is needed or should be allowed there.
Problem is, as far as I understand it, bwrap uses prctl (PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0), which among other things prevents any AppArmor profile transitions from then on, as those potentially can be made less restrictive, and kernel has no good way to compare profiles for "this is a subset of rules" or layering those at the moment.
That unfortunate restriction logs auditing error like this (long line split for readability):
audit: type=1400 audit(1764715027.910:552): apparmor="DENIED" operation="exec"
class="file" info="no new privs" error=-1 profile="chromium-wrapper//chromium//bwrap"
name="/usr/lib/glycin-loaders/2+/glycin-svg" pid=60431 comm="bwrap"
requested_mask="x" denied_mask="x" fsuid=1000 ouid=0 target="chromium-wrapper//chromium//glycin"
And prevents enforcing extra LSM restrictions on that binary, leaving it running with same DAC permissions as bwrap, only limited by various namespaces and mechanisms that bwrap setup, as well as bwrap's relatively lax LSM profile that has to allow things like netlink access, capabilities, userns, mount, pivot_root, etc etc - instead of pretty much literally nothing ("you parse image you're given without any fs access or fancy syscalls").
It would be nice if separate AppArmor profile could be applied to that final glycin-svg image parser, on top of any bwrap sandboxing/restrictions, which would require bwrap to loose that PR_SET_NO_NEW_PRIVS bit.
I think it's a legitimate use-case where trade-off of loosing that prctl bit is allowing to apply more restrictions overall via LSM profile, not less, and perfectly fine and appropriate usage of bwrap in addition to an LSM profile.
General approach here is "defence in depth" where layering more security mechanisms has afaik proven to be pretty much only good way to mitigate "attacker has to find ANY bug" scaling problem, hence it'd be nice to have "bwrap AND LSM", instead of "bwrap OR LSM", as it currently is due to PR_SET_NO_NEW_PRIVS.
Sorry if a bit long, thought to make a full case for why option might be useful, in light of previous rejections, to maybe give it more chance to not be (understandably) dismissed as "duplicate".
Hopefully it might make this limitation more easy to find/understand too, if nothing else.
Thanks for your consideration.
P.S. If added as e.g. --allow-new-privs option, patching that argument into a browser is probably not an issue for my use-case, as it's a custom chromium build anyway.
P.P.S. Example of an AppArmor profile limited by this issue is "chrome" in mk-fg/apparmor-profiles github repo.