From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=178.63.66.53 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796138682; b=AADx1/6UUf0NV3mLnybn9jBvbfPFwCF/OUBz+Wai83afiD4dFVSXBSB06RVDkPF6k9LE 1CLB7y9SKV1SqfBpG19A0eD4uLcsMTyVa7M3LURNHEXPyE/DrR48YYGXE8VCrIW6cOCj9 TpntTdWjhm4AytMKVPZv5pB59U6Psd4EEUSnLdkhOY5Cj1ZwGWrGwMVhWddni9gE0PxbV zwUL+nFWIYhkC1kSnyeynoHtPEr5xGJ4REVkDnXM0+VCqBl+p+87mv3VCxdXYb/s8HpxD qGTXLI4g5GVLqg/UowyZjyYcI8Gdh7ge67Ryxh5upeZkgUyaai8uD10QdnMKrYpzJeQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796138682; h=DMARC-Filter:DKIM-Signature:Received:Date:From:To:Cc:Subject: Message-ID:References:MIME-Version:Content-Type:Content-Disposition: In-Reply-To; bh=pdyDvoykDkIuPzuEYKl1/GPMzJKwAqPI3P95POtmGDw=; b=kfETZyXqDnR9e9rYEWSg5j7oZ48/SdR4bVDGGM0O5BhH3KaawHvL8VOD0CED98SS4CDi K0wr70q2z+wCU0hYQPFLMwR1hcxUuRvJpqwCpEAX3C7D0xtKqko4rJtW5iAsPW2mzotEy Bvy/A8b8VyhFso+A8Q7VubuAyULeGfZ1ONEqbbmRIQQK75CdESrYTlw0aFu3LOvHadeEu rV4RnLlJT3WABuJpPOIR396ztdVzJ8g0S4V08LmFbge2atHlFBdAbIdX/7Eix1cns7g9l pNbFhWxyBNzDtr7KSLZF8Le/I8chinsIgU1e5PG8appOWzoDB82Vg5+gh6w34mhjrfQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=hallyn.com; spf=(null) smtp.mailfrom=hallyn.com; dkim=pass header.d=hallyn.com header.i=@hallyn.com header.a=rsa-sha256 header.s=mail header.b=gHpUfgr1; arc=none smtp.remote-ip=178.63.66.53 Received: from mail.hallyn.com (mail.hallyn.com [178.63.66.53]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4C482606A31A; Tue, 1 Dec 2026 15:24:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 4C482606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=hallyn.com Authentication-Results: smtp.subspace.kernel.org; spf=tempfail smtp.mailfrom=hallyn.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=hallyn.com header.i=@hallyn.com header.a=rsa-sha256 header.s=mail header.b=gHpUfgr1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=hallyn.com; s=mail; t=1796138672; bh=ZlRot+calxk1JQwij3D0Dd6TRMLb9Nxooe5JlddeVCU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=gHpUfgr1CIt3PUB+Mx2ejiWPzlsJh4WF9pACeTZ7kSF0AKCX1f6XU0+OaCkHPfave jX8KpD3b7cWMFFamCHoczusnGMQg1L4uL/lOs350dhZYx0+mwzPMdt+s+P2z7qFr1X qE+tnKbTOAQ0FcQrj2+ZdKffty7+KcMlKk/XXFZD7rvagAjbXzFXsDCAH1i9Wg93lM 0uneq8gY5ru3YaqvR7Z4zQQuE3dJyV0R8cMTKUSuHSW/IzrFg6ApBfuR4R7+0eXQ1p mkLceJbMYIdYGmAazrV1N0Av2pqbtn3xGFFiaZvS+LDooas3xKB4jwhPUds/JDnOcO sYh1dPVkdnl3w== Received: by mail.hallyn.com (Postfix, from userid 1001) id 09C025FB; Tue, 1 Dec 2026 09:24:32 -0600 (CST) Date: Tue, 1 Dec 2026 09:24:31 -0600 From: "Serge E. Hallyn" To: Christian Brauner Cc: linux-fsdevel@vger.kernel.org, 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_=28NullSecurityX=29?= , Forest Huang Subject: Re: [PATCH 0/4] namespaces: close two ways out of a chroot Message-ID: References: <20261201-work-mount-empty_mntns_chroot-v1-0-070c96c234bc@kernel.org> X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261201-work-mount-empty_mntns_chroot-v1-0-070c96c234bc@kernel.org> On Tue, Dec 01, 2026 at 01:37:24PM +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. > > 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. > > 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. > > Both come with selftests. > > Signed-off-by: Christian Brauner (Amutable) > --- > Christian Brauner (4): > user: don't let a chrooted task join a user namespace > mount: don't let an empty mount namespace undo a chroot > selftests/namespaces: test joining a user namespace from a chroot > selftests/filesystems: test empty mount namespaces from a chroot > Looks good, thanks. Reviewed-by: Serge Hallyn Only thing I noticed is it might be nice if enter_jail() didn't need to be duplicated in both tools/testing/selftests/namespaces/userns_chroot_test.c and tools/testing/selftests/filesystems/empty_mntns/empty_mntns.h . > fs/namespace.c | 9 ++ > kernel/user_namespace.c | 9 ++ > .../empty_mntns/clone3_empty_mntns_test.c | 36 ++++++ > .../filesystems/empty_mntns/empty_mntns.h | 18 +++ > .../filesystems/empty_mntns/empty_mntns_test.c | 85 ++++++++++++++ > .../selftests/filesystems/failfs/failfs_test.c | 38 +++++++ > tools/testing/selftests/namespaces/.gitignore | 1 + > tools/testing/selftests/namespaces/Makefile | 4 +- > .../selftests/namespaces/userns_chroot_test.c | 124 +++++++++++++++++++++ > 9 files changed, 323 insertions(+), 1 deletion(-) > --- > base-commit: a63f17c4cacafcc9ff8c88651b42cd62b936d729 > change-id: 20261201-work-mount-empty_mntns_chroot-7372785b88f6