Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp1477261ybf; Thu, 27 Feb 2020 11:44:36 -0800 (PST) X-Google-Smtp-Source: APXvYqw8oiI+limLQ6384M3dDncKAfyF6tyeNqaXszC92HNU6r09b8ZApYz2g3itiVRTKCoWQVaq X-Received: by 2002:a9d:4c92:: with SMTP id m18mr416625otf.168.1582832676691; Thu, 27 Feb 2020 11:44:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582832676; cv=none; d=google.com; s=arc-20160816; b=C2nzsEfCRipa26/o1ud4gNnRMuOn4NScaMx9lEOQK3ht5lZCD+N/9NRwTjVh1K32kA tiuJhYYl54Wgf8PUZOs0nx2yu3Ryq4941BrB1pYoNnv03o/T9dbV6n3S5R23yJffbQgZ oDslk2VWf1Eq8pZBMnrFW3a9Tam1FVD82sxv4ihScdf+mmxTrjow4vJoBYjB+QVMjw1I c79E1KILCMeuWeq1aiCt3Z4OZRBu1xVR04JlqcNxUdL1A/I30kvc+N2BPJa1fEmNUm0P 37pLIsIxTMA6f2+sPabmuFCQINe4fKLP5Ek3o3jMfD3aQBLXJ9fa4ve7ZiQD0ehNephm ELJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=YrXNsOLtjOcLLNqVWonrp+5ER1eHKg+FyqDh0xsfHF0=; b=AP5cTgVvLFZ9DmWPvgdvBUdB67ZyLx5OgaCJ705NiAh1xugF5zenrMqBpEtdrnHCzJ GOC97AS3VkBGgc7JRA+aOtgb3ONgO+SiXGQjgHKRReiUAmJehgRxggcqw2WQCmijr71H ZGQEFvVyL7oLObEsb2LBUgxg0pzYqJ7n7UbOl1+TNVYR+UxB9uBXLVKjHZ8ZWeP2ku2D 9CKIsowg0LAZFz785+KkTlcB/duka7VKaXNU/hn6H3bnA6YGEBqccmVTDEEbM9bbFIx4 vOM3kQA9fOO+ZX6qgQfhPMZ495DG6nBw5SCbX0+0O9nDxUJUjW2+iOXbFEgxLjyfDK7k 2/Uw== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i5si440147oif.211.2020.02.27.11.44.23; Thu, 27 Feb 2020 11:44:36 -0800 (PST) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730522AbgB0TnP (ORCPT + 99 others); Thu, 27 Feb 2020 14:43:15 -0500 Received: from zeniv.linux.org.uk ([195.92.253.2]:47542 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730433AbgB0TnP (ORCPT ); Thu, 27 Feb 2020 14:43:15 -0500 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1j7P3w-0021LD-Ku; Thu, 27 Feb 2020 19:43:12 +0000 Date: Thu, 27 Feb 2020 19:43:12 +0000 From: Al Viro To: Linus Torvalds Cc: linux-fsdevel , Linux Kernel Mailing List Subject: Re: [RFC][PATCH v2 02/34] fix automount/automount race properly Message-ID: <20200227194312.GD23230@ZenIV.linux.org.uk> References: <20200223011154.GY23230@ZenIV.linux.org.uk> <20200223011626.4103706-1-viro@ZenIV.linux.org.uk> <20200223011626.4103706-2-viro@ZenIV.linux.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Feb 22, 2020 at 06:07:39PM -0800, Linus Torvalds wrote: > On Sat, Feb 22, 2020 at 5:16 PM Al Viro wrote: > > > > + > > +discard2: > > + namespace_unlock(); > > +discard1: > > + inode_unlock(dentry->d_inode); > > +discard: > > /* remove m from any expiration list it may be on */ > > Would you mind re-naming those labels? > > I realize that the numbering may help show that the error handling is > done in the reverse order, but I bet that a nice name could so that > too. Umm... A bit of reordering in the beginning eliminates discard1, suggesting s/discard2/discard_locked/... Incremental would be diff --git a/fs/namespace.c b/fs/namespace.c index 6228fd1ef94f..777c3116e62e 100644 --- a/fs/namespace.c +++ b/fs/namespace.c @@ -2844,22 +2844,22 @@ int finish_automount(struct vfsmount *m, struct path *path) * got", not "try to mount it on top". */ inode_lock(dentry->d_inode); + namespace_lock(); if (unlikely(cant_mount(dentry))) { err = -ENOENT; - goto discard1; + goto discard_locked; } - namespace_lock(); rcu_read_lock(); if (unlikely(__lookup_mnt(path->mnt, dentry))) { rcu_read_unlock(); err = 0; - goto discard2; + goto discard_locked; } rcu_read_unlock(); mp = get_mountpoint(dentry); if (IS_ERR(mp)) { err = PTR_ERR(mp); - goto discard2; + goto discard_locked; } err = do_add_mount(mnt, mp, path, path->mnt->mnt_flags | MNT_SHRINKABLE); @@ -2869,9 +2869,8 @@ int finish_automount(struct vfsmount *m, struct path *path) mntput(m); return 0; -discard2: +discard_locked: namespace_unlock(); -discard1: inode_unlock(dentry->d_inode); discard: /* remove m from any expiration list it may be on */