From patchwork Wed Apr 8 23:33:34 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Eric W. Biederman" X-Patchwork-Id: 6182921 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 5E10CBF4A6 for ; Wed, 8 Apr 2015 23:37:43 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6C66520395 for ; Wed, 8 Apr 2015 23:37:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 891212038F for ; Wed, 8 Apr 2015 23:37:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932431AbbDHXhk (ORCPT ); Wed, 8 Apr 2015 19:37:40 -0400 Received: from out03.mta.xmission.com ([166.70.13.233]:60330 "EHLO out03.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754893AbbDHXhj (ORCPT ); Wed, 8 Apr 2015 19:37:39 -0400 Received: from in02.mta.xmission.com ([166.70.13.52]) by out03.mta.xmission.com with esmtps (TLS1.2:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.82) (envelope-from ) id 1YfzXO-000535-Ne; Wed, 08 Apr 2015 17:37:38 -0600 Received: from 70-59-163-10.omah.qwest.net ([70.59.163.10] helo=x220.int.ebiederm.org.xmission.com) by in02.mta.xmission.com with esmtpsa (TLS1.2:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.82) (envelope-from ) id 1YfzXN-000467-TJ; Wed, 08 Apr 2015 17:37:38 -0600 From: ebiederm@xmission.com (Eric W. Biederman) To: Linux Containers Cc: , Al Viro , Andy Lutomirski , "Serge E. Hallyn" , Richard Weinberger , Andrey Vagin , Jann Horn , Willy Tarreau , Omar Sandoval References: <871tncuaf6.fsf@x220.int.ebiederm.org> <87mw5xq7lt.fsf@x220.int.ebiederm.org> <87a8yqou41.fsf_-_@x220.int.ebiederm.org> <874moq9oyb.fsf_-_@x220.int.ebiederm.org> Date: Wed, 08 Apr 2015 18:33:34 -0500 In-Reply-To: <874moq9oyb.fsf_-_@x220.int.ebiederm.org> (Eric W. Biederman's message of "Wed, 08 Apr 2015 18:31:56 -0500") Message-ID: <87mw2i8ab5.fsf_-_@x220.int.ebiederm.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 X-XM-AID: U2FsdGVkX1/qNXRDpeIdHwyGgVKtGSGnN9uo5cgVtbE= X-SA-Exim-Connect-IP: 70.59.163.10 X-SA-Exim-Mail-From: ebiederm@xmission.com X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-DCC: XMission; sa04 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: ;Linux Containers X-Spam-Relay-Country: X-Spam-Timing: total 348 ms - load_scoreonly_sql: 0.06 (0.0%), signal_user_changed: 4.2 (1.2%), b_tie_ro: 3.1 (0.9%), parse: 1.39 (0.4%), extract_message_metadata: 13 (3.7%), get_uri_detail_list: 1.70 (0.5%), tests_pri_-1000: 4.9 (1.4%), tests_pri_-950: 1.13 (0.3%), tests_pri_-900: 0.92 (0.3%), tests_pri_-400: 20 (5.8%), check_bayes: 19 (5.5%), b_tokenize: 6 (1.8%), b_tok_get_all: 6 (1.7%), b_comp_prob: 1.72 (0.5%), b_tok_touch_all: 2.8 (0.8%), b_finish: 0.72 (0.2%), tests_pri_0: 295 (84.8%), tests_pri_500: 3.7 (1.1%), rewrite_mail: 0.00 (0.0%) Subject: [PATCH review 3/4] vfs: Handle mounts whose parents are unreachable from their mountpoint X-SA-Exim-Version: 4.2.1 (built Wed, 24 Sep 2014 11:00:52 -0600) X-SA-Exim-Scanned: Yes (on in02.mta.xmission.com) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP - In follup_up and follow_up_rcu don't follow up if the current mount's mountpoint can not reach the parent mount's root. - In prepend_path and it's callers in the d_path family don't follow to the parent mount if the current mount's mountpoint can not reach the parent mount's root. Signed-off-by: "Eric W. Biederman" --- fs/dcache.c | 14 ++++++++++---- fs/namei.c | 27 +++++++++++++++++---------- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/fs/dcache.c b/fs/dcache.c index e07eb03f6de6..6e68312494ed 100644 --- a/fs/dcache.c +++ b/fs/dcache.c @@ -2894,10 +2894,16 @@ restart: struct mount *parent = ACCESS_ONCE(mnt->mnt_parent); /* Global root? */ if (mnt != parent) { - dentry = ACCESS_ONCE(mnt->mnt_mountpoint); - mnt = parent; - vfsmnt = &mnt->mnt; - continue; + struct path new = { + .dentry = ACCESS_ONCE(mnt->mnt_mountpoint), + .mnt = &parent->mnt, + }; + if (path_connected(&new)) { + mnt = parent; + dentry = new.dentry; + vfsmnt = new.mnt; + continue; + } } /* * Filesystems needing to implement special "root names" diff --git a/fs/namei.c b/fs/namei.c index 83cdcdf36eed..40e56d76df34 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -935,14 +935,16 @@ static int follow_up_rcu(struct path *path) { struct mount *mnt = real_mount(path->mnt); struct mount *parent; - struct dentry *mountpoint; + struct path new; parent = mnt->mnt_parent; - if (&parent->mnt == path->mnt) + if (parent == mnt) return 0; - mountpoint = mnt->mnt_mountpoint; - path->dentry = mountpoint; - path->mnt = &parent->mnt; + new.dentry = mnt->mnt_mountpoint; + new.mnt = &parent->mnt; + if (!path_connected(&new)) + return 0; + *path = new; return 1; } @@ -960,7 +962,7 @@ int follow_up(struct path *path) { struct mount *mnt = real_mount(path->mnt); struct mount *parent; - struct dentry *mountpoint; + struct path new; read_seqlock_excl(&mount_lock); parent = mnt->mnt_parent; @@ -968,13 +970,18 @@ int follow_up(struct path *path) read_sequnlock_excl(&mount_lock); return 0; } - mntget(&parent->mnt); - mountpoint = dget(mnt->mnt_mountpoint); + new.dentry = mnt->mnt_mountpoint; + new.mnt = &parent->mnt; + if (!path_connected(&new)) { + read_sequnlock_excl(&mount_lock); + return 0; + } + mntget(new.mnt); + dget(new.dentry); read_sequnlock_excl(&mount_lock); dput(path->dentry); - path->dentry = mountpoint; mntput(path->mnt); - path->mnt = &parent->mnt; + *path = new; return 1; } EXPORT_SYMBOL(follow_up);