nfs: fix potential credential leak in ff_layout_update_mirror_cred
authorJeff Layton <jlayton@poochiereds.net>
Wed, 24 Jun 2015 16:10:23 +0000 (12:10 -0400)
committerTrond Myklebust <trond.myklebust@primarydata.com>
Thu, 25 Jun 2015 23:34:40 +0000 (19:34 -0400)
If we have two tasks racing to update a mirror's credentials, then they
can end up leaking one (or more) sets of credentials. The first task
will set mirror->cred and then the second task will just overwrite it.

Use a cmpxchg to ensure that the creds are only set once. If we get to
the point where we would set mirror->cred and find that they're already
set, then we just release the creds that were just found.

Signed-off-by: Jeff Layton <jeff.layton@primarydata.com>
Cc: stable@vger.kernel.org # 4.0+
Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
fs/nfs/flexfilelayout/flexfilelayoutdev.c

index 77a2d026aa12b62bdc29dac2345cff0b3237e9c4..c19b9a88f74848fb2f022d5a2946a3705427d1b7 100644 (file)
@@ -324,7 +324,8 @@ static int ff_layout_update_mirror_cred(struct nfs4_ff_layout_mirror *mirror,
                                __func__, PTR_ERR(cred));
                        return PTR_ERR(cred);
                } else {
-                       mirror->cred = cred;
+                       if (cmpxchg(&mirror->cred, NULL, cred))
+                               put_rpccred(cred);
                }
        }
        return 0;
This page took 0.027656 seconds and 5 git commands to generate.