Skip to content

Commit 75da985

Browse files
author
Trond Myklebust
committed
NFS: finish_automount() requires us to hold 2 refs to the mount record
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: 22a1ae9 ("NFS: If nfs_mountpoint_expiry_timeout < 0, do not expire submounts") Cc: [email protected] # v5.5+ Signed-off-by: Trond Myklebust <[email protected]>
1 parent 529af90 commit 75da985

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

fs/nfs/namespace.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ struct vfsmount *nfs_d_automount(struct path *path)
145145
struct vfsmount *mnt = ERR_PTR(-ENOMEM);
146146
struct nfs_server *server = NFS_SERVER(d_inode(path->dentry));
147147
struct nfs_client *client = server->nfs_client;
148+
int timeout = READ_ONCE(nfs_mountpoint_expiry_timeout);
148149
int ret;
149150

150151
if (IS_ROOT(path->dentry))
@@ -190,12 +191,12 @@ struct vfsmount *nfs_d_automount(struct path *path)
190191
if (IS_ERR(mnt))
191192
goto out_fc;
192193

193-
if (nfs_mountpoint_expiry_timeout < 0)
194+
mntget(mnt); /* prevent immediate expiration */
195+
if (timeout <= 0)
194196
goto out_fc;
195197

196-
mntget(mnt); /* prevent immediate expiration */
197198
mnt_set_expiry(mnt, &nfs_automount_list);
198-
schedule_delayed_work(&nfs_automount_task, nfs_mountpoint_expiry_timeout);
199+
schedule_delayed_work(&nfs_automount_task, timeout);
199200

200201
out_fc:
201202
put_fs_context(fc);
@@ -233,10 +234,11 @@ const struct inode_operations nfs_referral_inode_operations = {
233234
static void nfs_expire_automounts(struct work_struct *work)
234235
{
235236
struct list_head *list = &nfs_automount_list;
237+
int timeout = READ_ONCE(nfs_mountpoint_expiry_timeout);
236238

237239
mark_mounts_for_expiry(list);
238-
if (!list_empty(list))
239-
schedule_delayed_work(&nfs_automount_task, nfs_mountpoint_expiry_timeout);
240+
if (!list_empty(list) && timeout > 0)
241+
schedule_delayed_work(&nfs_automount_task, timeout);
240242
}
241243

242244
void nfs_release_automount_timer(void)

0 commit comments

Comments
 (0)