]> git.ipfire.org Git - people/arne_f/kernel.git/commitdiff
NFSv4: Fix memory and state leak in _nfs4_open_and_get_state
authorTrond Myklebust <trond.myklebust@primarydata.com>
Wed, 8 Feb 2017 16:29:46 +0000 (11:29 -0500)
committerJiri Slaby <jslaby@suse.cz>
Mon, 13 Mar 2017 20:40:36 +0000 (21:40 +0100)
commit a974deee477af89411e0f80456bfb344ac433c98 upstream.

If we exit because the file access check failed, we currently
leak the struct nfs4_state. We need to attach it to the
open context before returning.

Fixes: 3efb9722475e ("NFSv4: Refactor _nfs4_open_and_get_state..")
Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
fs/nfs/nfs4proc.c

index a94ec130003b26540f70b43f1ea902fe6b597124..907d363337ebf5cc6a63e635eacb717386ff0ef6 100644 (file)
@@ -2169,6 +2169,7 @@ static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata,
        ret = PTR_ERR(state);
        if (IS_ERR(state))
                goto out;
+       ctx->state = state;
        if (server->caps & NFS_CAP_POSIX_LOCK)
                set_bit(NFS_STATE_POSIX_LOCKS, &state->flags);
 
@@ -2191,7 +2192,6 @@ static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata,
        if (ret != 0)
                goto out;
 
-       ctx->state = state;
        if (dentry->d_inode == state->inode) {
                nfs_inode_attach_open_context(ctx);
                if (read_seqcount_retry(&sp->so_reclaim_seqcount, seq))