Skip to content

Commit 41d4cc6

Browse files
Trond Myklebustgregkh
authored andcommitted
NFS: finish_automount() requires us to hold 2 refs to the mount record
[ Upstream commit 75da985 ] 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: stable@vger.kernel.org # v5.5+ Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent a976b33 commit 41d4cc6

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

‎fs/nfs/namespace.c‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ struct vfsmount *nfs_d_automount(struct path *path)
143143
struct nfs_server *server = NFS_SERVER(d_inode(path->dentry));
144144
struct nfs_fh *fh = NULL;
145145
struct nfs_fattr *fattr = NULL;
146+
int timeout = READ_ONCE(nfs_mountpoint_expiry_timeout);
146147

147148
if (IS_ROOT(path->dentry))
148149
return ERR_PTR(-ESTALE);
@@ -157,12 +158,12 @@ struct vfsmount *nfs_d_automount(struct path *path)
157158
if (IS_ERR(mnt))
158159
goto out;
159160

160-
if (nfs_mountpoint_expiry_timeout < 0)
161+
mntget(mnt); /* prevent immediate expiration */
162+
if (timeout <= 0)
161163
goto out;
162164

163-
mntget(mnt); /* prevent immediate expiration */
164165
mnt_set_expiry(mnt, &nfs_automount_list);
165-
schedule_delayed_work(&nfs_automount_task, nfs_mountpoint_expiry_timeout);
166+
schedule_delayed_work(&nfs_automount_task, timeout);
166167

167168
out:
168169
nfs_free_fattr(fattr);
@@ -201,10 +202,11 @@ const struct inode_operations nfs_referral_inode_operations = {
201202
static void nfs_expire_automounts(struct work_struct *work)
202203
{
203204
struct list_head *list = &nfs_automount_list;
205+
int timeout = READ_ONCE(nfs_mountpoint_expiry_timeout);
204206

205207
mark_mounts_for_expiry(list);
206-
if (!list_empty(list))
207-
schedule_delayed_work(&nfs_automount_task, nfs_mountpoint_expiry_timeout);
208+
if (!list_empty(list) && timeout > 0)
209+
schedule_delayed_work(&nfs_automount_task, timeout);
208210
}
209211

210212
void nfs_release_automount_timer(void)

0 commit comments

Comments
 (0)