]> git.baikalelectronics.ru Git - kernel.git/commitdiff
NFS: finish_automount() requires us to hold 2 refs to the mount record
authorTrond Myklebust <trond.myklebust@hammerspace.com>
Thu, 2 Apr 2020 14:34:36 +0000 (10:34 -0400)
committerTrond Myklebust <trond.myklebust@hammerspace.com>
Thu, 2 Apr 2020 22:51:12 +0000 (18:51 -0400)
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: e6939bab8135 ("NFS: If nfs_mountpoint_expiry_timeout < 0, do not expire submounts")
Cc: stable@vger.kernel.org # v5.5+
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
fs/nfs/namespace.c

index da67820462f2a8d9c75a3ee9d23a8b9f27705126..fe19ae280262aa0e00ebab2830f3c75474f0d720 100644 (file)
@@ -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)