Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp2254985ybd; Mon, 24 Jun 2019 03:23:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqyQqvNeaB5poulqZkpouccG0aO58sf4Fjfh3d2VL2SuBxsOz1JInZXaGQqSWBeTup3CHdYk X-Received: by 2002:a17:90a:d996:: with SMTP id d22mr6713497pjv.86.1561371814542; Mon, 24 Jun 2019 03:23:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561371814; cv=none; d=google.com; s=arc-20160816; b=v/Tlgdtu3MkNsJzytbUSsV3NPjWPgPcy0GNYsrQ6jkUumL1WU23iLHrxwP//+HGv2j LBKWGsYSh1rjAD8h28Me/YP5MnciU4PDOhwUJ2JpVtbiayFGNAjnge9v6c7NlH2pSbIY FLWw6405eY9NiVFq0GexMe6Sx4Ock33JYWzOKK8ufkRjTedUxMl+If/jarkwvRY1eMGx l0FOiKESFhnRPhKng2FCQNRqrN5NqNyg93dfZkj4itYlFHlK6CA61ofzHmOzC2MEejJO vmzILXRvaFmTCT4nX+apqFSi3Rd6OtdK8W85+LdBFAFCy4D+/ET6vTsdWVbwyygDoaJy pLvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=mnFFUF7hzrUj3nF/eq+HhpWR4UnDs/F6BVkOLIaLwRs=; b=Zv9WKYPLdco3t5BaGjdJ3YolV+KNR3Ab5Z4GY0hpYX1+szvu51t9fFFoSz7jnvfvg2 OjSHXUQXg52THaAEDGa/ufNMiERerscPzERCFvg5nF2cfaXMMTIVO4oDXpsSR0rBffqp pZoSz+qeKrx5d7GzEVPUB2Deq5rqgfTeqHqyt6vVGBfdRRco+yiK5LEx7XDHUo2ba+Ch oVOeNyz9Bivc3L2+G1C4e/SmmJ+/9L6EHpgm7UtXTurCmzWhb5n+viNoLkx0dh03lveU EeAr5b0paXV/kAG+kbznI8HXgnNi69GKFtWx+5xLLO/4S87Lz1E516Rh1wF/r+Vb75BR df0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=vH9Y0Mda; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s7si9946635plp.66.2019.06.24.03.23.19; Mon, 24 Jun 2019 03:23:34 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=vH9Y0Mda; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731157AbfFXKWq (ORCPT + 99 others); Mon, 24 Jun 2019 06:22:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:58084 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730777AbfFXKWO (ORCPT ); Mon, 24 Jun 2019 06:22:14 -0400 Received: from localhost (f4.8f.5177.ip4.static.sl-reverse.com [119.81.143.244]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A4ACB2133F; Mon, 24 Jun 2019 10:22:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1561371734; bh=WfFaIxEMITIz5eai5eS+2Gi1SVJf03WbAAv9BsFwjHw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vH9Y0MdaWl1IedjW/+0HnDBQdh3qfc5/evuaBgPRfu5lPyph7jkDaLHL28Z4mi/Ku AlhVfmulkfgDKewsnLKEeW7RKwdW81Dvw2Tzul+gKzCy5rpz9yqcOj4EG1AkVngmgZ I7NHL7fJ76GCyYIW4F5BSSyZTsnC+jbJ7vzis2Xo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Linus Torvalds , Al Viro , Christian Brauner , "Eric W. Biederman" Subject: [PATCH 5.1 114/121] fs/namespace: fix unprivileged mount propagation Date: Mon, 24 Jun 2019 17:57:26 +0800 Message-Id: <20190624092326.475497997@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190624092320.652599624@linuxfoundation.org> References: <20190624092320.652599624@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Christian Brauner commit d728cf79164bb38e9628d15276e636539f857ef1 upstream. When propagating mounts across mount namespaces owned by different user namespaces it is not possible anymore to move or umount the mount in the less privileged mount namespace. Here is a reproducer: sudo mount -t tmpfs tmpfs /mnt sudo --make-rshared /mnt # create unprivileged user + mount namespace and preserve propagation unshare -U -m --map-root --propagation=unchanged # now change back to the original mount namespace in another terminal: sudo mkdir /mnt/aaa sudo mount -t tmpfs tmpfs /mnt/aaa # now in the unprivileged user + mount namespace mount --move /mnt/aaa /opt Unfortunately, this is a pretty big deal for userspace since this is e.g. used to inject mounts into running unprivileged containers. So this regression really needs to go away rather quickly. The problem is that a recent change falsely locked the root of the newly added mounts by setting MNT_LOCKED. Fix this by only locking the mounts on copy_mnt_ns() and not when adding a new mount. Fixes: 3bd045cc9c4b ("separate copying and locking mount tree on cross-userns copies") Cc: Linus Torvalds Cc: Al Viro Cc: Tested-by: Christian Brauner Acked-by: Christian Brauner Signed-off-by: "Eric W. Biederman" Signed-off-by: Christian Brauner Signed-off-by: Al Viro Signed-off-by: Greg Kroah-Hartman --- fs/namespace.c | 1 + fs/pnode.c | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) --- a/fs/namespace.c +++ b/fs/namespace.c @@ -2079,6 +2079,7 @@ static int attach_recursive_mnt(struct m /* Notice when we are propagating across user namespaces */ if (child->mnt_parent->mnt_ns->user_ns != user_ns) lock_mnt_tree(child); + child->mnt.mnt_flags &= ~MNT_LOCKED; commit_tree(child); } put_mountpoint(smp); --- a/fs/pnode.c +++ b/fs/pnode.c @@ -262,7 +262,6 @@ static int propagate_one(struct mount *m child = copy_tree(last_source, last_source->mnt.mnt_root, type); if (IS_ERR(child)) return PTR_ERR(child); - child->mnt.mnt_flags &= ~MNT_LOCKED; mnt_set_mountpoint(m, mp, child); last_dest = m; last_source = child;