Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp2621323imm; Thu, 11 Oct 2018 13:18:37 -0700 (PDT) X-Google-Smtp-Source: ACcGV63DO3m1oehyUS+pHQCd/Sg/WWOm1kVc42g7DfZTK6hHbHRyeIleU9hFzEs0qAou4d4fFlVn X-Received: by 2002:a17:902:24e7:: with SMTP id l36-v6mr2922540plg.234.1539289117633; Thu, 11 Oct 2018 13:18:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539289117; cv=none; d=google.com; s=arc-20160816; b=qh3SvTmWSt+5S1mSqymFJZerTZRJZyaRfUZ6OWtE9QENwcdNBoCyPw2tKq7PAKoqNW 15EIhhNyLughjls/9O8omzEOdGSZV/CDSWrzB6Y9/zsUViuUggHybVRker3AZGR/qYs6 hL/U7NDt0yhaC8Vu6As/aAvsS0Y688ZRk2BhjfsiOIsa32hc+R0JEaMmVDLtQheR8Cn1 dr2wHbh3pXokGGGT++C0gniXtbRrfzGeoznfxxaFvGaSiSbka6LH0GyeK8IsN/QzBEP5 IPTSy2g6LPyZwdoqseiuJPVxGNOs4RSZqj6J5IAQxgd2Qm4dYO++tLz9JXvafN/iaIOV 9khg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:content-transfer-encoding :content-id:mime-version:subject:cc:to:references:in-reply-to:from :organization; bh=n87KMRRVw+3qszJylIS6dSkGUhmXHFbmDjW0NFMNl6c=; b=d+ODr5KXrQb6i0fP6IanzKdhnoOAE6qkkN8+miaigJKFQuUcIqBvjAqPpM+B95JdSR V978WssPzs0FeTiIKaIPIopBE77gJdj/SiDJh6zNXuPKfTalc52gXFGwEU0UNTtdCwcW 8dTVjYGtFndMDhzOO0+6OlMHgs15jAN/yb29BNWnuhSZ/SHivdwiHDoTyplwgz1HEgze 9uooINOcntl9NrcCWIvEezCGv1P02ZkUbPjNhrCEyFSQFe4PqZrPRUgVNUouw9jmEPFO BCcJPrzCX/4UMzUWe1HNtVxLGBDMXKQVPLw8iU8v5Iowz4klRdX9MuvneYAyPhDw0Yff NcIA== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b10-v6si31753496pfb.89.2018.10.11.13.18.22; Thu, 11 Oct 2018 13:18:37 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726376AbeJLDqs convert rfc822-to-8bit (ORCPT + 99 others); Thu, 11 Oct 2018 23:46:48 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42098 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726040AbeJLDqs (ORCPT ); Thu, 11 Oct 2018 23:46:48 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5964A1152B; Thu, 11 Oct 2018 20:17:57 +0000 (UTC) Received: from warthog.procyon.org.uk (ovpn-120-149.rdu2.redhat.com [10.10.120.149]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8133787379; Thu, 11 Oct 2018 20:17:55 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 From: David Howells In-Reply-To: <87sh1cqqfs.fsf@xmission.com> References: <87sh1cqqfs.fsf@xmission.com> <5c6f3d62-4cec-2aea-4693-62928611c526@gmail.com> <153754740781.17872.7869536526927736855.stgit@warthog.procyon.org.uk> <153754743491.17872.12115848333103740766.stgit@warthog.procyon.org.uk> <862e36a2-2a6f-4e26-3228-8cab4b4cf230@gmail.com> <17405.1539272035@warthog.procyon.org.uk> To: ebiederm@xmission.com (Eric W. Biederman) Cc: dhowells@redhat.com, Alan Jenkins , viro@zeniv.linux.org.uk, torvalds@linux-foundation.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, mszeredi@redhat.com Subject: Re: [PATCH 03/34] teach move_mount(2) to work with OPEN_TREE_CLONE [ver #12] MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <15323.1539289074.1@warthog.procyon.org.uk> Content-Transfer-Encoding: 8BIT Date: Thu, 11 Oct 2018 21:17:54 +0100 Message-ID: <15324.1539289074@warthog.procyon.org.uk> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 11 Oct 2018 20:17:57 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Eric W. Biederman wrote: > It should just be a matter of replacing the test > "if (p->mnt.mnt_sb->s_type == &nsfs)" with "if mnt_ns_loop(p->mnt.mnt_root)" Okay, the attached seems to work. Thanks, David --- diff --git a/fs/namespace.c b/fs/namespace.c index e969ded7d54b..5548fb9b7de2 100644 --- a/fs/namespace.c +++ b/fs/namespace.c @@ -2388,6 +2388,27 @@ static inline int tree_contains_unbindable(struct mount *mnt) return 0; } +/* + * Object if there are any nsfs mounts in the specified subtree. These can act + * as pins for mount namespaces that aren't checked by the mount-cycle checking + * code, thereby allowing cycles to be made. + */ +static bool check_for_nsfs_mounts(struct mount *subtree) +{ + struct mount *p; + bool ret = false; + + lock_mount_hash(); + for (p = subtree; p; p = next_mnt(p, subtree)) + if (mnt_ns_loop(p->mnt.mnt_root)) + goto out; + + ret = true; +out: + unlock_mount_hash(); + return ret; +} + static int do_move_mount(struct path *old_path, struct path *new_path) { struct path parent_path = {.mnt = NULL, .dentry = NULL}; @@ -2442,6 +2463,8 @@ static int do_move_mount(struct path *old_path, struct path *new_path) if (IS_MNT_SHARED(p) && tree_contains_unbindable(old)) goto out1; err = -ELOOP; + if (!check_for_nsfs_mounts(old)) + goto out1; for (; mnt_has_parent(p); p = p->mnt_parent) if (p == old) goto out1;