Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp2233141ybb; Thu, 2 Apr 2020 16:07:50 -0700 (PDT) X-Google-Smtp-Source: APiQypKO3qlb/gN6LkJPvprHGnTOfstXP1s4BWGwgHZwYvmY8V6uPaxnfTycxRinyrUsoYyV4SqO X-Received: by 2002:a05:6808:103:: with SMTP id b3mr1140292oie.46.1585868870213; Thu, 02 Apr 2020 16:07:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585868870; cv=none; d=google.com; s=arc-20160816; b=y00iKQAbAbLULMiYBcJR+ScyKMdr9m9gj1whEL/KB9ip5YdirLRIw2SNaMV1R7BgDQ ZTLxT7UDnh801gYYwWKMaweA1qg0KJ8s0NQz1zmXJ5u3Co7J50tLhO7VcUyPNLdM9tA9 yoy7gfWvCDU7e5zQ7YhryjhS0kmyH1XgwXrWpWVXRC5/99KFKHYR6ArcmtSPaHs7Wyt8 kvRnlVb399TBT145z+kDj6kBuJNyOhYV6D8qMLN9GnkeqpIhQ7k5mbJYfSsHKmeA3HCS 3fUzEwY3NLSF9GKJoOxS2hqSK5EjuKLvJgtIRdwy5eN1B58mkCDBr4TySkvm2JP+bSKI y0Hg== 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 :message-id:date:subject:to:from:dkim-signature; bh=Kd+1OnczwnDgu/CeBc9uaiuKPatNAjReRc5mlGKzg2o=; b=hyBS7xIttgHlpRZ66o7YpBXr6Ob75HLt+eS1ttqP78JG7s10AJYPVLhYZ56RgffLwn zSfAbPKzzJXxnqgiT2ZHm8kQGx7BkShr7e4wx6HtIyyfylEvkC3eztya/HKoR0eODagf IQkmMeCuZ7kzPMUqr2FiDiJD7tJDVkYOyqKB46EjjlF0YEctNGXq0Uy5noQG/9dDk1KE 8Apz4QiGX7DkMeNB+rHljmUNNwg8I8CbIorK7tGiMjpODpRfeYCEv8Unt1w0RsLsHf8a OkM6WsQsvfTTF4kKJy+hqki1GsTXcjPJZ/jWfxlKAP3cJbS8F2FiXMl2IkyTVlWsOAjB oIDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1N2AkPI4; spf=pass (google.com: best guess record for domain of linux-nfs-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k137si2860872oih.226.2020.04.02.16.07.28; Thu, 02 Apr 2020 16:07:50 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-nfs-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=1N2AkPI4; spf=pass (google.com: best guess record for domain of linux-nfs-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389586AbgDBXHQ (ORCPT + 99 others); Thu, 2 Apr 2020 19:07:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:56166 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388715AbgDBXHQ (ORCPT ); Thu, 2 Apr 2020 19:07:16 -0400 Received: from localhost.localdomain (c-68-36-133-222.hsd1.mi.comcast.net [68.36.133.222]) (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 D78A32073B for ; Thu, 2 Apr 2020 23:07:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1585868836; bh=tBe1xn5UtOjC6jEuHaEQeUMbqhQsKbohIVkjXsLrBXY=; h=From:To:Subject:Date:From; b=1N2AkPI4zkGEVhh8CJp4dioOVwQppS3nZgUkfvgFyzZ1roBiQmwOXUagkVcb5CWwF 7+AyT+PmiyRR6somp0GOqxsqTBqm0g/iNvv1wMMZLboiQgpvXLn5NuWhOz4cv5N2uh 5tqu6yS+w0gQyfaTYDDkfdN8OZ4maL0kc+TVrrpc= From: trondmy@kernel.org To: linux-nfs@vger.kernel.org Subject: [PATCH v2 1/2] NFS: finish_automount() requires us to hold 2 refs to the mount record Date: Thu, 2 Apr 2020 19:05:06 -0400 Message-Id: <20200402230507.795151-1-trondmy@kernel.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Trond Myklebust We must not return from nfs_d_automount() without holding 2 references to the mount record. Doing so, will trigger the BUG() in finish_automount(). Also ensure that we don't try to reschedule the automount timer with a negative or zero timeout value. Fixes: 22a1ae9a93fb ("NFS: If nfs_mountpoint_expiry_timeout < 0, do not expire submounts") Cc: stable@vger.kernel.org # v5.5+ Signed-off-by: Trond Myklebust --- fs/nfs/namespace.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/fs/nfs/namespace.c b/fs/nfs/namespace.c index da67820462f2..fe19ae280262 100644 --- a/fs/nfs/namespace.c +++ b/fs/nfs/namespace.c @@ -145,6 +145,7 @@ struct vfsmount *nfs_d_automount(struct path *path) struct vfsmount *mnt = ERR_PTR(-ENOMEM); struct nfs_server *server = NFS_SERVER(d_inode(path->dentry)); struct nfs_client *client = server->nfs_client; + int timeout = READ_ONCE(nfs_mountpoint_expiry_timeout); int ret; if (IS_ROOT(path->dentry)) @@ -190,12 +191,12 @@ struct vfsmount *nfs_d_automount(struct path *path) if (IS_ERR(mnt)) goto out_fc; - if (nfs_mountpoint_expiry_timeout < 0) + mntget(mnt); /* prevent immediate expiration */ + if (timeout <= 0) goto out_fc; - mntget(mnt); /* prevent immediate expiration */ mnt_set_expiry(mnt, &nfs_automount_list); - schedule_delayed_work(&nfs_automount_task, nfs_mountpoint_expiry_timeout); + schedule_delayed_work(&nfs_automount_task, timeout); out_fc: put_fs_context(fc); @@ -233,10 +234,11 @@ const struct inode_operations nfs_referral_inode_operations = { static void nfs_expire_automounts(struct work_struct *work) { struct list_head *list = &nfs_automount_list; + int timeout = READ_ONCE(nfs_mountpoint_expiry_timeout); mark_mounts_for_expiry(list); - if (!list_empty(list)) - schedule_delayed_work(&nfs_automount_task, nfs_mountpoint_expiry_timeout); + if (!list_empty(list) && timeout > 0) + schedule_delayed_work(&nfs_automount_task, timeout); } void nfs_release_automount_timer(void) -- 2.25.1