From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C82B94F96A6; Tue, 13 Oct 2026 12:06:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791893202; cv=none; b=q5p00bx9Hjtt6aHt6Fo92r101TpjNufJQpV9MhFkefENb3m429W9ZPZ9FLOvJ1sGId2Bo38s9im/RdVibEkgFYLL0tzXYlf6LPz9v+94SuumINdQ9vj3p2UxXDTh3XP0owPZ6L9bH9qxIIKNixKauDZb+fy/gXYpXnJZwjN+aTg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791893202; c=relaxed/simple; bh=OzY3+Fu+/hnGQSVq6FFlHwMSiAeTpknbrVMJYDaWBC8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZIM+qmawMOx98x3h3hpOk58fB9XHh+7K3FEsSIjxZT2BsN+cI/5RlYOLO1WDvHHnaQphyL4nloSJfSgDFxIUmK5WwPhX67Fj2JobfpllmJoXTfw8hKVIlg/veOAyPBnDjjESXZcT6XZz8frnMPVasR79/U9Vm+7hQzPVadSadng= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=vA27d+jz; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="vA27d+jz" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C282A1F000FF; Tue, 13 Oct 2026 12:06:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1791893201; bh=z04NG6wDvbNxb0gNCBHa7r2ipow7S/QQm9oGU1Onh1k=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=vA27d+jzvnf1tDPSoOjYkI2fduDxqcUHmFRhLSFHD9hYf+lyg1hRusMg+kU39zXDN 0/g3mJGkpDs5Hw7Y6Ghe0sdSLvx/LJNPlmU5AZMAcqY6Q15SHxdILLE/ZCUbcGc9lT Bc5si9OXJlz40kUzYLwdNqEF7ruDaFu2oK+eAZKc= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, "Christian Brauner (Amutable)" Subject: [PATCH 6.18 146/621] namespace: refuse an automount below a mount that is in no namespace Date: Tue, 13 Oct 2026 13:32:21 +0200 Message-ID: <20261013112924.319509994@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261013112920.855194808@linuxfoundation.org> References: <20261013112920.855194808@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Christian Brauner commit ba985ce08471c555af2a2fbe217c1bc2e72a6d8c upstream. It's possible to add autmounts even when the parent mount isn't in the mount namespace of the caller. The only requirement we have is that the parent mount namespace must not be NULL, i.e., unmounted. Problem is that clone_private_mount() has MNT_NS_INTERNAL which makes that trivially true. So that passes the test and attach_recursive_mnt() accepts that as a mount point and funny enough, count_mounts() dereferences MNT_NS_INTERNAL. The problem is it is an error pointer... So we can reach this in userspace via fanotify. A filesystem mark on the lower filesystem of an overlay reports paths on the layer clone and reading the event hands out a descriptor on it. For example with debugfs as the lower layer it goes kaboom: openat(evfd, "tracing", O_DIRECTORY) Oops: general protection fault KASAN: null-ptr-deref in range [0x1d0-0x1d7] RIP: 0010:count_mounts+0x35/0x200 attach_recursive_mnt finish_automount And since that sleeping beauty happens under namespace_sem held for writing every mount operation on the system blocks from then on. Congrats. Use is_mounted() instead which rejects unmounted and internal mounts alike. The open fails with EINVAL just as it did before clone_private_mount() used MNT_NS_INTERNAL. Fixes: df820f8de4e4 ("ovl: make private mounts longterm") Cc: stable@vger.kernel.org Link: https://patch.msgid.link/20261002-work-mount-fixes-4-v1-5-dd44b89d44ce@kernel.org Signed-off-by: Christian Brauner (Amutable) Signed-off-by: Greg Kroah-Hartman --- fs/namespace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/fs/namespace.c +++ b/fs/namespace.c @@ -3649,7 +3649,7 @@ static int do_add_mount(struct mount *ne if (!(mnt_flags & MNT_SHRINKABLE)) return -EINVAL; /* ... and for those we'd better have mountpoint still alive */ - if (!parent->mnt_ns) + if (!is_mounted(&parent->mnt)) return -EINVAL; }