Skip to content

Commit 2fdb05d

Browse files
author
Trond Myklebust
committed
NFSv4.0: Fix a use-after-free problem in the asynchronous open()
Yang Erkun reports that when two threads are opening files at the same time, and are forced to abort before a reply is seen, then the call to nfs_release_seqid() in nfs4_opendata_free() can result in a use-after-free of the pointer to the defunct rpc task of the other thread. The fix is to ensure that if the RPC call is aborted before the call to nfs_wait_on_sequence() is complete, then we must call nfs_release_seqid() in nfs4_open_release() before the rpc_task is freed. Reported-by: Yang Erkun <[email protected]> Fixes: 24ac23a ("NFSv4: Convert open() into an asynchronous RPC call") Reviewed-by: Yang Erkun <[email protected]> Signed-off-by: Trond Myklebust <[email protected]>
1 parent c968fd2 commit 2fdb05d

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

fs/nfs/nfs4proc.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2603,12 +2603,14 @@ static void nfs4_open_release(void *calldata)
26032603
struct nfs4_opendata *data = calldata;
26042604
struct nfs4_state *state = NULL;
26052605

2606+
/* In case of error, no cleanup! */
2607+
if (data->rpc_status != 0 || !data->rpc_done) {
2608+
nfs_release_seqid(data->o_arg.seqid);
2609+
goto out_free;
2610+
}
26062611
/* If this request hasn't been cancelled, do nothing */
26072612
if (!data->cancelled)
26082613
goto out_free;
2609-
/* In case of error, no cleanup! */
2610-
if (data->rpc_status != 0 || !data->rpc_done)
2611-
goto out_free;
26122614
/* In case we need an open_confirm, no cleanup! */
26132615
if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)
26142616
goto out_free;

0 commit comments

Comments
 (0)