On Mon, Nov 30, 2026 at 5:39 AM Christian Brauner <[email protected]> wrote: > > But I really really want to merge CLONE_NO_NNP. But please call it > CLONE_CLEAR_NNP from the other thread. I merged CLONE_NNP for v7.1 and > it sets no_new_privs on the child, so CLONE_NO_NNP right next to it is > going to be confusing.
I agree on the name. I looked at the code. I think that the core functionality would be quite straightforward (like ten minutes total writing the patch and some more to test it a bit). But there are two messes: - apparmor has this thing: commit 9fcf78cca198600b27c44b4e50f00f8af3927f17 Author: John Johansen <[email protected]> Date: Sun Oct 8 18:26:19 2017 -0700 apparmor: update domain transitions that are subsets of confinement at nnp Domain transition so far have been largely blocked by no new privs, unless the transition has been provably a subset of the previous confinement. There was a couple problems with the previous implementations, I'm concerned that the whole mechanism is unsound with CLONE_CLEAR_NNP: 1. ctx->nnp is a single label, but in a CLONE_CLEAR_NNP world it's possible for a task to set nnp more than once and to have labels that are not logically subsets of each other at the times of both enablements. 2. As noted by the comments in the code, it fails to actually capture the enablement of nnp -- it captures the first exec after enabling nnp. But one could set nnp, then set a malicious seccomp policy, then CLONE_CLEAR_NNP, and then exec and change labels, thus compromising the new label (but only scoped to a new userns). I'm honestly not convinced that #1 is an actual problem. #2 is, although it's arguably a fixable bug in the code. One solution to both would be to disallow CLONE_CLEAR_NNP by an apparmor-confined task. Maybe this is a good enough solution to make CLONE_CLEAR_NNP useful. selinux: The logic seems to all be in check_nnp_nosuid and its call sites in selinux_bprm_creds_for_exec. This has a similar issue to apparmor's but without the exec complication. A malicious confined task can set nnp, set a malicious seccomp policy, unshare and clear nnp, and then compromise a label where the policy did not intend to grant permission to transition to that label under nnp conditions. The problem is that my proposed apparmor solution doesn't apply cleanly to selinux, as there is no kernel-level concept of an "unconfined" domain as far as I know. There is a "permissive" domain, but I don't think existing policies use it for the unconfined domain. Anyway, here's a concrete proposal: We add a new LSM hook clear_nnp. The logic that one may only use it when unsharing userns goes outside LSM (because there is nothing in the hook that indicates that userns is being unshared, so it can't go in commoncap). Apparmor implements it by only allowing unconfined tasks to do it (and apparmor devs are welcome to change this policy if it becomes useful). selinux adds an actual new policy PROCESS2__CLEAR_NNP. Open question for selinux experts: does this need a policycap at all or is the handle_unknown mechanism adequate? Should the existing selinux_policycap_nnp_nosuid_transition be checked? --Andy
