]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
nfsd: call nfsd_last_thread() before final nfsd_put()
authorNeilBrown <neilb@suse.de>
Fri, 15 Dec 2023 00:56:31 +0000 (11:56 +1100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 10 Apr 2024 14:19:29 +0000 (16:19 +0200)
[ Upstream commit 2a501f55cd641eb4d3c16a2eab0d678693fac663 ]

If write_ports_addfd or write_ports_addxprt fail, they call nfsd_put()
without calling nfsd_last_thread().  This leaves nn->nfsd_serv pointing
to a structure that has been freed.

So remove 'static' from nfsd_last_thread() and call it when the
nfsd_serv is about to be destroyed.

Fixes: ec52361df99b ("SUNRPC: stop using ->sv_nrthreads as a refcount")
Signed-off-by: NeilBrown <neilb@suse.de>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Cc: <stable@vger.kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
fs/nfsd/nfsctl.c
fs/nfsd/nfsd.h
fs/nfsd/nfssvc.c

index 76a60e7a750978406bcab7b6da8e9201e1f9518e..eec442edb6556f8abfa77e2d25ae7e343f95c714 100644 (file)
@@ -720,8 +720,10 @@ static ssize_t __write_ports_addfd(char *buf, struct net *net, const struct cred
 
        err = svc_addsock(nn->nfsd_serv, net, fd, buf, SIMPLE_TRANSACTION_LIMIT, cred);
 
-       if (err >= 0 &&
-           !nn->nfsd_serv->sv_nrthreads && !xchg(&nn->keep_active, 1))
+       if (err < 0 && !nn->nfsd_serv->sv_nrthreads && !nn->keep_active)
+               nfsd_last_thread(net);
+       else if (err >= 0 &&
+                !nn->nfsd_serv->sv_nrthreads && !xchg(&nn->keep_active, 1))
                svc_get(nn->nfsd_serv);
 
        nfsd_put(net);
@@ -771,6 +773,9 @@ out_close:
                svc_xprt_put(xprt);
        }
 out_err:
+       if (!nn->nfsd_serv->sv_nrthreads && !nn->keep_active)
+               nfsd_last_thread(net);
+
        nfsd_put(net);
        return err;
 }
index 867dcfd64d42659b89d259a24a48dc1eed343ba2..3796015dc7656ef84745e9fa1e175928c0ea09cd 100644 (file)
@@ -138,6 +138,7 @@ int nfsd_vers(struct nfsd_net *nn, int vers, enum vers_op change);
 int nfsd_minorversion(struct nfsd_net *nn, u32 minorversion, enum vers_op change);
 void nfsd_reset_versions(struct nfsd_net *nn);
 int nfsd_create_serv(struct net *net);
+void nfsd_last_thread(struct net *net);
 
 extern int nfsd_max_blksize;
 
index 96d8d3346923865111c0d62067566b701206c35b..4c1a0a1623e5e73cba7dfd4fe88757cb48bce2cc 100644 (file)
@@ -529,7 +529,7 @@ static struct notifier_block nfsd_inet6addr_notifier = {
 /* Only used under nfsd_mutex, so this atomic may be overkill: */
 static atomic_t nfsd_notifier_refcount = ATOMIC_INIT(0);
 
-static void nfsd_last_thread(struct net *net)
+void nfsd_last_thread(struct net *net)
 {
        struct nfsd_net *nn = net_generic(net, nfsd_net_id);
        struct svc_serv *serv = nn->nfsd_serv;