NFSv4/pnfs: Fix a use-after-free bug in open
authorTrond Myklebust <trond.myklebust@hammerspace.com>
Tue, 2 Aug 2022 19:48:50 +0000 (15:48 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 25 Aug 2022 09:40:02 +0000 (11:40 +0200)
commit 2135e5d56278ffdb1c2e6d325dc6b87f669b9dac upstream.

If someone cancels the open RPC call, then we must not try to free
either the open slot or the layoutget operation arguments, since they
are likely still in use by the hung RPC call.

Fixes: 6949493884fe ("NFSv4: Don't hold the layoutget locks across multiple RPC calls")
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/nfs/nfs4proc.c

index a93b408..a808763 100644 (file)
@@ -3106,12 +3106,13 @@ static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata,
        }
 
 out:
-       if (opendata->lgp) {
-               nfs4_lgopen_release(opendata->lgp);
-               opendata->lgp = NULL;
-       }
-       if (!opendata->cancelled)
+       if (!opendata->cancelled) {
+               if (opendata->lgp) {
+                       nfs4_lgopen_release(opendata->lgp);
+                       opendata->lgp = NULL;
+               }
                nfs4_sequence_free_slot(&opendata->o_res.seq_res);
+       }
        return ret;
 }