From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796128672; b=gkYANteYWMFEuU3rYvQnnDcFijuLlYJT0zOmnB6EsJcriIVL2nR9JJt/MJkBVjfOYSos 0aTHs4hPQvwetpCipVQXX0pHQhrSSwPeCahsKhAzc6KELnG1owEAyFRerHC8Ds+A+8O1v oocwGIfE4wD8uwd57sJdP91qw+VOw0V9MA8A5imUGmwcC7HcEfGTonPnZgbTxLw8pfcGu PmuQxkEbkybeD+nJsBYgpDLNsSILYt4QR/v/JJnwUV4wHHqZPuofGtQQxi3WlPyea3WJB OaPa6FrisqkixAUQ24xLNpBvqlGGS94NHf2Kc69BKi7BFR1p2ADYx+vXQaQpzZu8Vpw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796128672; h=Received:DKIM-Signature:From:Subject:Date:Message-Id:MIME-Version: Content-Type:Content-Transfer-Encoding:X-B4-Tracking:X-Change-ID:To: Cc:X-Mailer:X-Developer-Signature:X-Developer-Key; bh=4yMHIgxKW/3CHMEZ8FFuC10RKqz1yT4Zxv761mFp9d4=; b=zq3atpwBNDVqre2L8sRaRIXPqjBvgHXyHFEUUTNWug7zzKqXR2EvZv2Hc4npYuW8g6ye F38XvWIFjCtNZTqOQSzz1sTEWe7UFSAwXZ4M8tC1W5f+ppZUmQPLzsztzyvyg30xFfiLc 6456McCQIMMThXnKqj0C5cuPWoaFsXL3Y1eCRv1kqNuX+xa1TeDfMSYwfxVflcy43V15/ RCm0VV+keq7pwCAsUdrik9GrBwVHkYkqTPid8YsjNZfqM5oBklu/vSa2gx8E+GF0FKzYS CUe/NQudn4EzN4CnhFr9Q8QVZc0TOrB5WV2EeLYXlLaD6MJXqmj056+hNEj0PJGkiHw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=LuSnkZeH; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BACBA606A31A; Tue, 1 Dec 2026 12:37:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=LuSnkZeH Received: by smtp.kernel.org (Postfix) with ESMTPSA id D15951F000C1; Tue, 1 Dec 2026 12:37:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796128672; bh=4yMHIgxKW/3CHMEZ8FFuC10RKqz1yT4Zxv761mFp9d4=; h=From:Subject:Date:To:Cc; b=LuSnkZeHsK6oEAA9+l9Ismh01le+VBLMTjir0TUR7c0D8Z3DI0sOcGt7pQm/BxkDB eUA0IrKOtQ5zjRMsZdnrwUsZz/HGpOq0wjQzlHhVloL39xvQ3rZn5T0iAiKomqmYOt imFDoZCGUL2wMw7uOkzQe9hb0i7bHWBgyrVG2cEuvU4Snc549Ss5LE2MRXzm7TWVwH CC9vT9PXMj44msir/MdljqXZNMkn94VPQj/XzLLeR72I3d31BS3dcFmq/rFHgH6Dg4 fzyZCW9hHBNAteI3oDKvN/8hhm+p1u6uuLFWnMdEWjsCKsbOfEFHzfglNh+TIplBxq G/OQIdRm72SAg== From: Christian Brauner Subject: [PATCH 0/4] namespaces: close two ways out of a chroot Date: Tue, 01 Dec 2026 13:37:24 +0100 Message-Id: <20261201-work-mount-empty_mntns_chroot-v1-0-070c96c234bc@kernel.org> X-Mailing-List: stable@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="utf-8" Content-Transfer-Encoding: 7bit X-B4-Tracking: v=1; b=H4sIAAAAAAAC/2XMSwrDIBSF4a2EO66SWBqlWykhqL2ptqhBTR+E7 L2aDjv8D4dvhYTRYoJzs0LEp002+BLdoQFtpL8hsdfSwFrWd6ztyCvEB3Fh8Zmgm/NndD77NGo TQ8iEHznj4qSEmHooxhxxsu/dvwy/Tou6o84VrQ8lExIVpdemTpWnO0//eVrPsG1fqg4G7LYAA AA= X-Change-ID: 20261201-work-mount-empty_mntns_chroot-7372785b88f6 To: linux-fsdevel@vger.kernel.org Cc: Jann Horn , Josef Bacik , Serge Hallyn , linux-kernel@vger.kernel.org, Alexander Viro , Jan Kara , "Christian Brauner (Amutable)" , stable@vger.kernel.org, =?utf-8?q?Ozan_A=C4=9Fdepe_=28NullSecurityX=29?= , Forest Huang X-Mailer: b4 0.17-dev-04696 X-Developer-Signature: v=1; a=openpgp-sha256; l=2135; i=brauner@kernel.org; h=from:subject:message-id; bh=77EOTZFjcXxQGt48n/X/50RjZpDjNrf70vpJegyitXE=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMWTz7Z92wfqAs/mdq75/7tWxf2d4fkiXd/Uzw2VNaibVq ge7i5k+dpSyMIhxMciKKbI4tJuEyy3nqdhslKkBM4eVCWQIAxenAEykSZDhf4UA9/7X8zI3XV1U Pl9y76Ke8POiQvbtR6ov94lqnVjK8JWRYTZ/ihFHj9/XGes/n/gYlTFDia+Md0JiZEOp18ksl4P sTAA= X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 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 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