From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.218.42 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796202605; b=uDy5TtTY/ZAeTlZodU/06bkFcYvmZFN9h2gs3pcbltUfuaPhjl+bSFXyo5iZEh3vR5tt y/lSTlT19BtRnpTYjrjgg65YadmIB/xhoABjbtkILkgKfFyCjEKfJxmmGsekt7zPDFJcZ W9Unvaal+fPaNj7A/DmwnRtUQ6+aKwkMpaJsKe0zRChfSwJBVbSXLcXHVhYls6a0zruSJ Zb5+q+oGiTOa5z4lHyztPblNpDaTjxb0Enmmq8+80gQDs1fht4+sCnVFn3spTyW7C/ohV vR8EFbzA8yHALde5tTU53fchAVlkg7J718DwIT6UR7w2VUfzRov+PqRoYNlwjAsy/0w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796202605; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:Content-Transfer-Encoding:User-Agent:MIME-Version; bh=oz9p4VCIJWcEUPsZjj8g8XVO/iLHfTT3r95oNn2rZrI=; b=ht6VTrInu7C/NrsK5Ugv8GL92glYTAqv6EMrlX5fxYF/HenKBLSz2eIkSvU+ROksjfnH nWttTrPNweA+SUEmIg2NgxzTSe/2ZB4MkH6X8BmprlET/z6GlA92Lm4qmSdKGtD1+ZGlc wiS8pU8nH/F09XvVMOzkHqMMl0T9uwg7W8ZKqsYKHHRWnTU/8aPjQnuiV+gqJ4TGH0sHe tY40/rU2E+QySSI8GPasGtRXk5D1GQYlWXa0wJ8BS9m3lZ+3tntxoAA7nE7Mz9V6MUtxu TVFAjBrgcxm8kCLaK532xczTxYNqveqiqYK/yUU9zxH0Cba1ooAfyBoqSfZ7Ya3noBg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=amutable.com; spf=pass smtp.mailfrom=amutable.com; dkim=pass header.d=amutable-com.20260707.gappssmtp.com header.i=@amutable-com.20260707.gappssmtp.com header.a=rsa-sha256 header.s=20260707 header.b="E4n/bxXx"; arc=none smtp.remote-ip=209.85.218.42 Received: from mail-ej1-f42.google.com (mail-ej1-f42.google.com [209.85.218.42]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B7A9F606A322 for ; Wed, 2 Dec 2026 09:10:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B7A9F606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=amutable.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amutable.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=amutable-com.20260707.gappssmtp.com header.i=@amutable-com.20260707.gappssmtp.com header.a=rsa-sha256 header.s=20260707 header.b=E4n/bxXx Received: by mail-ej1-f42.google.com with SMTP id a640c23a62f3a-c4d2b741ed9so2041287566b.2 for ; Wed, 02 Dec 2026 01:10:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amutable-com.20260707.gappssmtp.com; s=20260707; t=1796202603; x=1796807403; darn=vger.kernel.org; h=mime-version:user-agent:content-transfer-encoding:content-type :references:in-reply-to:date:cc:to:from:subject:message-id:from:to :cc:subject:date:message-id:reply-to:content-type; bh=oz9p4VCIJWcEUPsZjj8g8XVO/iLHfTT3r95oNn2rZrI=; b=E4n/bxXxMFqwHT5S8Rv3A3LuzgEeS4Vp/IHDB1KCYKYa2iawQzcO0+yIyKotWo/gFa Es6Zz9iA4ig697W1d5u518XeJ+AvWW4yjd5U1ggG/i3sHb5qAXkiIOEjFQTvcb1VYvdq 8jS0WWZWLQP6Dmlx4h4xH+fcdyWlo9C958X60ki1tvIxjdQBxsfBcEfzZNGfU7Uj0Lyi 7IN+/5CiNjTrmoIDcNenawGRhlOUFS21/ufnZhAG+UCnQCHyilP4LatQcjRC676wSO+n dlD1zgjEL/WA6BLeMQxq87aGYG8f8blXgnjYacAphqLevg8o7DEpaBwJiiBCbP+CsjTk Av8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796202603; x=1796807403; h=mime-version:user-agent:content-transfer-encoding:content-type :references:in-reply-to:date:cc:to:from:subject:message-id:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=oz9p4VCIJWcEUPsZjj8g8XVO/iLHfTT3r95oNn2rZrI=; b=G7CoFMTEU66JGE1mMFJ1UD5IIMyxlDO3DmiNdh7gqqmeBdSUt/gt2k05aCCAbFA3n0 bKE8GnIRSCQfxuBcY+zVXAtCViw97YfGwSUcNcsEgtVQu1k8ytlekcOzj8w3q7iiF3dt LK5mfg+yM1/deGtoZTULAsDwuDz3OpaJNUPcWuHpvNiSUw6ecRF2f+DFZaLfPydOUmgS /ekaLvpSNri/6Ux6+DBVvA+qvcxnjQaH9iNRBuwzDzmbR42aJYWxe8FkTXDaew7tNgpj NdlDOY48+Da69ZG87Oyy6VKWgHmcegBWFyHacjP397KzcorWMTlUfxSSzUxNdrYRLvSK quVA== X-Forwarded-Encrypted: i=1; AL+hErFLxOYRk+j1bcLadXU80u6J5kmQj3Xp20KdwXQCGoRv20QarybdvXNju+BNUSd6dZ96RHm61uqWo8tOTwg=@vger.kernel.org X-Gm-Message-State: APuU4Z+8Z3OLGj2JxxYRk0tgtJHt626pt3yl5WECcBjXoA/lZFMUgU2Y 32Ae1FSStDXJQzVRQvd5tQ5EKZCNpz7qvST8yCgc+EcQqZAs1LtTzMsaNnteuSxPFvCc X-Gm-Gg: AZFdTZcYaoAGuJHTbSLS3V+S/u0MAx0byArIZcn8/sT0r+yiDqEEDkwGsVTwp5dPGqw 9AYMATT/P24GjJTODsq3hAftOsg2gWTp2OT5VtFTeocCRRY14q32V5Bp65UKnJk795ZWdAJnHF9 3YuQG+shVj7laOB1KRcPk2nndsyalN7tn9+KccEE7oHfeCsWUfgy/wiJNtaRhk6UWR5QPcr1yFM 9xRnR72VCbU3r6ktsUz0qFYNXHHu1qoNgv6mo+95vxCHsTNmcKhDw48l8W5Fwcj1XBk6NWHg8gx uMo3jQdbi73pRX+OTazpRz6GTnjTf9RHud30sXtcdmy+Z8D5z3+UaSatK/aUKqBvwb3cHHrlxxW MtU2BypJOxvoWDW29L8oen97q//xHPkoc55JPNNXUW0NZRqaH9EsTB7EBCKnGGLhyGL4sHBFK2Q K9b7stf6iZmoT+ER8mVh8SFB/jBnow/FzmHpANrT/jfTjCfXZfOa/3kfZY2vq4EENWC55UHVSzU cSc4tlEO5wEI7Df93gzu1cUBFb4KfYyDIuU3s4uIcXW4qoJ/JZ8HoDRx5pKfJDZeL4r7W073/jQ 5MMe6Y/g29i02H0dPgC02pLWOu294fKfnHV8hI9oNhO7QW7DNKFSI7uvdrv+6iuHuQ== X-Received: by 2002:a17:906:6954:b0:c25:504a:1e25 with SMTP id a640c23a62f3a-c513a5ebc65mr2496612666b.13.1796202603083; Wed, 02 Dec 2026 01:10:03 -0800 (PST) Received: from [10.0.0.233] (tmo-084-240.customers.d1-online.com. [80.187.84.240]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-c513b01e242sm1286561966b.82.2026.12.02.01.10.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2026 01:10:02 -0800 (PST) Message-ID: <7a6173cc3cce42a100b202dfbc50587134ceafdb.camel@amutable.com> Subject: Re: [PATCH 0/4] namespaces: close two ways out of a chroot From: Alexander Mikhalitsyn To: Christian Brauner , linux-fsdevel@vger.kernel.org Cc: Jann Horn , Josef Bacik , Serge Hallyn , linux-kernel@vger.kernel.org, Alexander Viro , Jan Kara , stable@vger.kernel.org, Ozan =?UTF-8?Q?A=C4=9Fdepe?= "(NullSecurityX)" , Forest Huang Date: Wed, 02 Dec 2026 10:10:01 +0100 In-Reply-To: <20261201-work-mount-empty_mntns_chroot-v1-0-070c96c234bc@kernel.org> References: <20261201-work-mount-empty_mntns_chroot-v1-0-070c96c234bc@kernel.org> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.56.2-0+deb13u1 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 On Tue, 2026-12-01 at 13:37 +0100, Christian Brauner wrote: > CLONE_EMPTY_MNTNS lets a chrooted caller with only CAP_SYS_ADMIN > reset > its root to the empty root of a new mount namespace. That doesn't > make > any files reachable but afterwards the caller isn't chrooted anymore > and > can create user namespaces again. setns() requires CAP_SYS_CHROOT for > the same thing. So require it here as well if the caller is chrooted. >=20 > Ozan pointed out that joining a user namespace never got the chroot > restriction that creating one has. A chrooted task without any > capabilities can setns() into a user namespace owned by its uid that > some unchrooted process created and chroot() its way out. That one is > a > lot older. Refuse it unless the caller has CAP_SYS_CHROOT in its > current > user namespace, i.e., unless it could chroot() its way out anyway. >=20 > A task without CAP_SYS_CHROOT that setns()es into a user namespace > from > inside a chroot gets EPERM now. Creating one there already fails so I > don't expect anyone to rely on that. >=20 > Both come with selftests. >=20 > Signed-off-by: Christian Brauner (Amutable) LGTM Reviewed-by: Alexander Mikhalitsyn > --- > Christian Brauner (4): > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 user: don't let a chrooted task join a use= r namespace > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 mount: don't let an empty mount namespace = undo a chroot > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 selftests/namespaces: test joining a user = namespace from a > chroot > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 selftests/filesystems: test empty mount na= mespaces from a > chroot >=20 > =C2=A0fs/namespace.c=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 |=C2=A0=C2=A0 9 ++ > =C2=A0kernel/user_namespace.c=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 |=C2=A0=C2=A0 9 ++ > =C2=A0.../empty_mntns/clone3_empty_mntns_test.c=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 |=C2=A0 36 ++++++ > =C2=A0.../filesystems/empty_mntns/empty_mntns.h=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 |=C2=A0 18 +++ > =C2=A0.../filesystems/empty_mntns/empty_mntns_test.c=C2=A0=C2=A0=C2=A0=C2= =A0 |=C2=A0 85 > ++++++++++++++ > =C2=A0.../selftests/filesystems/failfs/failfs_test.c=C2=A0=C2=A0=C2=A0=C2= =A0 |=C2=A0 38 +++++++ > =C2=A0tools/testing/selftests/namespaces/.gitignore=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0 |=C2=A0=C2=A0 1 + > =C2=A0tools/testing/selftests/namespaces/Makefile=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 |=C2=A0=C2=A0 4 +- > =C2=A0.../selftests/namespaces/userns_chroot_test.c=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0 | 124 > +++++++++++++++++++++ > =C2=A09 files changed, 323 insertions(+), 1 deletion(-) > --- > base-commit: a63f17c4cacafcc9ff8c88651b42cd62b936d729 > change-id: 20261201-work-mount-empty_mntns_chroot-7372785b88f6